public function __construct($options) { $options = array_merge($options, array('allow_null' => true)); if (!isset($options['accept'])) { $options['accept'] = '1'; } parent::__construct($options); }
public static function checkExt(&$layer, &$external) { if (!$external) { return; } unset($layer['external']); Each::fora($external, function (&$exter) use(&$layer) { if (is_string($exter)) { $external =& Load::loadJSON($exter); } else { $external = $exter; } if ($external) { foreach ($external as $i => &$v) { external::merge($layer, $external, $i); } } }); }
Event::handler('layer.oncheck', function (&$layer) { if (!isset($layer['divtpl'])) { return; } $layer['div'] = Template::parse(array($layer['divtpl']), $layer); }, 'div:env,config,external'); Event::handler('layer.isshow', function (&$layer) { if (empty($layer['div']) && !empty($layer['parent'])) { return false; } //Такой слой игнорируется, события onshow не будет, но обработка пройдёт дальше у других дивов $start = false; if (Run::exec(Controller::$layers, function (&$l) use(&$layer, &$start) { //Пробежка не по слоям на ветке, а по всем слоям обрабатываемых после.. .то есть и на других ветках тоже if (!$start) { if (Each::isEqual($layer, $l)) { $start = true; } return; } if (@$l['div'] !== @$layer['div']) { return; } //ищим совпадение дивов впереди if (Controller::fire('layer.isshow', $l)) { $layer['is_save_branch'] = Layer::isParent($l, $layer); return true; //Слой который дальше показывается в томже диве найден } })) { return false;
/** * @expectedException Respect\Validation\Exceptions\EachException */ public function testAssertShouldFailOnNonTraversable() { $v = new Each(new NotEmpty()); $result = $v->assert(123); $this->assertFalse($result); }
$r = null; $counter++; if ($counter === 3) { assert(6 === $b); } return $r; }); assert(4 === $counter); $counter = 0; $el = 1; Each::exec($el, function &() use(&$counter) { $r = null; $counter++; return $r; }); assert(1 === $counter); $el = 'test'; Each::exec($el, function &() use(&$counter) { $r = null; $counter++; return $r; }); assert(2 === $counter); $el = ['name' => 'oduvanio', 'email' => 'mail']; Each::exec($el, function &() use(&$counter) { $r = null; $counter++; return $r; }); assert(3 === $counter); echo '{"result": 1}';
/** * @expectedException Respect\Validation\Exceptions\EachException */ public function testCheckShouldFailWithNonIterableInput() { $v = new Each($this->getRuleMock(false)); $v->check(null); }
public static function &forx(&$obj, $callback, $back = false) { //Бежим сначало по объекту а потом по его свойствам как по массивам return Each::foro($obj, function &(&$v, $key) use(&$obj, $callback, $back) { return Each::fora($v, function &(&$el, $i, &$group) use($callback, $key) { $r =& $callback($el, $key, $group, $i); return $r; }, $back); }, $back); }
$el = ['oduvanio', 'mail']; Each::exec($el, function () use(&$counter) { $counter++; }); assert(2 === $counter); $counter = 0; $el = [2, [4, 6], 5]; Each::exec($el, function ($b) use(&$counter) { $counter++; if ($counter === 3) { assert(6 === $b); } }); assert(4 === $counter); $counter = 0; $el = 1; Each::exec($el, function () use(&$counter) { $counter++; }); assert(1 === $counter); $el = 'test'; Each::exec($el, function () use(&$counter) { $counter++; }); assert(2 === $counter); $el = ['name' => 'oduvanio', 'email' => 'mail']; Each::exec($el, function () use(&$counter) { $counter++; }); assert(3 === $counter); echo '{"result": 1}';
/** * @expectedException Respect\Validation\Exceptions\EachException */ public function test_assert_should_fail_on_non_traversable() { $v = new Each(new NotEmpty()); $result = $v->assert(123); $this->assertFalse($result); }