Download the PHP package stefan-wiebe/elements without Composer

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

Elements

This is a simple library to construct HTML elements with PHP, mainly to avoid getting into a concatenation-hell.

1 Generating an element

1.1 Constructor

The first way to generate an Element is using its constructor.

It takes the following parameters

Parameter Type Description Example Default
$tag String The HTML-tag 'div' Required
$attributes array HTML-attributes ['id' => 'wrap-god'] array()
$content array The element's contents ['hi', $span] array()

You can put everything into an Element's contents as long as it parses to a String, including other Elements.

Classes can be passed as Array (as shown here) or using a String, separating them with spaces ('fresh mexican tortilla'). Note however that Strings will be exploded. As in the PHP-function.

1.2 Factory Method

There's also a fairly simple factory method for generating an Element only with a tag and the provided classes. As mentioned before, you can either provide an Array of classes or seperate them by spaces.

Parameter Type Description Example Default
$tag String The HTML-tag 'span' Required
$classes Array | String The classes 'winged-hussar' Required

2. Modifying Attributes

Since Elements implement ArrayAccess, its attributes can be manipulated by accessing the Element like an Array.

Let's say we wanted to give an id to the Element created in 1.2. We would do it like this:

With the exception of classes and styles, all attributes are Strings.

2.1 Classes

Classes are internally handled as Arrays, as previously mentioned. This enables you to easily add and remove classes without having to worry about having one space too many or too few.

If you wanted to add some to our pre-existing div, you could do it like so:

Replacing them works in the same way as declaring them in the first place:

2.2 Styles

Styles are also handled as Arrays, however unlike classes, they are associative Arrays, since it'd be kind of hard otherwise.

You can add classes like so:

Note that you can also pass a String to set an Element's styles, but it's not recommended since I can't guarantee that the regex will work 100% of the time. I didn't find any glaring issues, but I also didn't test a lot.

3 Content

An Element's contents can be anything that parses to a String. They are kept as array and can be manipulated using the addContent($content) and setContent(array $content) methods.

Example:

4 Outputting Elements

In order to output an Element, simply echo it or cast it to a string if you need to.


All versions of elements with dependencies

PHP Build Version
Package Version
No informations.
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 stefan-wiebe/elements contains the following files

Loading the files please wait ....