Ejemplo n.º 1
0
 public function testUnderscore()
 {
     $this->variable(PommInflector::underscore(null))->isNull()->string(PommInflector::underscore(''))->length->isEqualTo(0)->string(PommInflector::underscore('one'))->isEqualTo('one')->string(PommInflector::underscore('oneTwo'))->isEqualTo('one_two')->string(PommInflector::underscore('twoThreeFour'))->isEqualTo('two_three_four')->string(PommInflector::underscore('one_Two'))->isEqualTo('one__two')->string(PommInflector::underscore('one2Three'))->isEqualTo('one2_three')->string(PommInflector::underscore('one_2Three'))->isEqualTo('one_2_three')->string(PommInflector::underscore('One'))->isEqualTo('one');
 }
Ejemplo n.º 2
0
 protected function createWhereByCriteria($criteria = array())
 {
     $where = new Where();
     foreach ($criteria as $colname => $value) {
         $colname = Inflector::underscore($colname);
         $element = sprintf('%s = $*', $colname);
         $subWhere = new Where($element, array($value));
         $where->andWhere($subWhere);
     }
     return $where;
 }
Ejemplo n.º 3
0
 /**
  * __call
  *
  * Create handy methods to access clients through a pooler.
  *
  * @access  public
  * @param   string                   $method
  * @param   array                    $arguments
  * @throws  \BadFunctionCallException if unknown method
  * @throws  FoundationException      if no poolers found
  * @return  ClientInterface
  */
 public function __call($method, $arguments)
 {
     if (!preg_match('/get([A-Z][A-Za-z]+)/', $method, $matches)) {
         throw new \BadFunctionCallException(sprintf("Unknown method 'Session::%s()'.", $method));
     }
     return $this->getClientUsingPooler(Inflector::underscore($matches[1]), count($arguments) > 0 ? $arguments[0] : null);
 }
Ejemplo n.º 4
0
 /**
  * getCustomFields
  *
  * Return a list of custom methods with has() accessor.
  *
  * @access  private
  * @return  array
  */
 private function getCustomFields()
 {
     if (static::$has_methods === null) {
         static::fillHasMethods($this);
     }
     $custom_fields = [];
     foreach (static::$has_methods as $method) {
         if (call_user_func([$this, sprintf("has%s", $method)]) === true) {
             $custom_fields[Inflector::underscore(lcfirst($method))] = call_user_func([$this, sprintf("get%s", $method)]);
         }
     }
     return $custom_fields;
 }
Ejemplo n.º 5
0
 /**
  * extractMethodName
  *
  * Get container field name from method name.
  * It returns an array with the operation (get, set, etc.) as first member
  * and the name of the attribute as second member.
  *
  * @access protected
  * @param  string   $argument
  * @return array
  * @throws ModelException
  */
 protected function extractMethodName($argument)
 {
     $split = preg_split('/(?=[A-Z])/', $argument, 2);
     if (count($split) !== 2) {
         throw new ModelException(sprintf('No such argument "%s:%s()"', get_class($this), $argument));
     }
     return [$split[0], Inflector::underscore($split[1])];
 }