public static function register($container)
 {
     $panel = new self();
     Debugger::addPanel($panel);
     if (static::$appDir === null) {
         static::$appDir = \jasir\FileHelpers\File::simplifyPath(__DIR__ . '/../../../../app');
     }
     $application = $container->getService('application');
     $application->onResponse[] = callback(array($panel, 'getResponseCb'));
 }
Example #2
0
 /**
  * 初始化:创建Application
  * @access public
  * @param array $config设置
  */
 public static function createApplication($config = NULL)
 {
     if ($config === NULL) {
         throw new SYException('Configuration is required', '10001');
     } elseif (is_string($config)) {
         if (is_file($config)) {
             $config = (require $config);
         } else {
             throw new SYException('Config file ' . $config . ' not exists', '10002');
         }
     } elseif (!is_array($config)) {
         throw new SYException('Config can not be recognised', '10003');
     }
     //框架所在的绝对路径
     static::$frameworkDir = SY_ROOT;
     static::$rootDir = rtrim(str_replace('\\', '/', realpath(SY_ROOT . '../')), '/') . '/';
     //程序相对网站根目录所在
     $now = $_SERVER['PHP_SELF'];
     $dir = str_replace('\\', '/', dirname($now));
     $dir !== '/' && ($dir = rtrim($dir, '/') . '/');
     static::$siteDir = $dir;
     //网站根目录
     static::$webrootDir = substr(static::$rootDir, 0, strlen(static::$rootDir) - strlen(static::$siteDir)) . '/';
     //基本信息
     $config['cookie']['path'] = str_replace('@app/', $dir, $config['cookie']['path']);
     static::$app = $config;
     //应用的绝对路径
     static::$appDir = rtrim(str_replace('\\', '/', realpath(SY_ROOT . $config['dir'])), '/') . '/';
     if (isset($config['debug'])) {
         static::$debug = $config['debug'];
     }
     mb_internal_encoding($config['charset']);
     //是否启用CSRF验证
     if ($config['csrf']) {
         \sy\lib\YSecurity::csrfSetCookie();
     }
     //加载App的基本函数
     if (is_file(static::$appDir . 'common.php')) {
         require static::$appDir . 'common.php';
     }
     //开始路由分发
     static::router();
 }
 protected static function preparePaths($testsDir = NULL)
 {
     if ($testsDir !== NULL) {
         static::$testsDir = $testsDir;
     }
     if (static::$testsDir === NULL) {
         throw new InvalidStateException(__CLASS__ . '::$testsDir has to be set');
     }
     if (static::$rootDir === NULL) {
         static::$rootDir = static::$testsDir . '/..';
     }
     if (static::$vendorDir === NULL) {
         static::$vendorDir = static::$rootDir . '/vendor';
     }
     if (static::$appDir === NULL) {
         static::$appDir = static::$rootDir . '/app';
     }
     if (static::$tempDir === NULL) {
         static::$tempDir = static::$testsDir . '/temp';
     }
 }
Example #4
0
 /**
  * Method setDirApp
  * Seta diretório a aplicação
  * @author Bruno Oliveira <*****@*****.**>
  * @access public
  * @param string $dir
  */
 public function setDirApp($dir)
 {
     if (preg_match('/[\\\\|\\/]$/', $dir)) {
         static::$appDir = $dir;
     } else {
         static::$appDir = "{$dir}/";
     }
 }