コード例 #1
0
ファイル: Relationship.php プロジェクト: bullhorn/fast-rest
 /**
  * Constructor
  * @param Configuration $configuration
  * @param string $localTable
  * @param string $localColumn
  * @param string $remoteTable
  * @param string $remoteColumn
  * @param string $type
  * @param string $rawChanges
  */
 public function __construct(Configuration $configuration, $localTable, $localColumn, $remoteTable, $remoteColumn, $type, $rawChanges)
 {
     $this->setLocalTable($localTable);
     $this->setLocalColumn($localColumn);
     $this->setRemoteTable($remoteTable);
     $this->setRemoteColumn($remoteColumn);
     $this->setRemoteModel($configuration->getRootNamespace() . '\\Models\\' . $configuration->getModelSubNamespace() . '\\' . ucfirst($this->getRemoteTable()));
     $this->setRelationshipType($type);
     $this->setAction('NO_ACTION');
     if (preg_match_all('@ON (?P<actionType>(DELETE|UPDATE)+) (?P<action>(SET NULL|NO ACTION|CASCADE))@', $rawChanges, $subMatches)) {
         $length = sizeOf($subMatches[0]);
         $changes = array();
         for ($i = 0; $i < $length; $i++) {
             $changes[$subMatches['actionType'][$i]] = $subMatches['action'][$i];
         }
         $action = 'NO_ACTION';
         if (isset($changes['DELETE']) && $changes['DELETE'] == 'SET NULL') {
             $this->setNullable(true);
             $action = 'NO_ACTION';
         } elseif (isset($changes['DELETE']) && $changes['DELETE'] == 'CASCADE') {
             $action = 'ACTION_CASCADE';
         }
         $this->setAction($action);
     }
 }
コード例 #2
0
ファイル: ModelBuilder.php プロジェクト: bullhorn/fast-rest
 /**
  * Writes all of the models
  *
  * @param Configuration $configuration
  * @param string[] $ignoredTables
  *
  * @return void
  */
 public static function writeAll(Configuration $configuration, array $ignoredTables = [])
 {
     $results = $configuration->getConnection()->query('SHOW FULL TABLES WHERE Table_Type!="VIEW"');
     while ($result = $results->fetch()) {
         $result = (object) $result;
         $table = null;
         foreach ($result as $column) {
             $table = $column;
             break;
         }
         if (in_array($table, $ignoredTables)) {
             continue;
         }
         $index = new self($configuration, $table);
         $index->write();
     }
 }
コード例 #3
0
<?php

use Phalcon\DI\FactoryDefault;
use Bullhorn\FastRest\Generator\ModelBuilder;
use Bullhorn\FastRest\Generator\Configuration;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
require_once '/var/www/vendor/autoload.php';
/**
 * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
 */
$di = FactoryDefault::getDefault();
$di->set('instanceDb', function () {
    return new DbAdapter(array('host' => 'localhost', 'username' => 'root', 'password' => 'root', 'dbname' => 'db', 'port' => '3306'));
});
$configuration = new Configuration();
$configuration->setConnectionService('db');
$configuration->setRootDirectory('/var/www/web/app/');
$configuration->setRootTestDirectory('/var/www/tests');
$configuration->setRootNamespace('Api');
$configuration->setModelSubNamespace('Database');
$instanceConfiguration = $configuration;
//Build Controller
$modelBuilder = new ModelBuilder($instanceConfiguration, 'example');
$modelBuilder->write();