示例#1
0
 /**
  * @return Chain
  */
 public function makeChain($x, $y, $chain = null)
 {
     if (isset(self::$see[$y][$x])) {
         return $chain;
     }
     if ($this->allowPoint($x, $y)) {
         if (is_null($chain)) {
             $chain = new Chain();
         }
         $chain->addPoint($x, $y);
         self::$see[$y][$x] = 1;
         if (sizeof($chain->op) > 250) {
             return $chain;
         }
         $this->makeChain($x + 1, $y, $chain);
         $this->makeChain($x, $y + 1, $chain);
         $this->makeChain($x - 1, $y, $chain);
         $this->makeChain($x, $y - 1, $chain);
         $this->makeChain($x + 1, $y + 1, $chain);
         $this->makeChain($x + 1, $y - 1, $chain);
         $this->makeChain($x - 1, $y - 1, $chain);
         $this->makeChain($x - 1, $y + 1, $chain);
     }
     return $chain;
 }
示例#2
0
 public function __construct(Chain $child = null, $name = "", $type = "")
 {
     $this->child = $child;
     $this->name = $name;
     $this->type = $type;
     if ($child instanceof Chain) {
         $child->setParent($this);
     }
 }
 /**
  * Encode a value and return it's javascript representation.
  *
  * @param Chain    $chain The chain.
  * @param mixed    $value The generated javascript.
  * @param int|null $flags Force custom json encode flags.
  *
  * @return string
  */
 public static function routeEncodeValue(Chain $chain, $value, $flags = null)
 {
     if (static::isScalar($value)) {
         // If we got a scalar value, just encode it.
         return $chain->first('encodeScalar', [$value, $flags]);
     } elseif (is_array($value)) {
         return $chain->first('encodeArray', [$value, $flags]);
     }
     return $chain->first('encodeObject', [$value, $flags]);
 }
 public function handleRequest(Chain $chain)
 {
     $request = $chain->getRequest();
     $text = $request['msg'];
     if (preg_match('~(kroleg\\.tk)~uis', $text)) {
         $text = 'У меня бывают запоры и я писаюсь в кровать по ночам!';
     }
     $request['msg'] = $text;
     $chain->setRequest($request);
 }
示例#5
0
 /**
  * @test
  */
 function it_passes_previous_result_to_next_filter_and_returns_the_last_filter_result()
 {
     $filterChain = new Chain();
     $someDataToFilter = array();
     $filterResultA = 'filter result A';
     $filterResultB = 'filter result B';
     $filterResultC = 'filter result C';
     $filterA = $this->getFilter($someDataToFilter, $filterResultA);
     $filterB = $this->getFilter($filterResultA, $filterResultB);
     $filterC = $this->getFilter($filterResultB, $filterResultC);
     $filterChain->add($filterA)->add($filterB)->add($filterC);
     $this->assertSame($filterResultC, $filterChain->filter($someDataToFilter));
 }
 public function testPushOnline()
 {
     $data = [['instance' => $this->getControllerMock(), 'action' => 'test1'], ['instance' => $this->getControllerMock(), 'action' => 'test2']];
     $newItem = ['instance' => $this->getControllerMock(), 'action' => 'newAction'];
     $chain = new Chain($data);
     foreach ($chain as $key => $controller) {
         if ($key == 0) {
             $chain->pushAfterCurrent($newItem['instance'], $newItem['action']);
         } elseif ($key == 1) {
             $this->assertEquals($newItem['instance'], $controller['instance']);
             $this->assertEquals($newItem['action'], $controller['action']);
         }
     }
 }
示例#7
0
 public function testHasWord_Uninitialized()
 {
     $word = new Word();
     $word->name = "способность";
     $word->name_related_word = "чувство";
     $word->me = "способность живого существа воспринимать внешние впечатления, ощущать, испытывать что-нибудь";
     $word->arr_me = array('что-нибудь', 'существо', 'способность', 'ощущать', 'испытывать', 'воспринимать', 'живой', 'впечатление', 'внешний');
     $word1 = new Word();
     $test = new Chain();
     $test->number = 1;
     //array_push($test->words, $word);
     $test->words = array($word);
     //метод assertEquals(), который первым обязательным параметром принимает ожидаемое значение, вторым актуальное и проверяет их соответствие.
     $this->assertEquals(false, $test->hasWord($word1));
 }
示例#8
0
 /**
  * @covers \Tivie\Command\Chain::add
  * @covers \Tivie\Command\Chain::run
  */
 public function testRunPipedArgument()
 {
     $chain = new Chain();
     $xArg = 'foo';
     $result1 = $this->getResultMock($xArg, 0);
     $cmd1 = $this->getCmdMock();
     $cmd1->expects($this->once())->method('run')->willReturn($result1);
     $chain->add($cmd1);
     $cmd2 = $this->getCmdMock();
     $arg1 = $this->getArgumentMock('bar', array(PIPE_PH));
     $arg1->expects($this->once())->method('replaceValue')->with(0, $xArg);
     $cmd2->addArgument($arg1);
     $chain->add($cmd2, RUN_IF_PREVIOUS_SUCCEEDS, true);
     $chain->run();
 }
示例#9
0
 function testRunDoesNotNeedArgs()
 {
     Chain::add('test1', function () {
         return 1;
     });
     $this->assertEquals([1], Chain::run('test1')->realize());
 }
示例#10
0
 /**
  * C-o-R pattern
  * @param Chain $chain input stream
  * @return false|null|true
  */
 public function handleRequest(Chain $chain)
 {
     $request = $chain->getRequest();
     $msgParts = explode('|', $request['msg']);
     $brCount = 1;
     if (!empty($msgParts)) {
         $newMsgParts = [];
         $brCount = min(self::MAX_BR, count($msgParts));
         for ($i = 0; $i < $brCount; $i++) {
             $part = trim($msgParts[$i]);
             if (!$part) {
                 continue;
             }
             $newMsgParts[] = $part;
         }
         $request['msg'] = implode(self::BR, $newMsgParts);
     }
     $props = $chain->getUser()->getProperties();
     $props->setMessagesCount($props->getMessagesCount() + $brCount);
     $chain->setRequest($request);
 }
示例#11
0
文件: ga.php 项目: vench/esee
function makeChain($points, $x, $y, $chain = null)
{
    static $see = [];
    if (isset($see[$x][$y])) {
        return $chain;
    }
    $see[$x][$y] = 1;
    if (isset($points[$y][$x]) && $points[$y][$x] == 1) {
        if (is_null($chain)) {
            $chain = new Chain();
        }
        $chain->addPoint($x, $y);
        makeChain($points, $x + 1, $y, $chain);
        makeChain($points, $x + 1, $y + 1, $chain);
        makeChain($points, $x, $y + 1, $chain);
        makeChain($points, $x - 1, $y, $chain);
        makeChain($points, $x - 1, $y - 1, $chain);
        makeChain($points, $x, $y - 1, $chain);
        makeChain($points, $x + 1, $y - 1, $chain);
        makeChain($points, $x - 1, $y + 1, $chain);
    }
    return $chain;
}
示例#12
0
文件: client.php 项目: JJmaz/dp
function validate($input, $type)
{
    /**
     * チェーンの作成
     * typeの値によってチェーンを動的に変更
     */
    $chain = new Chain();
    $chain->setHandler(new NotNullValidationHandler());
    $chain->setHandler(new MaxLengthValidationHandler());
    //$chain -> setHandler(new MaxLengthValidationHandler(8));
    switch ($type) {
        case 1:
            $chain->setHandler(new AlphabetValidationHandler());
            break;
        case 2:
            $chain->setHandler(new NumberValidationHandler());
            break;
    }
    return $chain->validate($input);
}
示例#13
0
文件: chunk.php 项目: wemash/hooray
<?php

Chain::add('chunk', function ($data, $chunkSize, $preserveKeys = false) {
    return array_chunk($data, $chunkSize, $preserveKeys);
});
示例#14
0
文件: keys.php 项目: wemash/hooray
<?php

Chain::add('keys', function ($data) {
    return array_keys($data);
});
示例#15
0
文件: take.php 项目: wemash/hooray
<?php

Chain::add('take', function ($data, $count) {
    return array_slice($data, 0, $count);
});
示例#16
0
 /**
  * Create a new chain
  *
  * @param  \Zend\Controller\Router\Route\AbstractRoute $route
  * @param  string                                $separator
  * @return \Zend\Controller\Router\Route\Chain
  */
 public function addChain(AbstractRoute $route, $separator = '/')
 {
     $chain = new Chain();
     $chain->addChain($this)->addChain($route, $separator);
     return $chain;
 }
示例#17
0
文件: join.php 项目: wemash/hooray
<?php

Chain::addTerminal('join', function ($data, $joiner = '', $terminalJoiner = null, $ifEmpty = '') {
    if (is_null($terminalJoiner)) {
        $terminalJoiner = $joiner;
    }
    switch (count($data)) {
        case 0:
            return $ifEmpty;
        case 1:
            return $data[0];
        case 2:
            return join($terminalJoiner, $data);
        default:
            $last = array_pop($data);
            return join($terminalJoiner, [join($joiner, $data), $last]);
    }
});
示例#18
0
文件: shift.php 项目: wemash/hooray
<?php

Chain::addTerminal('shift', function ($data) {
    return array_shift($data);
});
示例#19
0
<?php

Chain::add('countValues', function ($data) {
    return array_count_values($data);
});
示例#20
0
文件: splice.php 项目: wemash/hooray
<?php

// This bad boy seems off. Why not decompose this into
// remove(offset, length) and insert(position, values)?
Chain::add('splice', function ($data, $offset, $length, $replacement) {
    array_splice($data, $offset, $length, $replacement);
    return $data;
});
示例#21
0
文件: sum.php 项目: wemash/hooray
<?php

Chain::addTerminal('sum', function ($data) {
    return array_sum($data);
});
示例#22
0
文件: pad.php 项目: wemash/hooray
<?php

Chain::add('pad', function ($data, $size, $value) {
    return array_pad($data, $size, $value);
});
示例#23
0
文件: shuffle.php 项目: wemash/hooray
<?php

Chain::add('shuffle', function ($data, $seed = null) {
    mt_srand($seed || microtime());
    $data = array_values($data);
    for ($i = count($data) - 1; $i > 0; $i--) {
        $j = mt_rand(0, $i);
        $tmp = $data[$i];
        $data[$i] = $data[$j];
        $data[$j] = $tmp;
    }
    return $data;
});
示例#24
0
文件: flatmap.php 项目: wemash/hooray
<?php

Chain::add('flatmap', function ($data, $action) {
    return hooray($data)->reduce(function ($carry, $datum) use($action) {
        $result = $action($datum);
        if (!is_array($result)) {
            $result = [$result];
        }
        return array_merge($carry, $result);
    }, []);
});
示例#25
0
require_once "../vendor/kint/Kint.class.php";
require_once "../models/Mysql_Connection.class.php";
require_once "../models/Model.class.php";
require_once "../controllers/Controller.class.php";
require_once "../views/View.class.php";
require_once "../models/User.class.php";
require_once "../models/Chain.class.php";
?>

<?php 
$mysqli = new Mysql_Connection();
$model = new Model($mysqli->getConn());
$view = new View($model);
$controller = new Controller($model, $view);
$chain = new Chain($mysqli->getConn());
d($chain->getChainSources("world war 2"));
?>
<form id="foo" >
    <input type="hidden" name="troveid" id="troveid" value="35568463"/>
    <button id="ViewSource1" class="TableButton">Add to Chain</button>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
    // variable to hold request
    var request;
    // bind to the submit event of our form
    $("#foo").submit(function(event){
        // abort any pending request
        if (request) {
            request.abort();
示例#26
0
<?php

Chain::add('intersect', function ($data, $other) {
    return array_intersect($data, Hooray::unwrap([$other]));
});
示例#27
0
文件: values.php 项目: wemash/hooray
<?php

Chain::add('values', function ($data) {
    return array_values($data);
});
示例#28
0
 /**
  * 
  * @param string $serviceName
  * @param array $args
  */
 public function broadcastArgs($serviceName, array $args)
 {
     $observers = $this->getObservers($serviceName);
     return Chain::invoke($serviceName, $observers, $args);
 }
示例#29
0
文件: filter.php 项目: wemash/hooray
<?php

Chain::add('filter', function ($data, $action) {
    return array_filter($data, $action);
});
示例#30
0
<?php

//use Guest\Mest\Test\ClassTest;
//namespace Guest\Mest\Test;
//require 'ClassTest.php';
//$c=new ClassTest();
//$c->set(1);
//$c->get();
//$m=new DateTime();
//echo $m->getTimestamp();
require_once "Cnain.php";
$ch = new Chain();
echo $ch->add2()->add5()->num;
//echo $ch->num;
echo "commiting";
echo "commiting 2";
echo 'COMMITING 3';