Download the PHP package imarc/anchor without Composer

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

========================================= = Anchor // a routing library for PHP 5 =

Build Status

The following is a short example on how to use Anchor. Once you've gone through this, there is additional PHPDoc documentation in the class.

  1. Configuring Anchor for your Controllers

The simplest way to use controller classes with Anchor is to pass a folder that contains the controllers. Anchor will attempt to load your controller classes by appending .php to the class name.

Anchor::setControllerPath('/path/to/controller/dir');

If you are using PHP 5.2 namespacing where _ characters are converted to folder separators (e.g. slashes), then be sure to add:

Anchor::setLegacyNamespacing();

If you want to load you controller classes on your own, you need to authorize Anchor to use them. This helps prevent vulnerabilities based on user input. All controller classes, or one of the classes they inherit from, must be authorized in order for Anchor to use them. The following authorizes all classes that inherit from BaseController.

Anchor::authorize('BaseController');

  1. Adding Routes

Next, you need to define the routes that Anchor will handle. Anchor::add() accepts two parameters, the URL to route and the callback to pass it to.

Anchor::add('/', 'Home::main');

While Home::main looks like a static method, all controller methods must be public instance methods, otherwise Anchor will not use them. This is another security feature.

You pull values out of URLs by using one of the four symbols, followed by a request variable name. The four symbols are the following single character:

! - matches letters, numbers and underscores : - matches anything but a slash % - matches numbers @ - matches letters

Here is an example of pulling a numeric id and string slug out of a URL:

Anchor::add('/blog/%id-:slug', 'Blogs::view');

These values will be pushed into the $_GET and $_REQUEST superglobals with the names you define.

There are three param names that are reserved by the class for use in determining what controller should be run when the controller includes wildcards. There are "class", "method" and "namespace". For instance:

Anchor::add('/!class/!method', '::');

Will attempt to run the Blog::list() controller method if the URL is /blog/list, but will attempt to run About::team() if the URL is /about/team.

There is one special route, the 404 route, which is called if no other routes match.

Anchor::add('404', 'Home::notFound');

  1. Running Anchor

Once Anchor is configured and the routes are added, you run it by calling:

Anchor::run();

  1. Linking

You can generate the link to a controller by passing it, with any required data to the link method:

Anchor::link('Users::view id slug', 5, 'john_smith');

This will find the route for Users::view that has the params id and slug in it and create a link. If no routes exist with those params, they will be added as query string params.

  1. Full Example

// .htaccess file in root of website

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ bootstrap.php [L,QSA]

// bootstrap.php

include $_SERVER['DOCUMENT_ROOT'] . '/../init.php';

Anchor::setControllerPath('/path/to/controller/dir');

Anchor::add('/!class/!method/%id-:slug', '::'); Anchor::add('/!class/!method', '::'); Anchor::add('/', 'Home::main'); Anchor::add('404', 'Home::notFound');

Anchor::run();

// Controller class in /path/to/controller/dir/Users.php

class Users { public function view($data) { $id = $_GET['id']; // do stuff here and output response } }


All versions of anchor with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.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 imarc/anchor contains the following files

Loading the files please wait ....