1. Go to this page and download the library: Download ophelios/zephyrus library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ophelios / zephyrus example snippets
namespace Models\Brokers;
class ClientBroker extends Broker
{
public function findAll(): array
{
return $this->select("SELECT * FROM client");
}
public function findById($clientId): ?\stdClass
{
return $this->selectSingle("SELECT * FROM client WHERE client_id = ?", [$clientId]);
}
}
namespace Controllers;
use Models\Brokers\ClientBroker;
use Zephyrus\Network\Router\Get;
class ExampleController extends Controller
{
#[Get("/clients")]
public function index()
{
$broker = new ClientBroker();
return $this->json(['clients' => $broker->findAll()]);
}
#[Get("/clients/{id}")]
public function read($clientId)
{
$broker = new ClientBroker();
$client = $broker->findById($clientId);
if (is_null($client)) {
return $this->abortNotFound();
}
return $this->json(['client' => $client]);
}
}
namespace Controllers;
use Models\Brokers\UserBroker;
use Zephyrus\Application\Rule;use Zephyrus\Network\Router\Post;
class ExampleController extends Controller
{
#[Post("/users")]
public function insert()
{
// Construire un objet Form depuis les données de la requête
$form = $this->buildForm();
// Appliquer une série de règles de validation sur les champs nécessaires. Il existe une grande quantité
// de validations intégrées dans Zephyrus. Consulter les Rule:: pour les découvrir.
$form->field('firstname', [Rule:: new Rule(function ($value) {
return $value != "admin";
}, "Username must not be admin!")
]);
// Si la vérification échoue, retourner les messages d'erreur avec leur champs
if (!$form->verify()) {
return $this->json($form->getErrors());
}
// Effectuer le traitement si aucune erreur n'est détectée (dans ce cas, ajouter l'utilisateur depuis
// un courtier et obtenir le nouvel identifiant).
$clientId = (new UserBroker())->insert($form->buildObject());
// Retourner au client l'identifiant du nouvel utilisateur
return $this->json(['client_id' => $clientId]);
}
}
<VirtualHost *:80>
ServerName <HOST or IP>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/<PROJECT_NAME>/public
<Directory /var/www/>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.