Download the PHP package nercury/object-router without Composer

On this page you can find all versions of the php package nercury/object-router. 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-router


Overview

Allows to create and manage friendly routes for objects. Provides a way to manage redirects to routes. Features unique slug generator.

Installation

Recommended instalation is over Composer.

Configuration and usage

For upgrading to 1.2, please read upgrade notes.

To set up a route to some object (i.e. a product), set up an event listener:

<service id="my_product.object_route_listener" class="%my_product.object_route_listener.class%">
    <tag name="kernel.event_listener" event="object_router.get_response" method="onRouteResponseGetEvent" />
    <!-- setters -->
</service>

Depending on your requirements, you can return response immediatelly (for example, a redirect response, not found response, etc.) or you can forward the route to your controller. An example for a forwarding service would look like this:

use Nercury\ObjectRouterBundle\Event\ObjectRouteEvent;

/**
 * Returns a response based on object route slug
 */
class ObjectRouteListener {

    /**
     * @var \Symfony\Bundle\FrameworkBundle\HttpKernel
     */
    private $kernel;

    public function setKernel($kernel) {
        $this->kernel = $kernel;
    }

    public function onRouteResponseGetEvent(ObjectRouteEvent $event) {
        // if the object type is "product", handle it the specified way
        if ($event->getObjectType() == 'product') {
            $options = $event->parameters->all();
            $options['productId'] = $event->getObjectId();
            $event->setResponse($this->kernel->forward('MyProductBundle:Product:view', $options));
        }
    }

}

The string "product" is understood as object type which should be routed to specified action.

To use the default object route controller to send previously mentioned event,
add this at the end of routing.yml:

NercuryObjectRouterBundle:
resource: "@ObjectRouterBundle/Controller/"
type:     annotation
prefix:   /

It defines the last route rule as object route:

/{slug}

It redirects the {page} parameter to the actual controller and action which receives:

'id' => $resolved_object_id,

To assign a route slug to some object, use:

$this->get('object_router.routing')->setSlug('product', $id, $locale, 'test-route');

Url should be routed to the product action when accessing the page over:

/test-route

You can get url of the product by calling:

$this->get('object_router.routing')->generateUrl('product', $id); // get url in current locale

Localle can be specified as an additional parameter:

$this->get('object_router.routing')->generateUrl('product', $id, $locale);

Pagination

Additionally, paging route is also defined:

/{slug}/page-{page}

It redirects the {page} parameter to the actual controller and action which receives:

'id'  => $resolved_object_id,
'page' => $page,

To get an url with a page, use:

$this->get('object_router.routing')->generateUrlWithPage('product', $id, $page);

Custom action

Custom actions can be easily used instead of the provided two. More documentation in doc/custom_action.rst.

Redirects

To create a redirect to an object:

$this->get('object_router.redirect')->addRedirectToObject('product', $id, $locale, $redirectFromSlug);

Additionally redirect type can be specified (Permanent redirect is the default):

$this->get('object_router.redirect')->addRedirectToObject('product', $id, $locale, $redirectFromSlug, 301);

To disable redirects, set this configuration:

object_router:
    controllers: []

Generator

Since object slugs need to be unique, a generator is available to automatically generate and set such slugs. Generator can use any string as source for slug. Generated slug is returned as string:

$finalSlug = $this->get('object_router.generator')->setUniqueSlug('product', $id, $locale, 'Not unique text', true);

// $finalSlug contains 'not-unique-text'

All versions of object-router with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.2
symfony/symfony Version >=2.1
doctrine/orm Version >=2.1.0
sensio/framework-extra-bundle Version >=2.0.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 nercury/object-router contains the following files

Loading the files please wait ....