示例#1
0
 /**
  * Exception handler.
  *
  * @return void
  */
 public static final function handler()
 {
     return function (\Throwable $e) {
         // if not local no error display (so set & store option)
         if (!is_local()) {
             set_global('display_errors', ini_set('display_errors', '0'));
         }
         // will be catched in shutdown handler
         throw $e;
     };
 }
示例#2
0
function main()
{
    global $global, $smarty;
    set_global();
    include_all('admin/class/parent');
    include_all('admin/class');
    set_more_global();
    $path = 'admin/admin.php';
    if ($global['url'] != '') {
        $path2 = 'admin/' . $global['channel'] . '.php';
        if (file_exists($path2)) {
            $path = $path2;
        }
    }
    include $path;
}
示例#3
0
function main()
{
    global $global, $smarty;
    set_global();
    if (S_HALF_STATIC) {
        if ($global['url'] == '') {
            if (S_FLASH != 1) {
                $path = '/' . S_URL_SUFFIX;
            } else {
                $path = '/flash.html';
            }
        } else {
            $path = $global['url'];
        }
        $path = 'html' . $path;
        if (substr($path, -1) == '/') {
            $path .= S_URL_SUFFIX;
        }
        if (file_exists($path)) {
            include $path;
            exit;
        } else {
            ob_start();
        }
    }
    if (S_FLASH && $_SERVER['REQUEST_URI'] == S_ROOT) {
        $path = 'index/flash.php';
    } else {
        include_all('index/class/parent');
        include_all('index/class');
        set_more_global();
        $path = 'index/' . $global['channel'] . '.php';
        if ($global['url'] != '') {
            if (!file_exists($path)) {
                $path = 'index/' . $global['original'] . '.php';
            }
        }
    }
    include $path;
}
示例#4
0
文件: App.php 项目: froq/froq
 /**
  * Run.
  * @return void
  */
 public final function run()
 {
     // security & performans checks
     if ($halt = $this->haltCheck()) {
         $this->halt($halt);
     }
     // re-set app as global
     set_global('app', $this);
     $this->request->init(['uriRoot' => $this->root]);
     $this->response->init();
     // set defaults
     $this->setDefaults();
     // start output buffer
     $this->startOutputBuffer();
     $this->service = (new ServiceAdapter($this))->getService();
     // create session if service uses session
     if ($this->service->usesSession()) {
         $this->session = Session::init($this->config['app.session.cookie']);
     }
     $output = $this->service->run();
     // end output buffer
     $this->endOutputBuffer($output);
 }
示例#5
0
 public final function run()
 {
     if (!$this->config) {
         throw new \RuntimeException('Call setConfig() first to get run application!');
     }
     // re-set app as global
     set_global('app', $this);
     $this->request = new Request();
     $this->response = new Response();
     // set application defaults
     $this->setDefaults();
     // security & performans checks
     if ($halt = $this->haltCheck()) {
         $this->halt($halt);
     }
     // hold output buffer
     $this->startOutputBuffer();
     $this->service = (new ServiceAdapter($this))->getService();
     // sessions used for only "site"
     if ($this->service->protocol == ServiceInterface::PROTOCOL_SITE) {
         $this->session = Session::init($this->config['app.session.cookie']);
     }
     if (!$this->service->isAllowedRequestMethod($this->request->method)) {
         // set fail stuff
         $this->response->setStatus(Status::METHOD_NOT_ALLOWED);
         $this->response->setContentType(ContentType::NONE);
         $output = '';
     } else {
         $output = $this->service->run();
     }
     // end output buffer
     $this->endOutputBuffer($output);
 }
示例#6
0
 /**
  * Constructor.
  * @param Froq\App $app
  */
 public final function __construct(App $app)
 {
     $this->app = $app;
     // aliases
     $serviceAliases = $this->app->config->get('app.service.aliases', []);
     // detect service name
     $serviceNameAlias = '';
     $serviceName = strtolower($this->app->request->uri->segment(0, ''));
     // check alias
     if (array_key_exists($serviceName, $serviceAliases) && isset($serviceAliases[$serviceName][0])) {
         $serviceNameAlias = $serviceName;
         $serviceName = $serviceAliases[$serviceName][0];
     } else {
         $serviceName = $serviceName ?: ServiceInterface::SERVICE_MAIN;
     }
     $this->serviceName = $this->toServiceName($serviceName);
     $this->serviceFile = $this->toServiceFile($this->serviceName);
     $this->serviceClass = $this->toServiceClass($this->serviceName);
     // set service as FailService
     if (!$this->isServiceExists()) {
         set_global('app.service.fail', ['code' => 404, 'text' => sprintf('Service not found [%s]', $this->serviceName)]);
         $this->serviceName = ServiceInterface::SERVICE_FAIL . ServiceInterface::SERVICE_NAME_SUFFIX;
         $this->serviceMethod = ServiceInterface::METHOD_MAIN;
         $this->serviceFile = $this->toServiceFile($this->serviceName);
         $this->serviceClass = $this->toServiceClass($this->serviceName);
     }
     $this->service = $this->createService();
     if (!$this->service->isFailService()) {
         // detect service method
         if ($this->service->useMainOnly) {
             // main only
             $this->serviceMethod = ServiceInterface::METHOD_MAIN;
         } elseif ($this->service->protocol == ServiceInterface::PROTOCOL_SITE) {
             // from segment
             $serviceMethod = strtolower($this->app->request->uri->segment(1, ''));
             // check alias
             if (isset($serviceAliases[$serviceNameAlias]['methods']) && array_key_exists($serviceMethod, $serviceAliases[$serviceNameAlias]['methods'])) {
                 $this->serviceMethod = $this->toServiceMethod($serviceAliases[$serviceNameAlias]['methods'][$serviceMethod]);
             } elseif ($serviceMethod == '' || $serviceMethod == ServiceInterface::METHOD_MAIN) {
                 $this->serviceMethod = ServiceInterface::METHOD_MAIN;
             } else {
                 $this->serviceMethod = $this->toServiceMethod($serviceMethod);
             }
         } elseif ($this->service->protocol == ServiceInterface::PROTOCOL_REST) {
             // from request method
             $this->serviceMethod = strtolower($this->app->request->method);
         }
         // check method
         if (!$this->isServiceMethodExists()) {
             // check fallback method
             if ($this->isServiceMethodFallExists()) {
                 $this->serviceMethod = ServiceInterface::METHOD_FALL;
             } else {
                 set_global('app.service.fail', ['code' => 404, 'text' => sprintf('Service method not found [%s::%s()]', $this->serviceName, $this->serviceMethod)]);
                 // overwrite
                 $this->serviceName = ServiceInterface::SERVICE_FAIL . ServiceInterface::SERVICE_NAME_SUFFIX;
                 $this->serviceMethod = ServiceInterface::METHOD_MAIN;
                 $this->serviceFile = $this->toServiceFile($this->serviceName);
                 $this->serviceClass = $this->toServiceClass($this->serviceName);
                 // re-create service as FailService
                 $this->service = $this->createService();
             }
         }
         // set service method
         $this->service->setMethod($this->serviceMethod);
         // set service method args
         if ($this->isServiceMethodExists()) {
             $methodArgs = array_slice($this->app->request->uri->segments(), 2);
             $ref = new \ReflectionMethod($this->serviceClass, $this->serviceMethod);
             foreach ($ref->getParameters() as $i => $param) {
                 if (!isset($methodArgs[$i])) {
                     $methodArgs[$i] = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
                 }
             }
             $this->service->setMethodArgs($methodArgs);
         }
     }
 }