Exemplo n.º 1
0
function main()
{
    // do a migration
    $migration = new Migration();
    $migration->execute();
    $serviceManager = new ServiceManager();
    $serviceManager->scan();
    $serviceManager->processRequest();
}
Exemplo n.º 2
0
 /**
  * Save an entity
  * @param Model $entity
  */
 public function save(&$entity)
 {
     /* @var Column $keyColumn */
     $keyColumn = null;
     $tableName = $this->getTableName();
     $columns = Migration::getProperties($this->getEntityClass());
     $database = Database::getInstance();
     $keys = array();
     $values = array();
     foreach ($columns as $column) {
         if (!$column->isKey) {
             $keys[] = $column->name;
             $value = null;
             if (isset($entity->{$column->name})) {
                 $value = $entity->{$column->name};
             }
             $values[] = $value;
         } else {
             $keyColumn = $column;
         }
     }
     if ($keyColumn) {
         $keyValue = null;
         if (isset($entity->{$keyColumn->name})) {
             $keyValue = $entity->{$keyColumn->name};
         }
         $query = null;
         // if there is an id
         if ($keyValue != null) {
             $setCommands = array();
             foreach ($columns as $column) {
                 /* @var Column $column */
                 if (!$column->isKey) {
                     $setCommands[] = $column->name . " = ?";
                 }
             }
             $query = "UPDATE {$tableName}";
             $query .= " SET " . join(", ", $setCommands);
             $query .= " WHERE {$keyColumn->name} = ?";
             $values[] = $keyValue;
             $database->executeUpdate($query, $values);
         } else {
             $query = "INSERT INTO {$tableName}";
             $query .= "(" . join(", ", $keys) . ")";
             $questionMarks = array_fill(0, sizeof($columns) - 1, "?");
             $query .= "VALUES (" . join(", ", $questionMarks) . ")";
             $database->executeUpdate($query, $values);
             $entity->{$keyColumn->name} = $database->getInsertId();
         }
     }
 }