Code Monkey home page Code Monkey logo

routing-auto-bundle's Introduction

This repository is no longer maintained

Due to lack of interest, we had to decide to discontinue this repository. The CMF project focusses on the Routing component and RoutingBundle, which are still in active use by other projects.

This repository will no longer be upgraded and marked as abandoned, but will be kept available for legacy projects or if somebody wants to experiment with the CMF.

You can contact us in the #symfony_cmf channel of the Symfony devs slack.

Symfony CMF Routing Auto Bundle

Latest Stable Version Latest Unstable Version License

Total Downloads Monthly Downloads Daily Downloads

Branch Travis Coveralls
master Build Status Coverage Status

This package is part of the Symfony Content Management Framework (CMF) and licensed under the MIT License.

This bundle automatically creates and manages routes for configured persisted document classes.

Requirements

  • PHP 7.1 / 7.2
  • Symfony 2.8 / 3.3 / 3.4 / 4.0
  • See also the require section of composer.json

Documentation

For the install guide and reference, see:

See also:

Support

For general support and questions, please use StackOverflow.

Contributing

Pull requests are welcome. Please see our CONTRIBUTING guide.

Unit and/or functional tests exist for this package. See the Testing documentation for a guide to running the tests.

Thanks to everyone who has contributed already.

License

This package is available under the MIT license.

routing-auto-bundle's People

Contributors

almacbe avatar amenophis avatar cordoval avatar damienflament avatar dantleech avatar dbu avatar eiannone avatar electricmaxxx avatar hacfi avatar lsmith77 avatar mmenozzi avatar petk avatar sroze avatar wouterj avatar xabbuh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

routing-auto-bundle's Issues

[Form] port prestacms url creation widget to cmf

It would be great to have the prestacms URL selection widget as a form type available in the cmf. having the logic for this in the backend and update the proposal on updating the title field would be great. then we could leverage the RoutingAutoBundle configuration to generate proposals.

http://sandbox.prestacms.com/admin/en/cms/page/edit?locale=en&website=%2Fwebsite%2Fsandbox&id=website%2Fsandbox%2Fmenu%2Fmain%2Fprojects

/cc @nicolas-bastien @dantleech

Remove ContentObject

Depending on other Auto-Routable objects in the route tree introduces difficult problems:

  • When saving we build the auto route for the mapped document, if we encounter a ContentObject provider, then we retrieve the route associated with this content object. But if we are on a translation which does not yet exist for the encountered content object then we would need to schedule this document to be reprocessed. Which is not trivial in the current implementation.

It would be easier, and simpler, to remove this object and force the user to construct a full URL from the current object. This will make the system more stable.

"strategy" option validation

PathProviders and PathActions are strategies, currently they accept arbitary options from the configurator, but will silently ignore any options which are not used.

There should perhaps be some code which enables the strategies to declare that options are used and if they are required or not.

Mappings should be inheritance aware

At the moment the mappings are explit where the target class for a mapping must match the exactly the persisted class. This should be changed to either match exactly or be a parent of the persisted class, as happens in other mapping scenarios.

If PHPCR not explicitly enabled, we get error

If the PHPCR persistence is not explicitly enabled as follows:

cmf_routing_auto:
    persistence:
        phpcr:
            enabled: true

We get the following error:

The service "cmf_routing_auto.adapter.phpcr_odm" has a dependency on a non-existent parameter "cmf_routing_auto.persistence.phpcr.route_basepath". Did you mean one of these:   
  "cmf_routing.dynamic.persistence.phpcr.route_basepaths", "cmf_routing.dynamic.persistence.phpcr.route_basepath", "cmf_routing.dynamic.persistence.phpcr.content_basepath"?

We should only load the PHPCR ODM adapter service if the PHPCR thing is enabled.

We can then throw a better error (e.g. choose a persistence strategy..)

RoutingAuto rules should be reusable

Currently it is necessary to redclare routing rules for each class.

I wonder if we shouldn't seperate schema and mapping?

e.g. currently I have the following:

        Acme\BasicCmsBundle\Document\Page:
            content_path:
                pages:
                    provider: [specified, { path: /cms/routes/page }]
                    exists_action: use
                    not_exists_action: create
            content_name:
                provider: [content_method, { method: getTitle }]
                exists_action: auto_increment
                not_exists_action: create

        Acme\BasicCmsBundle\Document\ContactPage:
            content_path:
                pages:
                    provider: [specified, { path: /cms/routes/page }]
                    exists_action: use
                    not_exists_action: create
            content_name:
                provider: [content_method, { method: getTitle }]
                exists_action: auto_increment
                not_exists_action: create

        Acme\BasicCmsBundle\Document\PostIndex:
            content_path:
                pages:
                    provider: [specified, { path: /cms/routes/page }]
                    exists_action: use
                    not_exists_action: create
            content_name:
                provider: [content_method, { method: getTitle }]
                exists_action: auto_increment
                not_exists_action: create

        Acme\BasicCmsBundle\Document\LatestBlogPost:
            content_path:
                pages:
                    provider: [specified, { path: /cms/routes/page }]
                    exists_action: use
                    not_exists_action: create
            content_name:
                provider: [content_method, { method: getTitle }]
                exists_action: auto_increment
                not_exists_action: create

Something like the following would be better:

    schemas:
        page_schema:
            content_path:
                pages:
                    provider: [specified, { path: /cms/routes/page }]
                    exists_action: use
                    not_exists_action: create
            content_name:
                provider: [content_method, { method: getTitle }]
                exists_action: auto_increment
                not_exists_action: create

    mappings:
        Acme\BasicCmsBundle\Document\Page: page_schema
        Acme\BasicCmsBundle\Document\ContactPage: page_schema
        Acme\BasicCmsBundle\Document\PostIndex: page_schema
        Acme\BasicCmsBundle\Document\LatestBlogPost: page_schema

Move AdapterInterface

All interfaces live in AutoRoute. I like that! But there is one exception: AdapterInterface lives in AutoRoute\Adapter. Let's move it to AutoRoute too

Review Exceptions

We should probably throw more specific Exceptions. The majority of Exceptions in this bundle are currently RuntimeException.

Update auto route code

Support updating routes

The current WIP does not support updating. I am adding this issue as the updating functionality did kind of exist in a previous version and there were some useful comments on that functionality:

0cb652e#L1R202

Refactor namespaces

The current namespacing isn't very logical and could be more organized.

  • AutoRoute/RouteStack namespace should probably be AutoRoute/Builder
  • RouteStack, AutoRouteStack (extends RouteStack) and BuilderContext should be grouped together in an NS, but then which one goes in the parent NS?
  • AutoRouteMaker and RoutePatcher\GenericPatcher are somewhat related, in that they both process RouteStack objects to create actual Routes.

Method to call Controllers and Templates based on class

The DynamicRouter has the possibility to call different controllers and template by class or type, but for AutoRouting it doesn't work because the Route Documents are all of the same type. This doesn't seem to be documented so i wonder if its possible at all.

Of course this could be done in other ways, i was just wondering if there is a way to do it like DynamicRouter intends to.

RedirectRoute does not Redirect

 Unable to find the controller for path "/page/home". Maybe you forgot to add the matching route in your routing configuration? 
home                   | nt:unstructured |                                                         |
|   jcr:primaryType    | NAME            | nt:unstructured                                         |
|   jcr:mixinTypes     | NAME            | [0] phpcr:managed                                       |
|                      |                 | [1] mix:referenceable                                   |
|   phpcr:class        | STRING          | Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Redi... |
|   phpcr:classparents | STRING          | [0] Symfony\Component\Routing\Route                     |
|                      |                 | [1] Symfony\Cmf\...                                     |
|   jcr:uuid           | STRING          | 6f6c2869-8188-4b4f-9ff8-70fe6b3bfed1                    |
|   host               | STRING          |                                                         |
|   defaults           | STRING          |                                                         |
|   requirements       | STRING          |                                                         |
|   options            | STRING          |                                                         |
|   addFormatPattern   | BOOLEAN         | false                                                   |
|   permanent          | BOOLEAN         | false                                                   |
|   parameters         | STRING          |                                                         |
|   addTrailingSlash   | BOOLEAN         | false                                                   |
|   routeTarget        | WEAKREFERENCE   | 24e66116-8643-492a-a555-2ed0a43af187                    |

Support MultiLingual routes

According to the AutoRouteMaker, the beginning has been made.

// If the document is translated, filter locales
if (null !== $locale) {
    throw new \Exception(
        'Translations not yet supported for Auto Routes - '.
        'Should be easy.'
    );

    // array_filter($referrers, function ($referrer) use ($dm, $uow, $locale) {
    //     $metadata = $dm->getClassMetadata($refferer);
    //     if ($locale == $uow->getLocaleFor($referrer, $referrer)) {
    //         return true;
    //     }

    //     return false;
    // });
}

Refactor to use URL schema

Had a long think about routing auto today, and it occurred to me that we could make it alot simpler:

cmf_routing_auto:
    mappings:
        Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Article:
            url_schema: /test/auto-route/%blog_name%/posts/%article_name%
            providers:
                blog_name:
                        provider: [ content_method, { method_name: "getBlogName" } ]
                        exists_action: use
                        not_exists_action: create
                article_name:
                        provider: [ content_method, { method_name: "getTitle" } ]
                        exists_action: use
                        not_exists_action: create

This has the following advantages:

  • Its a lot less verbose, alot easier to understand
  • It would be easier to do provide a web interface (to allow people to modify URL mappings at runtime) for this than with the current schema
  • There is no distinction between "content_name" and "content_path" stacks.

composer install problem

$ require symfony-cmf/routing-auto-bundle
symfony-cmf/routing-auto-bundle 1.0.x-dev requires symfony-cmf/routing-bundle 1.2.x-dev -> no matching package found.

there is no 1.2.x branch in routing bundle, but 1.2 exists. Dependency should probably be 1.2-dev

Specify action on content rename

Allow actions to be specified when an autoroute is renamed. e.g.

  • leave_redirect: When changing the name of post "This post title" to "That post title" a redirect should be created at /path/this-post-title to /path/that-post-title.
  • remove_headless When changing the name of post "This post title" to "That post title" the "headless" routes leading up to the old auto route should be deleted.

These options would probably best be placed in the "content_name" section of the configuration:

            content_name:
                # ...
                on_rename: 
                    - [ 'remove_orphans' ]
                    - [ 'leave_redirect', {'option_1': 'foo'} ]

Allow use of content_change strategy in non-building context

Allow the on_content_change strategy to be applied to route classes for which the RoutingAuto bundle doesn't build the routes automatically.

  • Allow specification of HEAD route (content_name route).
  • Ensure that we can not enable the "building" logic.

Remove composer.json doctrine-commons dev-master alias

I had "unresolvable" conflicts without aliasing doctrine/common. Find out why this was necessary, and remove the alias:

    "require-dev": {
        "symfony/class-loader": ">=2.1,<2.3-dev",
        "doctrine/doctrine-bundle": "1.*",
        "jackalope/jackalope-doctrine-dbal": "1.0.*",
        "symfony/yaml": ">=2.1,<2.3-dev",
        "symfony/form": ">=2.1,<2.3-dev",
        "symfony/finder": ">=2.1,<2.3-dev",
        "doctrine/phpcr-odm": "1.0.*",
        "doctrine/phpcr-bundle": "1.0.*",
        "doctrine/common": "dev-master as 2.3.x-dev"
    },

AutoRoute isn't being mapped properly as of RoutingBundle Model change

Original problem was that the identifier wasn't being mapped on AutoRoute (which extends Doctrine\Phpcr\Route in RoutingBundle).

If I changed the AutoRoute to a Route I get the following:

Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Functional\Subscriber\AutoRouteListenerTest::testUpdatePost
Doctrine\Common\Persistence\Mapping\MappingException: The class 'Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\
Route' was not found in the chain configured namespaces Symfony\Cmf\Component\Testing\Document, Symfony\Cmf\Bundl
e\RoutingAutoBundle\Tests\Resources\Document, Doctrine\ODM\PHPCR\Document, Symfony\Cmf\Bundle\RoutingAutoBundle\D
ocument

Any ideas? @dbu ?

More than one auto route for document

Hi,

I recently created and closed the PR #74. But the issue is still present. The issue appears when changing the value for a translatable field which is also used for building automatic paths using ContentMethodProvider in RoutingAutoBundle. Whenever I change this field in Sonata Admin and hit the Update-button, the following exception appears:

More than one auto route for document

This can be fixed by changing some lines in class AutoRouteMaker and method getAutoRouteForDocument:

protected function getAutoRouteForDocument($document)
{
    if (!$this->documentIsPersisted($document)) {
        return null;
    }

    $dm = $this->dm;
    $uow = $dm->getUnitOfWork();

    $referrers = $this->dm->getReferrers($document);

    if ($referrers->count() == 0) {
        return null;
    }

    // Filter non auto-routes
    $referrers = $referrers->filter(function ($referrer) {
        if ($referrer instanceof AutoRoute) {
            return true;
        }

        return false;
    });

    $metadata = $dm->getClassMetadata(get_class($document));

    $currentLocale = $uow->getCurrentLocale($document);

    // If the document is translated, filter locales
    if (null !== $currentLocale) {
        $referrers = $referrers->filter(function ($referrer) use ($dm, $uow, $currentLocale) {
            $defaults = $referrer->getDefaults();
            if ($currentLocale == $defaults['_locale']) {
                return true;
            }

            return false;
        });
    }

    if ($referrers->count() > 1) {
        throw new \RuntimeException(sprintf(
            'More than one auto route for document "%s"',
            get_class($document)
        ));
    }

    return $referrers->current();
}

This change results in routes being filtered out where locales != currentLocale.

Can anyone figure out whether I am doing something wrong or is it a bug?

Route Basepath is ignored

I have setup AutoRouting Bundle according to: http://symfony.com/doc/master/cmf/cookbook/creating_a_cms/auto-routing.html

cmf_routing:
    chain:
        routers_by_id:
            cmf_routing.dynamic_router: 20
            router.default: 100
    dynamic:
        enabled: true
        persistence:
            phpcr:
                route_basepath: /cms/routes

cmf_routing_auto:
    mappings:
        Kuoni\BackendBundle\Document\Page:
            content_path:
                # corresponds first path unit in diagram: my-forum
                language_path:
                    provider: [specified, { path: de }]
                    exists_action: use
                    not_exists_action: create
            content_name:
                provider: [content_method, { method: getTitle }]
                exists_action: [auto_increment, { pattern: -%d }]
                not_exists_action: create

but routes don't get created in '/cms/routes' but in the root, while content gets created correctly.

php app/console doctrine:phpcr:node:dump
ROOT:
  cms:
    content:
      dies-ist-ein-test:
        47cd75c30ef5c4cd852af128884de82d:
        a36071bc40a5da292057fb4ad2dc322e:
      gsdf-gsdfg-sdfgdsfg-sdfg:
        849d0ed89ed714fefc45f8a01d5c6074:
        9cedc225c02d4fcb3ac1026ddd113665:
    routes:
    taxonomy:
    media:
      image:
  de:
    dies-ist-ein-test:
    gsdf-gsdfg-sdfgdsfg-sdfg:

I feel this could have something todo with this issue i created for the DoctrinePhpCrBundle doctrine/DoctrinePHPCRBundle#119 (something related to the GenericInitializer class which gets the basepath as an argument)

Package Versions

symfony-cmf/content-bundle           dev-master 61d6ed1 Symfony CMF Content Bundle
symfony-cmf/core-bundle              1.0.1              Symfony CMF Core Bundle
symfony-cmf/media-bundle             dev-master d6ad6df Symfony CMF Media Bundle
symfony-cmf/menu-bundle              dev-master 22e4b71 Symfony CMF Menu Bundle
symfony-cmf/routing                  dev-master 8071fae Extends the Symfony2 routing component for dynamic routes and chaining several routers
symfony-cmf/routing-auto-bundle      dev-master c3b3a60 Bundle which automatically creates and manages routes for persisted objects
symfony-cmf/routing-bundle           dev-master dce6ad8 Symfony RoutingBundle
doctrine/phpcr-bundle                dev-master 63047af Symfony DoctrinePHPCRBundle
doctrine/phpcr-odm                   dev-master 1fea541 Object-Document-Mapper for PHPCR
phpcr/phpcr                          2.1.0              PHP Content Repository interfaces
phpcr/phpcr-utils                    1.1.0              PHP Content Repository implementation independant utilities

AutoRoutes automatic update on document change

The documentation (http://symfony.com/doc/current/cmf/cookbook/creating_a_cms/auto-routing.html) says "The routes (URLs) to your content will be automatically created and updated using the RoutingAutoBundle." but it does not seem to work in a reliable way.

My documents have a slug field which is defined as part of the route:
https://gist.github.com/awdng/300c5dd11827e0636c0d

When i update the slug field on the document, the route does not change. For some strange reason it sometimes seems to change on the first change but not on later changes after that.

Config:
https://gist.github.com/awdng/7c87095d3fb5c01f568a

Any idea what could be wrong ?

symfony-cmf/core-bundle              1.0.x-dev 6e4aef2  Symfony CMF Core Bundle
symfony-cmf/media-bundle             dev-master fcd08bc Symfony CMF Media Bundle
symfony-cmf/menu-bundle              1.0.x-dev befdef8  Symfony CMF Menu Bundle
symfony-cmf/routing                  1.1.x-dev a70ba68  Extends the Symfony2 routing component for dynamic routes and chaining several routers
symfony-cmf/routing-auto-bundle      1.0.0-alpha10      Bundle which automatically creates and manages routes for persisted objects

Update existing AutoRoutes

I changed the layout of my routes from this

cmf_routing_auto:
    mappings:
        Kuoni\BackendBundle\Document\Page\Page:
            content_path:
                base_path:
                    provider: [specified, { path: /cms/routes }]
                    exists_action: use
                    not_exists_action: create
                language_path:
                    provider: [specified, { path: de }]
                    exists_action: use
                    not_exists_action: create
                sub_content_path:
                    provider: [content_method, { method: getType }]
                    exists_action: use
                    not_exists_action: create
            content_name:
                provider: [content_method, { method: getTitle }]
                exists_action: [auto_increment, { pattern: -%d }]
                not_exists_action: create

to

cmf_routing_auto:
    mappings:
        Kuoni\BackendBundle\Document\Page\Page:
            content_path:
                base_path:
                    provider: [specified, { path: /cms/routes }]
                    exists_action: use
                    not_exists_action: create
                language_path:
                    provider: [specified, { path: de }]
                    exists_action: use
                    not_exists_action: create
            content_name:
                provider: [content_method, { method: getTitle }]
                exists_action: [auto_increment, { pattern: -%d }]
                not_exists_action: create

I built a symfony command to remove the route documents, but when i remove the routes the application breaks and routes are not regenerated (which is expected behavior i guess).

So i read that updating the Documents will trigger an update to the Routes, and while the AutoRouteListener is executed when updating a field of the document (like the title/name) the route does not get updated.

What am i missing ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.