Zeus Framework: Framework that reads annotation to route requests

Recommend this page to a friend!
  Info   View files Documentation   View files View files (22)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2021-10-02 (14 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 27 This week: 1All time: 10,328 This week: 189Up
Version License PHP version Categories
zeus-framework 1.0MIT/X Consortium ...5HTTP, PHP 5, Libraries
Description Author

This package implements a framework that reads annotation to route requests.

It provides a general HTTP request router class that can read a JSON configuration file to get the location of application classes that will handle the requests for each supported application URL pattern.

The framework router can read the application classes to parse their code and extract annotations.

The class annotations define the URL patterns that the respective class functions will handle.

The routing information extracted from the application classes is cached to avoid delaying the handling of the requests after the first time the application class annotations are processed.

Picture of Natanael Simões
  Performance   Level  
Name: Natanael Simões <contact>
Classes: 5 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Details

Zeus Framework

A lightweight framework with an annotation-based approach for routing.

Usage

Using annontation @Route you set a unique pattern. When Zeus detect this pattern in a request, redirects to properly class/method and execute it STATICALLY.

<?php

namespace MyBlog;

class Post
{

    / @Route("post/show/$id") */
    public static function show($id)
    {
        // code goes here
    }

    / @Route("post/create") */
    public static function create()
    {
        // code goes here
    }

    / @Route("post/edit/$id") */
    public static function edit($id)
    {
        // code goes here
    }

}

?>

Installation

This library can be found on Packagist. We endorse that everything will work fine if you install this through composer.

Add in your composer.json:

{
    "require": {
        "natanaelsimoes/zeus-framework": "0.1.0"
    }
}

or in your bash:

$ composer require natanaelsimoes/zeus-framework

You need to create 2 files on your project root folder: zeus.json containing Zeus configuration (see more at Configuration section below), and index.php just calling Zeus for the first time.

<?php
include_once 'vendor/autoload.php';
Zeus\Framework::start();
?>

Configuration

To configure Zeus, a zeus.json file needs to be created at project root folder. Following is the configuration file with all possible parameters.

{
    "database": {
        "driver": "mysql",
        "host": "localhost",
        "port": "3306",
        "dbname": "information_schema",
        "username": "root",
        "password": ""
    },
    "routes": {
        "initialDirectory": "src/",
        "index": "post"
    },
    "development": true,
    "cache": "xcache"
}

Database

Database connection is provided by Doctrine. Drivers supported are pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, pdo_sqlsrv, oci8.

If your project will not use any database, you can remove this parameter.

Routes

! This parameter is MANDATORY !

It tells the framework to look recursively inside initialDirectory for methods with @Route annotation. When no pattern is given by user (as for homepage), index informs what pattern to execute.

Development

! This parameter is MANDATORY !

Sets the project to development mode (if true) or production mode (if false)

Cache

If you need to use a cache system, in cache parameter inform which of the following will be used by framework: * apc (APC) * couchbase (Couchbase) * file (Filesystem, saved on /cache in root) * mem (Memcached) * mongodb (MongoDB, not implemented yet) * phpfile (PhpFile, saved on /cache in root) * redis (Redis) * riak (Riak, not implemented yet) * wincache (WinCache) * xcache (Xcache) * zend (ZendData) * none (No cache is used)

Cache is made currently based on URL. Inside the class/method you want to cache, do as follow:

/ @Route("post/create") */
public static function create()
{
    Zeus\Cache::getInstance()->getCache();
    // code goes here
    Zeus\Cache::getInstance()->setCache();
}

Method Zeus\Cache::getInstance()->getCache() verifies if there is a valid cache version of what user requested. If exists, prints and performs exit. If not valid (expired ttl) or not exists, continues generating the page normaly, then creates the cached version at Zeus\Cache::getInstance()->setCache().

If your project will not use cache, you can remove this parameter.

Testing

For testing you need to change parameter "url" in test.json providing HTTP path to test/ folder

  Files folder image Files  
File Role Description
Files folder imagesrc (7 files, 3 directories)
Files folder imagetests (5 files, 1 directory)
Accessible without login Plain text file apigen.neon Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageAnnotations (1 file)
Files folder imageCache (2 files)
Files folder imageCommon (1 file)
  Accessible without login HTML file 404.html Doc. Documentation
  Plain text file Cache.php Class Class source
  Plain text file Configuration.php Class Class source
  Plain text file Database.php Class Class source
  Plain text file Entity.php Class Class source
  Plain text file Framework.php Class Class source
  Plain text file Routes.php Class Class source

  Files folder image Files  /  src  /  Annotations  
File Role Description
  Plain text file Route.php Class Class source

  Files folder image Files  /  src  /  Cache  
File Role Description
  Plain text file CacheTime.php Class Class source
  Plain text file Dummy.php Class Class source

  Files folder image Files  /  src  /  Common  
File Role Description
  Plain text file Singleton.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagesrc (1 file, 1 directory)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Accessible without login Plain text file index.php Aux. Auxiliary script
  Accessible without login Plain text file test.json Data Auxiliary data
  Accessible without login Plain text file zeus.json Data Auxiliary data

  Files folder image Files  /  tests  /  src  
File Role Description
Files folder imagePost (1 file)
  Plain text file RoutesTest.php Class Class source

  Files folder image Files  /  tests  /  src  /  Post  
File Role Description
  Plain text file PostController.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:27
This week:1
All time:10,328
This week:189Up
For more information send a message to info at phpclasses dot org.