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