Пример #1
0
 /**
  * Constructor.
  *
  * @param string $key Criteria expression key that includes property name and an optional operator prefixed with `:`
  *                    e.g. `id:not`.
  * @param mixed $value Value for criteria filter.
  *
  * @throws InvalidOperatorException When invalid or unsupported operator given.
  */
 public function __construct($key, $value)
 {
     // explode the key in search for an operator
     $explodedKey = explode(':', $key);
     // just specify the property name
     $this->property = $explodedKey[0];
     if (empty($this->property)) {
         throw new \InvalidArgumentException(sprintf('Property name part of a key should not be empty in criteria expression, "%s" given.', $key));
     }
     // if there was no operator specified then use the EQUALS operator by default
     $operator = isset($explodedKey[1]) ? strtolower($explodedKey[1]) : 'eq';
     $operatorFn = StringUtils::toCamelCase($operator, '_') . 'Operator';
     // if there is no function defined to handle this operator then throw an exception
     if (!method_exists($this, $operatorFn)) {
         throw new InvalidOperatorException(sprintf('Unrecognized operator passed in criteria, "%s" given.', $key));
     }
     $this->{$operatorFn}($value);
 }
Пример #2
0
 public function testToCamelCase()
 {
     $this->assertEquals('whateverElse', StringUtils::toCamelCase('whatever-else'));
     $this->assertEquals('loremIpsumDolorSitAmet', StringUtils::toCamelCase('lorem-ipsum-dolor-sit-amet'));
     $this->assertEmpty(StringUtils::toCamelCase(''));
     $this->assertEquals('loremIpsumDolor', StringUtils::toCamelCase('lorem_ipsum_dolor', '_'));
     $this->assertEquals('lorem_IpsumDolor', StringUtils::toCamelCase('lorem__ipsum_dolor', '_'));
 }
Пример #3
0
 /**
  * Creates a setter name for the given object property name.
  *
  * Converts `snake_notation` to `camelCase`.
  *
  * Example:
  *
  *      echo \MD\Foundation\Utils\ObjectUtils::setter('property_name');
  *      // -> `setPropertyName`
  * 
  * @param string $property Property name.
  * @return string
  */
 public static function setter($property)
 {
     return 'set' . ucfirst(StringUtils::toCamelCase($property, '_'));
 }