예제 #1
0
 /**
  * Remap properties recursively via regex.
  *
  * @param FormatAble $data
  * @param string     $oldKey
  * @param string     $newKey
  */
 protected function remapRecursively(&$data, $oldKey, $newKey)
 {
     $data->loopThrough(function ($index, $value) use($data, $oldKey, $newKey) {
         $matches = $this->checkRegexRecursively($value, $oldKey, $index);
         foreach ($matches as $match) {
             $this->remap($data, $match[0], $this->getRegexProperty($match, $newKey));
         }
     });
 }
예제 #2
0
 /**
  * Format the given object or array of objects.
  *
  * @param FormatAble $data
  *
  * @return FormatAble
  */
 public function format($data)
 {
     $data->loopThrough(function ($key, $value) use($data) {
         if (!in_array($key, $this->fields)) {
             $data->setProperty($key, null);
         }
     });
     $data->unsetNull();
     return $data;
 }