コード例 #1
0
ファイル: PerfORM.php プロジェクト: Edke/PerfORM
 /**
  * Build model definition from setup
  *
  * Model will be cached if caching is enabled (PerfORMController::useModelCaching())
  */
 protected function buildDefinition()
 {
     $this->setup();
     if (!$this->getPrimaryKey() && $this->isTable() && $this->isExtended()) {
         $field = new IntegerField($this, $this->defaultPrimaryKey);
         $field->setPrimaryKey();
         $this->attachField($field, true);
         $this->setPrimaryKey($this->defaultPrimaryKey);
     } elseif (!$this->getPrimaryKey() && $this->isTable()) {
         $field = new AutoField($this, $this->defaultPrimaryKey);
         $field->setPrimaryKey();
         $this->attachField($field, true);
         $this->setPrimaryKey($this->defaultPrimaryKey);
     }
     $this->validate();
     # indexes
     foreach ($this->getFields() as $field) {
         foreach ($field->getIndexes() as $index) {
             $this->addIndex($field->getName(), $index->name, $index->unique);
         }
     }
     # aliases for model
     $this->buildAliases();
     # model hashing
     $model_hashes = array();
     if ($this->isTable()) {
         foreach ($this->getFields() as $field) {
             $model_hashes[] = md5($field->getName() . '|' . $field->getHash());
         }
         foreach ($this->getIndexes() as $index) {
             $model_hashes[] = md5($index->getName() . '|' . $index->getHash());
         }
         sort($model_hashes);
         $this->hash = md5(implode('|', $model_hashes));
     } elseif ($this->isView()) {
         $view = $this->getViewSetup();
         $view = trim(preg_replace('#\\s{2,}#m', ' ', $view));
         $this->hash = md5($view);
     }
     /*        if (PerfORMController::useModelCaching()) {
               $cache = PerfORMController::getCache();
               $cache->save($this->getCacheKey(), $this, array(
               Cache::FILES => array(__FILE__),
               ));
               } */
 }