Feature #8736

Implement generic Identity RoutePartHandler

Added by Bastian Waidelich about 11 years ago. Updated almost 10 years ago.

Status:
Resolved
Priority:
Should have
Category:
MVC - Routing
Start date:
Due date:
% Done:

100%

Estimated time:
PHP Version:
Has patch:
Complexity:

Description

We should provide a generic RoutePart handler, that allows to match/resolve Identities. This should be configurable through the "options" setting that was implemented with #2825.
Instead of

  uriPattern:    'posts/{post}'
  defaults:
    '@package':    Blog
    '@controller': Post
    '@action':     show
  routeParts:
    post:
      handler: F3\Blog\RoutePartHandlers\PostRoutePartHandler

I could imagine something like
  uriPattern:    'posts/{post}'
  defaults:
    '@package':    Blog
    '@controller': Post
    '@action':     show
  routeParts:
    post:
      handler: IdentityRoutePartHandler
      options:
        model: F3\Blog\Domain\Model\Post
        pattern: '{date}/{title}'

Then you wouldn't need a custom RoutePart handler anymore most cases..

Note1: the namespace of the handler can be omitted when it is in the FLOW3 package
Note2: the line "handler: IdentityRoutePartHandler" could be implicit for domain models
Note3: how to handle the date format here? should we somehow support regular expressions in the pattern?


Related issues

Related to TYPO3.Flow - Feature #29972: Configurable RedirectsUnder ReviewTim Kandel2011-09-18

Actions
Has duplicate TYPO3.Flow - Feature #26688: Magic Object RoutesClosedBastian Waidelich2011-05-06

Actions
#1

Updated by Bastian Waidelich about 11 years ago

  • Due date deleted (2009-03-16)
  • Start date deleted (2009-03-12)
  • % Done changed from 100 to 0
  • Estimated time changed from 2.00 h to 4.00 h
#2

Updated by Bastian Waidelich about 11 years ago

  • Status changed from New to Needs Feedback

One more addition:
According to "Convention over Configuration" the above example could be

  uriPattern:    'posts/{post}'
  defaults:
    '@package':    Blog
    '@controller': Post
    '@action':     show
  routeParts:
    post:
      options:
        pattern: '{date}/{title}'

-> By default FLOW3s IdentityRoutePart would be used for the domain model. And - if not specified - the model would be @package\Domain\Model\ and uppercase RoutePart-getName(). Would that work?
IMO even the routParts configuration could be ommited - then all @identity properties would be used to build the Uri segments..

What do you think?

#3

Updated by Bastian Waidelich about 11 years ago

  • Subject changed from Routing: Implement generic Identity RoutePartHandler to Implement generic Identity RoutePartHandler
  • Category changed from MVC to MVC - Routing
#4

Updated by Karsten Dambekalns about 11 years ago

I like the concept. As for date formatting, this needs to be configurable. Since the handler could find out about the types of the properties used, it could look for type-specific information in the pattern. E.g. like this:

uriPattern:    'posts/{post}'
defaults:
  '@package':    Blog
  '@controller': Post
  '@action':     show
routeParts:
  post:
    options:
      pattern: '{date format:Y-m-d}/{title}'

Then it could use format as needed.

#5

Updated by Bastian Waidelich about 11 years ago

Karsten Dambekalns wrote:

As for date formatting, this needs to be configurable.

Yes, but I'm unhappy about yet another syntax

{date format:Y-m-d}

Why hasn't the DateTime object more getters.. Then one could write
pattern: '{date.year}-{date.month}-{date.day}/{title}'

And this is not the only case where this was useful..
Maybe we can use our own DateTime implementation in FLOW3!?

#6

Updated by Karsten Dambekalns about 11 years ago

Bastian Waidelich wrote:

Yes, but I'm unhappy about yet another syntax
[...]
Why hasn't the DateTime object more getters.. Then one could write

So, in the pattern one could use the object path syntax as in Fluid. Nice idea.

Maybe we can use our own DateTime implementation in FLOW3!?

Yeah, one more reason to have one...

#7

Updated by Bastian Waidelich over 10 years ago

  • Status changed from Needs Feedback to Accepted
  • Target version set to 1.0 beta 1
  • % Done changed from 0 to 30
  • Estimated time deleted (4.00 h)

Note: One reason that prevented me from implementing this, was the missing "transliteration" feature of the I18n sub package, that would be needed to convert special characters (e.g. "รค" -> "ae").
As transliteration will most probably not make it into FLOW3 1.0, we'll have to find another (temporary) solution anyways.
Maybe we can make use of some built-in Doctrine functionality here (for example the sluggable behavior: http://www.doctrine-project.org/documentation/manual/1_0/en/behaviors:core-behaviors:sluggable -> https://github.com/l3pp4rd/DoctrineExtensions/tree/doctrine2.0.x/lib/Gedmo/Sluggable)

#8

Updated by Karsten Dambekalns over 10 years ago

Bastian Waidelich wrote:

As transliteration will most probably not make it into FLOW3 1.0, we'll have to find another (temporary) solution anyways.

Why not? The basics are all there, even in TYPO3 (v4).

Maybe we can make use of some built-in Doctrine functionality here (for example the sluggable behavior: http://www.doctrine-project.org/documentation/manual/1_0/en/behaviors:core-behaviors:sluggable -> https://github.com/l3pp4rd/DoctrineExtensions/tree/doctrine2.0.x/lib/Gedmo/Sluggable)

Oh, well, looks interesting, why not mix and match the best from our and their code. Either way, having this in I18n by 1.0 should be no problem. Even it's some kind of "workaround", I'd put it there. We should discuss your needs and just do it.

#9

Updated by Sebastian Kurfuerst about 10 years ago

  • Target version changed from 1.0 beta 1 to 1.0 beta 2
#10

Updated by Robert Lemke about 10 years ago

  • Target version changed from 1.0 beta 2 to 1.0.0
#11

Updated by Mr. Hudson almost 10 years ago

  • Status changed from Accepted to Under Review

Patch set 1 of change I8fb5d4f4be3649e2f6307f83af2f3bbaa2191b5b has been pushed to the review server.
It is available at http://review.typo3.org/5076

#12

Updated by Bastian Waidelich almost 10 years ago

FYI: The current implementation supports following syntax:

-
  name: 'Single Post Actions'
  uriPattern:    'posts/{post}(/{@action})'
  defaults:
    '@package':    'TYPO3.Blog'
    '@controller': 'Post'
    '@action':     'show'
    '@format':     'html'
  routeParts:
    post:
      objectType: TYPO3\Blog\Domain\Model\Post

By default the @identity property/ies of the specified object type are used to create the URI section, or - if they're not specified - the technical identifier (UUID) of the respective object.
Alternatively a custom URI pattern can be specified:

-
  name: 'Single Post Actions'
  uriPattern:    'posts/{post}(/{@action})'
  defaults:
    '@package':    'TYPO3.Blog'
    '@controller': 'Post'
    '@action':     'show'
    '@format':     'html'
  routeParts:
    post:
      objectType: TYPO3\Blog\Domain\Model\Post
      uriPattern: '{date:Y}/{date:m}/{date:d}/{title}'

#13

Updated by Mr. Hudson almost 10 years ago

Patch set 2 of change I8fb5d4f4be3649e2f6307f83af2f3bbaa2191b5b has been pushed to the review server.
It is available at http://review.typo3.org/5076

#14

Updated by Mr. Hudson almost 10 years ago

Patch set 3 of change I8fb5d4f4be3649e2f6307f83af2f3bbaa2191b5b has been pushed to the review server.
It is available at http://review.typo3.org/5076

#15

Updated by Mr. Hudson almost 10 years ago

Patch set 4 of change I8fb5d4f4be3649e2f6307f83af2f3bbaa2191b5b has been pushed to the review server.
It is available at http://review.typo3.org/5076

#16

Updated by Karsten Dambekalns almost 10 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 30 to 100

Also available in: Atom PDF