-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ceb5c7a
commit 5645621
Showing
14 changed files
with
348 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor/ | ||
composer.lock | ||
/var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
language: php | ||
|
||
matrix: | ||
include: | ||
# PHP tests | ||
- language: php | ||
php: 7.1 | ||
env: COMPOSER_FLAGS="--prefer-lowest" | ||
before_script: | ||
- composer update $COMPOSER_FLAGS --prefer-dist | ||
script: vendor/bin/phpunit | ||
- language: php | ||
php: 7.1 | ||
env: COMPOSER_FLAGS="--prefer-stable" | ||
before_script: | ||
- composer update $COMPOSER_FLAGS --prefer-dist | ||
script: vendor/bin/phpunit | ||
- language: php | ||
php: 7.1 | ||
env: COMPOSER_FLAGS="" | ||
before_script: | ||
- composer update $COMPOSER_FLAGS --prefer-dist | ||
script: vendor/bin/phpunit | ||
- language: php | ||
php: 7.1 | ||
env: SYMFONY_VERSION="4.0.*" | ||
before_script: | ||
- composer update $COMPOSER_FLAGS --prefer-dist | ||
script: vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,52 @@ | ||
# financial-twig-extension-bundle | ||
A simple Symfony Bundle that contains twig extensions for displaying financial information | ||
A simple Symfony Bundle that contains twig extensions for | ||
displaying financial information | ||
|
||
Installation | ||
------------ | ||
Install the latest version via [composer](https://getcomposer.org/): | ||
```bash | ||
php composer.phar require hostnet/financial-twig-extension-bundle | ||
``` | ||
|
||
Then add the bundle to your AppKernel bundles: | ||
```php | ||
<?php | ||
// app/AppKernel.php | ||
|
||
public function registerBundles() | ||
{ | ||
$bundles = array( | ||
// ... | ||
new \Hostnet\Bundle\FinancialTwigExtensionBundle\Bundle\HostnetFinancialTwigExtensionBundle(), | ||
// ... | ||
); | ||
} | ||
``` | ||
|
||
Usage | ||
----- | ||
Currently, we support formatting International Bank Account | ||
Numbers (IBAN) for displaying on a page (a space for every four characters): | ||
```twig | ||
{{ "NL85INGB0008523141"|formatIban }} | ||
``` | ||
|
||
This will result in the following output: | ||
```text | ||
NL85 INGB 0008 5231 41 | ||
``` | ||
|
||
Requirements | ||
------------ | ||
|
||
PHP 7.1.x or above. | ||
|
||
License | ||
------- | ||
|
||
This library is licensed under the MIT License, meaning you can reuse the code | ||
within proprietary software provided that all copies of the licensed software | ||
include a copy of the MIT License terms and the copyright notice. | ||
|
||
For more information, see the [LICENSE](LICENSE) file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "hostnet/financial-twig-extension-bundle", | ||
"type": "symfony-bundle", | ||
"description": "A simple Symfony Bundle that contains twig extensions for displaying financial information.", | ||
"license": "MIT", | ||
"require": { | ||
"php": "^7.1", | ||
"symfony/framework-bundle": "^3.3|^4.0" | ||
}, | ||
"require-dev": { | ||
"hostnet/phpcs-tool": "^5.2", | ||
"phpunit/phpunit": "^6.3", | ||
"symfony/twig-bundle": "^3.3|^4.0", | ||
"symfony/yaml": "^3.3|^4.0", | ||
"twig/twig": "^1.26|^2.0" | ||
}, | ||
"conflict": { | ||
"twig/twig": "<1.26" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Hostnet\\Bundle\\FinancialTwigExtensionBundle\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Hostnet\\Bundle\\FinancialTwigExtensionBundle\\": "test/" | ||
} | ||
}, | ||
"archive": { | ||
"exclude": [ | ||
"/test" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation = "http://schema.phpunit.de/4.7/phpunit.xsd" | ||
colors = "true" | ||
forceCoversAnnotation = "true" | ||
bootstrap = "vendor/autoload.php" | ||
> | ||
<php> | ||
<server name="KERNEL_CLASS" value="Hostnet\Bundle\FinancialTwigExtensionBundle\Functional\Fixtures\TestKernel"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="unit"> | ||
<directory>./test</directory> | ||
<exclude>./test/Functional</exclude> | ||
</testsuite> | ||
<testsuite name="functional"> | ||
<directory>./test/Functional</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory>./src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/** | ||
* @copyright 2017 Hostnet B.V. | ||
*/ | ||
declare(strict_types=1); | ||
namespace Hostnet\Bundle\FinancialTwigExtensionBundle\Bundle; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class HostnetFinancialTwigExtensionBundle extends Bundle | ||
{ | ||
public function build(ContainerBuilder $container) | ||
{ | ||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/Resources')); | ||
$loader->load('services.yml'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
services: | ||
Hostnet\Bundle\FinancialTwigExtensionBundle\Twig\FormatIbanExtension: | ||
public: false | ||
tags: | ||
- twig.extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* @copyright 2017 Hostnet B.V. | ||
*/ | ||
declare(strict_types=1); | ||
namespace Hostnet\Bundle\FinancialTwigExtensionBundle\Twig; | ||
|
||
class FormatIbanExtension extends \Twig_Extension | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFilters() | ||
{ | ||
return [ | ||
new \Twig_SimpleFilter('formatIban', [$this, 'formatIban']) | ||
]; | ||
} | ||
|
||
public function formatIban(string $iban): string | ||
{ | ||
return implode(' ', str_split(preg_replace('/\s+/', '', $iban), 4)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* @copyright 2017 Hostnet B.V. | ||
*/ | ||
declare(strict_types=1); | ||
namespace Hostnet\Bundle\FinancialTwigExtensionBundle\Bundle; | ||
|
||
use Hostnet\Bundle\FinancialTwigExtensionBundle\Twig\FormatIbanExtension; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
/** | ||
* @covers \Hostnet\Bundle\FinancialTwigExtensionBundle\Bundle\HostnetFinancialTwigExtensionBundle | ||
*/ | ||
class HostnetFinancialTwigExtensionBundleTest extends TestCase | ||
{ | ||
/** | ||
* @var HostnetFinancialTwigExtensionBundle | ||
*/ | ||
private $hostnet_financial_twig_extension_bundle; | ||
|
||
protected function setUp() | ||
{ | ||
$this->hostnet_financial_twig_extension_bundle = new HostnetFinancialTwigExtensionBundle(); | ||
} | ||
|
||
public function testBuild() | ||
{ | ||
$container = new ContainerBuilder(); | ||
$this->hostnet_financial_twig_extension_bundle->build($container); | ||
|
||
self::assertInstanceOf( | ||
Definition::class, | ||
$container->getDefinition(FormatIbanExtension::class) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* @copyright 2017 Hostnet B.V. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Hostnet\Bundle\FinancialTwigExtensionBundle\Functional; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
class ConfigurationTest extends KernelTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
static::bootKernel(); | ||
} | ||
|
||
public function testFormatIban() | ||
{ | ||
$container = static::$kernel->getContainer(); | ||
$twig = $container->get('twig'); | ||
|
||
self::assertSame( | ||
'NL85 INGB 0008 5231 41', | ||
$twig->render('/ibantest.html.twig', ['iban' => 'NL85INGB0008523141']) | ||
); | ||
|
||
self::assertSame( | ||
'NL85 INGB 0008 5231 41', | ||
$twig->render('/ibantest.html.twig', ['iban' => 'NL8 5I NGB00 085 2314 1']) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ iban|formatIban }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* @copyright 2017 Hostnet B.V. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Hostnet\Bundle\FinancialTwigExtensionBundle\Functional\Fixtures; | ||
|
||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
class TestKernel extends Kernel | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function registerBundles() | ||
{ | ||
return [ | ||
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), | ||
new \Symfony\Bundle\TwigBundle\TwigBundle(), | ||
new \Hostnet\Bundle\FinancialTwigExtensionBundle\Bundle\HostnetFinancialTwigExtensionBundle() | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function registerContainerConfiguration(LoaderInterface $loader) | ||
{ | ||
$loader->load(__DIR__ . '/config/config.yml'); | ||
} | ||
|
||
public function getLogDir() | ||
{ | ||
return __DIR__ . '/../../../var/log'; | ||
} | ||
|
||
public function getCacheDir() | ||
{ | ||
return __DIR__ . '/../../../var/cache'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
framework: | ||
secret: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* @copyright 2017 Hostnet B.V. | ||
*/ | ||
declare(strict_types=1); | ||
namespace Hostnet\Bundle\FinancialTwigExtensionBundle\Twig; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \Hostnet\Bundle\FinancialTwigExtensionBundle\Twig\FormatIbanExtension | ||
*/ | ||
class FormatIbanExtensionTest extends TestCase | ||
{ | ||
/** | ||
* @var FormatIbanExtension | ||
*/ | ||
private $format_iban_extension; | ||
|
||
protected function setUp() | ||
{ | ||
$this->format_iban_extension = new FormatIbanExtension(); | ||
} | ||
|
||
public function testGetFilters() | ||
{ | ||
self::assertEquals( | ||
[new \Twig_SimpleFilter('formatIban', [$this->format_iban_extension, 'formatIban'])], | ||
$this->format_iban_extension->getFilters() | ||
); | ||
} | ||
|
||
public function testFormatIban() | ||
{ | ||
self::assertSame('NL85 INGB 0008 5231 41', $this->format_iban_extension->formatIban('NL85INGB0008523141')); | ||
self::assertSame('NL85 INGB 0008 5231 41', $this->format_iban_extension->formatIban('N L85IN GB00085 23141')); | ||
} | ||
} |