SlideShare ist ein Scribd-Unternehmen logo
1 von 63
Aura Project for PHP 5.4


Hari K T
Bridge Global IT Staffing
http://harikt.com
http://auraphp.github.com
Brought to you by @pmjones
         Paul M Jones
Aura?
Independent library packages for PHP 5.4
Second major version of Solar PHP
Packages can be used alone, in concert with
 each other, or combined into a full-stack
 framework of their own.
Groups : http://groups.google.com/group/auraphp
Source Code : https://github.com/auraphp
API & Docs : http://auraphp.github.com/Aura.<Package>
IRC #auraphp on freenode
Current Components / Library
Aura.Autoload
Aura.Cli
Aura.Di
Aura.Http
Aura.Marshal
Aura.Router
Aura.Signal
Aura.Sql
Aura.View
Aura.Web
Aura.Autoload

PSR-0 compliant SPL autoloader
Matches the interface proposed at
 https://wiki.php.net/rfc/splclassloader
Read more information on PSR-0 Autoload
http://bit.ly/yzJ8r6 from phpmaster.com
Vendor.Package Structure
├── config ( default.php , test.php )
├── meta ( authors.csv, changes.txt, description.txt )
├── scripts ( instance.php )
├── src
│ └── Aura
│    └── Autoload
│       ├── Exception
│       ├── Exception.php
│       └── Loader.php ( namespace AuraAutoload )
├── src.php
├── tests
Instantiate
Create an instance of the Loader and register it
 with SPL.


$loader = require '/path/to/Aura.Autoload/scripts/
  instance.php';
$loader->register();
Class Prefix Usage
// look for all Vendor_* classes in this path:
$loader->add('Vendor_', '/path/to/lib');
// look for VendorPackage classes in this path:
$loader->add('VendorPackage',
  '/path/to/Vendor.Package/src');
// additionally, e.g. in testing modes, also look for
   VendorPackage
// classes in this path as well:
$loader->add('VendorPackage',
  '/path/to/Vendor.Package/tests');
All in one
$loader->setPaths([
      'AuraRouter' => '/path/Aura.Router/src/',
      'AuraDi'   => '/path/Aura.Di/src/',
]);
$loader->setClasses([
      'VendorPackageFoo' => '/path/to/Vendor/Package/Foo.php',
      'VendorPackageZim' => '/path/to/Vendor/Package/Zim.php',
]);
Aura.Router
Aura.Router
Aura Router is a PHP package that implements
 web routing
Given a URI path and a copy of $_SERVER, it
 will extract controller, action, and parameter
 values for a specific application route.
Inspired by Solar rewrite rules and
  http://routes.groovie.org
Add Routes
$map = require '/path/to/Aura.Router/scripts/instance.php';
$map->add('home', '/', [
      'values' => ['controller' => 'hello', 'action' => 'world',],
]);
$map->add('read', '/blog/read/{:id}{:format}', [
      'params' => [
           'id'   => '(d+)',
           'format' => '(..+)?',
      ],
      'values' => [
           'controller' => 'blog', 'action'   => 'read', 'format'    => '.html',
      ],
));
Matching a Route
// get the incoming request URI path
$path = parse_url($_SERVER['REQUEST_URI'],
  PHP_URL_PATH);


// get the route based on the path and server
$route = $map->match($path, $_SERVER);
if (! $route) {

    echo "No application route was found for that URI path."; exit();
}

// does the route indicate a controller?
if (isset($route->values['controller'])) {
    $controller = $route->values['controller']; // take the controller class directly from the route

} else {
    $controller = 'Default';   // use a default controller

}
if (isset($route->values['action'])) { // does the route indicate an action?

    $action = $route->values['action']; // take the action method directly from the route
} else {

    $action = 'index'; // use a default action
}

$page = new $controller(); // instantiate the controller class
echo $page->$action($route->values); // invoke the action method with the route values
Generating A Route Path
// $path => "/blog/read/42.atom"
$path = $map->generate('read', [
      'id' => 42,
      'format' => '.atom',
]);
$href = htmlspecialchars($path, 'UTF-8');
echo '<a href="$href">Atom feed for this blog entry</a>';
Aura.Web
http://auraphp.github.com/Aura.Web/

https://github.com/auraphp/Aura.Web/
Aura.Web
The Aura Web package provides tools to build web page
  controllers
includes an AbstractPage for action methods
a Context class for disovering the request environment
Response transfer object that describes the eventual HTTP
  response
Creating Page controller
namespace VendorPackageWeb;
use AuraWebAbstractPage;
class Page extends AbstractPage
{
    protected function actionHello($noun = null)
    {
        $noun = htmlspecialchars($noun, ENT_QUOTES, 'UTF-8');
        $content = "Hello, {$noun}!";
        $this->response->setContent($content);
    }
}
The Execution Cycle
namespace VendorPackageWeb;
use VendorPackageWebPage;
use AuraWebContext;
use AuraWebResponse;
$params = [
     'action' => 'hello',
     'format' => '.html',
];
$page = new Page(new Context, new Response, $params);
$response = $page->exec();
Internally, the exec() cycle runs
A preExec() hook to let you set up the object,
A preAction() hook to prepare for the action,
The action() method to invoke the method determined by the 'action' param
  value
A postAction() hook,
A preRender() hook to prepare for rendering,
The render() method to render a presentation (this is up to the developer to
  create),
A postRender() hook, and
A postExec() hook.
At the end returns a Response transfer object. Response object is not an
   HTTP response proper;
it is a data transfer object that has information on how to build an HTTP
     response.
The Context Object
$this->context->
getQuery(): gets a $_GET value
getPost(): gets a $_POST value
getFiles(): gets a $_FILES value
getInput(): gets the raw php://input value
getJsonInput(): gets the raw php://input value and
  json_decode() it
getAccept(): gets the Accept headers, ordered by weight
isGet(), isPut(), isXhr(), etc.: Tells if the request method
  was GET, PUT, an Xml-HTTP-Request, etc.
Rendering
render() method is empty by default.
this allows you to add in whatever presentation
  logic you want, from simply json_encode()-ing
  $this->data, to using a complex two-step or
  transform view.
Aura.View
Aura.View
https://github.com/auraphp/Aura.View

 http://auraphp.github.com/Aura.View
Aura.View
Template View pattern
preceded by systems such as Savant,
  Zend_View, and Solar_View
Auto escaping [escaper branch] a work in
 progress
Instantiation
$template = require
  '/path/to/Aura.View/scripts/instance.php';
     OR
use AuraViewTemplate;
use AuraViewTemplateFinder;
use AuraViewHelperLocator;
$template = new Template(new
  TemplateFinder, new HelperLocator);
echo $template->fetch('/path/to/tpl.php');
Adding Data
$template->addData([
      'foo' => 'Value of foo',
      'bar' => 'Value of bar',
]);
// this will remove $var, $foo, and $bar from the template
$template->setData([
      'baz' => 'Value of baz',
      'dib' => 'Value of dib',
]);
Template Composition
<?php $e = $this->getHelper('escape');      // template script ?>
<html>
<head>
  <?php include $this->find('head'); ?>
</head>
<body>
  <?php include $this->find('branding'); // branding.php ?>
  <?php include $this->find('navigation'); ?>
  <p>Hello, <?php echo $e($this->var); ?>!</p>
  <?php include $this->find('footer'); ?>
</body>
</html>
Template Finder
$finder = $template->getTemplateFinder();


// set the paths where templates can be found
$finder->setPaths([
      '/path/to/templates/foo',
      '/path/to/templates/bar',
      '/path/to/templates/baz',
]);
Writing Helpers
namespace VendorPackageViewHelper;
use AuraViewHelperAbstractHelper;


class Obfuscate extends AbstractHelper
{
    public function __invoke($string)
    {
        return $this->escape(str_rot13($input));
    }
}
Calling
$hl = $template->getHelperLocator();
$hl->set('obfuscate', function() {
   return new
  VendorPackageViewHelperObfuscate;
});
echo $this->obfuscate('plain text');
Aura.Sql
https://github.com/auraphp/Aura.Sql

 http://auraphp.github.com/Aura.Sql
Aura SQL
$adapter_factory = include
  '/path/to/Aura.Sql/scripts/instance.php';
$sql = $adapter_factory->newInstance(
     // adapter name
     'mysql',
     // DSN elements for PDO; this can also be
     // an array of key-value pairs
     'host=localhost;dbname=database_name',
     'username',
     'password'
);
Connecting
Lazy connection
Manually connect
  $sql->connect()
Fetching Results
// returns all rows
$result = $sql->fetchAll('SELECT * FROM foo');
Preventing SQL Injection
$text = 'SELECT * FROM foo WHERE id = :id AND bar
  IN(:bar_list)';
// values to bind to query placeholders
$data = [
     'id' => 1,
     'bar_list' => ['a', 'b', 'c'],
];
// returns all rows; the query ends up being
// "SELECT * FROM foo WHERE id = 1 AND bar IN('a', 'b', 'c')"
$result = $sql->fetchOne($text, $data);
Inserting
$table = 'foo';
// the columns and values to insert
$cols = [
     'bar' => 'value for column bar',
];
// perform the insert; result is number of rows affected
$result = $sql->insert($table, $cols);
// now get the last inserted ID
$id = $sql->lastInsertId(); // mysql
$id = $sql->lastInsertId($table, 'id'); // pgssql
Updating
$table = 'foo';
// the new column values to set
$cols = [
     'bar' => 'a new value for column bar',
];
// a where condition to specify which rows to update
$cond = 'id = :id';
// additional data to bind to the query
$data = ['id' => 1];
// perform the update; result is number of rows affected
$result = $sql->update($table, $cols, $cond, $data);
Transactions
// turn off autocommit and start a transaction
$sql->beginTransaction();
try {
    // ... perform some queries ...
    // now commit to the database:
    $sql->commit();
} catch (Exception $e) {
    // there was an error, roll back the queries
    $sql->rollBack();
}
Profiling
$sql->getProfiler()->setActive(true);
// issue a query
$result = $sql->fetchAll('SELECT * FROM foo');
// now get the profiler information
foreach ($sql->getProfiler()->getProfiles() as $i =>
  $profile) {
    echo 'Query #' . $i + 1 . ' took ' . $profile->time . '
    seconds.' . PHP_EOL;
}
Aura.Marshal
https://github.com/auraphp/Aura.Marshal

  http://auraphp.github.com/Aura.Marshal
Aura.Marshal
Aura Marshal makes it easy to avoid the N+1
 problem when working with a domain model.
 http://phpadvent.org/2011/a-stitch-in-time-saves-n
it does not have a query-building facility
it will not issue queries on its own
it will not handle persistence for you
it will not lazy-load results from a data source
it will not read metadata or schemas from the
   datasource
Defining Types and Relationships
Define Types
$manager->setType('posts',            ['identity_field' => 'id']);
$manager->setType('comments', ['identity_field' => 'id']);
// posts have many comments
Define Relationship
$manager->setRelation('posts', 'comments', [
      'relationship' => 'has_many',
      'native_field' => 'id',
      'foreign_field' => 'post_id'
]);
Loading Data
$result = $sql->fetchAll('SELECT * FROM posts LIMIT 10');
// load the results into the posts type object, and get back the
// identity (primary key) values for the loaded results.
$post_ids = $manager->posts->load($result);
// select and load all the comments on all the posts at once.
$result = $sql->fetchAll(
     'SELECT * FROM comments WHERE post_id IN (:post_ids)',
     [
         'post_ids' => $post_ids,
     ]
);
$manager->comments->load($result);
Aura.Cli
httpa://.github.com/auraphp/Aura.Cli
 http://auraphp.github.com/Aura.Cli
class ExampleCommand extends AbstractCommand {
  protected $input = 'foo bar baz';
  public function preExec() {
      // perform object setup here }
  public function preAction() {
      $this->stdio->outln('The input is currently ' . $this->input);
  }
  public function action() {
      $this->stdio->out('Please enter some text: ');
      $this->input = $this->stdio->in();
  }
  public function postAction() {
      $this->stdio->outln('The input was %r%2' . $this->input . '%n');
  }
  public function postExec() {
      // perform object teardown here
Instantiate
use AuraCliContext;
use AuraCliGetopt;
use AuraCliOptionFactory;
use AuraCliStdio;
use AuraCliVt100;
$command = new ExampleCommand(
  new Context($GLOBALS),
  new Stdio( fopen('php://stdin', 'r'), fopen('php://stdout', 'w+'),
     fopen('php://stderr', 'w+'), new Vt100 ),
  new Getopt(new OptionFactory));
// execute
$command->exec();
Aura.Signal
httpa://.github.com/auraphp/Aura.Signal
 http://auraphp.github.com/Aura.Signal
Aura Signal
SignalSlots/EventHandler implementation
invoke handlers ("slots" or "hooks") whenever
  an object sends a signal ("notification" or
  "event") to the signal manager
Instantiate and Add Handler
$signal = require '/path/Aura.Signal/scripts/instance.php';
$signal->handler(
     'VendorPackageExample',
     'example_signal',
     function ($arg) { echo $arg; }
);
use AuraSignalManager as SignalManager;
class Example
{
    protected $signal;
    public function __construct(SignalManager $signal)
    {
        $this->signal = $signal;
    }
    public function doSomething($text)
    {
        echo $text;
        $this->signal->send($this, 'example_signal', $text);
    }
}
Demo of Signal
Aura.Di
https://.github.com/auraphp/Aura.Di
 http://auraphp.github.com/Aura.Di
Dependency Injection
namespace ExamplePackage;


class Database
{
    public function __construct($hostname, $username, $password)
    {
        // ... make the database connection
    }
}
namespace ExamplePackage;
abstract class Model
{
    protected $db;
    public function __construct(Database $db)
    {
        $this->db = $db;
    }
}
class BlogModel extends Model
{
    // ...
}
new BlogModel( new Database( params ) );
Aura.Di
Dependecny Injection Container
Instantiation
$di = require '/path/to/Aura.Di/scripts/instance.php';


or


use AuraDiContainer;
use AuraDiForge;
use AuraDiConfig;
$di = new Container(new Forge(new Config));
Eager Loading
$di->set('database', new ExamplePackageDatabase(
      'localhost', 'user', 'passwd'
));
Instance created on a fly
Lazy Loading
$di->set('database', function() {
      return new ExamplePackageDatabase('localhost', 'user',
      'passwd');
});
Constructor Params
$di->set('database', function() use ($di) {
      return $di->newInstance('ExamplePackageDatabase', [
            'hostname' => 'localhost',
            'username' => 'user',
            'password' => 'passwd',
      ]);
});
Class Constructor Params
$di->params['ExamplePackageDatabase'] = [
      'hostname' => 'localhost',
      'username' => 'user',
      'password' => 'passwd',
];


$di->set('database', function() use ($di) {
      return $di->newInstance('ExamplePackageDatabase');
});
Override Class Constructor
                     Params
$di->params['ExamplePackageDatabase'] = [
      'hostname' => 'localhost',
      'username' => 'user',
      'password' => 'passwd',
];
$di->set('database', function() use ($di) {
      return $di->newInstance('ExamplePackageDatabase', [
            'hostname' => 'example.com',
      ]);
});
Getting Services
$db = $di->get('database');
Same object instance
lazyGet()
lazyNew()
there is more, have a look into
  https://github.com/auraphp/Aura.Di
Aura Framework
git clone git@github.com:auraphp/system.git
cd system
php update.php


point to web/index.php
Thank You

Rate it at http://joind.in/6279


Barcamp : http://joind.in/event/view/928

Weitere ähnliche Inhalte

Was ist angesagt?

Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsMichael Peacock
 
Puppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 EditionPuppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 EditionJoshua Thijssen
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2Elizabeth Smith
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Adam Tomat
 
Laravel5 Introduction and essentials
Laravel5 Introduction and essentialsLaravel5 Introduction and essentials
Laravel5 Introduction and essentialsPramod Kadam
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansiblebcoca
 
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & HadoopPuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & HadoopWalter Heck
 
Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4ripienaar
 
PuppetCamp SEA 1 - Puppet Deployment at OnApp
PuppetCamp SEA 1 - Puppet Deployment  at OnAppPuppetCamp SEA 1 - Puppet Deployment  at OnApp
PuppetCamp SEA 1 - Puppet Deployment at OnAppWalter Heck
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricksbcoca
 
Puppet control-repo 
to the next level
Puppet control-repo 
to the next levelPuppet control-repo 
to the next level
Puppet control-repo 
to the next levelAlessandro Franceschi
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkMichael Peacock
 
SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09Elizabeth Smith
 
Migrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain PointsMigrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain PointsSteven Evatt
 

Was ist angesagt? (20)

Intro to-puppet
Intro to-puppetIntro to-puppet
Intro to-puppet
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Puppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 EditionPuppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 Edition
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2
 
Spl in the wild
Spl in the wildSpl in the wild
Spl in the wild
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 
Laravel5 Introduction and essentials
Laravel5 Introduction and essentialsLaravel5 Introduction and essentials
Laravel5 Introduction and essentials
 
Puppi. Puppet strings to the shell
Puppi. Puppet strings to the shellPuppi. Puppet strings to the shell
Puppi. Puppet strings to the shell
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & HadoopPuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
 
Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4
 
PuppetCamp SEA 1 - Puppet Deployment at OnApp
PuppetCamp SEA 1 - Puppet Deployment  at OnAppPuppetCamp SEA 1 - Puppet Deployment  at OnApp
PuppetCamp SEA 1 - Puppet Deployment at OnApp
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricks
 
Php on Windows
Php on WindowsPhp on Windows
Php on Windows
 
Puppet control-repo 
to the next level
Puppet control-repo 
to the next levelPuppet control-repo 
to the next level
Puppet control-repo 
to the next level
 
Anatomy of a reusable module
Anatomy of a reusable moduleAnatomy of a reusable module
Anatomy of a reusable module
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech Talk
 
SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09
 
Migrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain PointsMigrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain Points
 
Puppet modules for Fun and Profit
Puppet modules for Fun and ProfitPuppet modules for Fun and Profit
Puppet modules for Fun and Profit
 

Ähnlich wie Aura Project for PHP

Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
Nashvile Symfony Routes Presentation
Nashvile Symfony Routes PresentationNashvile Symfony Routes Presentation
Nashvile Symfony Routes PresentationBrent Shaffer
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium AppsNate Abele
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Developmentjsmith92
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Fabien Potencier
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Filesystem abstractions and msg queue sergeev - symfony camp 2018
Filesystem abstractions and msg queue   sergeev - symfony camp 2018Filesystem abstractions and msg queue   sergeev - symfony camp 2018
Filesystem abstractions and msg queue sergeev - symfony camp 2018Юлия Коваленко
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesEyal Vardi
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking Sebastian Marek
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model Perforce
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection apiMatthieu Aubry
 
I Phone On Rails
I Phone On RailsI Phone On Rails
I Phone On RailsJohn Wilker
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3Jeremy Coates
 

Ähnlich wie Aura Project for PHP (20)

Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Nashvile Symfony Routes Presentation
Nashvile Symfony Routes PresentationNashvile Symfony Routes Presentation
Nashvile Symfony Routes Presentation
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Filesystem abstractions and msg queue sergeev - symfony camp 2018
Filesystem abstractions and msg queue   sergeev - symfony camp 2018Filesystem abstractions and msg queue   sergeev - symfony camp 2018
Filesystem abstractions and msg queue sergeev - symfony camp 2018
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource Services
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection api
 
I Phone On Rails
I Phone On RailsI Phone On Rails
I Phone On Rails
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Laravel
LaravelLaravel
Laravel
 

Mehr von Hari K T

Web routing in PHP with Aura
Web routing in PHP with AuraWeb routing in PHP with Aura
Web routing in PHP with AuraHari K T
 
Aura for PHP at Fossmeet 2014
Aura for PHP at Fossmeet 2014Aura for PHP at Fossmeet 2014
Aura for PHP at Fossmeet 2014Hari K T
 
Calicut University Script not traceable notification
Calicut University Script not traceable notificationCalicut University Script not traceable notification
Calicut University Script not traceable notificationHari K T
 
Speaking at Barcamp Kerala 11th Edition at IIM(K)
Speaking at Barcamp Kerala 11th Edition at IIM(K)Speaking at Barcamp Kerala 11th Edition at IIM(K)
Speaking at Barcamp Kerala 11th Edition at IIM(K)Hari K T
 
Characterset
CharactersetCharacterset
CharactersetHari K T
 

Mehr von Hari K T (6)

Web routing in PHP with Aura
Web routing in PHP with AuraWeb routing in PHP with Aura
Web routing in PHP with Aura
 
Aura for PHP at Fossmeet 2014
Aura for PHP at Fossmeet 2014Aura for PHP at Fossmeet 2014
Aura for PHP at Fossmeet 2014
 
Calicut University Script not traceable notification
Calicut University Script not traceable notificationCalicut University Script not traceable notification
Calicut University Script not traceable notification
 
Speaking at Barcamp Kerala 11th Edition at IIM(K)
Speaking at Barcamp Kerala 11th Edition at IIM(K)Speaking at Barcamp Kerala 11th Edition at IIM(K)
Speaking at Barcamp Kerala 11th Edition at IIM(K)
 
Characterset
CharactersetCharacterset
Characterset
 
Drupal
DrupalDrupal
Drupal
 

Kürzlich hochgeladen

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Kürzlich hochgeladen (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 

Aura Project for PHP

  • 1. Aura Project for PHP 5.4 Hari K T Bridge Global IT Staffing http://harikt.com http://auraphp.github.com
  • 2. Brought to you by @pmjones Paul M Jones
  • 3. Aura? Independent library packages for PHP 5.4 Second major version of Solar PHP Packages can be used alone, in concert with each other, or combined into a full-stack framework of their own. Groups : http://groups.google.com/group/auraphp Source Code : https://github.com/auraphp API & Docs : http://auraphp.github.com/Aura.<Package> IRC #auraphp on freenode
  • 4. Current Components / Library Aura.Autoload Aura.Cli Aura.Di Aura.Http Aura.Marshal Aura.Router Aura.Signal Aura.Sql Aura.View Aura.Web
  • 5. Aura.Autoload PSR-0 compliant SPL autoloader Matches the interface proposed at https://wiki.php.net/rfc/splclassloader Read more information on PSR-0 Autoload http://bit.ly/yzJ8r6 from phpmaster.com
  • 6. Vendor.Package Structure ├── config ( default.php , test.php ) ├── meta ( authors.csv, changes.txt, description.txt ) ├── scripts ( instance.php ) ├── src │ └── Aura │ └── Autoload │ ├── Exception │ ├── Exception.php │ └── Loader.php ( namespace AuraAutoload ) ├── src.php ├── tests
  • 7. Instantiate Create an instance of the Loader and register it with SPL. $loader = require '/path/to/Aura.Autoload/scripts/ instance.php'; $loader->register();
  • 8. Class Prefix Usage // look for all Vendor_* classes in this path: $loader->add('Vendor_', '/path/to/lib'); // look for VendorPackage classes in this path: $loader->add('VendorPackage', '/path/to/Vendor.Package/src'); // additionally, e.g. in testing modes, also look for VendorPackage // classes in this path as well: $loader->add('VendorPackage', '/path/to/Vendor.Package/tests');
  • 9. All in one $loader->setPaths([ 'AuraRouter' => '/path/Aura.Router/src/', 'AuraDi' => '/path/Aura.Di/src/', ]); $loader->setClasses([ 'VendorPackageFoo' => '/path/to/Vendor/Package/Foo.php', 'VendorPackageZim' => '/path/to/Vendor/Package/Zim.php', ]);
  • 11. Aura.Router Aura Router is a PHP package that implements web routing Given a URI path and a copy of $_SERVER, it will extract controller, action, and parameter values for a specific application route. Inspired by Solar rewrite rules and http://routes.groovie.org
  • 12. Add Routes $map = require '/path/to/Aura.Router/scripts/instance.php'; $map->add('home', '/', [ 'values' => ['controller' => 'hello', 'action' => 'world',], ]); $map->add('read', '/blog/read/{:id}{:format}', [ 'params' => [ 'id' => '(d+)', 'format' => '(..+)?', ], 'values' => [ 'controller' => 'blog', 'action' => 'read', 'format' => '.html', ], ));
  • 13. Matching a Route // get the incoming request URI path $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); // get the route based on the path and server $route = $map->match($path, $_SERVER);
  • 14. if (! $route) { echo "No application route was found for that URI path."; exit(); } // does the route indicate a controller? if (isset($route->values['controller'])) { $controller = $route->values['controller']; // take the controller class directly from the route } else { $controller = 'Default'; // use a default controller } if (isset($route->values['action'])) { // does the route indicate an action? $action = $route->values['action']; // take the action method directly from the route } else { $action = 'index'; // use a default action } $page = new $controller(); // instantiate the controller class echo $page->$action($route->values); // invoke the action method with the route values
  • 15. Generating A Route Path // $path => "/blog/read/42.atom" $path = $map->generate('read', [ 'id' => 42, 'format' => '.atom', ]); $href = htmlspecialchars($path, 'UTF-8'); echo '<a href="$href">Atom feed for this blog entry</a>';
  • 17. Aura.Web The Aura Web package provides tools to build web page controllers includes an AbstractPage for action methods a Context class for disovering the request environment Response transfer object that describes the eventual HTTP response
  • 18. Creating Page controller namespace VendorPackageWeb; use AuraWebAbstractPage; class Page extends AbstractPage { protected function actionHello($noun = null) { $noun = htmlspecialchars($noun, ENT_QUOTES, 'UTF-8'); $content = "Hello, {$noun}!"; $this->response->setContent($content); } }
  • 19. The Execution Cycle namespace VendorPackageWeb; use VendorPackageWebPage; use AuraWebContext; use AuraWebResponse; $params = [ 'action' => 'hello', 'format' => '.html', ]; $page = new Page(new Context, new Response, $params); $response = $page->exec();
  • 20. Internally, the exec() cycle runs A preExec() hook to let you set up the object, A preAction() hook to prepare for the action, The action() method to invoke the method determined by the 'action' param value A postAction() hook, A preRender() hook to prepare for rendering, The render() method to render a presentation (this is up to the developer to create), A postRender() hook, and A postExec() hook. At the end returns a Response transfer object. Response object is not an HTTP response proper; it is a data transfer object that has information on how to build an HTTP response.
  • 21. The Context Object $this->context-> getQuery(): gets a $_GET value getPost(): gets a $_POST value getFiles(): gets a $_FILES value getInput(): gets the raw php://input value getJsonInput(): gets the raw php://input value and json_decode() it getAccept(): gets the Accept headers, ordered by weight isGet(), isPut(), isXhr(), etc.: Tells if the request method was GET, PUT, an Xml-HTTP-Request, etc.
  • 22. Rendering render() method is empty by default. this allows you to add in whatever presentation logic you want, from simply json_encode()-ing $this->data, to using a complex two-step or transform view. Aura.View
  • 24. Aura.View Template View pattern preceded by systems such as Savant, Zend_View, and Solar_View Auto escaping [escaper branch] a work in progress
  • 25. Instantiation $template = require '/path/to/Aura.View/scripts/instance.php'; OR use AuraViewTemplate; use AuraViewTemplateFinder; use AuraViewHelperLocator; $template = new Template(new TemplateFinder, new HelperLocator); echo $template->fetch('/path/to/tpl.php');
  • 26. Adding Data $template->addData([ 'foo' => 'Value of foo', 'bar' => 'Value of bar', ]); // this will remove $var, $foo, and $bar from the template $template->setData([ 'baz' => 'Value of baz', 'dib' => 'Value of dib', ]);
  • 27. Template Composition <?php $e = $this->getHelper('escape'); // template script ?> <html> <head> <?php include $this->find('head'); ?> </head> <body> <?php include $this->find('branding'); // branding.php ?> <?php include $this->find('navigation'); ?> <p>Hello, <?php echo $e($this->var); ?>!</p> <?php include $this->find('footer'); ?> </body> </html>
  • 28. Template Finder $finder = $template->getTemplateFinder(); // set the paths where templates can be found $finder->setPaths([ '/path/to/templates/foo', '/path/to/templates/bar', '/path/to/templates/baz', ]);
  • 29. Writing Helpers namespace VendorPackageViewHelper; use AuraViewHelperAbstractHelper; class Obfuscate extends AbstractHelper { public function __invoke($string) { return $this->escape(str_rot13($input)); } }
  • 30. Calling $hl = $template->getHelperLocator(); $hl->set('obfuscate', function() { return new VendorPackageViewHelperObfuscate; }); echo $this->obfuscate('plain text');
  • 32. Aura SQL $adapter_factory = include '/path/to/Aura.Sql/scripts/instance.php'; $sql = $adapter_factory->newInstance( // adapter name 'mysql', // DSN elements for PDO; this can also be // an array of key-value pairs 'host=localhost;dbname=database_name', 'username', 'password' );
  • 33. Connecting Lazy connection Manually connect $sql->connect() Fetching Results // returns all rows $result = $sql->fetchAll('SELECT * FROM foo');
  • 34. Preventing SQL Injection $text = 'SELECT * FROM foo WHERE id = :id AND bar IN(:bar_list)'; // values to bind to query placeholders $data = [ 'id' => 1, 'bar_list' => ['a', 'b', 'c'], ]; // returns all rows; the query ends up being // "SELECT * FROM foo WHERE id = 1 AND bar IN('a', 'b', 'c')" $result = $sql->fetchOne($text, $data);
  • 35. Inserting $table = 'foo'; // the columns and values to insert $cols = [ 'bar' => 'value for column bar', ]; // perform the insert; result is number of rows affected $result = $sql->insert($table, $cols); // now get the last inserted ID $id = $sql->lastInsertId(); // mysql $id = $sql->lastInsertId($table, 'id'); // pgssql
  • 36. Updating $table = 'foo'; // the new column values to set $cols = [ 'bar' => 'a new value for column bar', ]; // a where condition to specify which rows to update $cond = 'id = :id'; // additional data to bind to the query $data = ['id' => 1]; // perform the update; result is number of rows affected $result = $sql->update($table, $cols, $cond, $data);
  • 37. Transactions // turn off autocommit and start a transaction $sql->beginTransaction(); try { // ... perform some queries ... // now commit to the database: $sql->commit(); } catch (Exception $e) { // there was an error, roll back the queries $sql->rollBack(); }
  • 38. Profiling $sql->getProfiler()->setActive(true); // issue a query $result = $sql->fetchAll('SELECT * FROM foo'); // now get the profiler information foreach ($sql->getProfiler()->getProfiles() as $i => $profile) { echo 'Query #' . $i + 1 . ' took ' . $profile->time . ' seconds.' . PHP_EOL; }
  • 40. Aura.Marshal Aura Marshal makes it easy to avoid the N+1 problem when working with a domain model. http://phpadvent.org/2011/a-stitch-in-time-saves-n it does not have a query-building facility it will not issue queries on its own it will not handle persistence for you it will not lazy-load results from a data source it will not read metadata or schemas from the datasource
  • 41. Defining Types and Relationships Define Types $manager->setType('posts', ['identity_field' => 'id']); $manager->setType('comments', ['identity_field' => 'id']); // posts have many comments Define Relationship $manager->setRelation('posts', 'comments', [ 'relationship' => 'has_many', 'native_field' => 'id', 'foreign_field' => 'post_id' ]);
  • 42. Loading Data $result = $sql->fetchAll('SELECT * FROM posts LIMIT 10'); // load the results into the posts type object, and get back the // identity (primary key) values for the loaded results. $post_ids = $manager->posts->load($result); // select and load all the comments on all the posts at once. $result = $sql->fetchAll( 'SELECT * FROM comments WHERE post_id IN (:post_ids)', [ 'post_ids' => $post_ids, ] ); $manager->comments->load($result);
  • 44. class ExampleCommand extends AbstractCommand { protected $input = 'foo bar baz'; public function preExec() { // perform object setup here } public function preAction() { $this->stdio->outln('The input is currently ' . $this->input); } public function action() { $this->stdio->out('Please enter some text: '); $this->input = $this->stdio->in(); } public function postAction() { $this->stdio->outln('The input was %r%2' . $this->input . '%n'); } public function postExec() { // perform object teardown here
  • 45. Instantiate use AuraCliContext; use AuraCliGetopt; use AuraCliOptionFactory; use AuraCliStdio; use AuraCliVt100; $command = new ExampleCommand( new Context($GLOBALS), new Stdio( fopen('php://stdin', 'r'), fopen('php://stdout', 'w+'), fopen('php://stderr', 'w+'), new Vt100 ), new Getopt(new OptionFactory)); // execute $command->exec();
  • 47. Aura Signal SignalSlots/EventHandler implementation invoke handlers ("slots" or "hooks") whenever an object sends a signal ("notification" or "event") to the signal manager
  • 48. Instantiate and Add Handler $signal = require '/path/Aura.Signal/scripts/instance.php'; $signal->handler( 'VendorPackageExample', 'example_signal', function ($arg) { echo $arg; } );
  • 49. use AuraSignalManager as SignalManager; class Example { protected $signal; public function __construct(SignalManager $signal) { $this->signal = $signal; } public function doSomething($text) { echo $text; $this->signal->send($this, 'example_signal', $text); } }
  • 52. Dependency Injection namespace ExamplePackage; class Database { public function __construct($hostname, $username, $password) { // ... make the database connection } }
  • 53. namespace ExamplePackage; abstract class Model { protected $db; public function __construct(Database $db) { $this->db = $db; } } class BlogModel extends Model { // ... } new BlogModel( new Database( params ) );
  • 55. Instantiation $di = require '/path/to/Aura.Di/scripts/instance.php'; or use AuraDiContainer; use AuraDiForge; use AuraDiConfig; $di = new Container(new Forge(new Config));
  • 56. Eager Loading $di->set('database', new ExamplePackageDatabase( 'localhost', 'user', 'passwd' )); Instance created on a fly
  • 57. Lazy Loading $di->set('database', function() { return new ExamplePackageDatabase('localhost', 'user', 'passwd'); });
  • 58. Constructor Params $di->set('database', function() use ($di) { return $di->newInstance('ExamplePackageDatabase', [ 'hostname' => 'localhost', 'username' => 'user', 'password' => 'passwd', ]); });
  • 59. Class Constructor Params $di->params['ExamplePackageDatabase'] = [ 'hostname' => 'localhost', 'username' => 'user', 'password' => 'passwd', ]; $di->set('database', function() use ($di) { return $di->newInstance('ExamplePackageDatabase'); });
  • 60. Override Class Constructor Params $di->params['ExamplePackageDatabase'] = [ 'hostname' => 'localhost', 'username' => 'user', 'password' => 'passwd', ]; $di->set('database', function() use ($di) { return $di->newInstance('ExamplePackageDatabase', [ 'hostname' => 'example.com', ]); });
  • 61. Getting Services $db = $di->get('database'); Same object instance lazyGet() lazyNew() there is more, have a look into https://github.com/auraphp/Aura.Di
  • 62. Aura Framework git clone git@github.com:auraphp/system.git cd system php update.php point to web/index.php
  • 63. Thank You Rate it at http://joind.in/6279 Barcamp : http://joind.in/event/view/928