diff --git a/.gitignore b/.gitignore index f22ae87..a3bd160 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ -.idea composer.lock -Tests/cache -Tests/log +clover.xml +/.idea/ +/var/ +/vendor/ +/Tests/cache +/Tests/log diff --git a/.travis.yml b/.travis.yml index 95d268a..7f1fe2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,8 @@ language: php php: - - 5.6 - - 7.0 - - 7.1 + - 7.1.3 + - 7.2.0 sudo: false @@ -16,10 +15,6 @@ matrix: fast_finish: true env: - - SYMFONY_VERSION="3.0.*" DECODA_VERSION="6.0.*" - - SYMFONY_VERSION="3.0.*" DECODA_VERSION="6.*" - - SYMFONY_VERSION="3.1.*" DECODA_VERSION="6.*" - - SYMFONY_VERSION="3.2.*" DECODA_VERSION="6.*" - SYMFONY_VERSION="3.3.*" DECODA_VERSION="6.*" - SYMFONY_VERSION="3.4.*" DECODA_VERSION="6.*" - SYMFONY_VERSION="4.0.*" DECODA_VERSION="6.*" diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 5d14579..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,14 +0,0 @@ -1.02.2013 -* Now can accept short and long locale codes - -30.01.2013 -* Upgraded to Decoda 5.x -* Added clean filter (bbcode_clean, to strip-out tags) -* Emoticons Dump Command - -14.03.2012: -* Root node for a configuration now called fm_bbcode -* Changed a lot of files, adda php template helper -* Changed behavior to filters function like ( in avalanche123/liip imagine bundle), i.e. from simple BBCode - twig extension to a little bit more complicated bbcode_filter('my_filter') -* Multiple bbcode filters now available \ No newline at end of file diff --git a/Command/DumpEmoticonsCommand.php b/Command/DumpEmoticonsCommand.php index 47a00d9..33edff1 100644 --- a/Command/DumpEmoticonsCommand.php +++ b/Command/DumpEmoticonsCommand.php @@ -21,18 +21,18 @@ protected function configure() { $this ->setName('bbcode:dump') - ->setDescription('dump emoticons to public folder') - ->addOption('emoticons-folder', null, InputOption::VALUE_OPTIONAL, null, null) + ->setDescription('Dumps the emoticons to their configured folder') + ->addOption('emoticons-folder', null, InputOption::VALUE_OPTIONAL) ; } /** * Copies one folder to another. * - * @param $src - * @param $dst + * @param string $src + * @param string $dst */ - private function recurseCopy($src, $dst) + private function recurseCopy(string $src, string $dst) { $dir = opendir($src); @mkdir($dst); @@ -49,15 +49,15 @@ private function recurseCopy($src, $dst) } /** - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Symfony\Component\Console\Output\OutputInterface $output + * @param InputInterface $input + * @param OutputInterface $output * - * @return int|null|void + * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { $webFolder = sprintf('%s%s', - $this->getContainer()->getParameter('assetic.write_to'), + $this->getContainer()->getParameter('fm_bbcode.public_path'), $this->getContainer()->getParameter('fm_bbcode.emoticon.path') ); @mkdir($webFolder); @@ -68,11 +68,14 @@ protected function execute(InputInterface $input, OutputInterface $output) } if (!file_exists($emoticonsFolder) && !is_dir($emoticonsFolder)) { - return $output->writeln('Emoticons folder does not exist'); + $output->writeln('Emoticons folder does not exist'); + return 2; // ENOENT - No such file or directory } $this->recurseCopy($emoticonsFolder, $webFolder); $output->writeln('Emoticons dumped succesfully'); + + return 0; } } diff --git a/DependencyInjection/Compiler/RegisterFiltersPass.php b/DependencyInjection/Compiler/RegisterFiltersPass.php index 1eae7c2..a7978d3 100644 --- a/DependencyInjection/Compiler/RegisterFiltersPass.php +++ b/DependencyInjection/Compiler/RegisterFiltersPass.php @@ -6,6 +6,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Decoda\Filter; class RegisterFiltersPass implements CompilerPassInterface { @@ -37,7 +38,7 @@ public function process(ContainerBuilder $container) $class = $container->getDefinition($id)->getClass(); $refClass = new \ReflectionClass($class); - $interface = 'Decoda\Filter'; + $interface = Filter::class; if (!$refClass->implementsInterface($interface)) { throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface)); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index e78ed60..6ce6d36 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -97,6 +97,7 @@ public function getConfigTreeBuilder() ->end() ->end() ->end() + ->scalarNode('public_path')->defaultValue('%kernel.project_dir%/public')->end() ->end() ->end(); @@ -132,7 +133,9 @@ private function addEmoticonSection(ArrayNodeDefinition $rootNode) }) ->end() ->end() - ->scalarNode('folder')->defaultValue('%kernel.root_dir%/../vendor/mjohnson/decoda/emoticons')->end() + ->scalarNode('folder') + ->defaultValue('%kernel.project_dir%/vendor/mjohnson/decoda/emoticons') + ->end() ->scalarNode('extension')->defaultValue('png')->end() ->end() ->end() diff --git a/DependencyInjection/FMBbcodeExtension.php b/DependencyInjection/FMBbcodeExtension.php index 872e647..77e6460 100644 --- a/DependencyInjection/FMBbcodeExtension.php +++ b/DependencyInjection/FMBbcodeExtension.php @@ -17,10 +17,10 @@ class FMBbcodeExtension extends Extension { /** - * @see Symfony\Component\DependencyInjection\Extension.ExtensionInterface::load() + * @see \Symfony\Component\DependencyInjection\Extension\ExtensionInterface::load() * - * @param array $configs - * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container + * @param array $configs + * @param ContainerBuilder $container */ public function load(array $configs, ContainerBuilder $container) { diff --git a/README.md b/README.md index 48f59a4..879cc68 100644 --- a/README.md +++ b/README.md @@ -40,26 +40,33 @@ Using Composer, just add the following configuration to your `composer.json`: Or you can use composer to install this bundle: -For symfony <3.0, use latest ~6 version +For Symfony <3.0, use latest ~6 version ```sh composer require helios-ag/fm-bbcode-bundle:~6 ``` -for Symfony 3 +For Symfony 3.0, use latest ~7 version ```sh composer require helios-ag/fm-bbcode-bundle ``` + or ```sh composer require helios-ag/fm-bbcode-bundle:~7 ``` +For Symfony 4.0 you can use the ~8 version + +```sh +composer require helios-ag/fm-bbcode-bundle:~8 +``` + ### Step 2: Enable the bundle -Finally, enable the bundle in the kernel: +Finally, for Symfony2 and Symfony3, enable the bundle in the AppKernel: ``` php ['all' => true], +]; +``` + ### Step 3: Dump emoticons (optional) To enable emoticons via emoticon hook, use the following command to copy emoticons images to public folder (web/emoticons) +For Symfony2: ``` bash ./app/console bbcode:dump ``` +For Symfony3 and Symfony4: +``` bash + ./bin/console bbcode:dump +``` + ## Basic configuration ### Make the Twig extensions available by updating your configuration: @@ -259,12 +283,27 @@ emoticons: - ":my_emoticon:" ``` +### How to customize the emoticons assets + +To customize emoticons assets folders, use `path` and `folder` node configuration: + +```yaml +# app/config.yml + +fm_bbcode: + public_path: # Default: %kernel.project_dir%/public + emoticon: + path: # Default: /emoticons + folder: # Default: %kernel.project_dir%/vendor/mjohnson/decoda/emoticons% +``` + +Using the default configuration it would dump the emoticons in ` %kernel.project_dir%/public/emoticons` + ### How to automatically dump emoticons on each deploy -Add the following commands to you projects composer.json: +Add the following commands to you projects `composer.json`: ```json -# composer.json "scripts": { "post-install-cmd": [ "FM\\BbcodeBundle\\Composer\\ScriptHandler::installEmoticons" @@ -274,14 +313,3 @@ Add the following commands to you projects composer.json: ] } ``` - -To customize emoticons assets folders, use `path` and `folder` node configuration: - -```yaml -# app/config.yml - -fm_bbcode: - emoticon: - path: # Default: /emoticons - folder: # Default: %kernel.root_dir%/../vendor/mjohnson/decoda/emoticons% -``` diff --git a/Resources/config/bbcode.xml b/Resources/config/bbcode.xml index cf80156..bd31f22 100644 --- a/Resources/config/bbcode.xml +++ b/Resources/config/bbcode.xml @@ -15,12 +15,12 @@ - + - + diff --git a/Resources/config/filters.xml b/Resources/config/filters.xml index 6ccd6a6..7b62859 100644 --- a/Resources/config/filters.xml +++ b/Resources/config/filters.xml @@ -19,37 +19,37 @@ - + - + - + - + - + - + - + - + - + - + - + diff --git a/Tests/Command/DumpEmoticonsCommandTest.php b/Tests/Command/DumpEmoticonsCommandTest.php index 1a1979b..633a430 100644 --- a/Tests/Command/DumpEmoticonsCommandTest.php +++ b/Tests/Command/DumpEmoticonsCommandTest.php @@ -2,13 +2,15 @@ namespace FM\BbcodeBundle\Tests\Command; +use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Tester\CommandTester; use FM\BbcodeBundle\Command\DumpEmoticonsCommand; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * @author Alexandre Quercia */ -class DumpEmoticonsCommandTest extends \PHPUnit_Framework_TestCase +class DumpEmoticonsCommandTest extends TestCase { private $rootDir; private $webDir; @@ -57,14 +59,14 @@ public function testExecute() $rootDir = $this->rootDir; $emoticonFolder = $this->emoticonFolder; - $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $container = $this->createMock(ContainerInterface::class); $container ->expects($this->any()) ->method('getParameter') ->withAnyParameters() ->will($this->returnCallback(function ($v) use ($webDir, $emoticonPath, $rootDir, $emoticonFolder) { switch ($v) { - case 'assetic.write_to': + case 'fm_bbcode.public_path': return $webDir; case 'fm_bbcode.emoticon.path': return $emoticonPath; diff --git a/Tests/Decoda/DecodaManagerTest.php b/Tests/Decoda/DecodaManagerTest.php index 651da49..1616d9e 100644 --- a/Tests/Decoda/DecodaManagerTest.php +++ b/Tests/Decoda/DecodaManagerTest.php @@ -2,10 +2,15 @@ namespace FM\BbcodeBundle\Tests\Decoda; +use Decoda\Filter; +use Decoda\Hook; use FM\BbcodeBundle\Decoda\DecodaManager; +use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Config\FileLocator; +use Symfony\Component\HttpKernel\KernelInterface; -class DecodaManagerTest extends \PHPUnit_Framework_TestCase +class DecodaManagerTest extends TestCase { /** * @var DecodaManager @@ -14,8 +19,8 @@ class DecodaManagerTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); - $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface'); + $container = $this->createMock(ContainerInterface::class); + $kernel = $this->createMock(KernelInterface::class); $locator = new FileLocator($kernel); $options = array( @@ -36,7 +41,7 @@ public function testHas() public function testSetFilter() { - $filter = $this->getMock('Decoda\\Filter'); + $filter = $this->createMock(Filter::class); $this->object->setFilter('foo', $filter); $this->assertTrue($this->object->hasFilter('foo')); $this->assertSame($filter, $this->object->getFilter('foo')); @@ -44,7 +49,7 @@ public function testSetFilter() public function testSetHook() { - $hook = $this->getMock('Decoda\\Hook'); + $hook = $this->createMock(Hook::class); $this->object->setHook('foo', $hook); $this->assertTrue($this->object->hasHook('foo')); $this->assertSame($hook, $this->object->getHook('foo')); diff --git a/Tests/Decoda/DecodaTest.php b/Tests/Decoda/DecodaTest.php index 317bde0..551dd1e 100644 --- a/Tests/Decoda/DecodaTest.php +++ b/Tests/Decoda/DecodaTest.php @@ -3,14 +3,10 @@ namespace FM\BbcodeBundle\Tests\Decoda; use FM\BbcodeBundle\Decoda\Decoda; +use PHPUnit\Framework\TestCase; -class DecodaTest extends \PHPUnit_Framework_TestCase +class DecodaTest extends TestCase { - public function testConstructor() - { - $result = new Decoda(); - } - public function testSetLocale() { $result = new Decoda(); @@ -30,7 +26,8 @@ public function testSetLocale() public function testMessage($defaultLocale, $locale, $value, $expect) { if ($expect instanceof \Exception) { - $this->setExpectedException(get_class($expect), $expect->getMessage()); + $this->expectException(get_class($expect)); + $this->expectExceptionMessage($expect->getMessage()); } $result = new Decoda(); diff --git a/Tests/Decoda/Hook/EmoticonHookTest.php b/Tests/Decoda/Hook/EmoticonHookTest.php index db9caac..3c4e2d3 100644 --- a/Tests/Decoda/Hook/EmoticonHookTest.php +++ b/Tests/Decoda/Hook/EmoticonHookTest.php @@ -2,23 +2,15 @@ namespace FM\BbcodeBundle\Tests\Decoda\Hook; +use FM\BbcodeBundle\Decoda\Hook\EmoticonHook; use FM\BbcodeBundle\Emoticon\Emoticon; use FM\BbcodeBundle\Emoticon\EmoticonCollection; -use FM\BbcodeBundle\Decoda\Hook\EmoticonHook; +use FM\BbcodeBundle\Emoticon\Loader\FileLoader; +use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\ContainerInterface; -class EmoticonHookTest extends \PHPUnit_Framework_TestCase +class EmoticonHookTest extends TestCase { - public function testConstructor() - { - $loader = $this->getMockBuilder('FM\\BbcodeBundle\\Emoticon\\Loader\\FileLoader') - ->disableOriginalConstructor() - ->getMockForAbstractClass() - ; - $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); - - $result = new EmoticonHook($loader, $container); - } - public function testGetMatcher() { $expectEmoticon = new Emoticon(); @@ -27,7 +19,7 @@ public function testGetMatcher() $expectCollection = new EmoticonCollection(); $expectCollection->add('foo', $expectEmoticon); - $loader = $this->getMockBuilder('FM\\BbcodeBundle\\Emoticon\\Loader\\FileLoader') + $loader = $this->getMockBuilder(FileLoader::class) ->disableOriginalConstructor() ->getMockForAbstractClass() ; @@ -36,7 +28,7 @@ public function testGetMatcher() ->will($this->returnValue($expectCollection)) ; - $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); + $container = $this->createMock(ContainerInterface::class); $result = new EmoticonHook($loader, $container, array('resource' => 'bar')); $collection = $result->getEmoticonCollection(); diff --git a/Tests/DependencyInjection/FMBbcodeExtensionTest.php b/Tests/DependencyInjection/FMBbcodeExtensionTest.php index e8b48fa..4f9b30b 100644 --- a/Tests/DependencyInjection/FMBbcodeExtensionTest.php +++ b/Tests/DependencyInjection/FMBbcodeExtensionTest.php @@ -10,8 +10,9 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use FM\BbcodeBundle\DependencyInjection\FMBbcodeExtension; use Symfony\Component\Yaml\Parser; +use PHPUnit\Framework\TestCase; -class FMBbcodeExtensionTest extends \PHPUnit_Framework_TestCase +class FMBbcodeExtensionTest extends TestCase { /** * @var \Symfony\Component\DependencyInjection\ContainerBuilder diff --git a/Tests/Emoticon/EmoticonCollectionTest.php b/Tests/Emoticon/EmoticonCollectionTest.php index d71cb7a..e1e8cbe 100644 --- a/Tests/Emoticon/EmoticonCollectionTest.php +++ b/Tests/Emoticon/EmoticonCollectionTest.php @@ -4,11 +4,12 @@ use FM\BbcodeBundle\Emoticon\Emoticon; use FM\BbcodeBundle\Emoticon\EmoticonCollection; +use PHPUnit\Framework\TestCase; /** * @author Alexandre Quercia */ -class EmoticonCollectionTest extends \PHPUnit_Framework_TestCase +class EmoticonCollectionTest extends TestCase { public function testAddOverriddenEmoticon() { diff --git a/Tests/Emoticon/Loader/PhpFileLoaderTest.php b/Tests/Emoticon/Loader/PhpFileLoaderTest.php index a3fa66e..dae6175 100644 --- a/Tests/Emoticon/Loader/PhpFileLoaderTest.php +++ b/Tests/Emoticon/Loader/PhpFileLoaderTest.php @@ -2,16 +2,17 @@ namespace FM\BbcodeBundle\Tests\Emoticon\Loader; -use Symfony\Component\Config\FileLocator; use FM\BbcodeBundle\Emoticon\Loader\PhpFileLoader; +use PHPUnit\Framework\TestCase; +use Symfony\Component\Config\FileLocator; /** * @author Alexandre Quercia */ -class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase +class PhpFileLoaderTest extends TestCase { /** - * @covers FM\BbcodeBundle\Emoticon\Loader\PhpFileLoader::supports + * @covers \FM\BbcodeBundle\Emoticon\Loader\PhpFileLoader::supports */ public function testSupports() { @@ -22,7 +23,7 @@ public function testSupports() } /** - * @covers FM\BbcodeBundle\Emoticon\Loader\PhpFileLoader::load + * @covers \FM\BbcodeBundle\Emoticon\Loader\PhpFileLoader::load */ public function testLoad() { @@ -36,7 +37,7 @@ public function testLoad() } /** - * @covers FM\BbcodeBundle\Emoticon\Loader\PhpFileLoader::load + * @covers \FM\BbcodeBundle\Emoticon\Loader\PhpFileLoader::load */ public function testLoadSupportImport() { diff --git a/Tests/FunctionalTestBundle/Resources/config/config.yml b/Tests/FunctionalTestBundle/Resources/config/config.yml index 9f2d55d..db6cb17 100644 --- a/Tests/FunctionalTestBundle/Resources/config/config.yml +++ b/Tests/FunctionalTestBundle/Resources/config/config.yml @@ -4,11 +4,14 @@ parameters: services: fm_bbcode.filter.bar: - class: %fm_bbcode.filter.bar.class% + class: '%fm_bbcode.filter.bar.class%' + public: true tags: - { name: fm_bbcode.decoda.filter, id: bar } + fm_bbcode.hook.bar: - class: %fm_bbcode.hook.bar.class% + class: '%fm_bbcode.hook.bar.class%' + public: true tags: - { name: fm_bbcode.decoda.hook, id: bar } @@ -20,9 +23,9 @@ fm_bbcode: - path: "@FunctionalTestBundle/Resources/views/templates" messages: "%kernel.root_dir%/FunctionalTestBundle/Resources/config/messages.json" filters: - - { classname: foo, class: %fm_bbcode.filter.bar.class% } + - { classname: foo, class: '%fm_bbcode.filter.bar.class%' } hooks: - - { classname: foo, class: %fm_bbcode.hook.bar.class% } + - { classname: foo, class: '%fm_bbcode.hook.bar.class%' } filter_sets: default_filter: locale: ru @@ -79,5 +82,5 @@ framework: session: ~ twig: - debug: %kernel.debug% - strict_variables: %kernel.debug% + debug: '%kernel.debug%' + strict_variables: '%kernel.debug%' diff --git a/Tests/FunctionalTestBundle/Resources/config/emoticons.yml b/Tests/FunctionalTestBundle/Resources/config/emoticons.yml index 95451ff..abbe02d 100644 --- a/Tests/FunctionalTestBundle/Resources/config/emoticons.yml +++ b/Tests/FunctionalTestBundle/Resources/config/emoticons.yml @@ -8,11 +8,11 @@ emoticons: smilies: - ":url_tester:" place_holder: - url: %fm_bbcode.emoticon.path%/foo.gif + url: '%fm_bbcode.emoticon.path%/foo.gif' smilies: - ":_lace_holder:" my_emoticon: - url: %fm_bbcode.emoticon.path%/my_emoticon.png + url: '%fm_bbcode.emoticon.path%/my_emoticon.png' html: '' xHtml: '' smilies: diff --git a/Tests/Templating/BbcodeExtensionTest.php b/Tests/Templating/BbcodeExtensionTest.php index be450bf..7fe6a22 100644 --- a/Tests/Templating/BbcodeExtensionTest.php +++ b/Tests/Templating/BbcodeExtensionTest.php @@ -65,8 +65,8 @@ public function testImgFilter($value, $expected) public function dataImgTags() { return array( - array('[img]http://github.com/picture.jpg[/img]', ''), - array('[img width="500"]http://github.com/picture.jpg[/img]', ''), + array('[img]http://github.com/picture.jpg[/img]', ''), + array('[img width="500"]http://github.com/picture.jpg[/img]', ''), ); } diff --git a/composer.json b/composer.json index 7872163..8af10ff 100644 --- a/composer.json +++ b/composer.json @@ -12,32 +12,26 @@ } ], "require": { - "php": ">=5.6", + "php": "^7.1.3", "mjohnson/decoda": "6.*", - "symfony/twig-bundle": "~3.0|~4.0", - "symfony/assetic-bundle": "~2.4|~4.0", - "symfony/config": "~3.0|~4.0", - "symfony/console": "~3.0|~4.0", - "symfony/dependency-injection": "~3.0|~4.0", - "symfony/framework-bundle": "~3.0|~4.0", - "symfony/http-foundation": "~3.0|~4.0", - "symfony/http-kernel": "~3.0|~4.0", - "symfony/process": "~3.0|~4.0", - "symfony/templating": "~3.0|~4.0", - "symfony/yaml": "~3.0|~4.0", - "sensio/distribution-bundle": "~5.0" + "symfony/twig-bundle": "~3.3|~4.0", + "symfony/config": "~3.3|~4.0", + "symfony/console": "~3.3|~4.0", + "symfony/dependency-injection": "~3.3|~4.0", + "symfony/framework-bundle": "~3.2|~4.0", + "symfony/http-foundation": "~3.2|~4.0", + "symfony/http-kernel": "~3.3|~4.0", + "symfony/process": "~3.3|~4.0", + "symfony/templating": "~3.3|~4.0", + "symfony/yaml": "~3.3|~4.0" }, "require-dev": { - "symfony/symfony": "~3.0|~4.0", - "satooshi/php-coveralls": "dev-master" + "symfony/symfony": "~3.3|~4.0", + "php-coveralls/php-coveralls": "~2.0", + "phpunit/phpunit": "~7.1" }, "autoload": { "psr-4": { "FM\\BbcodeBundle\\": "" } }, - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "6.x-dev" - } - } + "minimum-stability": "dev" }