sfDoctrineRecord::__call PHP Method

__call() public method

Provides getter and setter methods.
public __call ( string $method, array $arguments ) : mixed
$method string The method name
$arguments array The method arguments
return mixed The returned value of the called method
    public function __call($method, $arguments)
    {
        $failed = false;
        try {
            if (in_array($verb = substr($method, 0, 3), array('set', 'get'))) {
                $name = substr($method, 3);
                $table = $this->getTable();
                if ($table->hasRelation($name)) {
                    $entityName = $name;
                } else {
                    if ($table->hasField($fieldName = $table->getFieldName($name))) {
                        $entityNameLower = strtolower($fieldName);
                        if ($table->hasField($entityNameLower)) {
                            $entityName = $entityNameLower;
                        } else {
                            $entityName = $fieldName;
                        }
                    } else {
                        $underScored = $table->getFieldName(sfInflector::underscore($name));
                        if ($table->hasField($underScored) || $table->hasRelation($underScored)) {
                            $entityName = $underScored;
                        } else {
                            if ($table->hasField(strtolower($name)) || $table->hasRelation(strtolower($name))) {
                                $entityName = strtolower($name);
                            } else {
                                $camelCase = $table->getFieldName(sfInflector::camelize($name));
                                $camelCase = strtolower($camelCase[0]) . substr($camelCase, 1, strlen($camelCase));
                                if ($table->hasField($camelCase) || $table->hasRelation($camelCase)) {
                                    $entityName = $camelCase;
                                } else {
                                    $entityName = $underScored;
                                }
                            }
                        }
                    }
                }
                return call_user_func_array(array($this, $verb), array_merge(array($entityName), $arguments));
            } else {
                $failed = true;
            }
        } catch (Exception $e) {
            $failed = true;
        }
        if ($failed) {
            try {
                return parent::__call($method, $arguments);
            } catch (Doctrine_Record_UnknownPropertyException $e2) {
            }
            if (isset($e) && $e) {
                throw $e;
            } else {
                if (isset($e2) && $e2) {
                    throw $e2;
                }
            }
        }
    }

Usage Example

 /**
  * Provides getter and setter methods.
  *
  * @param  string $method    The method name
  * @param  array  $arguments The method arguments
  *
  * @return mixed The returned value of the called method
  */
 public function __call($method, $arguments)
 {
     $failed = false;
     try {
         return parent::__call($method, $arguments);
     } catch (Exception $e) {
         $failed = true;
     }
     if ($failed) {
         try {
             if (in_array($verb = substr($method, 0, 3), array('set', 'get'))) {
                 $name = substr($method, 3);
                 /* @var $table Doctrine_Table */
                 $table = $this->getTable();
                 foreach ($table->getRelations() as $alias => $relation) {
                     if ($name == str_replace('_', '', $alias)) {
                         $entityName = $alias;
                     }
                 }
                 return call_user_func_array(array($this, $verb), array_merge(array($entityName), $arguments));
             }
         } catch (Exception $e) {
             $failed = true;
         }
         if ($failed) {
             throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown method %s::%s', get_class($this), $method));
         }
     }
 }
All Usage Examples Of sfDoctrineRecord::__call