/** * Register module * * @param Application $application * @throws Exception * @return Module */ public function register(Application $application) { parent::register($application); // Add route params for the controllers if (null !== $this->application->router()) { $this->application->router()->addControllerParams('*', ['application' => $this->application, 'console' => new \Pop\Console\Console(120, ' ')]); } if (!empty($this->application->config()['database']) && !empty($this->application->config()['database']['adapter'])) { $adapter = $this->application->config()['database']['adapter']; $options = ['database' => $this->application->config()['database']['database'], 'username' => $this->application->config()['database']['username'], 'password' => $this->application->config()['database']['password'], 'host' => $this->application->config()['database']['host'], 'type' => $this->application->config()['database']['type']]; $check = \Pop\Db\Db::check($adapter, $options); if (null !== $check) { throw new Exception('DB ' . $check); } $this->application->services()->set('database', ['call' => 'Pop\\Db\\Db::connect', 'params' => ['adapter' => $adapter, 'options' => $options]]); } if ($this->application->services()->isAvailable('database')) { Record::setDb($this->application->getService('database')); } // Set up triggers to check the application session $this->application->on('app.route.pre', function () { if (isset($_SERVER['argv'][1])) { echo PHP_EOL . ' App Console' . PHP_EOL; echo ' ===========' . PHP_EOL . PHP_EOL; } }, 1000); $this->application->on('app.dispatch.post', function () { echo PHP_EOL; }, 1000); return $this; }
/** * Register module * * @param Application $application * @throws Exception * @return Module */ public function register(Application $application) { parent::register($application); if (null !== $this->application->router()) { $this->application->router()->addControllerParams('*', ['application' => $this->application, 'request' => new Request(), 'response' => new Response()]); } if (!empty($this->application->config()['database']) && !empty($this->application->config()['database']['adapter'])) { $adapter = $this->application->config()['database']['adapter']; $options = ['database' => $this->application->config()['database']['database'], 'username' => $this->application->config()['database']['username'], 'password' => $this->application->config()['database']['password'], 'host' => $this->application->config()['database']['host'], 'type' => $this->application->config()['database']['type']]; $check = \Pop\Db\Db::check($adapter, $options); if (null !== $check) { throw new Exception('DB ' . $check); } $this->application->services()->set('database', ['call' => 'Pop\\Db\\Db::connect', 'params' => ['adapter' => $adapter, 'options' => $options]]); } if ($this->application->services()->isAvailable('database')) { Record::setDb($this->application->getService('database')); } if (isset($this->config['forms'])) { $this->application->mergeConfig(['forms' => $this->config['forms']]); } if (isset($this->config['resources'])) { $this->application->mergeConfig(['resources' => $this->config['resources']]); } $this->application->on('app.route.pre', 'App\\Event\\Ssl::check', 1000)->on('app.dispatch.pre', 'App\\Event\\Session::check', 1001)->on('app.dispatch.pre', 'App\\Event\\Acl::check', 1000); $this->initNav(); return $this; }
/** * Initialize the application * * @param Application $application * @throws \Phire\Exception * @return Module */ public function register(Application $application) { parent::register($application); // Set the database if ($this->application->services()->isAvailable('database')) { Record::setDb($this->application->getService('database')); $db = count($this->application->getService('database')->getTables()) > 0; } else { $db = false; } $this->application->mergeConfig(['db' => $db]); // Check PHP version if (version_compare(PHP_VERSION, '5.4.0') < 0) { throw new \Phire\Exception('Error: Phire CMS requires PHP 5.4.0 or greater.'); } // Add route params for the controllers if (null !== $this->application->router()) { $this->application->router()->addControllerParams('*', ['application' => $this->application, 'console' => new Console(120, ' ')]); } // Set up triggers to check the application session $this->application->on('app.route.post', 'Phire\\Event\\Db::check', 1000); $this->application->on('app.route.pre', function () { if (isset($_SERVER['argv'][1]) && ($_SERVER['argv'][1] != 'sql' && $_SERVER['argv'][1] != 'archive')) { echo PHP_EOL . ' Phire Console' . PHP_EOL; echo ' =============' . PHP_EOL . PHP_EOL; } }, 1000); $this->application->on('app.dispatch.post', function () { echo PHP_EOL; }, 1000); return $this; }
/** * Register module * * @param \Pop\Application $application * @return Module */ public function register(\Pop\Application $application) { parent::register($application); if (null !== $this->config) { // If the module has navigation $params = $this->application->services()->getParams('nav.phire'); // If the module has module-level navigation if (isset($this->config['nav.module'])) { if (!isset($params['tree']['modules']['children'])) { $params['tree']['modules']['children'] = []; } $params['tree']['modules']['children'] = array_merge([$this->config['nav.module']], $params['tree']['modules']['children']); } // If the module has system-level navigation if (isset($this->config['nav.phire'])) { $newNav = []; foreach ($this->config['nav.phire'] as $key => $value) { if ($key !== 'modules' && $key !== 'users' && $key !== 'config') { $newNav[$key] = $value; } else { $params['tree'][$key] = array_merge_recursive($params['tree'][$key], $value); } } if (count($newNav) > 0) { $params['tree'] = array_merge($newNav, $params['tree'], $this->config['nav.phire']); } } // If the module has ACL resources if (isset($this->config['resources'])) { $this->application->mergeConfig(['resources' => $this->config['resources']]); } // If the module has form configs if (isset($this->config['forms'])) { $this->application->mergeConfig(['forms' => $this->config['forms']]); } // If the module has a header include if (isset($this->config['header'])) { $header = array_merge([$this->config['header']], $this->application->config()['headers']); $this->application->mergeConfig(['headers' => $header]); } // If the module has a dashboard include if (isset($this->config['dashboard'])) { $dashboard = array_merge([$this->config['dashboard']], $this->application->config()['dashboard']); $this->application->mergeConfig(['dashboard' => $dashboard]); } // If the module has a dashboard side include if (isset($this->config['dashboard_side'])) { $dashboard_side = array_merge([$this->config['dashboard_side']], $this->application->config()['dashboard_side']); $this->application->mergeConfig(['dashboard_side' => $dashboard_side]); } // If the module has a footer include if (isset($this->config['footer'])) { $footer = array_merge([$this->config['footer']], $this->application->config()['footers']); $this->application->mergeConfig(['footers' => $footer]); } // Add the nav params back to the service $this->application->services()->setParams('nav.phire', $params); } return $this; }