예제 #1
0
 /**
  * Returns the correct string version of the object based on the given backend
  * This is intended mainly for SQL backends where the identifier is almost always used as foreign key
  * 
  * @param t41_Backend_Uri $backend
  * @return string
  */
 public function asString(BackendUri $backend = null)
 {
     if ($backend && $backend->getAlias() == $this->_backendUri->getAlias()) {
         return $this->_identifier;
     } else {
         return $this->__toString();
     }
 }
예제 #2
0
파일: Backend.php 프로젝트: crapougnax/t41
 /**
  * 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');
     }
 }