Phalcon || Aura

or

A comparison of a PHP framework built as an extension and a bunch of decoupled PHP libraries


Ian Littman

About Me

  • @iansltx
  • Cloudy Hills
  • APIs
  • PHP
  • DevOps (or something)

Apples || Oranges

  • Phalcon
    • Framework implemented as a PHP extension (IDE stubs)
      • Phalcon 1.x - written in C
      • Phalcon 2.x - written in Zephir
    • Templating, ORM, cache, etc.
    • Classes can be used piecemeal but you're loading the entire extension into RAM either way (500k)
  • Aura (v2)
    • Small, decoupled user-space (5.3+) libraries
    • Insane test coverage
    • Framework/Kernel available if you want them (5.4+)
  • Both are very flexible/suited to either small or large apps

Benchmark Conditions (TBA)

Getting nginx and hhvm working...

location ~ \.(hh|php)$ {
    root /usr/share/nginx/html/web;
    fastcgi_keep_conn on;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}
...or not...

\nFatal error: Argument 1 passed to Aura\\Web\\Request\\Accept\\Charset::__construct() must be an instance of Aura\\Web\\Request\\Accept\\Value\\ValueFactory, null given in /usr/share/nginx/html/vendor/aura/web/src/Request/Accept/Charset.php on line 75


Setup

  • Phalcon 
    • Compile, add to loaded extensions
    • Can work with Composer; doesn't need it
    • Site has install guides for various web servers
  • Aura
    • Fetch via Composer...or...
    • Use without Composer by requiring each lib's autoload.php

Phalcon - DI

  • Class names, objects, closures, array access (a la Pimple)
  • Altering parameters before instantiation
  • Contstructor, setter, property injection
  • Magic method resolution
  • setShared() for singletons, set() for instances
  • Auto-calls setDi() if available on service construction
  • Singleton option: Phalcon\DI::getDefault()
  • Internal libs use DI (we've overridden the Request service)
  • Interface available

Phalcon - MVC

  • Single-module
  • Multi-module
  • Microframework
  • Directory structure doesn't matter...
  • ...because we can autoload!
    • Register namespaces, classes, directories
    • Add non-php extensions
    • Events support (AOP FTW)

Phalcon - Routing + Dispatching

  • Route groups
  • Parameter transformation
  • Annotations
  • Short syntax 
$sessions->addGet('/{session_id:[a-f0-9]+}', 'Session::getSession');
NOTE: The above syntax will always use the router's default namespace. For alternate namespaces, you'll need to use the longer (standard routing) syntax.

Phalcon - Models

Phalcon - Views

  • Hierarchical views via Phalcon\Mvc\View (optional)
    • views/index.phtml
    • views/layouts/controller_name.phtml
    • views/controller_name/action_name.phtml
    • $this->getContent()
  • View helpers (tags for forms, images, etc.)
  • Asset inclusion + minification
  • Volt templating (probably {{ looks_familiar }} )
    • Compiles templates to PHP

Phalcon - More Goodies

Aura - Autoload + DI

  • Autoloader (333 sloc)
    • PSR-4 + some PSR-0 (slashes only; use v1 for full PSR-0)
    • Class-to-file
    • Prefixes
  • DI
    • Eager loading (new with params)
    • Lazy loading
    • Parameter inheritence
    • NOTE: Does not autodetect param types
    • Setter injection
    • Can pass DI container into services, but not preferred
  • Also of note: Includer (e.g. for configs)

Aura - Router + Dispatcher

Aura - SQL

  • Sql - Extended PDO
    • WHERE IN array binding support
    • fetch*() for column, all, etc., including query execution
    • Query profiler
  • SqlQuery - query builder
    • Returns a query object that can be fed into a prepared statement executor
    • MySQL, Postgres, MS-SQL, SQLite support
  • SqlSchema - object-oriented DESCRIBE
    • PDO-based
    • Supports the same databases SqlQuery does

Aura - Escaping + Views

  • Html (helpers + escaping)
    • Quick static escape methods
      • $h = $escaper->escape()->html;
      • $h($someString);
    • Tag and form helpers
    • HelperLocator for custom helpers
  • View
    • Partialx + selections (cached partials)
    • Integrates with helper manager
    • Two-step view (content rendered into layout)
  • Also of note: Filter (v1)

Aura - CLI + Web

  • CLI
    • Command line arguments with defaulting (positional or not)
    • Input/output streams
    • Exit codes
    • Formatter
  • Web
    • Request + Response objects
    • Request object does content-type negotiation!
    • Doesn't actually send anything; that's what this is for

Aura - putting it all together

Performance? Sample apps?

  • Coming soon! (got in fights with nginx and hhvm and lost)
  • Phalcon has sample apps
  • Built APIs on both (first was Phalcon, next two are Aura)
  • In both cases, you're trading time-to-first-page for customization, but not to the extent of, say, Symfony2
 

Q&A

Phalcon || Aura

By Ian Littman

Phalcon || Aura

  • 3,194
Loading comments...

More from Ian Littman