Download the PHP package webfactory/object-routing without Composer

On this page you can find all versions of the php package webfactory/object-routing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package object-routing

Object Routing Library

This library allows to create routes based on objects. This can help reduce repetitive code patterns when the same parameters are read from an object every time a route is used, and also opens up new possibilities through the support of polymorphism.

This repository is a fork of jms/object-routing, and the original documentation is at http://jmsyst.com/libs/object-routing.

The library is not tied to any concrete router implementation. It ships with an adapter for Symfony's router.

Installation

Install this library through composer as webfactory/object-routing.

For Symfony projects, additionally install webfactory/object-routing-bundle.

Usage

The preferred and recommended way to declare object routes is through PHP attributes, although PHP, XML and YAML drivers are also available. See the original library's documentation on how to use those.

The 1.x version of this library supports configuration through annotations. Annotation support has been removed in the 2.0 release.

This declares an object route named view. A corresponding Symfony controller might look like this:

You use the object router to generate the URL or path of a given type for a given object. The type will be used to pick the right object route for the object's class, and the object route's name in turn determines the name of the route that will finally be used.

params declared in an object route will be evaluated as Symfony PropertyAccess expressions on the given object, and the resulting values will be passed on to the underlying router.

You can also use a configuration setting named paramExpressions for expression language support; see the section below.

extraParams can be given to the object router, and those will be passed-on to the underlying router as-is.

This example shows that when you need to read data from the object and pass it to the router, using the object router results in more concise expressions that can hide this detail, avoiding repetitions.

Twig support

For Twig, this library also provides two new functions:

Polymorphism support

Object routes of a given type can be defined differently in different classes.

For example, you could have a "conference website" application that displays details about schedule items, but the routes used to display "workshop" or "talk" detail pages differ.

In this example, you could use the same Twig expression object_path('detail', schedule_item) to generate the right route for the schedule_item depending on whether it is a Talk or a Workshop, and the appropriate parameters (either the id or the slug) would be passed automatically as well.

Expression Language support

In an #[ObjectRoute] declaration, you can also use the paramExpressions key to use Symfony Expression Language expressions.

The expression gets access to two variables: this is the object that the route is generated on, and params gives access to all extraParams passed to the object router and the values that have been read from the object through property path expressions.

The keys of extraParams indicate the parameter name. Prefixing the key with ? means that the value should not be set if the expression evaluates to null.

The motivating use case it that you might have a BlogPost object that can be archived. When you link to such a blog post, you need to include the post's year in an extra URL parameter: ?year=.....

This is not possible with Property Access paths alone, but can be done with Expression language support:

In this case, when the BlogPost::isArchived() method returns true, the value returned from BlogPost::getYear() will be included in the year parameter for the route. When it returns false, the year parameter is omitted.

License

The code is released under the Apache2 license.

Documentation is subject to the Attribution-NonCommercial-NoDerivs 3.0 Unported license.


All versions of object-routing with dependencies

PHP Build Version
Package Version
Requires php Version >= 8.1
jms/metadata Version ^2.6.1
symfony/expression-language Version ^6.4 || ^7.3 || ^8.0
symfony/property-access Version ^6.4 || ^7.3 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package webfactory/object-routing contains the following files

Loading the files please wait ...