示例#1
0
文件: db.php 项目: hazardland/db
 function get($scope, &$table, $query)
 {
     $path = 'database|' . scope($scope) . $table->hash();
     if (is_object($query)) {
         return $this->fetch($path . '|query|' . $query->hash($table));
     }
     return $this->fetch($path . '|entry|' . $query);
 }
示例#2
0
<?php

include '../../src/dispatch.php';
before(function () {
    echo "before()<br>";
});
before(function () {
    echo "before() again<br>";
});
after(function () {
    echo "after()<br>";
});
after(function () {
    echo "after() again<br>";
});
filter('name', function ($name) {
    scope('greeting', "Hello there, {$name}!<br>");
});
filter('name', function ($name) {
    scope('farewell', "Bye bye, {$name}!<br>");
});
on('GET', '/greet/:name', function ($name) {
    echo scope('greeting');
    echo scope('farewell');
});
dispatch();
示例#3
0
<?php

global $x;
//$x=123;
//$y=10;
function scope()
{
    //access the variable x inside the function, declared global
    global $x;
    //local variable
    $x = 90;
    echo "value of x inside is", $x, "<br>";
}
function sample()
{
    static $x = 0;
    $x = 0;
    $x = $x + 1;
    echo "value of x inside sample is", $x, "<br>";
}
scope();
sample();
sample();
sample();
echo "value of x outside is", $x;
示例#4
0
 /**
  * Merges data with the global scope, used by Views.
  *
  * @param $data
  */
 function share($data)
 {
     static $gs;
     $gs = $gs ?: scope();
     $gs->merge($data);
 }
<html>
	<head>
	
	</head>
	
	<body>
	    
		
		<?php 
//<?php echo ""
echo " <h1> &nbsp Hello FTFLs !! </h1>";
echo " <h1> echo is case insensative </h1>";
echo " <h1> echo is case insensative </h1>";
$x = 100;
$y = 90;
scope($x, $y);
$x = $x + 100;
function scope($x, $y)
{
    $x = $x + 1;
    echo "<h2>My variables in function  {$x},{$y}  <br></h2>";
}
echo "<h2>My variables in function  {$x},{$y}  <br></h2>";
?>
	
	
	
	</body>


示例#6
0
scope(function () {
    // Filter: If the user is logged in, allow the request. Otherwise, display an HTTP 403 Unauthorized Error.
    $apiFilter = function (Request $request) {
        if ($request->session->auth->loggedIn) {
            return true;
            // Require user authentication.
        }
        return 401;
        // HTTP 401 Unauthorized
    };
    // Filter: If the user is logged in, allow the request. Otherwise, redirect them to the login page.
    $authFilter = function (Request $request) {
        if ($request->session->auth->loggedIn) {
            return true;
            // Require user authentication.
        }
        return Redirect::to('/login');
    };
    // Route: Authentication System
    Route::get('/login', 'CASController@login');
    Route::post('/login', 'CASController@loginAction');
    Route::get('/logout', 'CASController@logout');
    // Route: Access Restricted Pages
    //Route::filter($authFilter, function() {
    Route::get('/', function (Request $request, Response $response) {
        // For local development builds: use the Google Closure Development bundle.
        if (Config::get('app.development', false) && !$request->get->has('prod')) {
            return View::make('SchedulePlannerDevelopment');
        } else {
            return View::make('SchedulePlanner');
        }
    });
    //});
    // Route: API Access Restricted Pages
    Route::filter($apiFilter, function () {
        Route::get('/api/user', 'API.UserController');
        Route::post('/api/user', 'API.UserController');
    });
    Route::get('/api/courses', 'API.CoursesController');
});
示例#7
0
test('site()', function () {
    config('dispatch.url', 'http://localhost:8888/mysite/');
    assert(site() === 'http://localhost:8888/mysite/');
    assert(site(true) === '/mysite');
});
test('url()', function () {
    $s = 'name=noodlehaus&project=dispatch';
    assert(url($s) === urlencode($s));
});
test('html()', function () {
    assert(html('&') === '&amp;');
});
test('scope()', function () {
    scope('one', 1);
    call_user_func(function () {
        assert(scope('one') === 1);
    });
});
/*--------------
 * remote tests
 */
test('before()', function () {
    $res = curly('GET', URL . '/index?name=dispatch');
    assert(preg_match('/BEFORE METHOD: GET/', $res));
    assert(preg_match('/BEFORE PATH: index/', $res));
});
test('after()', function () {
    $res = curly('GET', URL . '/index?name=dispatch');
    assert(preg_match('/AFTER METHOD: GET/', $res));
    assert(preg_match('/AFTER PATH: index/', $res));
});
示例#8
0
<html>
    <head>
        <title>Global Variables</title>
    </head>
        
    <body>
        <?php 
$var = "Toi o ngoai funciton";
function scope($var)
{
    global $var;
    $var = "Toi nam o trong function";
    return $var;
}
echo scope($var) . '<br/>';
// In ra bien da dat
echo $var;
?>
        
    </body>
</html>
示例#9
0
/**
 * Convenience function for storing/fetching content to be
 * plugged into the layout within render().
 *
 * @param string $value optional, value to use as content.
 *
 * @return string content
 */
function content($value = null)
{
    return scope('$content$', $value);
}
示例#10
0
<?php

include '../../src/dispatch.php';
before(function () {
    scope('object', ['name' => 'Dispatch', 'type' => 'Framework']);
});
on('GET', '/json', function () {
    json_out(scope('object'));
});
on('GET', '/jsonp', function () {
    json_out(scope('object'), 'callback');
});
dispatch();