PHP Classes

Fuse Array: Manage arrays with read only properties

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (9 months ago) RSS 2.0 feedStarStarStar 49%Total: 255 All time: 7,860 This week: 455Up
Version License PHP version Categories
fuse-array 1.0.9BSD License5.3PHP 5, Data types
Description 

Author

This class can manage arrays with read only properties.

It implements the ArrayAccess interface so its objects can be manipulated as if they are arrays of value elements.

The class can make certain array entries read-only, so it throws an exception if an application attempts to change the values of those entries.

Innovation Award
PHP Programming Innovation award nominee
July 2014
Number 4


Prize: One downloadable copy of Komodo IDE
Sometimes it is necessary to prevent that applications change the values of certain array entries.

This class implements the array access interface to emulate array values that may have certain entries disabled for change.

This way it can detect and prevent that applications attempt to change read-only array entry values.

Manuel Lemos
Picture of Thomas Björk
  Performance   Level  
Name: Thomas Björk <contact>
Classes: 11 packages by
Country: Sweden Sweden
Age: 56
All time rank: 1581 in Sweden Sweden
Week rank: 192 Down2 in Sweden Sweden Down
Innovation award
Innovation award
Nominee: 3x

Example

<?php
include('../extends/configarray.php');

$config = ConfigArray::ConvertIni('./exampleConfig.ini');
foreach(
$config as $key => $value) {
  echo
$key.' - '.$value.PHP_EOL;
}


Details

FuseArray

FuseArray is an implementation of an array with read-only capabilities.

Functions

public function Get($name)

A plain get-function. Identical to __get

public function Set($name, $value, $fuseOut = false)

An extended set-function which alse has the ability to set the property as read-only. If $fuseOut is set to true then the property will be read-only.

public function FuseOut($name)

FuseOut will set the property defined by $name as read-only.

public static function Convert($data, $fuseOut = false)

Convert is a static conservsion to FuseArray from a standard array or another FuseArray.

public function Import($data, $fuseOut = false)

Import is a dynamic conservsion to FuseArray from a standard array or another FuseArray.

Implemented functions

These functions are either basic functions in the class or functions for the implemented interfaces.

public function __construct()

public function __destruct()

public function __get($name)

public function __set($name, $value)

public function count()

public function offsetExists($offset)

public function offsetGet($offset)

public function offsetSet($offset, $value)

public function offsetUnset($offset)

public function serialize()

public function unserialize($serialized)

public function current()

public function key()

public function next()

public function prev()

public function rewind()

public function valid()

Usage

Can be used more or less as a standard array in many cases. The array functions in PHP (array_\*) will not work since the arrays produced by FuseArray are objects and not real arrays.

ConfigArray

ConfigArray is an extend of FuseArray which implements a simple way to handle configurations based on ini-files.

Functions

public static function ConvertIni($iniData, $fuseOut = true)

ConvertIni is a static method that will take either an dual layered array or a filename as its first argument and convert this into an config array.

[section]
property=value

Will be converted into

section.property=value

public function ImportIni($iniData, $fuseOut = true)

ImportIni is a dynamic method that will take either an dual layered array or a filename as its first argument and convert this into an config array.

[section]
property=value

Will be converted into

section.property=value

Repositories

This package can be found at the following places.

PHPClasses.org

http://www.phpclasses.org/fuse-array

GitHub

https://github.com/ultrix3x/FuseArray


  Files folder image Files (9)  
File Role Description
Files folder imageexamples (5 files)
Files folder imageextends (1 file)
Plain text file fusearray.php Class Main file with class
Accessible without login Plain text file LICENSE Data New license file
Accessible without login Plain text file README.md Data Changed format of the readme from readme.txt to readme.md

  Files folder image Files (9)  /  examples  
File Role Description
  Accessible without login Plain text file exampleConfig.ini Data Example ini-file used by the example
  Accessible without login Plain text file exampleConfig.php Example Example to read ini-file to use as an config
  Accessible without login Plain text file exampleConvert.php Example Example on how to load data statically
  Accessible without login Plain text file exampleFail.php Example Example on how not to use the class
  Accessible without login Plain text file exampleImport.php Example Example on how to load data dynamically

  Files folder image Files (9)  /  extends  
File Role Description
  Plain text file configarray.php Class En extend that reads and parses ini-files

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Reuses Unique User Downloads Download Rankings  
 100%1
Total:255
This week:0
All time:7,860
This week:455Up
 User Ratings  
 
 All time
Utility:70%StarStarStarStar
Consistency:65%StarStarStarStar
Documentation:-
Examples:75%StarStarStarStar
Tests:-
Videos:-
Overall:49%StarStarStar
Rank:2906