Ejemplo n.º 1
0
 /**
  * Add error using strings as arguments<br>
  * This method automatically creates fitting error object and adds it to storage
  * @param string ...$args
  * @return self
  */
 public function addError(string ...$args) : self
 {
     $count = count($args);
     if ($count < 1) {
         Debugger::debug('This method require at least one argument');
     }
     switch ($count) {
         case 1:
             $this->getErrorsObject()->add(new ErrorGlobal($args[0]));
             break;
         case 2:
             $this->getErrorsObject()->add(new ErrorForm($args[0], $args[1]));
             break;
         case 3:
             $this->getErrorsObject()->add(new ErrorForm($args[0], $args[1], $args[2]));
             break;
         default:
             Debugger::debug("Invalid arguments count ({$count})");
             break;
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  *
  * {@inheritdoc}
  *
  * @see \Minwork\Basic\Interfaces\ModelInterface::getData($filter)
  */
 public function getData($filter = null)
 {
     if (is_null($this->id)) {
         Debugger::debug('Trying to get data on model without id');
         return null;
     }
     return $this->execute(new Read($this->getEventDispatcher()), [$filter]);
 }
Ejemplo n.º 3
0
 /**
  * Set routing array
  * 
  * @param array $routing            
  * @return self
  */
 public function setRouting(array $routing) : self
 {
     foreach ($routing as $key => $route) {
         $curRouting = is_string($route) && is_file($route) ? require_once $route : [$key => $route];
         if (is_array($curRouting)) {
             if (!array_key_exists(self::DEFAULT_CONTROLLER_ROUTE_NAME, $curRouting)) {
                 Debugger::debug("Routing array should contain default controller route at '" . self::DEFAULT_CONTROLLER_ROUTE_NAME . "' key");
             }
             $this->routing = array_merge($this->routing, $curRouting);
         }
     }
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Set headers
  * 
  * @param string|array $header            
  * @param bool $merge            
  * @return self
  */
 public function setHeader($header, bool $merge = true) : self
 {
     if (is_string($header)) {
         if ($merge) {
             $this->headers[] = $header;
         } else {
             $this->headers = [$header];
         }
     } elseif (is_array($header)) {
         $this->headers = $merge ? array_merge($this->headers, $header) : $header;
     } else {
         Debugger::debug("Invalid header format");
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  *
  * {@inheritDoc}
  *
  * @see \Minwork\Http\Interfaces\UrlInterface::getParam($param)
  */
 public function getParam(string $param) : string
 {
     if (array_key_exists($param, $this->url)) {
         return $this->url[$param];
     }
     Debugger::debug("Param {$param} doesn't exists");
     return '';
 }
Ejemplo n.º 6
0
 /**
  * Trims array by keys
  *
  * @param array $array            
  * @param array $keys            
  * @return array
  */
 protected function trim(array $array, array $keys)
 {
     if (!is_array($array) || empty($array)) {
         Debugger::debug('Variable passed to trim isn\'t array or is empty');
     }
     if (!is_array($keys) || empty($keys)) {
         Debugger::debug('Can\'t trim to empty array');
     }
     return array_intersect_key($array, array_flip($keys));
 }