LFT
  • Namespace
  • Class
  • Tree

Namespaces

  • Docoflow
    • Contracts
    • Entity
    • Facades
    • Models
    • Traits
  • Docolight
    • Agno
      • Traits
    • Container
    • Http
      • Contracts
    • Rest
      • Handler
      • Http
    • Support
      • Debug
      • Traits
  • Docotory
    • Traits
  • None

Classes

  • ActiveRecordWrapper
  • Arr
  • Carbonate
  • ClassLoader
  • Collection
  • CollectionDataProvider
  • Facade
  • Factory
  • Fluent
  • Html
  • IterablePager
  • Repository
  • Set
  • Str

Class Fluent

This class can wrap your array to an object, make it more safe to access and maintain it's attributes. You can try to fill the attribute with your Model Attributes or a bunch of collection of models.

Let's take an example:

// This is your array:

$array = array( 'foo' => 'bar', 'baz' => 'qux' );

// Wrap your array with this class:

$myCoolArray = new \Docolight\Support\Fluent($array);

// After that you can do something like this:

echo $myCoolArray->foo;    // bar  // equals with: echo $myCoolArray['foo'];
echo $myCoolArray->baz;    // qux  // equals with: echo $myCoolArray['baz'];
echo $myCoolArray->blah;   // null // equals with: echo $myCoolArray['blah'];

$myCoolArray->blah = 'bruh'; // equals with $myCoolArray['blah'] = 'bruh';

echo $myCoolArray->blah;   // bruh
echo $myCoolArray['blah']; // bruh

// To get single attribute

$foo = $myCoolArray->get('foo');


// To get specific attributes:

$fooBaz = $myCoolArray->only(array('foo', 'bar'));


// To get all atributes except some attributes:

$fooBlah = $myCoolArray->except(array('baz'));


// To get all attributes:

$attributes = $myCoolArray->get();


// To remove single attribute:

$this->remove('foo');


// To remove specific attributes:

$this->clear(array('foo', 'baz'));


// To clear all attributes:

$myCoolArray->nuke();


// To convert all atributes to normal array:

$myArray = $myCoolArray->toArray();


// Oh, once more, you can also echoing the object, and convert them to JSON automagically!

echo $myCoolArray; // Output is a JSON // or equal with: echo $myCoolArray->toJson();

// In PHP >= 5.4, you can convert this object to json by:

$myJSON = json_encode($myCollArray); // Equals with: $myJSON = json_encode($myCoolArray->toArray());
Docolight\Support\Fluent implements ArrayAccess, JsonSerializable, Docolight\Http\Contracts\Arrayable

Direct known subclasses

Docoflow\Flo

Namespace: Docolight\Support
Author: Krisan Alfa Timur krisanalfa@docotel.co.id
Located at Docolight/Support/Fluent.php

Methods summary

public
# __construct( array $default = array() )

Initialize the class.

Initialize the class.

Parameters

$default
Default attribute inside this class
public static
# make( array $default = array() )

Initialize the class statically.

Initialize the class statically.

Parameters

$default
Default attribute inside this class
public boolean
# has( string $index )

Determine if index is exist in attributes.

Determine if index is exist in attributes.

Parameters

$index

Returns

boolean
public
# remove( string $index )

Remove an attributes.

Remove an attributes.

Parameters

$index
public
# set( string $index, mixed $value )

Set an attribute value.

Set an attribute value.

Parameters

$index
$value
public
# fill( mixed $attributes )

Bulk insert attributes.

Bulk insert attributes.

Parameters

$attributes

Implementation of

Docolight\Http\Contracts\Arrayable::fill()
public
# clear( array $attributes )

Bulk remove attributes by an array contains indexes name you want to remove.

Bulk remove attributes by an array contains indexes name you want to remove.

Parameters

$attributes

Returns

public array
# only( array $attributes )

Get a list of array which only if the key is exists on the given argument.

Get a list of array which only if the key is exists on the given argument.

Parameters

$attributes
List of array key you want to get from your attributes.

Returns

array

See

Docolight\Support\Arr::only()
public array
# except( array $attributes )

Get a list of array except the given array of index.

Get a list of array except the given array of index.

Parameters

$attributes
List of array keys you want to exclude from your array.

Returns

array

See

Docolight\Support\Arr::except()
public
# nuke( array $default = array() )

Reset the attributes.

Reset the attributes.

Parameters

$default
Default attributes after nuking current attributes.
public mixed
# get( string $index, mixed $default = null )

Get an attribute value.

Get an attribute value.

Parameters

$index
$default
Default value if index doesn't exist

Returns

mixed
public mixed
# attributes( mixed $attributes = null, mixed $default = null )

Get attributes value.

Get attributes value.

Parameters

$attributes
If it's null, it will return the whole attributes, if it's array, it will fetch only the given array value
$default
Default value if attributes don't exist

Returns

mixed
public array
# toArray( mixed $attributes = null )

Convert this implementation object to array.

Convert this implementation object to array.

Parameters

$attributes
Something you want to convert to array.

Returns

array

See

Docolight\Support\Arr::arToArray()
public array
# castToArray( )

Convert implementation to an array.

Convert implementation to an array.

Returns

array

Implementation of

Docolight\Http\Contracts\Arrayable::castToArray()
public string
# toJson( const $options = null )

Convert attributes to readable JSON.

Convert attributes to readable JSON.

Parameters

$options
JSON Decoding options.

Returns

string
public
# offsetSet( string $index, mized $value )

Set an attribute value.

Set an attribute value.

Parameters

$index
$value

Implementation of

ArrayAccess::offsetSet()
public boolean
# offsetExists( string $index )

Determine if index is exist in attributes.

Determine if index is exist in attributes.

Parameters

$index

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public
# offsetUnset( string $index )

Remove an attributes.

Remove an attributes.

Parameters

$index

Implementation of

ArrayAccess::offsetUnset()
public mixed
# offsetGet( string $index, mixed $default,… )

Get an attribute value.

Get an attribute value.

Parameters

$index
$default,…
Default value if index doesn't exist

Returns

mixed

Implementation of

ArrayAccess::offsetGet()
public array
# jsonSerialize( )

JsonSerializable implementation.

JsonSerializable implementation.

Returns

array

Implementation of

JsonSerializable::jsonSerialize()
public
# __set( string $index, mized $value )

Set an attribute value.

Set an attribute value.

Parameters

$index
$value
public mixed
# __get( string $index, mixed $default,… )

Get an attribute value.

Get an attribute value.

Parameters

$index
$default,…
Default value if index doesn't exist

Returns

mixed
public boolean
# __isset( string $index )

Determine if index exists in attributes.

Determine if index exists in attributes.

Parameters

$index

Returns

boolean
public
# __unset( string $index )

Remove an attributes.

Remove an attributes.

Parameters

$index
public string
# __toString( )

Convert your collection to JSON.

Convert your collection to JSON.

Returns

string

Properties summary

protected array $attributes

Data Attribute in this class.

Data Attribute in this class.

# array()
protected array $jsonAble

Use this to convert attributes to json.

Use this to convert attributes to json.

# null
LFT API documentation generated by ApiGen