Example #1
0
    /**
     * Adds support for magic finders.
     *
     * @return array|object The found entity/entities.
     * @throws BadMethodCallException  If the method called is an invalid find* method
     *                                 or no find* method at all and therefore an invalid
     *                                 method call.
     */
    public function __call($method, $arguments)
    {
        if (substr($method, 0, 6) == 'findBy') {
            $by = substr($method, 6, strlen($method));
            $method = 'findBy';
        } else if (substr($method, 0, 9) == 'findOneBy') {
            $by = substr($method, 9, strlen($method));
            $method = 'findOneBy';
        } else {
            throw new \BadMethodCallException(
                "Undefined method '$method'. The method name must start with ".
                "either findBy or findOneBy!"
            );
        }

        if ( !isset($arguments[0])) {
            // we dont even want to allow null at this point, because we cannot (yet) transform it into IS NULL.
            throw ORMException::findByRequiresParameter($method.$by);
        }

        $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));

        if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) {
            return $this->$method(array($fieldName => $arguments[0]));
        } else {
            throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method.$by);
        }
    }
 /**
  * Adds support for magic finders.
  *
  * @return array|object The found entity/entities.
  * @throws BadMethodCallException  If the method called is an invalid find* method
  *                                 or no find* method at all and therefore an invalid
  *                                 method call.
  */
 public function __call($method, $arguments)
 {
     if (substr($method, 0, 6) == 'findBy') {
         $by = substr($method, 6, strlen($method));
         $method = 'findBy';
     } else {
         if (substr($method, 0, 9) == 'findOneBy') {
             $by = substr($method, 9, strlen($method));
             $method = 'findOneBy';
         } else {
             throw new \BadMethodCallException("Undefined method '{$method}'. The method name must start with " . "either findBy or findOneBy!");
         }
     }
     if (!isset($arguments[0])) {
         throw ORMException::findByRequiresParameter($method . $by);
     }
     $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
     if ($this->_class->hasField($fieldName)) {
         return $this->{$method}(array($fieldName => $arguments[0]));
     } else {
         throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method . $by);
     }
 }
 /**
  * Adds support for magic finders.
  *
  * @return array|object The found entity/entities.
  * @throws BadMethodCallException  If the method called is an invalid find* method
  *                                 or no find* method at all and therefore an invalid
  *                                 method call.
  */
 public function __call($method, $arguments)
 {
     if (substr($method, 0, 6) == 'findBy') {
         $by = substr($method, 6, strlen($method));
         $method = 'findBy';
     } else {
         if (substr($method, 0, 9) == 'findOneBy') {
             $by = substr($method, 9, strlen($method));
             $method = 'findOneBy';
         } else {
             throw new \BadMethodCallException("Undefined method '{$method}'.");
         }
     }
     if (!isset($arguments[0])) {
         throw DoctrineException::findByNameRequired();
     }
     $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
     if ($this->_class->hasField($fieldName)) {
         return $this->{$method}(array($fieldName => $arguments[0]));
     } else {
         throw \Doctrine\Common\DoctrineException::invalidFindBy($by);
     }
 }
Example #4
0
 /**
  * Adds support for magic finders.
  *
  * @return array|object The found entity/entities.
  * @throws BadMethodCallException  If the method called is an invalid find* method
  *                                 or no find* method at all and therefore an invalid
  *                                 method call.
  */
 public function __call($method, $arguments)
 {
     switch (true) {
         case substr($method, 0, 6) == 'findBy':
             $by = substr($method, 6, strlen($method));
             $method = 'findBy';
             break;
         case substr($method, 0, 9) == 'findOneBy':
             $by = substr($method, 9, strlen($method));
             $method = 'findOneBy';
             break;
         default:
             throw new \BadMethodCallException("Undefined method '{$method}'. The method name must start with " . "either findBy or findOneBy!");
     }
     if (empty($arguments)) {
         throw ORMException::findByRequiresParameter($method . $by);
     }
     $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
     if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) {
         return $this->{$method}(array($fieldName => $arguments[0]));
     }
     throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method . $by);
 }