示例#1
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;
 }
示例#2
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');
     }
 }
示例#3
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();
 }
示例#4
0
 public function onKernelReady(BaseEvent $event)
 {
     $this->onEnvironmentUpdate($event);
     if ($webRoot = DC::getProjectConfig('webRoot')) {
         DC::getEnvironment()->setWebRoot($webRoot);
     }
     $databaseConfig = DC::getDatabaseConfig();
     $request = DC::getRouter()->getCurrentRequest();
     if ($profiles = $databaseConfig->get('profiles')) {
         foreach ($profiles as $profileName => $profileInfo) {
             DatabaseService::configProfile($profileInfo, $profileName);
         }
         if (empty($request) || $request && !$request->isConsoleRequest()) {
             ModelOperator::getInstance(DC::getEnvironment()->getUserClassesRoot() . 'db/');
             if ($databaseConfig->get('autoUpdateAll')) {
                 ModelOperator::getInstance()->generateAllModelClasses()->updateDBForAllModels();
             }
         }
     }
 }
示例#5
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;
 }
示例#6
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);
 }