示例#1
0
 /**
  * {@inherit}.
  *
  * @throws \Exception
  */
 public function map($from, $to)
 {
     foreach ($this->strategies as $class => $strategy) {
         if ($from instanceof $class) {
             return $strategy->map($from, $to);
         }
     }
     if ($this->fallaback) {
         return $this->fallaback->map($from, $to);
     }
     throw new MapperNotFoundException($from);
 }
示例#2
0
文件: Binder.php 项目: eux/Bindto
 /**
  * @param mixed $request
  * @param mixed $object
  *
  * @return BindResult
  *
  * @throws \Exception
  */
 public function bind($request, $object)
 {
     if (!is_object($object)) {
         $object = new $object();
     }
     $newObject = $this->mapper->map($request, $object);
     $groups = $this->defaultGroups;
     if (is_callable(array($request, 'getMethod'), true)) {
         $groups[] = $request->getMethod();
     }
     $issues = $this->validator->validate($object, null, $groups);
     return $this->createBindResultFromFilledObject($issues, $newObject);
 }
示例#3
0
文件: Binder.php 项目: pugx/bindto
 /**
  * @param mixed $request
  * @param mixed $object
  * @param string[] $validationGroups Groups to apply validation to
  *
  * @return BindResult
  *
  * @throws \Exception
  */
 public function bind($request, $object, array $validationGroups = [])
 {
     if (!is_object($object)) {
         $object = new $object();
     }
     $newObject = $this->mapper->map($request, $object);
     $groups = $this->defaultGroups;
     if (method_exists($request, 'getMethod')) {
         $groups[] = $request->getMethod();
     }
     $groups = array_merge($groups, $validationGroups);
     $issues = $this->validator->validate($object, null, $groups);
     return $this->createBindResultFromFilledObject($issues, $newObject);
 }