Example #1
0
 /**
  * Constructor.
  *
  * @return  void
  */
 public function __construct(array $parameters = [])
 {
     $this->_parameters = new Core\Parameter($this, [], ['prefix' => null, 'rules.public' => [], 'rules.private' => []]);
     $this->_parameters->setParameters($parameters);
     if (null === ($prefix = $this->_parameters->getParameter('prefix'))) {
         $this->setPrefix('\\' === ($_ = dirname($this->getBootstrap())) ? '/' : $_);
     } else {
         $this->setPrefix($prefix);
     }
     foreach ($this->_parameters->getParameter('rules.public') as $id => $rule) {
         @(list($methods, $pattern, $call, $able, $variables) = $rule);
         if (null === $variables) {
             $variables = [];
         }
         $this->addRule($id, $methods, $pattern, $call, $able, $variables);
     }
     foreach ($this->_parameters->getParameter('rules.private') as $id => $rule) {
         @(list($methods, $pattern, $call, $able, $variables) = $rule);
         if (null === $variables) {
             $variables = [];
         }
         $this->addPrivateRule($id, $methods, $pattern, $call, $able, $variables);
     }
     $this->setDefaultPort(static::getPort(), static::isSecure());
     return;
 }
Example #2
0
 /**
  * Constructor.
  *
  * @return  void
  */
 public function __construct(array $parameters = [])
 {
     $this->_parameters = new Core\Parameter($this, [], ['rules.public' => [], 'rules.private' => []]);
     $this->_parameters->setParameters($parameters);
     foreach ($this->_parameters->getParameter('rules.public') as $id => $rule) {
         @(list($methods, $pattern, $call, $able, $variables) = $rule);
         if (null === $variables) {
             $variables = [];
         }
         $this->addRule($id, $methods, $pattern, $call, $able, $variables);
     }
     foreach ($this->_parameters->getParameter('rules.private') as $id => $rule) {
         @(list($methods, $pattern, $call, $able, $variables) = $rule);
         if (null === $variables) {
             $variables = [];
         }
         $this->addPrivateRule($id, $methods, $pattern, $call, $able, $variables);
     }
     return;
 }
Example #3
0
 /**
  * Dispatch a router rule.
  *
  * @param   \Hoa\Router         $router    Router.
  * @param   \Hoa\View\Viewable  $view      View.
  * @return  mixed
  * @throws  \Hoa\Controller\Exception
  */
 public function dispatch(Router $router, View\Viewable $view = null)
 {
     $rule = $router->getTheRule();
     if (null === $rule) {
         $router->route();
         $rule = $router->getTheRule();
     }
     if (null === $view) {
         $view = $this->_currentView;
     } else {
         $this->_currentView = $view;
     }
     $parameters = $this->_parameters;
     $this->_parameters = clone $this->_parameters;
     foreach ($rule[Router::RULE_VARIABLES] as $key => $value) {
         $this->_parameters->setParameter('variables.' . $key, $value);
     }
     $out = $this->resolve($rule, $router, $view);
     unset($this->_parameters);
     $this->_parameters = $parameters;
     return $out;
 }
Example #4
0
 /**
  * Generate a continuous uniform distribution.
  *
  * @param   float   $lower    Lower bound value.
  * @param   float   $upper    Upper bound value.
  * @return  float
  */
 public function getFloat($lower = null, $upper = null)
 {
     if (null === $lower) {
         $lower = $this->_parameters->getParameter('float.min');
     }
     /*
     $lower = true === S_32\BITS
                  ? -3.4028235e38 + 1
                  : -1.7976931348623157e308 + 1;
     */
     if (null === $upper) {
         $upper = $this->_parameters->getParameter('float.max');
     }
     /*
     $upper = true === S_32\BITS
                  ? 3.4028235e38 - 1
                  : 1.7976931348623157e308 - 1;
     */
     if ($lower > $upper) {
         throw new Math\Exception('Unexpected values, float %f should be lower than %f', 2, [$lower, $upper]);
     }
     return $this->_getFloat($lower, $upper);
 }
Example #5
0
 /**
  * Initialize the core.
  *
  * @param   array   $parameters    Parameters of \Hoa\Core.
  * @return  \Hoa\Core
  */
 public function initialize(array $parameters = [])
 {
     $root = dirname(dirname(__DIR__));
     $cwd = 'cli' === PHP_SAPI ? dirname(realpath($_SERVER['argv'][0])) : getcwd();
     $this->_parameters = new Parameter\Parameter($this, ['root' => $root, 'cwd' => $cwd], ['root.hoa' => '(:root:)', 'root.application' => '(:cwd:h:)', 'root.data' => '(:%root.application:h:)' . DS . 'Data' . DS, 'protocol.Application' => '(:%root.application:)' . DS, 'protocol.Application/Public' => 'Public' . DS, 'protocol.Data' => '(:%root.data:)', 'protocol.Data/Etc' => 'Etc' . DS, 'protocol.Data/Etc/Configuration' => 'Configuration' . DS, 'protocol.Data/Etc/Locale' => 'Locale' . DS, 'protocol.Data/Library' => 'Library' . DS . 'Hoathis' . DS . RS . 'Library' . DS . 'Hoa' . DS, 'protocol.Data/Lost+found' => 'Lost+found' . DS, 'protocol.Data/Temporary' => 'Temporary' . DS, 'protocol.Data/Variable' => 'Variable' . DS, 'protocol.Data/Variable/Cache' => 'Cache' . DS, 'protocol.Data/Variable/Database' => 'Database' . DS, 'protocol.Data/Variable/Log' => 'Log' . DS, 'protocol.Data/Variable/Private' => 'Private' . DS, 'protocol.Data/Variable/Run' => 'Run' . DS, 'protocol.Data/Variable/Test' => 'Test' . DS, 'protocol.Library' => '(:%protocol.Data:)Library' . DS . 'Hoathis' . DS . RS . '(:%protocol.Data:)Library' . DS . 'Hoa' . DS . RS . '(:%root.hoa:)' . DS . 'Hoathis' . DS . RS . '(:%root.hoa:)' . DS . 'Hoa' . DS, 'namespace.prefix.*' => '(:%protocol.Data:)Library' . DS . RS . '(:%root.hoa:)' . DS, 'namespace.prefix.Application' => '(:%root.application:h:)' . DS]);
     $this->_parameters->setKeyword('root', $root);
     $this->_parameters->setKeyword('cwd', $cwd);
     $this->_parameters->setParameters($parameters);
     $this->setProtocol();
     return $this;
 }
Example #6
0
 /**
  * Get the last instance of a DAL, i.e. the last used singleton.
  * If no instance was set but if the connection.autoload parameter is set,
  * then we auto-connect (autoload) a connection.
  *
  * @return  \Hoa\Database\IDal\Wrapper
  * @throws  \Hoa\Database\Exception
  */
 public static function getLastInstance()
 {
     if (null === self::$_parameters) {
         self::initializeParameters();
     }
     if (null === self::$_id) {
         $autoload = self::$_parameters->getFormattedParameter('connection.autoload');
         if (null !== $autoload) {
             self::getInstance($autoload);
         }
     }
     if (null === self::$_id) {
         throw new Exception('No instance was set, cannot return the last instance.', 1);
     }
     return self::$_instance[self::$_id];
 }
Example #7
0
 /**
  * Set the current ID.
  *
  * @param   string  $id    ID.
  * @return  string
  */
 protected function setId($id)
 {
     $old = $this->_parameters->getKeyword('id');
     $this->_parameters->setKeyword('id', $id);
     return $old;
 }