PHPackages                             rougin/basilisk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rougin/basilisk

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rougin/basilisk
===============

Simple project skeleton for Slytherin.

v0.2.1(3w ago)119MITPHPPHP &gt;=5.3.0CI passing

Since Sep 6Pushed 3w ago1 watchersCompare

[ Source](https://github.com/rougin/basilisk)[ Packagist](https://packagist.org/packages/rougin/basilisk)[ Docs](https://roug.in/basilisk/)[ RSS](/packages/rougin-basilisk/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (8)Versions (4)Used By (0)

Basilisk
========

[](#basilisk)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5ab642f715e532f0fcbe0762ead7499e7409120ce1cf1062353a637d2b2dbaaa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f7567696e2f626173696c69736b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rougin/basilisk)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/rougin/basilisk/blob/master/LICENSE.md)[![Build Status](https://camo.githubusercontent.com/d36a6b71c58724d41ac899401f1a2f9df53b94c7a7a5e15f02a2139ec28e2919/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f7567696e2f626173696c69736b2f6275696c642e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/rougin/basilisk/actions)[![Coverage Status](https://camo.githubusercontent.com/b091e14c894b4bfe48d0b92e57d186f7e3fb8218508d41760f579288b39574ad/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f726f7567696e2f626173696c69736b3f7374796c653d666c61742d737175617265)](https://app.codecov.io/gh/rougin/basilisk)[![Total Downloads](https://camo.githubusercontent.com/6be66b4b0bedd41b8b2d437230661fcac518453970f496266affb4ea794e7bc0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f7567696e2f626173696c69736b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rougin/basilisk)

`Basilisk` is a project skeleton specifically for the [Slytherin](https://roug.in/slytherin/) PHP micro-framework which contains an opinionated code structure based on [my experiences](https://roug.in/) creating projects using `Slytherin` as its foundation. The code structure should be easy to understand and be under [SOLID](https://en.wikipedia.org/wiki/SOLID) principles.

Installation
------------

[](#installation)

Create a new `Basilisk` project via [Composer](https://getcomposer.org/):

```
$ composer create-project rougin/basilisk "hogwarts"
```

Once created, kindly execute the one-time setup to the project:

```
$ cd hogwarts
$ php setup.php
```

Running the project
-------------------

[](#running-the-project)

To run `Basilisk` in a web browser, the [PHP's built-in web server](https://www.php.net/manual/en/features.commandline.webserver.php) can be used:

```
$ php -S localhost:80 -t app/public
```

After running, open a web browser then proceed to  in a new tab.

Warning

This command should only be used for development purposes. It is recommended to use [Apache](https://httpd.apache.org/) or [Nginx](https://nginx.org/en/) in running this project.

What's inside?
--------------

[](#whats-inside)

A `Basilisk` project contains a configuration of the following packages:

### Slytherin

[](#slytherin)

[Slytherin](https://github.com/rougin/slytherin) is a simple and extensible PHP micro-framework that tries to achieve a [SOLID-based design](https://en.wikipedia.org/wiki/SOLID) 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](https://github.com/rougin/slytherin/wiki/Http) allows to use PHP's superglobals (e.g., `$_GET`, `$_POST`, etc.);
- [ConfigurationIntegration](https://github.com/rougin/slytherin/wiki/IntegrationInterface-Implementation) allows to use the `Configuration` class in any part of the code structure through dependency injection;
- [MiddlewareIntegration](https://github.com/rougin/slytherin/wiki/Middleware) provides a simple way in integrating [PSR-15](https://www.php-fig.org/psr/psr-15/) middlewares to HTTP requests and HTTP responses;
- [RoutingIntegration](https://github.com/rougin/slytherin/wiki/Routing) adds a systematic way of configuring HTTP routes and its routers; and
- [RendererIntegration](https://github.com/rougin/slytherin/wiki/Template) provides a simple logic for loading PHP templates.

Note

Kindly see the [Slytherin's documentation](https://github.com/rougin/slytherin/wiki) on how to use the above-mentioned packages.

### Dotenv

[](#dotenv)

[Dotenv](https://github.com/vlucas/phpdotenv) 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:

```
# .env.example

#######################
# Application Settings
#######################
APP_NAME="Basilisk"
APP_VERSION="0.1.0"

# ...

```

```
// app/config/app.php

return array(

    // ...

    'name' => getenv('APP_NAME'), // returns "Basilisk"

    // ...

    'version' => getenv('APP_VERSION'), // returns "0.1.0"

    // ...

);
```

### Phinx

[](#phinx)

[Phinx](https://phinx.org/) 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`:

```
$ composer require robmorgan/phinx
```

Once installed, kindly check the `app/config/phinx.php` file on the variables that requires an update:

```
// app/config/phinx.php

return array(

    /**
     * Paths to be used for database migration.
     *
     * @var array
     */
    'paths' => array(

        /**
         * @var array
         */
        'migrations' => array(
            $root . '/src/Phinx/Scripts',
        ),

        /**
         * @var array
         */
        'seeds' => array(
            $root . '/src/Phinx/Seeders',
        ),

    ),

    // ...

);
```

When creating or performing database migrations using `Phinx`, always use the configuration file provided by `Basilisk`:

```
$ vendor/bin/phinx create CreateUsersTable -c app/config/phinx.php
```

### Weasley

[](#weasley)

[Weasley](https://github.com/rougin/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](https://laravel.com/docs/eloquent) to `Basilisk` which is an [Object-relational mapper (ORM)](https://en.wikipedia.org/wiki/Object%E2%80%93relational_mapping) from [Laravel](https://laravel.com). To use this package, kindly install its required package first in `Composer`:

    ```
    $ composer require illuminate/database
    ```
- `Laravel\Blade` allows `Basilisk` to use [Blade](https://laravel.com/docs/blade) from `Laravel` for creating PHP templates using the `Blade` templating engine. To use this package, kindly uncomment its related code first in the `app/config/app.php` file:

    ```
    // app/config/app.php

    // ...

    /**
     * This section specifies the core integrations that are
     * required to run in Slytherin. The following will use
     * the defined HTTP variables, available HTTP routes, and
     * the specified HTTP middlewares (if they're available).
     */
    'Rougin\Slytherin\Http\HttpIntegration',
    'Rougin\Slytherin\Integration\ConfigurationIntegration',
    'Rougin\Slytherin\Middleware\MiddlewareIntegration',
    'Rougin\Slytherin\Routing\RoutingIntegration',
    // 'Rougin\Slytherin\Template\RendererIntegration', // comment this line

    /**
     * This section specifies the packages came from Weasley.
     * Please see Weasley's documentation for all of its
     * available packages and integrations that can be used.
     *
     * @link https://roug.in/weasley/
     */
    'Rougin\Weasley\Packages\Laravel\Eloquent',
    'Rougin\Weasley\Packages\Laravel\Blade', // uncomment this line
    ```

    Then proceed to install its required package from `Composer`:

    ```
    $ composer require illuminate/view
    ```

    Once installed, the `Blade` templates can now be added in the `app/blades` directory:

    ```
    // app/blades/index.blade.php

    @extends('main')

    @section('content')

          Hello, Muggle!

    @endsection
    ```

Directory structure
-------------------

[](#directory-structure)

The following directory names below are only the preferred names [based on my experience](https://roug.in/work/) 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:

```
src/
├─ Checks/
├─ Depots/
├─ Models/
├─ Phinx/
│  ├─ Scripts/
│  ├─ Seeders/
├─ Routes/
├─ Scripts/

```

### `Checks`

[](#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](https://roug.in/weasley/):

```
namespace App\Checks;

use Rougin\Weasley\Check;

class UserCheck extends Check
{
    /**
     * @var array
     */
    protected $labels =
    [
        'name' => 'Name',
        'email' => 'Email',
    ];

    /**
     * @var array
     */
    protected $rules =
    [
        'name' => 'required',
        'email' => 'required|email',
    ];
}
```

Note

For more information on how to create a validation class, please see the [Validation section](https://github.com/rougin/weasley?tab=readme-ov-file#validation) of the `Weasley` documentation.

### `Depots`

[](#depots)

This is the main directory that should contain the business logic of `Basilisk`:

```
namespace App\Depots;

use App\Models\User;

class UserDepot
{
    /**
     * @var \App\Models\User
     */
    protected $user;

    /**
     * @param \App\Models\User $user
     */
    public function __construct(User $user)
    {
        $this->user = $user;
    }

    /**
     * @return array[]
     */
    public function all()
    {
        $result = $this->user->all();

        $items = array();

        // ...

        return $items;
    }
}
```

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](https://designpatternsphp.readthedocs.io/en/latest/More/Repository/README.html).

### `Models`

[](#models)

This is the directory where for storing the models (if using [`Eloquent`](https://laravel.com/docs/eloquent)) or entities (if using [`Doctrine`](https://www.doctrine-project.org/index.html)). 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):

```
