idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
17,000
|
public function getAllValuesNode ( Node $ node = null , $ property ) { $ allValues = $ this -> getAllValues ( $ node , $ property ) ; $ output = [ ] ; foreach ( $ allValues as $ a ) if ( is_a ( $ a , 'ML\JsonLD\Node' ) ) $ output [ ] = $ a ; return $ output ; }
|
Reads all values from a node and returns them as a Node array . Returns only nodes literal values are skipped .
|
17,001
|
public static function append_config ( array $ array ) : array { $ start = 9999 ; foreach ( $ array as $ key => $ value ) { if ( is_numeric ( $ key ) ) { $ start ++ ; $ array [ $ start ] = Arr :: pull ( $ array , $ key ) ; } } return $ array ; }
|
Assign high numeric IDs to a config item to force appending .
|
17,002
|
public static function class_uses_recursive ( $ class ) { if ( \ is_object ( $ class ) ) { $ class = \ get_class ( $ class ) ; } $ results = [ ] ; foreach ( array_reverse ( class_parents ( $ class ) ) + [ $ class => $ class ] as $ class ) { $ results += self :: trait_uses_recursive ( $ class ) ; } return array_unique ( $ results ) ; }
|
Returns all traits used by a class its parent classes and trait of their traits .
|
17,003
|
public static function data_fill ( & $ target , $ key , $ value ) { return self :: data_set ( $ target , $ key , $ value , false ) ; }
|
Fill in data where it s missing .
|
17,004
|
public static function data_set ( & $ target , $ key , $ value , $ overwrite = true ) { $ segments = \ is_array ( $ key ) ? $ key : explode ( '.' , $ key ) ; if ( ( $ segment = array_shift ( $ segments ) ) === '*' ) { if ( ! Arr :: accessible ( $ target ) ) { $ target = [ ] ; } if ( $ segments ) { foreach ( $ target as & $ inner ) { self :: data_set ( $ inner , $ segments , $ value , $ overwrite ) ; } } elseif ( $ overwrite ) { foreach ( $ target as & $ inner ) { $ inner = $ value ; } } } elseif ( Arr :: accessible ( $ target ) ) { if ( $ segments ) { if ( ! Arr :: exists ( $ target , $ segment ) ) { $ target [ $ segment ] = [ ] ; } self :: data_set ( $ target [ $ segment ] , $ segments , $ value , $ overwrite ) ; } elseif ( $ overwrite || ! Arr :: exists ( $ target , $ segment ) ) { $ target [ $ segment ] = $ value ; } } elseif ( \ is_object ( $ target ) ) { if ( $ segments ) { if ( ! isset ( $ target -> { $ segment } ) ) { $ target -> { $ segment } = [ ] ; } self :: data_set ( $ target -> { $ segment } , $ segments , $ value , $ overwrite ) ; } elseif ( $ overwrite || ! isset ( $ target -> { $ segment } ) ) { $ target -> { $ segment } = $ value ; } } else { $ target = [ ] ; if ( $ segments ) { self :: data_set ( $ target [ $ segment ] , $ segments , $ value , $ overwrite ) ; } elseif ( $ overwrite ) { $ target [ $ segment ] = $ value ; } } return $ target ; }
|
Set an item on an array or object using dot notation .
|
17,005
|
public static function object_get ( $ object , $ key , $ default = null ) { if ( \ is_null ( $ key ) || trim ( $ key ) === '' ) { return $ object ; } foreach ( explode ( '.' , $ key ) as $ segment ) { if ( ! \ is_object ( $ object ) || ! isset ( $ object -> { $ segment } ) ) { return self :: value ( $ default ) ; } $ object = $ object -> { $ segment } ; } return $ object ; }
|
Get an item from an object using dot notation .
|
17,006
|
public static function preg_replace_array ( $ pattern , array $ replacements , $ subject ) { return preg_replace_callback ( $ pattern , function ( ) use ( & $ replacements ) { foreach ( $ replacements as $ key => $ value ) { return array_shift ( $ replacements ) ; } } , $ subject ) ; }
|
Replace a given pattern with each value in the array in sequentially .
|
17,007
|
public static function retry ( $ times , callable $ callback , $ sleep = 0 ) { $ times -- ; beginning : try { return $ callback ( ) ; } catch ( \ Exception $ e ) { if ( ! $ times ) { throw $ e ; } $ times -- ; if ( $ sleep ) { usleep ( $ sleep * 1000 ) ; } goto beginning ; } }
|
Retry an operation a given number of times .
|
17,008
|
public static function throw_if ( $ condition , $ exception , ... $ parameters ) { if ( $ condition ) { throw ( \ is_string ( $ exception ) ? new $ exception ( ... $ parameters ) : $ exception ) ; } return $ condition ; }
|
Throw the given exception if the given condition is true .
|
17,009
|
public static function throw_unless ( $ condition , $ exception , ... $ parameters ) { if ( ! $ condition ) { throw ( \ is_string ( $ exception ) ? new $ exception ( ... $ parameters ) : $ exception ) ; } return $ condition ; }
|
Throw the given exception unless the given condition is true .
|
17,010
|
public static function transform ( $ value , callable $ callback , $ default = null ) { if ( self :: filled ( $ value ) ) { return $ callback ( $ value ) ; } if ( \ is_callable ( $ default ) ) { return $ default ( $ value ) ; } return $ default ; }
|
Transform the given value if it is present .
|
17,011
|
public static function getMostFrequentValues ( array $ data , $ mostFrequentQuantity = NULL , $ allocationPeriod = NULL ) { $ mostFrequentValues = [ ] ; $ allocatedData = self :: allocateInfo ( $ data , $ allocationPeriod ) ; usort ( $ allocatedData , function ( $ a , $ b ) { if ( $ a -> getValueQuantity ( ) === $ b -> getValueQuantity ( ) ) { if ( $ a -> getValue ( ) === $ b -> getValueQuantity ( ) ) { return 0 ; } return ( $ a -> getValue ( ) < $ b -> getValue ( ) ) ? - 1 : 1 ; } else { return ( $ a -> getValueQuantity ( ) > $ b -> getValueQuantity ( ) ) ? - 1 : 1 ; } } ) ; if ( ! $ mostFrequentQuantity ) { $ mostFrequentQuantity = self :: MOST_FREQUENT_QUANTITY ; } for ( $ i = 0 ; $ i < $ mostFrequentQuantity ; $ i ++ ) { $ frequentValue = new SortData ( ) ; $ frequentValue -> setValue ( $ allocatedData [ $ i ] -> getValue ( ) ) ; $ frequentValue -> setValueQuantity ( $ allocatedData [ $ i ] -> getValueQuantity ( ) ) ; $ valueExamples = ( $ allocatedData [ $ i ] -> getValueExamples ( ) !== "" ) ? substr ( $ allocatedData [ $ i ] -> getValueExamples ( ) , 0 , - 2 ) : $ allocatedData [ $ i ] -> getValueExamples ( ) ; $ frequentValue -> setValueExamples ( $ valueExamples ) ; if ( $ mostFrequentQuantity === 1 ) { $ mostFrequentValues = $ frequentValue ; } else { $ mostFrequentValues [ ] = $ frequentValue ; } } return $ mostFrequentValues ; }
|
Allow to sort array with SortData elements .
|
17,012
|
protected function renderExtraRow ( $ model , $ key , $ index , $ totals ) { if ( $ this -> extraRowValue instanceof Closure ) { $ content = call_user_func ( $ this -> extraRowValue , $ model , $ index , $ totals ) ; } else { $ values = [ ] ; foreach ( $ this -> extraRowColumns as $ name ) { $ values [ ] = ArrayHelper :: getValue ( $ model , $ name ) ; } $ content = '<strong>' . implode ( ' :: ' , $ values ) . '</strong>' ; } $ colspan = count ( $ this -> columns ) ; $ cell = Html :: tag ( 'td' , $ content , [ 'class' => $ this -> extraRowClass , 'colspan' => $ colspan ] ) ; return Html :: tag ( 'tr' , $ cell ) ; }
|
Renders extra row when required
|
17,013
|
protected function isGroupEdge ( $ name , $ row ) { $ result = array ( ) ; foreach ( $ this -> _groups [ $ name ] as $ column ) { if ( $ column [ 'start' ] == $ row ) { $ result [ 'start' ] = $ row ; $ result [ 'group' ] = $ column ; } if ( $ column [ 'end' ] == $ row ) { $ result [ 'end' ] = $ row ; $ result [ 'group' ] = $ column ; } if ( count ( $ result ) ) break ; } return $ result ; }
|
Is current row start or end of group in particular column
|
17,014
|
protected function getExtraRowTotals ( $ model , $ index , $ totals ) { return $ this -> extraRowTotalsValue instanceof Closure ? call_user_func ( $ this -> extraRowTotalsValue , $ model , $ index , $ totals ) : [ ] ; }
|
If there is a Closure will return the newly calculated totals on the Closure according to the code specified by the user .
|
17,015
|
protected function getRowValues ( $ columns , $ model , $ index = 0 ) { $ values = [ ] ; $ keys = $ this -> dataProvider -> getKeys ( ) ; foreach ( $ columns as $ column ) { if ( $ column instanceof DataColumn ) { $ values [ $ column -> attribute ] = $ this -> getColumnDataCellContent ( $ column , $ model , $ keys [ $ index ] , $ index ) ; } } return $ values ; }
|
Returns the row values of the column
|
17,016
|
protected function getColumnDataCellContent ( $ column , $ model , $ key , $ index ) { if ( $ column -> content === null ) { return $ this -> formatter -> format ( $ this -> getColumnDataCellValue ( $ column , $ model , $ key , $ index ) , $ column -> format ) ; } else { if ( $ column -> content !== null ) { return call_user_func ( $ column -> content , $ model , $ key , $ index , $ column ) ; } else { return $ this -> emptyCell ; } } }
|
Returns the column data cell content
|
17,017
|
protected function getColumnDataCellValue ( $ column , $ model , $ key , $ index ) { if ( $ column -> value !== null ) { if ( is_string ( $ column -> value ) ) { return ArrayHelper :: getValue ( $ model , $ column -> value ) ; } else { return call_user_func ( $ column -> value , $ model , $ index , $ column ) ; } } elseif ( $ column -> attribute !== null ) { return ArrayHelper :: getValue ( $ model , $ column -> attribute ) ; } return null ; }
|
Returns the column data cell value
|
17,018
|
public function overrideRouteTokens ( $ name , & $ tokens ) { $ menu = $ this -> repository -> findByViewRoute ( $ name ) ; if ( isset ( $ menu ) ) { $ key = array_search ( 'text' , array_column ( $ tokens , 0 ) ) ; array_splice ( $ tokens [ $ key ] , - 1 , 1 , '/' . $ menu -> getPath ( ) ) ; return true ; } return null ; }
|
does overwrite the route tokens does return true on success or false if wrong route .
|
17,019
|
protected function template ( ) { $ reflector = new \ ReflectionClass ( get_class ( $ this ) ) ; $ classname = $ reflector -> getName ( ) ; $ template = preg_replace ( '/(Application|Synapse)\\\View\\\/' , '' , $ classname ) ; $ template = str_replace ( '\\' , '/' , $ template ) ; return $ template ; }
|
Return the corresponding template file name for this class minus file extension
|
17,020
|
public function compareTo ( $ obj ) { if ( ! \ is_a ( $ obj , \ get_called_class ( ) ) ) { throw new \ RuntimeException ( '$obj is not a comparable instance' ) ; } if ( \ is_int ( $ this -> _Value ) && \ is_int ( $ obj -> _Value ) ) { return Number :: compare ( $ this -> _Value , $ obj -> _Value ) ; } else if ( \ is_string ( $ this -> _Value ) && \ is_string ( $ obj -> _Value ) ) { return \ strcmp ( $ this -> _Value , $ obj -> _Value ) ; } else { throw new \ RuntimeException ( 'Incomparable types' ) ; } }
|
Checks whether this enum s interval value matches another
|
17,021
|
public static function fromName ( $ str ) { $ strName = \ strtoupper ( \ trim ( $ str ) ) ; foreach ( static :: getConstants ( ) as $ name => $ value ) { if ( $ strName === \ strtoupper ( $ name ) ) { return new static ( $ value ) ; } } return null ; }
|
Creates a new enum from the case - insensitive name of a given constant
|
17,022
|
public function getName ( ) { foreach ( static :: getConstants ( ) as $ name => $ value ) { if ( $ this -> _Value === $ value ) { return $ name ; } } return null ; }
|
Returns the name of the constant which matches the enum value
|
17,023
|
public function query ( $ params = array ( ) , $ operator = "OR" ) { $ page = intval ( @ $ params [ 'page' ] ) ; $ size = intval ( @ $ params [ 'size' ] ) ; $ sort = @ $ params [ 'sort' ] ; unset ( $ params [ 'page' ] ) ; unset ( $ params [ 'size' ] ) ; unset ( $ params [ 'sort' ] ) ; if ( ! $ size ) $ size = 20 ; $ cond = array ( ) ; $ bindings = array ( ) ; foreach ( $ params as $ key => $ value ) { $ cond [ ] = sprintf ( "`%s` %s :where_%s" , str_replace ( '`' , '``' , $ key ) , is_null ( $ value ) ? 'is' : ( strpos ( $ value , '%' ) !== FALSE ? 'LIKE' : '=' ) , $ key ) ; $ bindings [ ":where_$key" ] = $ value ; } $ query = sprintf ( self :: SELECT_SEARCH , $ this -> params [ 'table' ] , empty ( $ cond ) ? '1=1' : implode ( " $operator " , $ cond ) ) ; $ query .= sprintf ( " LIMIT %d, %d" , $ page * $ size , $ size ) ; $ stmt = $ this -> pdo -> prepare ( $ query ) ; $ stmt -> execute ( $ bindings ) ; if ( ! $ stmt ) { $ error = $ this -> pdo -> errorInfo ( ) ; throw new \ Exception ( $ error [ 2 ] ) ; } $ data = $ stmt -> fetchAll ( PDO :: FETCH_ASSOC ) ; $ stmt = $ this -> pdo -> query ( "SELECT FOUND_ROWS() as count" ) ; $ count = $ stmt -> fetch ( PDO :: FETCH_ASSOC ) ; if ( ! $ count ) { throw new \ Exception ( "Error fetching count" ) ; } $ count = intval ( $ count [ 'count' ] ) ; return array ( '_embedded' => array ( $ this -> params [ 'table' ] => $ data ) , 'page' => array ( 'size' => $ size , 'number' => $ page , 'totalElements' => $ count , 'totalPages' => ceil ( $ count / $ size ) ) ) ; }
|
Queries the Auth table
|
17,024
|
public function get ( $ username ) { if ( is_numeric ( $ username ) ) { $ key = 'id' ; } else { $ key = 'username' ; } $ query = sprintf ( self :: SELECT_ALL , $ this -> params [ 'table' ] , $ this -> params [ $ key ] , $ this -> pdo -> quote ( $ username ) ) ; $ stmt = $ this -> pdo -> query ( $ query ) ; if ( ! $ stmt ) { $ error = $ this -> pdo -> errorInfo ( ) ; throw new \ Exception ( $ error [ 2 ] ) ; } if ( $ user = $ stmt -> fetch ( PDO :: FETCH_ASSOC ) ) { return $ user ; } else { throw new UserException ( 'User not found' , 404 ) ; } }
|
Retrieves a user from the database
|
17,025
|
public function & user ( $ user = null ) { if ( $ user ) { $ _SESSION [ $ this -> params [ 'session_key' ] ] = $ user ; } else { if ( ! $ this -> check ( ) ) { throw new UserException ( 'Not logged in' , 403 ) ; } } return $ _SESSION [ $ this -> params [ 'session_key' ] ] ; }
|
Returns the current logged in user or sets the current login data
|
17,026
|
public function update ( $ username , array $ data ) { $ cond = array ( ) ; unset ( $ data [ $ this -> params [ 'id' ] ] ) ; unset ( $ data [ $ this -> params [ 'password' ] ] ) ; if ( $ this -> params [ 'token' ] ) { unset ( $ data [ $ this -> params [ 'token' ] ] ) ; } if ( $ this -> params [ 'created' ] ) { unset ( $ data [ $ this -> params [ 'created' ] ] ) ; } if ( $ this -> params [ 'last_login' ] ) { unset ( $ data [ $ this -> params [ 'last_login' ] ] ) ; } foreach ( $ data as $ k => $ v ) { $ cond [ ] = sprintf ( "`%s` = %s" , str_replace ( array ( '\\' , "\0" , '`' ) , '' , $ k ) , $ this -> pdo -> quote ( $ v ) ) ; } if ( is_numeric ( $ username ) ) { $ key = 'id' ; } else { $ key = 'username' ; } $ query = sprintf ( self :: UPDATE_QUERY , $ this -> params [ 'table' ] , implode ( ', ' , $ cond ) , $ this -> params [ $ key ] , $ this -> pdo -> quote ( $ username ) ) ; $ stmt = $ this -> pdo -> query ( $ query ) ; if ( $ stmt === FALSE ) { throw new UserException ( json_encode ( $ this -> pdo -> errorInfo ( ) ) ) ; } }
|
Update arbitrary user data
|
17,027
|
public function update_token ( $ username ) { $ token = self :: hash ( ) ; $ query = sprintf ( self :: UPDATE_VALUE , $ this -> params [ 'table' ] , $ this -> params [ 'token' ] , $ this -> pdo -> quote ( $ token ) , $ this -> params [ 'username' ] , $ this -> pdo -> quote ( $ username ) ) ; $ stmt = $ this -> pdo -> query ( $ query ) ; if ( $ stmt === FALSE || $ stmt -> rowCount ( ) !== 1 ) { throw new UserException ( 'Token not found' ) ; } return $ token ; }
|
Generates a new token for the user and update the database
|
17,028
|
public function & buildArray ( $ inputXml ) { $ this -> init ( ) ; if ( is_string ( $ inputXml ) ) { $ this -> xml = $ this -> createDOMDocument ( ) ; $ parsed = $ this -> xml -> loadXML ( $ inputXml ) ; if ( ! $ parsed ) { throw new \ Exception ( '[Transformer] Error parsing the XML string.' ) ; } } elseif ( $ inputXml instanceof \ DOMDocument ) { $ this -> xml = $ inputXml ; } else { throw new \ Exception ( '[Transformer] The input XML object should be of type: DOMDocument but got instead [' . gettype ( $ inputXml ) . '].' ) ; } $ docNodeName = $ this -> xml -> documentElement -> nodeName ; $ array [ $ docNodeName ] = $ this -> convert ( $ this -> xml -> documentElement ) ; if ( ! empty ( $ this -> namespaces ) ) { if ( ! isset ( $ array [ $ docNodeName ] [ $ this -> config [ 'attributesKey' ] ] ) ) { $ array [ $ docNodeName ] [ $ this -> config [ 'attributesKey' ] ] = array ( ) ; } foreach ( $ this -> namespaces as $ uri => $ prefix ) { if ( $ prefix ) { $ prefix = self :: ATTRIBUTE_NAMESPACE_SEPARATOR . $ prefix ; } $ array [ $ docNodeName ] [ $ this -> config [ 'attributesKey' ] ] [ self :: ATTRIBUTE_NAMESPACE . $ prefix ] = $ uri ; } } return $ array ; }
|
Convert an XML DOMDocument or XML string to an array
|
17,029
|
protected function collateNamespaces ( \ DOMNode $ node ) { if ( $ this -> config [ 'useNamespaces' ] && $ node -> namespaceURI && ! array_key_exists ( $ node -> namespaceURI , $ this -> namespaces ) ) { $ this -> namespaces [ $ node -> namespaceURI ] = $ node -> lookupPrefix ( $ node -> namespaceURI ) ; } }
|
Get the namespace of the supplied node and add it to the list of known namespaces for this document
|
17,030
|
protected function getConfig ( $ requestedName , ServiceLocatorInterface $ services ) { if ( $ this -> configKey ) { $ config = $ services -> get ( 'Config' ) ; if ( ! empty ( $ config [ $ this -> configKey ] [ $ requestedName ] ) && is_array ( $ config [ $ this -> configKey ] [ $ requestedName ] ) ) { return $ config [ $ this -> configKey ] [ $ requestedName ] ; } } return [ ] ; }
|
Retrieves configuration options
|
17,031
|
protected function fetchUrl ( $ path ) { $ path .= '&format=xml' ; $ uri = new Uri ( $ this -> options -> get ( 'api.url' ) . '/api.php' . $ path ) ; if ( $ this -> options -> get ( 'api.username' , false ) ) { $ uri -> setUser ( $ this -> options -> get ( 'api.username' ) ) ; } if ( $ this -> options -> get ( 'api.password' , false ) ) { $ uri -> setPass ( $ this -> options -> get ( 'api.password' ) ) ; } return ( string ) $ uri ; }
|
Method to build and return a full request URL for the request .
|
17,032
|
public function buildParameter ( array $ params ) { $ path = '' ; foreach ( $ params as $ param ) { $ path .= $ param ; if ( next ( $ params ) == true ) { $ path .= '|' ; } } return $ path ; }
|
Method to build request parameters from a string array .
|
17,033
|
public function validateResponse ( Response $ response ) { $ xml = simplexml_load_string ( $ response -> body ) ; if ( isset ( $ xml -> warnings ) ) { throw new \ DomainException ( $ xml -> warnings -> info ) ; } if ( isset ( $ xml -> error ) ) { throw new \ DomainException ( $ xml -> error [ 'info' ] ) ; } return $ xml ; }
|
Method to validate response for errors
|
17,034
|
public function checkGii ( ) { if ( ! isset ( Yii :: $ app -> controllerMap [ $ this -> giiID ] ) ) { $ msg = "Command \"{$this->giiID}\" is not available.\n" ; $ msg .= "Please check to ensure the module is mounted and added to bootstrap phase.\n" ; $ this -> controller -> stderr ( $ msg , Console :: FG_RED ) ; Yii :: $ app -> end ( 1 ) ; } }
|
Check whether Gii module is loaded .
|
17,035
|
public static function ImageSize ( $ Path , $ Filename = FALSE ) { if ( ! $ Filename ) $ Filename = $ Path ; if ( in_array ( strtolower ( pathinfo ( $ Filename , PATHINFO_EXTENSION ) ) , array ( 'gif' , 'jpg' , 'jpeg' , 'png' ) ) ) { $ ImageSize = @ getimagesize ( $ Path ) ; if ( ! is_array ( $ ImageSize ) || ! in_array ( $ ImageSize [ 2 ] , array ( IMAGETYPE_GIF , IMAGETYPE_JPEG , IMAGETYPE_PNG ) ) ) return array ( 0 , 0 , FALSE ) ; return $ ImageSize ; } return array ( 0 , 0 , FALSE ) ; }
|
Gets the image size of a file .
|
17,036
|
public function ValidateUpload ( $ InputName , $ ThrowError = TRUE ) { if ( ! function_exists ( 'gd_info' ) ) throw new Exception ( T ( 'The uploaded file could not be processed because GD is not installed.' ) ) ; $ TmpFileName = parent :: ValidateUpload ( $ InputName , $ ThrowError ) ; if ( $ TmpFileName ) { $ Size = getimagesize ( $ TmpFileName ) ; if ( $ Size === FALSE ) throw new Exception ( T ( 'The uploaded file was not an image.' ) ) ; } return $ TmpFileName ; }
|
Validates the uploaded image . Returns the temporary name of the uploaded file .
|
17,037
|
public function prependSet ( $ key , $ value ) : ArrayCollection { $ this -> items = [ $ key => $ value ] + $ this -> items ; return $ this ; }
|
Prepends a keyed value
|
17,038
|
public function pull ( $ key ) { $ value = $ this -> get ( $ key ) ; $ this -> remove ( $ key ) ; return $ value ; }
|
Retrieves and removes a value
|
17,039
|
public function splice ( int $ offset , ? int $ length = null , array $ replacement = [ ] ) : ArrayCollection { if ( $ length === null && empty ( $ replacement ) ) { return new static ( array_splice ( $ this -> items , $ offset ) ) ; } if ( $ length === null ) { $ length = $ this -> count ( ) ; } return new static ( array_splice ( $ this -> items , $ offset , $ length , $ replacement ) ) ; }
|
Removes and returns a portion of the collection
|
17,040
|
public function contains ( $ value , bool $ strict = true ) : bool { return in_array ( $ value , $ this -> items , $ strict ) ; }
|
Checks if a value exists
|
17,041
|
public function search ( $ value , bool $ strict = true ) { return array_search ( $ value , $ this -> items , $ strict ) ; }
|
Retrieves the key for a given value
|
17,042
|
public function any ( callable $ predicate ) : bool { foreach ( $ this -> items as $ key => $ value ) { if ( $ predicate ( $ value , $ key ) ) { return true ; } } return false ; }
|
Checks if any items pass a truth test
|
17,043
|
public function first ( ? callable $ predicate = null , $ default = null ) { if ( $ predicate === null ) { return $ this -> isEmpty ( ) ? $ default : reset ( $ this -> items ) ; } foreach ( $ this -> items as $ key => $ value ) { if ( $ predicate ( $ value , $ key ) ) { return $ value ; } } return $ default ; }
|
Retrieves the first value from the collection
|
17,044
|
public function last ( ? callable $ predicate = null , $ default = null ) { if ( $ predicate === null ) { return $ this -> isEmpty ( ) ? $ default : end ( $ this -> items ) ; } foreach ( array_reverse ( $ this -> items , true ) as $ key => $ value ) { if ( $ predicate ( $ value , $ key ) ) { return $ value ; } } return $ default ; }
|
Retrieves the last value from the collection
|
17,045
|
public function random ( int $ amount = 1 ) { $ count = $ this -> count ( ) ; if ( $ amount > $ count ) { $ message = sprintf ( 'Requested %d items with %d items present' , $ amount , $ count ) ; throw new DomainException ( $ message ) ; } $ keys = array_rand ( $ this -> items , $ amount ) ; if ( $ amount === 1 ) { return $ this -> items [ $ keys ] ; } return new static ( array_intersect_key ( $ this -> items , array_flip ( $ keys ) ) ) ; }
|
Retrieves items randomly
|
17,046
|
public function sort ( callable $ comparator = null ) : ArrayCollection { $ items = $ this -> items ; $ comparator ? uasort ( $ items , $ comparator ) : uasort ( $ items , function ( $ a , $ b ) { return $ a <=> $ b ; } ) ; return new static ( $ items ) ; }
|
Creates a sorted collection
|
17,047
|
public function sortBy ( callable $ callback , $ options = SORT_REGULAR , $ descending = false ) : ArrayCollection { $ items = [ ] ; foreach ( $ this -> items as $ key => $ value ) { $ items [ $ key ] = $ callback ( $ value , $ key ) ; } if ( $ descending ) { arsort ( $ items , $ options ) ; } else { asort ( $ items , $ options ) ; } foreach ( array_keys ( $ items ) as $ key ) { $ items [ $ key ] = $ this -> items [ $ key ] ; } return new static ( $ items ) ; }
|
Creates a sorted collection using values from a callback
|
17,048
|
public function sortByDesc ( callable $ callback , $ options = SORT_REGULAR ) : ArrayCollection { return $ this -> sortBy ( $ callback , $ options , true ) ; }
|
Creates a descending sorted collection using values from a callback
|
17,049
|
public function each ( callable $ callback ) : ArrayCollection { foreach ( $ this -> items as $ key => $ value ) { $ callback ( $ value , $ key ) ; } return $ this ; }
|
Applies a callback function to every item
|
17,050
|
public function map ( callable $ callback ) : ArrayCollection { $ items = [ ] ; foreach ( $ this -> items as $ key => $ value ) { $ items [ $ key ] = $ callback ( $ value , $ key ) ; } return new static ( $ items ) ; }
|
Creates a collection from the results of a callback function
|
17,051
|
public function pluck ( string $ key ) : ArrayCollection { return $ this -> map ( function ( $ value ) use ( $ key ) { return $ value [ $ key ] ?? null ; } ) ; }
|
Creates a collection of values with a given key
|
17,052
|
public function keyBy ( callable $ callback ) : ArrayCollection { $ items = [ ] ; foreach ( $ this -> items as $ key => $ value ) { $ items [ $ callback ( $ value , $ key ) ] = $ value ; } return new static ( $ items ) ; }
|
Creates a collection keyed by keys from a callback
|
17,053
|
public function groupBy ( callable $ callback , bool $ preserveKeys = false ) : ArrayCollection { $ items = [ ] ; foreach ( $ this -> items as $ key => $ value ) { $ group = $ callback ( $ value , $ key ) ; if ( ! array_key_exists ( $ group , $ items ) ) { $ items [ $ group ] = new static ( ) ; } $ items [ $ group ] -> set ( $ preserveKeys ? $ key : null , $ value ) ; } return new static ( $ items ) ; }
|
Creates a collection grouped by keys from a callback
|
17,054
|
public function chunk ( int $ size , bool $ preserveKeys = false ) : ArrayCollection { $ chunks = [ ] ; foreach ( array_chunk ( $ this -> items , $ size , $ preserveKeys ) as $ chunk ) { $ chunks [ ] = new static ( $ chunk ) ; } return new static ( $ chunks ) ; }
|
Creates a collection with item chunks
|
17,055
|
public function collapse ( ) : ArrayCollection { $ items = [ ] ; foreach ( $ this -> items as $ values ) { if ( $ values instanceof self ) { $ values = $ values -> all ( ) ; } elseif ( ! is_array ( $ values ) ) { continue ; } $ items = array_merge ( $ items , $ values ) ; } return new static ( $ items ) ; }
|
Creates a collection with items collapsed
|
17,056
|
public function zip ( ... $ items ) : ArrayCollection { $ arrayItems = array_map ( function ( $ items ) { return $ this -> itemsArray ( $ items ) ; } , $ items ) ; $ params = array_merge ( [ function ( ... $ items ) { return new static ( $ items ) ; } , $ this -> items ] , $ arrayItems ) ; return new static ( call_user_func_array ( 'array_map' , $ params ) ) ; }
|
Creates a collection zipped with the given items
|
17,057
|
public function unique ( ? callable $ callback = null ) : ArrayCollection { if ( $ callback === null ) { return new static ( array_unique ( $ this -> items , SORT_REGULAR ) ) ; } $ set = [ ] ; return $ this -> filter ( function ( $ value , $ key ) use ( $ callback , & $ set ) { $ hash = $ callback ( $ value , $ key ) ; if ( isset ( $ set [ $ hash ] ) ) { return false ; } $ set [ $ hash ] = true ; return true ; } ) ; }
|
Creates a collection with unique items
|
17,058
|
public function union ( $ items ) : ArrayCollection { return new static ( array_unique ( array_merge ( $ this -> items , $ this -> itemsArray ( $ items ) ) ) ) ; }
|
Creates a collection with the union of current and given items
|
17,059
|
public function filter ( callable $ predicate ) : ArrayCollection { $ items = [ ] ; foreach ( $ this -> items as $ key => $ value ) { if ( $ predicate ( $ value , $ key ) ) { $ items [ $ key ] = $ value ; } } return new static ( $ items ) ; }
|
Creates a collection from items that pass a truth test
|
17,060
|
public function reject ( callable $ predicate ) : ArrayCollection { $ items = [ ] ; foreach ( $ this -> items as $ key => $ value ) { if ( ! $ predicate ( $ value , $ key ) ) { $ items [ $ key ] = $ value ; } } return new static ( $ items ) ; }
|
Creates a collection from items that fail a truth test
|
17,061
|
public function where ( $ key , $ value , bool $ strict = true ) : ArrayCollection { return $ this -> filter ( function ( $ item ) use ( $ key , $ value , $ strict ) { if ( ! isset ( $ item [ $ key ] ) ) { return false ; } return $ strict ? $ item [ $ key ] === $ value : $ item [ $ key ] == $ value ; } ) ; }
|
Creates a filtered collection by key and value
|
17,062
|
public function whereIn ( $ key , array $ values , bool $ strict = true ) : ArrayCollection { return $ this -> filter ( function ( $ item ) use ( $ key , $ values , $ strict ) { if ( ! isset ( $ item [ $ key ] ) ) { return false ; } return in_array ( $ item [ $ key ] , $ values , $ strict ) ; } ) ; }
|
Creates a filtered collection by key and values
|
17,063
|
public function slice ( int $ offset , ? int $ length = null ) : ArrayCollection { return new static ( array_slice ( $ this -> items , $ offset , $ length , true ) ) ; }
|
Creates a collection from a slice of items
|
17,064
|
public function skip ( int $ step ) : ArrayCollection { $ items = [ ] ; $ pos = 0 ; foreach ( $ this -> items as $ key => $ value ) { if ( $ pos % $ step === 0 ) { $ items [ $ key ] = $ value ; } $ pos ++ ; } return new static ( $ items ) ; }
|
Creates a collection with every n - th element
|
17,065
|
public function partition ( callable $ predicate ) : ArrayCollection { $ items1 = [ ] ; $ items2 = [ ] ; foreach ( $ this -> items as $ key => $ value ) { if ( $ predicate ( $ value , $ key ) ) { $ items1 [ $ key ] = $ value ; } else { $ items2 [ $ key ] = $ value ; } } return new static ( [ new static ( $ items1 ) , new static ( $ items2 ) ] ) ; }
|
Creates a collection of two collections based on a truth test
|
17,066
|
public function page ( int $ page , int $ perPage ) : ArrayCollection { return $ this -> slice ( ( $ page - 1 ) * $ perPage , $ perPage ) ; }
|
Creates a paginated collection
|
17,067
|
public function implode ( ? string $ glue = null , ? callable $ callback = null ) : string { if ( $ glue === null ) { $ glue = '' ; } if ( $ callback !== null ) { return implode ( $ glue , $ this -> map ( $ callback ) -> all ( ) ) ; } return implode ( $ glue , $ this -> all ( ) ) ; }
|
Concatenates values into a string
|
17,068
|
public function join ( ? string $ glue = null , ? callable $ callback = null ) : string { return $ this -> implode ( $ glue , $ callback ) ; }
|
Alias for implode
|
17,069
|
public function reduce ( callable $ callback , $ initial = null ) { $ accumulator = $ initial ; foreach ( $ this -> items as $ key => $ value ) { $ accumulator = $ callback ( $ accumulator , $ value , $ key ) ; } return $ accumulator ; }
|
Reduces the collection to a single value
|
17,070
|
public function sum ( ? callable $ callback = null ) { if ( $ callback === null ) { $ callback = function ( $ value , $ key ) { return $ value ; } ; } return $ this -> reduce ( function ( $ total , $ value , $ key ) use ( $ callback ) { return $ total + $ callback ( $ value , $ key ) ; } , 0 ) ; }
|
Retrieves the sum of the collection
|
17,071
|
public function max ( ? callable $ callback = null ) { return $ this -> reduce ( function ( $ result , $ value , $ key ) use ( $ callback ) { if ( $ callback !== null ) { $ value = $ callback ( $ value , $ key ) ; } return ( $ result === null ) || $ value > $ result ? $ value : $ result ; } ) ; }
|
Retrieves the maximum value for a collection
|
17,072
|
public function min ( ? callable $ callback = null ) { return $ this -> reduce ( function ( $ result , $ value , $ key ) use ( $ callback ) { if ( $ callback !== null ) { $ value = $ callback ( $ value , $ key ) ; } return ( $ result === null ) || $ value < $ result ? $ value : $ result ; } ) ; }
|
Retrieves the minimum value for a collection
|
17,073
|
protected static function flattenArray ( array $ array , int $ depth = PHP_INT_MAX ) : array { $ items = [ ] ; foreach ( $ array as $ item ) { if ( $ item instanceof self ) { $ item = $ item -> all ( ) ; } if ( is_array ( $ item ) ) { if ( $ depth === 1 ) { $ items = array_merge ( $ items , $ item ) ; continue ; } $ items = array_merge ( $ items , static :: flattenArray ( $ item , $ depth - 1 ) ) ; continue ; } $ items [ ] = $ item ; } return $ items ; }
|
Flattens a multi - dimensional array into a single level
|
17,074
|
protected function itemsArray ( $ items ) : array { if ( is_array ( $ items ) ) { return $ items ; } elseif ( $ items instanceof self ) { return $ items -> all ( ) ; } elseif ( $ items instanceof Arrayable ) { return $ items -> toArray ( ) ; } return ( array ) $ items ; }
|
Retrieves items as an array
|
17,075
|
public function ok ( $ data , int $ status = 200 , int $ encodingOptions = 0 ) { $ this -> validHttpCode ( $ status ) ; return parent :: withJson ( $ data , $ status , $ encodingOptions ) ; }
|
Response data with 2xx status code
|
17,076
|
public function runControllerWithParameters ( $ parameters = [ ] ) { $ this -> setParameters ( $ this -> toArray ( $ parameters ) ) ; foreach ( $ this -> callbacks as $ callback ) { $ this -> app -> call ( $ callback ) ; } }
|
register parameters and run constructors
|
17,077
|
public function handle ( ) { Log :: debug ( "ArtisanCommand handle begin $this->command_string" ) ; $ input = new StringInput ( $ this -> command_string ) ; $ output = new PusherChannelOutput ( ) ; $ pusher = Broadcast :: connection ( ) -> getPusher ( ) ; $ channel_id = config ( 'platformadmin.console.pusher_channel_base' ) . $ this -> command_id ; $ output -> setPusherConnectionAndChannel ( $ pusher , $ channel_id ) ; $ output -> open ( ) ; $ kernel = app ( Kernel :: class ) ; $ status = $ kernel -> handle ( $ input , $ output ) ; $ kernel -> terminate ( $ input , $ status ) ; usleep ( 350000 ) ; $ output -> writeln ( '' ) ; usleep ( 750000 ) ; $ output -> close ( $ status ) ; Log :: debug ( "ArtisanCommand handle end $this->command_string" ) ; }
|
handle the job
|
17,078
|
public static function endpointsInfo ( Application $ app ) { $ app -> boot ( ) ; $ controllers = $ app [ 'controllers' ] ; $ rControllers = new ReflectionObject ( $ controllers ) ; $ pControllers = $ rControllers -> getProperty ( 'controllers' ) ; $ pControllers -> setAccessible ( true ) ; foreach ( $ pControllers -> getValue ( $ controllers ) as $ ctrl ) { if ( $ ctrl instanceof Controller ) { $ route = $ ctrl -> getRoute ( ) ; foreach ( $ route -> getMethods ( ) as $ method ) { echo '- ' . str_pad ( $ method , 7 ) . ' ' . str_pad ( $ route -> getPath ( ) , 70 ) ; if ( $ service = $ route -> getDefault ( '_controller' ) ) { if ( is_scalar ( $ service ) ) { echo 'Handler: ' . $ service ; } } echo "\n" ; } } } }
|
Simple method to print application resources .
|
17,079
|
protected function buildPagination ( ) { $ this -> calculateDisplayRange ( ) ; $ pages = array ( ) ; for ( $ i = $ this -> displayRangeStart ; $ i <= $ this -> displayRangeEnd ; $ i ++ ) { $ pages [ ] = array ( 'number' => $ i , 'isCurrent' => ( $ i === $ this -> currentPage ) ) ; } $ pagination = array ( 'pages' => $ pages , 'current' => $ this -> currentPage , 'numberOfPages' => $ this -> numberOfPages , 'displayRangeStart' => $ this -> displayRangeStart , 'displayRangeEnd' => $ this -> displayRangeEnd , 'hasLessPages' => $ this -> displayRangeStart > 2 , 'hasMorePages' => $ this -> displayRangeEnd + 1 < $ this -> numberOfPages ) ; if ( $ this -> currentPage < $ this -> numberOfPages ) { $ pagination [ 'nextPage' ] = $ this -> currentPage + 1 ; } if ( $ this -> currentPage > 1 ) { $ pagination [ 'previousPage' ] = $ this -> currentPage - 1 ; } return $ pagination ; }
|
Returns an array with the keys pages current numberOfPages nextPage & previousPage
|
17,080
|
public static function create_from_string ( $ input , $ pattern_key = 'local' ) { \ Config :: load ( 'date' , 'date' ) ; $ pattern = \ Config :: get ( 'date.patterns.' . $ pattern_key , null ) ; empty ( $ pattern ) and $ pattern = $ pattern_key ; $ time = strptime ( $ input , $ pattern ) ; if ( $ time === false ) { throw new \ UnexpectedValueException ( 'Input was not recognized by pattern.' ) ; } $ timestamp = mktime ( $ time [ 'tm_hour' ] , $ time [ 'tm_min' ] , $ time [ 'tm_sec' ] , $ time [ 'tm_mon' ] + 1 , $ time [ 'tm_mday' ] , $ time [ 'tm_year' ] + 1900 ) ; if ( $ timestamp === false ) { throw new \ OutOfBoundsException ( 'Input was invalid.' . ( PHP_INT_SIZE == 4 ? ' A 32-bit system only supports dates between 1901 and 2038.' : '' ) ) ; } return static :: forge ( $ timestamp ) ; }
|
Uses the date config file to translate string input to timestamp
|
17,081
|
public static function range_to_array ( $ start , $ end , $ interval = '+1 Day' ) { $ start = ( ! $ start instanceof Date ) ? static :: forge ( $ start ) : $ start ; $ end = ( ! $ end instanceof Date ) ? static :: forge ( $ end ) : $ end ; is_int ( $ interval ) or $ interval = strtotime ( $ interval , $ start -> get_timestamp ( ) ) - $ start -> get_timestamp ( ) ; if ( $ interval <= 0 ) { throw new \ UnexpectedValueException ( 'Input was not recognized by pattern.' ) ; } $ range = array ( ) ; $ current = $ start ; while ( $ current -> get_timestamp ( ) <= $ end -> get_timestamp ( ) ) { $ range [ ] = $ current ; $ current = static :: forge ( $ current -> get_timestamp ( ) + $ interval ) ; } return $ range ; }
|
Fetches an array of Date objects per interval within a range
|
17,082
|
public static function time_ago ( $ timestamp , $ from_timestamp = null , $ unit = null ) { if ( $ timestamp === null ) { return '' ; } ! is_numeric ( $ timestamp ) and $ timestamp = static :: create_from_string ( $ timestamp ) -> get_timestamp ( ) ; $ from_timestamp == null and $ from_timestamp = time ( ) ; \ Lang :: load ( 'date' , true ) ; $ difference = $ from_timestamp - $ timestamp ; $ periods = array ( 'second' , 'minute' , 'hour' , 'day' , 'week' , 'month' , 'year' , 'decade' ) ; $ lengths = array ( 60 , 60 , 24 , 7 , 4.35 , 12 , 10 ) ; for ( $ j = 0 ; isset ( $ lengths [ $ j ] ) and $ difference >= $ lengths [ $ j ] and ( empty ( $ unit ) or $ unit != $ periods [ $ j ] ) ; $ j ++ ) { $ difference /= $ lengths [ $ j ] ; } $ difference = round ( $ difference ) ; if ( $ difference != 1 ) { $ periods [ $ j ] = \ Inflector :: pluralize ( $ periods [ $ j ] ) ; } $ text = \ Lang :: get ( 'date.text' , array ( 'time' => \ Lang :: get ( 'date.' . $ periods [ $ j ] , array ( 't' => $ difference ) ) ) ) ; return $ text ; }
|
Returns the time ago
|
17,083
|
public function format ( $ pattern_key = 'local' , $ timezone = null ) { \ Config :: load ( 'date' , 'date' ) ; $ pattern = \ Config :: get ( 'date.patterns.' . $ pattern_key , $ pattern_key ) ; $ timezone === true and $ timezone = static :: $ display_timezone ; is_string ( $ timezone ) or $ timezone = $ this -> timezone ; if ( \ Fuel :: $ timezone != $ timezone ) { date_default_timezone_set ( $ timezone ) ; } $ output = strftime ( $ pattern , $ this -> timestamp ) ; if ( \ Fuel :: $ timezone != $ timezone ) { date_default_timezone_set ( \ Fuel :: $ timezone ) ; } return $ output ; }
|
Returns the date formatted according to the current locale
|
17,084
|
public function get_timezone_abbr ( $ display_timezone = false ) { $ display_timezone and $ timezone = static :: $ display_timezone ; empty ( $ timezone ) and $ timezone = $ this -> timezone ; if ( \ Fuel :: $ timezone != $ timezone ) { date_default_timezone_set ( $ timezone ) ; } $ output = date ( 'T' ) ; if ( \ Fuel :: $ timezone != $ timezone ) { date_default_timezone_set ( \ Fuel :: $ timezone ) ; } return $ output ; }
|
Returns the internal timezone or the display timezone abbreviation
|
17,085
|
protected function send ( ) { try { $ options = $ this -> getOptions ( ) ; $ message = sprintf ( 'Service: %2$s' . PHP_EOL . 'Host: %3$s' . PHP_EOL . 'State: %5$s' . PHP_EOL . 'Message: %7$s' , $ options [ 'type' ] , $ options [ 'service' ] , $ options [ 'host' ] , $ options [ 'address' ] , $ options [ 'state' ] , $ options [ 'time' ] , $ options [ 'output' ] ) ; $ priority = $ this -> determinePriority ( $ options [ 'state' ] ) ; $ this -> nmaClient -> verify ( ) ; $ this -> nmaClient -> notify ( self :: SENDER , $ options [ 'type' ] , $ message , $ priority , 'anag://open?updateonreceive=true' ) ; $ this -> setMessage ( 'Message was sent' ) ; $ this -> setCode ( self :: STATE_OK ) ; } catch ( Exception $ e ) { $ this -> setMessage ( 'Message could not be sent. Error from NMA client: ' . $ e -> getMessage ( ) ) ; $ this -> setCode ( self :: STATE_CRITICAL ) ; } return $ this ; }
|
Sends the notification to the given Android device .
|
17,086
|
protected function determinePriority ( $ state ) { $ priority = 0 ; if ( array_key_exists ( $ state , $ this -> stateToPriorityMap ) ) { $ priority = $ this -> stateToPriorityMap [ $ state ] ; } return $ priority ; }
|
Returns the priority for the given host or service state .
|
17,087
|
public function getDescription ( ) { if ( empty ( $ this -> paragraphId ) ) { return '' ; } $ model = $ this -> getServiceLocator ( ) -> get ( 'Grid\Paragraph\Model\Paragraph\Model' ) ; $ locale = $ model -> getLocale ( ) ; $ model -> setLocale ( $ this -> locale ) ; $ content = $ model -> find ( $ this -> paragraphId ) ; $ model -> setLocale ( $ locale ) ; if ( empty ( $ content ) ) { return $ this -> originalTitle ; } else if ( ! empty ( $ content -> title ) ) { return $ content -> title ; } else if ( ! empty ( $ content -> name ) ) { return $ content -> name ; } else { return $ this -> originalTitle ; } }
|
Get description for this log - event
|
17,088
|
protected function getRelationClosure ( Entity $ entity , Attribute $ attribute ) { $ method = $ attribute -> is_collection ? 'hasMany' : 'hasOne' ; return Closure :: bind ( function ( ) use ( $ entity , $ attribute , $ method ) { $ relation = $ entity -> $ method ( $ attribute -> getAttribute ( 'type' ) , 'entity_id' , 'id' ) ; $ relation -> where ( 'entity_type' , get_class ( $ entity ) ) ; return $ relation -> where ( $ attribute -> getForeignKey ( ) , $ attribute -> getKey ( ) ) ; } , $ entity , get_class ( $ entity ) ) ; }
|
Generate the entity attribute relation closure .
|
17,089
|
public final function getHeaderValue ( $ name ) { self :: checkString ( $ name ) ; foreach ( $ this -> _headers as $ headerName => $ headerValue ) { if ( strcasecmp ( $ name , $ headerName ) === 0 ) { return $ headerValue ; } } return null ; }
|
Find a header value by header name .
|
17,090
|
public final function setHeader ( $ name , $ value ) { self :: checkString ( $ name ) ; self :: checkString ( $ value ) ; $ this -> _headers [ $ name ] = $ value ; }
|
Set a single header .
|
17,091
|
public final function removeHeaders ( $ name ) { self :: checkString ( $ name ) ; foreach ( $ this -> _headers as $ headerName => $ headerValue ) { if ( strcasecmp ( $ name , $ headerName ) === 0 ) { unset ( $ this -> _headers [ $ headerName ] ) ; } } }
|
Removes any headers with the given name .
|
17,092
|
public function commit ( $ pWithChilds = false ) { try { $ prepared = Agl :: app ( ) -> getDb ( ) -> getConnection ( ) -> prepare ( " DELETE FROM `" . $ this -> getDbPrefix ( ) . $ this -> _item -> getDbContainer ( ) . "` WHERE `" . $ this -> _item -> getDbContainer ( ) . ItemInterface :: PREFIX_SEPARATOR . ItemInterface :: IDFIELD . "` = :" . ItemInterface :: IDFIELD . " " ) ; $ preparedValues = array ( ItemInterface :: IDFIELD => $ this -> _item -> getId ( ) -> getOrig ( ) ) ; if ( ! $ prepared -> execute ( $ preparedValues ) ) { $ error = $ prepared -> errorInfo ( ) ; throw new Exception ( "The delete query failed (table '" . $ this -> getDbPrefix ( ) . $ this -> _item -> getDbContainer ( ) . "') with message '" . $ error [ 2 ] . "'" ) ; } if ( $ pWithChilds ) { $ this -> _item -> removeJoinFromAllChilds ( ) ; } if ( Agl :: app ( ) -> isDebugMode ( ) ) { Agl :: app ( ) -> getDb ( ) -> incrementCounter ( ) ; } return $ prepared -> rowCount ( ) ; } catch ( Exception $ e ) { throw new Exception ( $ e ) ; } return true ; }
|
Commit the deletion to Mysql and check the query result .
|
17,093
|
public function set ( $ key , $ value , \ DatePeriod $ period = null ) { if ( is_null ( $ period ) ) { $ this -> repository -> set ( $ key , $ value ) ; } else { $ this -> setForPeriod ( $ key , $ value , $ period ) ; } }
|
Set value for a key .
|
17,094
|
public function get ( $ key , \ DatePeriod $ period = null ) { if ( is_null ( $ period ) ) { return new Value ( $ this -> repository -> get ( $ key ) ) ; } return $ this -> getForPeriod ( $ key , $ period ) ; }
|
Get value for a key .
|
17,095
|
protected function getForPeriod ( $ key , \ DatePeriod $ period ) { $ ranges = $ this -> getRanges ( $ period ) ; if ( count ( $ ranges ) > 0 ) { if ( count ( $ ranges ) == 1 && ! ( $ ranges [ 0 ] instanceof DateRange ) ) { return new DateValue ( $ ranges [ 0 ] , $ this -> repository -> getFor ( $ key , $ ranges [ 0 ] ) ) ; } $ values = array ( ) ; foreach ( $ ranges as $ range ) { $ values [ ] = new RangeValue ( $ range , $ this -> repository -> getForRange ( $ key , $ range -> getStartDate ( ) , $ range -> getEndDate ( ) ) ) ; } return $ values ; } return null ; }
|
Return value for a given period .
|
17,096
|
public function has ( $ key , \ DatePeriod $ period = null ) { if ( is_null ( $ period ) ) { return new Exists ( $ this -> repository -> has ( $ key ) ) ; } return $ this -> hasForPeriod ( $ key , $ period ) ; }
|
Determine if value exists .
|
17,097
|
protected function hasForPeriod ( $ key , \ DatePeriod $ period ) { $ ranges = $ this -> getRanges ( $ period ) ; if ( count ( $ ranges ) > 0 ) { if ( count ( $ ranges ) == 1 && ! ( $ ranges [ 0 ] instanceof DateRange ) ) { return new DateExists ( $ ranges [ 0 ] , $ this -> repository -> hasFor ( $ key , $ ranges [ 0 ] ) ) ; } $ values = array ( ) ; foreach ( $ ranges as $ range ) { $ values [ ] = new RangeExists ( $ range , $ this -> repository -> hasForRange ( $ key , $ range -> getStartDate ( ) , $ range -> getEndDate ( ) ) ) ; } return $ values ; } return new Exists ( false ) ; }
|
Determine if value exists for given period .
|
17,098
|
public function increment ( $ key , $ value , \ DatePeriod $ period = null ) { if ( is_null ( $ period ) ) { $ this -> repository -> increment ( $ key , $ value ) ; } else { $ this -> incrementForPeriod ( $ key , $ value , $ period ) ; } }
|
Increment value .
|
17,099
|
protected function incrementForPeriod ( $ key , $ value , \ DatePeriod $ period ) { $ ranges = $ this -> getRanges ( $ period ) ; if ( count ( $ ranges ) > 0 ) { foreach ( $ ranges as $ range ) { $ range instanceof DateRange ? $ this -> repository -> incrementForRange ( $ key , $ range -> getStartDate ( ) , $ range -> getEndDate ( ) , $ value ) : $ this -> repository -> incrementFor ( $ key , $ range , $ value ) ; } } }
|
Increment value for a given period .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.