public static function init() { $uri = explode('?', $_SERVER['REQUEST_URI']); $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false; static::$params = ['user_agent' => $_SERVER['HTTP_USER_AGENT'], 'status' => $_SERVER['REDIRECT_STATUS'], 'host' => $_SERVER['SERVER_NAME'], 'port' => $_SERVER['SERVER_PORT'], 'ip_address' => $_SERVER['REMOTE_ADDR'], 'method' => strtolower($_SERVER['REQUEST_METHOD']), 'query_string' => $_SERVER['QUERY_STRING'], 'uri' => $uri[0], 'ajax' => $ajax, 'accept' => $_SERVER['HTTP_ACCEPT'], 'accept_encoding' => $_SERVER['HTTP_ACCEPT_ENCODING'], 'accept_language' => $_SERVER['HTTP_ACCEPT_LANGUAGE']]; if (isset($_POST['_method'])) { static::$params['method'] = strtolower($_POST['_method']); unset($_POST['_method']); } foreach ($_GET as $key => $value) { static::$inputs[$key] = $value; } foreach ($_POST as $key => $value) { static::$inputs[$key] = $value; } foreach ($_FILES as $input_name => $file_properties) { if (is_array($file_properties['name'])) { // Closure $filter = function ($path) use($input_name) { // get the type as: name, tmp_name, size, error, type (mime-type) $type = substr($path, 0, strpos($path, '.')); // get the value of path in $_FILES array from $path :P $pathWitoutType = substr($path, strpos($path, '.') + 1); if ($type === 'tmp_name') { $file = new File(get_array_value($_FILES, $input_name . '.tmp_name.' . $pathWitoutType), static::$file_error_codes[get_array_value($_FILES, $input_name . '.error.' . $pathWitoutType)], get_array_value($_FILES, $input_name . '.name.' . $pathWitoutType)); $file->setArrayPath($input_name . '.' . $pathWitoutType); return $file; } return null; }; static::$files = array_merge(static::$files, array_paths($_FILES[$input_name], [], null, $filter)); } else { $file = new File($file_properties['tmp_name'], static::$file_error_codes[$file_properties['error']], $file_properties['name']); $file->setArrayPath($input_name); static::$files = array_merge(static::$files, [$file]); } } unset($_FILES); unset($_GET); unset($_POST); unset($_SERVER); }
public static function setupBeforeClass() { static::$root = sys_get_temp_dir() . '/insulin'; static::$files = array(static::$root . '/modules/', static::$root . '/sugar/', static::$root . '/sugar/custom/', static::$root . '/sugar/include/', static::$root . '/sugar/include/entryPoint.php', static::$root . '/sugar/include/MVC/', static::$root . '/sugar/include/MVC/SugarApplication.php', static::$root . '/sugar/config.php', static::$root . '/sugar/sugar_version.php'); static::$links = array(static::$root . '/modules' => static::$root . '/sugar/modules', static::$root . '/sugar/custom' => static::$root . '/custom'); if (is_dir(static::$root)) { static::tearDownAfterClass(); } else { mkdir(static::$root); } foreach (static::$files as $file) { if ('/' === substr($file, -1) && !is_dir($file)) { mkdir($file); } else { touch($file); } } foreach (static::$links as $target => $link) { symlink($target, $link); } file_put_contents(static::$root . '/sugar/sugar_version.php', '<?php $sugar_version = \'6.5.3\'; $sugar_db_version = \'6.5.3\'; $sugar_flavor = \'ENT\'; $sugar_build = \'123\'; $sugar_timestamp = \'2008-08-01 12:00am\'; '); }
protected static function initialize() { if (static::$initialized) { return; } static::$initialized = true; static::$parentPath = __FILE__; for ($i = substr_count(get_class(), static::$nsChar); $i >= 0; $i--) { static::$parentPath = dirname(static::$parentPath); } static::$paths = array(); static::$files = array(__FILE__); }
public static function setupBeforeClass() { static::$root = sys_get_temp_dir() . '/insulin'; static::$files = array(static::$root . '/modules/', static::$root . '/sugar/', static::$root . '/sugar/custom/', static::$root . '/sugar/include/', static::$root . '/sugar/include/entryPoint.php', static::$root . '/sugar/include/MVC/', static::$root . '/sugar/include/MVC/SugarApplication.php', static::$root . '/sugar/config.php', static::$root . '/sugar/sugar_version.php'); if (is_dir(static::$root)) { static::tearDownAfterClass(); } else { mkdir(static::$root); } foreach (static::$files as $file) { if ('/' === substr($file, -1) && !is_dir($file)) { mkdir($file); } else { touch($file); } } }
public static function setFiles(array $files) { static::$files = $files; }
/** * @return $this */ public static function findByFileExt($loc, $fileExt) { $finder = new static(); return $finder->files()->name('*.' . $fileExt)->in($loc); }
/** * Resets the internal static cache. * * Used by unit tests to ensure a clean slate. */ public function resetCache() { static::$files = array(); }
public static function reset() { static::$files = array(); }
public function getFoundFilesFromCache() { static::$files = Cache::get('ModuleLoader::findFile', []); }
static function mount($config) { static::$config = $config; //not configurables static::$root = ROOT; static::$php = ROOT . '.app/'; static::$ctrl = ROOT . '.app/controller/'; static::$html = ROOT . '.app/html/'; static::$upload = ROOT . '.app/upload/'; static::$style = ROOT . 'css/'; static::$script = ROOT . 'js/'; //Detect SSL access if (!isset($_SERVER['SERVER_PORT'])) { $_SERVER['SERVER_PORT'] = 80; } $http = isset($_SERVER['HTTPS']) && ($_SERVER["HTTPS"] == "on" || $_SERVER["HTTPS"] == 1 || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://'; //What's base??! $base = isset($_SERVER['PHAR_SCRIPT_NAME']) ? dirname($_SERVER['PHAR_SCRIPT_NAME']) : rtrim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']), ' /'); if ($_SERVER['SERVER_PORT'] != 80) { $base .= ':' . $_SERVER['SERVER_PORT']; } //URL & REQST Constants: defined('RQST') || define('RQST', urldecode(isset($_SERVER['REQUEST_URI']) ? urldecode(trim(str_replace($base, '', trim($_SERVER['REQUEST_URI'])), ' /')) : '')); defined('URL') || define('URL', isset($_SERVER['SERVER_NAME']) ? $http . $_SERVER['SERVER_NAME'] . $base . '/' : ''); static::$url = URL; static::$rqst = explode('/', RQST); static::$files = URL . 'files/'; }
/** * Reset the class variables to null. */ public static function reset() { static::$query = null; static::$post = null; static::$properties = null; static::$server = null; static::$cookies = null; static::$files = null; static::$headers = null; static::$method = null; static::$pathInfo = null; static::$requestUri = null; static::$requestPath = null; static::$basePath = null; static::$baseUrl = null; }
/** * Normalize the $_FILES array and store the result in $files * * @return void */ public static function process($config = array()) { // process runtime config if (is_array($config)) { static::$config = array_merge(static::$config, $config); } // processed files array's static::$files = array(); $files = array(); // any files uploaded? if (empty($_FILES)) { throw new \FuelException('No file upload was initiated. Did you specify "enctype" in your <form> tag?'); } // normalize the multidimensional fields in the $_FILES array foreach ($_FILES as $name => $value) { if (is_array($value['name'])) { foreach ($value as $field => $content) { foreach (\Arr::flatten($content) as $element => $data) { $_FILES[$name . ':' . $element][$field] = $data; } } unset($_FILES[$name]); } } // normalize the $_FILES array foreach ($_FILES as $name => $value) { // store the file data $file = array('field' => $name, 'file' => $value['tmp_name']); if ($value['error']) { $file['error'] = true; $file['errors'][] = array('error' => $value['error']); } else { $file['error'] = false; $file['errors'] = array(); } unset($value['tmp_name']); $files[] = array_merge($value, $file); } // verify and augment the files data foreach ($files as $key => $value) { // add some filename details (pathinfo can't be trusted with utf-8 filenames!) $files[$key]['extension'] = ltrim(strrchr(ltrim($files[$key]['name'], '.'), '.'), '.'); if (empty($files[$key]['extension'])) { $files[$key]['filename'] = $files[$key]['name']; } else { $files[$key]['filename'] = substr($files[$key]['name'], 0, strlen($files[$key]['name']) - (strlen($files[$key]['extension']) + 1)); } // does this upload exceed the maximum size? if (!empty(static::$config['max_size']) and $files[$key]['size'] > static::$config['max_size']) { $files[$key]['error'] = true; $files[$key]['errors'][] = array('error' => static::UPLOAD_ERR_MAX_SIZE); } // add mimetype information if (!$files[$key]['error']) { $handle = finfo_open(FILEINFO_MIME_TYPE); $files[$key]['mimetype'] = finfo_file($handle, $value['file']); finfo_close($handle); if ($files[$key]['mimetype'] == 'application/octet-stream' and $files[$key]['type'] != $files[$key]['mimetype']) { $files[$key]['mimetype'] = $files[$key]['type']; } // make sure it contains something valid if (empty($files[$key]['mimetype'])) { $files[$key]['mimetype'] = 'application/octet-stream'; } } // check the file extension black- and whitelists if (!$files[$key]['error']) { if (in_array(strtolower($files[$key]['extension']), (array) static::$config['ext_blacklist'])) { $files[$key]['error'] = true; $files[$key]['errors'][] = array('error' => static::UPLOAD_ERR_EXT_BLACKLISTED); } elseif (!empty(static::$config['ext_whitelist']) and !in_array(strtolower($files[$key]['extension']), (array) static::$config['ext_whitelist'])) { $files[$key]['error'] = true; $files[$key]['errors'][] = array('error' => static::UPLOAD_ERR_EXT_NOT_WHITELISTED); } } // check the file type black- and whitelists if (!$files[$key]['error']) { // split the mimetype info so we can run some tests preg_match('|^(.*)/(.*)|', $files[$key]['mimetype'], $mimeinfo); if (in_array($mimeinfo[1], (array) static::$config['type_blacklist'])) { $files[$key]['error'] = true; $files[$key]['errors'][] = array('error' => static::UPLOAD_ERR_TYPE_BLACKLISTED); } if (!empty(static::$config['type_whitelist']) and !in_array($mimeinfo[1], (array) static::$config['type_whitelist'])) { $files[$key]['error'] = true; $files[$key]['errors'][] = array('error' => static::UPLOAD_ERR_TYPE_NOT_WHITELISTED); } } // check the file mimetype black- and whitelists if (!$files[$key]['error']) { if (in_array($files[$key]['mimetype'], (array) static::$config['mime_blacklist'])) { $files[$key]['error'] = true; $files[$key]['errors'][] = array('error' => static::UPLOAD_ERR_MIME_BLACKLISTED); } elseif (!empty(static::$config['mime_whitelist']) and !in_array($files[$key]['mimetype'], (array) static::$config['mime_whitelist'])) { $files[$key]['error'] = true; $files[$key]['errors'][] = array('error' => static::UPLOAD_ERR_MIME_NOT_WHITELISTED); } } // store the normalized and validated result static::$files[$key] = $files[$key]; // validation callback defined? if (array_key_exists('validate', static::$callbacks) and !is_null(static::$callbacks['validate'])) { // get the callback method $callback = static::$callbacks['validate'][0]; // call the callback if (is_callable($callback)) { $result = call_user_func_array($callback, array(&static::$files[$key])); if (is_numeric($result) and $result) { static::$files[$key]['error'] = true; static::$files[$key]['errors'][] = array('error' => $result); } } } // and add the message texts foreach (static::$files[$key]['errors'] as $e => $error) { empty(static::$files[$key]['errors'][$e]['message']) and static::$files[$key]['errors'][$e]['message'] = \Lang::get('upload.error_' . $error['error']); } } // determine the validate status of at least one uploaded file $valid = false; foreach (static::$files as $key => $value) { if ($value['error'] === false) { $valid = true; break; } } static::$valid = $valid; }
static function mount(Router $router) { static::$router = $router; static::$root = WEB_PATH; static::$php = APP_PATH . ''; static::$ctrl = APP_PATH . 'controller/'; static::$html = HTML_PATH . ''; static::$upload = APP_PATH . 'upload/'; static::$style = WEB_PATH . 'css/'; static::$script = WEB_PATH . 'js/'; static::$url = URL; static::$rqst = explode('/', RQST); static::$files = URL . 'files/'; }
/** * initializes the test environment */ public static function setUpBeforeClass() { static::$files = array('composer' => sys_get_temp_dir() . '/composer.phar', 'other_composer' => sys_get_temp_dir() . '/other/dir/composer.phar', 'stream' => sys_get_temp_dir() . '/wrapper-unittest.stream'); }
/** * Constructs a new ExtensionDiscovery object. * * @param string $root * The app root. * @param bool $use_file_cache * (optional) Whether file cache should be used. Defaults to TRUE. * @param string[]|null $profile_directories * (optional) The available profile directories. Defaults to NULL, which * will cause this object to search for profile directories based on * settings. * @param string|null $site_path * (optional) The site path within the Drupal installation. Defaults to * NULL, which will cause this object to determine the site based on the * request information. */ public function __construct($root, $use_file_cache = TRUE, $profile_directories = NULL, $site_path = NULL) { $this->root = $root; $this->profileDirectories = $profile_directories; $this->sitePath = $site_path; // Invalidate the cache if we're using a new root directory. We must do this // since $files is static. if ($this->root != static::$cacheRoot) { static::$files = []; static::$cacheRoot = $this->root; } }
/** * Normalize the $_FILES array and store the result in $files * * @return void */ public static function process($config = array()) { // process runtime config if (is_array($config)) { static::$config = array_merge(static::$config, $config); } // processed files array static::$files = $files = array(); // normalize the $_FILES array foreach ($_FILES as $name => $value) { // if the variable is an array, flatten it if (is_array($value['name'])) { $keys = array_keys($value['name']); foreach ($keys as $key) { // skip this entry if no file was uploaded if ($value['error'][$key] == static::UPLOAD_ERR_NO_FILE) { continue; } // store the file data $file = array('field' => $name, 'key' => $key); $file['name'] = $value['name'][$key]; $file['type'] = $value['type'][$key]; $file['file'] = $value['tmp_name'][$key]; $file['error'] = $value['error'][$key]; $file['size'] = $value['size'][$key]; $files[] = $file; } } else { // skip this entry if no file was uploaded if ($value['error'] == static::UPLOAD_ERR_NO_FILE) { continue; } // store the file data $file = array('field' => $name, 'key' => false, 'file' => $value['tmp_name']); unset($value['tmp_name']); $files[] = array_merge($value, $file); } } // verify and augment the files data foreach ($files as $key => $value) { // add some filename details (pathinfo can't be trusted with utf-8 filenames!) $files[$key]['extension'] = ltrim(strrchr(ltrim($files[$key]['name'], '.'), '.'), '.'); if (empty($files[$key]['extension'])) { $files[$key]['filename'] = $files[$key]['name']; } else { $files[$key]['filename'] = substr($files[$key]['name'], 0, strlen($files[$key]['name']) - (strlen($files[$key]['extension']) + 1)); } // does this upload exceed the maximum size? if (!empty(static::$config['max_size']) and $files[$key]['size'] > static::$config['max_size']) { $files[$key]['error'] = static::UPLOAD_ERR_MAX_SIZE; } // add mimetype information if ($files[$key]['error'] == UPLOAD_ERR_OK) { $handle = finfo_open(FILEINFO_MIME_TYPE); $files[$key]['mimetype'] = finfo_file($handle, $value['file']); finfo_close($handle); if ($files[$key]['mimetype'] == 'application/octet-stream' and $files[$key]['type'] != $files[$key]['mimetype']) { $files[$key]['mimetype'] = $files[$key]['type']; } // make sure it contains something valid if (empty($files[$key]['mimetype'])) { $files[$key]['mimetype'] = 'application/octet-stream'; } } // check the file extension black- and whitelists if ($files[$key]['error'] == UPLOAD_ERR_OK) { if (in_array($files[$key]['extension'], (array) static::$config['ext_blacklist'])) { $files[$key]['error'] = static::UPLOAD_ERR_EXT_BLACKLISTED; } elseif (!empty(static::$config['ext_whitelist']) and !in_array($files[$key]['extension'], (array) static::$config['ext_whitelist'])) { $files[$key]['error'] = static::UPLOAD_ERR_EXT_NOT_WHITELISTED; } } // check the file type black- and whitelists if ($files[$key]['error'] == UPLOAD_ERR_OK) { // split the mimetype info so we can run some tests preg_match('|^(.*)/(.*)|', $files[$key]['mimetype'], $mimeinfo); if (in_array($mimeinfo[1], (array) static::$config['type_blacklist'])) { $files[$key]['error'] = static::UPLOAD_ERR_TYPE_BLACKLISTED; } if (!empty(static::$config['type_whitelist']) and !in_array($mimeinfo[1], (array) static::$config['type_whitelist'])) { $files[$key]['error'] = static::UPLOAD_ERR_TYPE_NOT_WHITELISTED; } } // check the file mimetype black- and whitelists if ($files[$key]['error'] == UPLOAD_ERR_OK) { if (in_array($files[$key]['mimetype'], (array) static::$config['mime_blacklist'])) { $files[$key]['error'] = static::UPLOAD_ERR_MIME_BLACKLISTED; } elseif (!empty(static::$config['mime_whitelist']) and !in_array($files[$key]['mimetype'], (array) static::$config['mime_whitelist'])) { $files[$key]['error'] = static::UPLOAD_ERR_MIME_NOT_WHITELISTED; } } // store the normalized and validated result static::$files[$key] = $files[$key]; // validation callback defined? if (array_key_exists('validate', static::$callbacks) and !is_null(static::$callbacks['validate'])) { // get the callback method $callback = static::$callbacks['validate'][0]; // call the callback if (is_callable($callback)) { $result = call_user_func_array($callback, array(&static::$files[$key])); if (is_numeric($result)) { static::$files[$key]['error'] = $result; } } } // update the valid flag static::$valid = (static::$valid or $files[$key]['error'] === 0); } }
public static function files() { if (!is_null(static::$files)) { return static::$files; } static::$files = array(); $files = dir::read(static::$root['default']); if (isset(static::$root['custom'])) { $files = array_merge($files, dir::read(static::$root['custom'])); } foreach ($files as $file) { $name = strtolower($file) . 'field'; if (isset(static::$root['custom']) and is_dir(static::$root['custom'] . DS . $file)) { static::$files[$name] = static::$root['custom'] . DS . $file . DS . $file . '.php'; } else { static::$files[$name] = static::$root['default'] . DS . $file . DS . $file . '.php'; } } return static::$files; }
public static function addFiles(array $files) { static::$files = array_merge(static::$files, $files); }
/** * Resets the internal static cache. * * Used by unit tests to ensure a clean slate. */ public function resetCache() { static::$files = []; }
/** * @return mixed */ protected function files() { return static::$files = $_FILES; }