Showing posts with label PHP Frameworks. Show all posts
Showing posts with label PHP Frameworks. Show all posts

Monday, May 26, 2008

Jelix - PHP5 Framework

General informations

Jelix is a framework for PHP5, whose objective is to ease the development of applications or Web sites of any kind.

Here is what is proposed to developers:

  • API dealing with numbers of technical aspects: data access, MVC model, templates, output format generators (HTML, XUL,…), Web services (xml-RPC, json-RPC), forms generator, CRUD, authentication, rights management, localization, etc…
  • a modular structure and an organization of the files of the project, imposing a framework and some developing standards.
  • a “layer” organization of the project: presentation, coordination, service, business, persistence.

These characteristics allow a better re-use of the code, a capitalization of know-how, a better organization in the development, leading to a better productivity.

Jelix uses to the maximum of specificities of PHP5, in order to be the lightest and most powerful possible. This is why a project based on Jelix is 100% object oriented.

Features

Original functions and characteristics

  • Modular architecture : an application can be cut out in several reusable modules.
  • Minimal guarantee on the data exchange : Jelix controls the generation of output formats according to the type of request. For example, if we have a request for a XML-RPC web service, we cannot generate HTML, the answer will be obligatorily in XML-RPC. Si it offers a certain robustness of the application in client/server communication. (Unless the developer does not use objects from Jelix, because indeed nothing prevents from making an echo of anything anywhere).
  • Generation of technical errors in specified format : thanks to the Jelix system described before, all the technical errors are returned in the format awaited by the client. For example: no HTML formatted error when client is awaiting XML-RPC or RDF response.
  • Light and evolutionary template engine (jTpl), with a syntax halfway between Smarty and PHP. A plugin system like in Smarty is also available.
  • jDao, object-relational mapping, based on the DAO design pattern (Data Access Object). Declared in XML files, automatic generation of its SQL requests , handling of security problems (SQL injection etc…).
  • Designation of files and resources by selectors, and not by physical ways, then bringing a certain independence to a module towards the installation.
  • Event system allowing module-to-module communication.
  • Overload file : it is possible to redefine some files of a module without changing the originals (DAO, templates, properties). Useful when a module is used by several applications at the same time, or to facilitate the update of a third module.

Modern functions and characteristics

Functions that we don’t find so often in frameworks:

  • Web Services : Jelix deals with analysis of the content of requests, and the generation of the response. XML-RPC and JSON-RPC are handled. Other types of services Web are completely possible (SOAP,…).
  • Handling of RESTfull : by simple implementation of an interface: one can easily define what is done after HTTP GET/POST/PUT/DELETE requests.
  • Themes system: it is possible to define several templates, each one redefining the template of modules.
  • Automatic system for URL generation and mapping : no complete URL in Jelix. The framework has the responsibility to generate urls in the templates or elsewhere, according to the configuration of URL mapping defined on actions (mod_rewrite & co).
  • PHP scripts for code generation to execute in command liner, allowing fast creation of various files of a project (module, DAO, template, controller, etc)
  • Technical cache system : almost all non PHP files of a Jelix project “are compiled” in PHP in order to improve the performances (templates, DAO, events etc.).
  • UTF-8 compliant: it's the default encoding of the framework
  • Module dedicated to unit tests: unit tests are essentials to create a reliable application. So Jelix provide a module which has an interface to launch unit tests and a simple way to create unit tests (using simpleTest)

Traditional functions and characteristics

Functions which one finds in many frameworks:

  • The architecture of the core is MVC type (Model-View-Controller). A coordinator handles the execution of an action according to the parameters in the URL. The possible actions are implemented in classes of jController type (controllers).
  • Jelix provide several output generators (jResponse objects): XHTML, CSS, ATOM, RSS, XML, RDF, XUL, XUL overlay, ZIP, PDF (from Latex source files or with TCPDF). Others formats are also possible.
  • Database access abstraction layer: jDb relies on PDO or its own classes (when PDO is not available) to access to the databases.
  • Localization: you can have your application translated in several languages. Storage of localized string is done in properties files.
  • System of authentication and rights management.
  • Use of XML: declaration of the events, DAOs etc, … That makes it possible to facilitate writing, generation and modifying these parts of a project by third-party tools (for example with JelixEclipse, an eclipse plugin), and thus to increase productivity.

How does Jelix work

  1. an HTTP request calls Jelix. Jelix creates an instance of a jRequest object which contains datas of the request. It then create an instance of your controller which corresponds to the asked action.
  2. A method in the controller is executed. It retrieves request parameters in order to know which process to run.
  3. Then the method execute business processes and retrieves eventually some results which will be used for the response
  4. The method of the controller create an instance of a jResponse object which is setup with datas or else (initialization of templates etc..).
  5. Jelix gets this jResponse object, launch the generation of the final document (html page, pdf..) and then sends it to the browser.

Thursday, April 3, 2008

Model View Controller

Model View Controller

Model View Controller MVC is a time tested method of separating the user interface of an application from its Domain Logic.

The primary goal of MVC is to isolate UI changes and prevent them from requiring changes to the Domain Logic of the application.

The primary reason for this division is that the user interface and Domain Logic have different drivers for change and different rates of change. By making this separation, you can change the UI without touching the Domain Logic and vice versa.

MVC is sometimes confused with other patterns that have the same goal of separating user interface from Domain Logic, such as Presentation Abstraction Control.

MVC divides an application into three concerns:

  • Model - Encapsulates core application data and functionality Domain Logic.
  • View - obtains data from the model and presents it to the user.
  • Controller - receives and translates input to requests on the model or the view.


The separation into three concerns is inspired by a information processing model where the controller represents system input, the model represents processing and the view represents the output of the system.


Model

The model encapsulates the functional core of an application, its Domain Logic. The goal of MVC is to make the model independent of the view and controller which together form the user interface of the application. An object may act as the model for more than one MVC triad at a time.

Since the model must be independent, it cannot refer to either the view or controller portions of the application. The model may not hold direct instance variables that refer to the view or the controller. It passively supplies its services and data to the other layers of the application.

See Domain Model and Transaction Script to organize Domain Logic.


Passive Model

With a passive model, the objects used in the model are completely unaware of being used in the MVC triad. The controller notifies the view when it executes an operation on the model that will require the view to be updated.

The passive model is commonly used in web MVC. The strict request/response cycle of HTTP does not require the immediacy of an active model. The view is always completely re-rendered on every cycle, regardless of changes. This may be especially true in PHP where no state is retained between requests.

Active Model

In the active model, model classes define a change notification mechanism, typically using the Observer pattern. This allows unrelated view and controller components to be notified when the model has changed. Because these components register themselves with the model and the model has no knowledge of any specific view or controller, this does not break the independence of the model.

This notification mechanism is what provides the immediate updating that is the hallmark of a MVC GUI application.

Model Adapter

It is possible to use an Adapter to add change propagation or other active model features to passive model objects, turning a passive model into an active model.


Presentation Model

The purpose of MVC is to separate UI from domain logic. In doing so, an MVC implementation typically develops a set of reusable classes for each of the concerns in the triad. Sometimes, data or behavior that firmly belongs on the user interface side of the division can conveniently be represented using the infrastructure of the model side of the division. Thus objects that would appear at first glance to be in the model are really part of the interface concern, that is the view and controller.

Some examples include scrollbar positions and column sorting.

This is sometimes called an Application Model and the pattern known as MMVC after the idea that there are two separate models.


View

The view obtains data from the model and presents it to the user. The view represents the output of the application.

The view generally have free access to the model, but should not change the state of the model. Views are read only representations of the state of the model. The view reads data from the model using query methods provided by the model.

With an Active model, the view can register itself to receive notifications when the model changes, and the view can then present a more up to date version of the model.

Sometimes generic reusable view components can be arbitrarily connected to the model in a process known as binding.

See Template View and Transform View for strategies of implementing views.


Controller

The controller receives and translates input to requests on the model or view.

The controllers are typically responsible for calling methods on the model that change the state of the model. In an active model, this state change is then reflected in the view via the change propagation mechanism. In the passive model, the controller is responsible for telling the view when to update.

In MVC, The controller is NOT a Mediator between the view and the model. The controller does not sit in between the model and the view. Both the controller and the view have equal opportunity to access the model. The controller does not copy data values from the model to the view, although it may place values in the model and tell the view that the model has changed. see Presentation Abstraction Control where the control layer acts as a mediator between Presentation and Abstraction.

The word controller is overloaded with different meanings in various patterns. see what is a Controller Anyway There are several of these controller patterns: Front Controller A single point of dispatch for incoming http requests. Page Controller Controls the flow of logic of a single web page. Application Controller Controls the flow of logic of a single application.

Because the popular MVC framework Java Struts from a PHP Perspective implements a combined Front Controller and Application Controller, some people assume that this is what is meant by the MVC pattern in the context of a web application. For the same reason, many descriptions of the Front Controller pattern on the web do not draw the distinction between a Front Controller and a Application Controller.


Relationships between components


View Controller Relationship

In traditional smalltalk MVC, views and controllers are tightly coupled. Each view instance is associated with a single unique controller instance and vise versa. The controller is considered a Strategy that the view uses for input. The view is also responsible for creating new views and controllers.

It is logical that views and controllers are strongly related, the input and output of an application is strongly related. In most GUI MVC frameworks, the view and controller are simply merged into one object. This is called Document View. The view and controller are combined as the view. The model becomes known as a document.

A passive model shifts more responsibility into the controller, as it must notify the views when they should update.

The modern web usage of MVC shifts even more of the traditional responsibilities of the view to the controller. The controller becomes responsible for creating and selecting views and the view tends to lose responsibility for its controller.

Sometimes responsibility for creating and selecting views is delegated to a specific object, this is known as the Application Controller pattern for web MVC and View Handler for GUI MVC.

The rigid request/response cycle of HTTP may make the Document View variant less popular in web applications than in GUI applications although the controller is still strongly related to the view. The HTTP request is handled by the controller, the processing to the model, and the response is handled by the view.


Model View Relationship

The view depends on the model. Changes to the model interface require parallel changes in the view.

It is very difficult to achieve a strict separation between the model and view. For example, consider the requirement “Show negative balances in red.” At first glance, this appears to be strictly an output requirement and a test might be placed into the view in roughly this form:

if balance <>

This would violate the separation of concerns in MVC. Upon further analysis it turns out that the real requirement is “show overdrawn balances in red” and the definition of overdrawn =balance < 0= should be placed in the model as that is domain specific. It is very easy for domain logic to migrate out of the model and into the view. Template View contains further discussion of this issue.


Model Controller Relationship

The Controller depends on the model. Changes to the model interface may require parallel changes to the controller.


Scale and Granularity

The MVC pattern is applicable at many different scales in an application. At the lowest level, an object oriented implementation involves three objects two with Document View. Although three objects are involved, only a portion of each object may be involved in any given MVC triad at the smallest scale. For example, a checkbox view/controller component operates on a data value from a model object. MVC is the easiest to understand and implement at the lowest level of granularity.

These small triads can be combined and composed into larger and larger triads. checkboxes and text fields into panels, panels into windows, windows into applications, etc. At each level, the separations mandated by MVC are maintained. At the higher levels, each concern might be considered a layer or package containing specific classes.

If the MVC separations are maintained at the lowest scale, it should follow that they are maintained on every higher scale.

If the three MVC concerns were simply separated into three classes for a non-trivial example, each of those classes would end up as a Big Ball Of Mud and would hardly be re-usable. Others patterns should be applied to structure the individual concerns of MVC.


Structuring views

Composite View.

The Composite pattern can be applied to the view giving it a hierarchical structure. This pattern is known as Composite View. Views are easy to decompose by partitioning the visual output of the application into nested rectangles that form the composite hierarchy.

This partitioning of the view layer creates smaller more focused view components which have more opportunity for re-use.


Structuring controllers

Because the controllers are so closely related to the view, they can also be partitioned with a parallel hierarchy to the Composite View. This is common with GUI MVC. One advantage of the Document View variant is that it is unnecessary to maintain two parallel hierarchies in this case.

The Command Pattern pattern is often used to structure the controller concern of the MVC triad. A specific set of model/view interactions is encapsulated into a command object, often called an action in the web MVC. This is commonly used in GUI MVC as well as Web MVC.

An action should not be confused with a Transaction Script. Just as it is easy for Domain Logic to bleed into the view, it is also easy for Domain Logic to bleed into the actions of the controller layer. Actions should translate input into requests on the model, create or select views, and generally provide user interface oriented services.

Actions promote reuse. They can be parameterized.

In any structuring of the controller concern, Input must be distributed to the correct controller sub components. In a GUI application, the Chain of Responsibility pattern is used along with the visual hierarchy defined by the Composite View to route input to the correct controller. _how to route input in web MVC?


Structuring models

The Domain Model and Transaction Script patterns are used to organize Domain Logic.

The Command Pattern pattern can be used in organizing Domain Logic, often as a way of implementing a Transaction Script. Using the Command pattern can promote re-use of domain logic, especially when parameterized.


Platform Independence

Typically each concern of the MVC triad has ties to a specific platform. It is possible to isolate these platform dependencies from the platform independent portions of the application by splitting each concern using the Bridge pattern.

The Context Object Pattern provides platform independence from the web server for the user interface view and controller of a web application.

The Data Access Object provides platform independence from the database server for the model of an application.


Benefits of MVC


Substitutable user interface

Different views and controllers can be substituted to provide alternate user interfaces for the same model. For example, the same model data can be displayed as a bar graph, or a pie chart, or a spreadsheet.

Some examples: Read only UI Expert and novice specific UI Different human languages Alternate input mechanisms User specific themes Alternate output formats XML, HTML, etc Alternate form mechanisms HTML forms, XForms, PDF forms


User interface components

Because MVC demands that the user interface of an application be structured into a hierarchy of objects and defines a standard relationship between these objects, generic versions of these objects are possible. They are usually called user interface components and no modern GUI environment is without a full complement of them usually combining view and controller into a single object. WACT is an attempt to provide a similarly rich set of components for web development that maintain the separation between view and controller. components promote reuse and reduce the need for special subclasses. These are known as “pluggable views” in the smalltalk MVC literature.


Multiple simultaneous views of the same model

Multiple different views can be active at the same time. Each view simultaneously and independently presents the same information from the model. This applies more to GUI MVC than web MVC.


Syncronized views

The change propagation mechanism insures that all views simultaneously reflect the current state of the model.


Easier user interface changes

Changes affecting just the user interface of the application logic become easier to make.


Easier testing

With MVC it can be easier to test the core of the application, as encapsulated by the model.


Drawbacks of MVC


Increased complexity

If reading this page doesn’t convince of you the complexity of this pattern, consider all of the auxiliary patterns that co-occur with MVC.


Close coupling of views and controllers to model

Changes to the model interface require parallel changes in the view and may require additional changes to the controller. certain code changes become more difficult.


Potential for excessive updates

The change propagation mechanism can be inefficient when frequent model changes require many change notifications. This is generally not as much of a problem if a passive model is used.


Close coupling between view and controller

strict separation is difficult if not impossible.


What goes where?

A common question about web MVC is “where does this go?” This question arises from the desire to concretely divide every portion of an application into one portion of the triad. In practice, however, a strict separation of concerns into three parts is difficult to achieve, perhaps impossible. The difficulty of separating view and controller is discussed in the Document View variant. Perhaps the effort to achieve strict separation exhibits diminishing returns and is simply not worth pursuing to the fullest extent.

_talk about how user interface models and domain logic bleed into the view and controller add to the confusion._

_Mediator based definitions of MVC also add to the confusion._

That said, the best guide to partitioning the application is to follow the input, processing, output form of the pattern.


When NOT to use MVC

The need to separate domain logic from presentation is almost an unquestioned axiom of object oriented design. Yet, many successful projects have not done this at all. Standard usage of PHP freely mixed UI and domain logic. Microsoft’s .NET architecture encourages domain logic to be mixed with user interface. Many successful software packages have been written without using the MVC pattern. see Separate Domain From Presentation for an alternate viewpoint.

Implementing MVC is complex and difficult. Following the You Aren't Going to Need It principle, one might hold off implementing MVC in an application until a need for one or more of the benefits of MVC manifests itself. Carefully weigh the benefits and drawbacks of using MVC before implementing this pattern in your application.

PHP Frameworks

MVC Frameworks Written in PHP

Frameworks for implementing the Model View Controller pattern in PHP

Framework Modeled after Notes
Web Application Component Toolkit - You are on the WACT web site.
Limb PHP Web Application Framework - PHP Web Application Framework
EZ Publish - -
LogiCreate - -
Mojavi - -
Navigator - PHP4/PHP5 MVC framework which uses “Inversion of Control” pattern. This framework is attended to provide maximal flexibility for developers.
Phrame Java Struts from a PHP Perspective -
phpDrone (wiki)- phpDrone is a open-source PHP framework for php5 or higher that incorporates a lot of features that will help PHP programmers in the process of web development.
ZNF - PHP5 MVC framework for enterprise web applications
Achievo ATK - -
Akelos PHP Framework Ruby on Rails A Ruby on Rails port to PHP. Additionally supports multilingual models and views, url rewriting, database migrations, interactive console, Pure PHP support for Unicode, Code Generators, Built in XHTML validator, Automated locale management, Ajax file uploads... feature list
AModules3 AModules2, Java*, Cocoa AModules3 application code might look more like Java code instead of PHP. Framework fully use potential of PHP5. It has conceptually proper MVC implementation, support for multiple APIs and fully OOP design makes it very good choice for writing serious applications. Most importantly - it’s been stable since 2006 February and heavily used in commercial and free applications. See presentation of AModules3 and explanation how it fits into Web
Ambivalence Maverick -
Aukyla PHP Framework - Nice ideas: Local URI’s (stream wrappers) and OpenDocument file handling. Released under a dual GPL/Commercial license.
Binarycloud - -
Biscuit Ruby on Rails Similar to Cake only using much more procedural code (rather than OO). BSD licensed.
bitweaver - bitweaver is a highly modular application framework for content management. It is a fully functional web application and feature rich CMS. It is truly open source, community driven, object oriented, and written in PHP. It uses Smarty Templates and ADOdb to support many databases including Postgres, Firebird, Oracle, and MySQL.
Caffeine Web Framework - Lightweight framework that uses whitebox approach to coding. Features pure-PHP templates and config files, as well as usable ORM implemented in just 2 classes. Quite simple (for the most part). BSD licensed.
Cake Ruby on Rails A Ruby on Rails like framework for PHP. MIT licensed.
Castor - -
Cgiapp CGI:: Application Cgiapp is a port of the perl library CGI::Application. Instead of providing a full MVC framework, it provides a framework for creating controller classes that have templating hooks. The default template engine used is Smarty, but users have used Savant with it successfully.
CodeIgniter RoR Small framework, but very promising
Copix - -
Core Enterprise PHP - Core Enterprise PHP (CEP) is a modular application framework designed to allow rapid application development of large application mande up of re-usable components.
FastFrame - -
Fusebox Ported from ColdFusion An extremely popular framework in the ColdFusion community, ported to PHP some time ago and actively supported in both languages.
FuseLogic - -
Kohana Code Igniter -
Konstrukt HTTP Focuses narrowly on the controller-layer.
Kumbia - Spanish Framework MVC Full Support and other patterns
Krysalis Cocoon -
Inek Java Struts from a PHP Perspective Inek Framework is designed around PEAR, using HTML_Quickform, DB, Config, Log and Smarty
InterJinn - -
Ismo - -
Jelix - highly extensible and modular PHP 5.2 MVC framework designed for huge loaded web site, with cool features like an ORM, a light-weight template engine, a powerful form system, ACL, authentification, Ajax & web services supports etc.
Medusa - -
Nexista - Nexista is an Open Source php/xml/xslt based development framework for building robust and scalable web applications. Focus is on applying REST philosophies to application APIs.
P4A MVC PHP 4 Applications (P4A) is a PHP RAD and object oriented PHP framework for building event-driven stateful web applications. It features tableless HTML, accesskey support, auto data type recognition, transparent AJAX, UTF-8, i18n/l10n, PEAR integration. PHP4 support is being phased out.
PHP on Trax Ruby on Rails A True Ruby on Rails framework clone for PHP (PHP5 and PHP4).
PHPulse - Fast templating MVC framework which handle the minutia of front end development such as form processing, HTML generation and templating thus leaving the developer to only worry about developing the application. Built-in templating engine, modular development and the fastest pageload time of any web framework.
PhpMVC Java Struts from a PHP Perspective -
phpPeanuts - Dynamic Scaffolding Application Framework. It doesn’t do just CRUD, relations and searching are also scaffolded (user interface and ORM). Favors default reasoning and the ‘once and only once’ principle. Adapts dynamically to changes in meta data.
Popoon Cocoon -
Prado .NET, Delphi PRADO is a component-based and event-driven programming framework for developing Web applications in PHP 5.
Qcodo - A code generation-based framework for PHP5. Generates your object relational model (CRUD objects) as WELL as simple CRUD-based pages which can be extended/customized. Code can be regenerated without destroying customizations. Presented at MySQL User’s Conference as well as the Zend/PHP conference in 2005.
rwfphp - PHP Reusable Web Framework - rwfphp for short. Basic framework to create bigger framework/custom apps with.
Sapphire / SilverStripe RoR and CMS systems Requires PHP5.2 to provide allow for object-oriented language features found in Ruby and Python, has SilverStripe CMS on top, providing Web2.0 style admin system built to manage basic and complex websites effectively, and has out of the box modules (shop, forum, blog, etc). A few months after launch, it was included in Google Summer of Code and voted a finalist in PacktPub Open Source CMS Awards.
Seagull best practices Concise OOP framework, builds on PHP‘s strengths, integrated with PEAR libraries, 10+ CMS modules included, includes tools for deploying and maintaining apps
Sitellite - -
SolarPHP - A PHP5 Web Framework. MVC-based.
sQeletor - (A PhpMVC extension, It has not yet its own web, but you can download the source code and API)
Studs Java Struts from a PHP Perspective -
struts4php Java Struts from a PHP Perspective struts4php is an application framework for PHP which is designed with the MVC pattern. It implements only the controller and lets the developer decide how to implement the model and the view.
symfony Mojavi, Propel, Ruby on Rails just another php5 framework ? Probably not. It takes the best of Mojavi, Propel and Rails, adds some more and packages it all into an integrated framework. MIT licensed.
TaniPHP Ruby on Rails PHP MVC Ruby on Rails like framework for PHP. LGPL licensed.
Tigermouse Active Record, Table Gateway LGPL licensed PHP/AJAX framework for development highly interactive web applications. It is designed to build large web applications rather than just web pages. With Tigermouse you are not forced to write JavaScript.
web.framework - web.framework is an MVC framework for PHP5. It features actions and action-chains, the ability to call to other actions or action-chains from an action-chain, pre- and post-actions with exceptions, validators for simple check forms, support for DB configuration in framework configuration, support for template systems (such as web.template and Smarty), a router for making URLs nice-looking, tokens, authorization frames, AJAX, clinet-side validation and many more.
Wolfden CMF - -
Yellow Duck Framework - An object oriented framework for PHP web application. Include Ajax forms construction and validation, easy files and images handling, dblayer, XML/RPC clients and servers, syndicated XML feeds such as RSS and Atom. Small community but impressive demo available at deployment.
Zend Framework - PHP5-MVC-Framework with a lot of extensions like PDF, Mail, ...
Zephyr Framework - Ajax based MVC framework for PHP5 developers. You can easily develop ajax applications with business layer within minutes.
Zoop Framework - The most unique of all php frameworks, Zoop features GuiControls (a PHP implementation of .net’s webcontrols), AJAX support and integration, automatic form validation and creation (including db integration), a Smarty templating system, PDF creation, session handling, and SMTP template-based email sending.
QPHP.NET ASP.NET - like, Code behind approach Object oriented, event driven, component based, with AJAX and I18N support. Very good documentation and plenty of examples.