Example #1
0
 public function create($name)
 {
     if (isset($this->iterators[$name])) {
         return $this->iterators[$name];
     }
     if (!isset($this->orms[$name]) && isset($this->orms[Inflector::singularize($name)])) {
         $orm = $this->orms[Inflector::singularize($name)];
         $vos = $orm->getVos();
         //var_dump($name);
         $iterator = new Iterator_Mock($vos);
         $this->iterators[$name] = $iterator;
         return $this->iterators[$name];
     }
     if (!isset($this->orms[$name])) {
         $this->orms[$name] = new Orm_Mock($name);
     }
     return $this->orms[$name];
 }
Example #2
0
 public function create($tableName)
 {
     if (!$this->config) {
         trigger_error('Not configured', E_USER_WARNING);
         return;
     }
     try {
         $db = Driver_Factory::factory($this->config['dsn']);
     } catch (PDOException $e) {
         // PDO error
         trigger_error($e->getMessage(), E_USER_ERROR);
     } catch (Exception $e) {
         // framework error
         trigger_error($e->getMessage(), E_USER_ERROR);
     }
     $dao = new Orm_Pdo($db, $tableName);
     $dao->autoCreateConfig($this->config['autoConfig']);
     $dao->setTableConfigs($this->config['configFile']);
     if (!$dao->existsTable() && $dao->existsTable(Inflector::singularize($tableName))) {
         $dao->setTableName(Inflector::singularize($tableName));
         $dao = new Iterator_Orm($dao);
     }
     return $dao;
 }
Example #3
0
 public function autoload($name)
 {
     $pattern = preg_quote(__NAMESPACE__, '/');
     if (!preg_match("/^{$pattern}/", $name)) {
         return;
     }
     $pattern = preg_quote('\\');
     if (!preg_match("/({$pattern}[^{$pattern}]+)\$/", $name, $matches)) {
         return;
     }
     $className = $matches[1];
     $fullNamespace = str_replace($className, '', $name);
     $realNamespace = str_replace(__NAMESPACE__, '', $fullNamespace);
     $interface = $realNamespace . Inflector::singularize($className);
     $interface = ltrim($interface, '\\');
     $className = ltrim($className, '\\');
     // fullNamespace: laiz\lib\aggregate\path\to
     // realNamespace: \path\to
     // interface    : path\to\Object
     // className:     Objects
     // debug
     //var_dump($fullNamespace, $realNamespace, $interface, $className);
     eval("\nnamespace {$fullNamespace};\nuse \\ArrayObject;\nuse \\laiz\\builder\\Container;\nclass {$className} extends ArrayObject\n{\n    public function __construct(\$input = null, \$flag = 0, \$iterator = 'ArrayIterator')\n    {\n        if (\$input === null){\n            \$input = Container::getInstance()->getComponents('{$interface}');\n        }\n        parent::__construct(\$input, \$flag, \$iterator);\n    }\n}\n");
 }
Example #4
0
 /**
  * クラス名と関数名から引数のオブジェクトを生成して返却
  *
  * @param string $className
  * @param ReflectionMethod
  * @return Object[]
  * @access private
  */
 public static function getMethodParamObjectsByReflection($className, ReflectionMethod $method)
 {
     $params = array();
     $paramRefs = $method->getParameters();
     $container = Container::getInstance();
     foreach ($paramRefs as $paramRef) {
         try {
             $obj = $paramRef->getClass();
             if (!is_object($obj)) {
                 if (!$paramRef->isArray()) {
                     continue;
                 }
                 $name = $paramRef->getName();
                 $objs = $container->getComponents(Inflector::classify($name));
                 // if (count($objs) > 0)
                 $params[] = $objs;
                 continue;
             }
             $name = $obj->getName();
         } catch (ReflectionException $e) {
             $tmp = explode(' ', $e->getMessage(), 3);
             // "Class $name does not exist"からクラス名を取得
             $name = $tmp[1];
         }
         if (is_object($component = $container->get($name))) {
             $params[] = $component;
         } elseif ($component = $container->create($name)) {
             $params[] = $component;
         } else {
             trigger_error("Failed to create object [{$name}] by type hinting.", E_USER_WARNING);
         }
     }
     return $params;
 }