コード例 #1
0
ファイル: Generator.php プロジェクト: mrblackus/micro-muffin
 public static function run()
 {
     self::init();
     self::writeLine("micro-muffin v" . LIB_VERSION_NUMBER . " generator");
     self::writeLine("Emptying t_model directory");
     self::emptyDirectory(self::$relativeTModelSaveDir);
     self::writeLine("Emptying sp_model directory");
     self::emptyDirectory(self::$relativeSPModelSaveDir);
     self::writeLine("Connecting to " . DBNAME . " on " . DBHOST . "...");
     try {
         $pdo = PDOS::getInstance();
         $driver = MicroMuffin::getDBDriver();
         self::writeLine("Success !", 'green');
         self::writeLine("Retrieving database " . DBSCHEMA . " schema...");
         $schema = $driver->getAbstractSchema();
         self::writeLine(count($schema->getTables()) . " tables founds");
         self::writeLine("Writing models...");
         $schema->writeFiles();
         self::writeLine("Done !");
         self::writeLine("Enjoy ! ;)");
     } catch (\Exception $e) {
         self::writeLine("Error ! Connection to database failed.", 'red');
         self::writeLine("Error returned : " . $e->getMessage(), 'red');
         die;
     }
 }
コード例 #2
0
ファイル: Writable.php プロジェクト: mrblackus/micro-muffin
 private function add()
 {
     $aAttributes = $this->getAttributes(new \ReflectionClass($this));
     //Detection of attributes to insert : non sequence holder and sequence holder that are null
     $aAttributesToInsert = array();
     $aSequencedAttributes = array();
     foreach ($aAttributes as $att => $val) {
         if (!array_key_exists($att, static::$_sequences) || !is_null($aAttributes[$att])) {
             $aAttributesToInsert[$att] = $val;
         } else {
             $aSequencedAttributes[] = $att;
         }
     }
     //Request building
     $sFields = '';
     $sPlaceholders = '';
     foreach ($aAttributesToInsert as $att => $val) {
         $sFields .= $att . ', ';
         $sPlaceholders .= ':' . $att . ', ';
     }
     $sFields = substr($sFields, 0, -2);
     $sPlaceholders = substr($sPlaceholders, 0, -2);
     $pdo = PDOS::getInstance();
     $driver = MicroMuffin::getDBDriver();
     $query = $pdo->prepare('INSERT INTO ' . static::getTableName() . ' (' . $sFields . ') VALUES(' . $sPlaceholders . ')');
     foreach ($aAttributesToInsert as $att => $val) {
         $driver::bindPDOValue($query, ':' . $att, $val);
     }
     $query->execute();
     //Retrieving sequence values for concerned attributes
     foreach ($aSequencedAttributes as $att) {
         $attributeName = '_' . $att;
         $this->{$attributeName} = $pdo->lastInsertId(static::$_sequences[$att]);
     }
     $this->_MM_notInserted = false;
 }
コード例 #3
0
 /**
  * @return bool
  */
 public function isStringType()
 {
     return MicroMuffin::getDBDriver()->isTypeString($this->type);
 }