Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tried to make the bundle SF4 compatible #147

Open
wants to merge 6 commits into
base: 4.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.idea
composer.lock
Tests/cache
Tests/log
clover.xml

/.idea/
/var/
/vendor/
/Tests/cache
/Tests/log
9 changes: 2 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.1.3
- 7.2.0

sudo: false

Expand All @@ -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.*"
Expand Down
14 changes: 0 additions & 14 deletions CHANGELOG.md

This file was deleted.

20 changes: 9 additions & 11 deletions Command/DumpEmoticonsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -49,15 +49,13 @@ private function recurseCopy($src, $dst)
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
* @return int|null|void
* @param InputInterface $input
* @param OutputInterface $output
*/
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);
Expand All @@ -68,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if (!file_exists($emoticonsFolder) && !is_dir($emoticonsFolder)) {
return $output->writeln('<error>Emoticons folder does not exist</error>');
$output->writeln('<error>Emoticons folder does not exist</error>');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return is expected here in order to stop the task execution here as the source folder does not exists.

Copy link
Author

@ghost ghost Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value inside execute should return something useful or nothing at all. Returning the output of $output->writeln() is not related to your command (in fact it doesn't even return anything).

However, I'll add it again (below $output->writeln()) it since it is indeed required for proper execution.

}

$this->recurseCopy($emoticonsFolder, $webFolder);
Expand Down
3 changes: 2 additions & 1 deletion DependencyInjection/Compiler/RegisterFiltersPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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));
}
Expand Down
5 changes: 4 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->scalarNode('public_path')->defaultValue('%kernel.project_dir%/public')->end()
->end()
->end();

Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions DependencyInjection/FMBbcodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
60 changes: 44 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
Expand All @@ -73,15 +80,32 @@ public function registerBundles()
);
}
```

For Symfony4, you'll need to enable the bundle in your `bundles.php`-file:
``` php
// config/bundles.php

return [
// ...
FM\BbcodeBundle\FMBbcodeBundle::class => ['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:
Expand Down Expand Up @@ -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"
Expand All @@ -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%
```
4 changes: 2 additions & 2 deletions Resources/config/bbcode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
<argument type="service" id="fm_bbcode.decoda_manager"/>
</service>

<service id="fm_bbcode.templating.helper" class="%fm_bbcode.templating.helper.class%">
<service id="fm_bbcode.templating.helper" class="%fm_bbcode.templating.helper.class%" public="true">
<tag name="templating.helper" alias="bbcode" />
<argument type="service" id="fm_bbcode.decoda_manager"/>
</service>

<service id="fm_bbcode.decoda_manager" class="FM\BbcodeBundle\Decoda\DecodaManager">
<service id="fm_bbcode.decoda_manager" class="FM\BbcodeBundle\Decoda\DecodaManager" public="true">
<argument type="service" id="service_container"/>
<argument type="service" id="file_locator" />
<argument type="collection">
Expand Down
22 changes: 11 additions & 11 deletions Resources/config/filters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@
</parameters>

<services>
<service id="fm_bbcode.decoda.filter.block" class="%fm_bbcode.decoda.filter.block.class%">
<service id="fm_bbcode.decoda.filter.block" class="%fm_bbcode.decoda.filter.block.class%" public="true">
<tag name="fm_bbcode.decoda.filter" id="block" />
</service>
<service id="fm_bbcode.decoda.filter.code" class="%fm_bbcode.decoda.filter.code.class%">
<service id="fm_bbcode.decoda.filter.code" class="%fm_bbcode.decoda.filter.code.class%" public="true">
<tag name="fm_bbcode.decoda.filter" id="code" />
</service>
<service id="fm_bbcode.decoda.filter.email" class="%fm_bbcode.decoda.filter.email.class%">
<service id="fm_bbcode.decoda.filter.email" class="%fm_bbcode.decoda.filter.email.class%" public="true">
<tag name="fm_bbcode.decoda.filter" id="email" />
</service>
<service id="fm_bbcode.decoda.filter.image" class="%fm_bbcode.decoda.filter.image.class%">
<service id="fm_bbcode.decoda.filter.image" class="%fm_bbcode.decoda.filter.image.class%" public="true">
<tag name="fm_bbcode.decoda.filter" id="image" />
</service>
<service id="fm_bbcode.decoda.filter.list" class="%fm_bbcode.decoda.filter.list.class%">
<service id="fm_bbcode.decoda.filter.list" class="%fm_bbcode.decoda.filter.list.class%" public="true">
<tag name="fm_bbcode.decoda.filter" id="list" />
</service>
<service id="fm_bbcode.decoda.filter.quote" class="%fm_bbcode.decoda.filter.quote.class%">
<service id="fm_bbcode.decoda.filter.quote" class="%fm_bbcode.decoda.filter.quote.class%" public="true">
<tag name="fm_bbcode.decoda.filter" id="quote" />
</service>
<service id="fm_bbcode.decoda.filter.text" class="%fm_bbcode.decoda.filter.text.class%">
<service id="fm_bbcode.decoda.filter.text" class="%fm_bbcode.decoda.filter.text.class%" public="true">
<tag name="fm_bbcode.decoda.filter" id="text" />
</service>
<service id="fm_bbcode.decoda.filter.url" class="%fm_bbcode.decoda.filter.url.class%">
<service id="fm_bbcode.decoda.filter.url" class="%fm_bbcode.decoda.filter.url.class%" public="true">
<tag name="fm_bbcode.decoda.filter" id="url" />
</service>
<service id="fm_bbcode.decoda.filter.default" class="%fm_bbcode.decoda.filter.default.class%">
<service id="fm_bbcode.decoda.filter.default" class="%fm_bbcode.decoda.filter.default.class%" public="true">
<tag name="fm_bbcode.decoda.filter" id="default" />
</service>
<service id="fm_bbcode.decoda.filter.video" class="%fm_bbcode.decoda.filter.video.class%">
<service id="fm_bbcode.decoda.filter.video" class="%fm_bbcode.decoda.filter.video.class%" public="true">
<tag name="fm_bbcode.decoda.filter" id="video" />
</service>
<service id="fm_bbcode.decoda.filter.table" class="%fm_bbcode.decoda.filter.table.class%">
<service id="fm_bbcode.decoda.filter.table" class="%fm_bbcode.decoda.filter.table.class%" public="true">
<tag name="fm_bbcode.decoda.filter" id="table" />
</service>
</services>
Expand Down
8 changes: 5 additions & 3 deletions Tests/Command/DumpEmoticonsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
class DumpEmoticonsCommandTest extends \PHPUnit_Framework_TestCase
class DumpEmoticonsCommandTest extends TestCase
{
private $rootDir;
private $webDir;
Expand Down Expand Up @@ -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;
Expand Down
Loading