Ejemplo n.º 1
0
 /**
  * Returns the internal dependency injector
  */
 public function getDI()
 {
     if (!$this->_dependencyInjector) {
         $this->_dependencyInjector = DependencyInjection::getDefault();
     }
     return $this->_dependencyInjector;
 }
Ejemplo n.º 2
0
 /**
  * Returns the internal dependency injector
  */
 public function getDI()
 {
     if (!is_object($this->_dependencyInjector)) {
         $this->_dependencyInjector = DependencyInjection::getDefault(null);
     }
     return $this->_dependencyInjector;
 }
Ejemplo n.º 3
0
 /**
  * Returns the internal dependency injector
  */
 public function getDI()
 {
     if (!is_object($this->_dependencyInjector)) {
         $this->_dependencyInjector = \WpPepVN\DependencyInjection::getDefault();
         if (!is_object($this->_dependencyInjector)) {
             throw new Exception("A dependency injection object is required to access the 'url' service");
         }
     }
     return $this->_dependencyInjector;
 }
Ejemplo n.º 4
0
 /**
  * WpPepVN\DependencyInjection\FactoryDefault constructor
  */
 public function __construct()
 {
     parent::__construct();
     $this->_services = array('router' => new Service('router', '\\WpPepVN\\Mvc\\Router', true), 'view' => new Service('view', '\\WpPepVN\\Mvc\\View', true), 'url' => new Service('url', '\\WpPepVN\\Mvc\\Url', true), 'crypt' => new Service('crypt', '\\WpPepVN\\Crypt', true), 'filter' => new Service('filter', '\\WpPepVN\\Filter', true), 'session' => new Service('session', '\\WpPepVN\\Session\\Adapter\\Files', true), 'cookies' => new Service('cookies', '\\WpPepVN\\Http\\Response\\Cookies', true), 'eventsManager' => new Service('eventsManager', '\\WpPepVN\\Event\\Manager', true), 'response' => new Service('response', '\\WpPepVN\\Http\\Response', true), 'request' => new Service('request', '\\WpPepVN\\Http\\Request', true), 'escaper' => new Service('escaper', 'WpPepVN\\Escaper', true), 'translate' => new Service('translate', 'WpPepVN\\Translate', true), 'validation' => new Service('translate', 'WpPepVN\\Validation', true), 'hook' => new Service('translate', 'WpPepVN\\Hook', true));
 }
Ejemplo n.º 5
0
 /**
  * Internally gets the request dispatcher
  */
 public static function getDI()
 {
     if (!is_object(self::$_dependencyInjector)) {
         self::$_dependencyInjector = DependencyInjection::getDefault(null);
     }
     return self::$_dependencyInjector;
 }
Ejemplo n.º 6
0
 /**
  * Gets the a value to validate in the array/object data source
  *
  * @param string field
  * @return mixed
  */
 public function getValue($field)
 {
     $entity = $this->_entity;
     /**
      * If the entity is an object use it to retrieve the values
      */
     if (is_object($this->_entity)) {
         $method = "get" . $field;
         if (method_exists($entity, $method)) {
             $value = $entity->{$method}();
         } else {
             if (method_exists($entity, "readAttribute")) {
                 $value = $entity->readAttribute($field);
             } else {
                 if (isset($entity->{$field})) {
                     $value = $entity->{$field};
                 } else {
                     $value = null;
                 }
             }
         }
         return $value;
     }
     $data = $this->_data;
     if (!is_array($data) && !is_object($data)) {
         throw new Exception("There is no data to validate");
     }
     /**
      * Check if there is a calculated value
      */
     //$values = $this->_values;
     if (isset($this->_values[$field])) {
         return $this->_values[$field];
     }
     $value = null;
     if (is_array($data)) {
         if (isset($data[$field])) {
             $value = $data[$field];
         }
     } else {
         if (is_object($data)) {
             if (isset($data->{$field})) {
                 $value = $data->{$field};
             }
         }
     }
     if (is_null($value)) {
         return null;
     }
     //$filters = $this->_filters;
     if (is_array($this->_filters)) {
         //if fetch fieldFilters, filters[field]
         if (isset($this->_filters[$field])) {
             if ($this->_filters[$field]) {
                 $dependencyInjector = $this->getDI();
                 if (!is_object($dependencyInjector)) {
                     $dependencyInjector = DependencyInjection::getDefault();
                     if (!is_object($dependencyInjector)) {
                         throw new Exception("A dependency injector is required to obtain the 'filter' service");
                     }
                 }
                 $filterService = $dependencyInjector->getShared("filter");
                 if (!is_object($filterService)) {
                     throw new Exception("Returned 'filter' service is invalid");
                 }
                 return $filterService->sanitize($value, $this->_filters[$field]);
             }
         }
     }
     /**
      * Cache the calculated value
      */
     $this->_values[$field] = $value;
     return $value;
 }