get() public static method

Returns an object from the default storage.
public static get ( string $key ) : object
$key string Object key
return object
コード例 #1
0
ファイル: ObjectCacheTest.php プロジェクト: JerryCR/php-2
 /**
  * Tests saving data.
  */
 public function testSaveData()
 {
     $object = $this->saveObject();
     $this->assertSame($object, $this->cache->get(self::CACHE_KEY));
     // Saving using one way
     ObjectCache::set(self::CACHE_KEY, $object);
     $this->assertSame($object, $this->cache->get(self::CACHE_KEY));
     // Saving using the other way
     $this->cache->{self::CACHE_KEY} = $object;
     $this->assertSame($object, $this->cache->get(self::CACHE_KEY));
     $this->cache->clear();
 }
コード例 #2
0
ファイル: Filter.php プロジェクト: jyxo/php
 /**
  * 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);
 }
コード例 #3
0
ファイル: Validator.php プロジェクト: jyxo/php
 /**
  * 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);
 }
コード例 #4
0
ファイル: ValidatorTest.php プロジェクト: honzap/php
 /**
  * Tests static call usage.
  */
 public function testCallStatic()
 {
     static $value = 42;
     $this->assertTrue(Validator::isInt($value));
     $this->assertTrue(Validator::lessThan($value, $value * 2));
     $this->assertTrue(Validator::callback($value, function ($value, $lowerBound) {
         return is_numeric($value) && $value > $lowerBound;
     }, 41));
     // Tests storing in cache - the first on in cached, the second one isn't
     // because it had additional parameters that had been added to the cache ID
     $this->assertNotNull(\Jyxo\Spl\ObjectCache::get('\\Jyxo\\Input\\Validator\\IsInt'));
     $this->assertNull(\Jyxo\Spl\ObjectCache::get('\\Jyxo\\Input\\Validator\\LessThan'));
 }