Skip to content

Small and lightweight MVC framework for PHP web apps. It provides a very flexible structure for your apps, without forcing you to abide to huge documentation, a specific file and naming structure, etc.

Notifications You must be signed in to change notification settings

matamouros/sentient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 

Repository files navigation

Sentient

Small and lightweight MVC framework for PHP web apps. It provides a very flexible structure for your apps, giving you some useful tools such as Obj-C style delegates, observers and automagic getters and setters, just to name a few. Unlike bigger and more complex frameworks, such as Zend's, Sentient goes out of its way to not bind you to pre-determined schemes of file and class naming and application structure.

Installation

To start using Sentient, place this repository inside a directory named Sentient inside, e.g., the lib directory of your app. You just then need to include Sentient's bootstrap file and you are ready to go:

include '../lib/sentient/bootstrap.php';

Some features

Object

  • Obj-C style automagic getters named after the properties, e.g., if there is a property named bar on the object foo, you can access it with $foo->bar().

    NOTE: currently private and protected properties can be called from outside!

  • Obj-C style automagic setter, e.g., $foo->setBar($bar). This automagic setter notifies all registered observers that this property has changed value (only if it actually changed!), using the Obj-C style willChangeValueForKey() method and didChangeValueForKey().

  • isBar() and hasBar() style automagic getters for each property, that always return a boolean.

  • emptyBar() style automagic getter, that checks if the bar attribute is empty.

  • Support for observers, for watching a specific property. These registered observers get notified whenever the property they are watching changes. Observer objects (which are also derived from the Object class) must implement observeValueForKeyPath(), which is what will be called by the observed object.

  • Obj-C style generic setValueForKey() and valueForKey() as setter and getter, besides the automagic ones.

  • Support for delegates. Delegates are an easy way to provide hooks on a class' behaviour. Object A executes action 'a' and, by design, fires a delegate method. If Object B is registered as delegate of Object A and implements the delegate method 'a', it will be called by A in runtime.

Config

  • JSON configuration files for your application.

  • Possibility of using ${VAR} variables in values, that will be expanded to the corresponding configuration key's value.

    NOTE: There is currently only one pass for expanding these placeholders, meaning that the complete JSON structure is first loaded as an array and then the variables will try to be resolved on one pass. Second and deeper levels of variable referencing might never be expanded.

  • Runtime loading of configuration, no configuration "compiling" time is necessary.

Routing

  • Simplified routing for simple applications, you just need to provide your own controller, which acts as a delegate. The only code you need is:

    $router = new Sentient\SimpleHttpRouter();
    $router->setDelegate(new MyHttpController());
    $router->init();
    $router->run();
    

    This simple routing will map the following URLs to methods on your controller:

    /foo         => foo()
    /foo-bar     => fooBar()
    /foo/bar     => foo_bar()
    /foo/foo-bar => foo_fooBar()
    
  • If you require more customisation for your routes and controllers, you have the option of using the advanced routing, which allows you to finely specify different combinations of controllers, methods and parameters for every route you register.

    The code required for this could be as easy as:

    $router = new Sentient\AdvancedHttpRouter();
    $router->addRoute("/^\\/project\\/(\\w*)\\/(\\w*)/", "ProjectHttpController", "->$1", "$2");
    $router->addRoute("/^\\/$/", "HomeHttpController", "->index");
    $router->init();
    $router->run();
    

    Note that you could also have the actual routes off-code in a JSON configuration file, that you would feed in a loop into addRoute().

Requirements

. array_replace_recursive() >= 5.3.0

About

Small and lightweight MVC framework for PHP web apps. It provides a very flexible structure for your apps, without forcing you to abide to huge documentation, a specific file and naming structure, etc.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages