/**
  * Kernel constructor.
  */
 public function __construct()
 {
     try {
         $this->Request = new Request();
         $this->Router = new Router($this->Request);
         $ControllerLoader = new ControllerLoader($this->Request->getController());
         if ($ControllerLoader->exist()) {
             $this->Controller = $ControllerLoader->getInstance($this->Request);
             if (method_exists($this->Controller, $this->Request->getAction())) {
                 call_user_func([$this->Controller, $this->Request->getAction()], $this->Request->getParams());
                 $Logger = new Logger('/logs/access.log');
                 $Date = new \DateTime('now');
                 $Logger->writeLine('[' . $Date->getTimestamp() . '] Path:' . $this->Request->getPath() . ' type:' . $this->Request->getMethod());
             } else {
                 $exception = new NotFoundException('Path:' . $this->Request->getPath() . ', Action ' . $this->Request->getAction() . ' not found in Controller ' . ucfirst($this->Request->getController() . 'Controller'));
                 throw $exception;
             }
         } else {
             $exception = new NotFoundException('Path:' . $this->Request->getPath() . ', Controller ' . ucfirst($this->Request->getController()) . 'Controller not found');
             throw $exception;
         }
     } catch (NotFoundException $e) {
         echo $e->cry();
     }
 }
Example #2
0
 protected function createDirectoryIfNotExists($jobCounter, \DateTime $DateTime, $cmod = 0775)
 {
     if (empty($this->projectSettings)) {
         return false;
     }
     if (!isset($this->projectSettings['dir_downloaded_posts']) || empty($this->projectSettings['dir_downloaded_posts'])) {
         return false;
     }
     if (!isset($jobCounter) || empty($jobCounter)) {
         return false;
     }
     $dir = $this->baseDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $this->projectSettings['dir_downloaded_posts'] . DIRECTORY_SEPARATOR . $DateTime->format('Y-m-d') . DIRECTORY_SEPARATOR . $jobCounter . '--' . $DateTime->format('Y-m-d--H-i-s') . '--' . uniqid();
     $success = true;
     if (!is_dir($dir)) {
         $success = mkdir($dir, $cmod, true);
     }
     if (!$success) {
         return false;
     }
     return $dir;
 }