示例#1
0
 /**
  * @inheritdoc
  */
 public function request($url, $args, $method, Options $options)
 {
     $headers = $options->get('headers', array());
     $method = Filter::up($method);
     $args = 'GET' !== $method ? $args : array();
     $httpResult = \Requests::request($url, $headers, $args, $method, $this->_getClientOptions($options));
     if ($options->isExceptions() && $httpResult->status_code >= 400) {
         throw new Exception($httpResult->body, $httpResult->status_code);
     }
     return array($httpResult->status_code, $httpResult->headers->getAll(), $httpResult->body);
 }
 public function migrate()
 {
     try {
         $this->isOk();
         if (isset($this->params['auto'])) {
             print "Auto mode selected." . PHP_EOL;
             $params = new OdaPrepareReqSql();
             $params->sql = "SELECT `param_value`\n                    FROM `" . self::$config->BD_ENGINE->prefixTable . "api_tab_parametres`\n                    WHERE 1=1\n                    AND `param_name` = 'install_date'\n                ";
             $params->typeSQL = OdaLibBd::SQL_GET_ONE;
             $retour = $this->BD_ENGINE->reqODASQL($params);
             if ($retour->data) {
                 $installDate = $retour->data->param_value;
                 $compressInstallDate = Filter::int(Str::sub($installDate, 2, 2) . Str::sub($installDate, 5, 2) . Str::sub($installDate, 8, 2));
                 print "Install date is: " . $installDate . PHP_EOL;
                 $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator('.' . DIRECTORY_SEPARATOR, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
                 foreach ($objects as $folderPath => $object) {
                     if ($object->isDir()) {
                         $filePath = $folderPath . DIRECTORY_SEPARATOR . 'do.sql';
                         if (file_exists($filePath)) {
                             $banned_words = "-install -reworkModel -matrixRangApi";
                             if (!preg_match('~\\b(' . str_replace(' ', '|', $banned_words) . ')\\b~', $filePath) && preg_match('/[0-9]{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])/', $filePath)) {
                                 $patchDate = Filter::int(Str::sub($filePath, 6, 6));
                                 if ($patchDate > $compressInstallDate) {
                                     $this->exe($filePath);
                                 }
                             }
                         }
                     }
                 }
             } else {
                 print "No install_date retrieve." . PHP_EOL;
             }
         } else {
             print "Target mode selected." . PHP_EOL;
             if ($this->params['partial'] !== "all") {
                 $this->exe('.' . DIRECTORY_SEPARATOR . $this->params['target'] . DIRECTORY_SEPARATOR . $this->params['partial'] . DIRECTORY_SEPARATOR . $this->params['option'] . '.sql');
             } else {
                 $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator('.' . DIRECTORY_SEPARATOR . $this->params['target'], \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
                 foreach ($objects as $name => $object) {
                     if ($object->isDir()) {
                         $this->exe($name . DIRECTORY_SEPARATOR . $this->params['option'] . '.sql');
                     }
                 }
             }
         }
         echo 'Success' . PHP_EOL;
         return $this;
     } catch (Exception $ex) {
         die($ex . '');
     }
 }
示例#3
0
 /**
  * @param string            $url
  * @param string|array|null $args
  * @param string            $method
  * @param array             $options
  * @return Response
  * @throws Exception
  */
 public function request($url, $args = null, $method = Options::DEFAULT_METHOD, array $options = array())
 {
     $method = Filter::up($method);
     $url = 'GET' === $method ? Url::addArg((array) $args, $url) : $url;
     $options = new Options(array_merge($this->_options->getArrayCopy(), $options));
     $client = $this->_getClient($options);
     $response = new Response();
     try {
         list($code, $headers, $body) = $client->request($url, $args, $method, $options);
         $response->setCode($code);
         $response->setHeaders($headers);
         $response->setBody($body);
     } catch (\Exception $e) {
         if ($options->isExceptions()) {
             throw new Exception($e->getMessage(), $e->getCode(), $e);
         } else {
             $response->setCode($e->getCode());
             $response->setHeaders(array());
             $response->setBody($e->getMessage());
         }
     }
     return $response;
 }
示例#4
0
文件: Filter.php 项目: JBZoo/Image
 /**
  * Pixelate effect
  *
  * @param resource $image     Image GD resource
  * @param int      $blockSize Size in pixels of each resulting block
  */
 public static function pixelate($image, $blockSize = 10)
 {
     $blockSize = VarFilter::int($blockSize);
     imagefilter($image, IMG_FILTER_PIXELATE, $blockSize, true);
 }
示例#5
0
文件: aliases.php 项目: jbzoo/phpunit
/**
 * Normilize paths and compare them
 *
 * @param string $expected
 * @param string $actual
 * @param string $message
 * @throws Exception
 */
function isSamePath($expected, $actual, $message = null)
{
    if (!class_exists('\\JBZoo\\Utils\\Filter')) {
        throw new Exception('jbzoo/utils required for isSamePath() function');
    }
    $cleanFunc = function ($paths) {
        $return = array();
        $paths = (array) $paths;
        foreach ($paths as $key => $path) {
            $return[$key] = FS::clean($path, '/');
        }
        return $return;
    };
    $expected = Filter::_($expected, $cleanFunc);
    $actual = Filter::_($actual, $cleanFunc);
    isSame($expected, $actual, $message);
}
示例#6
0
 /**
  * Is current request - ajax
  * @return bool
  */
 public function isAjax()
 {
     $method = Vars::get($_SERVER['HTTP_X_REQUESTED_WITH'], '');
     $method = Filter::cmd($method);
     $orig = Filter::cmd('XMLHttpRequest');
     return $orig === $method;
 }
示例#7
0
文件: Image.php 项目: JBZoo/Image
 /**
  * Overlay an image on top of another, works with 24-bit PNG alpha-transparency
  *
  * @param string|Image $overlay     An image filename or a Image object
  * @param string       $position    center|top|left|bottom|right|top left|top right|bottom left|bottom right
  * @param float|int    $opacity     Overlay opacity 0-1 or 0-100
  * @param int          $globOffsetX Horizontal offset in pixels
  * @param int          $globOffsetY Vertical offset in pixels
  *
  * @return $this
  * @throws Exception
  */
 public function overlay($overlay, $position = 'bottom right', $opacity = 0.4, $globOffsetX = 0, $globOffsetY = 0)
 {
     // Load overlay image
     if (!$overlay instanceof self) {
         $overlay = new self($overlay);
     }
     // Convert opacity
     $opacity = Helper::opacity($opacity);
     $globOffsetX = VarFilter::int($globOffsetX);
     $globOffsetY = VarFilter::int($globOffsetY);
     // Determine position
     list($xOffset, $yOffset) = Helper::getInnerCoords($position, array($this->_width, $this->_height), array($overlay->getWidth(), $overlay->getHeight()), array($globOffsetX, $globOffsetY));
     // Perform the overlay
     Helper::imageCopyMergeAlpha($this->_image, $overlay->getImage(), array($xOffset, $yOffset), array(0, 0), array($overlay->getWidth(), $overlay->getHeight()), $opacity);
     return $this;
 }
示例#8
0
文件: Cache.php 项目: jbzoo/less
 /**
  * @param int $newTTL In seconds (1 to 365 days)
  */
 public function setCacheTTL($newTTL)
 {
     $newTTL = Filter::int($newTTL);
     $newTTL = Vars::limit($newTTL, 1, 86400 * 365);
     $this->_cache_ttl = $newTTL;
 }
示例#9
0
 /**
  * @param string $email
  * @param string $name
  * @return bool
  */
 public function setFrom($email, $name = null)
 {
     $this->_from = array();
     if ($email = Filter::email($email)) {
         $this->_from[0] = $email;
         $this->_from[1] = $name;
         return true;
     }
     return false;
 }
示例#10
0
文件: Filter.php 项目: jbzoo/utils
 /**
  * Convert words to PHP Class name
  *
  * @param $input
  * @return string
  */
 public static function className($input)
 {
     $output = preg_replace(array('#(?<=[^A-Z\\s])([A-Z\\s])#i'), ' $0', $input);
     $output = explode(' ', $output);
     $output = array_map(function ($item) {
         $item = preg_replace('#[^a-z0-9]#i', '', $item);
         $item = Filter::ucfirst($item);
         return $item;
     }, $output);
     $output = array_filter($output);
     return implode('', $output);
 }
示例#11
0
文件: Data.php 项目: jbzoo/data
 /**
  * Filter value before return
  *
  * @param mixed $value
  * @param mixed $filter
  * @return mixed
  * @throws \JBZoo\Utils\Exception
  */
 protected function _filter($value, $filter)
 {
     if (null !== $filter) {
         $value = Filter::_($value, $filter);
     }
     return $value;
 }
示例#12
0
 public function testData()
 {
     $data = array('key' => 'value');
     $obj = new JSON($data);
     isSame($obj, Filter::data($obj));
     isSame($data, (array) Filter::data($obj));
     isSame($data, (array) Filter::data($data));
 }
示例#13
0
 /**
  * @param $code
  */
 public function setCode($code)
 {
     $this['code'] = Filter::int($code);
 }