Exemplo n.º 1
0
Arquivo: FnSpec.php Projeto: syhol/fn
 function it_should_pipe()
 {
     $pipe = $this->pipe(fn(function ($a) {
         return $a . 'boz';
     }));
     $pipe->shouldHaveType(Fn::class);
     $pipe->__invoke('qux:')->shouldReturn('foo:qux:boz');
 }
Exemplo n.º 2
0
<?php

fn('site.header');
?>

<?php 
echo $page['content'];
?>

<ul id="lightSlider">

	<?php 
$medias = fn::get_medias($page['id']);
foreach ($medias as $media) {
    ?>
			<li data-thumb="<?php 
    echo $media['url'];
    ?>
"><img src="<?php 
    echo $media['url'];
    ?>
" alt="<?php 
    echo $media['lookup_title'];
    ?>
" /><?php 
    echo $media['lookup_data'];
    ?>
</li>
	<?php 
}
?>
Exemplo n.º 3
0
<?php

function fn(...$args)
{
    var_dump(count($args));
}
$array = array_fill(0, 10000, 42);
fn(...$array, ...$array);
Exemplo n.º 4
0
    {
    }
    private static $hacklib_values = array('Fly' => "15", 'Blue' => 12, 'Red' => 15, 'Green' => "green");
    use \HH\HACKLIB_ENUM_LIKE;
    const Fly = "15";
    const Blue = 12;
    const Red = 15;
    const Green = "green";
}
echo "ImmVector: ";
var_dump(E2::assertAll(new \HH\ImmVector(array(15, "15", "12", 12, "green"))));
echo "array: ";
var_dump(E2::assertAll(array(15, "15", "12", 12, "green")));
echo "Map: ";
var_dump(E2::assertAll(\HH\Map::hacklib_new(array(12, "1", 1, "grey", 3), array(15, "15", "12", 12, "green"))));
function fn()
{
    $a = array(15, "15", "12", 12, "green");
    foreach ($a as $v) {
        (yield $v);
    }
}
$g = fn();
echo "Generator: ";
var_dump(E2::assertAll($g));
try {
    E2::assertAll(array(15, "true", 12));
} catch (\UnexpectedValueException $e) {
    echo $e->getMessage() . "\n";
}
var_dump(E2::assertAll("15"));
Exemplo n.º 5
0
?>
" />
		<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700|Bitter:400italic' rel='stylesheet' type='text/css'>
		<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
		<!--[if lte IE 8]>
			<link rel="stylesheet" href="http://yui.yahooapis.com/combo?pure/0.6.0/base-min.css&pure/0.6.0/grids-min.css&pure/0.6.0/grids-responsive-old-ie-min.css">
		<![endif]-->
		<!--[if gt IE 8]><!-->
			<link rel="stylesheet" href="http://yui.yahooapis.com/combo?pure/0.6.0/base-min.css&pure/0.6.0/grids-min.css&pure/0.6.0/grids-responsive-min.css">
		<!--<![endif]-->
		<!--[if lt IE 9]>
		<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
		<![endif]-->
		<script>document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';</script>
		<?php 
foreach (fn('page.styles') as $__inc) {
    ?>
		<link rel="stylesheet" href="<?php 
    echo $__inc;
    ?>
" media="screen" type="text/css" />
		<?php 
}
?>
		<?php 
echo fn::get_header();
?>
	</head>

<body class="<?php 
echo $page['title'];
Exemplo n.º 6
0
 * User: zzy
 * Date: 2015/11/29
 * Time: 17:50
 */
echo 'This is the main file.<br/>';
require 'reusable.php';
echo 'The script will end now.<br/>';
//phpinfo();
function fn()
{
    //echo "inside the function, \$var = ".$var."<br/>";
    $var = "contents 2";
    echo "inside the function, \$var = " . $var . "<br/>";
}
$var = "contents 1";
fn();
echo "outside the function, \$var = " . $var . "<br/>";
function fn2()
{
    global $var;
    $var = "contents";
    echo "inside the function, \$var = " . $var . "<br/>";
}
fn2();
echo "outside the function, \$var = " . $var . "<br/>";
/*未改变原变量的引用*/
function increment1($value, $amount = 1)
{
    $value = $value + $amount;
}
echo "without '&': <br/>";
Exemplo n.º 7
0
}
if ($page3) {
    $page = $page3;
} elseif ($page2) {
    $page = $page2;
} else {
    $page = $page1;
}
if ($page && empty($page['template'])) {
    $page['template'] = 'page.php';
}
if (empty($page['meta_title'])) {
    $page['meta_title'] = $page['title'];
}
$base = int . ext . templates;
$real = $base . $page['url'] . '.php';
$temp = $base . $page['template'] . '.php';
$fourohfour = $base . '404.php';
fn('page.meta_title', $page['meta_title']);
fn('page.meta_description', $page['meta_description']);
fn('page.meta_keywords', $page['meta_keywords']);
if (file_exists($real) && !is_dir($real)) {
    require_once $real;
} elseif (file_exists($temp) && !is_dir($temp)) {
    require_once $temp;
} else {
    require_once $fourohfour;
}
fn('site.header');
fn('site.footer');
Exemplo n.º 8
0
/**
 * 1. Function-constructor
 */
$constructor = fn(function () {
    $this->property = 1;
    $this->getProperty = function () {
        return $this->property;
    };
});
$instance = $constructor();
echo $instance->getProperty();
// 1
/**
 * 2. Different objects
 */
$instance2 = $constructor();
assert($instance !== $instance2);
$instance2->property = 2;
echo $instance->getProperty();
// 1
echo $instance2->getProperty();
// 2
/**
 * 3. Prototype
 */
$constructor->prototype = fn(['getDouble' => function () {
    return $this->getProperty() * 2;
}]);
$doubleInstance = $constructor();
echo $doubleInstance->getDouble();
// 2
Exemplo n.º 9
0
function is_scalar()
{
    return fn('is_scalar', func_get_args());
}
Exemplo n.º 10
0
function gen()
{
    fn();
    yield;
}
Exemplo n.º 11
0
            }
            fn::data('page.styles', $styles);
            return $styles;
            break;
        case 'site.header':
            require_once int . ext . templates . template . '/header.php';
            return;
            break;
        case 'site.footer':
            require_once int . ext . templates . template . '/footer.php';
            return;
            break;
    }
    $ps = explode('.', $method);
    $newopts = $opts[0];
    return fn::call_object($ps[0], $ps[1], $opts);
}
fn('add', 'db', new mysql(db_host, db_db, db_user, db_pass));
if (!fn('db.connected')) {
    fn::error('Could not connect to database.');
}
//fn('page.styles', ext.'js/lib/lightslider/css/lightslider.min.css');
fn('page.styles', ext . 'css/styles.css');
//fn('page.styles', 'http://yui.yahooapis.com/pure/0.6.0/pure-min.css');
//fn('page.styles', 'http://yui.yahooapis.com/pure/0.6.0/grids-responsive-min.css');
fn('page.scripts', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js');
//fn('page.scripts', ext.'js/lib/lightslider/js/lightslider.min.js');
fn('page.scripts', ext . lib . 'fn.js');
fn('page.scripts', ext . 'js/main.min.js');
//fn('page.scripts', ext.'js/lib/jquery.innerfade.js');
fn::sitemap();
Exemplo n.º 12
0
//    },
//    function($a, $b, $c) {
//        return '$a, $b and $c! wow, thats too much?';
//    }
//);
//
//$poly(1); // $a is great but only a?
//$poly(1, 2); // Perfect, thats $a $b
//$poly(1, 2 ,3); // $a, $b and $c! wow, thats too much?
// $f->parse(function(){
//
// }, function(){
//
// });
// $f(function(){
//
// })->parse(function(){
//
// });
// $func = $f(function(){
//
// });
// $func->parse(function(){
//
// });
// Invoking the facade and others
//Fn::parse(function(){});
fn(function () {
});
FnFactory::parse(function () {
});
Exemplo n.º 13
0
// Пример:
// 1 3 3 7 9 9 9 9 11 11 12 14
// Изход:
// Най-дългата площадка е: 4 елемента
// Брой на площадките: 3
$arr = [5, 5, 5, 1, 1, 1, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 1, 3, 3, 2, 2];
function fn($arr)
{
    $count = 0;
    $maxCount = 1;
    $numb;
    $len = count($arr);
    $set = 0;
    for ($i = 0; $i < $len - 1; $i++) {
        $count++;
        if ($arr[$i] != $arr[$i + 1]) {
            if ($count > 1) {
                $set++;
            }
            if ($count > $maxCount) {
                $maxCount = $count;
                $numb = $arr[$i];
            }
            $count = 0;
        }
    }
    echo "Най-дългата площадка е: {$maxCount} елемента", PHP_EOL;
    echo "Брой на площадките: {$set}", PHP_EOL;
}
fn($arr);
Exemplo n.º 14
0
 public static function getDataFormulaContract($qltyFormulas, $contractId, $year)
 {
     $aryMstCalcu = array();
     $aryValue = array();
     $x = array();
     $contractIdGlobal = $contractId;
     $yearGlobal = $year;
     foreach ($qltyFormulas as $key => $row) {
         if ($row->LEVEL == 0) {
             $str = str_replace('contract_attr(', '', $row->FORMULA);
             $str = str_replace(')', '', $str);
             $str = $row->ID . "," . $str;
             $str = "{$str},,{$contractId},{$year}";
             $aryMstCalcu['fn' . $row->FORMULA_NO] = call_user_func_array("contract_attr", explode(',', $str));
             $aryValue[$row->ID] = (int) $aryMstCalcu['fn' . $row->FORMULA_NO];
         } else {
             $x[$row->ID] = $row->FORMULA;
         }
     }
     /* while ( $row = mysql_fetch_array ( $result ) ) {
     			if ($row ['LEVEL'] == 0) {
     				$str = str_replace ( 'contract_attr(', '', $row ['FORMULA'] );
     				$str = str_replace ( ')', '', $str );
     				$str = $row ['ID'] . "," . $str;
     	
     				$aryMstCalcu ['fn' . $row ['FORMULA_NO']] = call_user_func_array ( "contract_attr", explode ( ',', $str ) );
     				$aryValue [$row ['ID']] = ( int ) $aryMstCalcu ['fn' . $row ['FORMULA_NO']];
     			} else {
     	
     				$x [$row ['ID']] = $row ['FORMULA'];
     			}
     		} */
     fn(1, $aryMstCalcu);
     set_error_handler("evalErrorHandler");
     foreach ($x as $kk => $vv) {
         $vvoutput = preg_replace("/fn\\(([a-z][0-9])\\)/", "fn('\$1')", $vv);
         try {
             eval('$aryValue[$kk] = (' . $vvoutput . ');');
         } catch (Exception $e) {
             \Log::info("Exception with eval {$s} " . $e->getMessage());
             $aryValue[$kk] = 0;
         }
     }
     restore_error_handler();
     return $aryValue;
 }
Exemplo n.º 15
0
<?php

function fn($reqParam, $optParam = null, ...$params)
{
    var_dump($reqParam, $optParam, $params);
}
fn(1);
fn(1, 2);
fn(1, 2, 3);
fn(1, 2, 3, 4);
fn(1, 2, 3, 4, 5);
Exemplo n.º 16
0
		<p>Telephone: <span class="lg">01904 470256</span></p>
		<p class="copyright">&copy; <?php 
echo site_title;
?>
 <?php 
echo date("Y");
?>
 &nbsp;<br/>
			&nbsp; Website by <a href="http://www.bowhouse.co.uk">www.bowhouse.co.uk</a></p>
	</footer>

</div> <!-- /container -->

<?php 
echo fn::get_footer();
?>

<?php 
foreach (fn('page.scripts') as $__inc) {
    ?>
<script src="<?php 
    echo $__inc;
    ?>
"></script>
<?php 
}
?>

</body>
</html>
Exemplo n.º 17
0
 function fmcmd($r, $g, $b, $imgin, $imgout)
 {
     return st() . $imgin . " " . ch("R", $r) . ch("G", $g) . ch("B", $b) . fn() . $imgout;
 }
Exemplo n.º 18
0
    return $ret;
}
${'@at'}->fn('on', fn('_on', array(FALSE, fn::ph(), fn::ph())));
${'@at'}->fn('on!', fn('_on', array(TRUE, fn::ph(), fn::ph())));
function _on($not, $cond, $block)
{
    if ($not === empty($GLOBALS['@' . trim($cond)])) {
        return $GLOBALS['@at']->run($block);
    }
}
// filters
${'@filter:texy'} = fn(array(new Texy(), 'process'), array(fn::ph()));
${'@filter:escape'} = fn('htmlspecialchars', array(fn::ph(), ENT_QUOTES));
${'@filter:date'} = fn('date', array('j. n. Y, H:i:s', fn::ph()));
${'@filter:mailize'} = fn('_mailize', array(fn::ph(), FALSE));
${'@filter:mailto'} = fn('_mailize', array(fn::ph(), TRUE));
function _mailize($email, $mailto = FALSE)
{
    $ret = '';
    if ($mailto) {
        $email = 'mailto:' . $email;
    }
    for ($i = 0, $len = strlen($email); $i < $len; ++$i) {
        $ord = ord($email[$i]);
        if ($ord <= 0x7f && $ord !== 64 && $ord !== 46 && $i % 15 !== 0) {
            $ret .= chr($ord);
            continue;
        }
        if (!$mailto && $i & 1) {
            $ret .= '<!---->';
        }