PHPackages                             simovative/zeus - 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. [Framework](/categories/framework)
4. /
5. simovative/zeus

ActiveLibrary[Framework](/categories/framework)

simovative/zeus
===============

A Post-Redirect-Get specialised framework for PHP

17.1.0(1y ago)7108.1k↓48.1%3MITPHPPHP ^8.2 || ^8.3CI passing

Since Jul 11Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/Simovative/zeus)[ Packagist](https://packagist.org/packages/simovative/zeus)[ Docs](https://github.com/Simovative-gmbh/zeus)[ RSS](/packages/simovative-zeus/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (7)Versions (68)Used By (0)

Simovative PRG-HTTP-Framework
=============================

[](#simovative-prg-http-framework)

[![Build Status](https://github.com/Simovative/zeus/actions/workflows/build.yml/badge.svg)](https://github.com/Simovative/zeus/actions)[![Coveralls](https://camo.githubusercontent.com/88e2e84166453d0dfa41167ba12e9957668587e77444228f991ec86f390ceb71/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f53696d6f7661746976652f7a6575732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Simovative/zeus?branch=master)

Index
-----

[](#index)

1.[Design principles](#design)
2.[Quickstart](#quickstart)
3.[General structure](#structure)
4.[Modifying components](#modifying)
5.[Build](#build)

Design principles
---------------------------------------------------

[](#design-principles)

This framework is made specifically for applications relying heavily on the HTTP protocol and the Post-Redirect-Get (PRG) design pattern. From our point of view it could be extended to create any kind of application, you just need to extend the HttpKernel or write your own Kernel. But currently this is not our intention.

To use the automatic form population, you need to use bootstrap (getbootstrap.com) as your frontend framework. If you do not want to use it, you need to write your own FormPopulation class and replace the existing with it. We will write a tutorial for it in future. See the [mofifying components](#modifying).

### Why did we develop this framework

[](#why-did-we-develop-this-framework)

This framework was created in collaboration with Stefan Priebsch from the PHP Consulting Company (thePHP.cc). It aims to provide a solid solution to create a modular maintainable product out of our monolithic application. It should be easy to understand for young and inexperienced developers and delivers solid boundaries to develop new features in a maintainable way. A way of doing CQRS (Command Query Responsibility Segregation) is embedded into it, but if you do not need or want to use it, you can just ignore it (but we would not recommend it).

### What is PRG?

[](#what-is-prg)

Post-Redirect-Get is a common web development design pattern. See

### Why would i want to use this framework over others?

[](#why-would-i-want-to-use-this-framework-over-others)

This framework doesn't aim to provide a solution for every problem your application can possibly encounter, instead it tries to provide an elegant way to implement a very specific task. Unlike other frameworks it doesn't try to be a foundation for everything, but rather a solid solution for your applications very specific PRG needs. We also implement the majority of all other HTTP-Methods, so it is also easy to use for a SPA as Backend or to implement a Web-Api.

It aims to be compatible with other frameworks for other tasks. The commands are re-usable and you should be able to inject any kind of action you already have into the framework using the command-interfaces.

### Compatibility

[](#compatibility)

PHP 7.1 and up for now. We will remove the support for the older PHP versions very soon, so if you aim to stay on 7.1 or older, you should not use this framework.

Quickstart
------------------------------------------------

[](#quickstart)

This section explains how you can get the framework up and running as fast as possible.
**Note: Registering the framework into an existing application is out of scope of this guide, but shouldn't be a big problem, as we also did this.**

### Generating your application

[](#generating-your-application)

Install with composer

```
php composer.phar require simovative/zeus

```

And let the cli help you in setting up a default application

```
vendor/bin/zeus c:a Simovative\\Demo Demo

```

This will create a folder public with an index.php file and a folder "bundles" containing the ApplicationBundle and ApplicationKernel.

You might want to configure your webserver right away to test if this worked.

### Webserver config

[](#webserver-config)

#### Apache

[](#apache)

Point your web-root to the $cwd/public

```
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [NC,L,QSA]

```

#### Nginx

[](#nginx)

```
location / {
    try_files = $uri index.php?$args;
    root   /var/www/site/public;
    index  index.php;
}

```

#### PHP internal webserver

[](#php-internal-webserver)

Just run the webserver and use the public/index.php as router script:

```
php -S localhost:8000 public/index.php

```

If everything worked you should see a basic setup page, telling you to add another bundle.

### Generating a Bundle

[](#generating-a-bundle)

```
vendor/bin/zeus c:b Test

```

Next, register the bundle, which we named "Test" in your Applications Kernel (in this case bundles/Application/DemoKernel.php)

```
	protected function registerBundles(HttpRequestInterface $request) {
		$bundles = array();
		$bundles[] = new DemoApplicationBundle();
		$bundles[] = new \Simovative\Demo\Test\TestBundle();
		return $bundles;
	}
```

If everything worked the Router should take over and you'll see a page with the message:

```
Replace me with some serious content, please

```

### Generating a Page to display content (GET)

[](#generating-a-page-to-display-content-get)

```
vendor/bin/zeus c:p Home Test

```

This will create two files in you bundles/Test/Page folder:

- HomePage.php: That's the page to show
- HomePageFactoryMethods.txt: Move this code into your Bundle-Factory (TestFactory.php) to create the page from the router. (The file can be deleted afterwards)

To create a route for this page add something similar to your GetRequestRouter

```
if ($request->getUrl() == '/test/home') {
	return $this->factory->createTestHomePage();
}

```

### Generating a Page with a form that will be submitted (GET)

[](#generating-a-page-with-a-form-that-will-be-submitted-get)

```
vendor/bin/zeus c:f Login Test

```

This will create two files in you bundles/Test/Page folder:

- LoginForm.php
- LoginFormFactoryMethods.txt They contain the same type of code as in a normal page and should be treated the same way. Also use the similar code to create a route for it.

The only difference is, if the form is submitted to an command, and the validator invalidates it, the error messages and form content will be automatically populated to the form. This happens in the CommandDispatcher if you want to have a look at it.

### Generating a Command (POST)

[](#generating-a-command-post)

```
vendor/bin/zeus c:c Login Test

```

This will create five files in you bundles/Test/Command folder:

- LoginCommand.php: The command object that holds all the data needed for execution.
- LoginCommandBuilder.php The command builder connects all the command classes and will be used by the command dispatcher to get the single components.
- LoginCommandHandler.php: The handler does the command execution.
- LoginCommandValidator.php: The validator checks the command request if the provided data is valid to create a command and execute the handler. We recommend basic checks for required data and if the data types are correct and data is in the correct format (e.g. like e-mail addresses). If the command can not be successfully executed because of the current state of the application (e.g. some data in the database is missing), the command handler should return a response that indicates that.
- LoginCommandFactoryMethods.txt: Move this code into your Bundle-Factory (TestFactory.php) to create all required components and access the builder creation method from the command router.

To create a route for this command add something similar to your CommandRouter

```
if ($request->getUrl() == '/test/login') {
	return $this->factory->createTestLoginCommandBuilder();
}

```

General Structure
------------------------------------------------------

[](#general-structure)

### Configuration

[](#configuration)

How you implement environments is up to you. Doing so can be really simple, like writing a small ini file containing information.

```
