Example #1
0
 public function execute()
 {
     $sPath = Request::path();
     foreach ($this->routes as $sKey => $sMethod) {
         if (preg_match('~' . $sKey . '~', $sPath)) {
             debug(get_class($this) . " -> {$sMethod}() [{$sPath} => {$sKey}]");
             if ($sMethod[0] == '#') {
                 $sMethod = substr($sMethod, 1);
                 if (class_exists($sMethod)) {
                     return Service::create($sMethod)->execute();
                 } else {
                     debug('Service not found: ' . $sMethod);
                     $this->error404();
                 }
             } else {
                 if (method_exists($this, $sMethod)) {
                     $this->catchAll();
                     $bReturn = $this->{$sMethod}();
                     P::mark(get_class($this) . '::' . $sMethod);
                     Response::end();
                     return $bReturn;
                 } else {
                     debug('Method not found: ' . get_class($this) . '::' . $sMethod . '()');
                     $this->error404();
                 }
             }
         }
     }
     debug(get_class($this) . " -> NO MATCH");
     return false;
 }
Example #2
0
 public function completeItem($id) : JsonResponse
 {
     $status = Nullable::fromValue($id)->reject('')->map('intval')->filter(P::lt(0))->flatMap(Item::class . '::findNullable')->map(function ($item) {
         return $item->setStateId(State::of('completed')->id)->save();
     })->getOrThrow(new \RuntimeException("Item by ID {$id} not found!"));
     return response()->json(['status' => $status, 'id' => $id]);
 }
 public function __construct($p1)
 {
     $this->prop = $p1;
     echo "Inside instance " . __METHOD__ . "\n";
     parent::__construct();
     M::__construct();
     // allowed
     N::__construct();
     // allowed
     $clName = "M";
     $clName::__construct();
     // allowed
     //      "M"::__construct();     // not allowed
     // can call instance and static methods using both -> and ::
     $this->gi();
     // $this explicitly used (and passed)
     P::gi();
     // $this implicitly used (and passed)
     self::gi();
     // $this implicitly used (and passed)
     $this->gs();
     // call to static method, so no $this passed
     P::gs();
     // call to static method, so no $this passed
     self::gs();
     // call to static method, so no $this passed
 }
Example #4
0
 /**
  * Get counts of items that are new and which ones are completed
  * @return Tuple(int, int, int)
  */
 public static function countNewAndDoneItems() : Tuple
 {
     $countNewAndPast = P::partition(function ($item) {
         $name = $item->state->getShortname();
         return $name === 'expired' || $name === 'completed';
     }, Item::all());
     list($done, $new) = $countNewAndPast;
     $counts = Tuple::create('integer', 'integer');
     return $counts(count($done), count($new));
 }
 function f()
 {
     self::nonStaticButSelfClass();
     static::nonStaticButSelfClass();
     parent::nonStaticButSelfClass();
     P::nonStaticAClass();
     P::staticAClass();
     A1::nonStaticButSelfClass();
     \a1::nonStaticButSelfClass();
     b::nonStaticButSelfClass();
 }
Example #6
0
function CA($f)
{
    P::Q();
    $j = P::$c->CE();
    $k = array();
    foreach ($j as $l) {
        $m = CF($l, $f);
        if ($m < 4) {
            $k[] = $l;
        }
    }
    return $k;
}
Example #7
0
function B($a = null)
{
    if (C) {
        D('E', __METHOD__);
    }
    if (F($a)) {
        switch ($this->G()) {
            case 'H':
                $a = I('J');
                break;
            case 'K':
                $a = L(M($this->N));
                break;
            default:
                $a = 'O';
        }
    }
    P::B($a);
}
Example #8
0
 public static function evalString($s, $aContextVariables = [], $bFlushBuffer = true)
 {
     if (class_exists('P')) {
         P::mark('EVAL_BEGIN');
     }
     ob_start();
     extract($aContextVariables);
     if (eval('?>' . $s) === false) {
         $_ENV['EVAL_ERROR'] = true;
         $_ENV['EVALED_CODE'] = $s;
         // file_put_contents(M::PROJECT_ROOT() . '/server/logs/processor.log', $s);
     }
     $sResult = ob_get_contents();
     ob_end_clean();
     if (class_exists('P')) {
         P::mark('EVAL_END');
     }
     if ($bFlushBuffer) {
         print $sResult;
     } else {
         return $sResult;
     }
 }
Example #9
0
<?php

require 'parcel.php';
P::run();
<?php

$a = new A("Link", "http://www.google.com", array("style" => "color:blue"));
echo $a;
$h1 = new H("1", "This is a h1");
$h2 = new H("2", "This is a h2");
echo $h1 . $h2;
$hr = new HR();
$h1->setContents("This is the new contents");
echo $hr . $h1 . $h2;
$p = new P();
$br = new BR();
$p->setContents("This is some {$br} contents");
echo $p;
$comment = new Comment("This is commented out");
echo $comment;
$img = new Img("https://i.ytimg.com/vi/KY4IzMcjX3Y/maxresdefault.jpg", "This is a dog", array("width" => "100", "height" => "100"));
echo $img;
$table = new Table();
$table->columns(array("col1", "col2", "col3"));
$table->addRow(array("data col1", "data col2", "data col3"));
echo $table;
$list = new BootstrapList();
$list->addLi("item 1")->addLi("item 2");
echo $list;
$div = new Div();
$div->setContents($p . $img);
echo $div;
$span = new Span();
$span->setContents("This is a span");
$div->setContents($span->setContents("This is some new content"));
Example #11
0
<?php

namespace yii\platform;

use yii\platform\validators\Validator;
class P extends \Yii
{
}
P::setAlias('@platform', __DIR__);
if (!isset(Validator::$builtInValidators['compareDate'])) {
    Validator::$builtInValidators['compareDate'] = 'yii\\platform\\validators\\CompareDateValidator';
}
Example #12
0
<?php

switch ($a) {
    case 'b':
        return 'c';
    case 'd':
        $e = 'f';
        if (G::h('i')) {
            $j .= "k";
        }
        return $l;
    case 'm':
        $n = 'o';
        if (P::q('r')) {
            $s .= "t";
        }
        return $u;
    default:
        return 'v';
}
Example #13
0
A<?php 
foreach ($a as $b => $c) {
    $d = $e->C(array('D' => $f));
    ?>
D<?php 
    echo F::G('H', 'I');
    ?>
I<?php 
    echo K::L($g, $h, NULL, NULL, M);
    ?>
M<?php 
    foreach ($i as $j) {
        ?>
N<?php 
        echo P::Q("{$k}R{$l}", "{$m}S{$n}", NULL, NULL, T);
        ?>
T<?php 
    }
    ?>
U<?php 
}
?>
V
Example #14
0
<nav class="component--nav">
	<a href="<?php 
echo P::url('home');
?>
"><?php 
echo P::string('Front page', 'text');
?>
</a>	
</nav>
Example #15
0
<?php

function B($a)
{
}
?>
B<?php 
D('E', array('F' => $b, 'G' => $c));
H('I');
J('K', 'L');
M('N');
if (O(P::Q('R') . 'S')) {
}
Example #16
0
$applyTax(6.0);
//-> Closure
$applyTax(6.0, 100);
//-> 106
$applyTax(6.0)(100);
//-> 106
// $total = P::compose($currency('USD'), $applyTax(6.0), 'P::sum');
// $total([10.95, 16.99, 25.99]); //-> USD 57.1658
// function findUserById($id) {
// 	//...
// 	return Option::fromValue($user);
// }
// $userOpt = Option::fromValue(findUserById(10)); //-> Option(Option(User))
// $userOpt->flatMap(P::prop('address'))->map(P::prop('country'))->get();
$a = function () {
    (yield 1);
    (yield 3);
};
$modulo = function ($number) {
    return $number % 2;
};
$modded = P::toArray(P::map($modulo, $a()));
print_r($modded);
// composition with currying
$input = 'A complex system that works is 
	          invariably found to have evolved 
	          from a simple system that worked';
$explodeOnSpace = P::curry2('explode')(' ');
$countWords = P::compose('count', $explodeOnSpace);
$countWords($input);
//-> 17
Example #17
0
function shutdownHandler()
{
    P::mark('END');
    P::report();
    if ($aError = error_get_last()) {
        errorHandler($aError['type'], $aError['message'], $aError['file'], $aError['line']);
    }
    // Flush debug
    $oPhpLogFile = fopen($_ENV['SETTINGS']['FILE_LOG_PHP'], 'a');
    fwrite($oPhpLogFile, $_ENV['DEBUG']);
    fclose($oPhpLogFile);
}
Example #18
0
<?php

require_once 'prototype.php';
$page = new P();
?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="stylesheet" href="css/<?php 
echo $page->stylesheet;
?>
">
    <script src="js/vendor/modernizr-2.7.1.min.js"></script>
</head>
<body>

	<?php 
$page->layout($page);
?>

	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.1.min.js"><\/script>')</script>
    <script src="js/script.min.js"></script>
Example #19
0
println('Example 1');
\Rx\Observable::fromArray([1, 2, 3, 4])->subscribe(new \Rx\Observer\CallbackObserver(function ($x) {
    echo 'Next: ', $x, PHP_EOL;
}, function (Exception $ex) {
    echo 'Error: ', $ex->getMessage(), PHP_EOL;
}, function () {
    echo 'Completed', PHP_EOL;
}));
println('Example 2 Reduce Map Filter with Curry');
$isEven = function ($num) {
    return $num % 2 === 0;
};
$add = function ($x, $y) {
    return $x + $y;
};
$raiseTo = function ($power, $num) {
    return pow($num, $power);
};
$computeSquare = P::curry2($raiseTo)(2);
\Rx\Observable::fromArray([1, 2, 3, 4])->filter($isEven)->map($computeSquare)->reduce($add, 0)->subscribe($stdoutObserver());
//-> 20
println('Example 3 - Map');
\Rx\Observable::fromArray([1, 2, 3, 4])->map(function ($num) {
    return $num * $num;
})->subscribe(new \Rx\Observer\CallbackObserver(function ($x) {
    echo 'Next: ', $x, PHP_EOL;
}, function (Exception $ex) {
    echo 'Error: ', $ex->getMessage(), PHP_EOL;
}, function () {
    echo 'Completed', PHP_EOL;
}));
Example #20
0
 public function hi()
 {
     echo $this->w . '<br/>';
     echo $this->l . '<br/>';
     parent::say();
 }
Example #21
0
<?php

$b['B'] = C('D', $b['B']);
$b['B'] = G($b['B']);
$b['B'] = J($b['B']);
$b['B'] = M('D', $b['B']);
P::$c = C('D', P::$c);
P::$c = G(P::$c);
P::$c = J(P::$c);
P::$c = M('D', P::$c);
$b->AD = C('D', $b->AD);
$b->AD = G($b->AD);
$b->AD = J($b->AD);
$b->AD = M('D', $b->AD);
$b['B2'] = C('D', $b['B']);
$b['B2'] = G($b['B']);
P::$c2 = C('D', P::$c3);
P::$c2 = G(P::$c4);
$b->AD2 = C('D', $b->AD4);
$b->AD2 = G($b->AD5);
 public function testMultipleManyManysToTheSameModelSearchQueryFormsCorrectly()
 {
     $quote = DatabaseCompatibilityUtil::getQuote();
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'ppManyAssumptive', 'relatedModelData' => array('attributeName' => 'name', 'operatorType' => 'equals', 'value' => 'somevalue')), 2 => array('attributeName' => 'ppManySpecific', 'relatedModelData' => array('attributeName' => 'name', 'operatorType' => 'equals', 'value' => 'somevalue2')));
     $searchAttributeData['structure'] = '1 and 2';
     //Build the query 'where' and 'joins'. Confirm they are as expected
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('P');
     $where = ModelDataProviderUtil::makeWhere('P', $searchAttributeData, $joinTablesAdapter);
     $compareWhere = "({$quote}pp{$quote}.{$quote}name{$quote} = 'somevalue') and ";
     $compareWhere .= "({$quote}pp1{$quote}.{$quote}name{$quote} = 'somevalue2')";
     $this->assertEquals($compareWhere, $where);
     $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
     $this->assertEquals(4, $joinTablesAdapter->getLeftTableJoinCount());
     $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
     $this->assertEquals('p_pp', $leftTables[0]['tableName']);
     $this->assertEquals('pp', $leftTables[1]['tableName']);
     $this->assertEquals('ppmanyspecificlink_p_pp', $leftTables[2]['tableName']);
     $this->assertEquals('pp', $leftTables[3]['tableName']);
     //Distinct because MANY_MANY relationships
     $this->assertTrue($joinTablesAdapter->getSelectDistinct());
     //Now test that the subsetSQL query produced is correct.
     $subsetSql = AAA::makeSubsetOrCountSqlQuery('p', $joinTablesAdapter, 1, 5, $where, null, false, $joinTablesAdapter->getSelectDistinct());
     $compareSubsetSql = "select distinct {$quote}p{$quote}.{$quote}id{$quote} id ";
     $compareSubsetSql .= "from {$quote}p{$quote} ";
     $compareSubsetSql .= "left join {$quote}p_pp{$quote} on ";
     $compareSubsetSql .= "{$quote}p_pp{$quote}.{$quote}p_id{$quote} = {$quote}p{$quote}.{$quote}id{$quote} ";
     $compareSubsetSql .= "left join {$quote}pp{$quote} on ";
     $compareSubsetSql .= "{$quote}pp{$quote}.{$quote}id{$quote} = {$quote}p_pp{$quote}.{$quote}pp_id{$quote} ";
     $compareSubsetSql .= "left join {$quote}ppmanyspecificlink_p_pp{$quote} on ";
     $compareSubsetSql .= "{$quote}ppmanyspecificlink_p_pp{$quote}.{$quote}p_id{$quote} = {$quote}p{$quote}.{$quote}id{$quote} ";
     $compareSubsetSql .= "left join {$quote}pp{$quote} pp1 on ";
     $compareSubsetSql .= "{$quote}pp1{$quote}.{$quote}id{$quote} = {$quote}ppmanyspecificlink_p_pp{$quote}.{$quote}pp_id{$quote} ";
     $compareSubsetSql .= "where " . $compareWhere . ' ';
     $compareSubsetSql .= 'limit 5 offset 1';
     $this->assertEquals($compareSubsetSql, $subsetSql);
     //Make sure the sql runs properly.
     $data = P::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
 }
Example #23
0
<?php

$condition = ['where' => ['field' => 'id', 'comparisino' => '=', 'value' => '1'], 'limit' => '220', 'order' => 'id DESC'];
class P
{
    public $limit = 10;
    public $maxLimit = 20;
    public $order = 'id ASC';
    public $condition = ['limit' => 10, 'order' => 'id ASC'];
    public function initialize($condition)
    {
        if (isset($condition['limit']) && $condition['limit'] >= $this->maxLimit) {
            $condition['limit'] = $this->maxLimit;
        }
        $this->condition = array_merge($this->condition, $condition);
    }
}
$p = new P();
$p->initialize($condition);
print_r($p->condition);
Example #24
0
<div class="component--footer">
	<?php 
echo P::string('Footer component', 'string');
?>
</div>        
Example #25
0
    }
}
class P extends O
{
    function __toString()
    {
        return '$this';
    }
    public function who()
    {
        echo "P\n";
    }
    public function call($cb)
    {
        echo join('|', $cb) . "\n";
        call_user_func($cb);
    }
    public function test()
    {
        $this->call(array('parent', 'who'));
        $this->call(array('P', 'parent::who'));
        $this->call(array($this, 'O::who'));
        $this->call(array($this, 'B::who'));
    }
}
echo "===FOREIGN===\n";
$o = new P();
$o->test();
?>
===DONE===
Example #26
0
<div class="layout--dev">
	
	<?php 
if ($page->page != 'index') {
    ?>
		<a href="<?php 
    echo P::url('index');
    ?>
">Back to prototype index</a>
	<?php 
}
?>

    <?php 
$page->section('main');
?>
    
</div>
/**
 * 加密密码
 * @param string $pwd 密码
 * @return string 加密的密码
 */
function EncodePwd($pwd)
{
    $p = new P();
    return $p->pwd($pwd);
}
Example #28
0
 public static function unnest($list)
 {
     Exception::assertList($list);
     return self::apply(P::chain('P::identity'), [$list]);
 }
Example #29
0
 public function testZipWith()
 {
     $f = function ($a, $b) {
         return $a . $b;
     };
     $concat = P::compose(['P', 'toArray'], P::zipWith($f));
     $concatOneTwo = P::zipWith($f, [1, 2]);
     $this->assertEquals(['1a', '2b'], P::toArray(P::zipWith($f, [1, 2], ['a', 'b'])));
     $this->assertEquals(['1a', '2b'], $concat([1, 2], ['a', 'b']));
     $this->assertEquals(['1a', '2b'], P::toArray($concatOneTwo(['a', 'b'])));
     $a = function () {
         (yield 'a');
         (yield 'b');
     };
     $this->assertEquals(['1a', '2b'], P::toArray(P::zipWith($f, [1, 2], $a())));
     $this->assertEquals(['1a', '2b'], $concat([1, 2], $a()));
 }
<div class="component--index">
	<h1>FFW Sitecore Prototype</h1>
	<h2>Prototype index</h2>
	<div class="pages">
		<h3>Website pages</h3>
		<ul>
			<li><a href="<?php 
echo P::url('home');
?>
" target="_blank">Front page</a></li>
		</ul>
		<h3>Development reference</h3>
		<ul>
			<li><a href="<?php 
echo P::url('components');
?>
" target="_blank">Components</a></li>
			<li><a href="<?php 
echo P::url('rich-text');
?>
" target="_blank">Rich text</a></li>
		</ul>
	</div>	
</div>