Пример #1
0
 /**
  * 初始化加载器
  *
  * @return \Powernote\Autoloader\ClassLoader
  */
 public static function init()
 {
     if (static::$loader == null) {
         static::$loader = new self();
         // 添加框架名称空间加载路径
         static::$loader->addNamespace('Powernote', realpath(__DIR__ . '/../'), true);
     }
     return static::$loader;
 }
Пример #2
0
 protected function getClosure($concrete)
 {
     //是否为一个类字符串定义
     if (is_string($concrete)) {
         //类别名
         if (ClassAliasLoader::init()->has($concrete)) {
             return function () use($concrete) {
             };
         }
         if ($r == false) {
             ClassLoader::init()->register()->load($concrete);
         }
     }
 }
Пример #3
0
 /**
  * 生成Closure
  *
  * @param string $module
  * @param string $name
  * @param string $method
  * @param array $arguments
  * @return mixed
  * @throws \Powernote\Routing\Exception\InvalidRouteCallbackException
  */
 public function callMethod($module, $name, $method, $arguments)
 {
     if ($path = $this->getControllerPath($module)) {
         ClassLoader::init()->addDirectories([$path]);
     }
     try {
         list($name, $method) = $this->normalizeName($name, $method);
         $parameters = (new \ReflectionMethod($name . '::' . $method))->getParameters();
         $tmp = [];
         if (is_array($parameters)) {
             foreach ($parameters as $p) {
                 $tmp[$p->name] = isset($arguments[$p->name]) ? $arguments[$p->name] : null;
             }
         }
         $arguments = $tmp;
         return call_user_func_array([new $name(), $method], $arguments);
     } catch (\Exception $e) {
         throw new InvalidRouteCallbackException($e->getMessage());
     }
 }
Пример #4
0
use Powernote\Config\Config;
use Powernote\Routing\Automate;
use Powernote\Support\Facades\Router;
use Powernote\Support\Facades\Facade;
use Powernote\Autoloader\ClassLoader;
// 开启错误报告
error_reporting(E_ALL);
// 加载配置
$app->singleton('config', function ($container) use($app) {
    return new Config($app->getConfigLoader(), $app['env']);
});
$config = $app['config']['app'];
$app->singleton('app', $app);
// 设置APP
Facade::clearResolvedInstances();
Facade::setFacadeApplication($app);
// 安装路由
$app->installRoute($app['path.route']);
// 自动路由
if ($config['route.automate'] == true) {
    Router::add([new Automate()]);
}
//开启错误提示
if ($config['debug'] == true) {
    ini_set('display_errors', 'on');
}
//注册当前应用程序名称空间
ClassLoader::init()->addNamespace('App', $app['path.app'] . '/');
// 设置时区
date_default_timezone_set($config['timezone']);
Пример #5
0
<?php

require __DIR__ . '/Powernote/Autoloader/ClassLoader.php';
// 注册类加载器
\Powernote\Autoloader\ClassLoader::init()->register();
// 注册类别名加载器
\Powernote\Autoloader\ClassAliasLoader::init()->register();