Ejemplo n.º 1
0
<?php

// def_alias - создаёт алиас для функции.
def('one', function () {
    echo 1;
});
def_alias('one', 'two');
one();
two();
?>
---
11
Ejemplo n.º 2
0
<?php

def_alias('bu::layout', 'l');
def_accessor('title');
def_accessor('keywords');
def_accessor('description');
def('show_404', function () {
    write_log("404", RAW_HTTP_STRING);
    header("Status: 404 Not Found");
    draw_page('Страница не найдена', view('404'));
});
def('draw_page', function ($title, $content) {
    title($title);
    echo dview('layout/default', $content);
});
Ejemplo n.º 3
0
        if (func_num_args()) {
            $arg = func_get_arg(0);
            if ($arg != $return) {
                $setter(!$arg);
            }
        }
        return $return;
    });
});
def('import_ns', function ($ns) {
    $fns = get_defined_functions();
    $fns = $fns['user'];
    foreach ($fns as $fn) {
        if (strstr($fn, $ns) !== false) {
            $fn_name = end(explode('\\', $fn));
            def_alias($fn, $fn_name);
        }
    }
});
def('import', function ($class_nm) {
    foreach ($class_nm::$fns as $name => $fn) {
        def($name, $fn);
    }
});
def('catcher', function ($nm, $fn) {
    Memo::$catchers[$nm] = $fn;
});
def('noise', function ($nm) {
    if (isset(Memo::$catchers[$nm])) {
        $args = func_get_args();
        array_shift($args);
Ejemplo n.º 4
0
<?php

function write_log($file, $txt)
{
    $f = fopen('log/' . $file, 'a+');
    fwrite($f, date('c') . " " . $txt . "\n");
    fclose($f);
}
def('path', function () {
    return implode('/', bu::path());
});
def_alias('bu::path', 'pth');
def_alias('bu::view', 'view');
def('dview', function ($pth, $data) {
    return view($pth, array('data' => $data));
});
def('map_dview', function ($tpl, $array, $separator = '') {
    return implode($separator, map(function ($v) use($tpl) {
        return dview($tpl, $v);
    }, $array));
});
def_sprintfer('cehr', '<div style="cehr"><center>-----------</center></div>');
Ejemplo n.º 5
0
<?php

// Проверяем что можно сделать алиас на функцию из другого нэймспэйса
def('foo\\bar\\baz\\hello', function () {
    echo "Hello!";
});
def_alias('foo\\bar\\baz\\hello', 'hello');
hello();
?>
---
Hello!
Ejemplo n.º 6
0
// Bark-bark!
undef('bark');
bark();
// Bark!
//////////////////////////////////////////////////
def('say_one', function () {
    puts("Me: one");
});
say_one();
// Me: one
def('say_two', function () {
    puts("Me: two");
});
say_two();
// Me: two
def_alias('say_one', 'say_two');
say_two();
// Me: one
////////////////////////////////////////
def_printfer('test_let', "calling outside let \n");
test_let();
// calling outside let
deflet(function () {
    def_printfer('test_let', "calling inside let \n");
    test_let();
    // calling inside let
});
test_let();
// calling outside let
////////////////////////////////////////
# using namespace
Ejemplo n.º 7
0
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: /{$pth}/" . implode('/', bu::args()));
}
function is_man_link($str)
{
    if (first(explode(' ', $str)) == 'man') {
        return true;
    }
}
function first($a)
{
    return reset($a);
}
def('last', function ($a) {
    return end($a);
});
def('but_last', function ($a) {
    $a = array_reverse($a);
    array_shift($a);
    return array_reverse($a);
});
def('w', function ($str) {
    return explode(' ', $str);
});
def_alias('array_map', 'map');
def('http_host', function () {
    return $_SERVER['HTTP_HOST'];
});
def('pp', function ($v) {
    echo '<pre>' . print_R($v, true) . '</pre>';
});