Exemplo n.º 1
0
 /**
  * Load defined constraint set from Configuration.
  *
  * @param string $setName
  *
  * @return Validation
  */
 public function loadSet($setName)
 {
     $sets = Configuration::get('input.validationSets', array());
     if (isset($sets[$setName])) {
         $this->set = $sets[$setName];
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Load a prepared stack.
  *
  * @param string $name
  *
  * @return Builder
  *
  * @throws RendererException
  */
 public function loadStack($name)
 {
     $stacks = Configuration::get('template.stacks');
     if (!isset($stacks[$name])) {
         throw new RendererException("Stack '" . $name . "' not found!");
     }
     $this->render->replaceAll($stacks[$name]);
     return $this;
 }
Exemplo n.º 3
0
 public static function template()
 {
     if (self::$templateStore == null) {
         // Base url + path
         $url = Configuration::get('app.url') . '/assets/';
         $path = APPPATH . Configuration::get('template.templatePath') . DS;
         self::$templateStore = new self($url, $path);
     }
     return self::$templateStore;
 }
Exemplo n.º 4
0
 public function testInvalidDefine()
 {
     try {
         Configuration::define('testinvalid', function () {
             return null;
         });
         $this->assertTrue(false);
     } catch (\Exception $e) {
         $this->assertTrue(true);
     }
 }
Exemplo n.º 5
0
 /**
  * Register handler/ability.
  *
  * @param array $options
  *
  * @return mixed
  */
 public static function register($options = array())
 {
     $self = self::getInstance();
     error_reporting(-1);
     set_error_handler([$self, 'handleError']);
     set_exception_handler([$self, 'handleException']);
     register_shutdown_function([$self, 'handleShutdown']);
     if (Configuration::get('app.env', 'production') !== 'development') {
         ini_set('display_errors', 'Off');
     }
 }
Exemplo n.º 6
0
 /**
  * Use internally only!
  *
  * @throws AlreadyInitiatedException
  */
 public function init()
 {
     if ($this->init) {
         return;
     }
     $this->init = true;
     // Get configuration for session.
     $this->config = Configuration::get('app.session', []);
     // Verify and defaulting config.
     if ($this->config === false) {
         return;
     }
     // Session is disabled, don't start it!
     if (!isset($this->config['name'])) {
         $this->config['name'] = 'arvici_session';
     }
     if (!isset($this->config['expire'])) {
         $this->config['expire'] = 1 * 60 * 60;
     }
     // 1 hour default.
     if (!isset($this->config['path'])) {
         $this->config['path'] = '/';
     }
     if (!isset($this->config['domain'])) {
         $this->config['domain'] = null;
     }
     if (!isset($this->config['secure'])) {
         $this->config['secure'] = false;
     }
     // Secure only flag.
     if (!isset($this->config['http'])) {
         $this->config['http'] = true;
     }
     // Http Only flag.
     if (isset($this->config['prefix'])) {
         $this->prefix = $this->config['prefix'];
     }
     if (session_status() === PHP_SESSION_ACTIVE) {
         throw new AlreadyInitiatedException('Session is already started before Arvici is started!');
     }
     if (defined('PHPUNIT_RUNNING')) {
         return;
     }
     $this->start();
 }
Exemplo n.º 7
0
 /**
  * MustacheTemplate constructor.
  */
 public function __construct()
 {
     $cacheFolder = Configuration::get('app.cache', null);
     // Prepare the cache folder.
     if ($cacheFolder === null || empty($cacheFolder)) {
         throw new ConfigurationException("The configuration for the APP.CACHE entry is invalid, should be a path to the cache folder!");
         // @codeCoverageIgnore
     }
     // TODO: Make cache heart component, for global cache folder prepare and usage.
     if (!file_exists($cacheFolder)) {
         // @codeCoverageIgnore
         $makeDir = mkdir($cacheFolder);
         // @codeCoverageIgnore
         if (!$makeDir) {
             // @codeCoverageIgnore
             throw new PermissionDeniedException("Could not make directory '" . $cacheFolder . "'! Please look at your permissions!");
             // @codeCoverageIgnore
         }
         // @codeCoverageIgnore
     }
     // @codeCoverageIgnore
     if (!file_exists($cacheFolder . DS . 'template')) {
         $makeDir = mkdir($cacheFolder . DS . 'template');
         // @codeCoverageIgnore
         if (!$makeDir) {
             // @codeCoverageIgnore
             throw new PermissionDeniedException("Could not make directory '" . $cacheFolder . DS . 'template' . "'! Please look at your permissions!");
             // @codeCoverageIgnore
         }
         // @codeCoverageIgnore
     }
     if (!file_exists($cacheFolder . DS . 'template' . DS . 'mustache')) {
         $makeDir = mkdir($cacheFolder . DS . 'template' . DS . 'mustache');
         // @codeCoverageIgnore
         if (!$makeDir) {
             // @codeCoverageIgnore
             throw new PermissionDeniedException("Could not make directory '" . $cacheFolder . DS . 'template' . DS . 'mustache' . "'! Please look at your permissions!");
             // @codeCoverageIgnore
         }
         // @codeCoverageIgnore
     }
     // Prepare the instance
     $this->mustache = new \Mustache_Engine(array('cache' => Configuration::get('app.cache', null), 'charset' => 'UTF-8'));
     $this->data = array();
 }
Exemplo n.º 8
0
 /**
  * Start function, will be called from the bootstrap file.
  */
 public static function start()
 {
     if (self::$instance !== null) {
         throw new LogException("Logger already started!");
     }
     if (Configuration::get('app.log', true)) {
         // Get configuration
         $logPath = Configuration::get('app.logPath');
         if ($logPath === null) {
             // @codeCoverageIgnore
             throw new ConfigurationException("app.logPath is not valid!");
             // @codeCoverageIgnore
         }
         // @codeCoverageIgnore
         if (!file_exists($logPath)) {
             // @codeCoverageIgnore
             $make = mkdir($logPath);
             // @codeCoverageIgnore
             if (!$make) {
                 // @codeCoverageIgnore
                 throw new PermissionDeniedException("Could not create directory '" . $logPath . "'!");
                 // @codeCoverageIgnore
             }
             // @codeCoverageIgnore
         }
         // @codeCoverageIgnore
         // Get all level and log files.
         self::$files = Configuration::get('app.logFile', ['app.log' => self::ERROR]);
         // Load the logger
         self::$instance = new Writer($logPath);
         self::$path = $logPath;
         // Load all handlers.
         foreach (self::$files as $file => $minimumLevel) {
             self::$instance->addHandler(new StreamHandler($logPath . $file, $minimumLevel));
         }
         // Write debug message for starting logger
         self::log(self::DEBUG, 'Arvici Logger Started!');
         // Register exception/error handler
         ExceptionHandler::register();
     }
 }
Exemplo n.º 9
0
 /**
  * Get default return type (fetch mode)
  *
  * @return int
  */
 public static function defaultReturnType()
 {
     return Configuration::get('database.fetchType', self::FETCH_ASSOC);
 }
Exemplo n.º 10
0
<?php

use Arvici\Heart\Config\Configuration as Configure;
/**
 * Config: app
 */
Configure::define('app', function ($config) {
    return ['url' => 'http://localhost:8080', 'env' => 'development', 'log' => true, 'visualException' => true, 'logPath' => BASEPATH . 'logs' . DS, 'logFile' => ['error.log' => \Logger::ERROR, 'development.log' => \Logger::DEBUG], 'timezone' => 'Europe/Amsterdam', 'locale' => 'en', 'private_key' => 'J7a6dhaA&*dhgAfhjkHJv*78gja8gjKg89(*Sf', 'services' => [], 'session' => ['name' => 'arvici_test_session', 'expire' => 1 * 60 * 60, 'path' => '/', 'domain' => null, 'secure' => false, 'http' => true, 'prefix' => 'arvici_'], 'cache' => BASEPATH . 'cache/'];
});
Exemplo n.º 11
0
<?php

use Arvici\Heart\Config\Configuration;
use Arvici\Component\View\View;
/**
 * Template Configuration
 */
Configuration::define('database', function () {
    return ['fetchType' => \Arvici\Heart\Database\Database::FETCH_ASSOC, 'connections' => ['default' => ['driver' => 'MySQL', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => 3306, 'database' => 'arvici_test'], 'incomplete' => ['driver' => 'MySQL'], 'nodriver' => []]];
});
Exemplo n.º 12
0
<?php

use Arvici\Heart\Config\Configuration;
use Arvici\Component\View\View;
/**
 * Template Configuration
 */
Configuration::define('template', function () {
    return ['templatePath' => 'Template/Default', 'viewPath' => 'View', 'defaultStack' => [View::template('header'), View::bodyPlaceholder(), View::template('footer')], 'defaultEngine' => 'PhpTemplate', 'stacks' => ['test-sample' => [View::template('testHeader'), View::bodyPlaceholder(), View::body('testContent'), View::template('testFooter')], 'test-basicrender' => [View::template('testHeader'), View::bodyPlaceholder(), View::template('testFooter')]]];
});
Exemplo n.º 13
0
<?php

use Arvici\Heart\Config\Configuration as Configure;
/**
 * Config: input
 */
Configure::define('input', function () {
    return ['validationSets' => ['testSet' => ['first' => new \Arvici\Heart\Input\Validation\Assert\IntegerType(), 'second' => new \Arvici\Heart\Input\Validation\Assert\Collection([new \Arvici\Heart\Input\Validation\Assert\Required(), new \Arvici\Heart\Input\Validation\Assert\BooleanType()]), 'third' => null, 'fourth' => new \Arvici\Heart\Input\Validation\Assert\Collection([new \Arvici\Heart\Input\Validation\Assert\Alpha(false, false), new \Arvici\Heart\Input\Validation\Assert\Required()])]]];
});
Exemplo n.º 14
0
<?php

use Arvici\Heart\Config\Configuration as Configure;
/**
 * Config: output
 */
Configure::define('output', function () {
    return [];
});
Exemplo n.º 15
0
 * @author     Tom Valk <*****@*****.**>
 * @copyright  2016 Tom Valk
 */
use Arvici\Heart\Config\Configuration;
/**
 * Define the base directory containing the 'App' folder.
 */
defined('BASEPATH') || define('BASEPATH', __DIR__ . DS);
/**
 * Define all the paths in the base.
 */
defined('APPPATH') || define('APPPATH', BASEPATH . 'App' . DS);
/**
 * Load all configuration files.
 */
$configDir = APPPATH . '/Config/';
foreach (glob($configDir . '*.php') as $fileName) {
    require_once $fileName;
}
/**
 * Set default timezone
 */
date_default_timezone_set(Configuration::get('app.timezone', 'UTC'));
/**
 * Start the logger.
 */
\Logger::start();
/**
 * Start the router.
 */
\Arvici\Component\Router::getInstance()->run();
Exemplo n.º 16
0
 /**
  * Get full path of view file.
  *
  * @return string
  *
  * @throws ConfigurationException
  */
 public function getFullPath()
 {
     $key = 'template.templatePath';
     if ($this->type === self::PART_BODY) {
         $key = 'template.viewPath';
     }
     $path = Configuration::get($key, null);
     if ($path === null) {
         // @codeCoverageIgnore
         throw new ConfigurationException("The template.templatePath or template.viewPath isn't configured right or doesn't exists!");
         // @codeCoverageIgnore
     }
     // @codeCoverageIgnore
     $path = BASEPATH . 'App' . DS . $path . DS . $this->path;
     $extension = pathinfo($path, PATHINFO_EXTENSION);
     if ($extension === "") {
         $path .= ".php";
     }
     return $path;
 }