PHPackages                             consik/yii2-fluent - 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. consik/yii2-fluent

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

consik/yii2-fluent
==================

Yii2 behavior that implements fluent interface for changing component's properties

1.0.0(9y ago)07MITPHPPHP ^5.6 || ^7.0

Since Dec 23Pushed 9y agoCompare

[ Source](https://github.com/consik/yii2-fluent)[ Packagist](https://packagist.org/packages/consik/yii2-fluent)[ RSS](/packages/consik-yii2-fluent/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Yii2 Fluent Component Behavior
==============================

[](#yii2-fluent-component-behavior)

Behavior that implements fluent interface methods for component attributes.

[![Latest Stable Version](https://camo.githubusercontent.com/0523c55c18c7e2aaa1dc20122a2e28beed5c5ea695c51966a0be68c2e8ff6caa/68747470733a2f2f706f7365722e707567782e6f72672f636f6e73696b2f796969322d666c75656e742f762f737461626c65)](https://packagist.org/packages/consik/yii2-fluent)[![Total Downloads](https://camo.githubusercontent.com/0790e0e2d21c5d71a7b22eb4c37ca7f45d01d6c5d4bf937ab4489d6ba7456205/68747470733a2f2f706f7365722e707567782e6f72672f636f6e73696b2f796969322d666c75656e742f646f776e6c6f616473)](https://packagist.org/packages/consik/yii2-fluent)[![License](https://camo.githubusercontent.com/4458f493d76c7e132ce7a8bf0274b0729ac36863f8f61ff068af7b5f7761bf86/68747470733a2f2f706f7365722e707567782e6f72672f636f6e73696b2f796969322d666c75656e742f6c6963656e7365)](https://packagist.org/packages/consik/yii2-fluent)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require consik/yii2-fluent

```

or add

```
"consik/yii2-fluent": "^1.0"
```

FluentComponentBehavior class description
-----------------------------------------

[](#fluentcomponentbehavior-class-description)

### Properties

[](#properties)

- ` array $attributes = []`

Associative or simple array of attributes that can be changed using fluent interface. For associative definition `key` is alias for attributes methods; Value is always component attribute name;

- ` string $initArraysIfEmpty = true`

Defines need bahavior to initialize property as array if it's empty and !is\_array() when calling array-access fluent methods(like `add*Property*($item)`)

### Public methods

[](#public-methods)

Universal fluent methods for owner component

- ` $this setProperty(string $property, mixed $value)`

Sets value to component property

- ` $this unsetProperty(string $property)`

Unsets component property

- ` $this addItemTo(string $arrName, mixed $value, bool $initOnEmpty = true)`

Adds `$item` to array property with name `$arrName`;

Throws exception if `$component->{$arrName}` is `!empty() && !is_array()`;

initializes `$component->{$arrName}` as empty array if `($initOnEmpty && empty($component->{$arrName}))` ;

Examples
--------

[](#examples)

### Short definition of behavior. Behavior will implement all available fluent methods for ALL component attributes

[](#short-definition-of-behavior-behavior-will-implement-all-available-fluent-methods-for-all-component-attributes)

```
