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");
 }