So, meet Aleph !
A new micro-framework for PHP, in size and functionality, which is appropriate comparison only with a medical scalpel.
The default contains everything you need to quickly start and write applications.
Reasons why you should pay attention to him:
- The framework is really small. Copiously spiked with phpDoc comments, the code takes about 3,000 lines;
- The framework is the result of more than 6 years of professional activity of its authors in the field of web-development;
- Framework features allow you to use it as a base for almost any application.
And Aleph is so far only the core of a full-fledged framework, already ready and used for a long time in real web applications. Publishing the rest of the system is just around the corner - you just fall in love with the opportunity to design and implement applications as if you did it in desktop programming (don't try to present it right now and immediately criticize, wait until you see it with your own eyes, and understand what I meant). There are ORM, and the system of controls (namely, controls, such as those in ASP.Net), validators, caching, templating, and everything that makes a set of auxiliary libraries a framework.
The kernel is written in php 5.3.0 and the code uses the features of the language that appeared in this version. The code is distributed under the MIT license, links to the githab and the website with the documentation and the forum - at the end of the article there is a bit of code, everything is commented, there is an explanation of the structure on the site.
')
Let's try to create an application using the framework to see it in action.
I recommend to begin acquaintance with the practical part by downloading an archive with ready source code and then at will - either we follow the train of thought or so we all understand and are happy that such code has been made publicly available, which means it can and should be used in current and future projects.

At the root of the project we see the following - the
index.php file, which is the single entry point into the application (I'm sure not to tell me about the contents of the adjacent
.htaccess ), the
lib folder, which contains the kernel itself (
aleph.php file) and a special script
requirements.php , the launch of which will tell you whether your system is ready to run applications based on Aleph. The
404.html file is
also in the root as an example of an error page template.

But the most interesting for us, of course, is the contents of the
app folder. No extra details:
cache folder - to store special cache files when selecting files in the caching configuration (comes with the kernel), and the
logs folder for system information logging service files. There are no hard restrictions (as well as restrictions in the framework in general) on the location and name of these folders is not imposed (all this is easily configured).
In the
engine folder are already directly files of our application.
As a demonstration, not a store, not a blog or even a todolist was chosen. Because when you look at blog implementation on% framework_name% or store implementation on% another_framework_name%, you involuntarily start to think “this is good, within the framework of the task, the framework behaves well, but how can I do what I need on it?”. Aleph does not answer these questions, he gives you a great tool to adapt to what you need. Remember about the guy who needed a hammer? (From the article
http://habrahabr.ru/post/141477/ ). So, php still uses hammers, and it makes practical sense, if you know what I mean.
First of all, we will demonstrate the capabilities of routing in the core. We all know perfectly well that regular expressions in skillful hands are great stuff, which is what routing uses. Let's look at the contents of the
index.php file:
<?php
The route map is an array whose keys are regular expressions that match the request, and the keys can contain variables (#method | ... #, #a | ... #) that will then be used as named parameters, and the values will be the corresponding methods classes.
Examples of valid calls, according to the routes:
http://demo.4leph.com/rom2dec/MMDCXCVIII (Roman translation to decimal)
http://demo.4leph.com/dec2rom/2012 (conversion from decimal to roman)
http://demo.4leph.com/sets/hab/ra/habr (generating variant sets from the specified data)
http://demo.4leph.com/akkerman/3/3 (calculation of the Ackermann function, parameter values are limited to maximum 3 and 3, the purpose of the method is to show the work with caching the results instead of the constant calculation)
http://demo.4leph.com/add/1243.454e+45/-2.45 (calculation by a simple calculator)
Naturally, instead of these, deliberately presented, academic examples could be, drunk,
/ product / 1532 / details / a-title-of-product , and even more, you can easily implement different issue on requests
/ product / 1532 / details / a-title-of-product ,
/product/1532/details/a-title-of-product.xml ,
/product/1532/details/a-title-of-product.json and in the same spirit. All this is very easy to implement, as you may have noticed.
Let us dwell on the implementation
$result = $a->route();
When requesting the form
demo.4leph.com/add/1243.454e+45/-2.45, the
Aleph \ Demo \ Arithmetic-> route method will be called with the parameters
'add' ,
'1243.454e + 45' and
'-2.45'. We are watching the implementation of the method (file
app / engine / arithmetic.php ):
<?php namespace Aleph\Demo; class Arithmetic extends Calculator { public function add($a, $b) { return $a + $b; } public function sub($a, $b) { return $a - $b; } public function mul($a, $b) { return $a * $b; } public function div($a, $b) { if ($b == 0) return 'Error: the second argument cannot be zero.'; return $a / $b; } }
The
Arithmetic class in turn inherits from the
Calculator class, which implements the
route method:
<?php namespace Aleph\Demo; class Calculator { public function route($method, $a, $b) { if (method_exists($this, $method)) { return call_user_func_array(array($this, $method), array($a, $b)); } return 'Error: method "' . $method . '" doesn\'t exist in class "' . get_class($this) . '"'; } }
It seems that everything is obvious and should not cause questions.
Notice that the
sets method takes as its only argument the string that goes after
sets / in the request, and processes this data on its own. The flexibility of the router is obvious, and in this form it is capable of using a minimum of actions to replace, for example, the
Yii route marshrutization, which is not an example more difficult, despite the fact that there the routes are rigidly fixed to the controllers and actions.
In addition to the routing, in the demo example the settings are loaded from the configuration file - this is the usual
ini file, the code is displayed in the configuration array. Often used practice, there are no tricks, good old
ini .
Among other things, the kernel provides support for caching, and the default kernel contains the implementation of caching on flat files. Adding new types of caching is available using the public interface.
More information about the kernel content on the official website, in the
Classes Directory and
Documentation sections.
Instead of conclusion
I would like to note once again that the published part is so far only the core. Do not rush into comparisons and ask what is better than well-known solutions, require performance tests and stuff. On the way to publishing and ORM and Page Object Model and everything else. When the php market is full of solutions made by some professionals for others, there is a lack of a solution made by professionals for non-professionals to make their work more professional.
Official siteGitHub RepositoryDemo exampleEmpty bye forum waiting for first visitors.