Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
lajosbencz committed Sep 7, 2019
1 parent 9abb8be commit 1000c40
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/PhalconModelGenerator/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function initialize()
{
$config = $this->getGenerator()->getConfig();
$blacklist = [];
if($config->offsetExists('blacklist')) {
if ($config->offsetExists('blacklist')) {
$blacklist = (array)$config->blacklist;
}
foreach ($this->generator->listTables() as $table) {
if(in_array($table, $blacklist)) {
if (in_array($table, $blacklist)) {
continue;
}
$this->_tables[$table] = new Table($this, $table);
Expand All @@ -52,8 +52,8 @@ public function initialize()
if (isset($this->_references[$tn])) {
foreach ($this->_references[$tn] as $tc => $refs) {
$tcn = preg_replace('/_id$/', '', $tc);
foreach($refs as $rt => $refCols) {
if(!array_key_exists($rt, $this->_tables)) {
foreach ($refs as $rt => $refCols) {
if (!array_key_exists($rt, $this->_tables)) {
continue 2;
}
}
Expand All @@ -68,8 +68,8 @@ public function initialize()
foreach ($this->_references as $rt => $refCols) {
foreach ($refCols as $rc => $refs) {
$rcn = preg_replace('/_id$/', '', $rc);
foreach($refs as $rt => $refCols) {
if(!array_key_exists($rt, $this->_tables)) {
foreach ($refs as $rt => $refCols) {
if (!array_key_exists($rt, $this->_tables)) {
continue 2;
}
}
Expand Down Expand Up @@ -102,14 +102,14 @@ public function initialize()

}

public function tables()
public function getGenerator(): Generator
{
return $this->_tables;
return $this->generator;
}

public function getGenerator(): Generator
public function tables()
{
return $this->generator;
return $this->_tables;
}

public function getName()
Expand Down
19 changes: 9 additions & 10 deletions src/PhalconModelGenerator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use Phalcon\Config;
use Phalcon\Db\Adapter\Pdo\Factory;
use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\Di\FactoryDefault;
use Phalcon\DiInterface;
use Phalcon\Logger;
Expand All @@ -22,18 +21,18 @@ class Generator extends Component
protected $_config;
protected $_configKey;

public function __construct(Config $config, string $configKey=null, DiInterface $di = null)
public function __construct(Config $config, string $configKey = null, DiInterface $di = null)
{
$this->_config = $config;
$configKey = $configKey ?? self::DEFAULT_CONFIG_KEY;
$this->_configKey = $configKey;

if(!$config->offsetExists($configKey)) {
throw new Exception('missing config key: '.$configKey);
if (!$config->offsetExists($configKey)) {
throw new Exception('missing config key: ' . $configKey);
}
foreach(['directory','namespace','namespace_auto','base_model','base_view','reusable','log'] as $k) {
if(!$config->{$this->_configKey}->offsetExists($k)) {
throw new Exception('missing config key: '.$configKey.'.'.$k);
foreach (['directory', 'namespace', 'namespace_auto', 'base_model', 'base_view', 'reusable', 'log'] as $k) {
if (!$config->{$this->_configKey}->offsetExists($k)) {
throw new Exception('missing config key: ' . $configKey . '.' . $k);
}
}

Expand All @@ -50,16 +49,16 @@ public function __construct(Config $config, string $configKey=null, DiInterface
$this->setDI($di);
}

if(!$di->has('db')) {
if(!$config->offsetExists('database')) {
if (!$di->has('db')) {
if (!$config->offsetExists('database')) {
throw new Exception('missing config key: database');
}
$di->setShared('db', function () use ($config) {
return Factory::load($config->database);
});
}

if(!$di->has('log')) {
if (!$di->has('log')) {
$di->setShared('log', function () use ($config, $configKey) {
$logger = new Logger\Multiple();
$log = $config->{$configKey}->log;
Expand Down

0 comments on commit 1000c40

Please sign in to comment.