/**
  *
  * Parse the file in 1 go
  *
  */
 function parse()
 {
     $pattern = array('/^Name\\s*:\\s*(.*)$/i', '/^Version\\s*:\\s*(.*)$/i', '/^Release\\s*:\\s*(\\S*)(%\\{\\?dist\\}).*$/', '/^Release\\s*:\\s*(\\S*)$/', '/^Summary\\s*:\\s*(.*)$/i', '/^License\\s*:\\s*(.*)$/i', '/^URL\\s*:\\s*(.*)$/i', '/^Epoch\\s*:\\s*(.*)/i', '/^Group\\s*:\\s*(.*)$/i', '/^%define\\s*(\\S*)\\s*(\\S*)\\s*$/i', '/^%description\\s*$/i', '/^%description\\s*(.*)$/i', '/^%description\\s*:(.*)$/', '/%package\\s*(.*)$/i', '/^Requires\\s*:(.*)$/i', '/^Obsoletes\\s*:(.*)$/i', '/^Conflicts\\s*:(.*)$/i', '/^Provides\\s*:(.*)$/i', '/^BuildRequires\\s*:(.*)$/i', '/^%(\\S+)\\s*(.*)$/i', '/^.*$/');
     $replace = array('name: $1', 'version: $1', 'release: $1' . $this->distribution, 'release: $1', 'summary: $1', 'license: $1', 'url: $1', 'epoch: $1', 'group: $1', '$1: $2', 'description: $1', 'description: $1', 'description: $1', 'package: $1', 'depends: $1', 'obsoletes: $1', 'conflicts: $1', 'provides: $1', 'buildDepends: $1', '$1: $2', '$0');
     // parse the file in 1 go
     while (($buffer = fgets($this->handle, $this->blocksize)) !== false) {
         $result = preg_filter($pattern, $replace, $buffer);
         if ($result) {
             $info = explode(':', $result, 2);
         }
     }
     if ($this->_flag_debug) {
         echo "\nDependencies\n";
         echo "---------------------\n";
         print_r($this->depends);
         echo "\nBuild Dependencies\n";
         echo "---------------------\n";
         print_r($this->buildDepends);
         echo "\nProvides\n";
         echo "---------------------\n";
         print_r($this->provides);
         echo "\nObsoletes\n";
         echo "---------------------\n";
         print_r($this->obsoletes);
         echo "\nConflicts\n";
         echo "---------------------\n";
         print_r($this->conflicts);
         echo "\nSubpackages\n";
         echo "---------------------\n";
         print_r($this->subpackages);
     }
     unset($buffer, $result, $info);
 }
示例#2
1
 private function setLanguageFile()
 {
     //filter language file
     $config = ParamesHelper::getLanguageConfig();
     $this->adminArray = preg_filter('/^/', $this->language . '.', $config['file_admin']);
     $this->siteArray = preg_filter('/^/', $this->language . '.', $config['file_site']);
     $site_list_file = JFolder::files($config['folder_site'] . $this->language);
     $this->itemsSite = MathHelper::filterArray($site_list_file, $this->siteArray);
     $admin_list_file = JFolder::files($config['folder_admin'] . $this->language);
     $this->itemsAdmin = MathHelper::filterArray($admin_list_file, $this->adminArray);
     return true;
 }
示例#3
1
 /**
  * Construct the driver with the configuration.
  *
  * @param ConfigurationInterface $configuration The configuration to be used.
  *
  * @throws \InvalidArgumentException If wrong configuration class received.
  */
 public function __construct(ConfigurationInterface $configuration)
 {
     // validate we get correct configuration class type.
     $type = (string) preg_filter('/Zikula\\\\Component\\\\FileSystem\\\\(\\w+)$/', '$1', get_class($this));
     $validName = "Zikula\\Component\\FileSystem\\Configuration\\{$type}Configuration";
     if ($validName != get_class($configuration)) {
         throw new \InvalidArgumentException(sprintf('Invalid configuration class for %1$s.  Expected %2$s but got %3$s instead. ::%4$s', get_class($this), $validName, get_class($configuration), $type));
     }
     $this->configuration = $configuration;
     $facade = "Zikula\\Component\\FileSystem\\Facade\\{$type}Facade";
     $this->driver = new $facade();
     $this->errorHandler = new Error();
 }
示例#4
0
文件: TestCase.php 项目: jave007/test
 /**
  * Runs the test case.
  * @return void
  */
 public function run($method = NULL)
 {
     $r = new \ReflectionObject($this);
     $methods = array_values(preg_grep(self::METHOD_PATTERN, array_map(function (\ReflectionMethod $rm) {
         return $rm->getName();
     }, $r->getMethods())));
     if (substr($method, 0, 2) === '--') {
         // back compatibility
         $method = NULL;
     }
     if ($method === NULL && isset($_SERVER['argv']) && ($tmp = preg_filter('#(--method=)?([\\w-]+)$#Ai', '$2', $_SERVER['argv']))) {
         $method = reset($tmp);
         if ($method === self::LIST_METHODS) {
             Environment::$checkAssertions = FALSE;
             header('Content-Type: text/plain');
             echo '[' . implode(',', $methods) . ']';
             return;
         }
     }
     if ($method === NULL) {
         foreach ($methods as $method) {
             $this->runMethod($method);
         }
     } elseif (in_array($method, $methods, TRUE)) {
         $this->runMethod($method);
     } else {
         throw new TestCaseException("Method '{$method}' does not exist or it is not a testing method.");
     }
 }
示例#5
0
文件: Job.php 项目: ehalls/sifter
 private function iterateSubSelectors($container, $payload)
 {
     $nodes = $this->crawler->filter($container);
     $results = array();
     $collect = function ($node, $i) use($payload, &$results) {
         $result = new \stdClass();
         foreach ($payload as $label => $selector) {
             if (is_string($selector)) {
                 $content = trim(strip_tags($node->filter($selector)->text()));
                 if ($label == "unit_price") {
                     $content = preg_filter(array("/£/", "/[a-z]/", "/\\//"), "", $content);
                 }
                 $result->{$label} = $content;
             } elseif (is_array($selector)) {
                 switch ($selector['type']) {
                     case "link":
                         $link = $node->filter($selector['context'])->link();
                         $nextPageCrawler = self::$goutte->click($link);
                         if ($selector['target'] == 'content_size') {
                             $result->{$label} = intval(ceil(strlen(self::$goutte->getResponse()->getContent()) / 1024));
                         } else {
                             $content = $nextPageCrawler->filter($selector['target']);
                             $result->{$label} = trim(strip_tags($content->text()));
                         }
                 }
             }
         }
         $results[] = $result;
     };
     $nodes->each($collect);
     return $results;
 }
示例#6
0
文件: Route.php 项目: Jurasikt/bso
 public function matches()
 {
     $url = $this->args;
     foreach ($this->routes as $args) {
         $path = preg_split('/\\//', $args['url']);
         $path = preg_filter('/\\w+/', '$0', $path);
         if (count($path) != count($url)) {
             continue;
         }
         $callback = function (array $matches) use($url, $path, &$args) {
             $key = array_search($matches[0], $path);
             if ($key !== false && array_key_exists($key, $url)) {
                 $find = array_search($matches[1], $args);
                 if ($find !== false && array_key_exists($find, $args)) {
                     $args[$find] = $url[$key];
                 }
                 return $url[$key];
             }
             return $matches[1];
         };
         $path = preg_replace_callback('/\\((.\\w+)\\)/', $callback, $path);
         $pattern = "^" . implode('\\/', $path);
         if (preg_match("/{$pattern}/", $this->request)) {
             if ($this->execute($args['controller'], $args['action'])) {
                 return $this;
             }
         }
     }
     throw new HTTP_Exception(404);
 }
示例#7
0
文件: Router.php 项目: tany/php-note
 protected static function parse($conf)
 {
     $routes = [];
     $curpos = [];
     foreach (explode("\n", $conf) as $line) {
         if (($pos = strpos($line, '#')) !== false) {
             $line = substr($line, 0, $pos);
         }
         if (!($line = rtrim($line))) {
             continue;
         }
         $depth = strlen(preg_filter('/^(\\s+).*/', '$1', $line));
         $data = preg_split('/\\s+/', ltrim($line));
         $path = $data[0];
         $node = $data[1] ?? null;
         $curpos = array_slice($curpos, 0, $depth);
         $curpos = array_pad($curpos, $depth, '');
         $curpos[] = $path;
         if (!$node) {
             continue;
         }
         $line = preg_replace('/^\\s*.*?\\s+/', '', $line);
         $path = preg_replace('/\\/+/', '/', '/' . join('/', $curpos));
         $node = preg_replace('/\\s*/', '', $line);
         $patt = str_replace('.', '\\.', $path);
         $patt = preg_replace('/:\\w+/', '([^/]+)', $patt);
         $patt = preg_replace('/@\\w+/', '(\\d+)', $patt);
         $class = preg_replace('/\\//', '\\controller\\', dirname($node), 1);
         $class = preg_replace('/\\//', '\\', $class);
         $routes[] = ['path' => $path, 'controller' => dirname($node), 'action' => basename($node), 'pattern' => $patt, 'class' => $class];
     }
     return $routes;
 }
示例#8
0
 public static function addParam($parameter, $params)
 {
     $params = preg_filter("/[\\{]?([^\\}]*)[\\}]?/si", "\$1", $params, 1);
     $values = explode(",", $params);
     $values[] = $parameter;
     return "{" . implode(",", $values) . "}";
 }
示例#9
0
 private function is_hello($str)
 {
     $a = $str . "q";
     $a = preg_filter("([^hello])", "", $a);
     $r = preg_filter(["(he)", "(2ll)", "([^3o])", "(3o)", "(o)"], ["2", "3", "", "4", ""], $a);
     return $r == "4" ? true : false;
 }
示例#10
0
文件: Crypt.php 项目: runeimp/stf
 public function blowfishHash($data, $cost = null, $alpha = null, $prefix = null)
 {
     if ($alpha !== null) {
         $alpha = preg_filter('/[^.\\/0-9a-z]/i', '', $alpha);
         if (strlen($alpha) > 22) {
             $alpha = substr($alpha, 0, 22);
         }
     }
     if ($prefix !== null) {
         switch ($prefix) {
             case '$2x$':
             case '$2y$':
                 break;
             case '$2a$':
                 $prefix = '$2x$';
                 break;
             case '$2$':
             default:
                 $prefix = null;
                 break;
         }
     }
     $salt = $this->blowfishSalt($cost, $alpha, $prefix);
     return crypt($data . $alpha, $salt['salt']);
 }
 /**
  * Return array of diff files only
  *
  * Scans the specified directory, discards all found items
  * except files with the extension ".diff" and returns array with it.
  *
  * @param  string $dir
  * @return array
  */
 public function listing($dir)
 {
     $dir = empty($dir) || !is_dir($dir) ? realpath(__DIR__ . '/../') : $dir;
     $list = scandir($dir);
     $list = preg_filter('/.\\.diff$/i', '$0', $list);
     return $list;
 }
示例#12
0
 /**
  * format()
  * Formata a mensagem recebida
  *
  * @version
  *     1.0 Initial
  *     
  * @param string $message Mensagem a ser formatada
  * @return string Mensagem formatada
  */
 public function format($message)
 {
     foreach ($this->patterns as $pattern => $replace) {
         preg_match($pattern, $message, $out);
     }
     return preg_filter(array_keys($this->patterns), array_values($this->patterns), $message);
 }
 public function testSimpleLambda()
 {
     $lambdaFunc = function ($word) {
         return preg_filter("/my/i", "", $word);
     };
     $stemmer = new LambdaStemmer($lambdaFunc);
     $this->assertEquals("tom", $stemmer->stem("tommy"));
 }
示例#14
0
 public function __call($name, $parameters)
 {
     if (preg_match('/Complete$/', $name)) {
         $name = preg_filter('/Complete$/', '', $name);
         return $this->_Complete($name, $parameters);
     }
     return $this->_callFunction($name, $parameters);
 }
示例#15
0
 /**
  * Perform a regular expression search and replace, returning only matched subjects.
  *
  * @param string $subject
  * @param string $pattern
  * @param string $replacement
  * @param int    $limit
  *
  * @return string
  */
 public function _preg_filter($subject, $pattern, $replacement = '', $limit = -1)
 {
     if (!isset($subject)) {
         return;
     } else {
         return preg_filter($pattern, $replacement, $subject, $limit);
     }
 }
 public function testLambdaPregFilter()
 {
     $lambda = function ($word) {
         return preg_filter("/bob/", "tom", $word);
     };
     $transformer = new LambdaFilter($lambda);
     $this->assertEquals("tomtom", $transformer->transform("bobbob"));
 }
示例#17
0
 public static function getCssEmbedCode($username, $css_url = null)
 {
     if (!$css_url) {
         $css_url = self::STYLA_URL;
     }
     $sCssUrl = preg_filter('/https?:(.+)/i', '$1', rtrim($css_url, '/') . '/') . 'styles/clients/' . $username . '.css?version=' . self::_getVersion($username);
     return '<link rel="stylesheet" type="text/css" href="' . $sCssUrl . '">';
 }
示例#18
0
 public function getPrincipalByPath($path)
 {
     $user = new Phprojekt_User_User();
     $user = $user->findByUsername(preg_filter('|.*principals/([^/]+)$|', '$1', $path));
     if (is_null($user)) {
         throw new Exception("Principal not found for path {$path}");
     }
     return array('id' => $user->id, 'uri' => "principals/{$user->username}", '{DAV:}displayname' => $user->username, '{http://sabredav.org/ns}email-address' => $user->getSetting('email'));
 }
示例#19
0
 /**
  * Implements getCalendarsForUser from Sabre_CalDAV_Backend_Abstract
  *
  * This is simplified for PHProjekt. We only have one calendar per user, so we return hard-coded data based on the
  * user name. The id of the calendar is the id of the user it belongs to.
  *
  * @param string $principalUri The uri of the user whose calendar to get
  *
  * @return array calendar description
  */
 public function getCalendarsForUser($principalUri)
 {
     // We have exactly one calendar per principal.
     $user = new Phprojekt_User_User();
     $user = $user->findByUsername(preg_filter('|.*principals/([^/]+)$|', '$1', $principalUri));
     if (is_null($user)) {
         throw new Exception("principal not found under {$principalUri} when retrieving calendars for {$username}");
     }
     return array(array('id' => $user->id, 'uri' => 'default', 'principaluri' => $principalUri, '{DAV:}displayname' => 'default', '{http://apple.com/ns/ical/}calendar-color' => 'blue', '{http://apple.com/ns/ical/}calendar-order' => 0, '{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}getctag' => time(), '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set' => new Sabre_CalDAV_Property_SupportedCalendarComponentSet(array('VEVENT'))));
 }
示例#20
0
 /**
  * Parses and adds a controller action
  *
  * @param string $actionName
  *
  * @return
  */
 private function addAction($actionName)
 {
     $template = $this->templates[$actionName];
     $command = preg_filter('/^/', '    ', explode(PHP_EOL, strtr($template, ['$actionName' => $actionName])));
     $command = array_filter($command, function ($var) {
         return strlen(trim($var));
     });
     $command = implode(PHP_EOL, $command);
     $this->commands[] = $command;
 }
示例#21
0
文件: Util.php 项目: saiyan/selim
 public static function stripPhpComments($str)
 {
     $regex_multiline = "/\\/\\*[^\\Z]*\\*\\//m";
     $regex_singleline = "/\\/\\/.*/m";
     $result = preg_filter($regex_multiline, "", $str);
     if ($result) {
         $str = $result;
     }
     return preg_filter($regex_singleline, "", $str);
 }
示例#22
0
 /**
  * Breaks Type into Type and Size, for example TINYINT(1) becomes Type TINYINT, Size 1
  */
 protected function _clarify()
 {
     $size = preg_filter('/\\D/', '', $this->Type);
     if ($size) {
         $this->Size = $size;
     }
     $type = preg_filter('/\\(.*\\)/', '', $this->Type);
     if ($type) {
         $this->Type = $type;
     }
 }
示例#23
0
 function __construct()
 {
     //array to set the bot name and for further checking. If you want, then you can manully add more bot name.
     $botArrayName = array('googlebot' => '/Googlebot/', 'msnbot' => '/MSNBot/', 'slurp' => '/Inktomi/', 'yahoo' => '/Yahoo/', 'askjeeves' => '/AskJeeves/', 'fastcrawler' => '/FastCrawler/', 'infoseek' => '/InfoSeek/', 'lycos' => '/Lycos/', 'yandex' => '/YandexBot/', 'geohasher' => '/GeoHasher/', 'gigablast' => '/Gigabot/', 'baidu' => '/Baiduspider/', 'spinn3r' => '/Spinn3r/');
     /**
      * Check whether the requester is bot or not
      */
     if (true == isset($_SERVER['HTTP_USER_AGENT'])) {
         $this->botArrayCheck = preg_filter($botArrayName, array_fill(1, count($botArrayName), '$0'), array(trim($_SERVER['HTTP_USER_AGENT'])));
     }
 }
示例#24
0
 /**
  * @param string $customerNumber
  * @param string $customerCode
  * @param string $customerName
  * @param string $username
  * @param string $password
  * @param string $collectionLocation
  * @param string $globalPack
  * @param bool $sandbox
  */
 public function __construct($customerNumber, $customerCode, $customerName, $username, $password, $collectionLocation, $globalPack, $sandbox = false)
 {
     $this->customerNumber = $customerNumber;
     $this->customerCode = $customerCode;
     $this->customerName = $customerName;
     $this->securityHeader = new ComplexTypes\SecurityHeader($username, $password);
     $this->collectionLocation = $collectionLocation;
     $this->globalPackBarcodeType = preg_filter('/^(.{2})(.{4})$/', '$1', $globalPack);
     $this->globalPackCustomerCode = preg_filter('/^(.{2})(.{4})$/', '$2', $globalPack);
     $this->sandbox = $sandbox;
 }
示例#25
0
 public static function datepickerField($name, $value, $htmlOptions = array(), $pickerOptions = array())
 {
     $id = isset($htmlOptions['id']) ? $htmlOptions['id'] : preg_filter('/[\\[\\]]/', '', $name);
     $pkOptions = array_merge(array('name' => $name, 'value' => $value, 'language' => 'pt-BR', 'options' => array('showAnim' => 'fold', 'dateFormat' => 'dd/mm/yy', 'changeMonth' => true, 'changeYear' => true, 'yearRange' => date('Y') - 5 . ':' . date('Y'), 'constrainInput' => false)), $pickerOptions);
     $pkOptions['htmlOptions'] = array_merge(array('class' => 'date'), $htmlOptions);
     $maskFormat = str_replace(array('-', 'yy'), array('/', 'yyyy'), $pkOptions['options']['dateFormat']);
     $js = "jQuery(\"#{$id}\").mask(\"" . preg_replace('/[dmy]/', '9', $maskFormat) . "\");";
     Yii::app()->clientScript->registerCoreScript('maskedinput');
     Yii::app()->clientScript->registerScript("datepicker#{$id}", $js);
     return self::widget('zii.widgets.jui.CJuiDatePicker', $pkOptions);
 }
 function testDefinedOrDie()
 {
     global $basepath;
     $search = "if\\( \\s* ! \\s* defined\\( \\s* 'EVO_MAIN_INIT' \\s* \\) \\s* \\) \\s* die\\( .*? \\);";
     $search_init = "if\\( \\s* ! \\s* defined\\( \\s* 'EVO_CONFIG_LOADED' \\s* \\) \\s* \\) \\s* die\\( .*? \\);";
     # $search_both = "if\( \s* ! \s* defined\( \s* 'EVO_MAIN_INIT' \s* ) \s* && \s* ! \s* defined( \s* 'EVO_CONFIG_LOADED' \s* ) \s* ) die\( .*? \);";
     $files = $this->get_files_without_symlinks($basepath);
     $badfiles = array();
     $badfiles_init = array();
     $badfiles_main = array();
     foreach ($files as $filename) {
         if (preg_filter($this->entry_points, 'whatever', $filename) || preg_filter($this->ignore_list, 'whatever', $filename)) {
             // file is an entry point
             continue;
         }
         $buffer = file_get_contents($filename);
         $pos_phptag = strpos($buffer, '<?php');
         if ($pos_phptag === false) {
             // not a PHP file
             continue;
         }
         $phpfiles['name'][] = $filename;
         $phpfiles['data'][] = $buffer;
     }
     $arr_init = array();
     foreach ($this->init_files as $filters) {
         $arr_init += preg_grep('~' . str_replace('\\*', '.+', quotemeta($filters)) . '~isx', $phpfiles['name']);
     }
     $arr_main = array_diff($phpfiles['name'], $arr_init);
     foreach ($arr_init as $k => $filename) {
         if (!preg_match('~' . $search_init . '~isx', $phpfiles['data'][$k])) {
             $badfiles_init[] = $filename;
         }
     }
     foreach ($arr_main as $k => $filename) {
         if (!preg_match('~' . $search . '~isx', $phpfiles['data'][$k])) {
             $badfiles_main[] = $filename;
         }
     }
     if (!empty($badfiles_init)) {
         echo '<h2>Files which seem to miss the check for defined(EVO_CONFIG_LOADED)</h2>';
         echo "\n<ul><li>\n";
         echo implode("\n</li><li>\n", $badfiles_init);
         echo "\n</li></ul>\n";
     }
     if (!empty($badfiles_main)) {
         echo '<h2>Files which seem to miss the check for defined(EVO_MAIN_INIT)</h2>';
         echo "\n<ul><li>\n";
         echo implode("\n</li><li>\n", $badfiles_main);
         echo "\n</li></ul>\n";
     }
     $this->assertFalse($badfiles_init + $badfiles_main);
 }
示例#27
0
 /**
  * {@inheritdoc}
  */
 public function toLdap($guid)
 {
     $guid = strtolower($guid) === self::AUTO ? LdapUtilities::uuid4() : $guid;
     if (!LdapUtilities::isValidGuid($guid)) {
         throw new AttributeConverterException(sprintf('The value "%s" is not a valid GUID.', $guid));
     }
     $guid = (new GUID($guid))->toBinary();
     if ($this->getOperationType() == self::TYPE_SEARCH_TO) {
         $guid = implode('', preg_filter('/^/', '\\', str_split(bin2hex($guid), 2)));
     }
     return $guid;
 }
示例#28
0
 /**
  * Get the paths that should be excluded.
  *
  * @param string $path
  *
  * @return array
  */
 public function getExcludePaths($path)
 {
     $excludePaths = [];
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
     $objects = new \RegexIterator($iterator, '/.*(.php)$/', \RecursiveRegexIterator::GET_MATCH);
     foreach ($objects as $filename => $object) {
         if (preg_filter($this->ignoredFolder, [], $filename)) {
             $excludePaths[] = dirname($filename);
         }
     }
     $excludePaths = array_unique($excludePaths);
     return $excludePaths;
 }
 public static function getPromoterTypes()
 {
     $arrOptions = array();
     $arrConstants = preg_filter('/^CALENDARPLUS_PROMOTER_TYPE_(.*)/', 'CALENDARPLUS_PROMOTER_TYPE_$1', array_keys(get_defined_constants()));
     if (!is_array($arrConstants)) {
         return $arrOptions;
     }
     foreach ($arrConstants as $strConstant) {
         $type = constant($strConstant);
         $arrOptions[$type] = $type;
     }
     return $arrOptions;
 }
示例#30
0
 public static function removeTextBetweenCharsIncludingDelimiters($s, $leftchar, $rightchar)
 {
     $leftchar = preg_quote($leftchar, "/");
     $rightchar = preg_quote($rightchar, "/");
     $pattern = "/" . $leftchar . "[^" . $leftchar . $rightchar . "]*" . $rightchar . "/";
     // replace matches with empty space
     $result = preg_filter($pattern, " ", $s);
     if ($result) {
         // and filter double whitespace afterwards (otherwise the upper pattern doesn't get matches without preceeding chars!?
         $result = preg_replace('/\\s+/', ' ', $result);
         return $result;
     }
     return $s;
 }