1. Go to this page and download the library: Download divengine/ways library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
divengine / ways example snippets
ways::listen('sql://...', function($data, $args){
ways::listen('sql://query', function($data){
$pdo = new PDO();
$st = $pdo->prepare($data['query']);
$st->execute($data['params']);
$data['result'] = $st->fetchAll(PDO::FETCH_OBJ);
return $data;
});
});
ways::invoke('sql://query', [
'query' => 'SELECT * FROM cats WHERE name = ?',
'params' => ['Tom']
]);
ways::rule('is-monday', function(){
return date('D') === 'Mon';
});
ways::listen('*', function (){
echo 'Today is Monday !!!';
}, [ways::PROPERTY_RULES => ['is-monday']]);
// arbitrary location for software's packages
define('PACKAGES', 'path/to/app/');
use divengine\ways;
// ways with closure
ways::listen("get://home", function($data){
echo "Hello {$data['user']}";
}, "home");
// add a hook
ways::hook(DIV_WAYS_BEFORE_RUN, "home", function($data){
$data['user'] = "Peter";
});
// listen...
$data = ways::bootstrap('_url', 'home');
#id = home
#listen = /home
class Home {
static function Run()
{
echo "Hello world";
}
static function About()
{
echo "About us";
}
#listen@Contact = get://about
static function Contact()
{
echo "Contact us";
}
}
// register a controller with the default static method ::Run()
ways::register("app/control/Home.php");
// route to another static method ([controllerID]@[method])
ways::listen("/about", "home@About");
// route to closure
ways::listen("/sayMeHello/{name}", function($data, $args) {
echo "Hello {$args['name']}";
});
// hook on the fly
ways::hook(DIV_WAYS_BEFORE_RUN,
ways::listen("/tests/...", function(){
ways::listen("/tests/1", function(){
echo "This is the test 1";
});
ways::listen("/tests/2", function(){
echo "This is the test 2";
});
if (ways::match("/tests/3")) {
echo "This is the test 3";
}
ways::bootstrap();
}),
function(){
if (!isset($_SESSION['user']))
{
echo "You are not a tester";
return false;
}
return true;
});
// route to a static method
ways::bootstrap("_url", "home");
// say me hello
// $ php one_script.php hello Peter
ways::listen("/hello/{name}", function ($data = [], $args = []) {
echo "Hello {$args['name']}\n";
});
$property = "This is a property value";
ways::listen("/", function ($data = [], $args = [], $properties = []) {
echo "Controller ID = " . $properties['id'] . "\n";
echo "A controller property = " . $properties['myProperty'];
}, [
'myProperty' => $property,
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.