diff --git a/.travis.yml b/.travis.yml index e36781b6..84d8ff7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,6 @@ matrix: - php: 5.6 env: SYMFONY_VERSION=3.0.* allow_failures: - - env: SYMFONY_VERSION=2.8.* - env: SYMFONY_VERSION=3.0.* fast_finish: true diff --git a/Admin/Extension/RouteReferrersExtension.php b/Admin/Extension/RouteReferrersExtension.php index a3f7cb82..c279c322 100644 --- a/Admin/Extension/RouteReferrersExtension.php +++ b/Admin/Extension/RouteReferrersExtension.php @@ -13,6 +13,7 @@ use Sonata\AdminBundle\Admin\AdminExtension; use Sonata\AdminBundle\Form\FormMapper; +use Symfony\Cmf\Bundle\RoutingBundle\Util\Sf2CompatUtil; /** * Admin extension to add routes tab to content implementing the @@ -30,7 +31,7 @@ public function configureFormFields(FormMapper $formMapper) )) ->add( 'routes', - 'sonata_type_collection', + Sf2CompatUtil::getFormTypeName('sonata_type_collection'), array(), array( 'edit' => 'inline', diff --git a/Admin/RedirectRouteAdmin.php b/Admin/RedirectRouteAdmin.php index 43fe1b35..76230411 100644 --- a/Admin/RedirectRouteAdmin.php +++ b/Admin/RedirectRouteAdmin.php @@ -16,6 +16,7 @@ use Sonata\AdminBundle\Form\FormMapper; use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; use Symfony\Cmf\Bundle\RoutingBundle\Model\Route; +use Symfony\Cmf\Bundle\RoutingBundle\Util\Sf2CompatUtil; class RedirectRouteAdmin extends Admin { @@ -37,17 +38,13 @@ protected function configureListFields(ListMapper $listMapper) protected function configureFormFields(FormMapper $formMapper) { - $isSf28 = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix'); - $textType = $isSf28 ? 'Symfony\Component\Form\Extension\Core\Type\TextType' : 'text'; - $doctrineTreeType = $isSf28 ? 'Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType' : 'doctrine_phpcr_odm_tree'; - $formMapper ->with('form.group_general') - ->add('parent', $doctrineTreeType, array('choice_list' => array(), 'select_root_node' => true, 'root_node' => $this->routeRoot)) - ->add('name', $textType) - ->add('routeName', $textType, array('required' => false)) - ->add('uri', $textType, array('required' => false)) - ->add('routeTarget', $doctrineTreeType, array('choice_list' => array(), 'required' => false, 'root_node' => $this->routeRoot)) + ->add('parent', Sf2CompatUtil::getFormTypeName('doctrine_phpcr_odm_tree'), array('choice_list' => array(), 'select_root_node' => true, 'root_node' => $this->routeRoot)) + ->add('name', Sf2CompatUtil::getFormTypeName('text')) + ->add('routeName', Sf2CompatUtil::getFormTypeName('text'), array('required' => false)) + ->add('uri', Sf2CompatUtil::getFormTypeName('text'), array('required' => false)) + ->add('routeTarget', Sf2CompatUtil::getFormTypeName('doctrine_phpcr_odm_tree'), array('choice_list' => array(), 'required' => false, 'root_node' => $this->routeRoot)) ->end() ; } diff --git a/Admin/RouteAdmin.php b/Admin/RouteAdmin.php index 08e3f16f..aa386c12 100644 --- a/Admin/RouteAdmin.php +++ b/Admin/RouteAdmin.php @@ -17,6 +17,7 @@ use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Cmf\Bundle\RoutingBundle\Model\Route; +use Symfony\Cmf\Bundle\RoutingBundle\Util\Sf2CompatUtil; use PHPCR\Util\PathHelper; class RouteAdmin extends Admin @@ -60,21 +61,16 @@ protected function configureListFields(ListMapper $listMapper) protected function configureFormFields(FormMapper $formMapper) { - $isSf28 = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix'); - $textType = $isSf28 ? 'Symfony\Component\Form\Extension\Core\Type\TextType' : 'text'; - $doctrineTreeType = $isSf28 ? 'Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType' : 'doctrine_phpcr_odm_tree'; - $sonataImmutableType = $isSf28 ? 'Sonata\CoreBundle\Form\Type\ImmutableArrayType' : 'sonata_type_immutable_array'; - $formMapper ->with('form.group_general', array( 'translation_domain' => 'CmfRoutingBundle', )) ->add( 'parent', - $doctrineTreeType, + Sf2CompatUtil::getFormTypeName('doctrine_phpcr_odm_tree'), array('choice_list' => array(), 'select_root_node' => true, 'root_node' => $this->routeRoot) ) - ->add('name', $textType) + ->add('name', Sf2CompatUtil::getFormTypeName('text')) ->end(); if (null === $this->getParentFieldDescription()) { @@ -82,20 +78,20 @@ protected function configureFormFields(FormMapper $formMapper) ->with('form.group_general', array( 'translation_domain' => 'CmfRoutingBundle', )) - ->add('content', $doctrineTreeType, array('choice_list' => array(), 'required' => false, 'root_node' => $this->contentRoot)) + ->add('content', Sf2CompatUtil::getFormTypeName('doctrine_phpcr_odm_tree'), array('choice_list' => array(), 'required' => false, 'root_node' => $this->contentRoot)) ->end() ->with('form.group_advanced', array( 'translation_domain' => 'CmfRoutingBundle', )) - ->add('variablePattern', $textType, array('required' => false), array('help' => 'form.help_variable_pattern')) + ->add('variablePattern', Sf2CompatUtil::getFormTypeName('text'), array('required' => false), array('help' => 'form.help_variable_pattern')) ->add( 'defaults', - $sonataImmutableType, + Sf2CompatUtil::getFormTypeName('sonata_type_immutable_array'), array('keys' => $this->configureFieldsForDefaults($this->getSubject()->getDefaults())) ) ->add( 'options', - $sonataImmutableType, + Sf2CompatUtil::getFormTypeName('sonata_type_immutable_array'), array('keys' => $this->configureFieldsForOptions($this->getSubject()->getOptions())), array('help' => 'form.help_options') ) @@ -146,13 +142,10 @@ public function getExportFormats() */ protected function configureFieldsForDefaults($dynamicDefaults) { - $isSf28 = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix'); - $textType = $isSf28 ? 'Symfony\Component\Form\Extension\Core\Type\TextType' : 'text'; - $defaults = array( - '_controller' => array('_controller', $textType, array('required' => false)), - '_template' => array('_template', $textType, array('required' => false)), - 'type' => array('type', $isSf28 ? 'Symfony\Cmf\Bundle\RoutingBundle\Form\Type\RouteTypeType' : 'cmf_routing_route_type', array( + '_controller' => array('_controller', Sf2CompatUtil::getFormTypeName('text'), array('required' => false)), + '_template' => array('_template', Sf2CompatUtil::getFormTypeName('text'), array('required' => false)), + 'type' => array('type', Sf2CompatUtil::getFormTypeName('cmf_routing_route_type'), array( 'empty_value' => '', 'required' => false, )), @@ -160,7 +153,7 @@ protected function configureFieldsForDefaults($dynamicDefaults) foreach ($dynamicDefaults as $name => $value) { if (!isset($defaults[$name])) { - $defaults[$name] = array($name, $textType, array('required' => false)); + $defaults[$name] = array($name, Sf2CompatUtil::getFormTypeName('text'), array('required' => false)); } } @@ -172,16 +165,16 @@ protected function configureFieldsForDefaults($dynamicDefaults) foreach ($matches as $match) { $name = substr($match[0][0], 1, -1); if (!isset($defaults[$name])) { - $defaults[$name] = array($name, $textType, array('required' => true)); + $defaults[$name] = array($name, Sf2CompatUtil::getFormTypeName('text'), array('required' => true)); } } } if ($route && $route->getOption('add_format_pattern')) { - $defaults['_format'] = array('_format', $textType, array('required' => true)); + $defaults['_format'] = array('_format', Sf2CompatUtil::getFormTypeName('text'), array('required' => true)); } if ($route && $route->getOption('add_locale_pattern')) { - $defaults['_locale'] = array('_format', $textType, array('required' => false)); + $defaults['_locale'] = array('_format', Sf2CompatUtil::getFormTypeName('text'), array('required' => false)); } return $defaults; diff --git a/Controller/RedirectController.php b/Controller/RedirectController.php index 595bb440..7a172efc 100644 --- a/Controller/RedirectController.php +++ b/Controller/RedirectController.php @@ -12,6 +12,7 @@ namespace Symfony\Cmf\Bundle\RoutingBundle\Controller; use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Cmf\Component\Routing\RedirectRouteInterface; @@ -53,10 +54,10 @@ public function redirectAction(RedirectRouteInterface $contentDocument) if (empty($url)) { $routeTarget = $contentDocument->getRouteTarget(); if ($routeTarget) { - $url = $this->router->generate($routeTarget, $contentDocument->getParameters(), true); + $url = $this->router->generate($routeTarget, $contentDocument->getParameters(), UrlGeneratorInterface::ABSOLUTE_URL); } else { $routeName = $contentDocument->getRouteName(); - $url = $this->router->generate($routeName, $contentDocument->getParameters(), true); + $url = $this->router->generate($routeName, $contentDocument->getParameters(), UrlGeneratorInterface::ABSOLUTE_URL); } } diff --git a/Form/Type/RouteTypeType.php b/Form/Type/RouteTypeType.php index fd689b93..3566c1c8 100644 --- a/Form/Type/RouteTypeType.php +++ b/Form/Type/RouteTypeType.php @@ -14,6 +14,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Cmf\Bundle\RoutingBundle\Util\Sf2CompatUtil; class RouteTypeType extends AbstractType { diff --git a/Tests/Functional/Routing/DynamicRouterTest.php b/Tests/Functional/Routing/DynamicRouterTest.php index a2b44a03..24c7c051 100644 --- a/Tests/Functional/Routing/DynamicRouterTest.php +++ b/Tests/Functional/Routing/DynamicRouterTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Cmf\Component\Routing\ChainRouter; use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route; use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute; use Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter; @@ -347,7 +348,7 @@ public function testGenerate() public function testGenerateAbsolute() { $route = $this->getDm()->find(null, self::ROUTE_ROOT.'/testroute/child'); - $url = $this->router->generate($route, array('test' => 'value'), true); + $url = $this->router->generate($route, array('test' => 'value'), UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('http://localhost/testroute/child?test=value', $url); } diff --git a/Util/Sf2CompatUtil.php b/Util/Sf2CompatUtil.php new file mode 100644 index 00000000..5133c0cb --- /dev/null +++ b/Util/Sf2CompatUtil.php @@ -0,0 +1,51 @@ + 'Symfony\Component\Form\Extension\Core\Type\TextType', + 'doctrine_phpcr_odm_tree' => 'Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType', + 'sonata_type_immutable_array' => 'Sonata\CoreBundle\Form\Type\ImmutableArrayType', + 'sonata_type_collection' => 'Sonata\CoreBundle\Form\Type\CollectionType', + 'cmf_routing_route_type' => 'Symfony\Cmf\Bundle\RoutingBundle\Form\Type\RouteTypeType', + ); + + public static function registerFormType($name, $fqcn) + { + self::$formTypes[$name] = $fqcn; + } + + public static function getFormTypeName($name) + { + if (!self::isAtLeastSymfony28()) { + return $name; + } + + if (!isset(self::$formTypes[$name])) { + throw new \InvalidArgumentException(sprintf('Unknown form type "%s", please register the FQCN of this form type to the Sf2CompatUtil first.', $name)); + } + + return self::$formTypes[$name]; + } + + public static function isAtLeastSymfony28() + { + if (null === self::$isAtLeastSymfony28) { + self::$isAtLeastSymfony28 = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix'); + } + + return self::$isAtLeastSymfony28; + } +} diff --git a/composer.json b/composer.json index ac37e99c..55f428a9 100644 --- a/composer.json +++ b/composer.json @@ -23,9 +23,9 @@ "symfony-cmf/testing": "~1.2,>=1.2.7", "doctrine/phpcr-odm": "~1.3", "matthiasnoback/symfony-dependency-injection-test": "~0.6", - "matthiasnoback/symfony-config-test": "0.*", + "matthiasnoback/symfony-config-test": "^1.3.1", "phpunit/php-code-coverage": "@stable", - "sonata-project/doctrine-phpcr-admin-bundle": "~1.1", + "sonata-project/doctrine-phpcr-admin-bundle": "^1.1|^2.0", "symfony/monolog-bundle": "~2.3", "doctrine/orm": "~2.3", "doctrine/data-fixtures": "1.*,>=1.0.0-alpha3"