Skip to content

Commit

Permalink
Symfony5 (#379)
Browse files Browse the repository at this point in the history
Symfony 5 Compatibility
  • Loading branch information
helios-ag authored Jan 12, 2020
1 parent cd377c6 commit 4fcf580
Show file tree
Hide file tree
Showing 50 changed files with 885 additions and 968 deletions.
35 changes: 10 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,24 @@ cache:
- $HOME/.composer/cache
- $HOME/symfony-bridge/.phpunit

env:
global:
- COMPOSER_PREFER_LOWEST=false
- SYMFONY_DEPRECATIONS_HELPER=weak_vendors
- SYMFONY_PHPUNIT_BRIDGE_VERSION=4.0.*
- SYMFONY_VERSION=3.4.*
- PHPUNIT_FLAGS="-v"
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
matrix:
fast_finish: true
include:
- php: 7.2
env: SYMFONY_VERSION=4.1.* SYMFONY_PHPUNIT_BRIDGE_VERSION=4.1.* SYMFONY_DEPRECATIONS_HELPER=weak_vendors LEVEL=0
- php: 7.3
env: SYMFONY_VERSION=4.1.* SYMFONY_PHPUNIT_BRIDGE_VERSION=4.1.* SYMFONY_DEPRECATIONS_HELPER=weak_vendors LEVEL=0
- php: 7.1
env: SYMFONY_VERSION=4.2.* SYMFONY_PHPUNIT_BRIDGE_VERSION=4.2.* SYMFONY_DEPRECATIONS_HELPER=weak_vendors LEVEL=0
- php: 7.2
env: SYMFONY_VERSION=4.2.* SYMFONY_PHPUNIT_BRIDGE_VERSION=4.2.* SYMFONY_DEPRECATIONS_HELPER=weak_vendors LEVEL=0
- php: 7.3
env: SYMFONY_VERSION=4.2.* SYMFONY_PHPUNIT_BRIDGE_VERSION=4.2.* SYMFONY_DEPRECATIONS_HELPER=weak_vendors LEVEL=0
- php: 7.2
env: SYMFONY_VERSION="^4.4.0"
- php: 7.3
env: SYMFONY_VERSION="^5.0.0"

before_install:
- echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- echo "memory_limit=4G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- phpenv config-rm xdebug.ini || true
- composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-master
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update "symfony/framework-bundle:${SYMFONY_VERSION}"; fi;

install:
- composer require --no-update symfony/symfony:${SYMFONY_VERSION}
- composer require --no-update symfony/form:${SYMFONY_VERSION}
- composer require --dev --no-update symfony/phpunit-bridge:${SYMFONY_PHPUNIT_BRIDGE_VERSION}
- composer update --prefer-source `if [[ $COMPOSER_PREFER_LOWEST = true ]]; then echo "--prefer-lowest --prefer-stable"; fi`
install: php -d memory_limit=-1 $(phpenv which composer) update $COMPOSER_FLAGS --no-suggest

script:
- SYMFONY_PHPUNIT_VERSION=6.5 ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
- ./vendor/bin/phpunit --coverage-text --colors

notifications:
email: [email protected]
Expand Down
35 changes: 6 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,22 @@ For Symfony Flex installation you need to enable community recipes:
composer config extra.symfony.allow-contrib true
```

And install
Install

```sh
composer require helios-ag/fm-elfinder-bundle
```

Other way (non flex way) is to add FMElFinderBundle to your composer.json

```json
{
"require": {
"helios-ag/fm-elfinder-bundle": "~9",
}
}
```

also add **component-dir** under **config** node of composer.json

(also you can manually copy assets to this directory)

```json
{
"config": {
"component-dir": "public/assets"
}
}
```

Now tell composer to download the bundle by running the command:

Copy elfinder assets to public folder

```sh
composer update helios-ag/fm-elfinder-bundle
bin/console elfinder:install
```

### Step 2: Enable the bundle

Enable the bundle in the kernel:
### Step 2: Enable the bundle (Optional)

Enable the bundle in the kernel (not needed with symfony flex):

```php
<?php
Expand Down Expand Up @@ -169,7 +147,6 @@ fm_elfinder:
#attributes: example of setting attributes permission
# - { pattern: '/(.*?)/', read: true, write: false, locked: true }
```
* **assets_path** - this is where css/js files of the bundle are, this options should be the same as composers `component-dir` option.
* **default** - instance of elfinder, can be used to define multiple configurations of ElFinder, allows simultaneous configuration for different types of WYSIWYG editors in your project
* **path** - define root directory for the files inside web/ directory, default is "uploads". Make sure to set proper write/read and owner permissions to this directory.
* **url** - url to be prefixed to image path, for displaying. Can be either `absolute` or `relative`. If absolute, you can use `{homeFolder}` string as placeholder which will be replaced automatically. If relative, it will be prefixed with the applications base-url. If left blank, url will be the base-url, append with the value of the 'path' parameter
Expand Down
28 changes: 14 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
"exclude": ["/tests", "./github"]
},
"require": {
"php": "^5.6|^7.0",
"symfony/framework-bundle": "~2.8|~3.0|~4.0",
"symfony/twig-bundle": "~2.8|~3.0|~4.0",
"symfony/form": "~2.8|~3.0|~4.0",
"symfony/asset": "~2.8|~3.0|~4.0",
"components/elfinder": "~3",
"studio-42/elfinder": "~2.1",
"robloach/component-installer": "~0.2"
"php": "^7.2",
"ext-json": "*",
"symfony/framework-bundle": "^4.4 || ^5.0",
"symfony/twig-bundle": "^4.4 || ^5.0",
"symfony/form": "^4.4 || ^5.0",
"symfony/asset": "^4.4 || ^5.0",
"studio-42/elfinder": "~2.1"
},
"require-dev" : {
"symfony/phpunit-bridge": "^4.0",
"matthiasnoback/symfony-config-test": "^3.0",
"matthiasnoback/symfony-dependency-injection-test": "^2",
"symfony/finder": "~3.0|~4.0",
"satooshi/php-coveralls": "~2"
"symfony/phpunit-bridge": "^4.1 || ^5.0",
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"symfony/finder": "^4.4 || ^5.0",
"php-coveralls/php-coveralls": "^2.0",
"phpunit/phpunit": "^8.5"
},
"suggest": {
"helios-ag/fm-tinymce-bundle": "FMTinyMCEBundle WYSIWYG Editor Bundle",
Expand All @@ -51,7 +51,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "9.0-dev"
"dev-master": "10.0-dev"
}
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</listeners>

<testsuites>
<testsuite name="FMRFMBundle test suite">
<testsuite name="FMElfinderBundle test suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
Expand Down
8 changes: 0 additions & 8 deletions src/Bridge/ElFinderBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@
use FM\ElfinderBundle\ElFinder\ElFinder;
use elFinderVolumeDriver;

/**
* Class ElFinderBridge.
*/
class ElFinderBridge extends ElFinder
{
/** @var SessionInterface */
protected $session;

/**
* ElFinderBridge constructor.
*
* @param $opts
*/
public function __construct($opts)
{
if ($this->session) {
Expand Down
56 changes: 56 additions & 0 deletions src/Command/ElFinderInstallerCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace FM\ElfinderBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Filesystem\Filesystem;

final class ElFinderInstallerCommand extends Command
{
private const ELFINDER_CSS_DIR = 'vendor/studio-42/elfinder/css';

private const ELFINDER_JS_DIR = 'vendor/studio-42/elfinder/js';

private const ELFINDER_SOUNDS_DIR = 'vendor/studio-42/elfinder/sounds';

private const ELFINDER_IMG_DIR = 'vendor/studio-42/elfinder/img';

protected static $defaultName = 'elfinder:install';

protected $fileSystem;

protected $parameterBag;

public function __construct(Filesystem $filesystem, ParameterBagInterface $parameterBag)
{
$this->fileSystem = $filesystem;
$this->parameterBag = $parameterBag;
parent::__construct();
}

protected function configure(): void
{
$this
->setDescription('Copies elfinder assets to public directory')
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$publicDir = $this->parameterBag->get('kernel.project_dir').'/public/bundles/fmelfinder';

$this->fileSystem->mirror(self::ELFINDER_CSS_DIR, $publicDir.'/css');
$this->fileSystem->mirror(self::ELFINDER_IMG_DIR, $publicDir.'/img');
$this->fileSystem->mirror(self::ELFINDER_JS_DIR, $publicDir.'/js');
$this->fileSystem->mirror(self::ELFINDER_SOUNDS_DIR, $publicDir.'/sounds');

$output->writeln('elFinder assets successfully installed');

return 0;
}
}
13 changes: 13 additions & 0 deletions src/Configuration/ElFinderConfigurationProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace FM\ElfinderBundle\Configuration;

/**
* Interface ElFinderConfigurationProviderInterface.
*/
interface ElFinderConfigurationProviderInterface
{
public function getConfiguration(string $instance): array;
}
60 changes: 11 additions & 49 deletions src/Configuration/ElFinderConfigurationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace FM\ElfinderBundle\Configuration;

use FM\ElfinderBundle\Model\ElFinderConfigurationProviderInterface;
use FM\ElfinderBundle\Security\ElfinderSecurityInterface;
use League\Flysystem\AdapterInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -32,46 +31,26 @@
*/
class ElFinderConfigurationReader implements ElFinderConfigurationProviderInterface
{
/**
* @var array
*/
protected $options = array();
/** @var array */
protected $options = [];

/**
* @var array
*/
/** @var array */
protected $parameters;

/**
* @var RequestStack
*/
/** @var RequestStack */
protected $requestStack;

/**
* @var ContainerInterface
*/
/** @var ContainerInterface */
protected $container;

/**
* @param $parameters
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* @param ContainerInterface $container
*/
public function __construct($parameters, RequestStack $requestStack, ContainerInterface $container)
public function __construct(array $parameters, RequestStack $requestStack, ContainerInterface $container)
{
$this->parameters = $parameters;
$this->requestStack = $requestStack;
$this->container = $container;
}

/**
* @param $instance
*
* @return array
*
* @throws \Exception
*/
public function getConfiguration($instance)
public function getConfiguration(string $instance): array
{
$request = $this->requestStack->getCurrentRequest();
$efParameters = $this->parameters;
Expand Down Expand Up @@ -166,15 +145,7 @@ public function getConfiguration($instance)
return $options;
}

/**
* @param $parameter
* @param $request
* @param $homeFolder
* @param $path
*
* @return string
*/
private function getURL($parameter, Request $request, $homeFolder, $path)
private function getURL(array $parameter, Request $request, string $homeFolder, string $path): string
{
if (isset($parameter['url']) && $parameter['url']) {
if (0 === strpos($parameter['url'], 'http')) {
Expand All @@ -195,8 +166,6 @@ private function getURL($parameter, Request $request, $homeFolder, $path)
* @param $serviceName
*
* @return Filesystem
*
* @throws \MongoConnectionException
*/
private function configureFlysystem($opt, $adapter, $serviceName)
{
Expand Down Expand Up @@ -316,7 +285,7 @@ private function configureFlysystem($opt, $adapter, $serviceName)
return $filesystem;
}

private function getFlysystemFilesystem($serviceName)
private function getFlysystemFilesystem(string $serviceName)
{
$filesystem = $this->container->get($serviceName);
if (!is_object($filesystem) || (!$filesystem instanceof Filesystem)) {
Expand All @@ -326,14 +295,9 @@ private function getFlysystemFilesystem($serviceName)
return $filesystem;
}

/**
* @param array $parameter
*
* @return array
*/
private function configureDriver(array $parameter)
private function configureDriver(array $parameter): array
{
$settings = array();
$settings = [];

switch (strtolower($parameter['driver'])) {
case 'ftp':
Expand Down Expand Up @@ -428,8 +392,6 @@ public function access($attr, $path, $data, $volume)
* @param ElfinderSecurityInterface $voter
*
* @return array
*
* @throws \Exception
*/
protected function parseSecurityConfiguration(ElfinderSecurityInterface $voter)
{
Expand Down
3 changes: 0 additions & 3 deletions src/Connector/ElFinderConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use elFinder;

/**
* Class ElFinderConnector.
*/
class ElFinderConnector extends \elFinderConnector
{
public function run($queryParameters = null)
Expand Down
Loading

0 comments on commit 4fcf580

Please sign in to comment.