Traducciones Español

In contact with StratusPHP.

In contact with StratusPHP. In this article we will show you a tutorial with the necessary steps to apply what we published about StratusPHP previously first video we published about StratusPHP. We recommend to watch the first undersigned video if you didn´t yet.

As we said previously, this project is still developing and we will be publishing articles about its new chracteristics, changes, news, etc. as it goes on. This publication will make easier to the users to create applications of proof with StratusPHP and the user could try the new characteristics we will be publishing gradually. Something important we have to specify is that StratusPHP will have different ways of work. That means that it can have a lot of options of configuration and those options need to be specified according to the application needs. StratusPHP could work with HTTP and with WebSockets too and that is why the option taked depend of the way of work . We are focus just on the working by HTTP.

Don´t worry if you have some queries about it. We know that there are a lot of things we have to explain but we will do it when the time comes, because it is necessary a practical approach in this publication.

1. Installing StratusPHP.

The StratusPHP installation is realized by Composer this way:

$ composer require thenlabs/stratus-php dev-master

You have to take into account that StratusPHP needs PHP 7.3 or superior.

2. Creating the application class.

We create the application class once the app has finalized that it has given back the HTML code page and created the next achive with that purpose:

// src/App.php

namespace ThenLabs\StratusPHP\Demo;

use ThenLabs\StratusPHP\AbstractApp;

class App extends AbstractApp
    public function getView(): string
        return <<<HTML
            <!DOCTYPE html>
            <html lang="en">
                <meta charset="UTF-8">
                <input type="" name="">
                <button> to greet</button>

You can notice that in our case we are using the space names ThenLabs\StratusPHP\Demo. As you can supose the application structure will depend of its own necessaries and that is why it is not absolute. In our case, we have to create the names space. You need to add the next archive for this composer.json:

    // ...
    "autoload": {
        "psr-4": {
            "ThenLabs\\StratusPHP\\Demo\\": "src/"

Once it has been realized we have to execute the command :

$ composer dump-autoload

As you could notice, our class App inherit from the class ThenLabs\StratusPHP\AbstractApp and it contain the method getView(): string that give back the HTML code of thepage.

3. Introduction to the controllers.

The web applications has controllers as you know.

In the case of the apps made withn StratusPHP will need two controllers to work. One of them will give back the HTML of the page, and the other one will process the asynchronous calls.

It is important to say that the platform of creation is totally this controllers are not within StratusPHP reach. It guarantee that it is compatible with other frameworks like Symfony, Laravel, etc. There are no doubt about this one of the best StratusPHP characteristics.

4. Creating the load controller.

For the load controller we will create the next archive:

// public/index.php

require_once __DIR__.'/../vendor/autoload.php';

use ThenLabs\StratusPHP\Demo\App;
use function Opis\Closure\serialize as s;

$app = new App('/controller.php');

$input = $app->querySelector('input');
$label = $app->querySelector('label');
$button = $app->querySelector('button');

$button->onClick(function () use ($input, $label) {
    $label->innerHTML = "Hola {$input->value}";

$_SESSION['app'] = s($app);

echo $app;

You can see that in the undersigned archive we define our application behavior.

5. Creating the processing controller.

In the case of our processing controller we do it next way:

// public/controller.php

require_once __DIR__.'/../vendor/autoload.php';

use ThenLabs\StratusPHP\StratusRequest;
use function Opis\Closure\{serialize as s, unserialize as u};


$app = u($_SESSION['app']);
$request = StratusRequest::createFromJson($_REQUEST['stratus_request']);

$result = $app->run($request);

if ($result->isSuccessful()) {
    $_SESSION['app'] = s($app);


6. Running the application.

To run demo:

$ php -S localhost:8000 -t public

Once we had visited the URL where our application have been served we can check that it works as we expect.

7. Conclusions.

At this point, the users will be ready to get contact with StratusPHP. They could try the new characteristics we will show soon with a similar project. We want to stress the StratusPHP abilities to modify the DOM elements of the page without reload the page. You can check that you could whrite or read about any dato. However we want you to remenber that StratusPHP is still developing and we will try a lot of things.

In the archive you could dowload an useful installation that we have reaized.

we thank you if you share this publication for another people to know about StratusPHP.

Fecha de publicación: 2020-06-21

Si desea enterarse por correo electrónico sobre nuestras próximas publicaciones y novedades en general, suscríbase a nuestro boletín.

Redes Sociales

Suscríbase también a nuestras redes sociales.
También por esos canales compartiremos nuestras novedades.


Para contactarnos puede escribirnos a: