Download the PHP package krzysztof-magosa/saffron without Composer

On this page you can find all versions of the php package krzysztof-magosa/saffron. 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 saffron

Saffron PHP Router

Build Status Scrutinizer Code Quality Coverage Status

What is Saffron?

Saffron is very fast and flexible PHP router for your application.

Version

I no longer develop software in PHP so I do not actively support this project. Recently due to contribution project has been updated to be sure it works with PHP 7.x. The newest tag supporting older PHP versions (and also HHVM) is 5.3. If you still use this project - contributions are welcome.

Features

Installation

You can easily install Saffron by adding below requirement to your composer.json

How to use

You need to use RouterFactory to create instance of Router. Constructor of RouterFactory accepts one parameter, Closure which configures routes. Closure gets RoutesCollection in the first parameter. Closure is fired only once, then everything is stored in compiled file.

By default Saffron stores cache in system temporary directory. To avoid collisions between projects you are encouraged to set separate cache directories in each project hosted on the same server. If you really need to use one directory for more projects you can set class suffix.

When you have configured RouterFactory, you can build Router instance by calling build() method.

Configuring routes

To add Route you need to call method route() on $collection, giving route name as the first parameter. Method returns Route instance and then you can set parameters on it. You can create as many routes as you want, but each one needs to have unique name.

Setting target

To execute controller after matching particular route you need to use setTarget() method. First parameter is class name of controller, second is method name. If you omit second parameter it will default to 'indexAction'.

Setting uri

To match request against uri you need to call method setUri() on Route instance. It takes only one parameter, expected uri.

Setting domain

To match request against domain you need to call method setDomain() on Route instance. It takes only one parameter, expected domain.

Setting method

To match request against method you need to call method setMethod() on Route instance. You can pass one method as a string, or more using array.

Setting https

You may want to allow access to some resources only via encrypted or unencrypted connection. It can be done using setHttps() method. Pass true to this method if you want only encrypted traffic, false if unecrypted. Null means that it doesn't matter (it's the default setting).

Using placeholders

If your uri or domain contains variable parts, you can catch them using placeholders. Placeholders are defined using curly braces.

This example allows you to use links like:

Sometimes you want to allow user to omit some placeholders in the link. You can use setDefaults() method to achieve this.

Now user can go into link http://example.com/contact, and lang will be 'english', and name will be 'webmaster'.

You can also set requirements for placeholders, to allow user only to use some values there. Requirements are build using regular expressions, the same which you use in the preg_match().

Matching requests

Saffron accepts Request object. In typical configurations you can use createFromGlobals() static method. It was tested on Apache server with mod_php.

If your configuration isn't typical, you can create this object manually.

Now you can pass this object to Router match() method which returns RoutingResult object.

You can check whether matching was successful using isSuccessful() method. To check why matching was not successful you need to use two methods: isResourceNotFound() and isMethodNotAllowed(). When isResourceNotFound() returns true you should display error 404 to user, when isMethodNotAllowed() returns true you should display error 405. RFC 2616 requires to set Allow header containing allowed methods in case of displaying 405 error. You can get this list by calling getAllowedMethods(). Remembet that Saffron is not framework, but just router, so it's up to you to do that.

Building links

Saffron is two-directional router, so in addition to matching requests you can also build links. Router has method assemble() for building links.

Executing controllers

After successful matching of request you can fire controller specified in the route using Executor.

In some cases there is need to do something with controller just before or/and just after executing action. It can be done by using setPreDispatch() and setPostDispatch().

In some cases (for example firing error controller) you may want to fire controller which doesn't come from matched route. Executor also supports such situation.

Getting parameters

If your uri or domain containts placeholders they will be passed to your controller in arguments to method. You just need to ensure that controller method has arguments with the same names as your placeholders. You don't have to catch all placeholders.


All versions of saffron with dependencies

PHP Build Version
Package Version
No informations.
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 krzysztof-magosa/saffron contains the following files

Loading the files please wait ....