/** * return option passed through cli * * @param string $Key * @return string */ public function getCLIOption($Key) { return $this->CLIOptions->get($Key); }
/** * @return mixed */ public function getComponent() { if (!isset($this->Component)) { $dbh = Factory::getDBH(); $_Component = Factory::getRouter()->getRoute('Component'); $_Controller = Factory::getRouter()->getRoute('Controller'); $Action = Factory::getRouter()->getRoute('Action'); $ID = Factory::getRouter()->getRoute('ID'); try { $stmt = $dbh->prepare('SELECT * FROM Component WHERE ApplicationID = :AppID AND blStatus = 1 AND Component = :Component;'); try { $stmt->bindValue(':AppID', $this->ApplicationID, PDO::PARAM_STR); $stmt->bindValue(':Component', (string) ucfirst($_Component), PDO::PARAM_STR); $stmt->execute(); $Component = new Object($stmt->fetch(PDO::FETCH_OBJ)); } catch (PDOException $e) { $dbh->catchException($e, $stmt->queryString); throw new Exception('EpsilonCMS cannot Load Component DB'); } if ($Component->get('ComponentID')) { $AccessLevels = Factory::getUser()->getAuthorizedLevels(); /** Verify if the current user has access to the component */ if (!in_array($Component->get('AccessLevelID'), $AccessLevels)) { if (Factory::getUser()->isGuest()) { if (Factory::getApplication()->isCLI()) { Factory::getLogger()->alert(Factory::getLanguage()->_('NOT_AUTHORIZED')); } else { Factory::getApplication()->redirectLogin(); } } else { Factory::getApplication()->redirectHome(); } } /** Creates the Class|Controller Namespace */ $Namespace = '\\Components\\' . $_Component . '\\Controllers\\'; /** * If the route contains a controller use that controller * else * use the component name as default controller */ if ($_Controller) { $Controller = $_Controller; } else { $Controller = $_Component; } $Class = $Namespace . $Controller; if (!class_exists($Class)) { throw new \Exception("Controller does not exist {$Controller}->{$Action}({$ID})"); } $Component = new $Class($dbh, $Component); /** Verify if the method (Action) exist */ if (is_callable([$Component, $Action])) { $Component->{$Action}($ID); } else { throw new \Exception("Controller method does not exist {$Controller}->{$Action}({$ID})"); } $this->Component = $Component; } else { throw new \Exception('Component {' . $_Component . '} does not exist in Database'); } } catch (\Exception $e) { Factory::getLogger()->alert('ComponentManagerException: {Message} {File} {Line}', ['Message' => $e->getMessage(), 'File' => $e->getFile(), 'Line' => $e->getLine()]); } } return $this->Component; }