예제 #1
0
 /**
  * Returns only specified items
  *
  * @param array $keys            Keys which to return from array
  * @param bool  $respectKeyOrder If you want the resulting array to be ordered
  *                               precisely as $keys. Especially useful in list() construct
  * @param bool  $requireAllKeys  Require all keys from $keys to be present in the result. Throw exception otherwise
  *
  * @return array
  * @throws Exception
  */
 public function getOnly(array $keys, $respectKeyOrder = false, $requireAllKeys = true)
 {
     $this->assertArrayDataExists();
     $result = $respectKeyOrder ? Arr::onlyRespectOrder($this->data, $keys) : Arr::only($this->data, $keys);
     if ($requireAllKeys) {
         $this->assertAllDataPresent($keys, $result);
     }
     return $result;
 }
예제 #2
0
 /**
  *
  */
 public function testOnlyRespectOrder()
 {
     $testData = ['key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'];
     $expected = ['key3' => 'value3', 'key2' => 'value2'];
     $this->assertEquals($expected, Arr::onlyRespectOrder($testData, ['key3', 'key2']));
 }