Ejemplo n.º 1
0
 /**
  * Get files content.
  *
  * @param  \Conrock\Application $app
  *
  * @return array
  */
 private function get_files_content(Application $app)
 {
     $config_path = $app->get_config_path();
     $environment = $app->get_environment();
     $files = [];
     foreach (Finder::create()->files()->name('*.php')->in($config_path) as $file) {
         $directory = dirname($file->getRealPath());
         if ($config_path !== $directory && !preg_match('/' . $environment . '$/', $directory)) {
             continue;
         }
         if ($tree = trim(str_replace($config_path, '', $directory), '/')) {
             $tree = str_replace('/', '.', $tree) . '.';
         }
         $files[$tree . basename($file->getRealPath(), '.php')] = $file->getRealPath();
     }
     $merge = [];
     foreach ($files as $key => $path) {
         $key = explode('.', $key);
         $key = array_pop($key);
         if (!isset($merge[$key])) {
             $merge[$key] = [];
         }
         $value = (require $path);
         if (!is_array($value)) {
             continue;
         }
         $merge[$key] = array_merge($merge[$key], $value);
     }
     return $merge;
 }
Ejemplo n.º 2
0
 /**
  * Bootstrap Dotenv.
  *
  * @param  \Conrock\Application $app
  */
 public function bootstrap(Application $app)
 {
     $path = $app->get_base_path();
     if (!file_exists($path . '/.env')) {
         throw new InvalidArgumentException('Cannot find .env file in ' . $path);
     }
     $dotenv = new Dotenv($path);
     $dotenv->load();
     $dotenv->required($app->get_required());
     if (!defined('WP_ENV')) {
         define('WP_ENV', getenv('WP_ENV') ?: 'development');
     }
 }
Ejemplo n.º 3
0
 /**
  * Bootstrap constants.
  *
  * @param  \Conrock\Application $app
  */
 public function bootstrap(Application $app)
 {
     $config = $app->make('Conrock\\config');
     $collection = $config->get_collection();
     foreach ($collection as $key => $list) {
         foreach ($list as $lkey => $lval) {
             if (is_array($lval) || is_object($lval)) {
                 continue;
             }
             $app->define(strtoupper($lkey), $config->nesting($lval));
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Get the available Conrock instance.
  *
  * @param  string $make
  *
  * @return \Conrock\Conrock
  */
 function conrock($make = null)
 {
     if (is_null($make)) {
         return \Conrock\Application::get_instance();
     }
     return \Conrock\Application::get_instance()->make('Conrock\\' . $make);
 }