This document discusses decoupled libraries and frameworks in PHP. It provides background on libraries, frameworks and components. Key principles of decoupled library packages are that they have no dependencies on other packages, encapsulate tests and assets, and are set up for dependency injection rather than static calls. Examples are given of how individual Aura library packages follow these principles, including the Router and Web packages. Limits to full decoupling are noted, as well as the direction of dependencies between packages.
Supercharging WordPress Development in 2018Adam Tomat
Slide links:
- PHP-FIG: https://www.php-fig.org/psr
- Timber: https://www.upstatement.com/timber/
- Bedrock: https://roots.io/bedrock/
- Lumberjack: https://github.com/Rareloop/lumberjack
- Lumberjack Core: https://github.com/Rareloop/lumberjack-core
- Collections: https://laravel.com/docs/5.6/collections
- PHP-DI: http://php-di.org/
- Lumberjack Validation: https://github.com/Rareloop/lumberjack-validation
- Sessions: https://github.com/Rareloop/lumberjack-core/tree/ft-session
- Lumberjack Example Repo: https://github.com/Rareloop/lumberjack-example
- Laravel Responsable: https://laravel-news.com/laravel-5-5-responsable
Towards the end of 2015 Rareloop launched their WordPress starter theme Lumberjack, which built on open source tools such as Bedrock and Timber. We wanted to move Lumberjack forward inline with everything we have learnt over the years of using it - which meant completely re-writing it from the ground up. The new Lumberjack is now stable and ready for use!
This talk is aimed at anyone involved in working with WordPress, regardless of how technical you are. The beauty of Lumberjack is that you can use as much or as little as you like, so whether you’re new to web development or a seasoned software engineer there will be something here for you.
PECL Picks - Extensions to make your life betterZendCon
One of the biggest strengths of PHP is its "glue" power. Take any C library and with a little magic and a compiler you have a fantastic extension. These extensions hide in PECL, but few people can tell the good from the unmaintained or just plain broken. Find the best extensions for your project, learn about PECL, and find out how to become a part of the PECL developer community.
Supercharging WordPress Development in 2018Adam Tomat
Slide links:
- PHP-FIG: https://www.php-fig.org/psr
- Timber: https://www.upstatement.com/timber/
- Bedrock: https://roots.io/bedrock/
- Lumberjack: https://github.com/Rareloop/lumberjack
- Lumberjack Core: https://github.com/Rareloop/lumberjack-core
- Collections: https://laravel.com/docs/5.6/collections
- PHP-DI: http://php-di.org/
- Lumberjack Validation: https://github.com/Rareloop/lumberjack-validation
- Sessions: https://github.com/Rareloop/lumberjack-core/tree/ft-session
- Lumberjack Example Repo: https://github.com/Rareloop/lumberjack-example
- Laravel Responsable: https://laravel-news.com/laravel-5-5-responsable
Towards the end of 2015 Rareloop launched their WordPress starter theme Lumberjack, which built on open source tools such as Bedrock and Timber. We wanted to move Lumberjack forward inline with everything we have learnt over the years of using it - which meant completely re-writing it from the ground up. The new Lumberjack is now stable and ready for use!
This talk is aimed at anyone involved in working with WordPress, regardless of how technical you are. The beauty of Lumberjack is that you can use as much or as little as you like, so whether you’re new to web development or a seasoned software engineer there will be something here for you.
PECL Picks - Extensions to make your life betterZendCon
One of the biggest strengths of PHP is its "glue" power. Take any C library and with a little magic and a compiler you have a fantastic extension. These extensions hide in PECL, but few people can tell the good from the unmaintained or just plain broken. Find the best extensions for your project, learn about PECL, and find out how to become a part of the PECL developer community.
DSpace UI Prototype Challenge: Spring Boot + ThymeleafTim Donohue
Presentation of my user interface prototype (#1) using Spring Boot + Thymeleaf for the DSpace UI Prototype Challenge:
https://wiki.duraspace.org/display/DSPACE/DSpace+UI+Prototype+Challenge
NOTE: As this was just a prototype/proof-of-concept there are NO GUARANTEES that this work will become a new User interface.
This is the thirteenth set of slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
This is a presentation about Z-Ray technology made by Zend Technologies. It allows capturing tracing and debug information during PHP script execution.
code4lib 2011 preconference: What's New in Solr (since 1.4.1)Erik Hatcher
code4lib 2011 preconference, presented by Erik Hatcher of Lucid Imagination.
Abstract: The library world is fired up about Solr. Practically every next-gen catalog is using it (via Blacklight, VuFind, or other technologies). Solr has continued improving in some dramatic ways, including geospatial support, field collapsing/grouping, extended dismax query parsing, pivot/grid/matrix/tree faceting, autosuggest, and more. This session will cover all of these new features, showcasing live examples of them all, including anything new that is implemented prior to the conference.
This session starts by giving an overview of components of an Alfresco content model. We then examine the various forms of call-backs and hook-points available to the developer and give some examples of how these can be used to enforce custom business logic and model consistency.
Solr 4.0 dramatically improves scalability, performance, and flexibility. An overhauled Lucene underneath sports near real-time (NRT) capabilities allowing indexed documents to be rapidly visible and searchable. Lucene’s improvements also include pluggable scoring, much faster fuzzy and wildcard querying, and vastly improved memory usage. These Lucene improvements automatically make Solr much better, and Solr magnifies these advances with “SolrCloud.” SolrCloud enables highly available and fault tolerant clusters for large scale distributed indexing and searching. There are many other changes that will be surveyed as well. This talk will cover these improvements in detail, comparing and contrasting to previous versions of Solr.
Ant is a Java library and command-line tool. Ant's mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C++ applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks.
Ant is written in Java. Users of Ant can develop their own "antlibs" containing Ant tasks and types, and are offered a large number of ready-made commercial or open-source "antlibs".
Ant is extremely flexible and does not impose coding conventions or directory layouts to the Java projects which adopt it as a build tool.
Software development projects looking for a solution combining build tool and dependency management can use Ant in combination with Ivy.
The Solar Framework for PHP 5 (2010 Confoo)Paul Jones
This presentation is a whirlwind tour of the Solar framework for PHP 5. After a short bit of background, the presentation will outline the major concepts in Solar: everything is a library, the unified constructor, unified configuration, inherited configuration and localization, unified factory and adapter systems, lazy-loading registry, and the dependency-injection system. Next is an overview of how the dynamic dispatch cycle works in Solar, and how it compares to other framework dispatch cycles. From there we will move on to the SQL system, including the MysqlReplicated adapter, and lead into the ORM system. The ORM overview will briefly cover models, collections, records, automated filters, automated form generation, and more. After discussing the authentication layer, CLI tooling, and command-line controllers, it will wrap up with a brief discussion of Solar project architecture, and a short note on Solar's performance in relation to other popular frameworks.
DSpace UI Prototype Challenge: Spring Boot + ThymeleafTim Donohue
Presentation of my user interface prototype (#1) using Spring Boot + Thymeleaf for the DSpace UI Prototype Challenge:
https://wiki.duraspace.org/display/DSPACE/DSpace+UI+Prototype+Challenge
NOTE: As this was just a prototype/proof-of-concept there are NO GUARANTEES that this work will become a new User interface.
This is the thirteenth set of slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
This is a presentation about Z-Ray technology made by Zend Technologies. It allows capturing tracing and debug information during PHP script execution.
code4lib 2011 preconference: What's New in Solr (since 1.4.1)Erik Hatcher
code4lib 2011 preconference, presented by Erik Hatcher of Lucid Imagination.
Abstract: The library world is fired up about Solr. Practically every next-gen catalog is using it (via Blacklight, VuFind, or other technologies). Solr has continued improving in some dramatic ways, including geospatial support, field collapsing/grouping, extended dismax query parsing, pivot/grid/matrix/tree faceting, autosuggest, and more. This session will cover all of these new features, showcasing live examples of them all, including anything new that is implemented prior to the conference.
This session starts by giving an overview of components of an Alfresco content model. We then examine the various forms of call-backs and hook-points available to the developer and give some examples of how these can be used to enforce custom business logic and model consistency.
Solr 4.0 dramatically improves scalability, performance, and flexibility. An overhauled Lucene underneath sports near real-time (NRT) capabilities allowing indexed documents to be rapidly visible and searchable. Lucene’s improvements also include pluggable scoring, much faster fuzzy and wildcard querying, and vastly improved memory usage. These Lucene improvements automatically make Solr much better, and Solr magnifies these advances with “SolrCloud.” SolrCloud enables highly available and fault tolerant clusters for large scale distributed indexing and searching. There are many other changes that will be surveyed as well. This talk will cover these improvements in detail, comparing and contrasting to previous versions of Solr.
Ant is a Java library and command-line tool. Ant's mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C++ applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks.
Ant is written in Java. Users of Ant can develop their own "antlibs" containing Ant tasks and types, and are offered a large number of ready-made commercial or open-source "antlibs".
Ant is extremely flexible and does not impose coding conventions or directory layouts to the Java projects which adopt it as a build tool.
Software development projects looking for a solution combining build tool and dependency management can use Ant in combination with Ivy.
The Solar Framework for PHP 5 (2010 Confoo)Paul Jones
This presentation is a whirlwind tour of the Solar framework for PHP 5. After a short bit of background, the presentation will outline the major concepts in Solar: everything is a library, the unified constructor, unified configuration, inherited configuration and localization, unified factory and adapter systems, lazy-loading registry, and the dependency-injection system. Next is an overview of how the dynamic dispatch cycle works in Solar, and how it compares to other framework dispatch cycles. From there we will move on to the SQL system, including the MysqlReplicated adapter, and lead into the ORM system. The ORM overview will briefly cover models, collections, records, automated filters, automated form generation, and more. After discussing the authentication layer, CLI tooling, and command-line controllers, it will wrap up with a brief discussion of Solar project architecture, and a short note on Solar's performance in relation to other popular frameworks.
Organinzing Your PHP Projects (2010 Memphis PHP)Paul Jones
By using a single organizational principle, developers can easily make their project structure more predictable, extensible, and modular. The talk will discuss this one lesson, how it can be discovered from researching publicly available PHP projects, how to apply it, and how it is used (or not used) in well-known applications and frameworks.
Action-Domain-Responder: A Refinement of MVCPaul Jones
Using Model-View-Controller as a pattern to describe stateless HTTP interactions has always been a bit of a kludge. There simply hasn't been a better pattern web applications -- until now.
ADR (Action-Domain-Responder) represents a refinement of generic MVC as an application architecture specifically tuned to the web. In this talk, we will discuss various patterns of overall application architecture, including MVC, MVP, PAC, DCI, RMR, and others. We will find out how the ADR pattern arises from generic MVC, and how it provides a better description of how web applications actually work. Finally, we will go over examples of how to architect an ADR application, as well as how to convert from an MVC architecture to an ADR one.
Record HTTP interactions in your tests and replay them during future test runs for fast, deterministic and accurate tests. This is a PHP fork of the fabulous VCR for ruby library.
One definition of insanity is "doing the same thing over and over, expecting different results." In this talk, Paul will discuss how organizations keep treating developers poorly, especially by demanding overtime, and why it is crazy for developers to expect their organizations to change. Paul will show how you can change the way your organization treats you, to your own benefit and (hopefully) the benefit of the organization.
A case study about the PHP-VCR: How it is used at a big Symfony2 project together with Behat/Selenium/PhantomJS and what kind of pitfalls exist and how to tackle them.
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerPaul Jones
Using Model-View-Controller as a pattern to describe stateless HTTP interactions has always been a bit of a kludge. There simply hasn't been a better pattern web applications -- until now.
ADR (Action-Domain-Responder) represents a refinement of generic MVC as an application architecture specifically tuned to the web. In this talk, we will discuss various patterns of overall application architecture, including MVC, MVP, PAC, DCI, RMR, and others. We will find out how the ADR pattern arises from generic MVC, and how it provides a better description of how web applications actually work. Finally, we will go over examples of how to architect an ADR application, as well as how to convert from an MVC architcture to an ADR one.
This was my entities and fields presentation from Drupalcamp Colorado 2020.
http://drupalcampcolorado.org/sessions/drupal-7-entities-and-fields-transitioning-d7
Presentation for azPHP on setting up a new project using Zend_Tool. Also goes over creating basic modules, controllers, actions, models and layouts.
All code in the presentation has not necessarily been tested. Will update presentation when done.
In this lecture we look at the patterns in chapter 18 in the textbook (Patterns of Enterprise Application Architecture). The lecture is in two parts. First we go through each of the patterns and explain each.
Then in the second part we look at a problem we have to solve and try to get the patterns to show themselves at the time they are needed.
How to measure and optimize performance of applications that use Zend Framework 1.x. A talk presented at the New York City Zend Framework Meetup (http://www.meetup.com/ZendFramework-NYCmetro/) on August 23, 2011.
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)James Titcumb
You've heard of Zend's new framework, Expressive, and you've heard it's the new hotness. In this talk, I will introduce the concepts of Expressive, how to bootstrap a simple application with the framework using best practices, and finally how to integrate a third party tool like Doctrine ORM.
Multi-Tenancy is a critical component of any Software as a Service (SaaS) application, which enables one application instance to serve multiple organizations, or tenants. This presentation by Scott Crespo covers the basics of multi-tenant architectures, and how to implement multi-tenancy using Python, Django, and the open-source project known as Django Tenant Schemas.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfPeter Spielvogel
Building better applications for business users with SAP Fiori.
• What is SAP Fiori and why it matters to you
• How a better user experience drives measurable business benefits
• How to get started with SAP Fiori today
• How SAP Fiori elements accelerates application development
• How SAP Build Code includes SAP Fiori tools and other generative artificial intelligence capabilities
• How SAP Fiori paves the way for using AI in SAP apps
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™UiPathCommunity
In questo evento online gratuito, organizzato dalla Community Italiana di UiPath, potrai esplorare le nuove funzionalità di Autopilot, il tool che integra l'Intelligenza Artificiale nei processi di sviluppo e utilizzo delle Automazioni.
📕 Vedremo insieme alcuni esempi dell'utilizzo di Autopilot in diversi tool della Suite UiPath:
Autopilot per Studio Web
Autopilot per Studio
Autopilot per Apps
Clipboard AI
GenAI applicata alla Document Understanding
👨🏫👨💻 Speakers:
Stefano Negro, UiPath MVPx3, RPA Tech Lead @ BSP Consultant
Flavio Martinelli, UiPath MVP 2023, Technical Account Manager @UiPath
Andrei Tasca, RPA Solutions Team Lead @NTT Data
6. Frameworks: Bad!
•
PHP 3, PHP 4, and early PHP 5: “framework” a bad word
(“content management system” was ok)
•
Libraries and collections: phpLib, Horde, PEAR, PhpClasses, FreshMeat
•
Not unified in operation: different constructor signatures, different
method verbiage, different usage idioms, tough to combine
•
Started Solar (solarphp.com) in late 2004 as a library collection
(first of the PHP 5 E_STRICT collections)
7. Frameworks: Good! (Round 1)
•
Ruby on Rails (2004/5): “framework” suddenly acceptable
•
Agavi, Cake, CodeIgniter, ezComponents, Mojavi, PhpOnTrax, Symfony,
Zend Framework, many others
•
Tapped into developer needs, including tribal belonging and plugins
9. Frameworks: Good?
•
Delivered as a monolithic whole
•
Want to use just part of a framework? Difficult.
•
Download entire framework and try to use one part ...
•
... except it’s coupled to dependencies within the framework.
•
Have to set up parts you don’t care about.
•
Components (kind of): Symfony 2, Zend Framework 2
10. Definitions of “Decoupled”
•
In formal design, decoupling means to make the features of a formal system as
independent as possible from each other. — Ioannis T. Kassios, http://
link.springer.com/chapter/10.1007/11526841_5
•
Decoupling refers to careful controls that separate code modules from particular
use cases, which increases code re-usability. — https://en.wikipedia.org/wiki/
Object-oriented_programming#Decoupling
•
Cf. http://www.coldewey.com/publikationen/Decoupling.1.1.PDF
•
Framework-level and package-level decoupling, not class-level
12. Symfony 2
•
Symfony Components implement common features needed to develop websites.
They are the foundation of the Symfony full-stack framework, but they can also
be used standalone even if you don't use the framework as they don't have any
mandatory dependencies. — http://symfony.com/components
•
Symfony’s claim … is clearly true for 11 of those packages … clearly false for
4 of them … debatable for the remaining 6 …
— http://paul-m-jones.com/archives/4263
13. How To Tell
•
Composer.json has “require” for another package? Not decoupled.
•
Composer.json has “require-dev”? Might or might not be decoupled.
(Allowance for interface packages.)
•
“Optional behavior”? Still coupled. Could say the same for framework.
/** Symfony/Component/Routing/Loader/AnnotationClassLoader.php */
namespace SymfonyComponentRoutingLoader;
use
use
use
use
use
use
DoctrineCommonAnnotationsReader;
SymfonyComponentConfigResourceFileResource;
SymfonyComponentRoutingRoute;
SymfonyComponentRoutingRouteCollection;
SymfonyComponentConfigLoaderLoaderInterface;
SymfonyComponentConfigLoaderLoaderResolverInterface;
16. Rewrite Solar as Aura
•
Solar Framework: 5+ years old at the time (Oct 2010)
•
Monolithic; tough to use just parts of it
•
Independent, decoupled library packages
•
V1 (Oct 2010): extract components, PSR-0
•
V2 (Sep 2013): split packages even further, PSR-4
17. Driving Principles (1)
•
Libraries first, framework later
•
No use of globals within packages (e.g., pass in $_SERVER)
•
No dependencies on any other package
•
Tests and assets encapsulated within package
•
No “composer install" to run tests or get extra/optional functionality
•
Each has its own repository (no subtree splits or extract-and-build)
19. Driving Principles (2):
Dependency Injection
•
Solar used static Service Locator and universal constructor
•
In Aura, a shared Service Locator would mean a package dependency
•
All packages are set up for dependency injection
•
You can use any container you like (Aura.Di is nice ;-) or none
•
Pass Factory objects instead of using new (reveals dependencies)
25. How To Tell Dependency Injection
from Service Locator
•
Both build and retain service objects: usage, not implementation
•
Any DI container instance can be injected into an object
•
Any SL container instance can be kept outside an object
•
Providing static methods on Container: Service Locator
•
implements ContainerAware:
•
Container
Service Locator
parameter typehint: Service Locator
26. Dependency Injection > Service Locator
•
Service Locator hides dependencies
•
Service Locator is itself a dependency (all libraries need it)
•
Harder to write tests for objects using the Service Locator
•
DI reveals dependencies (especially with Factories)
•
Is not itself a dependency
•
Easier to write tests, fakes, etc.
•
Service Locator instance, if needed, on a per-package basis
28. Description
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.
30. Adding Routes
// add an unnamed route with params
$router->add(null, '/{controller}/{action}/{id}');
// add a named 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' => 'blog',
'action'
=> 'read',
'format'
=> '.html',
));
// add a REST route: BREAD+CUR
$router->attachResource('users', '/users');
31. Matching Routes
// 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 = $router->match($path, $_SERVER);
The match() method does not parse the URI or use
$_SERVER internally. This is because different systems may
have different ways of representing that information; e.g.,
through a URI object or a context object. As long as you
can pass the string path and a server array, you can use
Aura.Router in your application foundation or framework.
37. Old (v1) Description
Provides tools to build web page controllers,
including an `AbstractPage` for action methods, a
`Context` class for discovering the request
environment, and a `Response` transfer object that
describes the eventual HTTP response.
39. Important Parts
for incoming parameters
•
$this->params
•
$this->context
•
$this->accept
•
$this->response
•
$this->signal
•
$this->renderer
•
$this->data
•
(pre|post)_(exec|action|render)
for get, post, files, etc.
for content-type, language, encoding, etc
for headers, cookies, content (data transfer object)
for signals/events/notifiers (separated interface)
for rendering strategy (default “none”)
for data to be rendered
hooks, and catch_exception hook
40. Rendering Strategy
class NaiveRenderer extends AbstractRenderer
{
public function exec()
{
// get data from controller
$data = (array) $this->controller->getData();
// pick a template file based on controller action
$action
= $this->controller->getAction();
$__file__ = "/path/to/templates/{$action}.php";
// closure to execute template file
$template = function () use (array $data, $__file__) {
ob_start();
extract($data);
require $__file__;
return ob_get_clean();
};
// invoke closure
$content = $template();
// set content on response, and done!
$response = $this->controller->getResponse();
$response->setContent($content);
}
}
41. Way Too Much In v1
•
At first, all seemed to go together: base controller, page controller, action
method dispatch, event signals, request, response, rendering
•
Even with separated interfaces, all coupled to each other
•
Extract Aura.Dispatcher from Aura.Web, Aura.Cli, front-controller
•
No more need for “controller” or “rendering” code
•
All that remains is request and response for your own controllers
42. New (v2) Description
Provides web Request and Response objects for use
by web controllers. These are representations of the
PHP web environment, not HTTP request and
response objects proper.
43. Request Object
•
Not an HTTP request, but a web execution context representation
•
If you have $_SESSION or $_ENV in your request object, it’s not HTTP
•
Read superglobals, headers, cookies, negotiate accept values, etc.
•
Read/write on “params”
44. Response Object
•
Not an HTTP response, but a Data Transfer Object
•
Must convert it to a real HTTP response (does not “send itself”)
•
Allows any HTTP library, or none
45.
// typical full-stack controller, dependency injection
class MyAppController
{
public function __construct(
Request $request,
Response $response
) {
$this->request = $request;
$this->response = $response;
}
public function foo()
{
$bar = $this->request->post->get('bar');
$this->response->content->setType('application/json');
}
}
// typical micro-framework route+dispatch+logic, service locator
$app->addGet('/foo', function () use ($app) {
$bar = $app->request->post->get('bar');
$app->response->content->setType('application/json');
});
46. Delivery Code
// send status line
header($response->status->get(), true, $response->status->getCode());
// send non-cookie headers
foreach ($response->headers->get() as $label => $value) {
header("{$label}: {$value}");
}
// send cookies
foreach ($response->cookies->get() as $name => $cookie) {
setcookie(
$name,
$cookie['value'],
$cookie['expire'],
$cookie['path'],
$cookie['domain'],
$cookie['secure'],
$cookie['httponly']
);
}
// send content
echo $response->content->get();
49. Combinations Mean Dependencies
•
Front controller will need router, dispatcher, responder
•
Action controller will need services, request/response
•
Gateway services will need data source connection
52. Watch For Dependency/Coupling
•
Controller should probably be independent of routing, dispatching,
external base class (and vice versa)
•
Service Locators are especially binding
•
Micro-frameworks are antithesis of decoupling: closure is bound to
routing, dispatching, locator (and probably middleware system)
54. •
Background: Libraries, Frameworks, Components
•
Principles of decoupled library packages
•
Examples: individual Aura library packages
•
Limits to decoupling, direction of dependencies
55. Modernizing Legacy Applications in PHP
Are you overwhelmed by a legacy application full of page scripts,
spaghetti includes, and global variables? Do you want to improve the
quality of the code, but don’t know where to begin or how to proceed?
!
My new book, Modernizing Legacy Applications in PHP, gives step-bystep instructions on how to get your code under control and keep
your application running the whole time.
!
http://mlaphp.com
!
Buy the early access version now and get free updates as it is
completed, or sign up on the mailing list below for more information
and a free sample chapter.