Example #1
0
 /**
  * Get an item from flash data
  *
  * @param     string     Flash data key
  * @param     mixed      Data to return if flash item is not found
  * @returns   mixed      Flash data value or default
  */
 public function get($key, $default = null)
 {
     if ($value = Arr::get($_SESSION, "flash.{$key}")) {
         if (Arr::get($value, 'aged', false)) {
             Arr::delete($_SESSION, "flash.{$key}");
             return $default;
         }
         Arr::set($_SESSION, "flash.{$key}.aged", true);
         return Arr::get($value, 'value');
     }
     return $default;
 }
Example #2
0
 /**
  * Set/get an option/attribute
  *
  * Simply sets or gets an option or attribute depending on whether or not a value
  * is passed. If setting the class attribute special handling is invoked.
  *
  * @param    string             Option or attribute name
  * @param    mixed|null         Option or attribute value or none
  * @return   mixed              If getting an option/attribute
  * @return   chainable          If setting an option/attribute
  */
 public function option($option, $value = null)
 {
     if ($value === null) {
         if ($option === 'class') {
             return implode(' ', $this->classes);
         }
         return Arr::get($this->options, $option, false);
     }
     if ($option === 'class') {
         $new = explode(' ', trim($value));
         $this->classes = array_merge($this->classes, $new);
     } else {
         Arr::set($this->options, $option, $value);
     }
     return $this;
 }
Example #3
0
 /**
  * @dataProvider data
  * @covers \Nerd\Arr::get
  */
 public function testArrGetDefault($users)
 {
     $this->assertNull(Arr::get($users, 'nonexistent.key'));
     $actual = Arr::get($users, 'nonexistent.key', 'default');
     $this->assertEquals($actual, 'default');
 }
Example #4
0
 /**
  * Retrieve data from the $_SERVER superglobal array
  *
  * @param     string     Dot notated path to data
  * @param     mixed      Default return value
  * @returns   mixed
  */
 public static function server($key = null, $default = null)
 {
     return $key === null ? $_SERVER : \Nerd\Arr::get($_SERVER, strtoupper($key), $default);
 }