Beispiel #1
0
 /**
  * Get the adapter for a specific connection. If the adapter doesn't
  * exist, it is created. If the connection config isn't found, an
  * exception is thrown.
  *
  * @return Adapter
  * @throw Exception\RuntimeException
  */
 public function getAdapter($connectionName, array $options = [])
 {
     if (!isset($this->adapters[$connectionName])) {
         if (!$this->connectionExists($connectionName)) {
             throw new Exception\RuntimeException(sprintf('Connection doesn\'t exist: %s', $connectionName));
         }
         $connectionConfig = $this->connections[$connectionName];
         if (!isset($connectionConfig['driver'])) {
             throw new Exception\InvalidArgumentException('A "driver" key to be present inside the database config parameters');
         }
         if ($connectionConfig['driver'] == 'mongo') {
             $connection = new MongoConnection($connectionConfig);
             $this->adapters[$connectionName] = $connection;
         } else {
             $driver = DriverCreator::create($connectionName, $connectionConfig);
             $adapterParams = ['driver' => $driver];
             if (isset($options['allowProfiler']) && !$options['allowProfiler']) {
                 $adapterParams['profiler'] = false;
             }
             $adapter = new Adapter($adapterParams);
             $this->adapters[$connectionName] = $adapter;
             $driver->getConnection()->setAdapter($adapter);
             if (\Rails::cli()) {
                 $adapter->setProfiler(new \Zend\Db\Adapter\Profiler\Profiler());
             }
         }
     }
     return $this->adapters[$connectionName];
 }
Beispiel #2
0
 private function buildRequestInfo()
 {
     if (\Rails::application()->dispatcher() && ($request = \Rails::application()->dispatcher()->request())) {
         $info = '[' . $request->remoteIp() . '] ' . $request->method() . ' ' . $request->fullPath();
     } elseif (\Rails::cli()) {
         $info = '[cli]';
     } else {
         $info = '';
     }
     return $info;
 }
Beispiel #3
0
 /**
  * Boots system.
  */
 public static function initialize()
 {
     self::$cli = PHP_SAPI === 'cli';
     # Set Rails path
     self::$path = str_replace(DIRECTORY_SEPARATOR, '/', __DIR__);
     // self::$path = str_replace(DIRECTORY_SEPARATOR, '/', RAILS_PATH);
     # Set root path
     self::$root = str_replace(DIRECTORY_SEPARATOR, '/', RAILS_ROOT);
     # Set public path
     self::$publicPath = defined('RAILS_PUBLIC_PATH') ? RAILS_PUBLIC_PATH : self::$root . '/public';
     self::$publicPath = str_replace(DIRECTORY_SEPARATOR, '/', self::$publicPath);
     /**
      * Set environment.
      */
     self::$env = RAILS_ENV;
     self::$config = self::defaultConfig();
     # Debugging functions...
     include self::$path . '/Toolbox/functions.php';
     self::setRailsConfig();
 }
Beispiel #4
0
 public function _render_view()
 {
     $buffer = '';
     $this->_report = $this->_params['report'];
     unset($this->_params['report']);
     if (\Rails::application()->config()->consider_all_requests_local) {
         $no_html = \Rails::cli();
         if ($no_html) {
             $buffer .= strip_tags($this->_report);
             $buffer .= "\n";
         } else {
             $buffer .= $this->_header();
             $buffer .= $this->_report;
             $buffer .= $this->_footer();
         }
     } else {
         $file = \Rails::publicPath() . '/' . $this->_params['status'] . '.html';
         if (is_file($file)) {
             $buffer = file_get_contents($file);
         }
     }
     $this->_buffer = $buffer;
 }