예제 #1
0
파일: before.php 프로젝트: prggmr/xpspl
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $foo = XP_SIG('foo');
    xp_signal($foo, function () {
    });
    xp_before($foo, function ($foo) {
        $foo->foo = 'foo';
    });
    xp_emit($foo);
    $test->equal($foo->foo, 'foo');
}, 'API Before function');
예제 #2
0
파일: sig_suite.php 프로젝트: prggmr/xpspl
 /**
  * Registers a setup function.
  *
  * @param  object  $function  Closure
  *
  * @return  void
  */
 public function setup($function)
 {
     xp_before($this->_test, xp_null_exhaust($function));
 }
예제 #3
0
파일: interrupt.php 프로젝트: prggmr/xpspl
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once '__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $foo = XP_SIG('foo');
    xp_before($foo, function ($foo) {
        $foo->bar = 'HelloWorld';
    });
    xp_after($foo, function ($foo) {
        unset($foo->bar);
    });
    xp_signal($foo, function ($foo) use($test) {
        $test->equal($foo->bar, 'HelloWorld');
    });
    xp_emit($foo);
    $test->false(isset($foo->bar));
}, 'Interruptions');
예제 #4
0
파일: interrupt.php 프로젝트: prggmr/xpspl
<?php

// Handle Foo
xp_signal(XP_SIG('foo'), function ($signal) {
    echo $signal->bar;
});
// When foo is emitted insert bar into the event
xp_before(XP_SIG('foo'), function ($signal) {
    echo "I RAN" . PHP_EOL;
    $signal->bar = 'foo';
});
xp_before(XP_SIG('foo'), xp_high_priority(function ($signal) {
    echo "I RAN BEFORE" . PHP_EOL;
}));
// After foo is emitted unset bar in the event
xp_after(XP_SIG('foo'), function ($signal) {
    unset($signal->bar);
});
$signal = xp_emit(XP_SIG('foo'));
var_dump(isset($signal->bar));