First steps

In this series, you'll learn the core concepts of Assegai by building a basic CRUD application. This will give you a solid foundation in the essential building blocks of Assegai applications and cover a wide range of topics at an introductory level.

Language

PHP 8 is a major release of the PHP programming language that was released on November 26, 2020. Some notable features and improvements in PHP 8 include:

  • Just-In-Time (JIT) compilation: PHP 8 includes a JIT compiler, which can significantly improve the performance of PHP code by compiling it to native machine code at runtime.
  • Union types: PHP 8 introduces a new syntax for declaring union types, which allow a function or method to accept multiple different types of arguments.
  • Match expression: PHP 8 introduces the match expression, which provides a concise and expressive way to perform complex conditional logic.
  • Improved type system: PHP 8 includes a number of improvements to the type system, including support for typed properties, improved type inference, and improved type error messages.
  • Deprecations and removals: PHP 8 includes a number of deprecations and removals of old features, including the removal of the create_function function and the __autoload magic method.

PHP 8 is a significant upgrade from previous versions of PHP and is worth considering for any new projects or major updates to existing projects. However, it is important to thoroughly test your code before upgrading to ensure that it is compatible with the new version.

Prerequisites

Before getting started with Assegai, it is important to make sure that your system meets the following prerequisites:

  • PHP version 8.2 or higher
  • Composer version 2.x.x or higher
  • PHP fileinfo extension enabled
  • Other common PHP extensions (such as cURL, JSON, and PDO) should also be enabled on your system.

Please ensure that these requirements are met before proceeding with the installation and use of Assegai. Not having these requirements met may cause unexpected issues when using the framework.

Setup

Using the Assegai CLI, it is easy to set up a new project. To create a new Assegai project, enter the following commands in your operating system's terminal:

$ assegai new project-name

After running the commands, a directory called project-name will be created. Composer dependencies and some other starter files will be installed, and a src/ directory will be created and filled with several core files.

src
AppController.php
AppModule.php
AppService.php
index.php

Here is a brief summary of those core files:

AppController.php A controller with a single route that serves as a foundation for building out your application.
AppModule.php The main module of the application, which serves as the starting point for the application.
AppService.php A service with a single method that can be used as a starting point for building out your application's services.
index.php The main entry file for the application, which uses the AssegaiFactory function to create an instance of the Assegai application.

The index.php file includes a function, which will bootstrap our application:

index.php
use Assegai\Core\AssegaiFactory;
use Assegai\App\AppModule;

require './vendor/autoload.php';

function bootstrap(): void
{
  $app = AssegaiFactory::create(AppModule::class);
  $app->run();
}
 bootstrap();

To create an instance of the Assegai application, we use the AssegaiFactory class, which has a static method that can be used to create an application instance. In the example above, we use the create() method to create an application object and then start the app by calling the run() method.

It's worth noting that a project generated using the Assegai CLI follows a certain structure that encourages developers to place each module in its own dedicated directory.

Running the application

After the installation is finished, you can run the following command in your operating system's terminal to start the application and listen for incoming HTTP requests:

$ composer run start

This command starts the app and causes the HTTP server to listen on the port specified in the composer.json file. When the application is running, you can open your web browser and go to http://localhost:5000/. You should see the message Muli Bwanji displayed on the page.

Alternatively, if the Assegai CLI is installed, you can run the following command in your operating system's terminal to start the appliaction:

$ assegai serve