PHP code example of divengine / ways

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




// Registering a closure
ways::listen("get://home", function($data){
    echo "Hello {$data['user']}";
}, "home");

// Adding a hook
ways::hook(DIV_WAYS_BEFORE_RUN, "home", function($data){
    $data['user'] = "Peter";
});

// Listening...
$data = ways::bootstrap('_url', 'home');



# Div PHP Ways 2.4.2



Ways is a class that adapts the concept of SOA to the architecture 
of a PHP application, and tries to integrate the parts of a hybrid 
system. 

With Ways you should think more about "control points" 
than on controllers of an MVC pattern. Control points are 
activated when they are needed, ie on demand, depending on 
the definition you have made.




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,
]);



Without composer, download the class and...



## Basic usage



## Call a static method

**app/control/Home.php**



**index.php**


**.htaccess**