Example #1
0
 /**
  * 加载配置文件
  */
 public static function loadConfig()
 {
     $context = ApplicationContext::getContext();
     $constants = get_defined_constants(true);
     foreach ($constants['user'] as $key => $val) {
         Config::$key($val);
     }
     include_once Config::SITE_CONF() . "/sherry.conf.php";
     $map = new ControllerMap();
     $map->setPackages($packages);
     $context->setControllerMap($map);
 }
Example #2
0
 private function getOptions()
 {
     $this->ensure(file_exists($this->config), "Could not find options file");
     $options = @SimpleXml_load_file($this->config);
     //        $this->ensure( $options instanceof SimpleXMLElement,
     //                            "Could not resolve options file" );
     $dsn = (string) $options->dsn;
     $this->ensure($dsn, "No DSN found");
     \woo\base\ApplicationRegistry::setDSN($dsn);
     $map = new ControllerMap();
     foreach ($options->control->view as $default_view) {
         $stat_str = trim($default_view['status']);
         $status = \woo\command\Command::statuses($stat_str);
         $map->addView('default', $status, (string) $default_view);
     }
     foreach ($options->control->command as $command_view) {
         $command = trim((string) $command_view['name']);
         if ($command_view->classalias) {
             $classroot = trim((string) $command_view->classalias['name']);
             $map->addClassroot($command, $classroot);
         }
         if ($command_view->view) {
             $view = trim((string) $command_view->view);
             $forward = trim((string) $command_view->forward);
             $map->addView($command, 0, $view);
             if ($forward) {
                 $map->addForward($command, 0, $forward);
             }
             foreach ($command_view->status as $command_view_status) {
                 $view = trim((string) $command_view_status->view);
                 $forward = trim((string) $command_view_status->forward);
                 $stat_str = trim($command_view_status['value']);
                 $status = \woo\command\Command::statuses($stat_str);
                 if ($view) {
                     $map->addView($command, $status, $view);
                 }
                 if ($forward) {
                     $map->addForward($command, $status, $forward);
                 }
             }
         }
     }
     \woo\base\ApplicationRegistry::setControllerMap($map);
 }
Example #3
0
 /**
  *
  * @param string $sRegex
  * @param string $sPath
  * @throws ExceptionController
  * @throws ExceptionSitemap
  * @returns ControllerMap
  */
 public function mapController($sRegex, $sPath)
 {
     if (!$sRegex) {
         throw new ExceptionSitemap('An URI must be present.');
     }
     $sKey = $sRegex;
     if (array_key_exists($sKey, $this->aControllerMaps)) {
         unset($this->aControllerMaps[$sKey]);
     }
     if (class_exists($sPath)) {
         // instead of a path we have a namespace
         $oNewMap = new ClassMap($sPath, $sKey);
         $oNewMap->setModuleMap($this);
         $oNewMap->merge($this);
         $this->aControllerMaps[$sKey] = $oNewMap;
         return $oNewMap;
     } else {
         $sPath = str_replace(array('/', '\\'), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $sPath);
         if (!SiteMapA::isValidObjectPath($sPath)) {
             $sPath = $this->getModulePath() . $sPath;
         }
         if (SiteMapA::isValidObjectPath($sPath)) {
             $oNewMap = new ControllerMap($sPath, $sKey);
             $oNewMap->setModuleMap($this);
             $oNewMap->merge($this);
             $this->aControllerMaps[$sKey] = $oNewMap;
             return $oNewMap;
         } else {
             throw new ExceptionController('Controller [' . $sPath . '] is invalid.');
         }
     }
 }
Example #4
0
 public function __construct()
 {
     parent::__construct(Html5Controller::class, '\\A.*\\Z');
 }