set() публичный статический Метод

Saves an object into the default storage.
public static set ( string $key, object $value ) : object
$key string Object key
$value object Object
Результат object saved object
Пример #1
0
 /**
  * Static filtering.
  *
  * @param string $method Filter name
  * @param array $params Parameters; the first value gets filtered, the rest will be used as constructor parameters
  * @return mixed
  */
 public static function __callStatic(string $method, array $params)
 {
     $factory = \Jyxo\Spl\ObjectCache::get(\Jyxo\Input\Factory::class) ?: \Jyxo\Spl\ObjectCache::set(\Jyxo\Input\Factory::class, new Factory());
     $value = array_shift($params);
     $key = 'Jyxo\\Input\\Filter\\' . ucfirst($method) . ($params ? '/' . serialize($params) : '');
     $filter = \Jyxo\Spl\ObjectCache::get($key) ?: \Jyxo\Spl\ObjectCache::set($key, $factory->getFilterByName($method, $params));
     /* @var $filter \Jyxo\Input\FilterInterface */
     return $filter->filter($value);
 }
Пример #2
0
 /**
  * Static validation.
  *
  * @param string $method Validator name
  * @param array $params Parameters; the first value gets validated, the rest will be used as constructor parameters
  * @return boolean
  */
 public static function __callStatic(string $method, array $params)
 {
     try {
         $factory = \Jyxo\Spl\ObjectCache::get(\Jyxo\Input\Factory::class) ?: \Jyxo\Spl\ObjectCache::set(\Jyxo\Input\Factory::class, new Factory());
         $value = array_shift($params);
         $key = 'Jyxo\\Input\\Validator\\' . ucfirst($method) . ($params ? '/' . serialize($params) : '');
         $validator = \Jyxo\Spl\ObjectCache::get($key) ?: \Jyxo\Spl\ObjectCache::set($key, $factory->getValidatorByName($method, $params));
     } catch (\Exception $e) {
         $validator = $factory->getValidatorByName($method, $params);
     }
     return $validator->isValid($value);
 }