Beispiel #1
0
 /**
  * @dataProvider getSnakeCaseToCamelCaseData
  */
 public function testSnakeCaseToCamelCase($str, $expected)
 {
     $result = Utils::snakeCaseToCamelCase($str);
     $this->assertEquals($expected, $result);
 }
Beispiel #2
0
 /**
  * Get the object properties in $data
  * Useful in controllers to have a method that accepts an array
  * @param string|array $data Name\value pairs to set, or can be string key
  * @param mixed $value
  */
 public function set($data, $value = null, $useCustomSetter = true)
 {
     // as we're supporting arrays, we'll make even a name/value
     // pair an array just so that we can use the same code later
     if (!is_array($data)) {
         $data = array($data => $value);
     }
     foreach ($data as $name => $value) {
         // check if a custom getter has been defined for this class
         $setterMethod = 'set' . Utils::snakeCaseToCamelCase($name);
         if ($useCustomSetter and method_exists($this, $setterMethod)) {
             $value = $this->{$setterMethod}($value);
         }
         // TODO can this be tidier, seems strange to pass $value twice (one for &ref, the other for value)
         // .. maybe try a Closure within the method to accomodate the &ref?
         $this->convertDotSyntaxNameToNestedArray($value, $name, $value);
         // set the update property so it knows what fields have changed
         $this->data = array_replace_recursive($this->data, $value);
     }
 }