super() method of
Frame files, it is mostly preferred
to use them in other class method in which a shutter method is applied. Their flexible structure makes
it possible for methods or windows to inherit them. While shutters have been discussed earlier, here, we
will focus on how to apply middlewares to shutters. Middlewares can be applied through the ONCALL() method or
by passing the SELF::ONCALL constant key into a specific shutter list of accepted urls. It can also be applied
by setting a preload function on urls using the self::preload() method. When supplied,
these functions will execute before the method or class is resolved.
preload() method takes a list of direct urls as its first argument and a boot function as its second argument.
A syntax and an example is shown below: #sample stucture 1: self::preload($acceptableUrls, $boot) $acceptableUrls //an array list of valid urls $boot //a function that is called before a url is rendered
<?php
use Window;
class Docs extends Window {
function __construct() {
self::preload(
[
'docs/user/settings',
'docs/user/profiles',
],
function() {
echo "middleware applied";
}
);
}
}
docs/user/settings or
docs/user/profiles is visited, the text "middleware applied"
will be printed on the page before the content of the page itself is rendered.
CASTED::CALL(or CASTED::CAST) CASTED::ROOT CASTED::BASE CASTED::PATH CASTED::E404 #sample stucture 1: self::ONCALL($option, $urls) $option //casted options $urls acceptable urls and their respective boot options
The code structure below is an example of its usage:
<?php
use Window;
class Home extends Window{
function __construct() {
//set middlewares for direct paths
SELF::ONCALL(CASTED::CALL, [
'home/user/settings' => function() {
// run this for settings
},
'home/user/profiles' => function() {
// run this for profiles
}
]);
//set middlewares for base paths
SELF::ONCALL(CASTED::BASE, [
'home/user' => function() {
// run this for user
},
'home/room' => function() {
// run this for room
}
]);
//set valid direct paths
SELF::CALL($this, [
'home/user/settings' => 'root',
'home/user/profiles' => 'profiles',
], false);
//set valid base paths
SELF::BASECALL($this, [
'home/user' => 'user',
'home/room' => 'room',
]);
}
}
SELF::ONCALL(CASTED::CALL) method is used to set a preset (or preload) function on the list of urls it contains which
is only applied within the SELF::CALL() method.
SELF::ONCALL(CASTED::BASE) method is used to set a preset (or preload) function on the list of urls it contains which
is only applied within the SELF::BASECALL() method.
SELF::CALL() can resolve any of its urls, then the function for SELF::ONCALL(CASTED::CALL) will be called before
the url is rendered. However, if it cannot resolve its urls, then because it was pended, it will continue to SELF::BASECALL().
SELF::BASECALL() can resolve any of its urls, the SELF::ONCALL(CASTED::BASE) function will be called for the relative url. If basecall
cannot resolve its url also, then a 404 error page is returned.
According to the explanation made above, this means that CASTED::BASE, CASTED::CALL, CASTED::PATH and CASTED::ROOT will
respond similarly only to their respective or relative shutter methods. However, the CASTED::E404 defines that a middleware should only be applied when a 404 error occurs.
SELF::ONCALL key on the shutter itself.
SELF::ONCALL key is a preload method can be applied within any list of urls for any of the four shutter methods. We don't have to apply any casted option since we are within the shutter itself.
SELF::CALL($this, [
'home/user/profiles' => 'profiles',
'home/user/settings' => 'settings',
SELF::ONCALL => function() {
if( invoked('home/user/profiles') ) {
//do this if resolved
}
if( invoked('home/user/settings') ) {
//do this if resolved
}
}
])
SELF::ONCALL() method. The only difference is that here,
our function is more localized and will not extend to a subsequent call method. For example, if the SELF::CALL()
method above was pended, then another SELF::CALL() or any shutter method below it will not inherit the SELF::ONCALL constant key.
The invoked() function is a case sensitive function that helps to match the current page url with the supplied url. To declare function as insensitive,
the url supplied must be initialized with an exclamation mark "!".