the function of this method is to try to find a given method from the templates (behaviors)
the record is using, and if found, execute it. Note that already existing methods would not be
overloaded.
So, in sense, this method replicates the usage of mixins (as seen in some programming languages)
/** * Extract the value of the field from a record. * @param Doctrine_Record $record * @return mixed */ public function getValue($record) { if (!$this->getField()) { throw new IllegalStateException('Not field defined por relation ' . $this->getName()); } $getter = 'get' . ucfirst($this->getName()); return $this->getField()->getValue($record->__call($getter, array())); }
/** * 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 { 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; } } } }
/** * Extract the value of the field from a record. * @param Doctrine_Record $record * @return mixed */ public function getValue($record) { $getter = 'get' . ucfirst($this->getName()); return $record->__call($getter, array()); }
public function __call($method, $arguments) { 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))) { $entityName = strtolower($fieldName); } else { $underScored = $table->getFieldName(sfInflector::underscore($name)); if ($table->hasField($underScored)) { $entityName = $underScored; } else { if ($table->hasField(strtolower($name))) { $entityName = strtolower($name); } else { $entityName = $underScored; } } } } return call_user_func_array(array($this, $verb), array_merge(array($entityName), $arguments)); } else { return parent::__call($method, $arguments); } } catch (Exception $e) { return parent::__call($method, $arguments); } }
/** * This magic __call is used to provide propel style accessors to Doctrine models * * @param string $m * @param string $a * @return void */ public function __call($m, $a) { try { $verb = substr($m, 0, 3); if ($verb == 'set' || $verb == 'get') { $camelColumn = substr($m, 3); // If is a relation if (in_array($camelColumn, array_keys($this->getTable()->getRelations()))) { $column = $camelColumn; } else { $column = sfInflector::underscore($camelColumn); } if ($verb == 'get') { return $this->get($column); } else { return $this->set($column, $a[0]); } } else { return parent::__call($m, $a); } } catch (Exception $e) { return parent::__call($m, $a); } }