GithubHelp home page GithubHelp logo

thenlabs / stratus-bundle Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 239 KB

Extends Symfony to the full stack development with integration of StratusPHP.

License: MIT License

PHP 100.00%
symfony symfony-bundle ui reactive event-driven ajax ajax-request promote ux-ui ux

stratus-bundle's Introduction

ThenLabsStratusBundle

Extends Symfony to the full stack development with integration of StratusPHP.

Notice: Like StratusPHP, this project is also in development and should not be used in a real project yet.

Installation.

Install StratusPHP specifying the development version.

$ composer require thenlabs/stratus-php 1.0.x-dev

Install the maker bundle in case it isn't.

$ composer require symfony/maker-bundle --dev

Install this bundle:

$ composer require thenlabs/stratus-bundle dev-master

Usage.

Creating reactive pages.

Once the installation has finished we can create the application pages that will bring the integration with StratusPHP.

In order to create a new page run the next command:

$ php bin/console make:stratus-page main

In this case, "main" refers to the page name.

As you can see, they was created three files, a template, a controller, and a class. You can review these files and edit it according to the project needs.

In the controller class you can fix the page route. By default will be like the page name, /main in this case.

The template file is empty by default but you should edit it with the page view.

In this example we will develop the Example 2 of the StratusPHP docs.

{# templates/main-stratus-page.html.twig #}

{% extends 'base.html.twig' %}

{% block body %}
    <input s-element="myInput" type="text">
    <label s-element="myLabel"></label>
    <button s-element="myButton" s-element-event-click="clickOnTheButton">Greet</button>
{% endblock %}

It’s very important highligh the s-element attribute and his value on key elements of the page view.

<?php
// src/StratusPage/MainStratusPage.php

namespace App\StratusPage;

use ThenLabs\Bundle\StratusBundle\Annotation\StratusPage;
use ThenLabs\Bundle\StratusBundle\AbstractPage;

/**
 * @StratusPage(template="main-stratus-page.html.twig")
 */
class MainStratusPage extends AbstractPage
{
    public function clickOnTheButton(): void
    {
        $this->myLabel->textContent = 'Hello ' . $this->myInput->value;
    }
}

We want to highligh that textContent and value they are properties managed in real time on the browser. Theorically, it's possible manage any property type and react to any event.

If you want to know all the StratusPHP posibilities, you can see the examples in his documentation.

Testing results.

$ symfony server:start

Now, if we access to the http://localhost:8000/main/ we will obtains the next results.

Getting services inside page classes.

<?php
// src/StratusPage/MainStratusPage.php

// ...

/**
 * @StratusPage(template="main-stratus-page.html.twig")
 */
class MainStratusPage extends AbstractPage
{
    public function clickOnTheButton(): void
    {
        // getting the doctrine service.
        $doctrine = $this->controller->get('doctrine');

        // ...
    }
}

Pending features.

  1. Enable the support of autowiring services inside the page classes.

Known issues.

One of the most representative features of StratusPHP is its ability to send messages by streaming to the browser as can be seen in example 3. It is very important to keep in mind that this feature causes problems when it is being developed with the Symfony Local Web Server (symfony server: start). Instead, we recommend using PHP's internal server which you can run with the command php -S localhost: 8000 -t public /.

stratus-bundle's People

Contributors

andaniel05 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.