Пример #1
0
 /**
  * @return void
  */
 public function next()
 {
     $this->load();
     if ($url = static::parseLink($this->response->getHeader('Link'), 'next')) {
         $this->request = new Http\Request($this->request->getMethod(), $url, $this->request->getHeaders(), $this->request->getContent());
     } else {
         $this->request = NULL;
     }
     $this->response = NULL;
     $this->counter++;
 }
Пример #2
0
 public function send()
 {
     $this->setHeader('User-Agent', 'Delta Systems Desk API Wrapper');
     $this->getAuthentication();
     $this->scanUrl();
     return parent::send();
 }
Пример #3
0
 $env = new Application\Environment(dirname(ABSPATH), dirname(dirname(ABSPATH)));
 /**
  * Get the app class name
  */
 $class = apply_filters('application_class', 'WordPress\\App');
 /**
  * Application instance.
  *
  * @var WordPress\App $app
  */
 \WordPress::init($app = new $class($env));
 $app->set('autoloader', function (App $app) {
     return $app->getGlobal('autoloader');
 });
 $app->setShared('env', $env);
 $app->setShared('request', Http\Request::createFromGlobals());
 $app->setShared('restManager', new Rest\Manager());
 $app->setShared('modelManager', new Model\Manager());
 $app->setShared('dataManager', new Data\Manager());
 $app->set('post', function () {
     return Model\Post::instance();
 });
 $app->set('user', function () {
     return Model\User::instance();
 });
 $app->setShared('dbConnection', function (App $app) {
     return new Database\Connection($app->getGlobal('wpdb'));
 });
 if (CLI) {
     $app->setShared('cliRequest', function () {
         return Cli\Request::createFromGlobals();
Пример #4
0
 /**
  * @return Http\Request
  */
 public function request()
 {
     return Http\Request::singleton();
 }
Пример #5
0
 public function __get($key)
 {
     $value = parent::__get($key);
     return null === $value ? $this->getQueryVar($key) : $value;
 }
Пример #6
0
 /**
  * Initialize the application.
  */
 private function init()
 {
     $errorHandler = new ErrorHandler();
     $errorHandler->register();
     static::$DI = $DI = DI::instance();
     $DI['Request'] = $request = new Http\Request();
     $DI['Config'] = $config = new Config($this->sitePath, dirname($_SERVER['SCRIPT_FILENAME']), $request->getBaseUrl());
     $DI['Alias'] = new Alias(['@app' => $config->get('app.path'), '@asset' => $this->sitePath . '/assets', '@media' => $config->get('media.path'), '@page' => $config->get('pages.path'), '@plugin' => $config->get('plugins.path'), '@post' => $config->get('posts.path'), '@site' => $this->sitePath, '@vendor' => $this->vendorDir, '@web' => $config->get('web.path')]);
     $DI['Assets'] = function ($DI) {
         return new Assets($DI['Alias'], $DI['Config']->get('web.url'));
     };
     $DI['Cache\\PageCache'] = function ($DI) {
         return Cache\CacheFactory::create('page', $DI['Config']);
     };
     $DI['Cache\\DataCache'] = function ($DI) {
         return Cache\CacheFactory::create('data', $DI['Config']);
     };
     $DI['DataArray'] = function ($DI) {
         $loader = new Loader\DataLoader($DI['Config']->get('data.extensions'));
         return $loader->load($DI['Config']->get('data.path'));
     };
     $DI['Loader\\PageLoader'] = function ($DI) {
         $loader = new Loader\PageLoader($DI['Alias']);
         return $loader;
     };
     $DI['Menu\\Page\\Builder'] = function ($DI) {
         $paths = [];
         $paths['@page'] = realpath($DI['Config']->get('pages.path'));
         foreach ($DI['Config']->get('pages.extra_paths', []) as $alias) {
             $paths[$alias] = $DI['Alias']->get($alias);
         }
         $extensions = $DI['Config']->get('pages.extensions', []);
         $builder = new Menu\Page\Builder($paths, $extensions);
         return $builder;
     };
     $DI['PluginManager'] = function ($DI) {
         $enabled = $DI['Config']->get('plugins.enable', []);
         $path = $DI['Config']->get('plugins.path');
         $enabledSysPlugins = $DI['Config']->get('sysplugins.enable');
         return new PluginManager($enabled, $path, $enabledSysPlugins);
     };
     $DI['Url\\UrlGenerator'] = function ($DI) {
         return new Url\UrlGenerator($DI['Request'], $DI['Config']->get('nice_urls', false));
     };
     setlocale(LC_ALL, $DI['Config']->get('locale'));
     // Add custom PSR-4 plugin path to Composer autoloader
     $autoload = (require $this->vendorDir . '/autoload.php');
     $autoload->addPsr4('herbie\\sysplugin\\', __DIR__ . '/../plugins/');
     $autoload->addPsr4('herbie\\plugin\\', $DI['Config']->get('plugins.path'));
     // Init PluginManager at first
     if (true === $DI['PluginManager']->init($DI['Config'])) {
         Hook::trigger(Hook::ACTION, 'pluginsInitialized', $DI['PluginManager']);
         Hook::trigger(Hook::ACTION, 'shortcodeInitialized', $DI['Shortcode']);
         $DI['Menu\\Page\\Collection'] = function ($DI) {
             $DI['Menu\\Page\\Builder']->setCache($DI['Cache\\DataCache']);
             return $DI['Menu\\Page\\Builder']->buildCollection();
         };
         $DI['Menu\\Page\\Node'] = function ($DI) {
             return Menu\Page\Node::buildTree($DI['Menu\\Page\\Collection']);
         };
         $DI['Menu\\Page\\RootPath'] = function ($DI) {
             $rootPath = new Menu\Page\RootPath($DI['Menu\\Page\\Collection'], $DI['Request']->getRoute());
             return $rootPath;
         };
         $DI['Menu\\Post\\Collection'] = function ($DI) {
             $builder = new Menu\Post\Builder($DI['Cache\\DataCache'], $DI['Config']);
             return $builder->build();
         };
         $DI['Page'] = function ($DI) {
             try {
                 $route = $DI['Request']->getRoute();
                 $page = false;
                 if (false === $page) {
                     $menuItem = $DI['Url\\UrlMatcher']->match($route);
                     $path = $menuItem->getPath();
                     $page = new Page();
                     $page->setLoader($DI['Loader\\PageLoader']);
                     $page->load($path);
                     Hook::trigger(Hook::ACTION, 'pageLoaded', $page);
                 }
             } catch (\Exception $e) {
                 $page = new Page();
                 $page->layout = 'error.html';
                 $page->setError($e);
             }
             return $page;
         };
         $DI['Translator'] = function ($DI) {
             $translator = new Translator($DI['Config']->get('language'), ['app' => $DI['Alias']->get('@app/../messages')]);
             foreach ($DI['PluginManager']->getLoadedPlugins() as $key => $dir) {
                 $translator->addPath($key, $dir . '/messages');
             }
             $translator->init();
             return $translator;
         };
         $DI['Url\\UrlMatcher'] = function ($DI) {
             return new Url\UrlMatcher($DI['Menu\\Page\\Collection'], $DI['Menu\\Post\\Collection']);
         };
     }
 }
Пример #7
0
 /**
  *  Initiate the routing for the given URL
  */
 public static function route(Http\Request $request)
 {
     $path = $request->REQUEST_URI;
     $key = $request->getMethod() . '@' . $path;
     $keyAny = 'ANY@' . $path;
     $matchedRoute = null;
     $matchedScore = 0;
     if (isset(self::$routes[$key])) {
         $matchedRoute = self::$routes[$key];
     } elseif (isset(self::$routes[$keyAny])) {
         $matchedRoute = self::$routes[$keyAny];
     } else {
         foreach (self::$routes as $key2 => $route) {
             if ($route->getMethod() != 'ANY' && $route->getMethod() != $request->getMethod()) {
                 continue;
             }
             $score = $route->getScore($path, $request->getMethod());
             if ($score > $matchedScore) {
                 $matchedRoute = $route;
                 $matchedScore = $score;
             }
         }
     }
     if ($matchedRoute) {
         $matchedRoute->setUrl($path);
     } elseif (self::$_404route) {
         $matchedRoute = self::$_404route;
     } else {
         throw new Exceptions\RouteException('Route not found');
     }
     return $matchedRoute;
 }