Skip to content

Latest commit

 

History

History
566 lines (280 loc) · 14.6 KB

class.DispatcherCore.md

File metadata and controls

566 lines (280 loc) · 14.6 KB

Class DispatcherCore

Contents

Constants

Properties

Methods

Constants

FC_ADMIN

const FC_ADMIN = 2

FC_FRONT

const FC_FRONT = 1

List of available front controllers types

FC_MODULE

const FC_MODULE = 3

Properties

$controller

protected string $controller

$controller_not_found

protected string $controller_not_found = 'pagenotfound'

$default_controller

protected string $default_controller

$default_routes

public array $default_routes = array('category_rule' => array('controller' => 'category', 'rule' => '{id}-{rewrite}', 'keywords' => array('id' => array('regexp' => '[0-9]+', 'param' => 'id_category'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'))), 'supplier_rule' => array('controller' => 'supplier', 'rule' => '{id}__{rewrite}', 'keywords' => array('id' => array('regexp' => '[0-9]+', 'param' => 'id_supplier'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'))), 'manufacturer_rule' => array('controller' => 'manufacturer', 'rule' => '{id}_{rewrite}', 'keywords' => array('id' => array('regexp' => '[0-9]+', 'param' => 'id_manufacturer'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'))), 'cms_rule' => array('controller' => 'cms', 'rule' => 'content/{id}-{rewrite}', 'keywords' => array('id' => array('regexp' => '[0-9]+', 'param' => 'id_cms'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'))), 'cms_category_rule' => array('controller' => 'cms', 'rule' => 'content/category/{id}-{rewrite}', 'keywords' => array('id' => array('regexp' => '[0-9]+', 'param' => 'id_cms_category'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'))), 'module' => array('controller' => null, 'rule' => 'module/{module}{/:controller}', 'keywords' => array('module' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'module'), 'controller' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'controller')), 'params' => array('fc' => 'module')), 'product_rule' => array('controller' => 'product', 'rule' => '{category:/}{id}-{rewrite}{-:ean13}.html', 'keywords' => array('id' => array('regexp' => '[0-9]+', 'param' => 'id_product'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*'), 'ean13' => array('regexp' => '[0-9\pL]*'), 'category' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'), 'reference' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'manufacturer' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'supplier' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'price' => array('regexp' => '[0-9\.,]*'), 'tags' => array('regexp' => '[a-zA-Z0-9-\pL]*'))), 'layered_rule' => array('controller' => 'category', 'rule' => '{id}-{rewrite}{/:selected_filters}', 'keywords' => array('id' => array('regexp' => '[0-9]+', 'param' => 'id_category'), 'selected_filters' => array('regexp' => '.*', 'param' => 'selected_filters'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'))))

$empty_route

protected array $empty_route

$front_controller

protected string $front_controller = self::FC_FRONT

$instance

public \Dispatcher $instance = null

$multilang_activated

protected mixed $multilang_activated = false

$request_uri

protected string $request_uri

$routes

protected array $routes = array()

$use_default_controller

protected mixed $use_default_controller = false

$use_routes

protected boolean $use_routes = false

Methods

__construct

mixed DispatcherCore::__construct()

Need to be instancied from getInstance() method

addRoute

mixed DispatcherCore::addRoute(string $route_id, string $rule, string $controller, integer $id_lang, array $keywords, array $params, integer $id_shop)

Arguments

  • $route_id string - Name of the route (need to be uniq, a second route with same name will override the first)
  • $rule string - Url rule
  • $controller string - Controller to call if request uri match the rule
  • $id_lang integer
  • $keywords array
  • $params array
  • $id_shop integer

createUrl

mixed DispatcherCore::createUrl(string $route_id, integer $id_lang, array $params, $force_routes, string $anchor, $id_shop)

Create an url from

Arguments

  • $route_id string - Name the route
  • $id_lang integer
  • $params array
  • $force_routes mixed
  • $anchor string - Optional anchor to add at the end of this url
  • $id_shop mixed

dispatch

mixed DispatcherCore::dispatch()

Find the controller and instantiate it

getController

string DispatcherCore::getController($id_shop)

Retrieve the controller from url or request uri if routes are activated

Arguments

  • $id_shop mixed

getControllers

array DispatcherCore::getControllers($dirs)

Get list of all available FO controllers

Arguments

  • $dirs mixed

getControllersInDirectory

array DispatcherCore::getControllersInDirectory(string $dir)

Get list of available controllers from the specified dir

Arguments

  • $dir string - Directory to scan (recursively)

getInstance

\Dispatcher DispatcherCore::getInstance()

Get current instance of dispatcher (singleton)

getModuleControllers

array DispatcherCore::getModuleControllers($type, $module)

Get list of all available Module Front controllers

Arguments

  • $type mixed
  • $module mixed

hasKeyword

boolean DispatcherCore::hasKeyword(string $route_id, integer $id_lang, string $keyword, integer $id_shop)

Check if a keyword is written in a route rule

Arguments

  • $route_id string
  • $id_lang integer
  • $keyword string
  • $id_shop integer

hasRoute

boolean DispatcherCore::hasRoute(string $route_id, integer $id_lang, integer $id_shop)

Check if a route exists

Arguments

  • $route_id string
  • $id_lang integer
  • $id_shop integer

loadRoutes

mixed DispatcherCore::loadRoutes($id_shop)

Load default routes group by languages

Arguments

  • $id_shop mixed

setRequestUri

mixed DispatcherCore::setRequestUri()

Set request uri and iso lang

useDefaultController

mixed DispatcherCore::useDefaultController()

validateRoute

mixed DispatcherCore::validateRoute(string $route_id, string $rule, array $errors)

Check if a route rule contain all required keywords of default route definition

Arguments

  • $route_id string
  • $rule string - Rule to verify
  • $errors array - List of missing keywords