Aleph
, (*1)
, (*2)
Aleph is a very simple PHP framework for very small sites., (*3)
Installation
Install via composer:, (*4)
$ composer require lastguest/aleph
Or download only the framework file, (*5)
Or remote include the framework file: (needs allow_url_include = true in php.ini), (*6)
<?php
include "https://raw.githubusercontent.com/lastguest/aleph/master/src/aleph.php";
Documentation
### Boostrap
Include composer vendor/autoload.php, (*7)
<?php
include 'vendor/autoload.php';
or directly the aleph.php file in your front controller:, (*8)
<?php
include 'aleph.php';
### URL Routing
// The index route
get('/',function(){
echo "
Hello!
";
});
// Listen POST on /
post('/',function(){
echo "
Received POST Data:
";
print_r($_POST);
echo "
";
});
If you return an array or an object it will served as JSON, (*9)
get('/api/todos',function(){
return [
[ "id"=>1, "text"=>"Write documentation" ],
[ "id"=>2, "text"=>"Smile" ],
[ "id"=>3, "text"=>"Play more games" ],
[ "id"=>4, "text"=>"Conquer the World" ],
];
});
The response will be :, (*10)
[
{
"id": 1,
"text": "Write documentation"
},
{
"id": 2,
"text": "Smile"
},
{
"id": 3,
"text": "Play more games"
},
{
"id": 4,
"text": "Conquer the World"
}
]
### Database
Init database DSN
database('init','mysql:host=localhost;dbname=test','root','root');
Run query and get single column
$uid = sql_value('select id from users where username = ? limit 1', array($username));
Run query and get single row
$user = sql_row('select * from users where username = ?', array($username));
echo $user->email;
Run query and iterate all returned rows
sql_each('select * from users', function($user){
echo "<li><a href="mailto:{$user->email}">{$user->name}</a></li>";
});
Passing parameters:, (*11)
sql_each('select * from users where activated = ?', function($user){
echo "<li><a href="mailto:{$user->email}">{$user->name}</a></li>";
}, array('YES'));
Exec sql command
if ( sql('delete from users where id = ?',array(123)) ) echo "User deleted.";
### Service
The Service function is a small DI container., (*12)
Register a factory method
class TestService {
public $value;
function __construct($x){ $this->value = $x; }
}
service('test',function($x){
return new TestService($x);
});
Make service instances
$a = service('test',3);
$b = service('test',5);
[{"value":3},{"value":5}]
Register a singleton service
service('test',function($x){
static $instance = null;
return $instance === null ? $instance = new TestService($x) : $instance;
});
Now if we call multiple times the service('test') function we got the singleton instance every time :, (*13)
$a = service('test',3);
$b = service('test',5);
$c = service('test');
[{"value":3},{"value":3},{"value":3}]
======================, (*14)
Contributing
How to get involved:, (*15)
-
Star the project!
- Answer questions that come through GitHub issues
-
Report a bug that you find
Core follows the GitFlow branching model. The master branch always reflects a production-ready state while the latest development is taking place in the develop branch., (*16)
Each time you want to work on a fix or a new feature, create a new branch based on the develop branch: git checkout -b BRANCH_NAME develop. Only pull requests to the develop branch will be merged., (*17)
Pull requests are highly appreciated., (*18)
Solve a problem. Features are great, but even better is cleaning-up and fixing issues in the code that you discover., (*19)
Versioning
Core is maintained by using the Semantic Versioning Specification (SemVer)., (*20)
Copyright and license
Copyright 2014 Stefano Azzolini under the MIT license., (*21)
, (*22)