File dsl/standard/StandardArray.class.php

Last commit: Tue Jul 19 00:10:39 2022 +0200	Jan Dankert	Fetched from upstream.
1 <?php 2 namespace dsl\standard; 3 4 use dsl\context\BaseScriptableObject; 5 6 class StandardArray extends BaseScriptableObject 7 { 8 private $value; 9 public $length = 0; 10 11 /** 12 * StandardArray constructor. 13 * @param $value 14 */ 15 public function __construct($value=null) 16 { 17 $this->value = $value; 18 if ( $value ) 19 $this->length = sizeof( $this->value ); 20 } 21 22 23 public function of() { 24 25 return func_get_args(); 26 } 27 28 29 public function __toString() 30 { 31 return '['.implode(',',$this->value).']'; 32 } 33 34 /** 35 * @return mixed 36 */ 37 protected function getValue() 38 { 39 return $this->value; 40 } 41 42 /** 43 * @return array|null 44 */ 45 public function getInternalValue() 46 { 47 return $this->value; 48 } 49 50 public function concat( $concat ) 51 { 52 return new StandardArray( array_merge($this->value,(array)$concat)); 53 } 54 public function fill( $value,$start,$count) 55 { 56 return array_fill( $value,$start,$count ); 57 } 58 public function forEach( $func ) 59 { 60 return array_walk( $this->value, $func ); 61 } 62 public function includes( $search ) 63 { 64 return array_search( $search, $this->value ) !== false; 65 } 66 public function indexOf( $search ) 67 { 68 return array_search( $search, $this->value ); 69 } 70 public function lastIndexOf( $search ) 71 { 72 $found = array_keys( $this->value,$search ); 73 return end( $found ); 74 } 75 public function isArray( $val ) 76 { 77 return is_array( $val ); 78 } 79 public function join( $split = ',' ) 80 { 81 return implode( $split,$this->value ); 82 } 83 public function keys() 84 { 85 return array_keys($this->value); 86 } 87 public function values() { 88 return array_values($this->value); 89 } 90 public function pop() 91 { 92 return array_pop( $this->value ); 93 } 94 public function push( $value ) 95 { 96 return array_push( $this->value,$value ); 97 } 98 public function reverse() 99 { 100 return array_reverse($this->value); 101 } 102 public function shift() 103 { 104 return array_shift( $this->value ); 105 } 106 public function unshift($value) 107 { 108 return array_unshift( $this->value,$value ); 109 } 110 public function slice($from,$end = null ) 111 { 112 if ( $end ) 113 return array_slice( $this->value,$from,$end-$from); 114 else 115 return array_slice( $this->value,$from); 116 } 117 public function sort() 118 { 119 return asort( $this->value ); 120 } 121 public function get( $key ) 122 { 123 return @$this->value[ $key ]; 124 } 125 126 }
Download dsl/standard/StandardArray.class.php
History Tue, 19 Jul 2022 00:10:39 +0200 Jan Dankert Fetched from upstream. Mon, 27 Jun 2022 00:41:50 +0200 Jan Dankert Fetched from upstream. Mon, 6 Jun 2022 14:06:46 +0200 Jan Dankert First commit after fetching from upstream repo.