Download the PHP package firelit/framework without Composer
On this page you can find all versions of the php package firelit/framework. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download firelit/framework
More information about firelit/framework
Files in firelit/framework
Package framework
Short Description Simple PHP framework and helper classes for web projects
License MIT
Informations about the package framework
Firelit-Framework
Firelit's standard PHP framework provides a set of helpful classes for developing a website. They are created and namespaced so that they can easily be used with an auto-loader, following the PSR-4 standard.
Requirements
- PHP version 5.4.0 or higher
- PHP version 5.6.0 or higher for testing
External PHP Extensions:
- OpenSSL extension (required for
Crypto
andCryptoKey
class) - cURL extension (required for
HttpRequest
class) - Database-specific PDO extension (e.g.,
pdo-mysql
, required forQuery
class)
How to Use
The easiest way to use this library is to use Composer which automatically handles dependencies and auto-loading.
Here is an example of how you'd add this package to your composer.json
under the require key:
You could also add it from the command line as follows:
Alternatively, you could go the manual way and setup your own autoloader and copy the project files from lib/
into your project directory.
MVC Architecture
This framework comes with classes to support building apps with the MVC architecture.
Firelit\View
classFirelit\Controller
classFirelit\DatabaseObject
(i.e., model) classFirelit\Router
class (see example below)
An example implementation using these classes in a single entry web app:
Note that this setup is considered single-entry so there must be a slight modification to web server to force it to use the main script (e.g., index.php) for all HTTP requests. Here's an example .htaccess
(from the WordPress project) that will configure Apache to route all requests to a single entry script.
Classes Included
ApiResponse
A response-handling class for API end-points. Can handle all HTTP response codes and JSON & limited XML. Set a template to ensure some fields are always sent back with the response.
Example usage:
Cache
A caching class. First uses php-memory cache (a global PHP variable) and configurable to use memcached second. The static variables $cacheHit
and $cacheMiss
are set after each cache check.
Example usage:
Controller
A minimal class to wrap controller logic. Extend to add additional controller-common methods and static data. It also has a "handoff" function call to simplify invocations to Controller objects.
Handoff syntax:
Firelit\Controller::handoff(ControllerClassName [, OptionalMethodName [, MethodParamater1 [, ... ]]])
Crypto Classes
Crypto, CryptoKey and CryptoPackage are encryption/decryption helper classes using OpenSSL (used in lieu of mcrypt based on this article). These classes can generate cryptographically secure secure keys and encrypt and decrypt using industry-standard symmetric encryption (RSA) and private key encryption (AES) schemes.
Note that AES encryption will not work for large strings (80 characters or more, depending on key bit size) due to the amount of processing power it takes -- it quickly becomes inefficient. For larger strings, the plain text should be encrypted with RSA and the encryption key should be encrypted with AES. This is exactly what CryptoPackage does for you on top of serializing/unserializing the subject to quickly store and retrieve variables of any type (string, object, array, etc) in an encrypted store.
Example encryption/decryption usage:
DatabaseObject
This class is a schema-less, active record-like class for creating, retrieving and manipulating a database row as an object. To set it up, extend the class for each table, specifing the primary key row and other special-value rows (e.g., serialized rows, date/time rows, etc.) to enable built-in pre-store and post-retrieval value manipulation.
HttpRequest
A class to manage new HTTP requests to external web services and websites. Includes file-based cookie support.
Example usage:
Query
A database interaction class and SQL query creator. Makes database connection management and SQL authoring slightly easier.
Example usage:
Use the config method to setup the database connection:
config( $configArray );
Available methods for building and executing queries:
query( $sql, [ $dataArray ]);
insert( $tableName, $dataArray );
replace( $tableName, $dataArray );
select( $tableName, [ $selectFieldsArray, [ $whereStatement, [ $whereDataArray, [ $limit, [ $range ]]]]] );
update( $tableName, $dataArray, $whereStatement, [ $whereDataArray, [ $limit, [ $range ]]] );
delete( $tableName, $whereStatement, [ $whereDataArray, [ $limit, [ $range ]]] );
Available methods for getting the status and/or results of a query:
getRes();
returns true if the query was successfully executedgetRow();
returns the next data row from a successful select querygetAll();
returns all the data rows from a successful select querygetNewId();
returns the new ID from newly-inserted data rowgetAffected();
returns the number of rows affected by the querygetNumRows();
returns the number of data rows returned by a select query (not reliable for all databases)getError();
returns the error messagegetErrorCode();
returns the error codesuccess();
returns true if the query was successfully executedlogError(LogEntry $logger, $file, $line);
is a helper method for logging any query errors
QueryIterator
A PHP iterator that allows for a Query result set to be passed around without actually pre-retrieving all results. The QueryIterator object can then be used in a foreach
loop, where it fetches the next row needed on-demand.
Example usage:
The QueryIterator constructor takes two parameters, the second optional: The Query object and the object into which the table row should be fetched.
Request
A class that captures the incoming HTTP request in a single object and performs any necessary preliminary work. Provides a nice class wrapper around all the important parameters within the request and allows for easy sanitization.
Example usage:
Example usage:
Available properties:
cli
will return true if the page was loaded from the command line interfacecookie
will return all data (filtered, as specified) originally available via $_COOKIEget
will return all data (filtered, as specified) originally available via $_GETheaders
will return an array of all HTTP headers by key (if Apache is the web server used)host
is set to the host as secified in the HTTP requestmethod
is set to the HTTP request method (eg, 'POST', 'PUT', etc.)path
is set to the requested path (eg, '/folder/test.php')post
will return all data (filtered, as specified) originally available via $_POSTprotocol
will return the request protocol (eg, HTTP 1.0 or HTTP 1.1)proxies
will return an array of IPs that may be in use as proxiesput
will return all data (filtered, as specified) in HTTP body (if PUT request)referer
will return the HTTP referer as specified by the clientsecure
will return true if the connection is secure (ie, 'HTTPS://')uri
will return the full URI of the request, including HTTP or HTTPS
Response
A class that manages the server's response to an incoming requests. Defaults to buffering output. Includes helper functions which make changing the HTTP response code and performing a redirect much easier. Note that the ApiResponse class inherits from this class to make use of its response management.
Available methods:
contentType()
can be used to set the content-type of the response (eg, 'application/json')redirect()
can be used to redirect the visitor to another URIsetCallback()
can be used to set a callback function to handle the server output before it is sentsetCode()
can be used to set the HTTP response code (eg, 404)
Session
Session management class which can use PHP's native session features (and an optional database store). You can get and set any property name to the session object and it is dynamically saved (using magic getter and setter methods). Implement the PHP-native SessionHandlerInterface to create your own session handler or session storage engine. This library provides database implementation called Firelit\DatabaseSessionHandler. Roll your own by implementing SessionHandlerInterface and use a class of this object when instantiating the Session object. Or, leave this parameter off to simply use PHP's built-in cookie- & file-based session handling.
Note that if you are using Firelit\DatabaseSessionHandler, the expiration of a session is NOT controlled by the session.gc_maxlifetime
as it is if you use the Session class without the session handler.
Example usage:
Strings
A set of string helper functions wrapped into a class.
Example usage:
Vars
A class for managing application-level, persistent variables. Vars is implemented through magic setters and getters so you can use any name you want for your vars and any type of persistant data store. The store can be custom defined by creating custom getter and setter functions (e.g., for reading/writing the values to a file) or you can leave it to the default (which stores the values in a database).
Example usage:
View
A class for managing views: View templates, view layouts (which wraps around a view template), partials (part of a view that is extracted for use elsewhere) and asset management (auto-inserting of required assets into the HTML
).Layouts are like view templates in which view templates reside. They typically contain the repeating HTML wrappers around the more view-specific elements. Layouts are an optional component. If no layout is specified, the view template is rendered on its own.
An example layout, saved to views\layouts\main.php
:
Now an example view file, saved to views\templates\dashboard.php
:
When the view is invoked, the data used in the view (see $name
above as an example) is specified using an associative array.
All versions of framework with dependencies
ext-mbstring Version *