Permalink
Browse files

moved magic call

  • Loading branch information...
1 parent 213f85c commit b95debe01ccd90ca7a249b5b2bc7a383c951ec5f @mpscholten committed Oct 9, 2013
Showing with 58 additions and 0 deletions.
  1. +58 −0 src/Propel/Generator/Builder/Om/templates/Object/_magicCall.php.twig
@@ -0,0 +1,58 @@
+/**
+ * Catches calls to undefined methods.
+ *
+ * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
+ * Allows to define default __call() behavior if you overwrite __call()
+ *
+ * @param string $name
+ * @param mixed $params
+ *
+ * @return array|string
+ */
+public function __call($name, $params)
+{
+ {{ behavior_api.include('Object/_magicCall.php.twig', builder) }}
+
+ return $this->__parentCall($name, $params);
+}
+
+/**
+ * Derived method to catches calls to undefined methods.
+ *
+ * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
+ * Allows to define default __call() behavior if you overwrite __call()
+ *
+ * @param string $name
+ * @param mixed $params
+ *
+ * @return array|string
+ */
+public function __parentCall($name, $params)
+{
+ if (0 === strpos($name, 'get')) {
+ $virtualColumn = substr($name, 3);
+ if ($this->hasVirtualColumn($virtualColumn)) {
+ return $this->getVirtualColumn($virtualColumn);
+ }
+
+ $virtualColumn = lcfirst($virtualColumn);
+ if ($this->hasVirtualColumn($virtualColumn)) {
+ return $this->getVirtualColumn($virtualColumn);
+ }
+ }
+
+ if (0 === strpos($name, 'from')) {
+ $format = substr($name, 4);
+
+ return $this->importFrom($format, reset($params));
+ }
+
+ if (0 === strpos($name, 'to')) {
+ $format = substr($name, 2);
+ $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true;
+
+ return $this->exportTo($format, $includeLazyLoadColumns);
+ }
+
+ throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name));
+}

0 comments on commit b95debe

Please sign in to comment.