alloy hmvc php framework

Download Alloy HMVC PHP Framework

Post on 13-Apr-2017

13.551 views

Category:

Technology

1 download

Embed Size (px)

TRANSCRIPT

  • Alloy FrameworkPHP 5.3+ Modular Hierarchical MVC

    http://alloyframework.org

    Wednesday, March 30, 2011

    http://alloyframework.orghttp://alloyframework.org

  • Vance Lucas (@vlucas) http://alloyframework.org

    Who am I?Vance Lucas

    http://vancelucas.com

    @vlucas

    Business: http://actridge.com

    PHP dev since 1999 (PHP 3)

    I love good OOP code and concepts, but hate the complexity it brings

    2

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.ithttp://vancelucas.comhttp://vancelucas.comhttp://actridge.comhttp://actridge.com

  • A Few Points...Kind of a disclaimer, but not really

    Wednesday, March 30, 2011

  • Vance Lucas (@vlucas) http://alloyframework.org

    You May NOT Like Alloy If...You are an Object-Oriented Programming Purist

    You dont care how complex code is as long as its correct OOP (because some guys book said so)

    You LOVE using Zend Framework, Symfony, or FLOW3

    You LOVE XML and Dependency Injection Containers

    You are looking for a component library

    4

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    You MIGHT Like Alloy If...You think frameworks like Zend, Symfony, or FLOW3 make some things too difficult and cumbersome

    You dont think any PHP framework has it quite right

    You dont like too much magic

    You want to know what your framework is doing

    You value ease of use over everything else

    You want good OOP code that follows known coding standards that is still easy to use and understand

    5

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    PhilosophyUsefulness, Simplicity and Strong Design

    Minimum code, maximum impact

    Use OOP principles and design, but dont over-do it

    PHP is not Java with dollar signs

    Explicitness > Magic

    Easier to understand & see what is going on

    Design patterns should never trump user experience or get in the way

    Users over correctness6

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Alloy Framework GoalsLightweight

    Modular Organization

    Hierarchical MVC (HMVC)

    Easy to understand and use

    Easy to make REST APIs and HTML pages

    No config/setup necessary, works anywhere

    Follow PEAR/Zend Coding Standards

    Strike a balance between good OOP concepts and ease of use with low learning curve

    7

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Alloy ArchitectureInside & Out

    Wednesday, March 30, 2011

  • Vance Lucas (@vlucas) http://alloyframework.org

    Alloy Architecture OverviewModular Organization

    Kernel

    Plugins

    Hierarchical MVC (HMVC)

    Controllers as Resources

    Events and Filters

    9

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Modular OrganizationAll related files in a single top-level named folder

    No separate controllers, models and views directories at same level

    Unlimited levels of nesting

    Easier distributable packages

    10

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Kernel

    Core object available from anywhere in your app

    \Kernel() - only global-scope function in Alloy

    Multiple uses:

    Config access

    Lazy-loading Factory / Service Locator

    Extension Point for Modules and Plugins

    Sole Dependency

    11

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Kernel - Config AccessGetter

    Setter

    12

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Kernel - Lazy-Load FactoryWrite This:

    Not That:

    Or This:

    13

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Kernel - Extension Point

    Proxies to callbacks added at runtime via __call

    Enables all kinds of custom functionality

    Factory methods for loading & using 3rd party libs

    Exposing plugin methods for global use

    Helper or utility methods

    14

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • PluginsThe primary way of extending Alloy

    Wednesday, March 30, 2011

  • Vance Lucas (@vlucas) http://alloyframework.org

    Plugin - Symfony2 FinderFile: app/Plugin/Finder/Plugin.php

    Libs: app/Plugin/Finder/lib/Symfony/Component/ ...

    Add finder method to Kernel for use

    16

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Plugin - Add to ConfigFile: app/config/app.php

    17

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Plugin - UsageUse finder method on Kernel instance

    18

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Hierarchical MVCSolves the widget problem

    Wednesday, March 30, 2011

  • Vance Lucas (@vlucas) http://alloyframework.org

    Hierarchical MVCMultiple MVC dispatches to fulfill a single request

    Solves the widget problem

    Sidebar content can be self-contained module

    Ads, tag clouds, blog headlines, etc.

    Encourages module re-use & helps DRY

    Not strictly hierarchical - more like nested

    Hierarchy is not tracked or enforced in any way

    20

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org 21Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org 22Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • ControllersRespond to both internal and external requests

    Wednesday, March 30, 2011

  • Vance Lucas (@vlucas) http://alloyframework.org

    ControllersPart of the Module package that handles requests

    Special name scope for web-accessible actions

    GET = Action

    POST, PUT, DELETE, etc = Method

    Ensures HTTP methods are required for access

    Alloy\Request object is first parameter

    All named params from route set on Request object

    24

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Controllers (contd)NOTHING is automatically or implicitly loaded

    No views, models, or anything else

    Explicitly return response or content to send

    Controllers are not factories

    Controllers are extremely lightweight

    Controllers do not hold the context of their requests

    25

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Example REST ControllerNotice Action vs Method

    26

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Controller Response TypesSending output and manipulating control flow

    Wednesday, March 30, 2011

  • Vance Lucas (@vlucas) http://alloyframework.org

    Simple StringsSends 200 OK status with string content as body

    28

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Any object with __toStringSends 200 OK status with string content as body

    29

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    View TemplatesMost common Module response type

    Returns object - template not yet rendered

    30

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Resource ObjectsAuto-converts array to JSON or XML for API response

    Accepts objects with toArray methods

    31

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Generic ResponseBody + HTTP Status

    Base Alloy\Module\Response that view templates and resources extend from

    Can set custom layout, errors, headers, etc. using a fluent interface just like templates and resources

    32

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Vance Lucas (@vlucas) http://alloyframework.org

    Boolean FalseGeneric 404 (Throws Alloy\Exception\FileNotFound)

    Plugins can filter on dispatch_exception event to produce a custom global response

    33

    Wednesday, March 30, 2011

    http://brightb.ithttp://brightb.it

  • Why Explicit Returns?Easier to manipulate responses and control flow

    Wednesday, March 30, 2011