SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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)
 

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
 
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
 

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
 
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
 

Kürzlich hochgeladen

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 

Kürzlich hochgeladen (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 

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