Пример #1
0
 public function testChain()
 {
     $option = new Some(1);
     $multiplyByTwo = function ($i) {
         return new Some($i * 2);
     };
     $multiplyByThree = function ($i) {
         return new Some($i * 3);
     };
     $assertValue = function ($i) {
         $this->assertSame(1 * 2 * 3, $i);
         return new Some($i);
     };
     $returnNone = function () {
         return new None();
     };
     $thisNeverRuns = function () {
         throw new \Exception();
     };
     $option->flatMap($multiplyByTwo)->flatMap($multiplyByThree)->flatMap($assertValue)->flatMap($returnNone)->flatMap($thisNeverRuns);
 }
Пример #2
0
<?php

trait Foo
{
    private $sValue = 'Foo';
    public function getFoo()
    {
        return 'Hallo From Trait ' . $this->sValue . PHP_EOL;
    }
}
trait Bar
{
    public function getBar()
    {
        return 'Hallo From Trait Bar' . PHP_EOL;
    }
}
class Some
{
    use Foo, Bar;
}
$foo = new Some();
echo $foo->getFoo();
echo $foo->getBar();
echo PHP_EOL;
Пример #3
0
<?php

require_once 'autoload.php';
class Some
{
    protected $value = 'hello';
    public function getValue()
    {
        return $this->value;
    }
}
class testSome
{
    use \PHPCraftdream\TestCase\tTestCase;
}
$some = new Some();
$testSome = new testSome();
var_dump($some->getValue() === 'hello');
//true
$testSome->setProp($some, 'value', 'bye');
var_dump($some->getValue() === 'bye');
//true
$testSome->setProp($some, 'value', 'byebye');
var_dump($testSome->getProp($some, 'value') === 'byebye');
//true
Пример #4
0
        return 'Im saying "getFunctionTwo" from Class: AnotherClass!' . PHP_EOL;
    }
    public function getFunctionThree()
    {
        return 'Im saying "getFunctionThree" from Class: AnotherClass!' . PHP_EOL;
    }
}
trait Foo
{
    public function getFunctionOne()
    {
        return 'Im saying "getFunctionOne" from trait Foo!' . PHP_EOL;
    }
    public function getFunctionTwo()
    {
        return 'Im saying "getFunctionTwo" from trait Foo!' . PHP_EOL;
    }
}
class Some extends AnotherClass
{
    use Foo;
    public function getFunctionOne()
    {
        return 'Im saying "getFunctionOne" from Class: Some!' . PHP_EOL;
    }
}
$foo = new Some();
echo $foo->getFunctionOne();
echo $foo->getFunctionTwo();
echo $foo->getFunctionThree();
echo PHP_EOL;
    {
        return 'Im saying foo from trait Foo!' . PHP_EOL;
    }
    public function sayBar()
    {
        return 'Im saying bar from trait Foo!' . PHP_EOL;
    }
}
trait Bar
{
    public function sayFoo()
    {
        return 'Im saying foo from trait Bar!' . PHP_EOL;
    }
    public function sayBar()
    {
        return 'Im saying bar from trait Bar!' . PHP_EOL;
    }
}
class Some
{
    use Foo, Bar {
        Bar::sayFoo insteadof Foo;
        Foo::sayBar insteadof Bar;
        Foo::sayBar as sayFooFromFoo;
    }
}
$foo = new Some();
echo $foo->sayBar();
echo $foo->sayFoo();
echo $foo->sayFooFromFoo();
Пример #6
0
 public function __construct()
 {
     eval("class Bar extends Foo {}");
     Some::foo($this);
 }