Exemplo n.º 1
0
 /**
 sets get, post, and in
 
 @param	options	{
 	get:<optional GET array, defaults to $_GET>
 	post:<optional POST array, defaults to $_POST>
 	in:<optional array of the input that is used, defaults to merged get and post>
 	special_json: < whether to look for, and parse "_json" key >
 	db: < optional, used for validation, model >
 @note special handling for _json key -> it is parsedd and merged into the array
 */
 function __construct($options = [])
 {
     # handle json post
     if (!isset($options['post'])) {
         if (!$_POST && substr($_SERVER['CONTENT_TYPE'], 0, 16) == 'application/json') {
             $_POST = json_decode(file_get_contents('php://input'), true);
         }
     }
     $this->options = $options = array_merge(['special_json' => false, 'get' => $_GET, 'post' => $_POST], $options);
     $this->get = (array) $options['get'];
     $this->post = (array) $options['post'];
     # if there was no post, check for json data
     if (isset($options['in'])) {
         $this->in = (array) $options['in'];
     } else {
         $this->in = array_merge($this->get, $this->post);
     }
     if ($options['special_json'] && $this->in['_json']) {
         $this->in['_json'] = \Grithin\Arrays::merge($this->in['_json'], json_decode((string) $this->in['_json'], true));
     }
     if ($options['db']) {
         $this->db = $options['db'];
     }
     $this->filter = new \Grithin\Filter($this);
     $this->validate = new \Grithin\Validate($this);
     $this->model = new \Grithin\Input\Model(['input' => $this]);
 }
Exemplo n.º 2
0
 static function get()
 {
     $get = $_GET;
     if ($get['_json']) {
         $get = \Grithin\Arrays::merge($get['_json'], json_decode((string) $get['_json'], true));
     }
     return $get;
 }
Exemplo n.º 3
0
 static function configure($env = [])
 {
     if (!$env['targetTimezone'] && $_ENV['timezone']) {
         $env['targetTimezone'] = $_ENV['timezone'];
     }
     $env = Arrays::merge(['inputTimezone' => 'UTC', 'targetTimezone' => 'UTC'], $_ENV, $env);
     self::$env = $env;
 }
Exemplo n.º 4
0
 function __construct($options = [])
 {
     $this->options = Arrays::merge(['input_timezone' => 'UTC', 'target_timezone' => 'UTC'], $options);
 }
Exemplo n.º 5
0
 /**
 @param	options {
 	mimic:<return paths prefixes with @:dir>,
 	prefix:<prefix returned file paths with>,
 	filter:<function to filter returned paths>,
 	ghost:<don't error on non-existent>}
 */
 static function scan($dir, $options = [])
 {
     if (!$options['prefix'] && $options['mimic']) {
         $options['prefix'] = $dir;
     }
     if (isset($options['maxDepth']) && $options['maxDepth'] == 0) {
         return [];
     }
     $realPath = realpath($dir);
     if (!$realPath) {
         if ($options['ghost']) {
             return [];
         } else {
             Debug::toss('No such directory');
         }
     }
     $realPath .= '/';
     $files = array();
     foreach (scandir($realPath) as $v) {
         if ($v != '.' && $v != '..') {
             if (is_dir($realPath . $v)) {
                 $newOptions = array_merge($options, ['prefix' => $options['prefix'] . $v . '/']);
                 if (isset($newOptions['maxDepth'])) {
                     $newOptions['maxDepth']--;
                 }
                 $newFiles = self::scan($realPath . $v, $newOptions);
                 $files = Arrays::merge($files, $newFiles);
             } else {
                 if (!$options['filter'] || $options['filter']($options['prefix'] . $v)) {
                     $files[] = $options['prefix'] . $v;
                 }
             }
         }
     }
     return $files;
 }
Exemplo n.º 6
0
 protected function setRequestOptions($url, $method, $vars, $files = null)
 {
     $purl = parse_url($url);
     if ($purl['scheme'] == 'https') {
         curl_setopt($this->request, CURLOPT_PORT, empty($purl['port']) ? 443 : $purl['port']);
         if ($this->validate_ssl) {
             curl_setopt($this->request, CURLOPT_SSL_VERIFYPEER, true);
         } elseif ($this->validate_ssl_host) {
             curl_setopt($this->request, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($this->request, CURLOPT_SSL_VERIFYHOST, 0);
         } else {
             curl_setopt($this->request, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($this->request, CURLOPT_SSL_VERIFYHOST, 2);
         }
     }
     $method = strtoupper($method);
     switch ($method) {
         case 'HEAD':
             curl_setopt($this->request, CURLOPT_NOBODY, true);
             break;
         case 'GET':
             curl_setopt($this->request, CURLOPT_HTTPGET, true);
             break;
         case 'PUT':
             curl_setopt($this->request, CURLOPT_CUSTOMREQUEST, "PUT");
             $toPost = true;
             break;
         case 'POST':
             curl_setopt($this->request, CURLOPT_POST, true);
             $toPost = true;
             break;
         default:
             curl_setopt($this->request, CURLOPT_CUSTOMREQUEST, $method);
     }
     curl_setopt($this->request, CURLOPT_URL, $url);
     if ($files || !empty($vars)) {
         if (!$toPost) {
             throw new \InvalidArgumentException('POST-vars may only be set for a POST or PUT Request.');
         }
         if (!is_array($vars)) {
             curl_setopt($this->request, CURLOPT_POSTFIELDS, $vars);
         } elseif ($files) {
             foreach ($files as &$file) {
                 if ($file[0] != '@') {
                     $file = '@' . $file;
                 }
             }
             unset($file);
             curl_setopt($this->request, CURLOPT_POSTFIELDS, Arrays::merge($files, $vars));
         } else {
             curl_setopt($this->request, CURLOPT_POSTFIELDS, Http::buildQuery($vars));
         }
     } elseif ($toPost) {
         throw new \InvalidArgumentException('POST-vars must be set for a POST-Request.');
     }
     # Set some default CURL options
     curl_setopt($this->request, CURLOPT_HEADER, true);
     curl_setopt($this->request, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($this->request, CURLOPT_USERAGENT, $this->user_agent);
     curl_setopt($this->request, CURLOPT_TIMEOUT, $this->timeout);
     if ($this->cookie_file) {
         curl_setopt($this->request, CURLOPT_COOKIEFILE, $this->cookie_file);
         curl_setopt($this->request, CURLOPT_COOKIEJAR, $this->cookie_file);
     }
     /* relative paths fix, see requestFix
     		if ($this->follow_redirects){
     			curl_setopt($this->request, CURLOPT_FOLLOWLOCATION, true);
     		}
     		*/
     if ($this->referrer) {
         curl_setopt($this->request, CURLOPT_REFERER, $this->referrer);
     }
     # Set any custom CURL options
     foreach ($this->options as $option => $value) {
         curl_setopt($this->request, $option, $value);
     }
 }
Exemplo n.º 7
0
Arquivo: Db.php Projeto: grithin/phpdb
 /**
 @param	additional	additional fields to merge with where on insert
 */
 protected function id($table, $where, $additional = null)
 {
     $sql = $this->select($table, $where, 'id');
     $id = $this->value($sql);
     if (!$id) {
         if ($additional) {
             $where = Arrays::merge($where, $additional);
         }
         $id = $this->insert($table, $where);
     }
     return $id;
 }
Exemplo n.º 8
0
 /**
 @param	env	{
 	mode:<name>
 	'debug.detail':<int>
 	'debug.stackExclusions':[<regex>,<regex>,...]
 	projectName:
 	'log.file':
 	'log.folder':
 	'log.size':<size in bytes>
 	'abbreviations':<paths to abbreviate> {name:match}
 }
 */
 static function configure($env = [])
 {
     $env = Arrays::merge(['loadBalancerIps' => []], $_ENV, $env);
     self::$env = $env;
 }