Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Add support for Symfony 4 (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectricMaxxx authored and greg0ire committed Jan 22, 2019
1 parent 03b0395 commit b0b731d
Show file tree
Hide file tree
Showing 43 changed files with 465 additions and 373 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -4,4 +4,4 @@
.php_cs.cache
composer.lock
phpunit.xml
tests/Resources/app/var
tests/Fixtures/App/var
10 changes: 10 additions & 0 deletions .travis/before_script_test.local.sh
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -ev

TESTING_SCRIPTS_DIR=vendor/symfony-cmf/testing/bin
CONSOLE=${TESTING_SCRIPTS_DIR}/console

export KERNEL_CLASS="Sonata\\DoctrinePHPCRAdminBundle\\Tests\\Fixtures\\App\\Kernel"
echo '+++ create PHPCR +++'
${CONSOLE} doctrine:phpcr:init:dbal --drop --force -vvv
${CONSOLE} doctrine:phpcr:repository:init -vvv
4 changes: 2 additions & 2 deletions .travis/before_script_test.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -ev

if [ -f before_script_test.local.sh ]
if [ -f .travis/before_script_test.local.sh ]
then
./before_script_test.local.sh
./.travis/before_script_test.local.sh
fi
2 changes: 2 additions & 0 deletions UPGRADE-3.0.md
@@ -0,0 +1,2 @@
UPGRADE FROM 2.x to 3.0
=======================
23 changes: 13 additions & 10 deletions composer.json
Expand Up @@ -23,19 +23,20 @@
"require": {
"php": "^7.1",
"doctrine/phpcr-bundle": "^1.3 || ^2.0",
"doctrine/phpcr-odm": "^1.4 || ^2.0",
"doctrine/phpcr-odm": "^1.4.2 || ^2.0",
"sonata-project/admin-bundle": "^3.30.1",
"sonata-project/block-bundle": "^3.11",
"symfony-cmf/resource-rest-bundle": "^1.0.1",
"symfony-cmf/tree-browser-bundle": "^2.0",
"symfony/config": "^2.8 || ^3.2",
"symfony/dependency-injection": "^2.8 || ^3.2",
"symfony/form": "^2.8.8 || ^3.2",
"symfony/framework-bundle": "^2.8.8 || ^3.2",
"symfony/http-foundation": "^2.8 || ^3.2",
"symfony/http-kernel": "^2.8 || ^3.2",
"symfony/options-resolver": "^2.8 || ^3.2",
"symfony/property-access": "^2.8 || ^3.2"
"symfony/config": "^2.8 || ^3.2 || ^4.0",
"symfony/dependency-injection": "^2.8 || ^3.2 || ^4.0",
"symfony/finder": "^2.8 || ^3.2 || ^4.0",
"symfony/form": "^2.8.8 || ^3.2 || ^4.0",
"symfony/framework-bundle": "^2.8.18 || ^3.2.5 || ^4.0",
"symfony/http-foundation": "^2.8 || ^3.2 || ^4.0",
"symfony/http-kernel": "^2.8 || ^3.2 || ^4.0",
"symfony/options-resolver": "^2.8 || ^3.2 || ^4.0",
"symfony/property-access": "^2.8 || ^3.2 || ^4.0"
},
"provide": {
"sonata-project/admin-bundle-persistency-layer": "1.0.0"
Expand All @@ -46,12 +47,14 @@
"matthiasnoback/symfony-dependency-injection-test": "^3.1",
"phpcr/phpcr": "^2.1",
"phpcr/phpcr-utils": "^1.4.0",
"sebastian/environment": "^1.3.4",
"sebastian/exporter": "^2.0",
"sonata-project/core-bundle": "^3.8",
"symfony-cmf/resource": "^1.0",
"symfony-cmf/resource-bundle": "^1.0",
"symfony-cmf/testing": "^2.1.11",
"symfony/phpunit-bridge": "^4.2",
"symfony/routing": "^2.8 || ^3.2",
"symfony/routing": "^2.8 || ^3.2 || ^4.0",
"symfony/security-acl": "^2.8 || ^3.0"
},
"config": {
Expand Down
70 changes: 38 additions & 32 deletions docs/reference/document_tree.rst
Expand Up @@ -14,11 +14,11 @@ You need to load two additional bundles to use the tree::
{
public function registerBundles()
{
$bundles = array(
$bundles = [
// ...
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
new Symfony\Cmf\Bundle\TreeBrowserBundle\CmfTreeBrowserBundle(),
);
];

// ...
}
Expand Down Expand Up @@ -128,26 +128,26 @@ content:
.. code-block:: php
// app/config/config.php
$container->loadFromExtension('sonata_block', array(
'blocks' => array(
$container->loadFromExtension('sonata_block', [
'blocks' => [
// ...
'sonata_admin_doctrine_phpcr.tree_block' => array(
'settings' => array(
'sonata_admin_doctrine_phpcr.tree_block' => [
'settings' => [
'id' => '/cms',
),
'contexts' => array('admin'),
),
),
));
$container->loadFromExtension('sonata_admin', array(
'dashboard' => array(
'blocks' => array(
array('position' => 'left', 'type' => 'sonata_admin_doctrine_phpcr.tree_block'),
array('position' => 'right', 'type' => 'sonata.admin.block.admin_list'),
),
),
));
],
'contexts' => ['admin'],
],
],
]);
$container->loadFromExtension('sonata_admin', [
'dashboard' => [
'blocks' => [
['position' => 'left', 'type' => 'sonata_admin_doctrine_phpcr.tree_block'],
['position' => 'right', 'type' => 'sonata.admin.block.admin_list'],
],
],
]);
Configuring the tree
--------------------
Expand Down Expand Up @@ -194,13 +194,13 @@ This configuration is global for all your document trees.
.. code-block:: php
// app/config/config.php
$container->loadFromExtension('sonata_doctrine_phpcr_admin', array(
'document_tree' => array(
'routing_defaults' => array('locale'),
$container->loadFromExtension('sonata_doctrine_phpcr_admin', [
'document_tree' => [
'routing_defaults' => ['locale'],
'repository_name' => 'default',
'sortable_by' => 'position',
),
));
],
]);
.. tip::

Expand All @@ -220,7 +220,7 @@ like this:
.. code-block:: jinja
{% render(controller(
'sonata.admin.doctrine_phpcr.tree_controller:treeAction',
'sonata.admin.doctrine_phpcr.tree_controller::treeAction',
{
'root': basePath ~ "/menu",
'selected': menuNodeId,
Expand All @@ -230,15 +230,21 @@ like this:
.. code-block:: php
<?php echo $view['actions']->render(new ControllerReference(
'sonata.admin.doctrine_phpcr.tree_controller:treeAction',
array(
echo $view['actions']->render(new ControllerReference(
'sonata.admin.doctrine_phpcr.tree_controller::treeAction',
[
'root' => $basePath . '/menu',
'selected' => $menuNodeId,
'_locale' => $app->getRequest()->getLocale()
),
)) ?>
'_locale' => $app->getRequest()->getLocale(),
],
));
.. note::

To use the configuration for Symfony < 3.4 you should use the single colon (:) notation to define controller
actions: ``sonata.admin.doctrine_phpcr.tree_controller:treeAction`` – `jsTree`_

.. _`CmfTreeBrowserBundle`: http://symfony.com/doc/master/cmf/bundles/tree_browser/introduction.html
.. _`cmf-sandbox configuration`: https://github.com/symfony-cmf/cmf-sandbox/blob/master/app/config/config.yml
.. _`jsTree`: http://www.jstree.com/documentation
.. _`Symfony documentation`: https://symfony.com/doc/3.1/controller/service.html#referring-to-the-service
16 changes: 8 additions & 8 deletions docs/reference/filter_field_definition.rst
Expand Up @@ -54,7 +54,7 @@ Example
$datagrid
->add('title')
->add('enabled')
->add('tags', null, array(), null, array('expanded' => true, 'multiple' => true))
->add('tags', null, [], null, ['expanded' => true, 'multiple' => true])
;
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ You can customize the label which appears on the main widget by using a ``label`
{
$datagrid
// ..
->add('tags', null, array('label' => 'les tags'), null, array('expanded' => true, 'multiple' => true))
->add('tags', null, ['label' => 'les tags'], null, ['expanded' => true, 'multiple' => true])
// ..
;
}
Expand Down Expand Up @@ -144,10 +144,10 @@ implement this functionality.
$datagridMapper
->add('title')
->add('enabled')
->add('tags', null, array(), null, array('expanded' => true, 'multiple' => true))
->add('tags', null, [], null, ['expanded' => true, 'multiple' => true])
->add('author')
->add('with_open_comments', 'doctrine_phpcr_callback', array(
// 'callback' => array($this, 'getWithOpenCommentFilter'),
->add('with_open_comments', 'doctrine_phpcr_callback', [
// 'callback' => [$this, 'getWithOpenCommentFilter'],
'callback' => function($queryBuilder, $alias, $field, $data) {
if (!$data || !is_array($data) || !array_key_exists('value', $data)) {
return;
Expand All @@ -161,7 +161,7 @@ implement this functionality.
return true;
},
'field_type' => 'checkbox'
))
])
;
}
Expand Down Expand Up @@ -202,8 +202,8 @@ To make the filter case insensitive, use the ``compare_case_insensitive`` option
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('title', 'doctrine_phpcr_string', array('compare_case_insensitive' => true))
->add('author', 'doctrine_phpcr_string', array('compare_case_insensitive' => true))
->add('title', 'doctrine_phpcr_string', ['compare_case_insensitive' => true])
->add('author', 'doctrine_phpcr_string', ['compare_case_insensitive' => true])
->add('label', 'doctrine_phpcr_string')
;
}
Expand Down
9 changes: 4 additions & 5 deletions docs/reference/form_field_definition.rst
Expand Up @@ -23,11 +23,10 @@ you can use the corresponding option in the form field definition:
{
$formMapper
->with('General')
->add('enabled', null, array('required' => false))
->add('author', 'sonata_type_model_list', array(
), array(
'placeholder' => 'No author selected'
))
->add('enabled', null, ['required' => false])
->add('author', 'sonata_type_model_list', [], [
'placeholder' => 'No author selected',
])
;
}
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/installation.rst
Expand Up @@ -33,15 +33,15 @@ Next, be sure to enable the bundle in your AppKernel.php file:
// app/AppKernel.php
public function registerBundles()
{
return array(
return [
// ...
// set up basic doctrine phpcr-odm requirements
// set up basic sonata requirements
// ...
new Symfony\Cmf\Bundle\TreeBrowserBundle\CmfTreeBrowserBundle(),
new Sonata\DoctrinePHPCRAdminBundle\SonataDoctrinePHPCRAdminBundle(),
// ...
);
];
}
.. note::
Expand Down
26 changes: 8 additions & 18 deletions phpunit.xml.dist
Expand Up @@ -10,20 +10,10 @@
stopOnFailure="false"
bootstrap="vendor/symfony-cmf/testing/bootstrap/bootstrap.php"
>
<php>
<server name="KERNEL_DIR" value="tests/Resources/app" />
<ini name="precision" value="8"/>
</php>

<testsuites>
<testsuite name="SonataDoctrinePHPCRAdminBundle Unit Test Suite">
<testsuite name="SonataDoctrinePHPCRAdminBundle Test Suite">
<directory>./tests/Unit</directory>
</testsuite>

<!-- SonataDoctrinePHPCRAdminBundle Integration Test Suite – The name has to be "phpcr" to trigger db listener.-->
<testsuite name="phpcr">
<directory>./tests/WebTest</directory>
<directory>./Tests</directory>
</testsuite>
</testsuites>

Expand All @@ -33,16 +23,16 @@
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
<directory>./Resources</directory>
<directory>./DependencyInjection</directory>
<file>./SonataDoctrinePHPCRAdminBundle.php</file>
<directory>./src/Resources</directory>
<directory>./src/DependencyInjection</directory>
<file>./src/SonataDoctrinePHPCRAdminBundle.php</file>
<directory>./coverage/</directory>
</exclude>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Cmf\Component\Testing\Phpunit\DatabaseTestListener" />
</listeners>
<php>
<ini name="precision" value="8"/>
<env name="KERNEL_CLASS" value="Sonata\DoctrinePHPCRAdminBundle\Tests\Fixtures\App\Kernel" />
</php>

</phpunit>
2 changes: 1 addition & 1 deletion src/Admin/Admin.php
Expand Up @@ -94,7 +94,7 @@ public function getSubject()
{
if (null === $this->subject && $this->request) {
$id = $this->request->get($this->getIdParameter());
if (!preg_match('#^[0-9A-Za-z/\-_]+$#', $id)) {
if (null === $id || !preg_match('#^[0-9A-Za-z/\-_]+$#', $id)) {
$this->subject = false;
} else {
if (!UUIDHelper::isUUID($id)) {
Expand Down
8 changes: 3 additions & 5 deletions src/Block/TreeBlockService.php
Expand Up @@ -14,25 +14,23 @@
namespace Sonata\DoctrinePHPCRAdminBundle\Block;

use Sonata\AdminBundle\Form\FormMapper;
use Sonata\BlockBundle\Block\BaseBlockService;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Model\BlockInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

class TreeBlockService extends BaseBlockService
class TreeBlockService extends AbstractBlockService
{
/**
* @var array
*/
protected $defaults;

/**
* @param string $name
* @param EngineInterface $templating
* @param array $defaults
* @param string $name
*/
public function __construct($name, EngineInterface $templating, array $defaults = [])
{
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/FormContractor.php
Expand Up @@ -175,7 +175,7 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
protected function getAssociationAdminException(FieldDescriptionInterface $fieldDescription)
{
$msg = sprintf('The current field `%s` is not linked to an admin. Please create one', $fieldDescription->getName());
if (\in_array($fieldDescription->getMappingType(), [ClassMetadata::MANY_TO_ONE, ClassMetadata::MANY_TO_MANY, 'referrers'])) {
if (\in_array($fieldDescription->getMappingType(), [ClassMetadata::MANY_TO_ONE, ClassMetadata::MANY_TO_MANY, 'referrers'], true)) {
if ($fieldDescription->getTargetEntity()) {
$msg .= " for the target document: `{$fieldDescription->getTargetEntity()}`";
}
Expand Down
5 changes: 3 additions & 2 deletions src/Builder/ListBuilder.php
Expand Up @@ -19,6 +19,7 @@
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Builder\ListBuilderInterface;
use Sonata\AdminBundle\Guesser\TypeGuesserInterface;
use Symfony\Component\Form\Guess\TypeGuess;

class ListBuilder implements ListBuilderInterface
{
Expand Down Expand Up @@ -57,7 +58,7 @@ public function buildField($type, FieldDescriptionInterface $fieldDescription, A
{
if (null == $type) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
$fieldDescription->setType($guessType->getType());
$fieldDescription->setType($guessType instanceof TypeGuess ? $guessType->getType() : null);
} else {
$fieldDescription->setType($type);
}
Expand Down Expand Up @@ -190,7 +191,7 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter

if ($metadata
&& $metadata->hasAssociation($fieldDescription->getName())
&& \in_array($fieldDescription->getMappingType(), $mappingTypes)
&& \in_array($fieldDescription->getMappingType(), $mappingTypes, true)
) {
$admin->attachAdminClass($fieldDescription);
}
Expand Down

0 comments on commit b0b731d

Please sign in to comment.