예제 #1
0
 /**
  * @param $pathInfo
  * @return bool|string
  */
 private function handlePathInfo($pathInfo)
 {
     @(list($id, $route) = explode('/', $pathInfo, 2));
     if (Yii::$app->hasModule($id) == false) {
         return false;
     }
     $module = Yii::$app->getModule($id);
     $controllerSuffix = Settings::getInstance()->isAdmin() ? AbstractModule::ADMIN_CONTROLLER_SUFFIX : AbstractModule::CONTROLLER_SUFFIX;
     $className = str_replace(' ', '', ucwords(str_replace('-', ' ', $id)) . $controllerSuffix);
     $className = ltrim($module->controllerNamespace . '\\' . $className, '\\');
     if (strpos($className, '-') !== false || !class_exists($className)) {
         return false;
     }
     if (isset($route)) {
         $routePaths = explode('/', $route, 2);
     } else {
         $routePaths = explode('/', $module->defaultRoute, 2);
     }
     $action = $routePaths[0];
     $reflectionClass = new \ReflectionClass($className);
     if ($reflectionClass->isSubclassOf('yii\\base\\Controller') && $reflectionClass->hasMethod('action' . $action)) {
         return sprintf('%s/%s', $id, $pathInfo);
     }
     return false;
 }
예제 #2
0
 /**
  * Method shifts admin prefix and sets Application as Admin site
  */
 public function init()
 {
     $request = \Yii::$app->getRequest();
     $pregPattern = sprintf('/(%s)+?/', AdminPlugin::ADMIN_PREFIX);
     if (preg_match($pregPattern, $request->getPathInfo())) {
         $newPathInfo = preg_replace($pregPattern, '', $request->getPathInfo());
         if ($newPathInfo == '' || $newPathInfo == '/') {
             $newPathInfo = AdminPlugin::DEFAULT_ROUTE;
         }
         $request->setPathInfo($newPathInfo);
         Settings::getInstance()->setAdminMode();
     }
 }
예제 #3
0
파일: Manager.php 프로젝트: pbabilas/bcode
 public function createUrl($params)
 {
     if (in_array(\Yii::$app->controller->module->id, $this->ignoreModules)) {
         return parent::createUrl($params);
     }
     if (is_array($params)) {
         @(list($module, $controllerId, $action) = explode('/', $params[0], 3));
         if ($module != $controllerId) {
             $route = sprintf('%s/%s/%s', $module, $controllerId, $action);
         } else {
             $route = sprintf('%s/%s', $module, $action);
         }
         unset($params[0]);
         if (!empty($params) && ($query = http_build_query($params)) !== '') {
             $route .= '?' . $query;
         }
         return sprintf('%s%s', Settings::getInstance()->isAdmin() ? 'admin/' : '', $route);
     }
     return parent::createUrl($params);
 }
예제 #4
0
 public function init()
 {
     $this->isAdminController = Settings::getInstance()->isAdmin();
     $this->controllerNamespace = sprintf($this->controllerNamespace, $this->id);
     parent::init();
 }
예제 #5
0
파일: Module.php 프로젝트: pbabilas/bcode
 public function init()
 {
     Settings::getInstance()->disableAdminMode();
     parent::init();
 }