PHP App::config Examples

PHP App::config - 30 examples found. These are the top rated real world PHP examples of App::config extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 /**
  * @param string $config
  *
  * @return \Songbird\App
  */
 public static function createApplication($config = '')
 {
     $app = new App(require __DIR__ . '/../config/di.php');
     $app->add('Config', new Config($config));
     $app->add('Symfony\\Component\\HttpFoundation\\Response', new Response());
     $app->add('Symfony\\Component\\HttpFoundation\\Request', Request::createFromGlobals());
     $app->add('Filesystem', 'League\\Flysystem\\Filesystem')->withArgument(new CachedAdapter(new Adapter($app->config('app.paths.resources')), new CacheStore()));
     $app->get('Logger')->pushHandler(new StreamHandler(vsprintf('%s/songbird-%s.log', [$app->config('app.paths.log'), date('Y-d-m')]), Logger::INFO));
     $app->inflector('League\\Container\\ContainerAwareInterface')->invokeMethod('setContainer', [$app]);
     $app->inflector('League\\Event\\EmitterAwareInterface')->invokeMethod('setEmitter', [$app->get('Emitter')]);
     $app->inflector('Psr\\Log\\LoggerAwareInterface')->invokeMethod('setLogger', [$app->get('Logger')]);
     $app->inflector('Songbird\\FilesystemAwareInterface')->invokeMethod('setFilesystem', ['Filesystem']);
     $app->add('Repository', $app->get('RepositoryFactory')->createContentRepository());
     return $app;
 }
Example #2
0
 public static function getConfig($key)
 {
     if (self::$config === null) {
         self::$config = (include_once 'app/config/main.php');
     }
     return isset(self::$config[$key]) ? self::$config[$key] : false;
 }
Example #3
0
 public static function start()
 {
     self::configuration(json_decode(App::config()->file('Sessions.sessions.json')->read(), true));
     if (session_status() == PHP_SESSION_NONE) {
         ini_set('session.cookie_httponly', true);
         //start session
         //set session name
         session_name(self::$_sessionName);
         session_start();
         //generate key
         Session::generate(self::$_userSessionsKey);
         Cookie::generate(self::$_userCookiesKey);
         //check initiated status
         if (intval(Session::get(self::$_initiatedKey)) == 0) {
             //regen
             session_regenerate_id();
             Session::generate(self::$_userSessionsKey);
             Session::set(self::$_initiatedKey, 1);
         }
         //check for corresponding user agent on same session
         if (Session::get(self::$_userAgentKey) !== false) {
             if (Session::get(self::$_userAgentKey) != hash('sha512', $_SERVER['HTTP_USER_AGENT'] . self::$_salt)) {
                 //invalid user agent detected
                 self::destroy();
                 die;
             }
         } else {
             Session::set(self::$_userAgentKey, hash('sha512', $_SERVER['HTTP_USER_AGENT'] . self::$_salt));
         }
     }
 }
Example #4
0
 public function __construct()
 {
     include 'config/config.php';
     include 'core/Controller.php';
     self::$config = $config;
     $this->route();
 }
Example #5
0
 static function init()
 {
     $version_file = APP_PATH . '/../version';
     if (file_exists($version_file)) {
         self::$version = trim(@file_get_contents($version_file));
     }
     $config_file = APP_PATH . '/config/config.php';
     if (!file_exists($config_file)) {
         throw new Exception("No config file");
     }
     $config = (include $config_file);
     self::$config = $config;
     self::$env = $config['env'];
     #self::$context = new stdClass();
     self::$context = new Context();
     Logger::init($config['logger']);
     if (isset($config['db'])) {
         Db::init($config['db']);
     }
     if (get_magic_quotes_gpc()) {
         foreach ($_GET as $k => $v) {
             $_GET[$k] = Text::stripslashes($v);
         }
         foreach ($_POST as $k => $v) {
             $_POST[$k] = Text::stripslashes($v);
         }
         foreach ($_COOKIE as $k => $v) {
             $_COOKIE[$k] = Text::stripslashes($v);
         }
     }
     $_REQUEST = $_GET + $_POST + $_COOKIE;
 }
Example #6
0
 /**
  * 运行应用实例
  * @access public
  * @return void
  */
 public function run()
 {
     //引入编译、缓存过的引入文件
     $compiledIncFile = $this->getCompiledIncFileName();
     if (App::config('compile_include_files') && is_file($compiledIncFile)) {
         self::$includeFiles = (require $compiledIncFile);
     }
     //检测控制器文件是否存在
     if (!is_file(APP_PATH . '/controller/' . self::$controller . 'Controller.class.php')) {
         die("<h1>Invalid Request</h1>\nController <strong>" . self::$controller . "</strong> not found.");
     }
     //导入必需文件
     irequire(PHPFW_PATH . '/common/common.php');
     is_file(APP_PATH . '/common/common.php') && irequire(APP_PATH . '/common/common.php');
     irequire(PHPFW_PATH . '/core/Controller.class.php');
     irequire(APP_PATH . '/controller/' . self::$controller . 'Controller.class.php');
     //实例化控制器并运行
     $controllerName = self::$controller . 'Controller';
     $controller = new $controllerName();
     $controller->run(self::$action);
     //编译、缓存 引入文件
     if (App::config('compile_include_files') && !is_file($compiledIncFile)) {
         $this->compileIncFiles();
     }
 }
 /**
  * @param  DownloadTokenModel $downloadToken
  * @return DownloadTokenModel
  */
 public function create(models\ModelAbstract $downloadToken)
 {
     if (!$downloadToken instanceof DownloadTokenModel) {
         throw new InvalidArgumentException('Supplied data must be a download token model');
     }
     $downloadToken->token = UserService::getInstance()->generatePassword(60);
     $brandService = BrandService::getInstance();
     $brand = $brandService->loadByOrganization(\App::getOrgUserLogged());
     $router = \Zend_Controller_Front::getInstance()->getRouter();
     $downloadToken->url = $brand->endPoint . $router->assemble(array('controller' => $downloadToken->controller, 'action' => $downloadToken->action, 'token' => $downloadToken->token), 'downloadToken');
     $downloadToken->orgId = \App::getOrgUserLogged()->getId();
     $downloadToken->expireDatetime = \App::config('downloadTokenLifeTime', "+1 day");
     $ident = \Zend_Auth::getInstance()->getIdentity();
     if (isset($ident['username'])) {
         $downloadToken->username = $ident['username'];
     }
     if (isset($ident['authType'])) {
         $downloadToken->authType = $ident['authType'];
     }
     if (isset($ident['apiId'])) {
         $downloadToken->apiId = $ident['apiId'];
     }
     if (isset($ident['impersonation'])) {
         $downloadToken->impersonation = $ident['impersonation'];
     }
     return parent::create($downloadToken);
 }
Example #8
0
 protected function __construct($config)
 {
     if (count($config) != 4) {
         throw new \Exception("Le nombre d'arguments n'est pas valable!");
     }
     self::$config = $config;
 }
 public function setUp()
 {
     $this->_watcherService = WatcherService::getInstance();
     $this->_txId = uniqid('test-', true);
     $user = \App::getUserLogged();
     $this->_watcher = new WatcherModel();
     $this->_watcher->scope = 'user';
     $this->_watcher->scopeId = $user->id;
     $this->_watcher->owner = $user->id;
     $this->_watcher->namespace = 'connectivity';
     $this->_watcher->entityType = 'transaction';
     $this->_watcher->entityIds = array($this->_txId);
     $this->_watcher->transport = 'popbox';
     $this->_watcher->priority = WatcherModel::PRIORITY_LOW;
     $this->_watcher->status = WatcherModel::STATUS_ACTIVE;
     $this->_watcher->expire = strtotime(\App::config('watchers.expire', "+1 day"));
     $this->_watcher->remove = strtotime(\App::config('watchers.autoremove', "+6 months"));
     $this->_watcher->tags = array('context_' . $user->getOrganizationId());
     $this->_watcher->maxEvents = 1;
     $this->_watcher->maxEventStackSize = 1;
     $this->_watcher->params = new StructConfigModel();
     $this->_watcher->hiddenParams = new StructConfigModel();
     $this->_event = new EventModel();
     $this->_event->namespace = 'connectivity';
     $this->_event->entityType = 'transaction';
     $this->_event->entityId = $this->_txId;
     $this->_event->created = time();
     $this->_event->modified = time();
     $this->_event->pushEventData = true;
 }
 protected function _getConfigMaxErrorsBeforeCompress()
 {
     if (!isset($this->_configMaxErrorsBeforeCompress)) {
         $this->_configMaxErrorsBeforeCompress = \App::config('watcher.event.maxErrorsBeforeCompress', 15);
     }
     return $this->_configMaxErrorsBeforeCompress;
 }
Example #11
0
 /**
  * close the application, by creating a CLOSED file
  * @param string $message the message to display
  * @since 1.2
  */
 public static function close($message = '')
 {
     $file = App::configPath('CLOSED');
     file_put_contents($file, $message);
     if (App::config()) {
         chmod($file, App::config()->chmodFile);
     }
 }
Example #12
0
 /**
  * Get the default disco twig loader which enables extension-less template use.
  *
  *
  * @param null|string|array $path The absolute path to the template directory, or an array of directories.
  *
  * @return \Disco\classes\TemplateLoader
  */
 public static function defaultLoader($path = null)
 {
     if ($path === null) {
         $path = \App::path() . '/' . trim(\App::config('TEMPLATE_PATH'), '/');
     }
     //if
     return new \Disco\classes\TemplateLoader($path);
 }
Example #13
0
 /**
  * 构造方法
  *
  * @param App $app
  */
 public function __construct($app)
 {
     $this->app = $app;
     $this->appConfig = $app->config();
     $this->request = $app->request();
     $this->response = $app->response();
     $app->controller = $this;
 }
Example #14
0
 /**
  * Get the app. It's a singleton.
  * @param  array $config  The default config
  * @return App
  */
 public static function getApp($config)
 {
     if (self::$_app === null) {
         self::$config = (include_once $config);
         self::$_app = new App();
     }
     return self::$_app;
 }
Example #15
0
 /**
  * Hash with sha512.
  * If no salt is provided the salt stored in `app/config/config.php` with key `SHA512_SALT` will be used as the 
  * salt value.
  *
  *
  * @param  string $value Value to hash using SHA512.
  * @param null|string $salt The salt to use in the hash.
  *
  * @return string The hashed value of $s.
  */
 public function hash($value, $salt = '')
 {
     if ($salt === '') {
         $salt = \App::config('SHA512_SALT');
     }
     //if
     return hash('sha512', $salt . $value);
 }
Example #16
0
 /**
  * put your comment there...
  * 
  * @param string $tpl
  * @param string $class
  * @return BaseLayout
  */
 static function layout($tpl = null, $class = 'Layout')
 {
     if ($tpl !== null) {
         Core::load($class, Core::kFTLayout);
         //			include kFWCorePath.'/layouts/'.$class.kPhpExt;
         self::$_layout = new $class($tpl, App::config());
     }
     return self::$_layout;
 }
Example #17
0
 protected function __construct($config)
 {
     if (count($config["db"]) != 4) {
         throw new \Exception("Le nombre d'arguments n'est pas valable!");
     }
     spl_autoload_register(array(__CLASS__, 'autoload'));
     self::$config = $config;
     self::$database = new Core\Db\ConnectPDO(self::$config["db"]);
 }
Example #18
0
 public function setUp()
 {
     // Session
     $this->_data = 'party rock';
     $this->_id = md5($this->_data);
     // Mongo
     $collection = \App::config('resources.session.saveHandler.options.collection');
     $this->_handler = new \App_Session_SaveHandler_Mongo(array('collection' => $collection));
     $this->_collection = \App::get('mongo')->{$collection};
 }
Example #19
0
 /**
  * Validate every call against CSRF if it's a POST call
  * and there's an available token on the session.
  * */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     // Avoid error override! :S
     if (count($this->getResponse()->getException())) {
         return;
     }
     $auth = Zend_Auth::getInstance();
     $identity = $auth->getIdentity();
     $byPassMethods = array(App_Controller_Plugin_Auth::AUTH_TYPE_LOST_PASSWORD, App_Controller_Plugin_Auth::AUTH_TYPE_ASYNC, App_Controller_Plugin_Auth::AUTH_TYPE_EXTERNAL, App_Controller_Plugin_Auth::AUTH_TYPE_THIRD_PARTY);
     $byPassModules = array('async', 'external', 'externalr12', 'thirdparty');
     //Bypass some auth methods
     if (in_array($request->module, $byPassModules) || $identity['authType'] && in_array($identity['authType'], $byPassMethods)) {
         return;
     }
     $session = new Zend_Session_Namespace('csrf');
     if (empty($session->token)) {
         // Generate a new CSRF token and save it on the session
         \App::log()->info("Session token empty, generating new CSRF token...");
         $session->token = $this->_generateToken();
     }
     // Return the token on an HTTP header
     $resp = $this->getResponse();
     $resp->setHeader('X-CSRF-Token', $session->token);
     // Don't do anything if it's a GET request
     if ($request->isGet()) {
         return;
     }
     $post = $request->getPost();
     if (empty($post) && empty($_FILES)) {
         $max = ini_get('post_max_size');
         $length = $request->getServer('CONTENT_LENGTH');
         if ($max < $length) {
             return;
         }
     }
     // Try to get the CSRF token from frontend
     if (!($csrfToken = $this->_getFrontendToken($request))) {
         $message = 'Possible CSRF attack: CSRF token not found on request';
         $this->_throwError($request, $message);
         return;
     }
     // Disable plugin for dev environment
     if (App::config('csrf.disabled', false) && $csrfToken == 'dev') {
         return true;
     }
     // If tokens don't match log a possible CSRF attack a throw an exception
     if ($session->token != $csrfToken) {
         $message = 'Possible CSRF attack: BE and FE tokens don\'t match';
         $this->_throwError($request, $message);
         return;
     }
 }
 public function setUp()
 {
     $config = \App::config();
     $this->_config = $config['resources']['tests']['rest'];
     $this->_httpClient = new Zend_Http_Client();
     $this->_httpClient->setMethod(Zend_Http_Client::POST);
     $this->_httpClient->setAuth($this->_config['username'], $this->_config['password']);
     if (empty($this->_config['timeout'])) {
         $this->_config['timeout'] = 30;
     }
     $this->_httpClient->setConfig(array('timeout' => $this->_config['timeout']));
     $this->_baseUri = $this->_config['apiBaseUrl'] . '/';
 }
Example #21
0
 public static function run($config)
 {
     try {
         self::$config = $config;
         self::$appName = $config['appName'];
         self::$layout = $config['layout'];
         self::$path = $config['path'];
         self::$params = $config['params'];
         self::importClasses();
         self::startController();
     } catch (\AppException $e) {
         echo $e;
     }
 }
Example #22
0
 public function __construct($group)
 {
     $cfg = \App::config()->get("cache.groups.{$group}");
     if (!$cfg) {
         user_error("Cache group {$group} is undefined.");
     }
     $adapter = $cfg->adapter;
     if (strpos($adapter, "\\") === false) {
         $adapterclass = "\\Cherry\\Cache\\" . $adapter . "adapter";
     } else {
         $adapterclass = $adapter;
     }
     $this->adapter = new $adapterclass();
 }
Example #23
0
 static function init()
 {
     header("Content-Type:text/html;charset=utf8");
     header('X-Powered-By: es 1.0');
     error_reporting(E_ALL ^ E_NOTICE);
     date_default_timezone_set('Asia/Shanghai');
     session_start();
     if (empty(App::$config) && file_exists(APP_FILE . 'config.dev.php')) {
         App::$config = (include APP_FILE . 'config.dev.php');
     }
     if (file_exists(APP_FILE . 'config.pro.php') && ($_dev = (include APP_FILE . 'config.pro.php'))) {
         APP::$config = array_merge(APP::$config, $_dev);
     }
     define('__ROOT__', str_replace($_SERVER['DOCUMENT_ROOT'], "", str_replace('\\', '/', realpath(dirname(__FILE__) . '/../'))));
 }
Example #24
0
 /**
  * Validate the form and returns the result at view
  *
  * @param  string  $ruleset Ruleset
  * @param  array   $params  Form parameters
  * @return boolean
  */
 public function direct($ruleset, $params, $msg = null)
 {
     // Add '[]' suffix to array params
     foreach ($params as $k => $v) {
         if (is_array($v)) {
             unset($params[$k]);
             // Convert to numeric array
             $params[$k . '[]'] = array_values($v);
         }
     }
     try {
         $runner = new App_Controller_Action_Helper_Validate_NodeRunner();
         $runner->setOption('url', App::config('validate.node.url'));
         $runner->assign('AJAX_BASE_URL', App::config('validate.ajaxBaseUrl'));
         $result = $runner->validate($ruleset, $params);
     } catch (Simcity_Controller_Helper_Validate_Exception $e) {
         App::log()->warn('Running validate for "' . $ruleset . '": ' . $e->getMessage());
         App::log()->info('Fallback to Rhino based validation');
         $runner = new Simcity_Controller_Helper_Validate_RhinoRunner();
         $runner->setLogger(App::log());
         $runner->setOption('command', App::config('validate.rhino.command'));
         $runner->setOption('tmpdir', App::config('validate.rhino.tmpdir', null));
         $runner->loadLibraries(App::config('validate.rhino.libsPath'));
         $runner->loadRulesets(App::config('validate.rhino.rulesetsPath'));
         $runner->assign('AJAX_BASE_URL', App::config('validate.ajaxBaseUrl'));
         $result = $runner->validate($ruleset, $params);
     }
     // Remove '[]' suffix from array params
     foreach ($result as $k => $v) {
         if (substr($k, -2) === '[]') {
             $result[substr($k, 0, -2)] = $v;
         }
     }
     App::log()->info('Validation result:');
     App::log()->info(print_r($result, true));
     // Set the result object in the view automatically
     $this->getActionController()->view->result = $result;
     if ($runner->hasErrors()) {
         $fm = $this->getActionController()->getHelper('flashMessenger');
         if (empty($msg)) {
             $msg = 'Please correct the errors shown below and try again';
         }
         $fm->setNamespace('error')->addMessage($msg);
         return false;
     } else {
         return $result;
     }
 }
 public function indexAction()
 {
     if (!isset($_GET['ok'])) {
         echo '<a href="?r=install&ok">Click here to INSTALL</a>';
     } else {
         $sqls = explode("\n", file_get_contents(APP_PATH . '/config/db.sql'));
         $sql = '';
         foreach ($sqls as $line) {
             $sql .= $line;
             if (preg_match('/;$/', trim($line))) {
                 $sql = str_replace('{TABLE_PREFIX}', App::config('db_table_prefix'), $sql);
                 $this->db()->query($sql);
                 $sql = '';
             }
         }
         echo 'install success <A HREF="index.php">Go to HOME</A>';
     }
 }
 protected function _createAsyncConsumptionReportEricsson($params, $columns)
 {
     $methodName = self::METHOD_CONSUMPTION_ASYNC_REPORT;
     try {
         $proto = $this->_createProto($methodName);
         $proto = $this->_constructProtoConsumptionReport($params, $proto);
         $proto->setColumnsOnReport($columns);
         $watcher = $this->_constructWatcherToTransaction();
         $watcher->entityType = 'report';
         $watcher->params->reportType = "consumption";
         $watcher->params->params = $params;
         $watcher->params->fileName = $watcher->entityType . '-' . (@$params['fileType'] ?: 'raw') . ".csv";
         $watcher->remove = strtotime(\App::config('reports.autoremove', "+1 year"));
         return $this->_sendAsyncRequest($methodName, $proto, array(), array(), $watcher);
     } catch (Exception $e) {
         \App::log()->CRIT($e);
         throw $e;
     }
 }
 /**
  * 架构函数
  * @access public
  * @param mixed $data 要创建的数据对象内容
  */
 public function __construct()
 {
     //初始化
     parent::__construct(App::config('db_host'), App::config('db_user'), App::config('db_password'), App::config('db_database'), App::config('db_charset'), App::config('db_pconnect'));
     //完整表名、表主键、表前缀
     $tablePrefix = $this->tablePrefix !== null ? $this->tablePrefix : App::config('db_table_prefix');
     $this->trueTableName = $tablePrefix . $this->tableName;
     $this->primaryKeys[$this->trueTableName] = $this->primaryKey;
     /**
      * 转化手工指定的表字段为:DESCRIBE tableName 查询出来的格式
      * 最佳的方法是缓存 DESCRIBE tableName 查询出来的数据
      * 这里暂且不使用缓存的方式
      */
     if (is_array($this->fields) && !empty($this->fields)) {
         foreach ((array) $this->fields as $field) {
             $fields[$field] = array();
         }
         $this->tableFields[$this->trueTableName] = $fields;
     }
 }
 public function __construct($protoData, $type)
 {
     parent::__construct($protoData);
     if ($protoData->currency) {
         $this->_currency = $protoData->getCurrency()->serialize(new PhpArray());
     }
     if ($protoData->crm_id !== null) {
         $this->_crmId = $protoData->crmId;
     }
     if ($protoData->fiscal_number !== null) {
         $this->_fiscalNumber = $protoData->fiscal_number;
     }
     if ($protoData->involved_billing_accounts !== null) {
         $this->_involvedBillingAccounts = $protoData->involved_billing_accounts;
     }
     $this->_states = new \ArrayIterator($this->_states);
     $this->_setCurrentDetails();
     $this->_type = $type;
     $this->_allowedOtherChargesConceptsList = \App::config('consumptionDetailReport.allowedOtherChargesConcepts', array());
 }
 public function putAction()
 {
     $this->_helper->output('json');
     $data = $this->getRequest()->getRawBody();
     if (strlen($data) > \App::config('userConfig.bodySizeLimit', 50) * 1024) {
         throw new InvalidArgumentException("Body size exceed limit");
     }
     $data = $this->_helper->requestData(true);
     // Filter data
     $data = $this->_helper->filter($data)->blacklist(array_merge($this->_blacklistCreateFields, $this->_blacklistUpdateFields));
     // Modify the current details with the new data
     $item = new \Core\Model\Config\UserConfigModel($data);
     $item->id = $this->getRequest()->getParam('id');
     $this->_helper->filterNotAllowedFields('update_field', $item);
     // Check permissions
     $this->_helper->allowed('update', $item);
     $this->_preUpdate($item);
     // Perform the update
     $this->_service->update($item);
     $this->view->data = $item->getId();
 }
Example #30
-1
 protected function __construct($config)
 {
     if (count($config["db"]) != 4) {
         throw new \Exception("Le nombre d'arguments n'est pas valable!");
     }
     spl_autoload_register(array(__CLASS__, 'autoload'));
     self::$config = $config;
     self::$database = new Core\Db\ConnectPDO(self::$config["db"]);
     self::$baseUrl = rtrim(dirname($_SERVER['PHP_SELF']), '/.\\');
     $route = isset($_GET["r"]) ? $_GET["r"] : $_SERVER["REQUEST_URI"];
     $url = parse_url($route);
     $path = preg_replace('/^' . preg_quote(self::$baseUrl, '/') . '\\//', "", $url["path"]);
     $query = @$url["query"];
     $method = $_SERVER['REQUEST_METHOD'];
     $request = new Core\Http\Request($method, $path, $query);
     $dispatcher = new Core\Http\Dispatcher();
     try {
         $dispatcher->handle($request);
     } catch (Exception $e) {
         $code = '404';
         header($_SERVER["SERVER_PROTOCOL"] . " " . $code);
         $request = new Core\Http\Request('GET', 'Site/error', 'code=' . $code . '&message=' . $e->getMessage());
         $dispatcher->handle($request);
     }
 }