public function __construct($refresh = false) { if (defined('PHPFOX_NO_APPS')) { return; } $base = PHPFOX_DIR_SITE . 'Apps/'; if (!is_dir($base)) { return; } if (self::$_apps !== null && !$refresh) { return; } self::$_apps = []; foreach (scandir($base) as $app) { if ($app == '.' || $app == '..') { continue; } $path = $base . $app . '/'; if (!file_exists($path . 'app.lock')) { continue; } $jsonData = file_get_contents($path . 'app.json'); $jsonData = preg_replace_callback('/{{ ([a-zA-Z0-9_]+) }}/is', function ($matches) use($jsonData) { $_data = json_decode($jsonData); if (!isset($_data->{$matches[1]})) { return $matches[0]; } return $_data->{$matches[1]}; }, $jsonData); $data = json_decode($jsonData); $data->path = $path; if (isset($data->routes)) { foreach ((array) $data->routes as $key => $route) { $route = (array) $route; $route['id'] = $data->id; Route::$routes = array_merge(Route::$routes, [$key => $route]); } } self::$_apps[$data->id] = $data; \Core\Route\Controller::$active = $data->path; \Core\Route\Controller::$activeId = $data->id; $vendor = $data->path . 'vendor/autoload.php'; if (file_exists($vendor)) { require_once $vendor; } if (file_exists($data->path . 'start.php')) { $callback = (require_once $data->path . 'start.php'); if (is_callable($callback)) { $View = new \Core\View(); $View->loader()->addPath($data->path . 'views/', $data->id); call_user_func($callback, $this->get($data->id), $View->env()); } } } // d(self::$_apps); exit; }
public function __construct() { if (defined('PHPFOX_NO_APPS')) { return; } $base = PHPFOX_DIR_SITE . 'Apps/'; if (!is_dir($base)) { return; } foreach (scandir($base) as $app) { if ($app == '.' || $app == '..') { continue; } $path = $base . $app . '/'; if (!file_exists($path . 'app.lock')) { continue; } $data = json_decode(file_get_contents($path . 'app.json')); $data->path = $path; if (isset($data->routes)) { self::$routes = array_merge(self::$routes, (array) $data->routes); } $this->_apps[$data->id] = $data; \Core\Route\Controller::$active = $data->path; \Core\Route\Controller::$activeId = $data->id; $vendor = $data->path . 'vendor/autoload.php'; if (file_exists($vendor)) { require_once $vendor; } if (file_exists($data->path . 'start.php')) { $callback = (require_once $data->path . 'start.php'); if (is_callable($callback)) { $View = new \Core\View(); $View->loader()->addPath($data->path . 'views/', $data->id); call_user_func($callback, $this->get($data->id), $View->env()); } } } // d($this->_apps); exit; }