Pop\Mvc\Controller::__construct PHP Method

__construct() public method

Instantiate the controller object
public __construct ( Pop\Http\Request $request = null, Pop\Http\Response $response = null, Project $project = null, string $viewPath = null ) : Controller
$request Pop\Http\Request
$response Pop\Http\Response
$project Pop\Project\Project
$viewPath string
return Controller
    public function __construct(Request $request = null, Response $response = null, Project $project = null, $viewPath = null)
    {
        $this->request = null !== $request ? $request : new Request();
        $this->response = null !== $response ? $response : new Response();
        if (null !== $project) {
            $this->project = $project;
        }
        if (null !== $viewPath) {
            $this->viewPath = $viewPath;
        }
    }

Usage Example

 /**
  * Constructor method to instantiate the default controller object
  *
  * @param  Request  $request
  * @param  Response $response
  * @param  Project  $project
  * @param  string   $viewPath
  * @return self
  */
 public function __construct(Request $request = null, Response $response = null, Project $project = null, $viewPath = null)
 {
     if (null === $viewPath) {
         $cfg = $project->module('Phire')->asArray();
         $viewPath = __DIR__ . '/../../../../../view/phire/install';
         if (isset($cfg['view'])) {
             $class = get_class($this);
             if (is_array($cfg['view']) && isset($cfg['view'][$class])) {
                 $viewPath = $cfg['view'][$class];
             } else {
                 if (is_array($cfg['view']) && isset($cfg['view']['*'])) {
                     $viewPath = $cfg['view']['*'] . '/install';
                 } else {
                     if (is_string($cfg['view'])) {
                         $viewPath = $cfg['view'] . '/install';
                     }
                 }
             }
         }
     }
     $lang = isset($_GET['lang']) ? $_GET['lang'] : 'en_US';
     if (!defined('POP_LANG')) {
         define('POP_LANG', $lang);
     }
     $this->i18n = I18n::factory();
     $this->i18n->loadFile($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . '/vendor/Phire/data/assets/i18n/' . $this->i18n->getLanguage() . '.xml');
     parent::__construct($request, $response, $project, $viewPath);
     $this->sess = Session::getInstance();
 }
All Usage Examples Of Pop\Mvc\Controller::__construct