Exemplo n.º 1
0
 /**
  * @return Cache
  * @throws ApplicationPartMissingException
  */
 public static function getCache()
 {
     if (!self::$cache instanceof Cache) {
         if (Configuration::get('phpframework', 'cache.enable')) {
             $cacheFolder = Configuration::get('phpframework', 'cache.folder', './cache');
             $cacheFolderPath = realpath($cacheFolder);
             if (!is_dir($cacheFolderPath)) {
                 if (!@mkdir($cacheFolder, 0777, TRUE)) {
                     throw new ApplicationPartMissingException('Cache folder "' . $cacheFolder . '" is missing and could not be created.', 1410537983);
                 }
                 $cacheFolderPath = realpath($cacheFolder);
             }
             $testfile = $cacheFolderPath . '/L7NxnrqsICAtxg0qxDWPUSA';
             @touch($testfile);
             if (file_exists($testfile)) {
                 unlink($testfile);
             } else {
                 throw new ApplicationPartMissingException('Cache folder "' . $cacheFolder . '" is not writable', 1410537933);
             }
             $storage = new FileStorage($cacheFolderPath, new FileJournal($cacheFolderPath));
         } else {
             $storage = new DevNullStorage();
         }
         self::$cache = new Cache($storage, Configuration::get('application', 'application'));
     }
     return self::$cache;
 }
Exemplo n.º 2
0
 /**
  * @throws \Exception
  */
 public static function initialize()
 {
     $applicationDirectory = Configuration::get('application', 'application_directory');
     $configFilePath = $applicationDirectory . 'settings.ini';
     $overwriteFilePath = $applicationDirectory . 'settings_local.ini';
     self::parse($configFilePath, $overwriteFilePath);
 }
 /**
  *
  */
 protected function encodeCryptCookie()
 {
     $sSecretKey = Configuration::get('phpframework', 'authentication.cookie.encrypt_key');
     $sDecrypted = json_encode($this->store);
     $data = trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $sSecretKey, $sDecrypted, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
     setcookie($this->cookieName, $data, time() + 31 * 86400, '/');
 }
Exemplo n.º 4
0
 /**
  * @test
  */
 public function applicationFolderBothFiles()
 {
     DefaultConfiguration::initialize('_both');
     IniParser::initialize();
     $this->assertSame('b', Configuration::get('unittest', 'foo'));
     $this->assertSame('42', Configuration::get('unittest', 'bar'));
     $this->assertNull(Configuration::get('unittest', 'baz'));
 }
Exemplo n.º 5
0
 /**
  * @param AbstractView $response
  */
 public static function contentTypeHeader(AbstractView $response)
 {
     $contentType = 'text/html';
     $charset = Configuration::get('phpframework', 'output_charset', 'utf-8');
     if ($charset) {
         $contentType .= '; charset=' . trim($charset);
     }
     $response->header('Content-Type', $contentType);
 }
Exemplo n.º 6
0
 /**
  * @test
  */
 public function removeKeyWorks()
 {
     Configuration::set('test', 'key1', TRUE);
     Configuration::set('test', 'key2', TRUE);
     $this->assertTrue(Configuration::get('test', 'key1'));
     $this->assertTrue(Configuration::get('test', 'key2'));
     Configuration::remove('test', 'key1');
     $this->assertNull(Configuration::get('test', 'key1'));
     $this->assertTrue(Configuration::get('test', 'key2'));
 }
Exemplo n.º 7
0
 /**
  * @param int $major
  * @param int $minor
  * @return bool
  */
 public static function maximum($major, $minor)
 {
     $version = Configuration::get('phpframework', 'version', '0.0');
     $versionParts = explode('.', $version, 2);
     $actualMajor = (int) $versionParts[0];
     $actualMinor = (int) $versionParts[1];
     if ($actualMajor < $major || $actualMajor === $major && $actualMinor <= $minor) {
         return true;
     } else {
         return false;
     }
 }
 /**
  *
  */
 public static function initialize()
 {
     $airbrake_ini = Configuration::getSection('phpframework-airbrake');
     if (!is_null($airbrake_ini) && Configuration::get('phpframework-airbrake', 'enable', FALSE)) {
         $apiKey = $airbrake_ini['api_key'];
         $airbrake_environment = isset($airbrake_ini['environment']) ? $airbrake_ini['environment'] : 'NO_ENVIRONMENT_SET';
         $options = ['secure' => TRUE, 'host' => $airbrake_ini['host'], 'resource' => $airbrake_ini['resource'], 'timeout' => 10, 'environmentName' => Configuration::get('application', 'application') . ' / ' . $airbrake_environment];
         \Airbrake\EventHandler::start($apiKey, FALSE, $options);
         $config = new \Airbrake\Configuration($apiKey, $options);
         self::$client = new \Airbrake\Client($config);
     }
 }
Exemplo n.º 9
0
 /**
  * @throws DatabaseMigratorException
  */
 public function __construct()
 {
     $this->db = StaticDatabaseConnection::getInstance();
     $this->migrationDirectory = Configuration::get('phpframework', 'db.migrator.directory');
     if (!$this->migrationDirectory) {
         throw new DatabaseMigratorException('Migration directory was not configured.', 1415085595);
     }
     if (!is_dir($this->migrationDirectory)) {
         throw new DatabaseMigratorException('Migration directory "' . $this->migrationDirectory . '" does not exist or is not a directory.', 1415085126);
     }
     $this->lastExecutedVersion = $this->getLastExecutedVersion();
 }
Exemplo n.º 10
0
 /**
  * @return \Twig_Environment
  * @throws ApplicationPartMissingException
  */
 protected function getRenderingEngine()
 {
     if (!isset($this->renderingEngine)) {
         if (!is_dir(Configuration::get('application', 'templates_directory'))) {
             throw new ApplicationPartMissingException('Template directory "' . Configuration::get('application', 'templates_directory') . '" does not exist.');
         }
         $loader = new \Twig_Loader_Filesystem(Configuration::get('application', 'templates_directory'));
         $options = [];
         if (Configuration::get('phpframework', 'cache.enable')) {
             $options['cache'] = Configuration::get('phpframework', 'cache.twig_folder', './cache/twig/');
         }
         $this->renderingEngine = new \Twig_Environment($loader, $options);
     }
     return $this->renderingEngine;
 }
Exemplo n.º 11
0
 /**
  *
  */
 public function __construct()
 {
     $sessionClass = Configuration::get('phpframework', 'authentication.sessionclass', 'BasePHPSession');
     if (!class_exists($sessionClass)) {
         $sessionClass = $this->defaultSessionClassNamespace . '\\' . $sessionClass;
     }
     if (class_exists($sessionClass)) {
         $this->session = new $sessionClass();
         if (!$this->session instanceof BaseSessionInterface) {
             unset($this->session);
             throw new BaseSessionException($sessionClass . ' is not an instance of AppZap\\PHPFramework\\Authentication\\BaseSessionInterface', 1409732473);
         }
     } else {
         throw new BaseSessionException('Session class ' . $sessionClass . ' not found', 1409732479);
     }
 }
Exemplo n.º 12
0
 /**
  * @param string $resource
  * @throws ApplicationPartMissingException
  * @throws InvalidHttpResponderException
  */
 public function __construct($resource)
 {
     $routesFile = Configuration::get('application', 'routes_file');
     if (!is_readable($routesFile)) {
         throw new ApplicationPartMissingException('Routes file "' . $routesFile . '" does not exist.', 1415134009);
     }
     $routes = (include $routesFile);
     if (!is_array($routes)) {
         throw new InvalidHttpResponderException('The routes file did not return an array with routes', 1415135585);
     }
     $this->route($routes, $resource);
     // check if the responder is valid
     if (is_string($this->responder)) {
         if (!class_exists($this->responder)) {
             throw new InvalidHttpResponderException('Controller ' . $this->responder . ' for uri "' . $resource . '" not found!', 1415129223);
         }
     } elseif (!isset($this->responder)) {
         throw new InvalidHttpResponderException('Route ' . $resource . ' could not be routed.', 1415136995);
     } elseif (!is_callable($this->responder)) {
         throw new InvalidHttpResponderException('The responder must either be a class string, a callable or an array of subpaths', 1415129333);
     }
 }
Exemplo n.º 13
0
 /**
  *
  */
 protected static function invokeDispatcher()
 {
     $dispatcher = new Dispatcher();
     if ($dispatcher->getRequestMethod() === 'cli') {
         $cliArguments = $_SERVER['argv'];
         array_shift($cliArguments);
         $resource = '/' . join('/', $cliArguments);
     } else {
         $resource = $_SERVER['REQUEST_URI'];
         $uriPathPrefix = '/' . trim(Configuration::get('phpframework', 'uri_path_prefix'), '/');
         if ($uriPathPrefix && strpos($resource, $uriPathPrefix) === 0) {
             $resource = substr($resource, strlen($uriPathPrefix));
         }
     }
     return $dispatcher->dispatch($resource);
 }
Exemplo n.º 14
0
 /**
  * @param string $template_name
  * @return \Twig_TemplateInterface
  */
 protected function getTemplateEnvironment($template_name = NULL)
 {
     if (is_null($template_name)) {
         $template_name = $this->templateName;
     }
     $template_file_extension = Configuration::get('phpframework', 'template_file_extension', $this->defaultTemplateFileExtension);
     $template = $this->getRenderingEngine()->loadTemplate($template_name . '.' . $template_file_extension);
     return $template;
 }