Hexavel Framework
Hexavel is a restructured version of Laravel, with the purpose of providing better work flows which
will simplify the development process., (*1)
Install
To install via composer simply use the command, (*2)
composer create-project --prefer-dist peterfox/hexavel <name of your project>
What's different from Laravel?
File structure
Hexavel uses a widely changed filesystem from Laravel with which to produce a working application. Each folder is
explained before so you can understand where to find or place your own work., (*3)
Binaries (bin)
This is where all our console applications go, including the artisan console and the binaries install via composer.
All of artisan's commands work the same as Laravel except now you must use bin/artisan
instead from the root directory of your
application., (*4)
Source (src)
This is where our base PHP application code goes using the default namespace \App., (*5)
Application (app)
For the moment this simply stores our applications configs and routing files., (*6)
Support
This is our biggest change from Laravel. Support is how it sounds, a directory for all files that support the
development of our application. This covers views, assets, language files, tests and migrations by default., (*7)
There is also a support packages folder which is the suggested place for local packages you might be developing
or sit as part of your project to be loaded via composer., (*8)
Variable (var)
Variable directory is effectively our application writable directory. All caches and data written by the application
should be stored under this directory. Examples would be the bootstrap cache, logs or an sqlite database., (*9)
Hexagonal Architecture
Hexagonal architecture is a fancy name for a simple concept,
you should separate your code into what's your framework, your domain and the connections between services
and or libraries that your application interacts with., (*10)
Laravel
Code that relates to the core of your application in this case Laravel specific code like
service providers or controllers., (*11)
Bridge
Code that relates to services or libraries that are used by the application., (*12)
Domain
Code which is unique to your business requirements and is separate to the bridge and framework., (*13)
Repository Pattern built in
The repository pattern is really important and it's useful when working with the Models you'll create using Eloquent.
To make this easier there's a service provider included which allows you to map your models to repositories and in
turn map repository interfaces from your domain to your model interfaces., (*14)
Example Repository:, (*15)
namespace App\Bridge\Eloquent;
use App\Bridge\Eloquent\Model\User;
use App\Domain\AuthenticatableRepository as AuthenticatableRepositoryInterface;
use Hexavel\Repository\EloquentRepository;
use Illuminate\Contracts\Auth\Authenticatable;
class AuthenticatableRepository extends EloquentRepository implements AuthenticatableRepositoryInterface
{
public function getModel()
{
return User::class;
}
/**
* @param string $email
* @return Authenticatable
*/
public function findByAuthIdentifier($email)
{
return $this->model->where('email', $email)->first();
}
}
Then add the model and repositories to the service provider., (*16)
namespace App\Laravel\Providers;
use App\Bridge\Eloquent\Model\User;
use App\Bridge\Eloquent\AuthenticatableRepository;
use App\Domain\AuthenticatableRepository as AuthenticatableRepositoryInterface;
use Hexavel\Support\Providers\RepositoryProvider as ServiceProvider;
class RepositoryServiceProvider extends ServiceProvider
{
/**
* @return string[]
*/
protected function getModelRepositories()
{
return [
AuthenticatableRepository::class => User::class
];
}
/**
* @return string[]
*/
protected function getRepositories()
{
return [
AuthenticatableRepositoryInterface::class => AuthenticatableRepository::class
];
}
}
Testing
Testing is a huge part of any good application that you're developing. Hexavel includes a simple setup for using
both Behat and PHPSpec to allow you to
test both the features and the code you develop., (*17)
Behat
Your feature files can be created under support/features, while the feature context for your test suite is under
support/context. You can run tests via bin/behat
or by calling gulp behat
., (*18)
To make separating the code easier the set up is ready for using the
page pattern
as a way of managing the interactions with your application for testing via Behat., (*19)
PHPSpec
Class specs are stored in support/spec they can be created simply by using the
phpspec command bin/phpspec desc <Namespace\\Class>
and then you can call bin/phpspec run
or gulp phpSpec
to perform the tests., (*20)
Warnings
Not all packages made for Laravel will work out of the box with Hexavel. Most will except if they install code into
your project. Laravel Spark is an example of this when it uses a number of stubs and adds assets etc., (*21)
Other Resources
-
Hexavel Sparkis a package for making Spark compatible with Hexavel due to
the install of stubs.
-
Hexavel Componentssits between Laravel Framework
and Hexavel.
-
Hexavel Behatholds the contexts that sets up Behat for Hexavel.