/** * Tests the SimpleFacadeBeanHelper factory setter. * * @return void */ public function testFactory() { SimpleFacadeBeanHelper::setFactoryFunction(function ($name) { $model = new $name(); $model->setNote('injected', 'dependency'); return $model; }); $bean = R::dispense('band')->box(); asrt($bean instanceof \Model_Band, TRUE); asrt($bean->getNote('injected'), 'dependency'); SimpleFacadeBeanHelper::setFactoryFunction(NULL); }
/** * @param ConfigInterface $config * @throws InvalidConfigException */ public function __construct(ConfigInterface $config) { $this->setConfig($config); if ($this->configIsEmpty('timezone')) { $this->getConfigObject()->setProtected('timezone', 'Asia/Jakarta'); } if ($this->configIsEmpty('publicDir')) { $this->getConfigObject()->setPublic('publicDir', 'public/'); } $this->setupTheme(); $this->langAdjustment(); date_default_timezone_set($this->config('timezone')); $this->addLangfile('common', $this->config('language')); $this->addLangfile('common', $this->getLanguage()); // Setting up RedBean $dbConfig = $config->getProtected('dbConfig'); if (!empty($dbConfig)) { $namespace = 'App'; if (!$this->configIsEmpty('namespace')) { $namespace = $this->config('namespace'); } if (!defined('REDBEAN_MODEL_PREFIX')) { define('REDBEAN_MODEL_PREFIX', '\\' . $namespace . '\\Models\\'); } if ($dbConfig['type'] == 'mysql') { self::setupRedBean("mysql:host={$dbConfig['host']};dbname={$dbConfig['dbname']};port={$dbConfig['port']}", $dbConfig['user'], $dbConfig['password'], $config->getProtected('isDevMode')); } elseif ($dbConfig['type'] == 'sqlite') { self::setupRedBean("sqlite:{$dbConfig['dbname']}", $dbConfig['user'], $dbConfig['password'], $config->getProtected('isDevMode')); } if (!$this->configIsEmpty('freeze') && $this->config('freeze') == false) { R::freeze(false); } // Below is needed so that RedBeanPHP\SimpleModel may use $this->app: SimpleFacadeBeanHelper::setFactoryFunction(function ($beanTypeName) { /** @var \Skully\App\Models\BaseModel $model */ $model = new $beanTypeName(); $model->setApp($this); return $model; }); } }