public function testGetValueByKey() { $inputArray = array('Account' => array('useCache' => true, 'sub' => array('subV' => '125', 'subO' => array('subOV' => '125', 'subOV2' => '125'))), 'Contact' => array('useCache' => true)); $this->assertEquals($inputArray, Util::getValueByKey($inputArray)); $this->assertEquals($inputArray, Util::getValueByKey($inputArray, '')); $this->assertEquals('125', Util::getValueByKey($inputArray, 'Account.sub.subV')); $result = array('useCache' => true); $this->assertEquals($result, Util::getValueByKey($inputArray, 'Contact')); $this->assertNull(Util::getValueByKey($inputArray, 'Contact.notExists')); $this->assertEquals('customReturns', Util::getValueByKey($inputArray, 'Contact.notExists', 'customReturns')); $this->assertNotEquals('customReturns', Util::getValueByKey($inputArray, 'Contact.useCache', 'customReturns')); }
/** * Undelete the deleted items * * @param string $key1 * @param string $key2 * @param array $data * @return void */ protected function undelete($key1, $key2, $data) { if (isset($this->deletedData[$key1][$key2])) { foreach ($this->deletedData[$key1][$key2] as $unsetIndex => $unsetItem) { $value = Util::getValueByKey($data, $unsetItem); if (isset($value)) { unset($this->deletedData[$key1][$key2][$unsetIndex]); } } } }
public function get($key = null, $returns = null) { $data = $this->getData(); if (!isset($data) || $data === false) { throw new Error('Language: current language [' . $this->getLanguage() . '] does not found'); } return Util::getValueByKey($data, $key, $returns); }
/** * Get Metadata * * @param string $key * @param mixed $return * * @return array */ public function get($key = null, $returns = null) { return Util::getValueByKey($this->getData(), $key, $returns); }