/** * @param \Cygnite\Foundation\Application $app * @internal param $route */ public function __construct(ApplicationInterface $app) { $this->app = $app; $this->router = $app['router']; $this->default['controller'] = lcfirst(Config::get('global.config', 'default.controller')); $this->default['action'] = lcfirst(Config::get('global.config', 'default.method')); }
/** * Convert Html special characters. * * Encoding will be used based on configuration given in Config file. * * @false string $value * * @param $value * * @throws InvalidArgumentException * * @return string */ public static function specialCharacters($value) { if (is_null($value)) { throw new InvalidArgumentException('Cannot pass null argument to ' . __METHOD__); } return htmlspecialchars($value, ENT_QUOTES, Config::get('global.config', 'encoding'), false); }
/** * Constructor of File Cache * We will initialize file cache */ public function __construct() { $config = array('name' => Config::get('global.config', 'cache_name'), 'path' => Config::get('global.config', 'cache_directory'), 'extension' => Config::get('global.config', 'cache_extension')); if ($config['path'] == "") { throw new InvalidCacheDirectoryException('You must define cache directory to use cache.'); } $this->initialize($config); }
/** * Set Social OAuth Configuration. * * @return void */ protected function configureSocialAuth() { $this->config = Config::get('global.config', 'social.config'); if (isset($this->config['active']) && !empty($this->config['active'])) { return true; } return false; }
/** * @return RedisConnector|null */ private static function getRedisDriver() { $config = Config::get('global.config', 'cache'); $redis = null; if (isset($config['redis'])) { $redis = new RedisConnector(new RedisClient(), $config['redis']); } return $redis; }
/** * Constructor of File Cache * We will initialize file cache */ public function __construct() { $config = Config::get('global.config', 'cache'); $data = ['name' => $config['file']['name'], 'path' => $config['file']['directory'], 'extension' => $config['file']['extension']]; if ($data['path'] == "") { throw new InvalidCacheDirectoryException('You must define cache directory to use cache.'); } $this->setup($data); }
/** * Constructor of Mailer * * Configure Mailer to send email * * @param null $swift */ public function __construct($swift = null) { if (!is_null($swift)) { $this->swift = $swift; } $this->emailConfig = Config::get('global.config', 'email.configurations'); //set transport type protocol $this->setTransportType($this->emailConfig['protocol']); }
/** * Session Constructor. */ public function __construct() { /* | We will set session configuration into config property | Based on user defined configuration we will load the session | driver */ $this->config = Config::get('config.session'); $this->setName($this->config['session_name']); }
/** * Constructor function * @false string - encryption key * */ public function __construct() { $encryptKey = Config::get('global.config', 'cf_encryption_key'); if (is_null($encryptKey)) { $config = (include_once CYGNITE_BASE . DS . APPPATH . DS . 'configs' . DS . 'application' . EXT); $this->setSaltKey($config['cf_encryption_key']); } else { $this->setSaltKey($encryptKey); } }
public function __construct() { $this->emailConfig = Config::get('global.config', 'emailConfiguration'); try { Application::import('vendor' . DS . $this->emailConfig['swift_mailer_path']); } catch (Exception $ex) { throw new Exception($ex->getMessage()); } //set transport type protocol $this->setTransportType($this->emailConfig['protocol']); }
public function __construct() { Config::get('global.config', 'cache_name'); $cache_config = array('name' => Config::get('global.config', 'cache_name'), 'path' => Config::get('global.config', 'cache_directory'), 'extension' => Config::get('global.config', 'cache_extension')); $this->initialize($cache_config); if (Config::get('global.config', 'cache_directory') == "none") { throw new \Exception('You must define cache directory to use cache.'); } else { $this->_cachePath = APPPATH . Config::get('global.config', 'cache_directory') . '/'; } }
/** * @return bool */ public function terminate() { /**------------------------------------------------------------------ * Throw Exception is default controller * has not been set in configuration * ------------------------------------------------------------------ */ if (is_null(Config::get('global.config', "default_controller"))) { trigger_error("Default controller not found ! Please set the default\n controller in configs/application" . EXT); } Application::import(APPPATH . '.routes'); }
/** * Constructor function * @false string - encryption key * */ public function __construct() { $encryptKey = Config::get('global.config', 'cf_encryption_key'); if (!is_null($encryptKey)) { $this->set($encryptKey); if (!function_exists('mcrypt_create_iv')) { throw new \BadFunctionCallException("Mcrypt extension library not loaded"); } $this->iv = mcrypt_create_iv(32); } else { throw new \BadFunctionCallException("Please check for encription key inside config file and autoload helper encrypt key is set or not."); } }
/** * Validate user request and send response to browser * * @throws \Exception * @return mixed */ public function run() { // If no argument passed or single slash call default controller if ($this->router->getCurrentUri() == '/' || $this->router->getCurrentUri() == '/' . self::$indexPage) { if ($this->default['controller'] != '') { list($controller, $action) = $this->getControllerAndAction($this->default['controller'], $this->default['action']); $response = $this->handleControllerDependencies($controller, $action); } } else { $routeConfig = Config::get('config.router'); $newUrl = str_replace('/index.php', '', rtrim($this->router->getCurrentUri())); $exp = array_filter(explode('/', $newUrl)); $matchedUrl = $this->matches($routeConfig); //Check with router configuration if matched then call defined controller if (!is_null($matchedUrl)) { $requestUri = preg_split('/[\\.\\ ]/', $matchedUrl['controllerPath']); // We are matching with static routing if match then dispatch it list($controller, $action) = $this->getControllerAndAction($requestUri[0], $requestUri[1]); if (!class_exists($controller)) { throw new Exception('Unhandled Exception (404 Page)'); } $params = (array) $matchedUrl['params']; $response = $this->handleControllerDependencies($controller, $action, $params); } else { // Process user request provided in url $controller = $method = $param = $instance = null; $controller = $exp[1]; if (isset($exp[2])) { $method = $exp[2]; } $params = array_slice($exp, 2); $controllerDir = ''; if (is_dir(CYGNITE_BASE . str_replace('\\', DS, strtolower("\\" . APPPATH . $this->app->namespace . $exp[1])))) { $controllerDir = ucfirst($exp[1]); $controller = $exp[2]; $method = $exp[3]; $params = array_slice($exp, 3); } $action = isset($method) ? $method : 'index'; list($controller, $action) = $this->getControllerAndAction($controller, $action, $controllerDir); if (!class_exists($controller)) { throw new Exception('Unhandled Exception (404 Page)'); } $response = $this->handleControllerDependencies($controller, $action, $params); } } return $response; }
public function setSessionConfig() { /* | Get user configuration */ $config = Config::get('config.session'); $sessionManager = $this->getWrapper(); $sessionManager->setHash(); // set session hash // We will use session cookie if configured if ($config['use_session_cookie']) { $sessionManager->useOnlyCookie(); // use cookie } // Make sure the session cookie is not accessible via javascript. $sessionManager->setCookieParams($config['secure'], $config['httponly']); }
/** * Set Stripe Configuration. * * @return void */ protected function configureOmnipay() { $this->config = Config::get('global.config', 'omnipay.config'); }
/** * Enable and set configuration to Tracy Handler * Event will Trigger this method on runtime when any exception * occurs */ public function handleException() { /* | Exception handler registered here. So it will handle all | exceptions and thrown as pretty format |----------------------------------- | Enable pretty exception handler and | do necessary configuration |----------------------------------- */ $config = Config::get('global.config'); $this->enable($config['logs']['activate'], $config['logs']['path'])->setTitle()->setDebugger(Debugger::getBlueScreen())->setEmailAddress($config['logs']['email'], $config['logs']['error.emailing'])->run(); }
private function getConfigParameter() { $data = [lcfirst(Config::get('global.config', 'default.controller')), lcfirst(Config::get('global.config', 'default.method'))]; return $data; }
/** * @return static */ public static function create() { $encryptKey = Config::get('global.config', 'encryption.key'); if (self::$instance === null) { self::$instance = new static($encryptKey); } return self::$instance; }
/** * @param $module * @return bool */ public function bootstrapModule($module) { $config = Config::get('module'); $modulePath = $config['module.path'] . DS; $moduleConfigDir = $config['module.config'] . DS; $class = '\\' . APP_NS . '\\' . $this->getModuleDir() . '\\' . ucfirst($module) . '\\BootStrap'; $file = $modulePath . ucfirst($module) . DS . $moduleConfigDir . strtolower($module) . EXT; if (!file_exists($file)) { return false; } Config::setConfigurationItems(strtolower($module) . '.config', include $file); return (new $class())->register($this->getApplication(), $file); }
/** * Initialize and do all configuration then start booting */ public function initialize() { /** * Set Environment for Application * Example: * <code> * define('DEVELOPMENT_ENVIRONMENT', 'development'); * define('DEVELOPMENT_ENVIRONMENT', 'production'); * </code> */ define('MODE', Config::get('global.config', 'environment')); global $event; if (MODE == 'development') { ini_set('display_errors', 1); error_reporting(E_ALL); } else { ini_set('display_error', 0); error_reporting(0); } $event->trigger("exception"); /** *-------------------------------------------------- * Turn on application if profiling is on * in configuration *-------------------------------------------------- */ if (Config::get('global.config', 'enable_profiling') == true) { Profiler::start(); } /** -------------------------------------------------- * Set Cygnite user defined encryption key * --------------------------------------------------- */ if (!is_null(Config::get('global.config', 'cf_encryption_key')) || in_array('encrypt', Config::get('config.autoload', 'helpers')) == true) { define('CF_ENCRYPT_KEY', Config::get('global.config', 'cf_encryption_key')); } /**---------------------------------------------------------------- * Get Session config and set it here * ---------------------------------------------------------------- */ define('SECURE_SESSION', Config::get('config.session', 'cf_session')); /**---------------------------------------------------------------- * Auto load Session library based on user configurations * ---------------------------------------------------------------- */ if (SECURE_SESSION === true) { Session::instance(); } /**------------------------------------------------------------------ * Throw Exception is default controller * has not been set in configuration * ------------------------------------------------------------------ */ if (is_null(Config::get('global.config', "default_controller"))) { trigger_error("Default controller not found ! Please set the default\n\t\t\t\t\t\t\tcontroller in configs/application" . EXT); } }
function show($resultArray = array(), $hasExit = "") { echo '<pre>'; print_r($resultArray); echo '</pre>'; if ($hasExit === 'exit') { exit; } } global $event; //create Event handler to attach all events $event = new Event(); $event->attach("exception", '\\Cygnite\\Exception\\Handler@handleException'); $config = array(); //Get the configuration variables. $config = array('app' => Config::load(), 'event' => $event); //unset($config); //Load application and Get application instance to boot up $application = Application::instance(function ($app) use($config) { /** *--------------------------------------------------- * Set Configurations and Events for boot-up process * -------------------------------------------------- */ return $app->setConfiguration($config)->boot(); }); //Response to browser $application->run(); if (Config::get('global.config', 'enable_profiling') == true) { Profiler::end(); }
/** * Start booting and handler all user request * * @return Dispatcher */ public function boot() { //Set up configurations for your awesome application Config::set('config.items', $this['config']); //Set URL base path. Url::setBase(Config::get('global.config', 'base_path') == '' ? $this['router']->getBaseUrl() : Config::get('global.config', 'base_path')); $this['service.provider'](); //initialize framework $this['boot']->initialize($this); $this['boot']->terminate(); return $this; }
/** * Run user quest and call controller * * @return mixed */ public function run() { $dispatcher = null; $dispatcher = $this; // If no argument passed or single slash call default controller if ($this->router->getCurrentUri() == '/' || $this->router->getCurrentUri() == '/' . self::$indexPage) { if ($this->default['controller'] != '') { //Static route: / (Default Home Page) $response = $this->router->get('/', function () use($dispatcher) { return Application::instance(function ($app) use($dispatcher) { $controller = $app->getController($dispatcher->default['controller']); $action = $app->getActionName($dispatcher->default['action']); $instance = $app->make($controller); $app->propertyInjection($instance, $controller); return call_user_func_array(array($instance, $action), array()); }); }); } } else { $routeConfig = Config::get('config.router'); $newUrl = str_replace('/index.php', '', rtrim($this->router->getCurrentUri())); $exp = array_filter(explode('/', $newUrl)); $matchedUrl = $this->matches($routeConfig); //Check with router configuration if matched then call defined controller if (!is_null($matchedUrl)) { $requestUri = preg_split('/[\\.\\ ]/', $matchedUrl['controllerPath']); // We are matching with static routing if match then dispatch it $response = Application::instance(function ($app) use($requestUri, $matchedUrl, $dispatcher) { $controller = $app->getController($requestUri[0]); $action = $app->getActionName($requestUri[1]); if (!class_exists($controller)) { throw new Exception('Unhandled Exception (404 Page)'); } $params = (array) $matchedUrl['params']; $instance = $app->make($controller); $app->propertyInjection($instance, $controller); return call_user_func_array(array($instance, $action), $params); }); } else { // Process user request provided in url $response = Application::instance(function ($app) use($exp, $dispatcher) { $controller = $method = $param = $instance = null; $controller = $exp[1]; if (isset($exp[2])) { $method = $exp[2]; } $params = array_slice($exp, 2); $controllerDir = ''; if (is_dir(CYGNITE_BASE . str_replace('\\', DS, strtolower($app->namespace . $exp[1])))) { $controllerDir = ucfirst($exp[1]); $controller = $exp[2]; $method = $exp[3]; $params = array_slice($exp, 3); } $controller = $app->getController($controller, $controllerDir); $action = isset($method) ? $method : 'index'; $action = $app->getActionName($action); if (!class_exists($controller)) { throw new Exception('Unhandled Exception (404 Page)'); } $instance = $app->make($controller); $app->propertyInjection($instance, $controller); return call_user_func_array(array($instance, $action), $params); }); } } $this->router->run(); return $response; }
/** * We will activate middle ware events if set as true in * Configs/application.php * @return mixed */ public function activateEventMiddleWare() { $eventMiddleware = Config::get('global.config', 'activate.event.middleware'); if ($eventMiddleware) { $class = "\\" . APP_NS . "\\Middleware\\Events\\Event"; return (new $class())->register($this); } }
/** * Start booting and handler all user request * @return Dispatcher */ public function boot() { Url::instance($this['router']); //Set up configurations for your awesome application Config::set('config.items', $this['config']); //Set URL base path. Url::setBase(Config::get('global.config', 'base_path') == '' ? $this['router']->getBaseUrl() : Config::get('global.config', 'base_path')); //initialize framework $this['boot']->initialize(); $this['boot']->terminate(); /**------------------------------------------------------- * Booting completed. Lets handle user request!! * Lets Go !! * ------------------------------------------------------- */ return new Dispatcher($this['router']); }
/** * Set Stripe Configuration. * * @return void */ protected function configureStripe() { $this->config = Config::get('global.config', 'stripe.config'); }
<?php use Cygnite\Common\UrlManager\Url; use Cygnite\Helpers\Config; define('APP', str_replace('src/', 'src' . DS, APPPATH)); //Set URL base path. Url::setBase(Config::get('global.config', 'base_path') == '' ? $app['router']->getBaseUrl() : Config::get('global.config', 'base_path')); /* * -------------------------------------------------- * Set application encryption key * --------------------------------------------------- */ if (!is_null(Config::get('global.config', 'encryption.key'))) { define('CF_ENCRYPT_KEY', Config::get('global.config', 'encryption.key')); } /* * ---------------------------------------------------- * Throw Exception is default controller * has not been set in configuration * ---------------------------------------------------- */ if (is_null(Config::get('global.config', 'default.controller'))) { throw new \Exception('You must set default controller in ' . APPPATH . '/Configs/application.php'); }
/** * Enable and set configuration to Tracy Handler * Event will Trigger this method on runtime when any exception * occurs */ public function handleException() { $config = Config::get('global.config'); // Exception handler registered here. So it will handle all your exception // and throw you pretty format Handler::register(function ($exception) use($config) { /* |----------------------------------- | Enable pretty exception handler and | do necessary configuration |----------------------------------- */ $exception->enable($config)->setTitle()->setDebugger(Debugger::getBlueScreen())->setEmailAddress($config['params']['log_email'], $config['enable_error_emailing'])->run(); unset($config); }); }
public function __construct($name = null, $cacheLimiter = null, $wrapperInstance = null) { $this->name = $name; /* | Override native session handler */ $this->sessionSaveHandler(); /* | Get user configuration */ $this->config = Config::get('config.session'); /* | Set Database and Table for storing | session into database */ $this->database($this->config['database_name']); $this->table($this->config['table']); $this->setWrapperInstance($wrapperInstance); /* |Check if session started if not we will start new session |if session started already we will try */ if (!session_id()) { $this->start(); } $this->storage =& $_SESSION; /* | Check csrf token already exists into session | else regenerate the token */ $this->checkToken(); // This line prevents unexpected effects when using objects as save handlers. register_shutdown_function('session_write_close'); }