Download the PHP package rossato/declarative-php without Composer

On this page you can find all versions of the php package rossato/declarative-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package declarative-php

Declarative PHP

:hammer: Simple micro-framework for building declarative web applications in PHP :newspaper:

Minimal experimental PHP framework inspired by ReactDOM to create web pages in a declarative way.

Create dynamic elements through php classes that render into HTML.

Getting started

After installing this framework with composer require rossato/declarative-php you can build elements with the Element constructor: The class constructor receives 3 arguments: the element tag name, the properties array and the content of the element (its children):

This outputs an html div element with the custom class and text as content, like so: <div class="custom">text</div>

Nested examples

Elements can be nested, the third, fourth, and other parameters can be other elements

You can also supply an array of elements as children:

Generates the following:

Functional usage

You are supposed to create components like this:

Page example

The Page element is useful if you're doing top-level stuff, it is supposedly the page's HTML tag element:

Inspiration

React (the javascript library / framework) has an interesting way of defining components and their hierarchical relations. This experiment is supposed to explore that on PHP.

PHP already has a DOM library internally, but it's full of features such as querying and parsing, this library is only focused on building html elements that are sanitized so that you can just do stuff. This library is 2 source files big and handles attribute and content sanitization.

And this library wasn't made to be complicated, here's an oversimplification of how the element's content is made on the Element class:

You can probably read and understand this library in 15 minutes.

Problems you can solve using this

Transforming data in PHP to HTML is difficult because html is not strictly validated in general:

You think your browser will let you know that you mispelled 'span' on the second closing tag? Nope, the browser just silently goes on.

You can take advantage of PHP interpreter to tell you if something is incorrect with syntax errors that fail fast.

The idea is to declare in composition-based components all the visual logic, with the data that it needs to render fully.

React developers have been doing this in javascript, its tremendously useful and the same coding rules apply. Sadly implementing JSX is a huge chore and I don't think PHPX would catch on.

Managing data

Data has to be passed around in a top-down fashion:

Obviously, you're left alone regarding how and where you get data. But be advised: All security rules still apply and you must strip your tags from your data!.

Instalation

But you should use composer to install the project from the command line, at the folder of your project:

Just don't forget to require composer's autoload on your entry point:

And at the top of every file you need to use the Element class, you write this:

Now everytime you write Element you'll be referring to this project's Element.

Alternatively, you can download this repository and require the files inside /src/ manually, no credits required.

Automatic Compressing of Styles in Elements

Alright, there's just ONE piece of magic in this library: they style property of html elements are heavily featured in two ways:

  1. If you put in an object on the property, it becomes the string representation of that object:

  2. But if you put a raw string, then we minimize it with a simplistic function to save a few bytes every now and then:

html

$script = new Element("script", [], "console.log('hi

');");

echo $script; // '"

$script->isRawHTML = true;

echo $script; // '" javascript async function requestData() { const element = document.querySelector(".content"); document.querySelector(".content").innerHTML = "loading..."; const response = await fetch("/api/endpoint/"); const html = await response.text(); document.querySelector(".content").innerHTML = content; }

requestData();



And at the endpoint you could just handle that

## Testing and Balancing

The idea about the declarative programming style is that you can render different things based on arbitrary conditions:

Or, you could setup caching and serve the cache to end users and bypass it for developers (but keeping the cache files intact).

## Performance

Since we're developing the HTML structure in the backend, the server CPU usage will be increased, I think most servers have low CPU usage and high memory latency problems, like database calls and file readings.

Every request re-renders the entire structure, so caching the result (memoing) is advised. Guess how the you do that:

php

# Licence

You are free to use this and do what you want with it, like changing, redistributing, even claiming as your own, just don't annoy me as I provide no warranty or anything.

All versions of declarative-php with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rossato/declarative-php contains the following files

Loading the files please wait ....