<commit_before><?php

namespace Logikos\Application;


use Phalcon\Di;
use Phalcon\Config;
use Phalcon\Loader;
use Phalcon\Mvc\Router;
use Phalcon\Events\Event;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Application;
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Error\Handler as ErrorHandler;
use Phalcon\Events\Manager as EventsManager;
use Phalcon\Logger\Adapter\File as FileLogger;
use Phalcon\Mvc\Model\Manager as ModelsManager;
use Phalcon\Di\Injectable;
use Logikos\Application\Bootstrap\Modules;

class Bootstrap extends Injectable {
  //use \Logikos\UserOptionTrait;
  
  private $_defaultOptions = [
      'basedir'  => null,
      'confdir'  => null,
      'appdir'   => null,
      'config'   => null,
      'app'      => null,
      'eventsManager' => null,
      'env'      => 'development',
      'defaultModule' => null
  ];
  
  /**
   * @var Application
   */
  public $app;
  
  /**
   * @var Config
   */
  public $config;
  
  /**
   * @var Modules
   */
  public $modules;
  
  const ENV_PRODUCTION  = 'production';
  const ENV_STAGING     = 'staging';
  const ENV_DEVELOPMENT = 'development';
  const ENV_TESTING     = 'testing';
  
  public function __construct(Di $di=null, $config = null, array $userOptions = null) {
    $di = $this->initDi($di);
    $this->initOptions($di, $config, $userOptions);
    $this->initEventsManager($di);
  }
  protected function initDi($di) {
    if (!$di instanceof Di)
      $di = new FactoryDefault();
    $this->setDi($di);
    Di::setDefault($di);
    return $di;
  }
  public function setUserOption($option, $value) {
    $this->config[$option] = $value;
  }
  public function getUserOption($option, $default=null) {
    $value = $this->config->get($option);
    
    if ($value instanceof Config)
      $value = $value->toArray();
    
    if (is_null($value) && !is_null($default))
      $value = $default;
    
    return $value;
  }
  public function setUserOptions(array $options) {
    $this->config->merge($options instanceof Config?$options:new Config($options));
  }
  public function getUserOptions() {
    return $this->config->toArray();
  }
  public function run() {
    if (!defined('APP_ENV'))
      define('APP_ENV', getenv('APP_ENV') ?: static::ENV_PRODUCTION);
    $di     = $this->getDi();
    $config = $this->initConfig($di);
    
    if ($config->get('autoload'))
      $this->initLoader($config->get('autoload'));
    $this->app = $this->getUserOption('app',new Application);
    $this->app->setDI($di);
    $this->app->setEventsManager($di->get('eventsManager'));
    if ($this->_shouldAutoloadModules())
      $this->initModules($this->_moduleConfig(), $this->_moduleOptions());
    
    $di->setShared('app', $this->app);
    return $this;
  }

  /**
   * @return \Phalcon\Mvc\Application
   */
  public function getApp() {<commit_msg>bootstrap now disables implicit views if a viewservice is set in DI and it is not a ViewInterface<commit_after><?php

namespace Logikos\Application;


use Phalcon\Di;
use Phalcon\Config;
use Phalcon\Loader;
use Phalcon\Mvc\Router;
use Phalcon\Events\Event;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Application;
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Error\Handler as ErrorHandler;
use Phalcon\Events\Manager as EventsManager;
use Phalcon\Logger\Adapter\File as FileLogger;
use Phalcon\Mvc\Model\Manager as ModelsManager;
use Phalcon\Di\Injectable;
use Logikos\Application\Bootstrap\Modules;
use Phalcon\Mvc\ViewInterface;

class Bootstrap extends Injectable {
  //use \Logikos\UserOptionTrait;
  
  private $_defaultOptions = [
      'basedir'  => null,
      'confdir'  => null,
      'appdir'   => null,
      'config'   => null,
      'app'      => null,
      'eventsManager' => null,
      'env'      => 'development',
      'defaultModule' => null
  ];
  
  /**
   * @var Application
   */
  public $app;
  
  /**
   * @var Config
   */
  public $config;
  
  /**
   * @var Modules
   */
  public $modules;
  
  const ENV_PRODUCTION  = 'production';
  const ENV_STAGING     = 'staging';
  const ENV_DEVELOPMENT = 'development';
  const ENV_TESTING     = 'testing';
  
  public function __construct(Di $di=null, $config = null, array $userOptions = null) {
    $di = $this->initDi($di);
    $this->initOptions($di, $config, $userOptions);
    $this->initEventsManager($di);
  }
  protected function initDi($di) {
    if (!$di instanceof Di)
      $di = new FactoryDefault();
    $this->setDi($di);
    Di::setDefault($di);
    return $di;
  }
  public function setUserOption($option, $value) {
    $this->config[$option] = $value;
  }
  public function getUserOption($option, $default=null) {
    $value = $this->config->get($option);
    
    if ($value instanceof Config)
      $value = $value->toArray();
    
    if (is_null($value) && !is_null($default))
      $value = $default;
    
    return $value;
  }
  public function setUserOptions(array $options) {
    $this->config->merge($options instanceof Config?$options:new Config($options));
  }
  public function getUserOptions() {
    return $this->config->toArray();
  }
  public function run() {
    if (!defined('APP_ENV'))
      define('APP_ENV', getenv('APP_ENV') ?: static::ENV_PRODUCTION);
    $di     = $this->getDi();
    $config = $this->initConfig($di);
    
    if ($config->get('autoload'))
      $this->initLoader($config->get('autoload'));
    $this->app = $this->getUserOption('app',new Application);
    $this->app->setDI($di);
    $this->app->setEventsManager($di->get('eventsManager'));
    
    // disable implicit views if using simple views
    if ($view = $di->get('view'))
      if (!$view instanceof ViewInterface)
        $this->app->useImplicitView(false);
    
    if ($this->_shouldAutoloadModules())
      $this->initModules($this->_moduleConfig(), $this->_moduleOptions());
    
    $di->setShared('app', $this->app);
    return $this;
  }

  /**
   * @return \Phalcon\Mvc\Application
   */
  public function getApp() {
{'fraction_non_alphanumeric': 0.15829730628533423, 'fraction_numerical': 0.0, 'mean_word_length': 3.3025751072961373, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6620093', 'n_tokens_mistral': 2008, 'n_tokens_neox': 2015, 'n_words': 416}