FOF30\Controller\Controller::__construct PHP Method

__construct() public method

modelConfig array The configuration overrides for the Model.
public __construct ( Container $container, array $config = [] ) : Controller
$container FOF30\Container\Container The application container
$config array The configuration array
return Controller
    public function __construct(Container $container, array $config = array())
    {
        // Initialise
        $this->methods = array();
        $this->message = null;
        $this->messageType = 'message';
        $this->paths = array();
        $this->redirect = null;
        $this->taskMap = array();
        // Get a local copy of the container
        $this->container = $container;
        // Determine the methods to exclude from the base class.
        $xMethods = get_class_methods('\\FOF30\\Controller\\Controller');
        // Get the public methods in this class using reflection.
        $r = new \ReflectionClass($this);
        $rMethods = $r->getMethods(\ReflectionMethod::IS_PUBLIC);
        foreach ($rMethods as $rMethod) {
            $mName = $rMethod->getName();
            // If the developer screwed up and declared one of the helper method public do NOT make them available as
            // tasks.
            if (substr($mName, 0, 8) == 'onBefore' || substr($mName, 0, 7) == 'onAfter' || substr($mName, 0, 1) == '_') {
                continue;
            }
            // Add default display method if not explicitly declared.
            if (!in_array($mName, $xMethods) || $mName == 'display' || $mName == 'main') {
                $this->methods[] = $mName;
                // Auto register the methods as tasks.
                $this->taskMap[$mName] = $mName;
            }
        }
        if (isset($config['name'])) {
            $this->name = $config['name'];
        }
        // Get the default values for the component and view names
        $this->view = $this->getName();
        $this->layout = $this->input->getCmd('layout', null);
        // If the default task is set, register it as such
        if (array_key_exists('default_task', $config) && !empty($config['default_task'])) {
            $this->registerDefaultTask($config['default_task']);
        } else {
            $this->registerDefaultTask('main');
        }
        // Cache the config
        $this->config = $config;
        // Set any model/view name overrides
        if (array_key_exists('viewName', $config) && !empty($config['viewName'])) {
            $this->setViewName($config['viewName']);
        }
        if (array_key_exists('modelName', $config) && !empty($config['modelName'])) {
            $this->setModelName($config['modelName']);
        }
        // Apply the autoRouting preference
        if (array_key_exists('autoRouting', $config)) {
            $this->autoRouting = (int) $config['autoRouting'];
        }
        // Apply the csrfProtection preference
        if (array_key_exists('csrfProtection', $config)) {
            $this->csrfProtection = (int) $config['csrfProtection'];
        }
    }

Usage Example

Example #1
0
 /**
  * Assigns callback functions to the class, the $methods array should be an associative one, where
  * the keys are the method names, while the values are the closure functions, e.g.
  *
  * array(
  *    'foobar' => function(){ return 'Foobar'; }
  * )
  *
  * @param           $container
  * @param array     $config
  * @param array     $methods
  */
 public function __construct(Container $container, array $config = array(), array $methods = array())
 {
     foreach ($methods as $method => $function) {
         $this->mockedMethods[$method] = $function;
     }
     parent::__construct($container, $config);
 }
All Usage Examples Of FOF30\Controller\Controller::__construct