Download the PHP package marwanalsoltany/velox without Composer
On this page you can find all versions of the php package marwanalsoltany/velox. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marwanalsoltany/velox
More information about marwanalsoltany/velox
Files in marwanalsoltany/velox
Package velox
Short Description The minimal PHP micro-framework.
License MIT
Homepage https://github.com/MarwanAlsoltany/velox/blob/master/README.md
Informations about the package velox
VELOX
The fastest way to build simple websites using PHP!
[![PHP Version][php-icon]][php-href]
[![Latest Version on Packagist][version-icon]][version-href]
[![Total Downloads][downloads-icon]][downloads-href]
[![License][license-icon]][license-href]
[![Maintenance][maintenance-icon]][maintenance-href]
[![Documentation][documentation-icon]][documentation-href]
[![Scrutinizer Build Status][scrutinizer-icon]][scrutinizer-href]
[![Scrutinizer Code Coverage][scrutinizer-coverage-icon]][scrutinizer-coverage-href]
[![Scrutinizer Code Quality][scrutinizer-quality-icon]][scrutinizer-quality-href]
[![Travis Build Status][travis-icon]][travis-href]
[![StyleCI Code Style][styleci-icon]][styleci-href]
[![Open in Visual Studio Code][vscode-icon]][vscode-href] [![Run on Repl.it][replit-icon]][replit-href]
[![Tweet][tweet-icon]][tweet-href] [![Star][github-icon]][github-href]
Table of Contents
[Installation](#installation)
[About VELOX](#about-velox)
[Architecture](#architecture)
[Config](#config)
[Classes](#classes)
[Functions](#functions)
[Commands](#commands)
[Themes](#themes)
[Extending VELOX](#extending-velox)
[MVC](#mvc)
[Templating](#templating)
[Authentication](#authentication)
[Changelog](./CHANGELOG.md)
[Documentation](https://marwanalsoltany.com/velox)
If you like this project and would like to support its development, giving it a :star: would be appreciated!
Check out the [**Demo**](https://velox.marwanalsoltany.repl.co) or play with the [**REPL**](https://replit.com/@MarwanAlsoltany/velox).
Do you feel like reading? Check out the full API on the documentation website on [`marwanalsoltany.github.io/velox`](https://marwanalsoltany.github.io/velox).
Key Features
- Zero dependencies
- Minimal, intuitive and easy to get along with
- Unlimited flexibility when it comes to customizing it to your exact needs
Installation
Using Composer:
Table of Contents
[Installation](#installation)
[About VELOX](#about-velox)
[Architecture](#architecture)
[Config](#config)
[Classes](#classes)
[Functions](#functions)
[Commands](#commands)
[Themes](#themes)
[Extending VELOX](#extending-velox)
[MVC](#mvc)
[Templating](#templating)
[Authentication](#authentication)
[Changelog](./CHANGELOG.md)
[Documentation](https://marwanalsoltany.com/velox)
If you like this project and would like to support its development, giving it a :star: would be appreciated!
Check out the [**Demo**](https://velox.marwanalsoltany.repl.co) or play with the [**REPL**](https://replit.com/@MarwanAlsoltany/velox). Do you feel like reading? Check out the full API on the documentation website on [`marwanalsoltany.github.io/velox`](https://marwanalsoltany.github.io/velox).
Note: You may need to add the --stability=dev
depending on the version/branch. You may also want to add --no-dev
flag to not install development dependencies.
Using Git:
Fact: If you don't want to use any other third party packages. Installing VELOX using Git is sufficient.
Using Source:
Download VELOX as a .zip
or .tar.gz
and extract it in your server web root directory.
Advice: If you want to test out VELOX quickly and you don't have any web server available, use whatever installing method and run php bin/app-serve
from inside VELOX directory. This command will spin up a development web server on localhost:8000
(Note that you need to have at least PHP installed on your system).
About VELOX
VELOX is a lightweight micro-framework that makes creating a simple website using PHP joyful. It helps you create future-proof websites faster and more efficiently. It provides components that facilitate the process of creating a website using PHP. VELOX does not have any dependencies, the VELOX package and everything that it needs is included in the project itself. All that VELOX provides is a way to work with config, pass data, register routes, interact with the database, render views, handle exceptions, autoload code, and resolve assets. It provides the View and the Controller parts of an MVC design pattern. Staring from v1.3.0
, VELOX also provides the Model part, making it a fully featured MVC framework and starting from v1.4.0
it also comes shipped with a simple authentication system. VELOX can also be used as a Static Site Generator if all you need is HTML files in the end.
Why does VELOX exist?
VELOX was created to solve a specific problem, it's a way to build a website that is between dynamic and static, a way to create a simple website with few pages without being forced to use a framework or a CMS that comes with a ton of stuff which will never get used, it's lightweight, minimal, and straight to the point.
It's not recommended to use VELOX if you have an intermediary project, you would be better off using a well-established framework. VELOX is not an initiative to reinvent the wheel, you can look at VELOX as a starter-kit for small projects.
VELOX has a very special use-case, simple websites, and here is meant really simple websites. The advantage is, you don't have stuff that you don't need. Comparing VELOX to Laravel or Symfony is irrelevant, as these frameworks play in a totally different area, it also worth mentioning that VELOX is much simpler than Lumen or Slim.
Architecture
Directory structure
Directory | Description |
---|---|
bootstrap |
This is where VELOX bootstraps the application. You normally don't have to change anything in this directory, unless you want to extend VELOX functionality beyond basic stuff. |
bin |
This is where PHP executables are placed. You can freely add yours, or delete the entire directory. |
app |
This is where your own backend logic will be placed. You will be mostly working here for the backend part of your app. |
classes |
This is where VELOX source files live. You shouldn't be touching anything here unless you want to make your own version of VELOX. |
functions |
This is where all functions that are loaded in the application live. You can freely add yours, or delete the entire directory. |
includes |
This is where all files that should be preloaded will be placed. You can freely add yours, or delete the entire directory. |
themes |
This is where all your frontend themes will be placed. You will be mostly working here for the frontend part of your app. |
config |
This is where all config files will live. All files here will be accessible using the Config class at runtime. |
storage |
This is where VELOX will write caches and logs. You can also use this directory to store installation-wide assets. |
public |
This is where you should put your index.php with a symlink for static assets (active theme assets/ directory for example) for maximum security. You can freely delete this directory if you want to. |
vendor |
This is where your Composer dependencies will be placed. You can freely delete this directory if you don't want to use Composer. |
Advice: Most files listed in these directories are documented. Take a look through them to learn more about VELOX.
App Entry
The entry point for a VELOX app is the bootstrap/autoload.php
, register some routes with their handlers using the Router::class
, and start the router. This is all that you need to have a working VELOX app.
Additionally, you can add middlewares using Router::middleware()
and/or set up handlers for 404
and 405
responses using {global.errorPages.CODE}
config value.
Alternatively, you can extract the "routes registration part" in its own file and let VELOX know about it using bootstrap/additional.php
.
Starting from v1.2.0
VELOX does that by default, the file includes/routes/web.php
is where you should register your routes. The router will also start automatically if not started explicitly.
Note: In order for VELOX to work correctly and safely, you need to redirect all requests to application entry point (index.php
) and block all requests to other PHP files on the server (take a look at .htaccess.dist
to get started with Apache).
Config
The following table lists all config files that come shipped with VELOX.
Config File | Description |
---|---|
global.php |
This config file contains some global variables that are used by almost all classes (app-wide config). |
router.php |
This config file can be used to override Router::class default parameters. |
session.php |
This config file contains session configuration, it is used by the Session::class . |
database.php |
This config file contains database credentials, it is used by the Database::class . |
auth.php |
This config file contains authentication configuration, it is used by the Auth::class . |
theme.php |
This config file can be used to edit/extend theme configuration. |
view.php |
This config file can be used to customize everything about the views. It is used by the View::class . |
data.php |
This config file can be used to provide any arbitrary data, which then will get injected in the Data::class . |
cli.php |
This config file can be used to enable/disable the commands or change their arguments. |
Fact: You can freely add your own config files too, all you need to do is to create a new file under /config
and add your configuration to it. VELOX will know about this file and load it in the application. You can access your config via Config::get('filename.whateverKeyYouWrote')
.
Classes
VELOX classes are divided in four namespaces:
MAKS\Velox
MAKS\Velox\Backend
MAKS\Velox\Frontend
MAKS\Velox\Helper
The following table lists all available classes with their description:
Class | Description |
---|---|
Velox\App |
A class that serves as a basic service-container for VELOX. |
Backend\Event |
A class that offers simple events handling functionality (dispatching and listening). |
Backend\Config |
A class that loads everything from the /config directory and make it as an array that is accessible via dot-notation. |
Backend\Router |
A class that serves as a router and an entry point for the application. |
Backend\Globals |
A class that serves as an abstraction/wrapper to work with superglobals. |
Backend\Session |
A class that offers a simple interface to work with sessions. |
Backend\Controller |
An abstract class that serves as a base Controller that can be extended to make handlers for the router. |
Backend\Database |
A class that represents the database and handles database operations. |
Backend\Model |
An abstract class that serves as a base model that can be extended to create custom models. |
Backend\Auth |
A class that serves as an authentication system for users. |
Frontend\Data |
A class that serves as an abstracted data bag/store that is accessible via dot-notation. |
Frontend\View |
A class that renders view files (Layouts, Pages, and Partials) with the ability to include additional files, divide page content into sections and cache rendered views. |
Frontend\HTML |
A class that serves as a fluent interface to write HTML in PHP. It also helps with creating HTML elements on the fly. |
Frontend\Path |
A class that serves as a path resolver for different paths/URLs of the app. |
Helper\Dumper |
A class that dumps variables and exception in a nice formatting. |
Helper\Misc |
A class that serves as a holder for various miscellaneous utility function. |
Note: This all what the VELOX package provides out of the box.
Fact: The App
, Event
, Config
, Router
, Globals
, Session
, Database
, Auth
, Data
, View
, HTML
, Path
classes are aliased on the root namespace for ease-of-use.
Functions
VELOX functions are divided into these files:
helpers.php
: This is where helper functions for VELOX classes live, these are mainly functions that return an instance of class or alias some method on it.html.php
: This is where HTML helper functions live, these are nothing other than aliases for the most used PHP functions with HTML.
The following table lists all available functions and to which class/group they belong:
Class/Group | Function(s) |
---|---|
App::class |
app() , abort() , terminate() |
Event::class |
event() |
Config::class |
config() |
Router::class |
router() , handle() , redirect() , forward() |
Database::class |
database() |
Globals::class |
globals() |
Session::class |
session() , flash() , csrf() |
Auth::class |
auth() |
View::class |
view() , render() , render_layout() , render_page() , render_partial() , section_push() , section_reset() , section_start() , section_end() , section_yield() , include_file() |
Data::class |
data() , data_has() , data_get() , data_set() |
HTML::class |
html() |
Path::class |
path() , app_path_current() , app_url_current() , app_path() , app_url() , theme_path() , theme_url() , assets_path() , assets_url() |
Dumper::class |
dd() , dump() , dump_exception() |
HTML Helpers | he() , hd() , hse() , hsd() , st() , nb() |
Fact: You can freely add your own functions too, all you need to do is to create a new file under /functions
and add your functions to it. VELOX will know about this file and load it in the application.
Commands
VELOX comes with some handy commands that you can use to do some repetitive tasks. You can execute these commands using the php bin/{command-name}
.
The following table lists all available commands with their description.
Command | Description |
---|---|
app-serve |
This command starts a development server. |
app-mirror |
This command mirrors the application in the /public directory. |
config-cache |
This command caches the current configuration. |
config-dump |
This command dumps the current configuration with syntax highlighting. |
cache-clear |
This command clears caches. |
You can customize these commands using the config/cli.php
file. Here you can enable/disable them or provide different arguments for them.
If you would like to make all these commands accessible via a single interface. Check out my other package Blend, which will do that for you and even more.
Themes
VELOX is built around the idea of themes, a theme is divided into four directories:
- The
assets/
directory is where all your static assets associated with this theme will be placed. - The
layouts/
directory is where you define your layouts. A layout in VELOX terminology is the outer framing of a webpage. - The
pages/
directory is where you put the content specific to every page, the page will then be wrapped with some layout of your choice and finally get rendered. A page in VELOX terminology is the actual content of a webpage. - The
partials/
directory is where you put all your reusable pieces of the theme, which then will be used in your layouts, pages, or other partials. A good example for partials could be: Components, Includes, and Content-Elements.
You can customize the behavior of themes using the config/view.php
file.
Advice: You can take a look at the provided velox
theme to see how all stuff work together in practice.
Examples:
themes/velox/layouts/main.phtml
themes/velox/pages/home.phtml
themes/velox/partials/text-image.phtml
Extending VELOX
To add your own classes use the app/
directory, this is where you should put you own business logic. Note that you have to follow PSR-4 in order for VELOX to load your classes. See app/Controller/DefaultController.php
, to get an idea.
Here is a list of some important files that you should consider when working with VELOX:
- Preloading files/directories
autoload/additional.php
. - Providing additional data
config/data.php
. - Registering web routes
includes/routes/web.php
(starting fromv1.2.0
). - Registering event handlers
includes/events/system.php
(starting fromv1.2.0
).
MVC
Creating a Model:
Working with the Model:
Using the Model in the Controller:
Fact: CRUD operations (namely: index
, create
, store
, show
, edit
, update
, destroy
) are registered and configured by default. To register your own routes automatically, use the @route("<path>", {<http-verb>, ...})
annotation. See Controller::registerRoutes()
DocBlock to learn more.
Fact: To make the model available as property for the controller ($this->model
), use Controller::associateModel()
. See Controller::associateModel()
DocBlock to learn more.
Advice: If in production mode, as a shortcut, throwing an exception with a code matching {global.errorPages.CODE}
config value will render the corresponding error page. For example, when throwing new Exception('Not found', 404)
form the controller, the configured 404
error page will be rendered and will be passed the exception message. If the page is not configured, the 500
error page will be rendered as a fallback instead.
VELOX does not have any way to validate data. Check out my other package Mighty, which will do that for you and even more.
Using the Model in a View:
Advice: Check out the PersonsController
to see a realistic example.
Templating
VELOX comes with its own templating engine. This templating engine is very intuitive and easy to get along with, if you have experience with any other templating engine, learning it would be a matter of minutes. Note that the use of this templating engine is optional. You can simply use raw PHP in your views.
The following table lists all available tags and what they do:
Tag | Description |
---|---|
code>{! @extends 'path/to/template' !} | Extend a template, blocks of this template will be inherited. |
code>{! @include 'path/to/file' !} | Include a file, this will get rendered before inclusion (can't access context variables). |
code>{! @embed 'path/to/file' !} | Embed a file, this will be included as is (can access context variables). |
br>{! @endblock !}
| Create a block to wrap some code. |
code>{! @super !} | Use it inside a block in an extended template to inherit parent block content. |
code>{! @block(name) !} | Print a block. Needs to be called at least once in order to render a block. |
{! @foreach ($vars as $var) !}/code> | |
{! $var = '' !} |
Variable assignments. Content can be a variable or any valid PHP expression. |
{{ $var }} |
Print a variable. Content can be a variable or any PHP expression that can be casted to a string. |
{{{ $var }}} |
Print a variable without escaping. Content can be a variable or any PHP expression that can be casted to a string. |
{# This is a comment #} |
Comment something. This will be a PHP comment (will not be available in final HTML). |
Advice: Take a look at PersonsController
in VELOX theme for a realistic example.
Authentication
Starting from v1.4.0
VELOX comes shipped with a simple built-in authentication system. This system is very simple and easy to use.
Advice: Check out the UsersController
to see a realistic example.
License
VELOX is an open-source project licensed under the MIT license.
Copyright (c) 2021 Marwan Al-Soltany. All rights reserved.
All versions of velox with dependencies
ext-mbstring Version *
ext-json Version *
ext-dom Version *
ext-intl Version *
ext-pdo Version *