Best Atoum code snippet using phpArray.__get
ABG_PhpToXls.cls.php
Source:ABG_PhpToXls.cls.php
1<?php2################################################################################3# Project : ABG Framework4# File : ABG_PhpToXls.cls.php5# V1.0.0 27/03/20116# © G. BENABOU / ABG Soft PARIS FRANCE7#8# PHP class to export PHP array to Excel file9#10#*******************************************************************************11#12#--- PROPERTIES-----------------------------------------------------------------13# FileName Xls file name14# PhpArray Input array to build Xls data15# XlsDir Output directory for Xls file16#17#--- METHODS -------------------------------------------------------------------18# public __construct(PhpArray, XlsDir, FileName, PrtMsg)19# Initialize class & set properties20#...............................................................................21# public BuildXls(PhpArrayl)22# Main loop on PhpArray to build xls cells23#...............................................................................24# public SaveFile()25# Utility to write xls file to disk26#...............................................................................27# public SendFile()28# Utility to HTTP-send xls data to caller29#30#--- EXCEPTIONS ----------------------------------------------------------------31# . Unknown GET attribute : Specified attribute is not a property32# . Unknown SET attribute : -id-33# . Unable to create directory : Failure while buiding XlsDir directory34# . Null PHP input array : Source array is null35# . Unable to open Xls file : Failure while opening Xls file for writing36# . Invalid Xls file name : ill formatted name37# . Xls data not available : Assignement of PhpArray property never made38################################################################################3940/*** Required stuff ***********************************************************/41 // None4243### Class ABG_PhpToXls ########################################################44class ABG_PhpToXls {45 /*** Loacal constants *******************************************************/46 const C_DefName = 'ABG'; // Default for xls file name47 /*** Private Properties *****************************************************/48 private $PrtMsg; // Allow/deny printing end message after saving file49 private $XlsData; // Xls representaion of input PHP array50 //... Get'able ......51 private $_PhpArray = array();52 private $_XlsDir;53 private $_FileName;5455 ### C O N S T R U C T O R ###################################################56 /*** obj __construct(array PhpArray, str XlsDir, FileName, bool PrtMsg) ********57 Initialize class & set properties58 - PhpArray : PHP array to convert to Xls59 - XlsDir : Directory for xls file; default to current60 - FileName : Name for xls file; default to 'ABG'61 - PrtMsg : Validate printing exit message in SaveFile; default to false62 - RETURN : ABG_PhpToXls object63 *****************************************************************************/64 public function __construct($_PhpArray=null, $_XlsDir=null, $_FileName=null, $_PrtMsg=false) {65 $this->XlsDir = $_XlsDir;66 $this->FileName = $_FileName;67 if(isset($_PrtMsg))68 $this->PrtMsg = $_PrtMsg;69 if(isset($_PhpArray))70 $this->PhpArray = $_PhpArray;71 } // ABG_PhpToXls::__construct7273 /*** mixed __Get(str Attr) **************************************************/74 protected function __Get($_Attr){75 switch($_Attr){76 case 'PhpArray' : //flow77 case 'XlsDir' : // flow78 case 'FileName' : $Attr_ = "_$_Attr"; return($this->$Attr_);79 default : throw new exception("Unknown GET attribute <u><b>$_Attr</b></u>");80 }81 } // ABG_PhpToXls::__Get8283 /*** void __Set(str Attr, Mixed Value) **************************************/84 protected function __Set($_Attr, $_Value){85 switch($_Attr){86 case 'PhpArray' : $this->BuildXls($_Value); break;87 case 'XlsDir' :88 if(isset($_Value)) {89 $_Value = rtrim($_Value, "/\\");90 if(!is_dir($_Value))91 if(!@mkdir($_Value, 0777, true))92 throw new exception("Unable to create directory <u><b>$_Value</b></u>");93 $this->_XlsDir = $_Value;94 } else95 $this->_XlsDir = getcwd();96 break;97 case 'FileName' :98 if(isset($_Value)){99 $P_ = pathinfo($_Value, PATHINFO_FILENAME);100 $N_ = preg_match ("/[\"%,\'\/:;<>?]/", $_Value);101 if(empty($P_) || (bool)$N_)102 throw new exception("Invalid Xls file name <u><b>\"$_Value\"</b></u>");103 if(strtolower(pathinfo($_Value, PATHINFO_EXTENSION)) <> 'xls')104 $_Value = "$_Value.xls";105 $this->_FileName = $_Value;106 } else107 $this->_FileName = self::C_DefName;108 break;109 default : throw new exception("Unknown SET attribute <u><b>$_Attr</b></u>");110 }111 } // ABG_PhpToXls::__Set112113 ### P U B L I C M E T H O D S ##############################################114 /**** str BuildXls(array PhpArray) ********************************************115 Main loop on PhpArray to build xls cells116 - PhpArray : Optional; array to parse117 - RETURN : Xls data (also in XlsData)118 *****************************************************************************/119 public function BuildXls($_PhpArray=null) {120 $this->XlsData = "";121 if(isset($_PhpArray))122 $this->_PhpArray = $_PhpArray;123 $_PhpArray = $this->_PhpArray;124 if(!isset($_PhpArray))125 throw new exception('Null PHP input array');126 $Res_ = pack("S*", 0x809, 8, 0,0x10, 0, 0);127 foreach($_PhpArray as $RowNo_=>$RowS_)128 foreach($RowS_ as $ColNo_=>$Cell_)129 $Res_ .= $this->BuildCell($RowNo_, $ColNo_, $Cell_);130 $Res_ .= pack('S*', 0x0A, 0);131 $this->XlsData = $Res_;132 return($Res_);133 } // ABG_PhpToXls::BuildXls134135 /*** void SaveFile() *********************************************************136 Utility to write xls file to disk137 *****************************************************************************/138 public function SaveFile() {139 if(empty($this->XlsData))140 throw new exception('Xls data not available');141 $Path_ = $this->_XlsDir.DIRECTORY_SEPARATOR.$this->_FileName;142 $Hnd_ = @fopen($Path_, "wb");143 if($Hnd_===false)144 throw new exception("Unable to open Xls file <u><b>$Path_</b></u>");145 fwrite($Hnd_, $this->XlsData);146 fclose($Hnd_);147$Msg_ = <<< ABGHereDoc148 <div style="color: ActiveCaption; font: bold 18px sans-serif; padding-top:48px; text-align: center;">149 File <span style="color: red;">$Path_ </span> now saved to disk150 </div>151ABGHereDoc;152 if($this->PrtMsg)153 print($Msg_) ;154 } // ABG_PhpToXls::SaveFile155156 /*** void SendFile()**********************************************************157 Utility to send (HTTP) xls data to caller158 *****************************************************************************/159 public function SendFile(){160 if(empty($this->XlsData))161 throw new exception('Xls data not available');162 header("Cache-Control: no-cache, must-revalidate");163 header("Content-Description: ABG_PhpToXls Generated XLS Data");164 header("Content-Disposition: attachment; filename=\"$this->_FileName\"");165 header('Content-Transfer-Encoding: binary');166 header('Content-Type: application/force-download');167 header('Content-Type: application/octet-stream');168 header("Content-type: application/x-msexcel");169 header("Expires: Mon, 1 Apr 1974 05:00:00 GMT");170 header("Last-Modified: ".gmdate("D,d M YH:i:s")." GMT");171 header("Pragma: no-cache");172 print($this->XlsData);173 } // ABG_PhpToXls::SendFile174175 /*** void ExceptPrint(Except) ************************************************176 Utility to print error message from exceptions177 *****************************************************************************/178 static public function ExceptPrint($_Except){179 $Msg_ = "<b>Fatal ".get_class($_Except)." : </b>";180 $Msg_ .= $_Except->GetMessage()." in <b>".$_Except->GetFile();181 $Msg_ .= "</b> on line <b>".$_Except->GetLine()."</b><br />\n";182 print($Msg_);183 } // ABG_PhpToXls::ExceptPrint184185 ### P R I V A T E M E T H O D S ###########################################186 /*** str BuildCell(RowNo, ColNo, Cell) ***************************************187 Utility to build cell data according to type(int, float, string, boolean)188 - RowNo : Row number in spread sheet189 - ColNo : Column190 - Cell : Data to convert to xls format191 - RETURN : Piece of formatted data for the cell192 *****************************************************************************/193 private function BuildCell($_RowNo, $_ColNo, $_Cell) {194 if(is_string($_Cell)) {195 $Len_ = strlen($_Cell);196 return(pack("S*", 0x0204, $Len_ + 8, $_RowNo, $_ColNo, 0x00, $Len_).$_Cell);197 }198 if(is_int($_Cell))199 return(pack("S*", 0x027E, 10, $_RowNo, $_ColNo, 0x00).pack("I", ($_Cell<<2) | 2));200 if(is_float($_Cell))201 return(pack("S*", 0x0203, 14, $_RowNo, $_ColNo, 0x00).pack("d", $_Cell));202 if(is_bool($_Cell))203 return($this->BuildCell($_RowNo, $_ColNo, (int)($_Cell ? 1 : 0)));204 // Returns a null cell205 return(pack("S*", 0x0201, 6, $_RowNo, $_ColNo, 0x17));206 } // ABG_PhpToXls::BuildCell207208} ### End class ABG_PhpToXls #################################################
...
excel.php
Source:excel.php
1<?php2################################################################################3# Project : ABG Framework4# File : ABG_PhpToXls.cls.php5# V1.0.0 27/03/20116# � G. BENABOU / ABG Soft PARIS FRANCE7#8# PHP class to export PHP array to Excel file9#10#*******************************************************************************11#12#--- PROPERTIES-----------------------------------------------------------------13# FileName Xls file name14# PhpArray Input array to build Xls data15# XlsDir Output directory for Xls file16#17#--- METHODS -------------------------------------------------------------------18# public __construct(PhpArray, XlsDir, FileName, PrtMsg)19# Initialize class & set properties20#...............................................................................21# public BuildXls(PhpArrayl)22# Main loop on PhpArray to build xls cells23#...............................................................................24# public SaveFile()25# Utility to write xls file to disk26#...............................................................................27# public SendFile()28# Utility to HTTP-send xls data to caller29#30#--- EXCEPTIONS ----------------------------------------------------------------31# . Unknown GET attribute : Specified attribute is not a property32# . Unknown SET attribute : -id-33# . Unable to create directory : Failure while buiding XlsDir directory34# . Null PHP input array : Source array is null35# . Unable to open Xls file : Failure while opening Xls file for writing36# . Invalid Xls file name : ill formatted name37# . Xls data not available : Assignement of PhpArray property never made38################################################################################3940/*** Required stuff ***********************************************************/41 // None4243### Class ABG_PhpToXls ########################################################44class Excel {45 /*** Loacal constants *******************************************************/46 const C_DefName = 'ABG'; // Default for xls file name47 /*** Private Properties *****************************************************/48 private $PrtMsg; // Allow/deny printing end message after saving file49 private $XlsData; // Xls representaion of input PHP array50 //... Get'able ......51 private $_PhpArray = array();52 private $_XlsDir;53 private $_FileName;5455 ### C O N S T R U C T O R ###################################################56 /*** obj __construct(array PhpArray, str XlsDir, FileName, bool PrtMsg) ********57 Initialize class & set properties58 - PhpArray : PHP array to convert to Xls59 - XlsDir : Directory for xls file; default to current60 - FileName : Name for xls file; default to 'ABG'61 - PrtMsg : Validate printing exit message in SaveFile; default to false62 - RETURN : ABG_PhpToXls object63 *****************************************************************************/64 public function __construct($_PhpArray=null, $_XlsDir=null, $_FileName=null, $_PrtMsg=false) {65 $this->XlsDir = $_XlsDir;66 $this->FileName = $_FileName;67 if(isset($_PrtMsg))68 $this->PrtMsg = $_PrtMsg;69 if(isset($_PhpArray))70 $this->PhpArray = $_PhpArray;71 } // ABG_PhpToXls::__construct7273 /*** mixed __Get(str Attr) **************************************************/74 public function __Get($_Attr){75 switch($_Attr){76 case 'PhpArray' : //flow77 case 'XlsDir' : // flow78 case 'FileName' : $Attr_ = "_$_Attr"; return($this->$Attr_);79 default : throw new exception("Unknown GET attribute <u><b>$_Attr</b></u>");80 }81 } // ABG_PhpToXls::__Get8283 /*** void __Set(str Attr, Mixed Value) **************************************/84 public function __Set($_Attr, $_Value){85 switch($_Attr){86 case 'PhpArray' : $this->BuildXls($_Value); break;87 case 'XlsDir' :88 if(isset($_Value)) {89 $_Value = rtrim($_Value, "/\\");90 if(!is_dir($_Value))91 if(!@mkdir($_Value, 0777, true))92 throw new exception("Unable to create directory <u><b>$_Value</b></u>");93 $this->_XlsDir = $_Value;94 } else95 $this->_XlsDir = getcwd();96 break;97 case 'FileName' :98 if(isset($_Value)){99 $P_ = pathinfo($_Value, PATHINFO_FILENAME);100 $N_ = preg_match ("/[\"%,\'\/:;<>?]/", $_Value);101 if(empty($P_) || (bool)$N_)102 throw new exception("Invalid Xls file name <u><b>\"$_Value\"</b></u>");103 if(strtolower(pathinfo($_Value, PATHINFO_EXTENSION)) <> 'xls')104 $_Value = "$_Value.xls";105 $this->_FileName = $_Value;106 } else107 $this->_FileName = self::C_DefName;108 break;109 default : throw new exception("Unknown SET attribute <u><b>$_Attr</b></u>");110 }111 } // ABG_PhpToXls::__Set112113 ### P U B L I C M E T H O D S ##############################################114 /**** str BuildXls(array PhpArray) ********************************************115 Main loop on PhpArray to build xls cells116 - PhpArray : Optional; array to parse117 - RETURN : Xls data (also in XlsData)118 *****************************************************************************/119 public function BuildXls($_PhpArray=null) {120 $this->XlsData = "";121 if(isset($_PhpArray))122 $this->_PhpArray = $_PhpArray;123 $_PhpArray = $this->_PhpArray;124 if(!isset($_PhpArray))125 throw new exception('Null PHP input array');126 $Res_ = pack("S*", 0x809, 8, 0,0x10, 0, 0);127 foreach($_PhpArray as $RowNo_=>$RowS_)128 foreach($RowS_ as $ColNo_=>$Cell_)129 $Res_ .= $this->BuildCell($RowNo_, $ColNo_, $Cell_);130 $Res_ .= pack('S*', 0x0A, 0);131 $this->XlsData = $Res_;132 return($Res_);133 } // ABG_PhpToXls::BuildXls134135 /*** void SaveFile() *********************************************************136 Utility to write xls file to disk137 *****************************************************************************/138 public function SaveFile() {139 if(empty($this->XlsData))140 throw new exception('Xls data not available');141 $Path_ = $this->_XlsDir.DIRECTORY_SEPARATOR.$this->_FileName;142 $Hnd_ = @fopen($Path_, "wb");143 if($Hnd_===false)144 throw new exception("Unable to open Xls file <u><b>$Path_</b></u>");145 fwrite($Hnd_, $this->XlsData);146 fclose($Hnd_);147$Msg_ = '';148 if($this->PrtMsg)149 print($Msg_) ;150 } // ABG_PhpToXls::SaveFile151152 /*** void SendFile()**********************************************************153 Utility to send (HTTP) xls data to caller154 *****************************************************************************/155 public function SendFile(){156 if(empty($this->XlsData))157 throw new exception('Xls data not available');158 header("Cache-Control: no-cache, must-revalidate");159 header("Content-Description: ABG_PhpToXls Generated XLS Data");160 header("Content-Disposition: attachment; filename=\"$this->_FileName\"");161 header('Content-Transfer-Encoding: binary');162 header('Content-Type: application/force-download');163 header('Content-Type: application/octet-stream');164 header("Content-type: application/x-msexcel");165 header("Expires: Mon, 1 Apr 1974 05:00:00 GMT");166 header("Last-Modified: ".gmdate("D,d M YH:i:s")." GMT");167 header("Pragma: no-cache");168 print($this->XlsData);169 } // ABG_PhpToXls::SendFile170171 /*** void ExceptPrint(Except) ************************************************172 Utility to print error message from exceptions173 *****************************************************************************/174 static public function ExceptPrint($_Except){175 $Msg_ = "<b>Fatal ".get_class($_Except)." : </b>";176 $Msg_ .= $_Except->GetMessage()." in <b>".$_Except->GetFile();177 $Msg_ .= "</b> on line <b>".$_Except->GetLine()."</b><br />\n";178 print($Msg_);179 } // ABG_PhpToXls::ExceptPrint180181 ### P R I V A T E M E T H O D S ###########################################182 /*** str BuildCell(RowNo, ColNo, Cell) ***************************************183 Utility to build cell data according to type(int, float, string, boolean)184 - RowNo : Row number in spread sheet185 - ColNo : Column186 - Cell : Data to convert to xls format187 - RETURN : Piece of formatted data for the cell188 *****************************************************************************/189 private function BuildCell($_RowNo, $_ColNo, $_Cell) {190 if(is_string($_Cell)) {191 $Len_ = strlen($_Cell);192 return(pack("S*", 0x0204, $Len_ + 8, $_RowNo, $_ColNo, 0x00, $Len_).$_Cell);193 }194 if(is_int($_Cell))195 return(pack("S*", 0x027E, 10, $_RowNo, $_ColNo, 0x00).pack("I", ($_Cell<<2) | 2));196 if(is_float($_Cell))197 return(pack("S*", 0x0203, 14, $_RowNo, $_ColNo, 0x00).pack("d", $_Cell));198 if(is_bool($_Cell))199 return($this->BuildCell($_RowNo, $_ColNo, (int)($_Cell ? 1 : 0)));200 // Returns a null cell201 return(pack("S*", 0x0201, 6, $_RowNo, $_ColNo, 0x17));202 } // ABG_PhpToXls::BuildCell203204} ### End class ABG_PhpToXls #################################################
...
child.php
Source:child.php
...9 {10 parent::__construct($parent->getGenerator(), $parent->getAnalyzer(), $parent->getLocale());11 $this->setWithParent($parent);12 }13 public function __get($property)14 {15 return $this->parentIsSet()->parent->__get($property);16 }17 public function __call($method, $arguments)18 {19 return $this->parentIsSet()->parent->__call($method, $arguments);20 }21 public function __invoke(\closure $assertions)22 {23 $assertions($this->parent->phpArray($this->value));24 return $this;25 }26 public function setWithParent(asserters\phpArray $parent)27 {28 $this->parent = $parent;29 return $this;...
__get
Using AI Code Generation
1$phpArray = new phpArray();2$phpArray->set('a', '1');3$phpArray->set('b', '2');4$phpArray->set('c', '3');5$phpArray->set('d', '4');6$phpArray->set('e', '5');7$phpArray->set('f', '6');8$phpArray->set('g', '7');9$phpArray->set('h', '8');10$phpArray->set('i', '9');11$phpArray->set('j', '10');12$phpArray->set('k', '11');13$phpArray->set('l', '12');14$phpArray->set('m', '13');15$phpArray->set('n', '14');16$phpArray->set('o', '15');17$phpArray->set('p', '16');18$phpArray->set('q', '17');19$phpArray->set('r', '18');20$phpArray->set('s', '19');21$phpArray->set('t', '20');22$phpArray->set('u', '21');23$phpArray->set('v', '22');24$phpArray->set('w', '23');25$phpArray->set('x', '24');26$phpArray->set('y', '25');27$phpArray->set('z', '26');28$phpArray->set('aa', '27');29$phpArray->set('ab', '28');30$phpArray->set('ac', '29');31$phpArray->set('ad', '30');32$phpArray->set('ae', '31');33$phpArray->set('af', '32');34$phpArray->set('ag', '33');35$phpArray->set('ah', '34');36$phpArray->set('ai', '35');37$phpArray->set('aj', '36');38$phpArray->set('ak', '37');39$phpArray->set('al', '38');40$phpArray->set('am', '39');41$phpArray->set('an', '40');42$phpArray->set('ao', '41');43$phpArray->set('ap', '42');44$phpArray->set('aq', '43');45$phpArray->set('ar', '44');46$phpArray->set('
__get
Using AI Code Generation
1$myArray = new phpArray(array("a" => "apple", "b" => "banana"));2$myArray = new phpArray(array("a" => "apple", "b" => "banana"));3$myArray->c = "cat";4$myArray = new phpArray(array("a" => "apple", "b" => "banana"));5$myArray = new phpArray(array("a" => "apple", "b" => "banana"));6unset($myArray->a);7$myArray = new phpArray(array("a" => "apple", "b" => "banana"));8$myArray = new phpArray(array("a" => "apple", "b" => "banana"));9$myArray = new phpArray(array("a" => "apple", "b" => "banana"));10echo $myArray("c");
__get
Using AI Code Generation
1include("phpArray.php");2$a=new phpArray("array.txt");3echo $a->one;4include("phpArray.php");5$a=new phpArray("array.txt");6$a->one="new value";7include("phpArray.php");8$a=new phpArray("array.txt");9echo isset($a->one);10include("phpArray.php");11$a=new phpArray("array.txt");12unset($a->one);13include("phpArray.php");14$a=new phpArray("array.txt");15echo $a;16include("phpArray.php");17$a=new phpArray("array.txt");18var_dump($a);19include("phpArray.php");20$a=new phpArray("array.txt");21echo $a->one();22include("phpArray.php");23echo phpArray::one();24include("phpArray.php");25$a=new phpArray("array.txt");26echo $a["one"];27include("phpArray.php");28$a=new phpArray("array.txt");29$a["one"]="new value";30include("phpArray.php");31$a=new phpArray("array.txt");32echo isset($a["one"]);33include("phpArray.php");34$a=new phpArray("array.txt");35unset($a["one"]);
__get
Using AI Code Generation
1include 'phpArray.php';2$array = new phpArray();3$array->setArray(array(1,2,3,4,5));4echo $array[0]."\n";5echo $array[1]."\n";6echo $array[2]."\n";7echo $array[3]."\n";8echo $array[4]."\n";9include 'phpArray.php';10$array = new phpArray();11$array->setArray(array(1,2,3,4,5));12$array[0] = 10;13$array[1] = 20;14$array[2] = 30;15$array[3] = 40;16$array[4] = 50;17echo $array[0]."\n";18echo $array[1]."\n";19echo $array[2]."\n";20echo $array[3]."\n";21echo $array[4]."\n";22include 'phpArray.php';23$array = new phpArray();24$array->setArray(array(1,2,3,4,5));25echo isset($array[0])."\n";26echo isset($array[1])."\n";27echo isset($array[2])."\n";28echo isset($array[3])."\n";29echo isset($array[4])."\n";30include 'phpArray.php';31$array = new phpArray();32$array->setArray(array(1,2,3,4,5));33unset($array[0]);34unset($array[1]);35unset($array[2]);36unset($array[3]);37unset($array[4]);38echo isset($array[0])."\n";39echo isset($array[1])."\n";40echo isset($array[2])."\n";
__get
Using AI Code Generation
1require_once 'phpArray.php';2$array = new phpArray();3$array->set('name','saurabh');4$array->set('age','22');5$array->set('address','kolkata');6$array->set('phone','1234567890');7$array->set('email','
__get
Using AI Code Generation
1require_once('phpArray.php');2$array = new phpArray();3$array['name'] = 'phpArray';4$array['version'] = '1.0';5echo $array['name'];6echo $array['version'];7echo $array['author'];
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with __get on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!