Esempio n. 1
0
 public function checkCommand(...$params)
 {
     $o = Flux::getInstance();
     $fail = array();
     if (!is_array($params)) {
         $fail[] = $params;
         return $fail;
     }
     foreach ($params as $v) {
         if (!is_array($v)) {
             $fail[] = $v;
             continue;
         }
         $funcName = array_shift($v);
         $func = array($o, $funcName);
         if (!is_callable($func)) {
             $fail[] = $funcName;
         } else {
             $reflection = new ReflectionMethod($o, $funcName);
             $parameters = $reflection->getParameters();
             $params = array();
             foreach ($parameters as $p) {
                 if (!$p->isdefaultvalueavailable()) {
                     $params[] = $p;
                 }
             }
             if (count($params) > count($v)) {
                 $fail[] = array($funcName, $v);
             }
         }
     }
     return $fail;
 }
Esempio n. 2
0
 public function testPhoneMatchReplace()
 {
     $phone = '6124240013';
     $flux = Flux::getInstance()->startOfLine()->maybe('(')->digits(3)->maybe(')')->maybe(' ')->digits(3)->maybe('-')->digits(4)->endOfLine();
     $this->assertTrue((bool) $flux->match($phone));
     $this->assertTrue($flux->replace('($2) $5-$7', $phone) === '(612) 424-0013');
 }
Esempio n. 3
0
<?php

require_once realpath(__DIR__ . '/../vendor/autoload.php');
use SelvinOrtiz\Utils\Flux\Flux;
use SelvinOrtiz\Utils\Flux\Helper;
// The subject string (Phone)
$str = '(612) 424-0013';
// Building the pattern (Fluently)
$flux = Flux::getInstance()->startOfLine()->find('(')->digits(3)->then(')')->maybe(' ')->digits(3)->anyOf(' -')->digits(4)->endOfLine();
// Output the Flux instance
Helper::dump($flux);
// Output the fluently built pattern (@see /src/SelvinOrtiz/Utils/Flux/Helper)
Helper::msg($flux);
// Inspect the results
Helper::msg($str);
Helper::msg($flux->match($str) ? 'matched' : 'unmatched');
Helper::msg($flux->replace('$2.$5.$7', $str));
//--------------------------------------------------------------------------------
// EOF
//--------------------------------------------------------------------------------
Esempio n. 4
0
<?php

require_once realpath(__DIR__ . '/../vendor/autoload.php');
use SelvinOrtiz\Utils\Flux\Flux;
use SelvinOrtiz\Utils\Flux\Helper;
// The subject string (URL)
$str = 'http://www.selvinortiz.com';
// Building the pattern (Fluently)
$flux = Flux::getInstance()->startOfLine()->find('http')->maybe('s')->then('://')->maybe('www.')->anythingBut('.')->either('.co', '.com')->ignoreCase()->endOfLine();
// Output the Flux instance
Helper::dump($flux);
// Output the fluently built pattern (@see /src/SelvinOrtiz/Utils/Flux/Helper)
Helper::msg($flux);
// Inspect the results
Helper::msg($str);
Helper::msg($flux->match($str) ? 'matched' : 'unmatched');
Helper::msg($flux->replace('https://$5$6', $str));
Helper::msg(Flux::getInstance()->word()->length(1));
Helper::msg(Flux::getInstance()->then('hello')->length(5));
//--------------------------------------------------------------------------------
// EOF
//--------------------------------------------------------------------------------
Esempio n. 5
0
<?php

require_once realpath(__DIR__ . '/../vendor/autoload.php');
use SelvinOrtiz\Utils\Flux\Flux;
use SelvinOrtiz\Utils\Flux\Helper;
// The subject string (Date)
$str = 'Monday, Jul 22, 2013';
// Building the pattern (Fluently)
$flux = Flux::getInstance()->startOfLine()->word()->then(', ')->letters(3)->then(' ')->digits(1, 2)->then(', ')->digits(4)->endOfLine();
// Output the Flux instance
Helper::dump($flux);
// Output the fluently built pattern (@see /src/SelvinOrtiz/Utils/Flux/Helper)
Helper::msg($flux);
// Inspect the results
Helper::msg($str);
Helper::msg($flux->match($str) ? 'matched' : 'unmatched');
Helper::msg($flux->replace('$3/$5/$7', $str));
//--------------------------------------------------------------------------------
// EOF
//--------------------------------------------------------------------------------
Esempio n. 6
0
 /**
  * @test
  */
 public function shouldWorkWhenCalledWithFlux()
 {
     $regex = Flux::getInstance()->either('a', 'b')->digits();
     $result = $this->executor->getAllMatches($regex, self::MATCHING_SUBJECT);
     $this->assertInstanceOf(MatchResult::class, $result);
     $this->assertEquals(4, $result->getMatchesCount());
     $this->assertEquals('a5', $result->getMatchAt(2)->getFullMatch());
     $this->assertEquals('a', $result->getMatchAt(2)->getSubMatchAt(1));
     $this->assertEquals(14, $result->getMatchAt(2)->getSubmatchOffsetAt(1));
 }