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