PHPackages                             webiny/std-lib - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. webiny/std-lib

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

webiny/std-lib
==============

Webiny StdLib Component

v1.6.1(8y ago)918.9k↓50%120MITPHPPHP ^7

Since Sep 20Pushed 8y ago9 watchersCompare

[ Source](https://github.com/Webiny/StdLib)[ Packagist](https://packagist.org/packages/webiny/std-lib)[ Docs](http://www.webiny.com/)[ RSS](/packages/webiny-std-lib/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (24)Used By (20)

StdLib
======

[](#stdlib)

The standard library is a set of core Webiny framework components that make coding a bit more pleasurable when working with some low level objects like strings, array, date time and url.

Install the component
---------------------

[](#install-the-component)

The best way to install the component is using Composer.

```
composer require webiny/std-lib
```

For additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/std-lib).

About
-----

[](#about)

The standard library consists of following libraries:

- [Exception](Exception)
- \[StdObject\] (StdObject)

.. and following helper traits:

- ComponentTrait
- FactoryLoaderTrait
- SingletonTrait
- ValidatorTrait
- StdLibTrait
- StdObjectTrait

ComponentTrait
--------------

[](#componenttrait)

This trait is used when creating a new Webiny Framework component. By implementing this trait you automatically get the possibility to register the required class loader libraries, services and additional parameters for your new component. The trait is based on two main methods `setConfig` and `getConfig`, both methods are defined as `public static`.

Here is an example Webiny Framework component that uses the `ComponentTrait`.

```
$crypy = \Webiny\Component\Crypt::setConfig('ExampleConfig.yaml');
```

The `ExampleConfig.yaml` file is defined like this:

```
Crypt:
    Services:
        Password:
            Class: \Webiny\Component\Crypt\Crypt
            Arguments: [Blowfish, CCM, rijndael-128, _FOO_VECTOR]
        Cookie:
            Class: \Webiny\Component\Crypt\Crypt
            Arguments: [Blowfish, CCM, rijndael-128, _FOO_VECTOR]
    Bridge: \Webiny\Component\Crypt\Bridge\CryptLib\CryptLib
    ClassLoader:
        CryptLib: /var/www/Vendors/PHP-CryptLib/lib/CryptLib
```

There are couple of things you should notice:

- the root of yaml file matches the class name (`Crypt`) and the class name matches the root component namespace `\Webiny\Component\Crypt`
- the `Services` definition is based on rules defined by \[ServiceManager)(../ServiceManager) component and all services defined in the yaml file are automatically registered with the `ServiceManager` under the name `ComponentName.ServiceName` in this example that would be `Crypt.Password` and `Crypt.Cookie`
- the `Bridge` is an optional parameter. You can define as many optional parameters as you want
- the `ClassLoader` parameter is an array that contains the namespace as key and path as a value. All the definitions under the `ClassLoader` parameter are automatically assigned to Webiny Framework ClassLoader component

So basically as you see, the `ComponentTrait` does a lot of handy stuff and makes Webiny Framework components very neatly organised.

### Callback

[](#callback)

If you want to know when the configuration file on your class has been parsed, and all the services and class loader paths have been assigned, you can just define a `protected static function _postSetConfig` inside your component class, and the `ComponentTrait` will automatically call it each time you define a configuration for that class.

FactoryLoaderTrait
------------------

[](#factoryloadertrait)

A handy trait when you want to load some classes where the class name is defined as a string or inside a variable and you want to pass along some parameters to the constructor. You can also pass a interface or a class name that the factory class must implement/extend. This trait will first construct the object, with the given parameters, and then it will verify its instance against the given interface or a class. If everything matches, the class instance is returned, otherwise, and Exception is thrown.

```
class MyClass
{
    use FactoryTrait;

    function myMethod()
    {
        // let's say we have a class we want to construct
        // the class has a constructor defined like this __construct($param1, $param2)
        // the class should implement \Webiny\Crypt\Bridge\CryptInterface
        $class = '\SomeVendor\SomeLib\SomeClass';

        try {
            $classInstance = $this->factory($class, '\Webiny\Crypt\Bridge\CryptInterface', ['foo1', 'foo2']);
        } catch (\Webiny\StdLib\Exception\Exception $e) {
            throw $e; // the class probably doesn't implement the required interface
        }
    }
}
```

SingletonTrait
--------------

[](#singletontrait)

The `SingletonTrait` is used on classes that must implement [singleton pattern](http://en.wikipedia.org/wiki/Singleton_pattern). You just `use` the trait on the class you want to be singleton, and that's it.

There are two methods that you can optionally implement in your class, `public function init()` and `protected function _init()`, they are called only once and at the moment when you request a singleton instance.

```
class MyClass
{
    use SingletonTrait;

    protected function __init()
    {
        // this will be called only once
        $this->__somePrivateMethod();
    }
}
```

To use your class you just call the static `getInstance` method that is implemented by the trait.

```
$instance = MyClass::getInstance(); // this calls the internal __init method, but only the first time, when it creates the instance
```

StdLibTrait
-----------

[](#stdlibtrait)

Also a helper trait with some commonly used functions. The trait itself only supports a limited number of methods, but we plan to expand it with more, so feel free to give suggestions.

This trait, not only that it defines helper methods, but it also `uses` `ValidatorTrait` and `StdObjectTrait` traits.

StdObjectTrait
--------------

[](#stdobjecttrait)

This trait provides helper functions when working with `StdObject` library.

```
class MyClass
{
    use StdObjectTrait;

    public function test()
    {
        // create StringObject
        $this->str('This is a string');

        // create ArrayObject
        $this->arr(['one', 'two']);

        // create UrlObject
        $this->url('http://www.webiny.com/');

        // create DateTimeObject
        $this->dateTime('now');
    }
}
```

ValidatorTrait
--------------

[](#validatortrait)

This is a helper trait with some common validation methods like `isNull`, `isEmpty`, `isInstanceOf` and many more. Just view the class, all the methods are documented and, mostly self-explanatory.

Resources
---------

[](#resources)

To run unit tests, you need to use the following command:

```
$ cd path/to/Webiny/Component/StdLib/
$ composer.phar install
$ phpunit

```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~50 days

Recently: every ~5 days

Total

23

Last Release

3154d ago

PHP version history (3 changes)v1.0.0PHP &gt;=5.4.0

v1.3.0PHP &gt;=5.5.9

1.5.x-devPHP ^7

### Community

Maintainers

![](https://www.gravatar.com/avatar/4440afa738ed146b05c06073a90345e0464c4f4d042b039532d881ca24859d77?d=identicon)[SvenAlHamad](/maintainers/SvenAlHamad)

---

Top Contributors

[![SvenAlHamad](https://avatars.githubusercontent.com/u/3808420?v=4)](https://github.com/SvenAlHamad "SvenAlHamad (30 commits)")

---

Tags

factoryarraystringdatetimesingleton

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webiny-std-lib/health.svg)

```
[![Health](https://phpackages.com/badges/webiny-std-lib/health.svg)](https://phpackages.com/packages/webiny-std-lib)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[phootwork/lang

Missing PHP language constructs

1224.8M8](/packages/phootwork-lang)[danielstjules/php-pretty-datetime

Generates human-readable strings for PHP DateTime objects

5791.9k](/packages/danielstjules-php-pretty-datetime)[illuminatech/array-factory

Allows DI aware object creation from array definition

2159.6k6](/packages/illuminatech-array-factory)[michaldudek/foundation

A set of useful PHP classes.

13111.9k13](/packages/michaldudek-foundation)[clausnz/php-helpers

A Collection of useful php helper functions.

388.7k](/packages/clausnz-php-helpers)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
