PHP code example of memcrab / router

1. Go to this page and download the library: Download memcrab/router library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

memcrab / router example snippets



declare (strict_types = 1);
tion;
use memCrab\Exceptions\RoutingException;
use memCrab\File\Yaml;
use memCrab\Router\Router;

try {
  # Read routes from yaml
  $Yaml = new Yaml();

  $routes = $Yaml->load("../src/routs.example.yaml", null)->getContent();

  # For enable cache You can use FileCache object as second parametr of
  # $Yaml->load() function. Use memCrab\Cache library for it.
  # Redis Cache: $FileCache = new RedisCache([Redis obj]);
  # PHP file Cache: $FileCache = new PHPCache([PathToTMLFolder]);

  # Initialize Router
  $Router = new Router();
  $Router->loadRoutes($routes);

  # Routing
  $Router->matchRoute("http://example.com/post/", "POST");
  # Run your Controller|Service|Component
  $ServiceName = $Router->getService();
  $ActionName = $Router->getAction();
  $Service = new $ServiceName();
  $Response = $Service->$Action($Router->getParams());
} catch (RoutingException $error) {
  $Respose = new \Response();
  $Respose->setErrorResponse($error);
} catch (FileException $error) {
  $Respose = new \Response();
  $Respose->setErrorResponse($error);
}

$Respose->sendHeaders();
$Respose->sendContent();

- apt-get update
- apt-get install php-pear
- apt-get install php-dev
- apt-get install php-xml php7.0-xml
- apt-get install libyaml-dev
- pecl channel-update pecl.php.net
- pecl install yaml-2.0.0

- brew install php71 --with-pear
- brew install autoconf
- touch $(brew --prefix php71)/lib/php/.lock && chmod 0644 $(brew --prefix php71)/lib/php/.lock
- pecl install yaml-2.0.0