idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
38,600
public function validatePassword ( string $ password , $ autoSave = true ) : bool { $ hasher = $ this -> getHasher ( ) ; $ isValid = $ hasher -> verify ( $ password , $ this -> password ) ; if ( $ isValid && $ hasher -> needsRehash ( $ this -> password ) ) { $ this -> password = $ password ; if ( $ autoSave ) { $ this -> save ( ) ; } } return $ isValid ; }
Returns true if the provided password is correct and false if not .
38,601
public function isLocked ( ) : bool { return $ this -> locked_until !== null && $ this -> locked_until -> getTimestamp ( ) >= Time :: now ( ) -> getTimestamp ( ) ; }
Returns TRUE if the account is locked and FALSE if not .
38,602
public function throttle ( int $ maxLoginAttempts , int $ lockTime , bool $ autoSave = true ) : bool { $ now = Time :: now ( ) ; if ( $ this -> last_fail_at !== null ) { if ( ( $ now -> getTimestamp ( ) - $ this -> last_fail_at -> getTimestamp ( ) ) > $ lockTime ) { $ this -> failed_attempts = 0 ; } } $ this -> failed_attempts ++ ; $ this -> last_fail_at = $ now ; if ( $ this -> failed_attempts >= $ maxLoginAttempts ) { $ this -> locked_until = ( clone $ now ) -> forward ( $ lockTime ) ; } return $ autoSave ? $ this -> save ( ) : true ; }
Throttles login attempts .
38,603
public function resetThrottle ( bool $ autoSave = true ) : bool { if ( $ this -> failed_attempts > 0 ) { $ this -> failed_attempts = 0 ; $ this -> last_fail_at = null ; $ this -> locked_until = null ; return $ autoSave ? $ this -> save ( ) : true ; } return true ; }
Resets the login throttling .
38,604
public function get_access_token ( ) { if ( isset ( $ this -> ll_access_token ) && ! is_null ( $ this -> ll_access_token ) ) { return $ this -> ll_access_token ; } $ app_client_values = array ( 'client_id' => $ this -> client_id , 'client_secret' => $ this -> client_secret , 'grant_type' => 'client_credentials' ) ; $ access_data = MPRestClient :: post ( array ( "uri" => "/oauth/token" , "data" => $ app_client_values , "headers" => array ( "content-type" => "application/x-www-form-urlencoded" ) ) ) ; if ( $ access_data [ "status" ] != 200 ) { throw new MercadoPagoException ( $ access_data [ 'response' ] [ 'message' ] , $ access_data [ 'status' ] ) ; } $ this -> access_data = $ access_data [ 'response' ] ; return $ this -> access_data [ 'access_token' ] ; }
Get Access Token for API use
38,605
public function get_payment ( $ id ) { $ uri_prefix = $ this -> sandbox ? "/sandbox" : "" ; $ request = array ( "uri" => "/v1/payments/{$id}" , "params" => array ( "access_token" => $ this -> get_access_token ( ) ) ) ; $ payment_info = MPRestClient :: get ( $ request ) ; return $ payment_info ; }
Get information for specific payment
38,606
public function get_authorized_payment ( $ id ) { $ request = array ( "uri" => "/authorized_payments/{$id}" , "params" => array ( "access_token" => $ this -> get_access_token ( ) ) ) ; $ authorized_payment_info = MPRestClient :: get ( $ request ) ; return $ authorized_payment_info ; }
Get information for specific authorized payment
38,607
public function refund_payment ( $ id ) { $ request = array ( "uri" => "/v1/payments/{$id}/refunds" , "params" => array ( "access_token" => $ this -> get_access_token ( ) ) ) ; $ response = MPRestClient :: post ( $ request ) ; return $ response ; }
Refund accredited payment
38,608
public function cancel_payment ( $ id ) { $ request = array ( "uri" => "/v1/payments/{$id}" , "params" => array ( "access_token" => $ this -> get_access_token ( ) ) , "data" => array ( "status" => "cancelled" ) ) ; $ response = MPRestClient :: put ( $ request ) ; return $ response ; }
Cancel pending payment
38,609
public function cancel_preapproval_payment ( $ id ) { $ request = array ( "uri" => "/preapproval/{$id}" , "params" => array ( "access_token" => $ this -> get_access_token ( ) ) , "data" => array ( "status" => "cancelled" ) ) ; $ response = MPRestClient :: put ( $ request ) ; return $ response ; }
Cancel preapproval payment
38,610
public function search_payment ( $ filters , $ offset = 0 , $ limit = 0 ) { $ filters [ "offset" ] = $ offset ; $ filters [ "limit" ] = $ limit ; $ uri_prefix = $ this -> sandbox ? "/sandbox" : "" ; $ request = array ( "uri" => "/v1/payments/search" , "params" => array_merge ( $ filters , array ( "access_token" => $ this -> get_access_token ( ) ) ) ) ; $ collection_result = MPRestClient :: get ( $ request ) ; return $ collection_result ; }
Search payments according to filters with pagination
38,611
public function create_preference ( $ preference ) { $ request = array ( "uri" => "/checkout/preferences" , "params" => array ( "access_token" => $ this -> get_access_token ( ) ) , "data" => $ preference ) ; $ preference_result = MPRestClient :: post ( $ request ) ; return $ preference_result ; }
Create a checkout preference
38,612
public function update_preference ( $ id , $ preference ) { $ request = array ( "uri" => "/checkout/preferences/{$id}" , "params" => array ( "access_token" => $ this -> get_access_token ( ) ) , "data" => $ preference ) ; $ preference_result = MPRestClient :: put ( $ request ) ; return $ preference_result ; }
Update a checkout preference
38,613
public function get_preference ( $ id ) { $ request = array ( "uri" => "/checkout/preferences/{$id}" , "params" => array ( "access_token" => $ this -> get_access_token ( ) ) ) ; $ preference_result = MPRestClient :: get ( $ request ) ; return $ preference_result ; }
Get a checkout preference
38,614
public function create_preapproval_payment ( $ preapproval_payment ) { $ request = array ( "uri" => "/preapproval" , "params" => array ( "access_token" => $ this -> get_access_token ( ) ) , "data" => $ preapproval_payment ) ; $ preapproval_payment_result = MPRestClient :: post ( $ request ) ; return $ preapproval_payment_result ; }
Create a preapproval payment
38,615
public function get_preapproval_payment ( $ id ) { $ request = array ( "uri" => "/preapproval/{$id}" , "params" => array ( "access_token" => $ this -> get_access_token ( ) ) ) ; $ preapproval_payment_result = MPRestClient :: get ( $ request ) ; return $ preapproval_payment_result ; }
Get a preapproval payment
38,616
public function update_preapproval_payment ( $ id , $ preapproval_payment ) { $ request = array ( "uri" => "/preapproval/{$id}" , "params" => array ( "access_token" => $ this -> get_access_token ( ) ) , "data" => $ preapproval_payment ) ; $ preapproval_payment_result = MPRestClient :: put ( $ request ) ; return $ preapproval_payment_result ; }
Update a preapproval payment
38,617
public function get ( $ request , $ params = null , $ authenticate = true ) { if ( is_string ( $ request ) ) { $ request = array ( "uri" => $ request , "params" => $ params , "authenticate" => $ authenticate ) ; } $ request [ "params" ] = isset ( $ request [ "params" ] ) && is_array ( $ request [ "params" ] ) ? $ request [ "params" ] : array ( ) ; if ( ! isset ( $ request [ "authenticate" ] ) || $ request [ "authenticate" ] !== false ) { $ request [ "params" ] [ "access_token" ] = $ this -> get_access_token ( ) ; } $ result = MPRestClient :: get ( $ request ) ; return $ result ; }
Generic resource get
38,618
public function post ( $ request , $ data = null , $ params = null ) { if ( is_string ( $ request ) ) { $ request = array ( "uri" => $ request , "data" => $ data , "params" => $ params ) ; } $ request [ "params" ] = isset ( $ request [ "params" ] ) && is_array ( $ request [ "params" ] ) ? $ request [ "params" ] : array ( ) ; if ( ! isset ( $ request [ "authenticate" ] ) || $ request [ "authenticate" ] !== false ) { $ request [ "params" ] [ "access_token" ] = $ this -> get_access_token ( ) ; } $ result = MPRestClient :: post ( $ request ) ; return $ result ; }
Generic resource post
38,619
public function delete ( $ request , $ params = null ) { if ( is_string ( $ request ) ) { $ request = array ( "uri" => $ request , "params" => $ params ) ; } $ request [ "params" ] = isset ( $ request [ "params" ] ) && is_array ( $ request [ "params" ] ) ? $ request [ "params" ] : array ( ) ; if ( ! isset ( $ request [ "authenticate" ] ) || $ request [ "authenticate" ] !== false ) { $ request [ "params" ] [ "access_token" ] = $ this -> get_access_token ( ) ; } $ result = MPRestClient :: delete ( $ request ) ; return $ result ; }
Generic resource delete
38,620
public function add ( $ key , CFType $ value = null ) { if ( ! $ value ) { $ value = new CFString ( ) ; } $ this -> value [ $ key ] = $ value ; }
Add CFType to collection .
38,621
public function toArray ( ) { $ a = array ( ) ; foreach ( $ this -> value as $ key => $ value ) { $ a [ $ key ] = $ value -> toArray ( ) ; } return $ a ; }
Get CFType s value .
38,622
public function loadXMLStream ( $ stream ) { if ( ( $ contents = stream_get_contents ( $ stream ) ) === false ) { throw IOException :: notReadable ( '<stream>' ) ; } $ this -> parse ( $ contents , CFPropertyList :: FORMAT_XML ) ; }
Load an XML PropertyList .
38,623
public function loadBinaryStream ( $ stream ) { if ( ( $ contents = stream_get_contents ( $ stream ) ) === false ) { throw IOException :: notReadable ( '<stream>' ) ; } $ this -> parse ( $ contents , CFPropertyList :: FORMAT_BINARY ) ; }
Load an binary PropertyList .
38,624
public function load ( $ file = null , $ format = null ) { $ file = $ file ? $ file : $ this -> file ; $ format = $ format !== null ? $ format : $ this -> format ; $ this -> value = array ( ) ; if ( ! is_readable ( $ file ) ) { throw IOException :: notReadable ( $ file ) ; } switch ( $ format ) { case CFPropertyList :: FORMAT_BINARY : $ this -> readBinary ( $ file ) ; break ; case CFPropertyList :: FORMAT_AUTO : $ fd = fopen ( $ file , "rb" ) ; if ( ( $ magic_number = fread ( $ fd , 8 ) ) === false ) { throw IOException :: notReadable ( $ file ) ; } fclose ( $ fd ) ; $ filetype = substr ( $ magic_number , 0 , 6 ) ; $ version = substr ( $ magic_number , - 2 ) ; if ( $ filetype == "bplist" ) { if ( $ version != "00" ) { throw new PListException ( "Wrong file format version! Expected 00, got $version!" ) ; } $ this -> detectedFormat = CFPropertyList :: FORMAT_BINARY ; $ this -> readBinary ( $ file ) ; break ; } $ this -> detectedFormat = CFPropertyList :: FORMAT_XML ; case CFPropertyList :: FORMAT_XML : $ doc = new DOMDocument ( ) ; $ prevXmlErrors = libxml_use_internal_errors ( true ) ; libxml_clear_errors ( ) ; if ( ! $ doc -> load ( $ file ) ) { $ message = $ this -> getLibxmlErrors ( ) ; libxml_clear_errors ( ) ; libxml_use_internal_errors ( $ prevXmlErrors ) ; throw new DOMException ( $ message ) ; } libxml_use_internal_errors ( $ prevXmlErrors ) ; $ this -> import ( $ doc -> documentElement , $ this ) ; break ; } }
Load a plist file . Load and import a plist file .
38,625
public function parse ( $ str = null , $ format = null ) { $ format = $ format !== null ? $ format : $ this -> format ; $ str = $ str !== null ? $ str : $ this -> content ; if ( $ str === null || strlen ( $ str ) === 0 ) { throw IOException :: readError ( '' ) ; } $ this -> value = array ( ) ; switch ( $ format ) { case CFPropertyList :: FORMAT_BINARY : $ this -> parseBinary ( $ str ) ; break ; case CFPropertyList :: FORMAT_AUTO : if ( ( $ magic_number = substr ( $ str , 0 , 8 ) ) === false ) { throw IOException :: notReadable ( "<string>" ) ; } $ filetype = substr ( $ magic_number , 0 , 6 ) ; $ version = substr ( $ magic_number , - 2 ) ; if ( $ filetype == "bplist" ) { if ( $ version != "00" ) { throw new PListException ( "Wrong file format version! Expected 00, got $version!" ) ; } $ this -> detectedFormat = CFPropertyList :: FORMAT_BINARY ; $ this -> parseBinary ( $ str ) ; break ; } $ this -> detectedFormat = CFPropertyList :: FORMAT_XML ; case CFPropertyList :: FORMAT_XML : $ doc = new DOMDocument ( ) ; $ prevXmlErrors = libxml_use_internal_errors ( true ) ; libxml_clear_errors ( ) ; if ( ! $ doc -> loadXML ( $ str ) ) { $ message = $ this -> getLibxmlErrors ( ) ; libxml_clear_errors ( ) ; libxml_use_internal_errors ( $ prevXmlErrors ) ; throw new DOMException ( $ message ) ; } libxml_use_internal_errors ( $ prevXmlErrors ) ; $ this -> import ( $ doc -> documentElement , $ this ) ; break ; } }
Parse a plist string . Parse and import a plist string .
38,626
protected function import ( DOMNode $ node , $ parent ) { if ( ! $ node -> childNodes -> length ) { return ; } foreach ( $ node -> childNodes as $ n ) { if ( ! isset ( self :: $ types [ $ n -> nodeName ] ) ) { continue ; } $ class = __NAMESPACE__ . '\\' . self :: $ types [ $ n -> nodeName ] ; $ key = null ; $ ps = $ n -> previousSibling ; while ( $ ps && $ ps -> nodeName == '#text' && $ ps -> previousSibling ) { $ ps = $ ps -> previousSibling ; } if ( $ ps && $ ps -> nodeName == 'key' ) { $ key = $ ps -> firstChild -> nodeValue ; } switch ( $ n -> nodeName ) { case 'date' : $ value = new $ class ( CFDate :: dateValue ( $ n -> nodeValue ) ) ; break ; case 'data' : $ value = new $ class ( $ n -> nodeValue , true ) ; break ; case 'string' : $ value = new $ class ( $ n -> nodeValue ) ; break ; case 'real' : case 'integer' : $ value = new $ class ( $ n -> nodeName == 'real' ? floatval ( $ n -> nodeValue ) : intval ( $ n -> nodeValue ) ) ; break ; case 'true' : case 'false' : $ value = new $ class ( $ n -> nodeName == 'true' ) ; break ; case 'array' : case 'dict' : $ value = new $ class ( ) ; $ this -> import ( $ n , $ value ) ; if ( $ value instanceof CFDictionary ) { $ hsh = $ value -> getValue ( ) ; if ( isset ( $ hsh [ 'CF$UID' ] ) && count ( $ hsh ) == 1 ) { $ value = new CFUid ( $ hsh [ 'CF$UID' ] -> getValue ( ) ) ; } } break ; } if ( $ parent instanceof CFDictionary ) { $ parent -> add ( $ key , $ value ) ; } else { $ parent -> add ( $ value ) ; } } }
Convert a DOMNode into a CFType .
38,627
public function saveXML ( $ file , $ formatted = false ) { $ this -> save ( $ file , CFPropertyList :: FORMAT_XML , $ formatted ) ; }
Convert CFPropertyList to XML and save to file .
38,628
public function save ( $ file = null , $ format = null , $ formatted_xml = false ) { $ file = $ file ? $ file : $ this -> file ; $ format = $ format ? $ format : $ this -> format ; if ( $ format == self :: FORMAT_AUTO ) { $ format = $ this -> detectedFormat ; } if ( ! in_array ( $ format , array ( self :: FORMAT_BINARY , self :: FORMAT_XML ) ) ) { throw new PListException ( "format {$format} is not supported, use CFPropertyList::FORMAT_BINARY or CFPropertyList::FORMAT_XML" ) ; } if ( ! file_exists ( $ file ) ) { if ( ! is_writable ( dirname ( $ file ) ) ) { throw IOException :: notWritable ( $ file ) ; } } elseif ( ! is_writable ( $ file ) ) { throw IOException :: notWritable ( $ file ) ; } $ content = $ format == self :: FORMAT_BINARY ? $ this -> toBinary ( ) : $ this -> toXML ( $ formatted_xml ) ; $ fh = fopen ( $ file , 'wb' ) ; fwrite ( $ fh , $ content ) ; fclose ( $ fh ) ; }
Convert CFPropertyList to XML or binary and save to file .
38,629
public function toXML ( $ formatted = false ) { $ domimpl = new DOMImplementation ( ) ; $ dtd = $ domimpl -> createDocumentType ( 'plist' , '-//Apple//DTD PLIST 1.0//EN' , 'http://www.apple.com/DTDs/PropertyList-1.0.dtd' ) ; $ doc = $ domimpl -> createDocument ( null , "plist" , $ dtd ) ; $ doc -> encoding = "UTF-8" ; if ( $ formatted ) { $ doc -> formatOutput = true ; $ doc -> preserveWhiteSpace = true ; } $ plist = $ doc -> documentElement ; $ plist -> setAttribute ( 'version' , '1.0' ) ; $ plist -> appendChild ( $ this -> getValue ( true ) -> toXML ( $ doc ) ) ; return $ doc -> saveXML ( ) ; }
Convert CFPropertyList to XML
38,630
public function del ( $ key ) { if ( isset ( $ this -> value [ $ key ] ) ) { $ t = $ this -> value [ $ key ] ; unset ( $ this -> value [ $ key ] ) ; return $ t ; } return null ; }
Remove CFType from collection .
38,631
protected function isAssociativeArray ( $ value ) { $ numericKeys = true ; $ i = 0 ; foreach ( $ value as $ key => $ v ) { if ( $ i !== $ key ) { $ numericKeys = false ; break ; } $ i ++ ; } return ! $ numericKeys ; }
Determine if an array is associative or numerical . Numerical Arrays have incrementing index - numbers that don t contain gaps .
38,632
protected static function make64Int ( $ hi , $ lo ) { if ( PHP_INT_SIZE > 4 ) { return ( ( ( int ) $ hi ) << 32 ) | ( ( int ) $ lo ) ; } $ lo = sprintf ( "%u" , $ lo ) ; if ( function_exists ( "gmp_mul" ) ) { return gmp_strval ( gmp_add ( gmp_mul ( $ hi , "4294967296" ) , $ lo ) ) ; } if ( function_exists ( "bcmul" ) ) { return bcadd ( bcmul ( $ hi , "4294967296" ) , $ lo ) ; } if ( class_exists ( 'Math_BigInteger' ) ) { $ bi = new \ Math_BigInteger ( $ hi ) ; return $ bi -> multiply ( new \ Math_BigInteger ( "4294967296" ) ) -> add ( new \ Math_BigInteger ( $ lo ) ) -> toString ( ) ; } throw new PListException ( "either gmp or bc has to be installed, or the Math_BigInteger has to be available!" ) ; }
Create an 64 bit integer using bcmath or gmp
38,633
protected function readBinaryInt ( $ length ) { if ( $ length > 3 ) { throw new PListException ( "Integer greater than 8 bytes: $length" ) ; } $ nbytes = 1 << $ length ; $ val = null ; if ( strlen ( $ buff = substr ( $ this -> content , $ this -> pos , $ nbytes ) ) != $ nbytes ) { throw IOException :: readError ( "" ) ; } $ this -> pos += $ nbytes ; switch ( $ length ) { case 0 : $ val = unpack ( "C" , $ buff ) ; $ val = $ val [ 1 ] ; break ; case 1 : $ val = unpack ( "n" , $ buff ) ; $ val = $ val [ 1 ] ; break ; case 2 : $ val = unpack ( "N" , $ buff ) ; $ val = $ val [ 1 ] ; break ; case 3 : $ words = unpack ( "Nhighword/Nlowword" , $ buff ) ; $ val = self :: make64Int ( $ words [ 'highword' ] , $ words [ 'lowword' ] ) ; break ; } return new CFNumber ( $ val ) ; }
Read an integer value
38,634
protected function readBinaryReal ( $ length ) { if ( $ length > 3 ) { throw new PListException ( "Real greater than 8 bytes: $length" ) ; } $ nbytes = 1 << $ length ; $ val = null ; if ( strlen ( $ buff = substr ( $ this -> content , $ this -> pos , $ nbytes ) ) != $ nbytes ) { throw IOException :: readError ( "" ) ; } $ this -> pos += $ nbytes ; switch ( $ length ) { case 0 : case 1 : $ x = $ length + 1 ; throw new PListException ( "got {$x} byte float, must be an error!" ) ; case 2 : $ val = unpack ( "f" , strrev ( $ buff ) ) ; $ val = $ val [ 1 ] ; break ; case 3 : $ val = unpack ( "d" , strrev ( $ buff ) ) ; $ val = $ val [ 1 ] ; break ; } return new CFNumber ( $ val ) ; }
Read a real value
38,635
protected function readBinaryDate ( $ length ) { if ( $ length > 3 ) { throw new PListException ( "Date greater than 8 bytes: $length" ) ; } $ nbytes = 1 << $ length ; $ val = null ; if ( strlen ( $ buff = substr ( $ this -> content , $ this -> pos , $ nbytes ) ) != $ nbytes ) { throw IOException :: readError ( "" ) ; } $ this -> pos += $ nbytes ; switch ( $ length ) { case 0 : case 1 : $ x = $ length + 1 ; throw new PListException ( "{$x} byte CFdate, error" ) ; case 2 : $ val = unpack ( "f" , strrev ( $ buff ) ) ; $ val = $ val [ 1 ] ; break ; case 3 : $ val = unpack ( "d" , strrev ( $ buff ) ) ; $ val = $ val [ 1 ] ; break ; } return new CFDate ( $ val , CFDate :: TIMESTAMP_APPLE ) ; }
Read a date value
38,636
protected function readBinaryData ( $ length ) { if ( $ length == 0 ) { $ buff = "" ; } else { $ buff = substr ( $ this -> content , $ this -> pos , $ length ) ; if ( strlen ( $ buff ) != $ length ) { throw IOException :: readError ( "" ) ; } $ this -> pos += $ length ; } return new CFData ( $ buff , false ) ; }
Read a data value
38,637
protected function readBinaryString ( $ length ) { if ( $ length == 0 ) { $ buff = "" ; } else { if ( strlen ( $ buff = substr ( $ this -> content , $ this -> pos , $ length ) ) != $ length ) { throw IOException :: readError ( "" ) ; } $ this -> pos += $ length ; } if ( ! isset ( $ this -> uniqueTable [ $ buff ] ) ) { $ this -> uniqueTable [ $ buff ] = true ; } return new CFString ( $ buff ) ; }
Read a string value usually coded as utf8
38,638
public static function convertCharset ( $ string , $ fromCharset , $ toCharset = 'UTF-8' ) { if ( function_exists ( 'mb_convert_encoding' ) ) { return mb_convert_encoding ( $ string , $ toCharset , $ fromCharset ) ; } if ( function_exists ( 'iconv' ) ) { return iconv ( $ fromCharset , $ toCharset , $ string ) ; } if ( function_exists ( 'recode_string' ) ) { return recode_string ( $ fromCharset . '..' . $ toCharset , $ string ) ; } throw new PListException ( 'neither iconv nor mbstring supported. how are we supposed to work on strings here?' ) ; }
Convert the given string from one charset to another . Trying to use MBString Iconv Recode - in that particular order .
38,639
public static function charsetStrlen ( $ string , $ charset = "UTF-8" ) { if ( function_exists ( 'mb_strlen' ) ) { return mb_strlen ( $ string , $ charset ) ; } if ( function_exists ( 'iconv_strlen' ) ) { return iconv_strlen ( $ string , $ charset ) ; } throw new PListException ( 'neither iconv nor mbstring supported. how are we supposed to work on strings here?' ) ; }
Count characters considering character set Trying to use MBString Iconv - in that particular order .
38,640
protected function readBinaryUnicodeString ( $ length ) { if ( strlen ( $ buff = substr ( $ this -> content , $ this -> pos , 2 * $ length ) ) != 2 * $ length ) { throw IOException :: readError ( "" ) ; } $ this -> pos += 2 * $ length ; if ( ! isset ( $ this -> uniqueTable [ $ buff ] ) ) { $ this -> uniqueTable [ $ buff ] = true ; } return new CFString ( self :: convertCharset ( $ buff , "UTF-16BE" , "UTF-8" ) ) ; }
Read a unicode string value coded as UTF - 16BE
38,641
protected function readBinaryArray ( $ length ) { $ ary = new CFArray ( ) ; if ( $ length != 0 ) { if ( strlen ( $ buff = substr ( $ this -> content , $ this -> pos , $ length * $ this -> objectRefSize ) ) != $ length * $ this -> objectRefSize ) { throw IOException :: readError ( "" ) ; } $ this -> pos += $ length * $ this -> objectRefSize ; $ objects = self :: unpackWithSize ( $ this -> objectRefSize , $ buff ) ; for ( $ i = 0 ; $ i < $ length ; ++ $ i ) { $ object = $ this -> readBinaryObjectAt ( $ objects [ $ i + 1 ] + 1 ) ; $ ary -> add ( $ object ) ; } } return $ ary ; }
Read an array value including contained objects
38,642
protected function readBinaryDict ( $ length ) { $ dict = new CFDictionary ( ) ; if ( $ length != 0 ) { if ( strlen ( $ buff = substr ( $ this -> content , $ this -> pos , $ length * $ this -> objectRefSize ) ) != $ length * $ this -> objectRefSize ) { throw IOException :: readError ( "" ) ; } $ this -> pos += $ length * $ this -> objectRefSize ; $ keys = self :: unpackWithSize ( $ this -> objectRefSize , $ buff ) ; if ( strlen ( $ buff = substr ( $ this -> content , $ this -> pos , $ length * $ this -> objectRefSize ) ) != $ length * $ this -> objectRefSize ) { throw IOException :: readError ( "" ) ; } $ this -> pos += $ length * $ this -> objectRefSize ; $ objects = self :: unpackWithSize ( $ this -> objectRefSize , $ buff ) ; for ( $ i = 0 ; $ i < $ length ; ++ $ i ) { $ key = $ this -> readBinaryObjectAt ( $ keys [ $ i + 1 ] + 1 ) ; $ object = $ this -> readBinaryObjectAt ( $ objects [ $ i + 1 ] + 1 ) ; $ dict -> add ( $ key -> getValue ( ) , $ object ) ; } } return $ dict ; }
Read a dictionary value including contained objects
38,643
public function readBinaryObject ( ) { if ( strlen ( $ buff = substr ( $ this -> content , $ this -> pos , 1 ) ) != 1 ) { throw IOException :: readError ( "" ) ; } $ this -> pos ++ ; $ object_length = unpack ( "C*" , $ buff ) ; $ object_length = $ object_length [ 1 ] & 0xF ; $ buff = unpack ( "H*" , $ buff ) ; $ buff = $ buff [ 1 ] ; $ object_type = substr ( $ buff , 0 , 1 ) ; if ( $ object_type != "0" && $ object_length == 15 ) { $ object_length = $ this -> readBinaryObject ( ) ; $ object_length = $ object_length -> getValue ( ) ; } $ retval = null ; switch ( $ object_type ) { case '0' : $ retval = $ this -> readBinaryNullType ( $ object_length ) ; break ; case '1' : $ retval = $ this -> readBinaryInt ( $ object_length ) ; break ; case '2' : $ retval = $ this -> readBinaryReal ( $ object_length ) ; break ; case '3' : $ retval = $ this -> readBinaryDate ( $ object_length ) ; break ; case '4' : $ retval = $ this -> readBinaryData ( $ object_length ) ; break ; case '5' : $ retval = $ this -> readBinaryString ( $ object_length ) ; break ; case '6' : $ retval = $ this -> readBinaryUnicodeString ( $ object_length ) ; break ; case '8' : $ num = $ this -> readBinaryInt ( $ object_length ) ; $ retval = new CFUid ( $ num -> getValue ( ) ) ; break ; case 'a' : $ retval = $ this -> readBinaryArray ( $ object_length ) ; break ; case 'd' : $ retval = $ this -> readBinaryDict ( $ object_length ) ; break ; } return $ retval ; }
Read an object type byte decode it and delegate to the correct reader function
38,644
public function parseBinaryString ( ) { $ this -> uniqueTable = array ( ) ; $ this -> countObjects = 0 ; $ this -> stringSize = 0 ; $ this -> intSize = 0 ; $ this -> miscSize = 0 ; $ this -> objectRefs = 0 ; $ this -> writtenObjectCount = 0 ; $ this -> objectTable = array ( ) ; $ this -> objectRefSize = 0 ; $ this -> offsets = array ( ) ; $ buff = substr ( $ this -> content , - 32 ) ; if ( strlen ( $ buff ) < 32 ) { throw new PListException ( 'Error in PList format: content is less than at least necessary 32 bytes!' ) ; } $ infos = unpack ( "x6/Coffset_size/Cobject_ref_size/x4/Nnumber_of_objects/x4/Ntop_object/x4/Ntable_offset" , $ buff ) ; $ coded_offset_table = substr ( $ this -> content , $ infos [ 'table_offset' ] , $ infos [ 'number_of_objects' ] * $ infos [ 'offset_size' ] ) ; if ( strlen ( $ coded_offset_table ) != $ infos [ 'number_of_objects' ] * $ infos [ 'offset_size' ] ) { throw IOException :: readError ( "" ) ; } $ this -> countObjects = $ infos [ 'number_of_objects' ] ; $ formats = array ( "" , "C*" , "n*" , null , "N*" ) ; if ( $ infos [ 'offset_size' ] == 3 ) { $ this -> offsets = array ( null ) ; while ( $ coded_offset_table ) { $ str = unpack ( "H6" , $ coded_offset_table ) ; $ this -> offsets [ ] = hexdec ( $ str [ 1 ] ) ; $ coded_offset_table = substr ( $ coded_offset_table , 3 ) ; } } else { $ this -> offsets = unpack ( $ formats [ $ infos [ 'offset_size' ] ] , $ coded_offset_table ) ; } $ this -> uniqueTable = array ( ) ; $ this -> objectRefSize = $ infos [ 'object_ref_size' ] ; $ top = $ this -> readBinaryObjectAt ( $ infos [ 'top_object' ] + 1 ) ; $ this -> add ( $ top ) ; }
Parse a binary plist string
38,645
public function readBinaryStream ( $ stream ) { if ( ( $ str = stream_get_contents ( $ stream ) ) === false || empty ( $ str ) ) { throw new PListException ( "Error reading stream!" ) ; } $ this -> parseBinary ( $ str ) ; }
Read a binary plist stream
38,646
public function parseBinary ( $ content = null ) { if ( $ content !== null ) { $ this -> content = $ content ; } if ( empty ( $ this -> content ) ) { throw new PListException ( "Content may not be empty!" ) ; } if ( substr ( $ this -> content , 0 , 8 ) != 'bplist00' ) { throw new PListException ( "Invalid binary string!" ) ; } $ this -> pos = 0 ; $ this -> parseBinaryString ( ) ; }
parse a binary plist string
38,647
public function readBinary ( $ file ) { if ( ! ( $ fd = fopen ( $ file , "rb" ) ) ) { throw new IOException ( "Could not open file {$file}!" ) ; } $ this -> readBinaryStream ( $ fd ) ; fclose ( $ fd ) ; }
Read a binary plist file
38,648
public static function bytesSizeInt ( $ int ) { $ nbytes = 0 ; if ( $ int > 0xE ) { $ nbytes += 2 ; } if ( $ int > 0xFF ) { $ nbytes += 1 ; } if ( $ int > 0xFFFF ) { $ nbytes += 2 ; } return $ nbytes ; }
calculate the bytes needed for a size integer value
38,649
public static function intBytes ( $ int ) { $ intbytes = "" ; if ( $ int > 0xFFFF ) { $ intbytes = "\x12" . pack ( "N" , $ int ) ; } elseif ( $ int > 0xFF ) { $ intbytes = "\x11" . pack ( "n" , $ int ) ; } else { $ intbytes = "\x10" . pack ( "C" , $ int ) ; } return $ intbytes ; }
Code an integer to byte representation
38,650
public static function typeBytes ( $ type , $ type_len ) { $ optional_int = "" ; if ( $ type_len < 15 ) { $ type .= sprintf ( "%x" , $ type_len ) ; } else { $ type .= "f" ; $ optional_int = self :: intBytes ( $ type_len ) ; } return pack ( "H*" , $ type ) . $ optional_int ; }
Code an type byte consisting of the type marker and the length of the type
38,651
protected function uniqueAndCountValues ( $ value ) { if ( $ value instanceof CFNumber ) { $ val = $ value -> getValue ( ) ; if ( intval ( $ val ) == $ val && ! is_float ( $ val ) && strpos ( $ val , '.' ) === false ) { $ this -> intSize += self :: bytesInt ( $ val ) ; } else { $ this -> miscSize += 9 ; } $ this -> countObjects ++ ; return ; } elseif ( $ value instanceof CFDate ) { $ this -> miscSize += 9 ; $ this -> countObjects ++ ; return ; } elseif ( $ value instanceof CFBoolean ) { $ this -> countObjects ++ ; $ this -> miscSize += 1 ; return ; } elseif ( $ value instanceof CFArray ) { $ cnt = 0 ; foreach ( $ value as $ v ) { ++ $ cnt ; $ this -> uniqueAndCountValues ( $ v ) ; $ this -> objectRefs ++ ; } $ this -> countObjects ++ ; $ this -> intSize += self :: bytesSizeInt ( $ cnt ) ; $ this -> miscSize ++ ; return ; } elseif ( $ value instanceof CFDictionary ) { $ cnt = 0 ; foreach ( $ value as $ k => $ v ) { ++ $ cnt ; if ( ! isset ( $ this -> uniqueTable [ $ k ] ) ) { $ this -> uniqueTable [ $ k ] = 0 ; $ len = self :: binaryStrlen ( $ k ) ; $ this -> stringSize += $ len + 1 ; $ this -> intSize += self :: bytesSizeInt ( self :: charsetStrlen ( $ k , 'UTF-8' ) ) ; } $ this -> objectRefs += 2 ; $ this -> uniqueTable [ $ k ] ++ ; $ this -> uniqueAndCountValues ( $ v ) ; } $ this -> countObjects ++ ; $ this -> miscSize ++ ; $ this -> intSize += self :: bytesSizeInt ( $ cnt ) ; return ; } elseif ( $ value instanceof CFData ) { $ val = $ value -> getValue ( ) ; $ len = strlen ( $ val ) ; $ this -> intSize += self :: bytesSizeInt ( $ len ) ; $ this -> miscSize += $ len + 1 ; $ this -> countObjects ++ ; return ; } else { $ val = $ value -> getValue ( ) ; } if ( ! isset ( $ this -> uniqueTable [ $ val ] ) ) { $ this -> uniqueTable [ $ val ] = 0 ; $ len = self :: binaryStrlen ( $ val ) ; $ this -> stringSize += $ len + 1 ; $ this -> intSize += self :: bytesSizeInt ( self :: charsetStrlen ( $ val , 'UTF-8' ) ) ; } $ this -> uniqueTable [ $ val ] ++ ; }
Count number of objects and create a unique table for strings
38,652
public function toBinary ( ) { $ this -> uniqueTable = array ( ) ; $ this -> countObjects = 0 ; $ this -> stringSize = 0 ; $ this -> intSize = 0 ; $ this -> miscSize = 0 ; $ this -> objectRefs = 0 ; $ this -> writtenObjectCount = 0 ; $ this -> objectTable = array ( ) ; $ this -> objectRefSize = 0 ; $ this -> offsets = array ( ) ; $ binary_str = "bplist00" ; $ value = $ this -> getValue ( true ) ; $ this -> uniqueAndCountValues ( $ value ) ; $ this -> countObjects += count ( $ this -> uniqueTable ) ; $ this -> objectRefSize = self :: bytesNeeded ( $ this -> countObjects ) ; $ file_size = $ this -> stringSize + $ this -> intSize + $ this -> miscSize + $ this -> objectRefs * $ this -> objectRefSize + 40 ; $ offset_size = self :: bytesNeeded ( $ file_size ) ; $ table_offset = $ file_size - 32 ; $ this -> objectTable = array ( ) ; $ this -> writtenObjectCount = 0 ; $ this -> uniqueTable = array ( ) ; $ value -> toBinary ( $ this ) ; $ object_offset = 8 ; $ offsets = array ( ) ; for ( $ i = 0 ; $ i < count ( $ this -> objectTable ) ; ++ $ i ) { $ binary_str .= $ this -> objectTable [ $ i ] ; $ offsets [ $ i ] = $ object_offset ; $ object_offset += strlen ( $ this -> objectTable [ $ i ] ) ; } for ( $ i = 0 ; $ i < count ( $ offsets ) ; ++ $ i ) { $ binary_str .= self :: packItWithSize ( $ offset_size , $ offsets [ $ i ] ) ; } $ binary_str .= pack ( "x6CC" , $ offset_size , $ this -> objectRefSize ) ; $ binary_str .= pack ( "x4N" , $ this -> countObjects ) ; $ binary_str .= pack ( "x4N" , 0 ) ; $ binary_str .= pack ( "x4N" , $ table_offset ) ; return $ binary_str ; }
Convert CFPropertyList to binary format ; since we have to count our objects we simply unique CFDictionary and CFArray
38,653
protected static function binaryStrlen ( $ val ) { for ( $ i = 0 ; $ i < strlen ( $ val ) ; ++ $ i ) { if ( ord ( $ val { $ i } ) >= 128 ) { $ val = self :: convertCharset ( $ val , 'UTF-8' , 'UTF-16BE' ) ; return strlen ( $ val ) ; } } return strlen ( $ val ) ; }
Counts the number of bytes the string will have when coded ; utf - 16be if non - ascii characters are present .
38,654
public function stringToBinary ( $ val ) { $ saved_object_count = - 1 ; if ( ! isset ( $ this -> uniqueTable [ $ val ] ) ) { $ saved_object_count = $ this -> writtenObjectCount ++ ; $ this -> uniqueTable [ $ val ] = $ saved_object_count ; $ utf16 = false ; for ( $ i = 0 ; $ i < strlen ( $ val ) ; ++ $ i ) { if ( ord ( $ val { $ i } ) >= 128 ) { $ utf16 = true ; break ; } } if ( $ utf16 ) { $ bdata = self :: typeBytes ( "6" , mb_strlen ( $ val , 'UTF-8' ) ) ; $ val = self :: convertCharset ( $ val , 'UTF-8' , 'UTF-16BE' ) ; $ this -> objectTable [ $ saved_object_count ] = $ bdata . $ val ; } else { $ bdata = self :: typeBytes ( "5" , strlen ( $ val ) ) ; $ this -> objectTable [ $ saved_object_count ] = $ bdata . $ val ; } } else { $ saved_object_count = $ this -> uniqueTable [ $ val ] ; } return $ saved_object_count ; }
Uniques and transforms a string value to binary format and adds it to the object table
38,655
protected function intToBinary ( $ value ) { $ nbytes = 0 ; if ( $ value > 0xFF ) { $ nbytes = 1 ; } if ( $ value > 0xFFFF ) { $ nbytes += 1 ; } if ( $ value > 0xFFFFFFFF ) { $ nbytes += 1 ; } if ( $ value < 0 ) { $ nbytes = 3 ; } $ bdata = self :: typeBytes ( "1" , $ nbytes ) ; $ buff = "" ; if ( $ nbytes < 3 ) { if ( $ nbytes == 0 ) { $ fmt = "C" ; } elseif ( $ nbytes == 1 ) { $ fmt = "n" ; } else { $ fmt = "N" ; } $ buff = pack ( $ fmt , $ value ) ; } else { if ( PHP_INT_SIZE > 4 ) { $ high_word = $ value >> 32 ; $ low_word = $ value & 0xFFFFFFFF ; } else { if ( $ value < 0 ) { $ high_word = 0xFFFFFFFF ; } else { $ high_word = 0 ; } $ low_word = $ value ; } $ buff = pack ( "N" , $ high_word ) . pack ( "N" , $ low_word ) ; } return $ bdata . $ buff ; }
Codes an integer to binary format
38,656
protected function realToBinary ( $ val ) { $ bdata = self :: typeBytes ( "2" , 3 ) ; return $ bdata . strrev ( pack ( "d" , ( float ) $ val ) ) ; }
Codes a real value to binary format
38,657
public function numToBinary ( $ value ) { $ saved_object_count = $ this -> writtenObjectCount ++ ; $ val = "" ; if ( intval ( $ value ) == $ value && ! is_float ( $ value ) && strpos ( $ value , '.' ) === false ) { $ val = $ this -> intToBinary ( $ value ) ; } else { $ val = $ this -> realToBinary ( $ value ) ; } $ this -> objectTable [ $ saved_object_count ] = $ val ; return $ saved_object_count ; }
Converts a numeric value to binary and adds it to the object table
38,658
public function boolToBinary ( $ val ) { $ saved_object_count = $ this -> writtenObjectCount ++ ; $ this -> objectTable [ $ saved_object_count ] = $ val ? "\x9" : "\x8" ; return $ saved_object_count ; }
Convert a bool value to binary and add it to the object table
38,659
public function dataToBinary ( $ val ) { $ saved_object_count = $ this -> writtenObjectCount ++ ; $ bdata = self :: typeBytes ( "4" , strlen ( $ val ) ) ; $ this -> objectTable [ $ saved_object_count ] = $ bdata . $ val ; return $ saved_object_count ; }
Convert data value to binary format and add it to the object table
38,660
public function arrayToBinary ( $ val ) { $ saved_object_count = $ this -> writtenObjectCount ++ ; $ bdata = self :: typeBytes ( "a" , count ( $ val -> getValue ( ) ) ) ; foreach ( $ val as $ v ) { $ bval = $ v -> toBinary ( $ this ) ; $ bdata .= self :: packItWithSize ( $ this -> objectRefSize , $ bval ) ; } $ this -> objectTable [ $ saved_object_count ] = $ bdata ; return $ saved_object_count ; }
Convert array to binary format and add it to the object table
38,661
public function dictToBinary ( $ val ) { $ saved_object_count = $ this -> writtenObjectCount ++ ; $ bdata = self :: typeBytes ( "d" , count ( $ val -> getValue ( ) ) ) ; foreach ( $ val as $ k => $ v ) { $ str = new CFString ( $ k ) ; $ key = $ str -> toBinary ( $ this ) ; $ bdata .= self :: packItWithSize ( $ this -> objectRefSize , $ key ) ; } foreach ( $ val as $ k => $ v ) { $ bval = $ v -> toBinary ( $ this ) ; $ bdata .= self :: packItWithSize ( $ this -> objectRefSize , $ bval ) ; } $ this -> objectTable [ $ saved_object_count ] = $ bdata ; return $ saved_object_count ; }
Convert dictionary to binary format and add it to the object table
38,662
public function setValue ( $ value , $ format = CFDate :: TIMESTAMP_UNIX ) { if ( $ format == CFDate :: TIMESTAMP_UNIX ) { $ this -> value = $ value ; } else { $ this -> value = $ value + CFDate :: DATE_DIFF_APPLE_UNIX ; } }
Set the Date CFType s value .
38,663
public function getValue ( $ format = CFDate :: TIMESTAMP_UNIX ) { if ( $ format == CFDate :: TIMESTAMP_UNIX ) { return $ this -> value ; } else { return $ this -> value - CFDate :: DATE_DIFF_APPLE_UNIX ; } }
Get the Date CFType s value .
38,664
public static function dateValue ( $ val ) { if ( ! preg_match ( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z/' , $ val , $ matches ) ) { throw new PListException ( "Unknown date format: $val" ) ; } return gmmktime ( $ matches [ 4 ] , $ matches [ 5 ] , $ matches [ 6 ] , $ matches [ 2 ] , $ matches [ 3 ] , $ matches [ 1 ] ) ; }
Create a UNIX timestamp from a PList date string
38,665
protected function _setupViewVars ( ) { foreach ( $ this -> _specialVars as $ viewVar ) { if ( ! isset ( $ this -> viewVars [ $ viewVar ] ) ) { $ this -> viewVars [ $ viewVar ] = null ; } } if ( $ this -> viewVars [ '_delimiter' ] === null ) { $ this -> viewVars [ '_delimiter' ] = ',' ; } if ( $ this -> viewVars [ '_enclosure' ] === null ) { $ this -> viewVars [ '_enclosure' ] = '"' ; } if ( $ this -> viewVars [ '_newline' ] === null ) { $ this -> viewVars [ '_newline' ] = "\n" ; } if ( $ this -> viewVars [ '_eol' ] === null ) { $ this -> viewVars [ '_eol' ] = PHP_EOL ; } if ( $ this -> viewVars [ '_null' ] === null ) { $ this -> viewVars [ '_null' ] = '' ; } if ( $ this -> viewVars [ '_bom' ] === null ) { $ this -> viewVars [ '_bom' ] = false ; } if ( $ this -> viewVars [ '_setSeparator' ] === null ) { $ this -> viewVars [ '_setSeparator' ] = false ; } if ( $ this -> viewVars [ '_dataEncoding' ] === null ) { $ this -> viewVars [ '_dataEncoding' ] = 'UTF-8' ; } if ( $ this -> viewVars [ '_csvEncoding' ] === null ) { $ this -> viewVars [ '_csvEncoding' ] = 'UTF-8' ; } if ( $ this -> viewVars [ '_extension' ] === null ) { $ this -> viewVars [ '_extension' ] = self :: EXTENSION_ICONV ; } if ( $ this -> viewVars [ '_extract' ] !== null ) { $ this -> viewVars [ '_extract' ] = ( array ) $ this -> viewVars [ '_extract' ] ; } }
Setup defaults for CsvView view variables
38,666
protected function _renderContent ( ) { $ extract = $ this -> viewVars [ '_extract' ] ; $ serialize = $ this -> viewVars [ '_serialize' ] ; if ( $ serialize === true ) { $ serialize = array_diff ( array_keys ( $ this -> viewVars ) , $ this -> _specialVars ) ; } foreach ( ( array ) $ serialize as $ viewVar ) { if ( is_scalar ( $ this -> viewVars [ $ viewVar ] ) ) { throw new Exception ( "'" . $ viewVar . "' is not an array or iteratable object." ) ; } foreach ( $ this -> viewVars [ $ viewVar ] as $ _data ) { if ( $ _data instanceof EntityInterface ) { $ _data = $ _data -> toArray ( ) ; } if ( $ extract === null ) { $ this -> _renderRow ( $ _data ) ; continue ; } $ values = [ ] ; foreach ( $ extract as $ formatter ) { if ( ! is_string ( $ formatter ) && is_callable ( $ formatter ) ) { $ value = $ formatter ( $ _data ) ; } else { $ path = $ formatter ; $ format = null ; if ( is_array ( $ formatter ) ) { list ( $ path , $ format ) = $ formatter ; } if ( strpos ( $ path , '.' ) === false ) { $ value = $ _data [ $ path ] ; } else { $ value = Hash :: get ( $ _data , $ path ) ; } if ( $ format ) { $ value = sprintf ( $ format , $ value ) ; } } $ values [ ] = $ value ; } $ this -> _renderRow ( $ values ) ; } } }
Renders the body of the data to the csv
38,667
protected function _renderRow ( $ row = null ) { static $ csv = '' ; if ( $ this -> _resetStaticVariables ) { $ csv = '' ; $ this -> _resetStaticVariables = false ; return null ; } $ csv .= ( string ) $ this -> _generateRow ( $ row ) ; return $ csv ; }
Aggregates the rows into a single csv
38,668
protected function _generateRow ( $ row = null ) { static $ fp = false ; if ( empty ( $ row ) ) { return '' ; } if ( $ fp === false ) { $ fp = fopen ( 'php://temp' , 'r+' ) ; if ( $ this -> viewVars [ '_setSeparator' ] ) { fwrite ( $ fp , "sep=" . $ this -> viewVars [ '_delimiter' ] . "\n" ) ; } } else { ftruncate ( $ fp , 0 ) ; } if ( $ this -> viewVars [ '_null' ] !== '' ) { foreach ( $ row as & $ field ) { if ( $ field === null ) { $ field = $ this -> viewVars [ '_null' ] ; } } } $ delimiter = $ this -> viewVars [ '_delimiter' ] ; $ enclosure = $ this -> viewVars [ '_enclosure' ] ; $ newline = $ this -> viewVars [ '_newline' ] ; $ row = str_replace ( [ "\r\n" , "\n" , "\r" ] , $ newline , $ row ) ; if ( $ enclosure === '' ) { if ( fputs ( $ fp , implode ( $ delimiter , $ row ) . "\n" ) === false ) { return false ; } } else { if ( fputcsv ( $ fp , $ row , $ delimiter , $ enclosure ) === false ) { return false ; } } rewind ( $ fp ) ; $ csv = '' ; while ( ( $ buffer = fgets ( $ fp , 4096 ) ) !== false ) { $ csv .= $ buffer ; } $ eol = $ this -> viewVars [ '_eol' ] ; if ( $ eol !== "\n" ) { $ csv = str_replace ( "\n" , $ eol , $ csv ) ; } $ dataEncoding = $ this -> viewVars [ '_dataEncoding' ] ; $ csvEncoding = $ this -> viewVars [ '_csvEncoding' ] ; if ( $ dataEncoding !== $ csvEncoding ) { $ extension = $ this -> viewVars [ '_extension' ] ; if ( $ extension === self :: EXTENSION_ICONV ) { $ csv = iconv ( $ dataEncoding , $ csvEncoding , $ csv ) ; } elseif ( $ extension === self :: EXTENSION_MBSTRING ) { $ csv = mb_convert_encoding ( $ csv , $ csvEncoding , $ dataEncoding ) ; } } if ( $ this -> viewVars [ '_bom' ] && $ this -> isFirstBom ) { $ csv = $ this -> getBom ( $ this -> viewVars [ '_csvEncoding' ] ) . $ csv ; $ this -> isFirstBom = false ; } return $ csv ; }
Generates a single row in a csv from an array of data by writing the array to a temporary file and returning it s contents
38,669
protected function getBom ( $ csvEncoding ) { $ csvEncoding = strtoupper ( $ csvEncoding ) ; return isset ( $ this -> bomMap [ $ csvEncoding ] ) ? $ this -> bomMap [ $ csvEncoding ] : '' ; }
Returns the BOM for the encoding given .
38,670
public function make ( $ key , callable $ callable ) { $ menu = new Menu ( $ callable ) ; $ menu -> key ( $ key ) ; $ this -> collection -> put ( $ key , $ menu ) ; return $ this ; }
Make a Front End Menu an Object .
38,671
public function add ( $ key , $ callable ) { $ menu = new AdminMenu ( $ callable ) ; $ this -> adminMenu -> put ( $ key , $ menu ) ; return $ this ; }
Add Menu to a Collection
38,672
public function getProductValueModel ( $ productId ) { $ dataType = ucfirst ( strtolower ( $ this -> data_type ) ) ; $ method = 'productProperty' . $ dataType . 'Value' ; $ productPropertyModel = $ this -> $ method ( ) -> whereProductId ( $ productId ) -> get ( ) ; if ( $ productPropertyModel -> count ( ) == 0 ) { $ valueClass = __NAMESPACE__ . '\\' . ucfirst ( $ method ) ; $ valueModel = new $ valueClass ( [ 'property_id' => $ this -> id , 'product_id' => $ productId ] ) ; } else { $ valueModel = $ this -> $ method ( ) -> whereProductId ( $ productId ) -> first ( ) ; } return $ valueModel ; }
Get Product Property Value Model based by ProductID .
38,673
public function getDropdownOptions ( ) { $ options = Collection :: make ( [ ] ) ; $ dropdowns = $ this -> propertyDropdownOptions ; if ( null !== $ dropdowns && $ dropdowns -> count ( ) > 0 ) { foreach ( $ dropdowns as $ dropdown ) { $ dropdown -> display_text = $ dropdown -> getDisplayText ( ) ; $ options -> push ( $ dropdown ) ; } } return $ options ; }
Get dropdown options with language transted
38,674
public function make ( $ name , callable $ callable ) { $ breadcrumb = new Breadcrumb ( $ callable ) ; $ breadcrumb -> route ( $ name ) ; $ this -> collection -> put ( $ name , $ breadcrumb ) ; }
Breadcrumb Make an Object .
38,675
public function render ( $ routeName ) { $ breadcrumb = $ this -> collection -> get ( $ routeName ) ; if ( null === $ breadcrumb ) { return '' ; } return view ( 'avored-framework::breadcrumb.index' ) -> with ( 'breadcrumb' , $ breadcrumb ) ; }
Render BreakCrumb for the Route Name .
38,676
public function make ( ) { $ ext = strtolower ( strrchr ( $ this -> path , '.' ) ) ; $ path = storage_path ( 'app/public/' ) . $ this -> path ; switch ( $ ext ) { case '.jpg' : case '.jpeg' : $ this -> image = @ imagecreatefromjpeg ( $ path ) ; break ; case '.gif' : $ this -> image = @ imagecreatefromgif ( $ path ) ; break ; case '.png' : $ this -> image = @ imagecreatefrompng ( $ path ) ; break ; default : $ this -> image = false ; break ; } if ( false === $ this -> image ) { throw new ImageNotFoundException ( 'Image extension not supported!' ) ; } $ this -> width = imagesx ( $ this -> image ) ; $ this -> height = imagesy ( $ this -> image ) ; return $ this ; }
Make the Image as GD Resource and return self
38,677
public function saveImage ( $ savePath , $ imageQuality = '100' ) { $ extension = strrchr ( $ savePath , '.' ) ; $ extension = strtolower ( $ extension ) ; switch ( $ extension ) { case '.jpg' : case '.jpeg' : if ( imagetypes ( ) & IMG_JPG ) { imagejpeg ( $ this -> imageResized , $ savePath , $ imageQuality ) ; } break ; case '.gif' : if ( imagetypes ( ) & IMG_GIF ) { imagegif ( $ this -> imageResized , $ savePath ) ; } break ; case '.png' : $ scaleQuality = round ( ( $ imageQuality / 100 ) * 9 ) ; $ invertScaleQuality = 9 - $ scaleQuality ; if ( imagetypes ( ) & IMG_PNG ) { imagepng ( $ this -> imageResized , $ savePath , $ invertScaleQuality ) ; } break ; default : break ; } imagedestroy ( $ this -> imageResized ) ; return $ this ; }
Save the Image
38,678
protected function getDimensions ( $ newWidth , $ newHeight ) { $ usedRatio = $ widthRatio = $ this -> width / $ newWidth ; $ heightRatio = $ this -> height / $ newHeight ; if ( $ heightRatio < $ widthRatio ) { $ usedRatio = $ heightRatio ; } $ height = $ this -> height / $ usedRatio ; $ width = $ this -> width / $ usedRatio ; return [ $ width , $ height ] ; }
Get the Width & height of the Image
38,679
protected function crop ( $ with , $ height , $ newWidth , $ newHeight ) { $ cropStartX = ( $ with / 2 ) - ( $ newWidth / 2 ) ; $ cropStartY = ( $ height / 2 ) - ( $ newHeight / 2 ) ; $ crop = $ this -> imageResized ; $ this -> imageResized = imagecreatetruecolor ( $ newWidth , $ newHeight ) ; imagecopyresampled ( $ this -> imageResized , $ crop , 0 , 0 , $ cropStartX , $ cropStartY , $ newWidth , $ newHeight , $ newWidth , $ newHeight ) ; return $ this ; }
Crop the Image
38,680
public function attributes ( $ attributes = null ) { if ( null === $ attributes ) { return $ this -> attributes ; } $ this -> attributes = $ attributes ; return $ this ; }
To Check if Cart Product Has Attributes .
38,681
public function add ( $ key ) { $ configuration = new AdminConfigurationGroup ( ) ; $ configuration -> key ( $ key ) ; $ this -> configurations -> put ( $ key , $ configuration ) ; return $ configuration ; }
Add Admin Configuration into Collection .
38,682
public function get ( $ key ) { if ( $ this -> configurations -> has ( $ key ) ) { return $ this -> configurations -> get ( $ key ) ; } return Collection :: make ( [ ] ) ; }
Get Admin Configuration Collection if exists or Return Empty Collection .
38,683
public function findTranslated ( $ category , $ languageId ) { return CategoryTranslation :: whereCategoryId ( $ category -> id ) -> whereLanguageId ( $ languageId ) -> first ( ) ; }
Find an Translated Category by given CategoryModel and Language Id
38,684
public function create ( $ data ) { if ( Session :: has ( 'multi_language_enabled' ) ) { $ languageId = $ data [ 'language_id' ] ; $ languaModel = Language :: find ( $ languageId ) ; if ( $ languaModel -> is_default ) { return Category :: create ( $ data ) ; } else { return CategoryTranslation :: create ( $ data ) ; } } else { return Category :: create ( $ data ) ; } }
Create a Category
38,685
public function update ( Category $ category , array $ data ) { if ( Session :: has ( 'multi_language_enabled' ) ) { $ languageId = $ data [ 'language_id' ] ; $ languaModel = Language :: find ( $ languageId ) ; if ( $ languaModel -> is_default ) { return $ category -> update ( $ data ) ; } else { $ category -> update ( Arr :: only ( $ data , [ 'parent_id' ] ) ) ; $ translatedModel = $ category -> translations ( ) -> whereLanguageId ( $ languageId ) -> first ( ) ; if ( null === $ translatedModel ) { return CategoryTranslation :: create ( array_merge ( $ data , [ 'category_id' => $ category -> id ] ) ) ; } else { $ translatedModel -> update ( $ data , $ category -> getTranslatedAttributes ( ) ) ; return $ translatedModel ; } } } else { return $ category -> update ( $ data ) ; } }
Update a Category
38,686
public function options ( $ empty = true ) { if ( true === $ empty ) { $ empty = new Category ( ) ; $ empty -> name = 'Please Select' ; return Category :: all ( ) -> prepend ( $ empty ) ; } return Category :: all ( ) ; }
Get an Category Options for Vue Components
38,687
public function add ( $ slug , $ qty , $ attribute = null ) : Manager { $ cartProducts = $ this -> getSession ( ) ; $ product = Product :: whereSlug ( $ slug ) -> first ( ) ; $ price = $ product -> price ; $ attributes = null ; if ( null !== $ attribute && count ( $ attribute ) ) { foreach ( $ attribute as $ attributeId => $ attributeValueId ) { if ( 'variation_id' == $ attributeId ) { continue ; } $ variableProduct = Product :: find ( $ attribute [ 'variation_id' ] ) ; $ attributeModel = Attribute :: find ( $ attributeId ) ; $ productAttributeIntValModel = ProductAttributeIntegerValue :: whereAttributeId ( $ attributeId ) -> whereProductId ( $ variableProduct -> id ) -> first ( ) ; $ optionModel = $ attributeModel -> AttributeDropdownOptions ( ) -> whereId ( $ productAttributeIntValModel -> value ) -> first ( ) ; $ price = $ variableProduct -> price ; $ attributes [ ] = [ 'attribute_id' => $ attributeId , 'variation_id' => $ variableProduct -> id , 'attribute_dropdown_option_id' => $ optionModel -> id , 'variation_display_text' => $ attributeModel -> name . ': ' . $ optionModel -> display_text ] ; } } $ cartProduct = new CartFacadeProduct ( ) ; $ cartProduct -> name ( $ product -> name ) -> qty ( $ qty ) -> slug ( $ slug ) -> price ( $ price ) -> image ( $ product -> image ) -> lineTotal ( $ qty * $ price ) -> attributes ( $ attributes ) ; $ cartProducts -> put ( $ slug , $ cartProduct ) ; $ this -> sessionManager -> put ( $ this -> getSessionKey ( ) , $ cartProducts ) ; return $ this ; }
Add Product into cart using Slug and Qty .
38,688
public function destroy ( $ slug ) : Manager { $ cartProducts = $ this -> getSession ( ) ; $ cartProducts -> pull ( $ slug ) ; return $ this ; }
Remove an Item from Cart Products by Slug .
38,689
public function getSession ( ) { $ sessionKey = $ this -> getSessionKey ( ) ; return $ this -> sessionManager -> has ( $ sessionKey ) ? $ this -> sessionManager -> get ( $ sessionKey ) : new Collection ; }
Get the Current Collection for the Prophetoducts .
38,690
public function total ( $ formatted = true ) { $ total = 0.00 ; $ cartProducts = $ this -> getSession ( ) ; foreach ( $ cartProducts as $ product ) { $ total += $ product -> lineTotal ( ) ; } if ( $ formatted == true ) { $ symbol = Session :: get ( 'currency_symbol' ) ; return $ symbol . number_format ( $ total , 2 ) ; } return $ total ; }
Get the Current Cart Total
38,691
public function taxTotal ( $ formatted = true ) { $ taxTotal = 0.00 ; $ cartProducts = $ this -> getSession ( ) ; foreach ( $ cartProducts as $ product ) { $ taxTotal += $ product -> tax ( ) ; } if ( $ formatted == true ) { $ symbol = Session :: get ( 'currency_symbol' ) ; return $ symbol . number_format ( $ taxTotal , 2 ) ; } return $ taxTotal ; }
Get the Current Cart Tax Total
38,692
public function update ( Page $ page , array $ data ) { if ( Session :: has ( 'multi_language_enabled' ) ) { $ languageId = $ data [ 'language_id' ] ; $ languaModel = Language :: find ( $ languageId ) ; if ( $ languaModel -> is_default ) { return $ page -> update ( $ data ) ; } else { $ translatedModel = $ page -> translations ( ) -> whereLanguageId ( $ languageId ) -> first ( ) ; if ( null === $ translatedModel ) { return PageTranslation :: create ( array_merge ( $ data , [ 'page_id' => $ page -> id ] ) ) ; } else { $ translatedModel -> update ( $ data , $ page -> getTranslatedAttributes ( ) ) ; return $ translatedModel ; } } } else { return $ page -> update ( $ data ) ; } }
Update a Page
38,693
public function parent ( $ key ) : self { $ breadcrumb = BreadcrumbFacade :: get ( $ key ) ; $ this -> parents -> put ( $ key , $ breadcrumb ) ; return $ this ; }
Set AvoRed BreakCrumb Parents .
38,694
public function editStatus ( Model $ order ) { $ orderStatus = OrderStatus :: all ( ) -> pluck ( 'name' , 'id' ) ; $ view = view ( 'avored-framework::order.view' ) -> with ( 'order' , $ order ) -> with ( 'orderStatus' , $ orderStatus ) -> with ( 'changeStatus' , true ) ; return $ view ; }
Edit the Order Status View
38,695
public function store ( AttributeRequest $ request ) { $ attribute = $ this -> attributeRepository -> create ( $ request -> all ( ) ) ; $ this -> saveDropdownOptions ( $ attribute , $ request ) ; return redirect ( ) -> route ( 'admin.attribute.index' ) ; }
Store an Atttibute into Database and Redirect to List Route
38,696
public function update ( Attribute $ attribute , array $ data ) { if ( Session :: has ( 'multi_language_enabled' ) ) { $ languageId = $ data [ 'language_id' ] ; $ languaModel = Language :: find ( $ languageId ) ; if ( $ languaModel -> is_default ) { return $ attribute -> update ( $ data ) ; } else { $ translatedModel = $ attribute -> translations ( ) -> whereLanguageId ( $ languageId ) -> first ( ) ; if ( null === $ translatedModel ) { return AttributeTranslation :: create ( array_merge ( $ data , [ 'attribute_id' => $ attribute -> id ] ) ) ; } else { $ translatedModel -> update ( $ data , $ attribute -> getTranslatedAttributes ( ) ) ; return $ translatedModel ; } } } else { return $ attribute -> update ( $ data ) ; } }
Update an attribute
38,697
public function syncDropdownOptions ( $ attribute , $ data ) { $ dropdownOptionsData = $ data [ 'dropdown_options' ] ?? [ ] ; if ( count ( $ dropdownOptionsData ) ) { $ defaultLanguage = Session :: get ( 'default_language' ) ; $ languageId = $ data [ 'language_id' ] ?? $ defaultLanguage -> id ; if ( $ defaultLanguage -> id != $ languageId ) { foreach ( $ dropdownOptionsData as $ key => $ val ) { if ( empty ( $ val [ 'display_text' ] ) ) { continue ; } if ( is_int ( $ key ) ) { $ optionModel = AttributeDropdownOption :: find ( $ key ) ; $ translatedModel = $ optionModel -> translations ( ) -> whereLanguageId ( $ languageId ) -> first ( ) ; if ( null !== $ translatedModel ) { $ translatedModel -> update ( $ val ) ; } else { $ optionModel -> translations ( ) -> create ( array_merge ( $ val , [ 'language_id' => $ languageId ] ) ) ; } } } } else { if ( $ attribute -> attributeDropdownOptions ( ) -> get ( ) != null && $ attribute -> attributeDropdownOptions ( ) -> get ( ) -> count ( ) >= 0 ) { $ attribute -> attributeDropdownOptions ( ) -> delete ( ) ; } foreach ( $ dropdownOptionsData as $ key => $ val ) { if ( empty ( $ val [ 'display_text' ] ) ) { continue ; } $ option = $ attribute -> attributeDropdownOptions ( ) -> create ( $ val ) ; } } } }
Sync Attribute Dropdown Options
38,698
public function label ( $ label = null ) { if ( null !== $ label ) { $ this -> label = $ label ; return $ this ; } if ( Lang :: has ( $ this -> label ) ) { return __ ( $ this -> label ) ; } return $ this -> label ; }
Specify a label for permission group
38,699
public function addPermission ( $ key , $ callable = null ) { if ( null !== $ callable ) { $ permission = new Permission ( $ callable ) ; $ permission -> key ( $ key ) ; $ this -> permissionList -> put ( $ key , $ permission ) ; } else { $ permission = new Permission ( ) ; $ permission -> key ( $ key ) ; $ this -> permissionList -> put ( $ key , $ permission ) ; } return $ permission ; }
Add Permission to a group