コード例 #1
0
ファイル: BagTest.php プロジェクト: adamnicholson/bag
 public function testArrayAccess()
 {
     $bag = new Bag();
     $bag['foo'] = 'bar';
     $this->assertTrue(isset($bag['foo']));
     $this->assertEquals('bar', $bag['foo']);
     $this->assertEquals('bar', $bag->get('foo'));
     unset($bag['foo']);
     $this->assertEquals(null, $bag->get('foo'));
     $this->assertFalse(isset($bag['foo']));
 }
コード例 #2
0
ファイル: Request.php プロジェクト: freyr/envelope
 public function get($field, $default = null)
 {
     if (!$this->get->has($field)) {
         if (!$this->post->has($field)) {
             if (!$this->cookie->has($field)) {
                 if ($default === null) {
                     throw new RequestParameterNotFoundException();
                 }
                 return $default;
             } else {
                 return $this->cookie->get($field);
             }
         } else {
             return $this->post->get($field);
         }
     } else {
         return $this->get->get($field);
     }
 }
コード例 #3
0
ファイル: NestedBag.php プロジェクト: bolt/collections
 /**
  * Gets the item at the specified path.
  *
  * Example:
  *
  *    $c = new NestedCollection([
  *        'foo' => [
  *            'bar' => 'hello world',
  *        ],
  *    ]);
  *
  *    $c->get('foo/bar'); // Returns 'hello world'
  *
  * @param int|string $path Path to the key of item to retrieve
  * @param mixed|null $default The default valud to return if not found
  *
  * @return mixed
  */
 public function get($path, $default = null)
 {
     $parts = explode('/', $path);
     if (count($parts) <= 1) {
         return parent::get($path);
     }
     $value = $this;
     while (null !== ($part = array_shift($parts))) {
         if (!Utils::isArrayAccessible($value) || !isset($value[$part])) {
             return $default;
         }
         $value = $value[$part];
     }
     return $value;
 }
コード例 #4
0
ファイル: HeaderBag.php プロジェクト: JanHuang/http
 /**
  * @param $name
  * @param bool $raw
  * @param null $callback
  * @return mixed|string
  */
 public function get($name, $raw = false, $callback = null)
 {
     return parent::get(strtolower(str_replace('_', '-', $name)), $raw, $callback);
 }