Download the PHP package sy/component without Composer

On this page you can find all versions of the php package sy/component. 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 component

sy/component

The concept of component allows you to build an application as a tree of simpler components (Composite design pattern). And each component can be reusable.

Basically we can assume that a component is a stringable object. At this point, it just use a template to generate a string that can be in any format (html, xml, json, plain text etc...). On top of this, we can build web components by adding css and js properties.

The class Sy\Component is the base class of other web components (sy/webcomponent) and html page and elements (sy/html) like form and table etc...

Component template engine

The template engine used is sy/template

Template syntax notion: slot and block

Example with setVar method for filling a slot, your PHP script:

Template file, template.tpl:

Output result:

Example with setBlock method, your PHP script:

Template file, template.tpl:

Output result:

ELSE block

When a block is not set, you can use the ELSE block to show a default content.

Set block with isolated vars

By default, when the second parameter of setBlock method is empty, it will use vars globally set for setting slots in the block scope. It is possible to use isolated vars for setting slots on the block scope with the second parameter.

Result:

Set blocks using a data array

Template file, template.html:

Output:

Alternative template syntax

It's possible to use simple PHP template syntax. You must specify that you are using a PHP template file:

PHP template file, template.tpl:

Output result:

Create a component

Create a custom class derived from Sy\Component class.

For example in Hello.php

Hello.tpl

Use your component:

Add a component in another one

Use setVar method to add a component in another one.

Component actions

The actionDispatch method help you to call action method.

This method takes 2 arguments:

An action method name must be suffixed by 'Action': fooAction

For example in MyComponent.php

Component translators

Translator can be added in a Component. Each Translator will load translation data from a file in a specified directory. This translation file must be named as the detected language. For example, if the detected language is "fr", the PHP Translator will try to load "fr.php". And Gettext Translator will try to load "fr.mo".

This feature is provided by the library sy/translate

Language detection

Language will be detected using these variables in this order:

  1. $_SESSION['sy_language']
  2. $_COOKIE['sy_language']
  3. $_SERVER['HTTP_ACCEPT_LANGUAGE']

Translation methods

Exemple:

PHP Translation file:

Template file:

Output result:

Add multiple translators

It's possible to add multiple translators in a component. The order of addition is important because the translate process will stop right after the first translation data found.

Translators transmission to inner web component

When adding a web component B in a web component A, all the translators of A will be added into B.

Translation file added in component A:

Translation file added in component C:

Output result:

The translator of A is transmitted to B and C. C will use his own translator in priority.

We need to use the mount method here to register callbacks on the mount event triggered just before the rendering stage. This is because we need to ensure that all the leaf components received the translators from their parents components.


All versions of component with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.0
sy/template Version ^2
sy/http Version ^1
sy/debug Version ^1
sy/translate Version ^1.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 sy/component contains the following files

Loading the files please wait ....