From 876390b557b79118d4844225300e6ff88d698668 Mon Sep 17 00:00:00 2001 From: freepius Date: Mon, 25 Aug 2014 12:11:11 +0200 Subject: [PATCH 1/2] Update Silex to version 2.0 --- README.md | 4 ++-- composer.json | 6 +++--- src/Nicl/Silex/AutolinkServiceProvider.php | 19 ++++++------------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 426f675..14e1a67 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ the following to your `composer.json` file: { "require": { - "nicl/silex-autolink": "1.0.*" + "nicl/silex-autolink": "2.0.*" } } @@ -41,4 +41,4 @@ the silex-autolink root directory run: phpunit (You may need to adapt the phpunit command and paths depending on your -configuration.) \ No newline at end of file +configuration.) diff --git a/composer.json b/composer.json index ec812a6..656c24d 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "silex/silex": "1.0.*@dev", + "silex/silex": "2.0.*@dev", "twig/twig": ">=1.8,<2.0-dev" }, "autoload": { @@ -18,7 +18,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0-dev" } } -} \ No newline at end of file +} diff --git a/src/Nicl/Silex/AutolinkServiceProvider.php b/src/Nicl/Silex/AutolinkServiceProvider.php index f3d5f6d..84662de 100644 --- a/src/Nicl/Silex/AutolinkServiceProvider.php +++ b/src/Nicl/Silex/AutolinkServiceProvider.php @@ -2,8 +2,8 @@ namespace Nicl\Silex; -use Silex\Application; -use Silex\ServiceProviderInterface; +use Pimple\Container; +use Pimple\ServiceProviderInterface; use Nicl\Autolink; use Nicl\Twig\Extension\AutolinkTwigExtension; @@ -15,18 +15,11 @@ class AutolinkServiceProvider implements ServiceProviderInterface /** * {@inheritdoc} */ - public function register(Application $app) + public function register(Container $app) { - $app['twig'] = $app->share($app->extend('twig', function($twig, $app) { + $app['twig'] = $app->extend('twig', function($twig, $app) { $twig->addExtension(new AutolinkTwigExtension(new Autolink())); return $twig; - })); + }); } - - /** - * {@inheritdoc} - */ - public function boot(Application $app) - { - } -} \ No newline at end of file +} From f71e57daba9f7a942ca0fe3630288c88e40bcddd Mon Sep 17 00:00:00 2001 From: freepius Date: Mon, 25 Aug 2014 12:13:11 +0200 Subject: [PATCH 2/2] Better DIC conception --- src/Nicl/Autolink.php | 53 +-------------- src/Nicl/AutolinkInterface.php | 67 +++++++++++++++++++ src/Nicl/Silex/AutolinkServiceProvider.php | 6 +- .../Twig/Extension/AutolinkTwigExtension.php | 8 +-- 4 files changed, 78 insertions(+), 56 deletions(-) create mode 100644 src/Nicl/AutolinkInterface.php diff --git a/src/Nicl/Autolink.php b/src/Nicl/Autolink.php index b56df39..cb24307 100644 --- a/src/Nicl/Autolink.php +++ b/src/Nicl/Autolink.php @@ -7,57 +7,8 @@ * * Identifying URLs within a string is actually quite difficult. */ -class Autolink +class Autolink implements AutolinkInterface { - /** - * Permissive match if begins with protocal - */ - const PROTOCAL = '((ftp|https?)://[-\p{L}\p{N}]+(\.[\p{L}\p{N}_][-\p{L}\p{N}_]*)+)'; - - /** - * Match when protocal missing - * - * Wikipedia helpfully lists available top-level domains. - * @link http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains - */ - const NO_PROTOCAL = '(([\p{L}\p{N}]+ \. )+ - ( aero\b - | asia\b - | biz\b - | cat\b - | com\b - | coop\b - | edu\b - | gov\b - | info\b - | int\b - | jobs\b - | mil\b - | mobi\b - | museum\b - | name\b - | net\b - | org\b - | pro\b - | tel\b - | travel\b - | xxx\b - | [a-z][a-z]\b - ))'; - - /** - * Definition of (optional) port - */ - const PORT = '(:\d+)?'; - - /** - * Pragmatic definition of path - * - * Note, the whitelist for ending characters which excludes several valid - * characters. - */ - const PATH = '(((/[\pL\pN-._~:/?#\[\]@!$&\'()*+,;=]*) *)?[\pL\pN_&=#\\/])?'; - /** * @var string * @@ -92,4 +43,4 @@ public function autolink($txt) return preg_replace($pattern, $replacement, $txt); } -} \ No newline at end of file +} diff --git a/src/Nicl/AutolinkInterface.php b/src/Nicl/AutolinkInterface.php new file mode 100644 index 0000000..730667b --- /dev/null +++ b/src/Nicl/AutolinkInterface.php @@ -0,0 +1,67 @@ +extend('twig', function($twig, $app) { - $twig->addExtension(new AutolinkTwigExtension(new Autolink())); + $twig->addExtension(new AutolinkTwigExtension($app['autolink.parser'])); return $twig; }); } diff --git a/src/Nicl/Twig/Extension/AutolinkTwigExtension.php b/src/Nicl/Twig/Extension/AutolinkTwigExtension.php index 2a897f6..72d382b 100644 --- a/src/Nicl/Twig/Extension/AutolinkTwigExtension.php +++ b/src/Nicl/Twig/Extension/AutolinkTwigExtension.php @@ -2,7 +2,7 @@ namespace Nicl\Twig\Extension; -use Nicl\Autolink; +use Nicl\AutolinkInterface; /** * Twig Autolink extension @@ -14,11 +14,11 @@ class AutolinkTwigExtension extends \Twig_Extension /** * Public constructor * - * @param Autolink $parser + * @param AutolinkInterface $parser * * @return AutolinkTwigExtension */ - public function __construct(Autolink $parser) + public function __construct(AutolinkInterface $parser) { $this->parser = $parser; } @@ -53,4 +53,4 @@ public function getName() { return 'autolink'; } -} \ No newline at end of file +}