/** * Map properties against mapper to obtain a backend-compatible array * * @param t41\Backend\Mapper $mapper * @param t41\Backend\Adapter\AbstractAdapter $backend * @return array */ public function map(\t41\Backend\Mapper $mapper, $backend) { $array = $this->toArray($backend); return array('data' => $mapper->toArray($array['data'], $this->_class), 'collections' => $array['collections']); }
/** * Instanciate a backend from its uri * * @param t41_Uri $uri * @param string $alias alias name * @param string $mapper mapper name * @return t41\Backend\Adapter\AbstractAdapter * @throws t41\Backend\Exception */ public static function factory(Backend\BackendUri $uri, $alias = null, $mapper = null) { if (!is_null($alias)) { $uri->setAlias($alias); } $parts = explode('_', $uri->getType()); foreach ($parts as $key => $part) { $parts[$key] = ucfirst(strtolower($part)); } $backendClass = sprintf('\\t41\\Backend\\Adapter\\%sAdapter', implode('\\', $parts)); try { $backend = new $backendClass($uri); $alias = self::addBackend($backend, $alias); if ($mapper) { $backend->setMapper(Backend\Mapper::getInstance($mapper)); } return $backend; } catch (\Exception $e) { throw new Backend\Exception('UNKNOWN_CLASS'); } }