PHP Classes

Lean Framework PHP: General purpose Web application framework

Recommend this page to a friend!
  Info   View files Documentation   View files View files (35)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 253 All time: 7,885 This week: 455Up
Version License PHP version Categories
lean 1.0.0GNU General Publi...5.3PHP 5, Libraries
Description 

Author

This package is a general purpose Web application framework.

It consists of many small classes for all sorts of Web application purposes.

Currently it provides classes to implement MVC processing routes, dispatching controllers, accessing models, displaying views, retrieving configuration, logging events, authenticating users, generating HTML page elements, handling file uploads and downloads, formatting date, time and money values, etc..

Picture of Dyorg
Name: Dyorg <contact>
Classes: 1 package by
Country: Brazil Brazil
Age: ???
All time rank: 3974321 in Brazil Brazil
Week rank: 270 Up19 in Brazil Brazil Up

Documentation

Lean Framework PHP

Lean Framework is a tiny PHP framework (~40KB), modern frameworks are powerfull but so much complicated. With Lean I can construct apps really fast, using mvc, namespaces, autoloader, routes and more.

Requirement

PHP 5.3+

Basic structure

-- app
	-- main (module)
		-- controllers
			-- BasicController.php
		-- models
		-- views
			-- basic
				-- index.phtml
	-- secondary (other module)
		-- controllers
		-- models
		-- views
-- public_html
	-- css
	-- js
	-- img
	-- index.php
	-- .htaccess
-- settings
	-- Bootstrap.php
	-- Routes.php
-- vendor
	-- Lean
	-- autoloader.php

Easy configuration

create file index.php into public_html

<?php require_once '../settings/Bootstrap.php'; ?>

create file .htaccess into public_html to custom urls

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

create file autoloader.php into vendor directory, and use the Symfony Autoloader

<?php

require_once __DIR__ . '/Lean/Libs/Symfony/Component/ClassLoader/UniversalClassLoader.php';

/*
 * add new libs in autoloader is easy, clone libs in vendor directory and add array position, see example to Zend Framework and Amazon Web Service libs
 * $loader->registerNamespaces(array(
 * 		'Lean'     => __DIR__,
 *		'Zend'     => __DIR__,
 * 		'AWS'     => __DIR__
 * ));
 *
 * Just for now add only Lean Framework PHP lib, see below
 */
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->registerNamespaces(array(
	'Lean'     => __DIR__
));

$loader->useIncludePath(true);
$loader->register();

create file Bootstrap.php into settings

<?php
require_once '../vendor/autoloader.php';


/
 * errors
 */
error_reporting(E_ALL);


/
 * include path
 */
set_include_path(
	PATH_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 
	PATH_SEPARATOR . get_include_path());


/ 
 * locale e zone 
 */
date_default_timezone_set('America/Sao_Paulo');
setlocale(LC_ALL, 'pt_BR', 'pt_BR.iso-8859-1', 'pt_BR.utf-8', 'portuguese');


/
 * init lean framework
 */
Lean\Launch::instance()->run();

Create a controller

It's work, access in your browser http://localhost/lean_project/public_html

Remember, in your domain shows only www.yourdomain.com

<?php
namespace app\main\controllers;

class IndexController extends \Lean\App
{
	public function index()
	{		
		echo 'HELLO WORLD';
	}
}

Call non-default module, controller and method, type in your browser localhost http://localhost/lean_project/public_html/foo/product/do-something

Remember, in your domain shows only www.yourdomain.com/foo/product/do-something

<?php
namespace app\foo\controllers;

class ProductController extends \Lean\App
{
	public function do_something()
	{		
		/*
		 * your action here
		 */
	}
}

Using REQUEST object into controller

http://localhost/lean_project/public_html/foo/product?name=foo&category=bar&price=15

<?php
namespace app\foo\controllers;

class ProductController extends \Lean\App
{
	public function index()
	{		
		/
		 * get HTTP $_REQUEST
		 */
		$request = $this->request();
		$name = $request->name;
		$category = $request->category;
		$price = $request->price;
	
	
		/
		 * get only $_POST
		 */
		$request = $this->request()->post();		

		
		/
		 * get only $_GET
		 */
		$request = $this->request()->get();		

		
		/
		 * get only $_FILE
		 */		 
		 $request = $this->request()->file();		
		 
		 
		/*
		 * your action here
		 */
	}
}

Using Views

Create followings views index.phtml and edit.phtml into views

-- app
	-- foo (module)
		-- controllers
			-- ProductController.php
		-- models
		-- views
			-- product
				-- index.phtml
				-- edit.phtml
			-- layout
				-- header.phtml
				-- footer.phtml
				-- template.html

Create template.phtml in layout directory, you can include header and footer parts here

<html>
<head>
	<title>My new app</title>
</head>
<body>

	<? $this->app->view->render('layout.header') ?>

	<div id="container">
		<!--
		-- content page setted in controller will be render here
		-->
		<? $this->app->view->make('content') ?>
	</div>
	
	<? $this->app->view->render('layout.footer') ?>
	
</body>
</html>

Controllers shows yours views

<?php
namespace app\foo\controllers;

class ProductController extends \Lean\App
{
	public function index()
	{	
		/
		 * set the product/index.phtml to be render
		 */
		$this->view()->set('content', 'index');
		
		/*
		 * render the template
		 */
		$this->view()->render('layout.template');
	}
	
	public function edit()
	{	
		/
		 * this render file "../views/product/edit.phtml"
		 */
		$this->view()->set('content', 'edit');
		
		$this->view()->render('layout.template');
	}
}

Using routes

add into Bootstrap.php before launch Lean

...

/
 * routes
 */
Lean\Route::set_routes_path('settings/Routes.php');

/
 * init lean framework
 */
Lean\Launch::instance()->run();

Basic route

create file Routes.php into settings

<?php
use Lean\Route;

Route::set('foo/bar', function() {
	echo 'Hi';
});

Route to method in controller

<?php
use Lean\Route;

Route::set('product/do', array(
	'module' => 'basic', 
	'controller' => 'product',
	'method' => 'do_something'
));

Route to method in controller, same result as above but with clousure and call controller manually

<?php
use Lean\Route;

Route::set('product/do', function() {
	new app/basic/controllers/ProductController::singleton->do_something();
});

Simple alias

Route::alias('do-something', 'product/do');

Multiple alias

Route::alias(array('do-something', 'do-something2', 'foo', 'bar'), 'product/do');

License

Lean is released under MIT public license.

http://www.opensource.org/licenses/MIT

Copyright (c) 2014, Dyorg Almeida <dyorg.almeida@gmail.com>


  Files folder image Files  
File Role Description
Files folder image.phar (1 file)
Files folder imageFile (6 files)
Files folder imageFormat (3 files)
Files folder imageLibs (1 directory)
Files folder imageRequest (4 files)
Files folder imageSession (1 file)
Files folder imageUtils (4 files)
Accessible without login Plain text file .buildpath Data Auxiliary data
Plain text file App.php Class Class source
Plain text file Auth.php Class Class source
Plain text file Config.php Class Class source
Plain text file Format.php Class Class source
Plain text file Launch.php Class Class source
Plain text file Lean.php Class Class source
Plain text file Logger.php Class Class source
Plain text file Null.php Class Class source
Accessible without login Plain text file README.md Doc. Auxiliary data
Plain text file Request.php Class Class source
Plain text file Route.php Class Class source
Plain text file Session.php Class Class source
Plain text file Singleton.php Class Class source
Plain text file View.php Class Class source

  Files folder image Files  /  .phar  
File Role Description
  Accessible without login Plain text file stub.php Aux. Configuration script

  Files folder image Files  /  File  
File Role Description
  Plain text file Download.php Class Class source
  Plain text file Export.php Class Class source
  Plain text file Handler.php Class Class source
  Plain text file Image.php Class Class source
  Plain text file Remove.php Class Class source
  Plain text file Upload.php Class Class source

  Files folder image Files  /  Format  
File Role Description
  Plain text file Date.php Class Class source
  Plain text file Money.php Class Class source
  Plain text file Time.php Class Class source

  Files folder image Files  /  Libs  
File Role Description
Files folder imageSymfony (1 directory)

  Files folder image Files  /  Libs  /  Symfony  
File Role Description
Files folder imageComponent (1 directory)

  Files folder image Files  /  Libs  /  Symfony  /  Component  
File Role Description
Files folder imageClassLoader (1 file)

  Files folder image Files  /  Libs  /  Symfony  /  Component  /  ClassLoader  
File Role Description
  Plain text file UniversalClassLoader.php Class Class source

  Files folder image Files  /  Request  
File Role Description
  Plain text file Files.php Class Class source
  Plain text file Get.php Class Class source
  Plain text file Http.php Class Class source
  Plain text file Post.php Class Class source

  Files folder image Files  /  Session  
File Role Description
  Plain text file Namespace.php Class Class source

  Files folder image Files  /  Utils  
File Role Description
  Plain text file Hash.php Class Class source
  Plain text file Label.php Class Class source
  Plain text file Link.php Class Class source
  Plain text file Select.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:253
This week:0
All time:7,885
This week:455Up