public static function init() { try { if (!Schema::hasTable('sites')) { return static::setCurrent(new Site()); } } catch (\Exception $e) { return static::setCurrent(new Site()); } static::$baseUrl = $baseUrl = rtrim(config('app.url'), '/'); static::$domain = $domain = parse_url($baseUrl, PHP_URL_HOST); $basePath = parse_url($baseUrl, PHP_URL_PATH); static::$host = $host = parse_url(request()->root(), PHP_URL_HOST); if (false === strpos($host, $domain) && !request()) { throw new \Exception('Anda harus men-set konfigurasi domain ' . $domain); } $subdomain = $basePath ? null : rtrim(substr($host, 0, strlen($host) - strlen($domain)), '.'); if ($subdomain) { return static::initSubdomain($subdomain); } if ($site = static::getBySubfolder(new static())) { return static::setCurrent($site); } return static::setCurrent(new Site()); }
public static function setUpBeforeClass() { static::$host = getenv('MONGODB_STANDALONE_HOST') ?: static::DEFAULT_STANDALONE_HOST; static::$port = getenv('MONGODB_STANDALONE_PORT') ?: static::DEFAULT_STANDALONE_PORT; static::$server = static::$host . ':' . static::$port; static::$conn_str = 'mongodb://' . static::$server; }
public static function init($config) { static::$host = $config['host']; static::$port = $config['port']; static::$pid_file = $config['pid_file']; static::$root_dir = $config['root_dir']; static::$gzip = $config['gzip']; static::$gzip_min_length = $config['gzip_min_length']; }
protected function init($config) { static::$host = $config['host']; static::$port = $config['port']; static::$pid_file = $config['pid_file']; static::$root_dir = $config['root_dir']; static::$deal_with_public = $config['deal_with_public']; static::$gzip = $config['gzip']; static::$gzip_min_length = $config['gzip_min_length']; }
public function __construct() { // Because some hosts are complete // idiotic pieces of shit, let's // strip slashes from input. if (get_magic_quotes_gpc()) { $php_is_the_worst_language_ever_because_of_this = function (&$value) { $value = stripslashes($value); }; array_walk_recursive($_GET, $php_is_the_worst_language_ever_because_of_this); array_walk_recursive($_POST, $php_is_the_worst_language_ever_because_of_this); array_walk_recursive($_COOKIE, $php_is_the_worst_language_ever_because_of_this); array_walk_recursive($_REQUEST, $php_is_the_worst_language_ever_because_of_this); } // Set query string static::$query = (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null); // Set request scheme static::$scheme = static::isSecure() ? 'https' : 'http'; // Set host static::$host = strtolower(preg_replace('/:\d+$/', '', trim($_SERVER['SERVER_NAME']))); // Set base url static::$base = static::baseUrl(); // Set the request path static::$request_uri = static::requestPath(); // Set relative uri without query string $uri = explode('?', str_replace(static::$base, '', static::$request_uri)); static::$uri = $uri[0]; // Request segments static::$segments = explode('/', trim(static::$uri, '/')); // Set the request method static::$method = strtolower($_SERVER['REQUEST_METHOD']); // Requested with static::$requested_with = @$_SERVER['HTTP_X_REQUESTED_WITH']; // _REQUEST static::$request = $_REQUEST; // _POST static::$post = $_POST; }
public function beginApplication($configDir = '.', $rootDir = '.', $loadDefaultData = true) { if ($this->_initialized) { return; } if (static::$_initConfig['undoMagicQuotes'] && function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { static::undoMagicQuotes($_GET); static::undoMagicQuotes($_POST); static::undoMagicQuotes($_COOKIE); static::undoMagicQuotes($_REQUEST); } if (function_exists('get_magic_quotes_runtime') && get_magic_quotes_runtime()) { @set_magic_quotes_runtime(false); } if (static::$_initConfig['setMemoryLimit']) { static::setMemoryLimit(64 * 1024 * 1024); } ignore_user_abort(true); if (static::$_initConfig['resetOutputBuffering']) { @ini_set('output_buffering', false); @ini_set('zlib.output_compression', 0); if (!@ini_get('output_handler')) { $level = ob_get_level(); while ($level) { @ob_end_clean(); $newLevel = ob_get_level(); if ($newLevel >= $level) { break; } $level = $newLevel; } } } error_reporting(E_ALL | E_STRICT & ~8192); //@ini_set('pcre.backtrack_limit', 1000000); date_default_timezone_set('UTC'); static::$time = time(); static::$host = empty($_SERVER['HTTP_HOST']) ? '' : $_SERVER['HTTP_HOST']; static::$secure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'; $this->_configDir = $configDir; $this->_rootDir = $rootDir; //$this->addLazyLoader('requestPaths', array($this, 'loadRequestPaths')); if ($loadDefaultData) { $this->loadDefaultData(); } $this->_initialized = true; }
/** * Set the host name * * @param string $host Hostname * @return void */ protected static function _setHost($host) { static::$host = $host; if (strpos(static::$host, ':') !== false) { static::$host = substr(static::$host, 0, strpos(static::$host, ':')); } }
/** * @param string $host */ public static function setHost($host) { static::$host = $host; }
public static function setAppHost($host) { static::$host = (string) $host; }
/** * Router response. * * @since 160308 PHP CLI server. * * @return string|bool Response. */ public static function route() { if (isset(static::$response)) { return static::$response; } # Merge environment vars. $_SERVER = array_merge($_ENV, $_SERVER); // Like FastCGI. See: <http://jas.xyz/1LcxXIx> # Setup document root & path-related environment vars. # Also bind a few super-globals to route-related properties. # This is like FastCGI. See: <http://jas.xyz/1LcJeJ7> static::$root = $_SERVER['DOCUMENT_ROOT']; static::$root = preg_replace('/[\\\\\\/]+$/u', '', static::$root); static::$host = preg_replace('/\\:[0-9]+/u', '', $_SERVER['HTTP_HOST']); $_SERVER['DOCUMENT_BASE'] = $_SERVER['DOCUMENT_ROOT'] =& static::$root; if (!preg_match('/' . preg_quote(static::$host, '/') . '$/ui', static::$root)) { static::$root .= DIRECTORY_SEPARATOR . static::$host; } $_SERVER['PHP_SELF'] =& static::$full_path; $_SERVER['SCRIPT_NAME'] =& static::$path; $_SERVER['DOCUMENT_URI'] =& static::$path; $_SERVER['PATH_INFO'] =& static::$path_info; $_SERVER['SCRIPT_FILENAME'] =& static::$file; $_SERVER['PATH_TRANSLATED'] =& static::$file; # Fill-in environment vars missing in PHP CLI server. # This is like FastCGI. See: <http://jas.xyz/1LcJeJ7> if (!isset($_SERVER['REDIRECT_STATUS'])) { $_SERVER['REDIRECT_STATUS'] = 200; # Always 200. } if (!isset($_SERVER['REQUEST_SCHEME'])) { $_SERVER['REQUEST_SCHEME'] = 'http'; # `https` not possible. } if (!isset($_SERVER['SERVER_ADDR']) && !empty($_SERVER['SERVER_NAME'])) { $_SERVER['SERVER_ADDR'] = gethostbyname($_SERVER['SERVER_NAME']); } # Identify the WebSharks router. $_SERVER['SERVER_SOFTWARE'] .= '; via WebSharks router.'; # Fill file and path-related vars now. # This is like FastCGI. See: <http://jas.xyz/1LcJeJ7> static::$full_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); static::$path = static::$full_path; static::$path_info = ''; if (preg_match('/^(?<path>.+?\\.php)(?<path_info>\\/.*)$/u', static::$full_path, $_m)) { // This is like `fastcgi_split_path_info`. See: <http://jas.xyz/1LcIbca> static::$path = $_m['path']; static::$path_info = $_m['path_info']; } // unset($_m); // Housekeeping. static::propagatePath(static::$path); // `file` & `ext`. // This sets `file` & `ext` as a part of the propagation. # Route this request and return response. if ((static::$response = static::toFile()) !== null) { return static::$response; } elseif ((static::$response = static::toDirIndex()) !== null) { return static::$response; } elseif ((static::$response = static::toStatic404Error()) !== null) { return static::$response; } elseif ((static::$response = static::toRootPhpIndex()) !== null) { return static::$response; } return static::$response = static::to404Error(); }
public static function setUpBeforeClass() { error_reporting(E_ALL & ~E_DEPRECATED); if (getenv('TRAVIS') === false) { fwrite(STDERR, "=> Finding binaries\n"); static::$bin['dm'] = $dm = exec('/usr/bin/env which docker-machine'); static::$bin['docker'] = $docker = exec('/usr/bin/env which docker'); if (empty($dm) && empty($docker)) { static::markTestSkipped('Docker is required to run these tests'); } if (!empty($dm)) { fwrite(STDERR, "=> Starting Docker Machine\n"); passthru($dm . ' create -d virtualbox mysql-shim'); passthru($dm . ' start mysql-shim'); $env = ''; exec($dm . ' env mysql-shim', $env); foreach ($env as $line) { if ($line[0] !== '#') { putenv(str_replace(["export ", '"'], "", $line)); } } } fwrite(STDERR, "=> Running Docker Container: "); static::$container = exec($docker . ' run -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -P -d mysql/mysql-server:5.7'); if (empty(static::$container)) { static::markTestSkipped("Unable to start docker container"); } fwrite(STDERR, static::$container . "\n"); fwrite(STDERR, "=> Finding MySQL Host: "); static::$host = exec($docker . ' port ' . self::$container . ' 3306'); fwrite(STDERR, static::$host . "\n"); if (!empty($dm)) { fwrite(STDERR, "=> Using Docker Machine IP: "); $info = explode(':', static::$host); $port = array_pop($info); static::$host = exec($dm . ' ip mysql-shim') . ':' . $port; fwrite(STDERR, static::$host . "\n"); } fwrite(STDERR, "=> Waiting on mysqld to start:"); $out = ''; while (trim($out) != 'mysqld') { $out = exec(static::$bin['docker'] . ' exec ' . static::$container . ' ps ax | awk \'/mysqld/ {print $NF}\''); } fwrite(STDERR, " started\n"); sleep(3); fwrite(STDERR, "=> Docker Container Running\n\n"); return; } static::$host = 'localhost'; }
/** * Settings Connection Data * * @param array $args * @return void */ public static function setting($args) { static::$host = $args['host']; static::$user = $args['user']; static::$pass = $args['pass']; static::$name = $args['name']; }
/** * Sets database connection settings as properties. */ public static function init($dbName, $dbHost, $dbUser, $dbPass, $tablePrefix = '', $dbDriver = 'mysql') { static::$name = $dbName; static::$host = $dbHost; static::$user = $dbUser; static::$pass = $dbPass; static::$prefix = $tablePrefix; // Skip driver check if reinitializing with same driver. if (isset(static::$driver) && $dbDriver == static::$driver) { return; } $drivers = PDO::getAvailableDrivers(); if (!in_array($dbDriver, $drivers, true)) { throw new OutOfBoundsException("Invalid database driver {$dbDriver}."); } static::setDriver($dbDriver); }
/** * Instantiate application host * * @param string|array $config Host file path or array of config data * @return Host * @api */ public static function host($config = null) { if (!isset(static::$host)) { if (!class_exists('Pi\\Application\\Host', false)) { require static::PATH_LIB . '/Pi/Application/Host.php'; } static::$host = new Host($config); } return static::$host; }
public static function setUpBeforeClass() { error_reporting(E_ALL & ~E_DEPRECATED); if (getenv('TRAVIS') === false) { fwrite(STDERR, "=> Finding binaries\n"); static::$bin['docker'] = $docker = exec('/usr/bin/env which docker'); if (empty($docker)) { static::markTestSkipped('Docker is required to run these tests'); } fwrite(STDERR, "=> Running Docker Container: "); static::$container = exec($docker . ' run -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -P -d mysql/mysql-server:5.7'); if (empty(static::$container)) { static::markTestSkipped("Unable to start docker container"); } fwrite(STDERR, static::$container . "\n"); fwrite(STDERR, "=> Finding MySQL Host: "); static::$host = exec($docker . ' port ' . self::$container . ' 3306'); fwrite(STDERR, static::$host . "\n"); fwrite(STDERR, "=> Waiting on mysqld to start:"); $out = ''; while (trim($out) != 'mysqld') { $out = exec(static::$bin['docker'] . ' exec ' . static::$container . ' ps ax | awk \'/mysqld/ {print $NF}\''); } fwrite(STDERR, " started\n"); sleep(3); fwrite(STDERR, "=> Docker Container Running\n\n"); return; } static::$host = 'localhost'; }
/** * Старт маршрутизации */ public static function start() { if (static::$start) { return false; } else { static::$start = true; } static::$record = true; static::$host = Request::host(); static::$path = Request::path(); static::$query = Request::query(); static::$method = Request::method(); if (preg_match('#^/index.php#i', static::$path)) { Error::e404(); } if (preg_match('#^/public/#i', static::$path)) { Error::e404(); } static::running(); if (!static::$found) { if (mb_substr(static::$path, -1, 1) != '/') { $extension = pathinfo(static::$path, PATHINFO_EXTENSION); if ($extension == "") { static::$path .= "/"; static::running(); if (static::$found) { Redirect::r302(static::$path . (static::$query != '' ? '?' . static::$query : '')); } } } } static::$record = false; if (static::$found) { static::render(); } else { Error::e404(); } }