Download the PHP package rougin/basilisk without Composer
On this page you can find all versions of the php package rougin/basilisk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rougin/basilisk
More information about rougin/basilisk
Files in rougin/basilisk
Package basilisk
Short Description A project skeleton for Slytherin.
License MIT
Homepage https://roug.in/basilisk/
Informations about the package basilisk
Basilisk
Basilisk
is a project skeleton specifically for the Slytherin PHP micro-framework which contains an opinionated code structure based on my experiences creating projects using Slytherin
as its foundation. The code structure should be easy to understand and be under SOLID principles.
Installation
Create a new Basilisk
project via Composer:
Once created, kindly execute the one-time setup to the project:
Running the project
To run Basilisk
in a web browser, the PHP's built-in web server can be used:
After running, open a web browser then proceed to http://localhost in a new tab.
[!WARNING] This command should only be used for development purposes. It is recommended to use Apache or Nginx in running this project.
What's inside?
A Basilisk
project contains a configuration of the following packages:
Slytherin
Slytherin is a simple and extensible PHP micro-framework that tries to achieve a SOLID-based design for creating web applications. As Slytherin
is the core foundation of Basilisk
, the following packages of Slytherin
has already been configured out of the box:
- HttpIntegration allows to use PHP's superglobals (e.g.,
$_GET
,$_POST
, etc.); - ConfigurationIntegration allows to use the
Configuration
class in any part of the code structure through dependency injection; - MiddlewareIntegration provides a simple way in integrating PSR-15 middlewares to HTTP requests and HTTP responses;
- RoutingIntegration adds a systematic way of configuring HTTP routes and its routers; and
- RendererIntegration provides a simple logic for loading PHP templates.
[!NOTE] Kindly see the Slytherin's documentation on how to use the above-mentioned packages.
Dotenv
Dotenv is a simple PHP package that loads environment variables from .env
files to getenv()
, $_ENV
and $_SERVER
automagically. This is one of the core packages of Basilisk
as it uses environment variables in most of its configuration in the app/config
directory:
Phinx
Phinx is a tool made for PHP in performing database migrations. Being a framework-agnostic package, Phinx
can create, write and perform database migrations easily. To use this package, kindly install it first using Composer
:
Once installed, kindly check the app/config/phinx.php
file on the variables that requires an update:
When creating or performing database migrations using Phinx
, always use the configuration file provided by Basilisk
:
Weasley
Weasley is a utility package in PHP that provides generators, helpers, and utilities for Slytherin. The following packages are also configured within Basilisk
:
-
Laravel\Eloquent
enables the usage of Eloquent toBasilisk
which is an Object-relational mapper (ORM) from Laravel. To use this package, kindly install its required package first inComposer
: -
Laravel\Blade
allowsBasilisk
to use Blade fromLaravel
for creating PHP templates using theBlade
templating engine. To use this package, kindly uncomment its related code first in theapp/config/app.php
file:Then proceed to install its required package from
Composer
:Once installed, the
Blade
templates can now be added in theapp/blades
directory:
Directory structure
The following directory names below are only the preferred names based on my experience building projects using Slytherin
. However, they can be easily be extended or removed as Slytherin
not does not conform to any of the specified preferences:
Checks
This directory contains PHP classes that are used specifically for validation. The said PHP classes may be extended to the Check
class of Weasley:
[!NOTE] For more information on how to create a validation class, please see the Validation section of the
Weasley
documentation.
Depots
This is the main directory that should contain the business logic of Basilisk
:
Prior in using depots, I implemented most of the logic in the Routes
or Models
directories. However, it presents a challenge to me in organizing code when implementing new features. In using depots, I can reuse the same logic in to either Routes
(for receiving user request) or in Scripts
directory (for handling terminal-based actions).
[!NOTE] In other PHP frameworks and other guides,
Depot
is also known as the Repository pattern.
Models
This is the directory where for storing the models (if using Eloquent
) or entities (if using Doctrine
). In my experience, my best practice is that the class names added in this directory should represent a database table (e.g., if having a users
table from the database, it should be represented in Basilisk
as User
class):
[!NOTE] As
Basilisk
provided aUser
model based onEloquent
, kindly see its official discussion for its usage and configuration.
Phinx
This is the directory for the storage of related files to the Phinx package. The Scripts
directory must contain the generated database migrations while the Seeders
directory must contain the custom database seeders:
This directory will also be used for performing database migrations and its seeders. To perform a database migration, kindly run the migrate
command:
The seed:run
command can be used for populating data in a database:
When executed, the command above will perform the database seeders in alphabetical order.
[!NOTE] Before performing any database migrations from
Phinx
, kindly update the database credentials first in.env
:
Routes
This is the gateway of Basilisk
wherein the HTTP routes are stored and configured as a PHP class. The PHP class can call or instantiate the classes found from the previously mentioned directories:
Once a HTTP route was created to the directory, it should be added to the Router
for it to be recognized by Slytherin
:
[!NOTE] In other PHP frameworks,
Routes
is commonly known asControllers
.
Scripts
This is the directory to store commands or scripts. These scripts can be executed directly using the php
command in the terminal:
Development workflow
Basilisk
also provides unit testing and static code analysis out of the box when implementing new features to minimize the introduction of errors during development. It also has an opinionated coding style which can be configured after the installation.
Unit testing
The sample unit tests provided in Basilisk
were written in PHPUnit:
It is recommended to run the above command to always check if the updated code introduces errors when creating fixes or implementing new features.
[!NOTE] Please see the official documentation of
PHPUnit
on how to write unit tests to the specified testing framework.
Code quality
To retain the code quality of Basilisk
, a static code analysis code tool named PHPStan can be used during development. To start, kindly install the specified package in the global environment of Composer
:
Once installed, PHPStan
can now be run using its namesake command:
[!NOTE] When running
phpstan
, it will use thephpstan.neon
file which is already provided byBasilisk
.
Coding style
Aside from code quality, Basilisk
also uses a tool named PHP Coding Standards Fixer for maintaining an opinionated style guide. To use this tooling, it needs also to be installed in the Composer
's global environment first:
After its installation, kindly use the php-cs-fixer
command in the same Authsum
directory:
The phpstyle.php
file provided by Basilisk
currently follows the PSR-12 standard as its baseline for the coding style and uses Allman as its indentation style.
[!NOTE] Installing both
PHPStan
andPHP Coding Standards Fixer
requires a minimum version of PHP at least7.4
.
Changelog
Please see CHANGELOG for more information what has changed recently.
License
The MIT License (MIT). Please see LICENSE for more information.