Exemple #1
0
 /**
  * This method returns whether the specified method exists.
  *
  * @access public
  * @param string $method                                    the name of the method
  * @return boolean                                          whether the specified method exists
  */
 public function __hasMethod($method)
 {
     if (parent::__hasMethod($method)) {
         return true;
     } else {
         if (preg_match('/^get[_a-zA-Z0-9]+$/', $method)) {
             $properties = preg_split('/_+/', substr($method, 3));
             $value = $this->models;
             foreach ($properties as $key) {
                 if (!property_exists($value, $key)) {
                     return false;
                 }
                 $value = $value->{$key};
             }
             return true;
         }
     }
     return false;
 }
Exemple #2
0
 /**
  * This method returns whether the specified method exists.
  *
  * @access public
  * @param string $method                                    the name of the method
  * @return boolean                                          whether the specified method exists
  */
 public function __hasMethod($method)
 {
     if (parent::__hasMethod($method)) {
         return true;
     } else {
         if (preg_match('/^(g|s)et[_a-zA-Z0-9]+$/', $method)) {
             $field = substr($method, 3);
             $scope = substr($method, 0, 3);
             $nodes = $this->resource->xpath("/translators/translator[@name='{$this->name}']/fields/field[@name='{$field}' and (@scope='{$scope}' or @scope='both')]");
             return count($nodes) > 0;
         }
     }
     return false;
 }
Exemple #3
0
 /**
  * This method maps the getter methods in the source model's translator to their corresponding setter
  * methods in the target model's translator.
  *
  * @access public
  * @static
  * @param \Unicity\MappingService\Data\Translator $source      the model that will be the source for
  *                                                             the mapping
  * @param \Unicity\MappingService\Data\Translator $target      the model that will be the target for
  *                                                             the mapping
  */
 public static function map(MappingService\Data\Translator $source, MappingService\Data\Translator $target)
 {
     $source->__before(static::SOURCE_MAPPING);
     $target->metadata =& $source->metadata;
     $target->__before(static::TARGET_MAPPING);
     $set = 'set';
     $get = 'get';
     if ($source->__getClass() == $target->__getClass()) {
         $set = 'u' . $set;
         $get = 'u' . $get;
     }
     $methods = $target->__getMethods();
     foreach ($methods as $method) {
         if (preg_match("/^{$set}[_a-zA-Z0-9]+\$/", $method)) {
             $getter = $get . substr($method, 3);
             if ($source->__hasMethod($getter)) {
                 $target->{$method}($source->{$getter}());
             }
         }
     }
     $target->__after(static::TARGET_MAPPING);
     $source->__after(static::SOURCE_MAPPING);
 }