SlideShare a Scribd company logo
1 of 29
Aura for PHP

Hari KT
@harikt
http://harikt.com
FOSSMeet 2014 @ NIT Calicut
About me
●

Freelance LAMP developer

●

Open-source lover and contributor

●

Writes for sitepoint.com

●

Technical reviewer of Packt

FOSSMeet 2014 @ NIT Calicut
Aura
●

2nd major version of SolarPHP ( started in
2004 by Paul M Jones)

●

Independent decoupled library packages

●

V1 started around late 2010 ( PSR-0 standard )

●

V2 started around late 2013 ( PSR-4 standard )

FOSSMeet 2014 @ NIT Calicut
PSR-0 vs PSR-4
namespace AuraRouter;
class RouterFactory {
}
●

PSR-0 : http://www.php-fig.org/psr/psr-0/
AuraRouterRouteFactory => /path/to/src/Aura/Router/RouteFactory.php
Zend_Mail_Message => /path/to/lib/Zend/Mail/Message.php

●

PSR-4 : http://www.php-fig.org/psr/psr-4/
AuraRouterRouteFactory => /path/to/src/RouteFactory.php

FOSSMeet 2014 @ NIT Calicut
Driving Principles
●
●

Libraries first, framework 2nd
No use of globals within packages
( $_SERVER, $_GET etc )

●

No dependency on any other package

●

Tests and Assets inside the package

FOSSMeet 2014 @ NIT Calicut
Library / Package Organization

FOSSMeet 2014 @ NIT Calicut
Aura.Router v2

FOSSMeet 2014 @ NIT Calicut
Aura.Router
●
●

Provides a web router implementation
Given a URL path and a copy of $_SERVER, it
will extract path-info parameters and
$_SERVER values for a specific route

FOSSMeet 2014 @ NIT Calicut
Instantiation
require path/to/Aura.Router/autoload.php;
use AuraRouterRouterFactory;
$router_factory = new RouterFactory;
$router = $router_factory->newInstance();
or
use AuraRouterRouter;
use AuraRouterRouteCollection;
use AuraRouterRouteFactory;
$router = new Router(new RouteCollection(new RouteFactory));
FOSSMeet 2014 @ NIT Calicut
Adding Route
●

// add a simple unnamed route with params
$router->add(null, '/{controller}/{action}/{id}');

●

// add a route with optional params
$router->add('archive', '/archive{/year,month,day}')

●

// add a named route with an extended specification
$router->add('read', '/blog/read/{id}{format}')
->addTokens(array('id' => 'd+', 'format' => '(.[^/]+)?',))
->addValues(array('controller' => 'BlogPage', 'action' => 'read', 'format' =>
'.html',));

●

// REST resource route
$router->attachResource('blog', '/blog');
FOSSMeet 2014 @ NIT Calicut
Matching A Route
// get the incoming request URL path
$path = parse_url($_SERVER['REQUEST_URI'],
PHP_URL_PATH);
// get the route based on the path and server
$route = $router->match($path, $_SERVER);

FOSSMeet 2014 @ NIT Calicut
Example
$path = '/blog/read/42.json';
$route = $router->match($path, $_SERVER);
var_export($route->params);
[
'controller' => 'BlogPage',
'action' => 'read',
'id' => 42,
'format' => 'json'
]

FOSSMeet 2014 @ NIT Calicut
Dispatching a Route
if ($route) {
echo "No application route was found for that URL path.";
exit();
}
$class = $route->params['controller']; // BlogPage
$method = $route->params['action']; // read
// instantiate the controller class
$object = new $class();
echo $object->$method($route->params);
// $object->read($route->params);
FOSSMeet 2014 @ NIT Calicut
Microframework Route
$router->add('read', '/blog/read/{id}')
->addTokens(array( 'id' => 'd+', ))
->addValues(array(
'controller' => function ($params) {
$id = (int) $params['id'];
header('Content-Type: application/json');
echo json_encode(['id' => $id]);
},
));

FOSSMeet 2014 @ NIT Calicut
Microframework Dispatcher
$controller = $route->params['controller'];
echo $controller($route->params);

FOSSMeet 2014 @ NIT Calicut
Generating a route path
// $path => "/blog/read/42.atom"
$path = $router->generate('read', array(
'id' => 42,
'format' => '.atom',
));
$href = htmlspecialchars($path, ENT_QUOTES, 'UTF-8');
echo '<a href="$href">Atom feed for this blog entry</a>';

FOSSMeet 2014 @ NIT Calicut
Aura.Filter v1

FOSSMeet 2014 @ NIT Calicut
Instantiation
$filter = require "/path/to/Aura.Filter/scripts/instance.php";
or
use AuraFilterRuleCollection as Filter;
use AuraFilterRuleLocator;
use AuraFilterTranslator;
$filter = new Filter(
new RuleLocator,
new Translator(require 'path/to/Aura.Filter/intl/en_US.php')
);
FOSSMeet 2014 @ NIT Calicut
Rule Types
●

●

●

Soft : if the rule fails, the filter will keep applying all
remaining rules to that field and all other fields
Hard : if the rule fails, the filter will not apply any
more rules to that field, but it will keep filtering other
fields.
Stop : if the rule fails, the filter will not apply any
more filters to any more fields; this stops all filtering
on the data object.
FOSSMeet 2014 @ NIT Calicut
Aura.Filter
$filter->addSoftRule('username', $filter::IS, 'alnum');
$filter->addSoftRule('username', $filter::IS, 'strlenBetween', 6, 12);
$filter->addSoftRule('username', $filter::FIX, 'string');
$filter->addSoftRule('password', $filter::IS, 'strlenMin', 6);
$filter->addSoftRule('password_confirm', $filter::IS, 'equalToField',
'password');
$data = [ 'username' => 'bolivar', 'password' => 'p@55w0rd',
'password_confirm' => 'p@55word', // not the same!];
$success = $filter->values($data);
if (! $success) {
$messages = $filter->getMessages();
}

FOSSMeet 2014 @ NIT Calicut
Validating and Sanitizing
●

●

●

●

●

RuleCollection::IS means the field value must match the rule.
RuleCollection::IS_NOT means the field value must not match
the rule.
RuleCollection::IS_BLANK_OR means the field value must
either be blank, or match the rule.
RuleCollection::FIX to force the field value to comply with the
rule; this may forcibly transform the value.
RuleCollection::FIX_BLANK_OR will convert blank values to
null; non-blank fields will be forced to comply with the rule.
FOSSMeet 2014 @ NIT Calicut
Available Rules
alnum

alpha

between

blank

creditCard

dateTime

email

equalToField

equalToValue

float

inKeys

inValues

int

ipv4

locale

max

min

regex

strictEqualToF strictEqualToV
ield
alue

string

strlen

strlenBetween strlenMax

strlenMin

trim

upload

url

isbn

any

all

word

FOSSMeet 2014 @ NIT Calicut
Custom Rules
●

Write a rule class

●

Set that class as a service in the RuleLocator

●

Use the new rule in our filter chain

FOSSMeet 2014 @ NIT Calicut
Rule Class
●

●

●

●

●

Extend AuraFilterAbstractRule with two methods:
validate() and sanitize()
Add params as needed to each method.
Each method should return a boolean: true on success, or
false on failure.
Use getValue() to get the value being validated, and
setValue() to change the value being sanitized.
Add a property $message to indicate a string that should be
translated as a message when validation or sanitizing fails.
FOSSMeet 2014 @ NIT Calicut
Example
use AuraFilterAbstractRule;
class Hex extends AbstractRule {
protected $message;
public function validate($max = null) {
$value = $this->getValue();
}
public function sanitize($max = null) { $this->setValue('Hello'); // some code }
}
$locator = $filter->getRuleLocator();
$locator->set('hex', function () {
return new Hex;
});

FOSSMeet 2014 @ NIT Calicut
Questions ?
●

Hire me to coach you PHP, Aura
Hari KT
harikt.com
https://github.com/harikt
FOSSMeet 2014 @ NIT Calicut
more library / framework
Aura.Cli

Aura.Di

Aura.Includer

Aura.Input

Aura.Web

Aura.Di

Aura.Dispatcher

Aura. Sql

Aura.View

Aura.Html

Aura.Http

Aura.Intl

Aura.Router

Aura.Signal

Aura.Filter

Aura.Session

Aura.Sql_Query

Aura.Sql_Schema

Aura.Marshal

Aura.Autoload

Aura.Web_Project

Aura.Framework

Aura.Framework_Project

Aura.Project_Kernel

Aura.Web_Kernel

Aura.Web_Project

Aura.Cli_Kernel

Aura.Cli_Project

.....

FOSSMeet 2014 @ NIT Calicut
PHP User Group in Calicut
●

●
●

Plan to organize a user group meetup once in a
month
Looking for space and audience
Join https://groups.google.com/forum/#!
forum/php-clt

FOSSMeet 2014 @ NIT Calicut
Thanks
●

Website : http://auraphp.com/

●

Source Code : http://github.com/auraphp

●

●
●

●

Groups :
https://groups.google.com/d/forum/auraphp
Paul M Jones : http://paul-m-jones.com/
Chris Tankersley
http://www.slideshare.net/ctankersley/dtyu
SolarPHP : http://solarphp.com/
FOSSMeet 2014 @ NIT Calicut

More Related Content

What's hot

Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentationVan Huong
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhHarmeet Singh(Taara)
 
PHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedPHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedAyesh Karunaratne
 
#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity#Pharo Days 2016 Reflectivity
#Pharo Days 2016 ReflectivityPhilippe Back
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8LivePerson
 
Generating parsers using Ragel and Lemon
Generating parsers using Ragel and LemonGenerating parsers using Ragel and Lemon
Generating parsers using Ragel and LemonTristan Penman
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8Takipi
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2LiviaLiaoFontech
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java langer4711
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in JavaErhan Bagdemir
 
Introduction to web and php mysql
Introduction to web and php mysqlIntroduction to web and php mysql
Introduction to web and php mysqlProgrammer Blog
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the futureAnsviaLab
 
#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and Protocols#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and ProtocolsPhilippe Back
 
Why You Should Use TAPIs
Why You Should Use TAPIsWhy You Should Use TAPIs
Why You Should Use TAPIsJeffrey Kemp
 

What's hot (20)

Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Java8
Java8Java8
Java8
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
 
PHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedPHP 8.1 - What's new and changed
PHP 8.1 - What's new and changed
 
#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Generating parsers using Ragel and Lemon
Generating parsers using Ragel and LemonGenerating parsers using Ragel and Lemon
Generating parsers using Ragel and Lemon
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
Introduction to web and php mysql
Introduction to web and php mysqlIntroduction to web and php mysql
Introduction to web and php mysql
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
 
Slim Framework
Slim FrameworkSlim Framework
Slim Framework
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
Hadoop training-in-hyderabad
Hadoop training-in-hyderabadHadoop training-in-hyderabad
Hadoop training-in-hyderabad
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the future
 
Lambdas and Laughs
Lambdas and LaughsLambdas and Laughs
Lambdas and Laughs
 
#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and Protocols#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and Protocols
 
Why You Should Use TAPIs
Why You Should Use TAPIsWhy You Should Use TAPIs
Why You Should Use TAPIs
 

Similar to Aura for PHP at Fossmeet 2014

Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)James Titcumb
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)James Titcumb
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Decoupled Libraries for PHP
Decoupled Libraries for PHPDecoupled Libraries for PHP
Decoupled Libraries for PHPPaul Jones
 
Php 5.6 From the Inside Out
Php 5.6 From the Inside OutPhp 5.6 From the Inside Out
Php 5.6 From the Inside OutFerenc Kovács
 
Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngineMichaelRog
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST APICaldera Labs
 
Submit PHP: Standards in PHP world. Михайло Морозов
Submit PHP: Standards in PHP world. Михайло МорозовSubmit PHP: Standards in PHP world. Михайло Морозов
Submit PHP: Standards in PHP world. Михайло МорозовBinary Studio
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroChristopher Pecoraro
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)James Titcumb
 
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Antonio Peric-Mazar
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)James Titcumb
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
Laravel5 Introduction and essentials
Laravel5 Introduction and essentialsLaravel5 Introduction and essentials
Laravel5 Introduction and essentialsPramod Kadam
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)James Titcumb
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)James Titcumb
 

Similar to Aura for PHP at Fossmeet 2014 (20)

Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Decoupled Libraries for PHP
Decoupled Libraries for PHPDecoupled Libraries for PHP
Decoupled Libraries for PHP
 
Php 5.6 From the Inside Out
Php 5.6 From the Inside OutPhp 5.6 From the Inside Out
Php 5.6 From the Inside Out
 
Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngine
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Submit PHP: Standards in PHP world. Михайло Морозов
Submit PHP: Standards in PHP world. Михайло МорозовSubmit PHP: Standards in PHP world. Михайло Морозов
Submit PHP: Standards in PHP world. Михайло Морозов
 
PHP Development Tools
PHP  Development ToolsPHP  Development Tools
PHP Development Tools
 
Plsql
PlsqlPlsql
Plsql
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
Getting Started With Aura
Getting Started With AuraGetting Started With Aura
Getting Started With Aura
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Laravel5 Introduction and essentials
Laravel5 Introduction and essentialsLaravel5 Introduction and essentials
Laravel5 Introduction and essentials
 
Best practices tekx
Best practices tekxBest practices tekx
Best practices tekx
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
 

More from 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
 
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
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHPHari 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
 

More from 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
 
Calicut University Script not traceable notification
Calicut University Script not traceable notificationCalicut University Script not traceable notification
Calicut University Script not traceable notification
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
 
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
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

Aura for PHP at Fossmeet 2014

  • 1. Aura for PHP Hari KT @harikt http://harikt.com FOSSMeet 2014 @ NIT Calicut
  • 2. About me ● Freelance LAMP developer ● Open-source lover and contributor ● Writes for sitepoint.com ● Technical reviewer of Packt FOSSMeet 2014 @ NIT Calicut
  • 3. Aura ● 2nd major version of SolarPHP ( started in 2004 by Paul M Jones) ● Independent decoupled library packages ● V1 started around late 2010 ( PSR-0 standard ) ● V2 started around late 2013 ( PSR-4 standard ) FOSSMeet 2014 @ NIT Calicut
  • 4. PSR-0 vs PSR-4 namespace AuraRouter; class RouterFactory { } ● PSR-0 : http://www.php-fig.org/psr/psr-0/ AuraRouterRouteFactory => /path/to/src/Aura/Router/RouteFactory.php Zend_Mail_Message => /path/to/lib/Zend/Mail/Message.php ● PSR-4 : http://www.php-fig.org/psr/psr-4/ AuraRouterRouteFactory => /path/to/src/RouteFactory.php FOSSMeet 2014 @ NIT Calicut
  • 5. Driving Principles ● ● Libraries first, framework 2nd No use of globals within packages ( $_SERVER, $_GET etc ) ● No dependency on any other package ● Tests and Assets inside the package FOSSMeet 2014 @ NIT Calicut
  • 6. Library / Package Organization FOSSMeet 2014 @ NIT Calicut
  • 8. Aura.Router ● ● Provides a web router implementation Given a URL path and a copy of $_SERVER, it will extract path-info parameters and $_SERVER values for a specific route FOSSMeet 2014 @ NIT Calicut
  • 9. Instantiation require path/to/Aura.Router/autoload.php; use AuraRouterRouterFactory; $router_factory = new RouterFactory; $router = $router_factory->newInstance(); or use AuraRouterRouter; use AuraRouterRouteCollection; use AuraRouterRouteFactory; $router = new Router(new RouteCollection(new RouteFactory)); FOSSMeet 2014 @ NIT Calicut
  • 10. Adding Route ● // add a simple unnamed route with params $router->add(null, '/{controller}/{action}/{id}'); ● // add a route with optional params $router->add('archive', '/archive{/year,month,day}') ● // add a named route with an extended specification $router->add('read', '/blog/read/{id}{format}') ->addTokens(array('id' => 'd+', 'format' => '(.[^/]+)?',)) ->addValues(array('controller' => 'BlogPage', 'action' => 'read', 'format' => '.html',)); ● // REST resource route $router->attachResource('blog', '/blog'); FOSSMeet 2014 @ NIT Calicut
  • 11. Matching A Route // get the incoming request URL path $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); // get the route based on the path and server $route = $router->match($path, $_SERVER); FOSSMeet 2014 @ NIT Calicut
  • 12. Example $path = '/blog/read/42.json'; $route = $router->match($path, $_SERVER); var_export($route->params); [ 'controller' => 'BlogPage', 'action' => 'read', 'id' => 42, 'format' => 'json' ] FOSSMeet 2014 @ NIT Calicut
  • 13. Dispatching a Route if ($route) { echo "No application route was found for that URL path."; exit(); } $class = $route->params['controller']; // BlogPage $method = $route->params['action']; // read // instantiate the controller class $object = new $class(); echo $object->$method($route->params); // $object->read($route->params); FOSSMeet 2014 @ NIT Calicut
  • 14. Microframework Route $router->add('read', '/blog/read/{id}') ->addTokens(array( 'id' => 'd+', )) ->addValues(array( 'controller' => function ($params) { $id = (int) $params['id']; header('Content-Type: application/json'); echo json_encode(['id' => $id]); }, )); FOSSMeet 2014 @ NIT Calicut
  • 15. Microframework Dispatcher $controller = $route->params['controller']; echo $controller($route->params); FOSSMeet 2014 @ NIT Calicut
  • 16. Generating a route path // $path => "/blog/read/42.atom" $path = $router->generate('read', array( 'id' => 42, 'format' => '.atom', )); $href = htmlspecialchars($path, ENT_QUOTES, 'UTF-8'); echo '<a href="$href">Atom feed for this blog entry</a>'; FOSSMeet 2014 @ NIT Calicut
  • 18. Instantiation $filter = require "/path/to/Aura.Filter/scripts/instance.php"; or use AuraFilterRuleCollection as Filter; use AuraFilterRuleLocator; use AuraFilterTranslator; $filter = new Filter( new RuleLocator, new Translator(require 'path/to/Aura.Filter/intl/en_US.php') ); FOSSMeet 2014 @ NIT Calicut
  • 19. Rule Types ● ● ● Soft : if the rule fails, the filter will keep applying all remaining rules to that field and all other fields Hard : if the rule fails, the filter will not apply any more rules to that field, but it will keep filtering other fields. Stop : if the rule fails, the filter will not apply any more filters to any more fields; this stops all filtering on the data object. FOSSMeet 2014 @ NIT Calicut
  • 20. Aura.Filter $filter->addSoftRule('username', $filter::IS, 'alnum'); $filter->addSoftRule('username', $filter::IS, 'strlenBetween', 6, 12); $filter->addSoftRule('username', $filter::FIX, 'string'); $filter->addSoftRule('password', $filter::IS, 'strlenMin', 6); $filter->addSoftRule('password_confirm', $filter::IS, 'equalToField', 'password'); $data = [ 'username' => 'bolivar', 'password' => 'p@55w0rd', 'password_confirm' => 'p@55word', // not the same!]; $success = $filter->values($data); if (! $success) { $messages = $filter->getMessages(); } FOSSMeet 2014 @ NIT Calicut
  • 21. Validating and Sanitizing ● ● ● ● ● RuleCollection::IS means the field value must match the rule. RuleCollection::IS_NOT means the field value must not match the rule. RuleCollection::IS_BLANK_OR means the field value must either be blank, or match the rule. RuleCollection::FIX to force the field value to comply with the rule; this may forcibly transform the value. RuleCollection::FIX_BLANK_OR will convert blank values to null; non-blank fields will be forced to comply with the rule. FOSSMeet 2014 @ NIT Calicut
  • 23. Custom Rules ● Write a rule class ● Set that class as a service in the RuleLocator ● Use the new rule in our filter chain FOSSMeet 2014 @ NIT Calicut
  • 24. Rule Class ● ● ● ● ● Extend AuraFilterAbstractRule with two methods: validate() and sanitize() Add params as needed to each method. Each method should return a boolean: true on success, or false on failure. Use getValue() to get the value being validated, and setValue() to change the value being sanitized. Add a property $message to indicate a string that should be translated as a message when validation or sanitizing fails. FOSSMeet 2014 @ NIT Calicut
  • 25. Example use AuraFilterAbstractRule; class Hex extends AbstractRule { protected $message; public function validate($max = null) { $value = $this->getValue(); } public function sanitize($max = null) { $this->setValue('Hello'); // some code } } $locator = $filter->getRuleLocator(); $locator->set('hex', function () { return new Hex; }); FOSSMeet 2014 @ NIT Calicut
  • 26. Questions ? ● Hire me to coach you PHP, Aura Hari KT harikt.com https://github.com/harikt FOSSMeet 2014 @ NIT Calicut
  • 27. more library / framework Aura.Cli Aura.Di Aura.Includer Aura.Input Aura.Web Aura.Di Aura.Dispatcher Aura. Sql Aura.View Aura.Html Aura.Http Aura.Intl Aura.Router Aura.Signal Aura.Filter Aura.Session Aura.Sql_Query Aura.Sql_Schema Aura.Marshal Aura.Autoload Aura.Web_Project Aura.Framework Aura.Framework_Project Aura.Project_Kernel Aura.Web_Kernel Aura.Web_Project Aura.Cli_Kernel Aura.Cli_Project ..... FOSSMeet 2014 @ NIT Calicut
  • 28. PHP User Group in Calicut ● ● ● Plan to organize a user group meetup once in a month Looking for space and audience Join https://groups.google.com/forum/#! forum/php-clt FOSSMeet 2014 @ NIT Calicut
  • 29. Thanks ● Website : http://auraphp.com/ ● Source Code : http://github.com/auraphp ● ● ● ● Groups : https://groups.google.com/d/forum/auraphp Paul M Jones : http://paul-m-jones.com/ Chris Tankersley http://www.slideshare.net/ctankersley/dtyu SolarPHP : http://solarphp.com/ FOSSMeet 2014 @ NIT Calicut