-
-
Notifications
You must be signed in to change notification settings - Fork 2
Lambada Overloading Syntax
The class frdl\webfan\App supports the following construct by method overloading:
<?php
//...
frdl\webfan\App::God(true, "Demo of the extensible style functionallity 'Lambada crank'", 'frdl\webfan\Autoloading\SourceLoader', false)
//...
->{'$'}('MyMethodIdentifier', (function($arg){$a = func_get_args(); echo $a[0];}) )
-> {'MyMethodIdentifier'}('Hello world')
->{'$'}('-i!', array( new \webfan\Install(),'run'))
->{'-i!'}()
//...
'$' is a pre-defined shortcut , defined in the App constructor by the the method frdl\webfan\App->addShortCut(). The addShortCut method adds a callback to the overloading function mapping of the App class. It expects two parameters: The method fn and a callable. Callable could be e.g. a closure or a callable (array or string syntax). In the above example MyMethodIdentifier "is bound by" a closure while the use of the stupid method identifier -i! will call new \webfan\Install() -> run() .
Amazing, isn't it? It works, because we can use ->{'any?String'} curly brace to __call overloading methods while using invalid method identifiers. This enables php scripts to work with other or own syntax stylers.
Overloaded callables of frdl\webfan\App will return $this or self::God() to prepare for Lambada syntax style. The (at this point of development) most important class, the autoloader frdl\webfan\Autoloading\SourceLoader provides the method "j" returning \webfan\App::God(), where \webfan\App is an alias for \frdl\webfan\App. Each class of this shamework SHOULD provide the method "j". This method MUST return the singletone instance of \webfan\App.
Avoid rough-handling the overloading system, better refer to another classes callable than to extend the App class itself. Use the class aliasing mapping with care! It is meant to provide a little plugin mechanism:
- Alias names SHOULD be defined by the core and not implementation code!
- The plugged real existing class SHOULD implement an certain feature interface or extend a certain abstract or wrapping class.
\webfan\App::God returns the App classes singletone instance and remembers that God classes are considered as antipattern in most (or all?) cases. In our case God just refers to a method (getInstance), and the App class MUST NOT be used as a God class, but it SHOULD be the application wide accessible singletone class to access, refer to, map and use all the significant classes used during the application flow and make them accessible in any/every scope of the application. All in all it could be called a Plugin-Interface/Mapping-Manager/Reference-Connector, or something like that... .
Application Composer
Installation
API
Features
Package Installation
Application Building
Autoloading
Lamb@da Overloading Syntax
Aliasing
Components
Components…
Command line processor
Autoloader SourceLoader
Components Access Wrapper
Get Source Code
Get latest …
Get stable versions…