taviroquai/architectphp

Architect PHP Framework a pragmatic approach in web development

v1.0.0 2014-03-04 18:48 UTC

This package is auto-updated.

Last update: 2024-10-08 08:13:14 UTC


README

Architect PHP Framework uses a pragmatic and modular Web development approach. The idea is to create a small API but with the most common features in web development.

Latest Stable Version Build Status Scrutinizer Quality Score Total Downloads

Online Demo

An online demo can be found in http://marcoafonso.pt/tests/architect/

Install

Look at demo repository at https://github.com/taviroquai/architect-demo/

Main features

  • Small API - You should not need to learn another language. All features can be called in the form app()->featureName(). Use IDE type hinting.
  • Modular and Events architecture
  • Theme slots configuration and Idiom strings are XML files (no programming skills required)

Common features

Most features can be called in 1 line of code, ie. app()->featureName(). If you prefer to use functions style, there are also core functions aliases. Se below.

  • Multiple themes
  • Multiple idioms
  • Routes with PHP5 anonymous functions
  • Events for inter-module actions
  • Fluent Interface DB queries - supports MySQL, PostgreSQL and SQLite
  • Flash messages
  • Application logging
  • Input validation and sanitization
  • Generic views as shopping cart, anti-span input field, file upload, datepicker, pagination, breadcrumbs, carousel, line chart, tree view, file explorer, leaflet map, comment form, automatic table/form from database tables, image gallery, poll and text editor
  • More to come...

This is an on-going work and there is not yet a stable version

Theme Configuration without programming skills

/theme/default/slots.xml

<config>
    <slot name="topbar">
        <module>
            <classname>LoginNavView</classname>
        </module>
    </slot>
</config>

Idiom configuration without programming skills

/idiom/en/default.xml

<items>
	<item key="TITLE">Architect PHP Framework</item>
</items>

API usage examples

All code has type hinting in ie. NetBeans IDE, so it's easy to start.

ALIAS

Architect framework is built using OOP but if you prefer to use functions code styling there are also core function aliases that may speed up development. The first letter gives an idea of what it does. Remember to use IDE type hinting to know how the alias works.

app() - Application. The main gate to access features
conf() - Configuration item. Returns a configuration item
view() - Returns the generic view factory
help() - Returns the helper factory
theme() - Loads a theme or returns current theme
session() - Sets or gets a session item
redirect() - Sends location HTTP header and save session before exit
filter() - calls Input to sanitize an input param
r() - Route. Adds a new route
c() - Content. Adds content to the default theme
u() - URL. Returns an internal URL. Use this to generate internal URLs
m() - Message. Adds a message to be shown to the user
i() - Returns all input parameters or just one from GET/POST
j() - JSON. Sets JSON output
o() - Output. Sets the application Output, ie. a View or plain text
f() - FILES. Returns a FILES entry by index
q() - Query table. Returns a Table instance to start querying
s() - Secure. Returns a secured (encrypted) string
e() - Event. Adds a new event
tr() - TRigger. Triggers the event
v() - View. Creates a new view. You can pass a template file path
l() - Layout. Creates a new layout - a view with layout slots operations

APP

app() // returns the application instance

ROUTER

r('/my/path/(:any)', function ($param) { ... }); // Adds a route callback

THEME

c('Hello World!'); // Adds content to default theme

URL

u('/demo', array('param1' => 'World')); // creates an URL

INPUT (GET / POST / RAW / FILES / CLI ARGS)

i('username'); // returns $_GET['username'] or $_POST['username']
f(0); // returns $_FILES['file'] or $_FILES['file'][0] for multiple

EVENTS

e('my.event.name', function($target) { ... }); // Register an event
tr('my.event.name', $target); // Triggers an event and passes a variable

CORE EVENTS

There are core events that allows to change application workflow without changing the core system. These are:

'arch.module.after.load'
'arch.database.load'
'arch.session.load'
'arch.theme.load'
'arch.action.before.call'
'arch.output.before.send'
'arch.session.save'
'arch.before.end'

IDIOM

$i = help()->createIdiom();  // tries to find a default idiom by session or input
$i->loadTranslation('filename', 'optional module name'); // loads a translation file
$i->translate('key', array('key' => 'World')); // returns translated key in filename
$i->t('TITLE'); // An alias to use in templates

SCREEN MESSAGES

m('An error has occured', 'css class'); // Adds a flash message
app()->flushMessages(); // Returns array. Remember to call flush in template

CAPTCHA

$v = view()->createAntiSpam(); // returns an HTML antispam element
$v->validate(); // validates antispam code (saved in session)

ENCRYPTION

s('secure this string'); // returns an encrypted string (crypt)

REDIRECT

redirect('http://www.google.com'); // redirects to an url

VALIDATION

$v = help()->createValidator();
$rules[] = $v->createRule('email', 'IsEmail', 'Invalid email message);
$result = $v->validate($rules); // more rules at /src/Arch/Rule/
app()->getSession()->loadMessages($v->getMessages());

HTTP

$curl = help()->createCurl('http://google.com'); // gets a Curl helper
$result = $curl->run(); // Gets the URL response
$curl->closeConnection(); // Closes the cURL handler

FILE UPLOAD

$v = view()->createFileUpload(); // Creates an upload field
$v->upload(f($index), '/var/www/architect/theme/data'); // uploads a file

DOWNLOAD

$helper = help()->createDownload('/var/www/architect/theme/data/image.jpg');
$helper->execute(); // forces a file download

DATABASE

q('user')->s()->w('id = ?', array(1))->run(); // select user where id = 1
q('user')->i(array('username' => 'admin'))->run(); // insert into user
q('user')->u(array('username' => 'guest'))->w('id = ?', array(1))->run(); // update
q('user')->d('id = ?', array(1))->run(); // delete from user where id = 1
q('user')->s('group.*')->j('usergroup', 'usergroup.id_group = group.id')->run(); // join

BREADCRUMBS VIEW

view()->createBreadcrumbs(); // returns a breadcrumbs view

DATEPICKER VIEW

view()->createDatepicker(); // returns a date picker view

PAGINATION VIEW

view()->createPagination(); // returns a pagination view

TEXT EDITOR VIEW

view()->createTexteditor(); // returns a text editor view

POLL VIEW

view()->createPoll(); // returns a poll view

LINE CHART VIEW

$data = array(
    array("x" => "2011 W27", "y" => 100),
    array("x" => "2011 W28", "y" => 500)
);
$chart = view()->createLineChart() // returns a new line chart view
    ->set('data', $data)
    ->set('labels', array('Sells'));

TREE VIEW

view()->createTreeView();

FILE EXPLORER VIEW

$explorer = view()->createFileExplorer();
$explorer->setPath($path);

IMAGE GALLERY VIEW

$gallery = view()->createImageGallery()
    ->setPath($path)
    ->setPathToUrl(conf('BASE_URL').$path); // relative url

MAP VIEW

view()->createMap();

CAROUSEL VIEW

view()->createCarousel(); // returns a carousel view

COMMENT FORM VIEW

view()->createCommentForm(); // returns a comment form view

FILE UPLOAD VIEW

view()->createFileUpload(); // returns a file upload view

AUTO TABLE VIEW

$config = array(
    'table'     => 'demo_user',
    'select'    => 'demo_user.*',
    'columns'   => array(
        array('type' => 'value', 'label' => 'Email', 'property'  => 'email'),
        array('type' => 'action',   'icon'  => 'icon-edit', 
            'action' => u('/demo/crud/'), 'property' => 'id')
    )
);
$v = view()->createAutoTable(); // returns an html table view
$v->configure($config, $db);
$v->setPagination($pagination);

AUTO FORM VIEW

$config = array(
    'table'     => 'demo_user',
    'select'    => 'demo_user.*',
    'action'    => u('/demo/crud/save'),
    'items'     => array(
        array('type' => 'hidden',   'property'  => 'id'),
        array('type' => 'label',    'label' => 'Email'),
        array('type' => 'text',     'property'  => 'email'),
        array('type' => 'breakline'),
        array('type' => 'submit',   'label' => 'Save', 
            'class' => 'btn btn-success inline')
    )
);
$v = view()->createAutoForm(); // returns an html form view
$v->configure($config, $db);

ROAD MAP (TODO)

January 2014 - Version 1.0.0-beta
February 2014 - Version 1.0.0