示例#1
0
文件: Installer.php 项目: solve/admin
 public static function onPostPackageInstall(CommandEvent $event)
 {
     $projectRoot = realpath(__DIR__ . '/../../../..') . '/';
     $packageRoot = __DIR__ . '/';
     $appRoot = $projectRoot . 'app/Admin/';
     $io = $event->getIO();
     if ($io->askConfirmation('Would you like to install admin panel? (Y/n) ', true)) {
         if (!is_dir($projectRoot . 'app')) {
             die('Solve project is not found in ' . $projectRoot . ', exiting...');
         }
         $name = $io->ask('Enter the app name (admin): ', 'admin');
         $kernel = Kernel::getMainInstance();
         $appRoot = $projectRoot . 'app/' . ucfirst($name) . '/';
         $kernel->getEnvironment()->setProjectRoot($projectRoot);
         $config = DC::getProjectConfig();
         while ($name && $config->get('applications/' . $name)) {
             $name = $io->ask('Application exists, specify other name(or type exit): ');
         }
         $config->set('applications/' . $name, $name);
         $config->save();
     }
     if ($io->askConfirmation('Would you like to update assets? (Y/n) ', true)) {
         FSService::makeWritable($appRoot);
         FSService::makeWritable($projectRoot . 'web/admin/');
         FSService::copyRecursive($packageRoot . 'app/', $appRoot);
         FSService::copyRecursive($packageRoot . 'assets/', $projectRoot . 'web/admin/');
         exec('cd ' . $projectRoot . 'web/admin/ && npm install');
     }
 }
示例#2
0
 public static function getStructure($what = null)
 {
     if (empty(self::$_structure)) {
         self::$_structure = new YamlStorage(DC::getApplication()->getRoot() . 'structure.yml');
     }
     return $what ? self::$_structure->getDeepValue($what) : self::$_structure;
 }
示例#3
0
 public static function exceptionHandler(\Exception $e)
 {
     $fullTrace = $e->getTrace();
     if (is_callable(array($e, 'postAction'))) {
         $e->postAction($e->getMessage(), $e->getCode());
     }
     if (!DC::getProjectConfig('devMode')) {
         DC::getLogger()->add('Exception: ' . $e->getMessage(), 'exception');
         die;
     }
     $content = '<div style="font-size: 13px; font-family: Consolas, Menlo, Monaco, monospace;white-space: pre-wrap;">';
     $htmlTrace = "<b>\nLast arguments(" . count($fullTrace[0]['args']) . "):</b>\n" . dumpAsString($fullTrace[0]['args']) . "<b>\n\nCall stack:</b>\n<table style='font-size: 13px;'>";
     foreach ($fullTrace as $item) {
         $info = self::compileShortCallee($item);
         $htmlTrace .= '<tr><td style="color:#666;padding-right:10px;">' . $info['file'] . '</td><td>' . $info['call'] . '</td></tr>';
     }
     $htmlTrace .= '</table>';
     $content .= '<div style="background:#c00;color:white;font-weight:bold;padding:5px;margin-bottom: 5px; ">' . $e->getMessage() . '</div>';
     $content .= $htmlTrace;
     $content .= '</div>';
     if (DC::getRouter()->getExecutionMode() == Request::MODE_CONSOLE) {
         $content = strip_tags(str_replace('</td><td>', "\n", $content)) . "\n";
     }
     echo $content;
     die;
 }
示例#4
0
 public function requireAuthorization()
 {
     if (!$this->_storage['user']) {
         DC::getEventDispatcher()->dispatchEvent('security.unauthenticated');
     }
     return false;
 }
示例#5
0
 public function forwardToRoute($routeName, $vars = null)
 {
     if ($route = DC::getRouter()->getRoute($routeName)) {
         DC::getRouter()->setCurrentRoute($route)->getCurrentRequest()->setUri($route->buildUri($vars));
         $route = new ApplicationRoute($route);
         DC::getApplication()->setRoute($route);
         ControllerService::processControllerAction($route->getControllerName(), $route->getActionName());
     }
 }
示例#6
0
 public function onEnvironmentUpdate(BaseEvent $event)
 {
     ConfigService::setConfigsPath(DC::getEnvironment()->getConfigRoot());
     ConfigService::loadAllConfigs();
     DC::getLogger()->setLogsPath(DC::getEnvironment()->getTmpRoot() . 'log');
     DC::getAutoloader()->registerSharedPath(DC::getEnvironment()->getUserClassesRoot(), true);
     DC::getAutoloader()->registerSharedPath(DC::getEnvironment()->getUserClassesRoot() . 'db/bases');
     DC::getAutoloader()->registerSharedPath(DC::getEnvironment()->getUserClassesRoot() . 'db/classes');
     DC::getAutoloader()->registerNamespaceSharedPaths(DC::getEnvironment()->getUserClassesRoot() . 'classes/', true);
     FilesAbility::setBaseStoreLocation(DC::getEnvironment()->getUploadRoot());
 }
示例#7
0
 public function detectApplication()
 {
     DC::getEventDispatcher()->dispatchEvent('route.buildRequest', Request::getIncomeRequest());
     $this->_name = 'console';
     $this->_config = array('uri' => 'solve/', 'path' => 'SolveConsole/');
     $this->_namespace = 'SolveConsole';
     $this->_root = realpath(__DIR__ . '/../SolveConsole/') . '/';
     DC::getAutoloader()->registerNamespacePath($this->_namespace, realpath(__DIR__ . '/../') . '/');
     ControllerService::setActiveNamespace($this->_namespace);
     return $this->_name;
 }
示例#8
0
 public function __construct()
 {
     parent::__construct();
     $this->_sessionToken = RemoteSessionManager::getSessionToken();
     $this->_sessionStorage = new SessionStorage(null, 'api_session');
     $this->_data = new ArrayStorage();
     $action = DC::getApplication()->getRoute()->getActionName();
     $action = substr($action, 0, -6);
     if (!in_array($action, $this->_unprotectedMethods)) {
         $this->requireAuthorization();
     }
 }
示例#9
0
 public function configure()
 {
     parent::configure();
     $this->_slot = new Slot();
     $this->_slot->setTemplateDir($this->_view->getTemplatesPath());
     $this->_slot->setCompileDir(DC::getEnvironment()->getTmpRoot() . 'templates/' . DC::getApplication()->getName() . '/');
     $fs = new FSService();
     DC::getAutoloader()->registerSharedPath(DC::getEnvironment()->getUserClassesRoot() . 'helpers');
     if ($files = $fs->in(DC::getEnvironment()->getUserClassesRoot() . 'helpers')->find('*Block.php')) {
         foreach ($files as $file) {
             $this->_slot->registerBlock(Inflector::underscore(substr($file, strrpos($file, DIRECTORY_SEPARATOR) + 1, -9)), '\\');
         }
     }
 }
示例#10
0
 public function testBasic()
 {
     $this->buildTestStructure();
     $kernel = Kernel::getMainInstance();
     $env = $kernel->getEnvironment();
     $this->assertEquals(realpath(__DIR__ . '/../../../') . '/', $env->getProjectRoot(), 'root detected correctly');
     $kernel->getEnvironment()->setProjectRoot(realpath(__DIR__ . '/project/') . '/', true);
     $this->assertEquals('Test project', DC::getProjectConfig('name'));
     $_SERVER['REQUEST_URI'] = '/';
     $_SERVER['QUERY_STRING'] = '';
     $_SERVER['HTTP_HOST'] = 'test.com';
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER['DOCUMENT_ROOT'] = $env->getWebRoot();
     $_SERVER['HTTP_ACCEPT'] = 'text/html';
     $kernel->run();
 }
示例#11
0
 /**
  * Created database for profile default
  */
 public function createDbAction()
 {
     $config = DC::getDatabaseConfig('profiles/default');
     DatabaseService::configProfile(array('user' => $config['user'], 'pass' => $config['pass']));
     DBOperator::getInstance()->createDB($config['name']);
     $this->notify($config['name'], '+Database created:');
 }
示例#12
0
 public function tmpFileAction()
 {
     if ($path = $this->request->getVar('p')) {
         if (!FSService::showFileAndExit(DC::getEnvironment()->getTmpRoot() . $path)) {
             $response = new Response('<h1>Requested content not found</h1>', 404);
             $response->send();
             die;
         }
     }
 }
示例#13
0
文件: View.php 项目: solve/solve
 public function getCombinedVars($format = null)
 {
     if (!$format) {
         $format = $this->_responseFormat;
     }
     $combinedVars = new ArrayStorage($this->_vars);
     if ($this->_formatVars->has($format)) {
         $combinedVars->extendDeepValue($this->_formatVars->get($format));
     }
     if ($format == View::FORMAT_HTML) {
         $combinedVars['_baseUri'] = DC::getRouter()->getBaseUri();
     }
     return $combinedVars;
 }
示例#14
0
文件: Kernel.php 项目: solve/solve
 public function boot()
 {
     $this->_eventDispatcher->dispatchEvent('kernel.boot');
     if (headers_sent()) {
         DC::getLogger()->add('Cannot start session, headers sent', Logger::NAMESPACE_KERNEL);
     } else {
         if (empty($_SESSION)) {
             session_start();
         }
     }
 }
示例#15
0
 public static function onUnauthenticated(BaseEvent $event)
 {
     DC::getRouter()->redirectToRelativeUri('admin/');
 }
示例#16
0
 protected function getContentFromTemplate($templatePath, $vars = array())
 {
     if (!is_file($templatePath)) {
         throw new \Exception('No template found in ' . $templatePath);
     }
     $content = file_get_contents($templatePath);
     foreach ($vars as $key => $value) {
         $vars['__' . strtoupper($key) . '__'] = $value;
         unset($vars[$key]);
     }
     $vars['__DATE__'] = date('Y-m-d H:i:s');
     $vars['__PROJECT__'] = DC::getProjectConfig('name');
     return str_replace(array_keys($vars), $vars, $content);
 }
示例#17
0
 public function __call($method, $params)
 {
     $operation = substr($method, 0, 3);
     if (in_array($operation, array('get', 'set'))) {
         if (substr($method, -4) == 'Root') {
             $key = 'roots/' . strtolower(substr($method, 3, -4));
         } else {
             $key = strtolower(substr($method, 3));
         }
         if ($operation == 'get') {
             return $this->_vars->getDeepValue($key);
         } else {
             $this->_vars->setDeepValue($key, $params[0]);
             DC::getEventDispatcher()->dispatchEvent('environment.update', $key);
             return $this;
         }
     } else {
         return $this;
     }
 }
示例#18
0
 protected static function fireRouteNotFound($controllerName, $actionName)
 {
     DC::getEventDispatcher()->dispatchEvent('route.notFound');
     DC::getLogger()->add('Invalid action call:' . $controllerName . '->' . $actionName . '()');
 }
示例#19
0
 public function detectApplication()
 {
     DC::getEventDispatcher()->dispatchEvent('route.buildRequest', Request::getIncomeRequest());
     /**
      * @var ArrayStorage $appList
      */
     $appList = DC::getProjectConfig('applications');
     if (empty($appList)) {
         throw new \Exception('Empty application list');
     }
     $defaultAppName = DC::getProjectConfig('defaultApplication', 'frontend');
     $this->_name = $defaultAppName;
     $uri = (string) Request::getIncomeRequest()->getUri();
     $uriParts = explode('/', $uri);
     $webRoot = DC::getRouter()->getWebRoot();
     if (strlen($webRoot) > 1) {
         if (strpos($uri, substr($webRoot, 1)) === 0) {
             $uriParts = explode('/', substr($uri, strlen($webRoot)));
         }
     }
     if (!empty($uriParts) && (count($uriParts) > 0 && $uriParts[0] != '/')) {
         foreach ($appList as $appName => $appParams) {
             if ($appName == $defaultAppName) {
                 continue;
             }
             $appUri = !empty($appParams['uri']) ? $appParams['uri'] : $appName;
             if (strpos($uriParts[0], $appUri) === 0) {
                 array_shift($uriParts);
                 Request::getIncomeRequest()->setUri((strlen($webRoot) > 1 ? $webRoot . '/' : '') . implode('/', $uriParts));
                 $this->_name = $appName;
                 break;
             }
         }
     }
     $this->_config = DC::getProjectConfig('applications/' . $this->_name);
     if (!is_array($this->_config)) {
         $this->_config = array('uri' => $this->_name);
     }
     if (empty($this->_config['path'])) {
         $this->_config['path'] = Inflector::camelize($this->_name) . '/';
     }
     $this->_namespace = Inflector::camelize($this->_name);
     $this->_root = DC::getEnvironment()->getApplicationRoot() . $this->_config['path'];
     DC::getAutoloader()->registerNamespacePath($this->_namespace, DC::getEnvironment()->getApplicationRoot());
     ControllerService::setActiveNamespace($this->_namespace);
     return $this->_name;
 }