idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
4,200
|
protected function assertClass ( $ class ) { if ( ! preg_match ( '/^([a-zA-Z_]\w*\\\\)*[a-zA-Z_]\w*$/' , $ class ) ) { throw new \ UnexpectedValueException ( "Can't route to controller '$class': invalid classname" ) ; } if ( ! class_exists ( $ class ) ) { throw new \ UnexpectedValueException ( "Can't route to controller '$class': class not exists" ) ; } $ refl = new \ ReflectionClass ( $ class ) ; $ realClass = $ refl -> getName ( ) ; if ( $ realClass !== $ class ) { throw new \ UnexpectedValueException ( "Can't route to controller '$class': case mismatch with '$realClass'" ) ; } }
|
Assert that a class exists and will provide a callable object
|
4,201
|
protected function studlyCase ( $ string ) { return preg_replace_callback ( '/(?:^|(\w)-)(\w)/' , function ( $ match ) { return $ match [ 1 ] . strtoupper ( $ match [ 2 ] ) ; } , strtolower ( addcslashes ( $ string , '\\' ) ) ) ; }
|
Turn kabab - case into StudlyCase .
|
4,202
|
private function setYamlPath ( string $ yamlPath ) : void { $ chars = preg_quote ( ':._-\/\\\\' , '#' ) ; $ pattern = '#^[\w' . $ chars . ']+\.(yaml|yml)$#' ; if ( ! preg_match ( $ pattern , $ yamlPath ) ) { throw new ParserException ( 'Given path to YAML file is invalid' ) ; } $ givenPath = $ yamlPath ; $ yamlPath = realpath ( $ yamlPath ) ; if ( ! $ yamlPath ) { throw new ParserException ( sprintf ( 'YAML file "%s" not found in directory "%s"' , basename ( $ givenPath ) , dirname ( $ givenPath ) ) ) ; } $ this -> yamlPath = $ yamlPath ; $ this -> baseDirectory = dirname ( $ this -> yamlPath ) ; }
|
Validates path checks if starting Yaml file exists
|
4,203
|
public function setEOL ( string $ eol = PHP_EOL ) : self { if ( ! in_array ( $ eol , [ "\n" , "\r\n" ] ) ) { throw new ParserException ( 'Invalid EOL character' ) ; } $ this -> eolChar = $ eol ; return $ this ; }
|
Set EOL character
|
4,204
|
public function addUserAgentNormalizer ( WURFL_Request_UserAgentNormalizer_Interface $ normalizer ) { $ userAgentNormalizers = $ this -> _userAgentNormalizers ; $ userAgentNormalizers [ ] = $ normalizer ; return new WURFL_Request_UserAgentNormalizer ( $ userAgentNormalizers ) ; }
|
Adds a new UserAgent Normalizer to the chain
|
4,205
|
public function get ( $ key ) { $ items = Arr :: get ( $ this -> items , $ key ) ; return $ this -> firstOrAll ( $ items ) ; }
|
Get the resolved resource by key .
|
4,206
|
public static function Range ( int $ num , int $ from , int $ to ) : bool { return ( $ num >= $ from && $ num <= $ to ) ? true : false ; }
|
Check if specified number is with in specified range
|
4,207
|
private function surroundInDiv ( DOMNode $ element , $ class ) { $ div = $ this -> createElement ( 'div' ) ; $ div -> setAttribute ( 'class' , $ class ) ; $ div -> appendChild ( $ element ) ; return $ div ; }
|
Surround an element in a div with a given class
|
4,208
|
public static function forBindingClass ( $ typeName , $ bindingClass , Exception $ cause = null ) { return new static ( sprintf ( 'The type "%s" does accept bindings of class "%s".' , $ typeName , $ bindingClass ) , 0 , $ cause ) ; }
|
Creates a new exception .
|
4,209
|
public function addManagedCollections ( $ collections ) { if ( ! is_array ( $ collections ) ) { $ collections = array ( $ collections ) ; } $ this -> managedCollections = array_merge ( $ this -> managedCollections , $ collections ) ; return $ this ; }
|
function addManagedCollections .
|
4,210
|
public function shortenUrl ( $ url ) { if ( $ this -> getOptions ( ) -> getBitlyApiKey ( ) && $ this -> getOptions ( ) -> getBitlyUsername ( ) ) { $ client = new \ Zend \ Http \ Client ( $ this -> getOptions ( ) -> getBitlyUrl ( ) ) ; $ client -> setParameterGet ( array ( 'format' => 'json' , 'longUrl' => $ url , 'login' => $ this -> getOptions ( ) -> getBitlyUsername ( ) , 'apiKey' => $ this -> getOptions ( ) -> getBitlyApiKey ( ) , ) ) ; $ result = $ client -> send ( ) ; if ( $ result ) { $ jsonResult = \ Zend \ Json \ Json :: decode ( $ result -> getBody ( ) ) ; if ( $ jsonResult -> status_code == 200 ) { return $ jsonResult -> data -> url ; } } } return $ url ; }
|
This method call Bit . ly to shorten a given URL .
|
4,211
|
public function setValidationRules ( $ attr , $ validationRules = null ) { $ rules = is_array ( $ attr ) ? $ attr : [ $ attr => $ validationRules ] ; $ this -> validationRules = array_merge ( $ this -> validationRules , $ rules ) ; return $ this ; }
|
Set validation rules array
|
4,212
|
public static function create ( $ conn , Configuration $ config = null , EventManager $ eventManager = null ) { if ( null === $ config ) { $ config = new Configuration ( ) ; $ config -> setProxyDir ( __DIR__ . '/../Proxies' ) ; $ config -> setProxyNamespace ( 'Doctrine\Tests\Proxies' ) ; $ config -> setMetadataDriverImpl ( $ config -> newDefaultAnnotationDriver ( [ ] , true ) ) ; } if ( null === $ eventManager ) { $ eventManager = new EventManager ( ) ; } return new EntityManagerMock ( $ conn , $ config , $ eventManager ) ; }
|
Mock factory method to create an EntityManager .
|
4,213
|
public function has ( $ id ) { if ( $ this -> isSilverStripeServiceRequest ( $ id ) ) { return ( bool ) $ this -> getSilverStripeService ( $ id ) ; } else { return parent :: has ( $ id ) ; } }
|
Return true if the service requested is a SilverStripe service and it exists in the SS container
|
4,214
|
public function importString ( $ content , $ isMandatory = true ) { if ( empty ( $ content ) && $ isMandatory ) { throw new JsonException ( "Json content mandatory but none found." ) ; } $ this -> params = array ( ) ; if ( ! empty ( $ content ) ) { $ this -> params = @ json_decode ( $ content , true ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { throw new JsonException ( "Error parsing json content: '$content'. Error: " . json_last_error_msg ( ) ) ; } if ( null === $ this -> params ) { throw new JsonException ( "Error parsing json content: '$content'" ) ; } } return $ this -> params ; }
|
Import string json and parse
|
4,215
|
private function translatePathElement ( $ path , & $ paramsRef ) { $ dotPos = strpos ( $ path , '.' ) ; $ currPath = $ path ; if ( $ dotPos !== false ) { $ currPath = substr ( $ path , 0 , $ dotPos ) ; } if ( $ currPath == '*' ) { if ( $ dotPos !== false ) { $ newParamsRef = array ( ) ; foreach ( $ paramsRef as $ subArray ) { if ( is_array ( $ subArray ) ) { foreach ( $ subArray as $ key => $ value ) { if ( isset ( $ newParamsRef [ $ key ] ) ) { $ newParamsRef [ $ key ] [ ] = $ value ; } else { if ( is_array ( $ value ) ) { $ newParamsRef [ $ key ] = $ value ; } else { $ newParamsRef [ $ key ] = array ( $ value ) ; } } } } } return $ this -> translatePathElement ( substr ( $ path , $ dotPos + 1 ) , $ newParamsRef ) ; } else { return $ paramsRef ; } } if ( ( $ lbracktePos = strpos ( $ currPath , '[' ) ) !== false ) { $ subPath = substr ( $ currPath , 0 , $ lbracktePos ) ; $ index = intval ( substr ( $ currPath , $ lbracktePos + 1 , - 1 ) ) ; if ( isset ( $ paramsRef [ $ subPath ] ) && is_array ( $ paramsRef [ $ subPath ] ) && isset ( $ paramsRef [ $ subPath ] [ $ index ] ) ) { if ( $ dotPos === false ) { return $ paramsRef [ $ subPath ] [ $ index ] ; } else { return $ this -> translatePathElement ( substr ( $ path , $ dotPos + 1 ) , $ paramsRef [ $ subPath ] [ $ index ] ) ; } } } else { if ( isset ( $ paramsRef [ $ currPath ] ) ) { if ( $ dotPos === false ) { return $ paramsRef [ $ currPath ] ; } else { return $ this -> translatePathElement ( substr ( $ path , $ dotPos + 1 ) , $ paramsRef [ $ currPath ] ) ; } } } return null ; }
|
Traverse through params according to path . This is a recursive function .
|
4,216
|
public function getMandatoryParam ( $ path ) { $ this -> validatePath ( $ path ) ; $ value = $ this -> translatePathElement ( $ path , $ this -> params ) ; if ( null === $ value ) { throw new JsonException ( "Json mandatory param '$path' not found found." ) ; } return $ value ; }
|
Returns json key value or throws exception if key doesn t exist
|
4,217
|
public function hasParam ( $ path ) { $ this -> validatePath ( $ path ) ; $ value = $ this -> translatePathElement ( $ path , $ this -> params ) ; return ( null === $ value ) ? false : true ; }
|
Returns json true if path exists
|
4,218
|
public function getOptionalParam ( $ path , $ default = false ) { $ this -> validatePath ( $ path ) ; $ value = $ this -> translatePathElement ( $ path , $ this -> params ) ; if ( null === $ value ) { return ( null === $ default ) ? null : $ default ; } return $ value ; }
|
Returns json key value or false if key doesn t exist
|
4,219
|
public function sendSeries ( Series $ series ) { $ metrics = $ series -> getMetrics ( ) ; if ( empty ( $ metrics ) ) { throw new EmptySeriesException ( 'The series must contain metric data to send' ) ; } $ this -> send ( self :: ENDPOINT_SERIES . $ this -> getApiKey ( ) , $ series -> toArray ( ) ) ; return $ this ; }
|
Send a Series object to datadog
|
4,220
|
public function sendMetric ( Metric $ metric ) { $ points = $ metric -> getPoints ( ) ; if ( empty ( $ points ) ) { throw new EmptyMetricException ( 'The metric must contain points to send' ) ; } $ this -> sendSeries ( new Series ( $ metric ) ) ; return $ this ; }
|
Send a Metric object to datadog
|
4,221
|
public function metric ( $ name , array $ points , array $ options = array ( ) ) { return $ this -> sendMetric ( Factory :: buildMetric ( $ name , $ points , $ options ) ) ; }
|
Send metric data to datadog
|
4,222
|
public function event ( $ text , $ title = '' , array $ options = array ( ) ) { return $ this -> sendEvent ( Factory :: buildEvent ( $ text , $ title , $ options ) ) ; }
|
Send an event to datadog
|
4,223
|
public function sendEvent ( Event $ event ) { $ this -> send ( self :: ENDPOINT_EVENT . $ this -> getApiKey ( ) , $ event -> toArray ( ) ) ; return $ this ; }
|
Send an Event object to datadog
|
4,224
|
public function getContactData ( $ addressData , Contact $ contact = null ) { $ result = array ( ) ; if ( $ addressData && isset ( $ addressData [ 'firstName' ] ) && isset ( $ addressData [ 'lastName' ] ) ) { $ result [ 'firstName' ] = $ addressData [ 'firstName' ] ; $ result [ 'lastName' ] = $ addressData [ 'lastName' ] ; $ result [ 'fullName' ] = $ result [ 'firstName' ] . ' ' . $ result [ 'lastName' ] ; if ( isset ( $ addressData [ 'title' ] ) ) { $ result [ 'title' ] = $ addressData [ 'title' ] ; } if ( isset ( $ addressData [ 'salutation' ] ) ) { $ result [ 'salutation' ] = $ addressData [ 'salutation' ] ; } } elseif ( $ contact ) { $ result [ 'firstName' ] = $ contact -> getFirstName ( ) ; $ result [ 'lastName' ] = $ contact -> getLastName ( ) ; $ result [ 'fullName' ] = $ contact -> getFullName ( ) ; $ result [ 'salutation' ] = $ contact -> getFormOfAddress ( ) ; if ( $ contact -> getTitle ( ) !== null ) { $ result [ 'title' ] = $ contact -> getTitle ( ) -> getTitle ( ) ; } } else { throw new MissingAttributeException ( 'firstName, lastName or contact' ) ; } return $ result ; }
|
Returns contact data as an array . either by provided address or contact
|
4,225
|
public function addDatatableButtonExport ( $ text = 'Export CSV' ) { $ this -> hasToken ( ) ? : $ this -> generateToken ( ) ; $ this -> addDatatableButtonLink ( $ text , route ( 'datatable-export' , [ 'token' => $ this -> getToken ( ) ] ) ) ; return $ this ; }
|
Ajoute un Bouton d export
|
4,226
|
public function save ( ) { if ( ! $ this -> hasToken ( ) ) { if ( static :: hasSingleToken ( ) ) { $ this -> setToken ( static :: getSingleToken ( ) ) ; } else { $ this -> generateToken ( ) ; } } if ( ! $ this -> hasConstructor ( ) ) { $ this -> setConstructor ( static :: class ) ; } Session :: push ( $ this -> getToken ( ) , json_encode ( [ 'constructor' => $ this -> getConstructor ( ) ] ) ) ; return $ this ; }
|
Save the Table configuration in Session
|
4,227
|
static public function load ( $ token = null ) { if ( is_null ( $ token ) && static :: hasSingleToken ( ) ) { $ token = static :: getSingleToken ( ) ; } if ( ! Session :: has ( $ token ) ) { if ( static :: hasSingleToken ( ) ) { Session :: push ( $ token , json_encode ( [ 'constructor' => static :: class ] ) ) ; } else { throw new \ InvalidArgumentException ( 'Token "' . $ token . '" is not valid' ) ; } } $ config = Session :: get ( $ token ) ; $ config = json_decode ( $ config [ 0 ] , true ) ; $ constructor = $ config [ 'constructor' ] ; if ( preg_match ( '#(?<class>.+)::(?<method>.+)#' , $ constructor , $ match ) ) { $ method = $ match [ 'method' ] ; $ params = [ ] ; if ( preg_match ( '#(?<method>[^:]+):(?<params>.+)#' , $ method , $ params ) ) { $ method = $ params [ 'method' ] ; $ params = explode ( ',' , $ params [ 'params' ] ) ; } $ table = call_user_func_array ( [ $ match [ 'class' ] , $ method ] , $ params ) ; } else { $ instance = new \ ReflectionClass ( $ config -> constructor ) ; $ table = $ instance -> newInstance ( ) ; } if ( ! ( $ table instanceof static ) ) { throw new \ Exception ( 'Loaded instance is not viable' ) ; } return $ table ; }
|
Load a datable from a token
|
4,228
|
public function getRequestToken ( $ callback_uri = NULL ) { $ this -> getOauthPlugin ( ) -> setCallbackUri ( $ callback_uri ) ; $ response = $ this -> get ( $ this -> getConfig ( 'request_token_path' ) ) -> send ( ) ; $ request_token = array ( ) ; parse_str ( $ response -> getBody ( ) , $ request_token ) ; if ( ! isset ( $ request_token [ 'oauth_callback_confirmed' ] ) || ! in_array ( $ request_token [ 'oauth_callback_confirmed' ] , array ( true , "true" ) ) ) { throw new \ Exception ( "There was an error regarding the callback confirmation" ) ; } return $ request_token ; }
|
Get a Request Token .
|
4,229
|
public function getAuthorizeUrl ( $ request_token , $ callback_uri = NULL , $ state = NULL ) { $ request_token = array ( 'oauth_token' => is_array ( $ request_token ) ? $ request_token [ 'oauth_token' ] : $ request_token , ) ; $ url = Url :: factory ( $ this -> getConfig ( 'base_url' ) ) ; $ url -> addPath ( $ this -> getConfig ( 'authorize_path' ) ) ; $ url -> setQuery ( $ request_token ) ; return ( string ) $ url ; }
|
Return a authorize url .
|
4,230
|
public function set ( $ route ) { if ( $ route instanceof Group ) { foreach ( $ route -> all ( ) as $ r ) $ this -> routes [ ] = $ r ; } else $ this -> routes [ ] = $ route ; return $ this ; }
|
Set a new Route or merge an existing group of routes .
|
4,231
|
public function setMethod ( $ method ) { foreach ( $ this -> routes as $ route ) $ route -> setMethod ( $ method ) ; return $ this ; }
|
Set one HTTP method to all grouped routes .
|
4,232
|
public function setAction ( $ action ) { foreach ( $ this -> routes as $ route ) $ route -> setAction ( $ action ) ; return $ this ; }
|
Set one action to all grouped routes .
|
4,233
|
public function setPrefix ( $ prefix ) { $ prefix = "/" . ltrim ( $ prefix , "/" ) ; $ routes = [ ] ; foreach ( $ this -> routes as $ route ) $ routes [ ] = $ route -> setPattern ( rtrim ( $ prefix . $ route -> getPattern ( ) , "/" ) ) ; $ this -> routes = $ routes ; return $ this ; }
|
Add a prefix to all grouped routes pattern .
|
4,234
|
public function setMetadata ( $ key , $ value ) { foreach ( $ this -> routes as $ route ) $ route -> setMetadata ( $ key , $ value ) ; return $ this ; }
|
Set metadata to all grouped routes .
|
4,235
|
public function setMetadataArray ( array $ metadata ) { foreach ( $ this -> routes as $ route ) $ route -> setMetadataArray ( $ metadata ) ; return $ this ; }
|
Set a bunch of metadata to all grouped routes .
|
4,236
|
public function setDefaults ( array $ defaults ) { foreach ( $ this -> routes as $ route ) $ route -> setDefaults ( $ defaults ) ; return $ this ; }
|
Set default parameters to all grouped routes .
|
4,237
|
public function setDefault ( $ key , $ value ) { foreach ( $ this -> routes as $ route ) $ route -> setDefault ( $ key , $ value ) ; return $ this ; }
|
Set a default parameter to all grouped routes .
|
4,238
|
public function setStrategy ( $ strategy ) { foreach ( $ this -> routes as $ route ) $ route -> setStrategy ( $ strategy ) ; return $ this ; }
|
Set one dispatch strategy to all grouped routes .
|
4,239
|
public function setName ( $ name ) { if ( count ( $ this -> routes ) > 1 ) { throw new \ LogicException ( "You cannot set the same name to several routes." ) ; } $ this -> routes [ 0 ] -> setName ( $ name ) ; return $ this ; }
|
Set a name to a Route .
|
4,240
|
protected function determineIfModelIsSluggable ( ) { $ this -> context -> modelIsSluggable = false ; $ this -> context -> modelIsParentOfSluggableTranslation = false ; if ( $ this -> data [ 'sluggable' ] ) { if ( ! isset ( $ this -> data -> sluggable_setup [ 'translated' ] ) || ! $ this -> data -> sluggable_setup [ 'translated' ] || $ this -> data -> is_translation ) { $ this -> context -> modelIsSluggable = true ; } else { $ this -> context -> modelIsParentOfSluggableTranslation = true ; } } }
|
Determines and stores whether model itself is sluggable If so it will have both the trait and implement the interface
|
4,241
|
private function protect ( ) { if ( ! in_array ( $ this -> certificateType , self :: allAsString ( ) , true ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid certificate type %s' , $ this -> certificateType ) ) ; } }
|
Check if the certificateType exists in our list
|
4,242
|
protected function getBasePath ( string $ action ) : string { return sprintf ( 'project/%s/%s?key=%s' , $ this -> getProjectId ( ) , $ action , $ this -> getApiKey ( ) ) ; }
|
Get the base path for the command including an action .
|
4,243
|
public function getState ( ) { if ( empty ( $ this -> state ) ) { $ this -> state = \ Drupal :: service ( 'state' ) ; } return $ this -> state ; }
|
Gets the state storage .
|
4,244
|
public function merge ( $ headers ) { foreach ( $ headers as $ key => $ value ) { $ this -> set ( $ key , $ value ) ; } return $ this ; }
|
Merge actual headers with an array of headers
|
4,245
|
public function getFiltered ( $ page , $ numRows , $ sortAttr , $ sortOrder , $ searchAttr , $ searchValue , $ richFilters = [ ] ) { $ query = $ this -> prepareQuery ( ) ; $ query = $ this -> richFiltersOnQuery ( $ query , $ richFilters ) ; if ( $ sortAttr && $ sortOrder && $ this -> inScope ( $ sortAttr ) ) { $ scope = $ this -> getScope ( $ sortAttr ) ; $ query = $ query -> orderBy ( $ scope , $ sortOrder ) ; } if ( $ searchAttr && $ searchValue && $ this -> inScope ( $ searchAttr ) ) { $ scope = $ this -> getScope ( $ searchAttr ) ; $ query = $ query -> where ( $ scope , 'like' , '%' . $ searchValue . '%' ) ; } $ collection = $ query -> get ( ) ; $ collection = $ this -> addPermissions ( $ collection ) ; $ collection = $ this -> formatCollection ( $ collection ) ; $ collection = $ collection -> each ( function ( $ model ) { $ model = $ this -> formatModel ( $ model ) ; } ) ; if ( $ sortAttr && $ sortOrder && ! $ this -> inScope ( $ sortAttr ) ) { $ collection = $ sortOrder == 'asc' ? $ collection -> sortBy ( $ sortAttr ) : $ collection -> sortByDesc ( $ sortAttr ) ; } $ collection = $ this -> richFiltersOnCollection ( $ collection , $ richFilters ) ; if ( $ searchAttr && $ searchValue && ! $ this -> inScope ( $ searchAttr ) ) { $ collection = $ collection -> filter ( function ( $ model ) use ( $ searchAttr , $ searchValue ) { $ value = ( string ) $ model -> $ searchAttr ; $ value = strtolower ( $ value ) ; $ search = strtolower ( $ searchValue ) ; return strpos ( $ value , $ search ) !== false ; } ) ; } if ( $ page && $ numRows ) { $ toSkip = ( $ page - 1 ) * $ numRows ; $ count = $ collection -> count ( ) ; $ collection = $ collection -> take ( - ( $ count - $ toSkip ) ) -> take ( $ numRows ) ; } else if ( $ numRows ) $ collection = $ collection -> take ( $ numRows ) ; return collect ( array_values ( $ collection -> toArray ( ) ) ) ; }
|
Get filtered collection
|
4,246
|
public function countFiltered ( $ searchAttr , $ searchValue , $ richFilters ) { $ collection = $ this -> getFiltered ( null , null , null , null , $ searchAttr , $ searchValue , $ richFilters ) ; return count ( $ collection ) ; }
|
Count all rows with condition
|
4,247
|
public function addPermissions ( $ collection ) { $ newCollection = collect ( [ ] ) ; $ customActions = $ this -> crudeSetup -> getCustomActions ( ) ; $ collection -> each ( function ( $ model ) use ( $ newCollection , $ customActions ) { if ( $ this -> permissionView ( $ model ) ) { $ model = $ this -> addPermissionsForModel ( $ model , $ customActions ) ; $ newCollection -> push ( $ model ) ; } } ) ; return $ newCollection ; }
|
Filter collection by permissions and add attributes canBeEdited and canBeRemoved
|
4,248
|
public function dispatch ( $ dispatchable , $ resolutionType , $ dispatchSource , Request $ request , ... $ rest ) { return $ dispatchable ( $ request , ... $ rest ) ; }
|
Call the callable providing parameters and returning the returned value .
|
4,249
|
public function scanCollection ( $ collection , $ fields ) { $ fields = ( array ) $ fields ; foreach ( $ collection as $ item ) { $ this -> collectIdsFromItem ( $ item , $ fields ) ; } return $ this ; }
|
Add a collection source .
|
4,250
|
public function scanItem ( $ item , $ fields ) { $ fields = ( array ) $ fields ; $ this -> collectIdsFromItem ( $ item , $ fields ) ; return $ this ; }
|
Add an item source .
|
4,251
|
public function addIds ( $ ids ) { foreach ( $ ids as $ id ) { if ( ( int ) $ id ) { $ this -> ids [ ] = ( int ) $ id ; } } return $ this ; }
|
Add existeing ids array source .
|
4,252
|
protected function collectIdsFromField ( $ item , $ field ) { $ ids = Arr :: get ( $ item , $ field , [ ] ) ; return is_object ( $ ids ) && method_exists ( $ ids , 'toArray' ) ? $ ids -> toArray ( ) : ( array ) $ ids ; }
|
Collect ids from field of item
|
4,253
|
public function segments ( $ highway = NULL ) { if ( $ highway && isset ( $ this -> trafficData [ $ highway ] [ 'segments' ] ) ) { return array_keys ( $ this -> trafficData [ $ highway ] [ 'segments' ] ) ; } return null ; }
|
This function returns the list of segments in a given highway .
|
4,254
|
final private function getTrafficData ( $ feedUrl ) { $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ feedUrl ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; $ response = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; $ xml = simplexml_load_string ( $ response ) ; return $ this -> sanitizeTrafficData ( $ this -> parseTrafficData ( $ xml ) ) ; }
|
This function retrieves the traffic data from the MMDA Traffic API .
|
4,255
|
final private function parseTrafficData ( $ xml ) { $ traffic = [ ] ; foreach ( $ xml -> channel -> item as $ item ) { $ item = get_object_vars ( $ item ) ; $ title = $ item [ 'title' ] ; $ description = $ item [ 'description' ] ; $ pubDate = $ item [ 'pubDate' ] ; $ highway = explode ( '-' , $ title , 2 ) [ 0 ] ; $ segment = substr ( explode ( '-' , $ title , 2 ) [ 1 ] , 0 , - 3 ) ; $ direction = substr ( explode ( '-' , $ title , 2 ) [ 1 ] , - 2 ) ; if ( empty ( $ traffic [ $ highway ] ) ) $ traffic [ $ highway ] = [ ] ; if ( empty ( $ traffic [ $ highway ] [ $ segment ] ) ) $ traffic [ $ highway ] [ $ segment ] = [ ] ; $ traffic [ $ highway ] [ $ segment ] [ $ direction ] = $ description ; $ traffic [ $ highway ] [ $ segment ] [ 'pubDate' ] = $ pubDate ; } return $ traffic ; }
|
This function parses the XML response from the MMDA Traffic API into JSON .
|
4,256
|
final private function sanitizeTrafficData ( Array $ trafficData ) { $ traffic = [ ] ; foreach ( $ trafficData as $ highway => $ segments ) { $ traffic [ $ highway ] = [ 'name' => $ highway , 'label' => $ this -> convertToTitle ( $ highway ) , ] ; $ traffic [ $ highway ] [ 'segments' ] = [ ] ; $ dataSegments = [ ] ; foreach ( $ segments as $ segment => $ status ) { $ dataSegments [ $ segment ] = [ 'name' => $ segment , 'label' => $ this -> convertToTitle ( $ segment ) , 'status' => $ this -> convertToStatus ( $ status ) , ] ; $ traffic [ $ highway ] [ 'segments' ] = $ dataSegments ; } } return $ traffic ; }
|
This function sanitizes the traffic data and organizes them into an envelope
|
4,257
|
final private function convertToStatus ( Array $ data ) { $ statusMatrix = [ 'L' => 'Light' , 'ML' => 'Light to Moderate' , 'M' => 'Moderate' , 'MH' => 'Moderate to Heavy' , 'H' => 'Heavy' ] ; $ status = [ 'NB' => [ 'name' => $ data [ 'NB' ] , 'label' => $ statusMatrix [ $ data [ 'NB' ] ] . ' Traffic' , 'last_updated' => $ data [ 'pubDate' ] ] , 'SB' => [ 'name' => $ data [ 'SB' ] , 'label' => $ statusMatrix [ $ data [ 'SB' ] ] . ' Traffic' , 'last_updated' => $ data [ 'pubDate' ] ] ] ; return $ status ; }
|
This function converts traffic data status to readable format .
|
4,258
|
final private function convertToTitle ( $ string ) { $ string2 = [ ] ; $ string = str_replace ( [ '_' , 'AVE.' , 'BLVD.' ] , [ ' ' , 'AVENUE' , 'BOULEVARD' ] , $ string ) ; $ words = explode ( ' ' , $ string ) ; foreach ( $ words as $ word ) { if ( ! in_array ( $ word , [ 'EDSA' , 'U.N.' ] ) ) { $ word = ucwords ( mb_strtolower ( $ word ) ) ; } array_push ( $ string2 , $ word ) ; } return implode ( ' ' , $ string2 ) ; }
|
This function sanitizes certain abbreviations into readable format .
|
4,259
|
public function findByRecId ( $ recId ) { if ( empty ( $ recId ) ) { throw new \ Exception ( 'No record ID specified' ) ; } $ this -> primeCommandArray ( ) ; $ this -> addToCommandArray ( [ '-recid' => $ recId ] ) ; $ this -> addToCommandArray ( [ '-find' => null ] ) ; return $ this ; }
|
Find a record based on it s internal FileMaker record ID
|
4,260
|
public function createRecord ( $ data ) { $ this -> primeCommandArray ( ) ; $ this -> addToCommandArray ( $ data ) ; $ this -> addToCommandArray ( [ '-new' => null ] ) ; return $ this ; }
|
Create a new record and populate it with data .
|
4,261
|
public function updateRecord ( $ recId , $ data ) { if ( empty ( $ recId ) ) { throw new \ Exception ( 'No record ID specified' ) ; } $ this -> primeCommandArray ( ) ; $ this -> addToCommandArray ( $ data ) ; $ this -> addToCommandArray ( [ '-recid' => $ recId ] ) ; $ this -> addToCommandArray ( [ '-edit' => null ] ) ; return $ this ; }
|
Update data in an existing record per it s internal FileMaker record ID .
|
4,262
|
public function deleteRecord ( $ recId ) { if ( empty ( $ recId ) ) { throw new \ Exception ( 'No record ID specified' ) ; } $ this -> primeCommandArray ( ) ; $ this -> addToCommandArray ( [ '-recid' => $ recId ] ) ; $ this -> addToCommandArray ( [ '-delete' => null ] ) ; return $ this ; }
|
Delete a record per it s internal FileMaker record ID .
|
4,263
|
protected function createDocumentManager ( ) { AnnotationDriver :: registerAnnotationClasses ( ) ; $ configuration = new Configuration ( ) ; $ configuration -> setProxyDir ( $ this -> configuration [ 'doctrine' ] [ 'proxyDir' ] ) ; $ configuration -> setProxyNamespace ( $ this -> configuration [ 'doctrine' ] [ 'proxyNamespace' ] ) ; $ configuration -> setHydratorDir ( $ this -> configuration [ 'doctrine' ] [ 'hydratorDir' ] ) ; $ configuration -> setHydratorNamespace ( $ this -> configuration [ 'doctrine' ] [ 'hydratorNamespace' ] ) ; $ configuration -> setMetadataDriverImpl ( AnnotationDriver :: create ( ) ) ; return DocumentManager :: create ( new Connection ( $ this -> configuration [ 'doctrine' ] [ 'connection' ] [ 'server' ] ) , $ configuration ) ; }
|
Creates the doctrine document mananger for working on the database
|
4,264
|
protected function initPromises ( $ promisesTrait ) { return $ promisesTrait -> findOne ( $ this -> createFindOneClosure ( ) ) -> findMany ( $ this -> createFindManyClosure ( ) ) -> renderResult ( $ this -> createRenderResultClosure ( ) ) -> allowRequest ( $ this -> createAllowRequestClosure ( ) ) ; }
|
Method for initializing a PromisesTrait object with the Closures
|
4,265
|
protected function createHttpException ( $ code , $ message = null ) { if ( $ code == 404 ) { $ message = 'Entity not found' ; } $ exception = new HttpException ( $ message , $ code ) ; return $ exception ; }
|
Helper method for creating HTTP exceptions
|
4,266
|
public function resource ( $ className , $ settings = [ ] ) { $ resource = $ this -> initPromises ( Resource :: create ( $ className , $ settings , $ this ) ) ; foreach ( $ resource -> settings [ 'actions' ] as $ action => $ actionSettings ) { $ methodName = "setup$action" ; if ( method_exists ( $ this , $ methodName ) ) { $ this -> { $ methodName } ( $ resource ) ; } } return $ resource ; }
|
The second most important method . Will create RESTful routes for MongoDB model .
|
4,267
|
public function api ( $ request = null , $ response = null , $ sendResponse = true ) { $ this -> klein -> respond ( 'POST' , '/authenticate' , $ this -> authenticate ) ; $ this -> klein -> onHttpError ( $ this -> handleError ) ; if ( $ request === null ) $ request = Request :: createFromGlobals ( ) ; $ uri = $ request -> server ( ) -> get ( 'REQUEST_URI' ) ; $ request -> server ( ) -> set ( 'REQUEST_URI' , '/' . substr ( $ uri , strlen ( $ this -> configuration [ 'basePath' ] ) ) ) ; $ this -> klein -> dispatch ( $ request , $ response , $ sendResponse ) ; }
|
The most important method . Will start the hive engine and listening for requests .
|
4,268
|
private function getFlexLocale ( $ language ) { if ( ! empty ( $ language ) ) { $ split = explode ( "-" , $ language , 2 ) ; if ( count ( $ split ) == 2 && $ split [ 1 ] != "" ) { $ split [ 1 ] = strtoupper ( $ split [ 1 ] ) ; } else { $ split = null ; } } if ( empty ( $ split ) ) $ split = [ 'en' , 'US' ] ; return $ split [ 0 ] . self :: LANGUAGUE_SEPARATOR . $ split [ 1 ] ; }
|
Returns locale with format for flex application
|
4,269
|
protected function assertPayload ( $ aPayload = null ) { if ( ! array_key_exists ( 'enabled' , $ aPayload ) || ! array_key_exists ( 'interval' , $ aPayload ) ) { throw new \ InvalidArgumentException ( 'Payload does not contain a enabled or interval key' ) ; } if ( ! is_bool ( $ aPayload [ 'enabled' ] ) ) throw new \ InvalidArgumentException ( 'Enabled flag must be a boolean value' ) ; if ( ! is_int ( $ aPayload [ 'interval' ] ) ) throw new \ InvalidArgumentException ( 'Ticker interval must be an integer' ) ; }
|
Assert that payload contains all required information for this command
|
4,270
|
public function renderLabel ( $ content , $ class = '' , $ style = '' ) { $ styleAttr = ( $ style ) ? ' style="' . $ style . '"' : '' ; $ classes = ( $ class ) ? ' ' . $ class : '' ; $ renderLabel = '' ; $ renderLabel .= '<span class="fs-label' . $ classes . '"' . $ style . '>' ; $ renderLabel .= $ content ; $ renderLabel .= '</span>' ; return $ renderLabel ; }
|
Returns a label .
|
4,271
|
public function renderSeparator ( $ bold = true , $ class = '' , $ style = '' ) { $ styleAttr = ( $ style ) ? ' style="' . $ style . '"' : '' ; $ classes = ( $ class ) ? ' ' . $ class : '' ; if ( $ bold ) { return '<hr class="fs-hr' . $ classes . '"' . $ styleAttr . '>' ; } else { return '<hr class="fs-hr-dotted' . $ classes . '"' . $ styleAttr . '>' ; } }
|
Returns a separator .
|
4,272
|
public function renderTrace ( $ debug_backtrace ) { $ renderTrace = '' ; $ renderTrace .= '<span class="fs-label">' ; foreach ( $ debug_backtrace as $ index => $ trace ) { $ renderTrace .= '#' . $ index . ' ' ; if ( ! empty ( $ trace [ 'file' ] ) ) { $ renderTrace .= $ trace [ 'file' ] ; } if ( ! empty ( $ trace [ 'line' ] ) ) { $ renderTrace .= '(' . $ trace [ 'line' ] . ') ' ; } if ( ! empty ( $ trace [ 'class' ] ) ) { $ renderTrace .= $ trace [ 'class' ] . '::' ; } $ renderTrace .= $ trace [ 'function' ] . '()' . '<br>' ; } $ renderTrace .= '</span>' ; return $ renderTrace ; }
|
Returns a rendered debug_backtrace .
|
4,273
|
public function fetch ( $ query ) { $ result = $ this -> query ( $ query ) ; return $ result -> fetch ( \ PDO :: FETCH_ASSOC ) ; }
|
Return associate array with all data of one row in table
|
4,274
|
protected function addFields ( $ fields ) { $ fields_array = [ ] ; foreach ( $ fields as $ field => $ value ) { $ fields_array [ ] = $ field ; } return '`' . implode ( '`, `' , $ fields_array ) . '`' ; }
|
Generates a set of fields that need to be updated or inserted . For the terms INSERT INTO .
|
4,275
|
protected function _addValue ( $ values ) { $ method = $ this -> getSaveMode ( ) ; $ value_array = [ ] ; foreach ( $ values as $ key => $ value ) { $ value_array [ ] = $ this -> $ method ( $ key , $ value ) ; } return implode ( ',' , $ value_array ) ; }
|
Handles one - dimensional array of data and generates a set for one group .
|
4,276
|
protected function getSluggableConfigReplace ( ) { $ setup = $ this -> data -> sluggable_setup ; if ( ! $ this -> context -> modelIsSluggable || ! $ this -> data -> sluggable || empty ( $ setup ) ) return '' ; $ replace = $ this -> tab ( ) . "protected \$sluggable = [\n" ; $ rows = [ ] ; if ( array_get ( $ setup , 'source' ) ) { $ rows [ 'build_from' ] = "'" . $ setup [ 'source' ] . "'" ; } if ( array_get ( $ setup , 'target' ) ) { $ rows [ 'save_to' ] = "'" . $ setup [ 'target' ] . "'" ; } if ( config ( 'pxlcms.generator.models.slugs.resluggify_on_update' ) ) { $ rows [ 'on_update' ] = 'true' ; } if ( array_get ( $ setup , 'translated' ) === true ) { $ rows [ 'language_key' ] = "'" . config ( 'pxlcms.slugs.keys.language' , 'language_id' ) . "'" ; $ rows [ 'locale_key' ] = 'null' ; } $ longestPropertyLength = $ this -> getLongestKey ( $ rows ) ; foreach ( $ rows as $ property => $ value ) { $ replace .= $ this -> tab ( 2 ) . "'" . str_pad ( $ property . "'" , $ longestPropertyLength + 1 ) . " => {$value},\n" ; } $ replace .= $ this -> tab ( ) . "];\n\n" ; return $ replace ; }
|
Returns the replacement for the sluggable config placeholder
|
4,277
|
public static function meatOnBones ( Event $ event ) { $ basePath = realpath ( "." ) ; $ handler = new ComposerHydrationHandler ( $ event , $ basePath ) ; $ handler -> hydrate ( ) ; }
|
Composer callback method for Hydration process .
|
4,278
|
public function setSelectors ( $ selectors ) { $ this -> selectors = [ ] ; if ( ! is_array ( $ selectors ) ) { $ selectors = [ $ selectors ] ; } foreach ( $ selectors as $ selector ) { $ this -> addSelector ( $ selector ) ; } return $ this ; }
|
Sets the selectors for the style rule .
|
4,279
|
protected function parseRuleString ( $ ruleString ) { foreach ( $ this -> getSelectorStrings ( $ ruleString ) as $ selectorString ) { if ( $ selectorString === "" ) { $ this -> setIsValid ( false ) ; $ this -> addValidationError ( "Invalid selector at '$ruleString'." ) ; break ; } $ this -> addSelector ( new StyleSelector ( $ selectorString , $ this -> getStyleSheet ( ) ) ) ; } }
|
Parses the selector rule .
|
4,280
|
public function createFromTokens ( array $ tokens ) { $ buffer = $ this -> delimiter . '^' ; foreach ( $ tokens as $ token ) { $ buffer .= $ this -> translateToken ( $ token ) ; } $ buffer .= '$' . $ this -> delimiter . $ this -> modifiers ; return $ buffer ; }
|
Creates a regular expression based on the supplied tokens . This return expression will be wrapped by the value of the delimiter property and the modifiers contained within the modifiers property will be appended to the end .
|
4,281
|
protected function translateToken ( array $ token ) { $ identifier = is_string ( $ token [ 0 ] ) ? null : $ token [ 0 ] ; $ value = $ token [ 2 ] ; $ result = $ this -> translateTokenFromIdentifier ( $ identifier , $ value ) ; if ( $ result === null ) { throw new BuildException ( sprintf ( 'No available translation for "%s"' , $ value ) ) ; } return $ result ; }
|
Translates a token into an appropriate regular expression construct . Various map directly to the same values ; others require some massaging and escaping to make them valid within the constructed in the regular expression .
|
4,282
|
protected function translateTokenFromIdentifier ( $ identifier , $ value ) { $ result = null ; if ( array_key_exists ( $ identifier , self :: $ tokenValueMap ) ) { $ result = $ this -> translateTokenUsingMap ( $ identifier ) ; } elseif ( array_key_exists ( $ identifier , self :: $ tokenCallbackMap ) ) { $ result = $ this -> translateTokenUsingCallback ( $ identifier , $ value ) ; } return $ result ; }
|
Translates a token based on the identifier flavour .
|
4,283
|
protected function translateTokenUsingCallback ( $ identifier , $ value ) { $ method = self :: $ tokenCallbackMap [ $ identifier ] ; return call_user_func ( [ $ this , $ method ] , $ value ) ; }
|
Calls an internal method to retrieve an appropriate value for use within the regex .
|
4,284
|
protected function closeOutputBuffers ( int $ targetLevel = 0 , bool $ flush = false ) : void { $ status = ob_get_status ( true ) ; $ level = \ count ( $ status ) ; while ( $ level -- > $ targetLevel ) { $ flush ? ob_end_flush ( ) : ob_end_clean ( ) ; } }
|
Cleans or flushes output buffers up to target level . Resulting level can be greater than target level if a non - removable buffer has been encountered .
|
4,285
|
public function getrenderer ( ) { if ( empty ( $ this -> renderer ) ) { $ this -> renderer = \ Drupal :: service ( 'renderer' ) ; } return $ this -> renderer ; }
|
Gets the renderer .
|
4,286
|
protected function describe ( ) { if ( is_null ( $ this -> _tableName ) == false ) { $ this -> _query = 'DESCRIBE ' . $ this -> _tableName ; if ( $ this -> _db -> execute ( $ this -> _query ) !== false ) { $ res = $ this -> _db -> getAllRows ( ) ; unset ( $ this -> _fields ) ; unset ( $ this -> _primaryKey ) ; $ this -> _fields = array ( ) ; foreach ( $ res as $ r ) { $ this -> _fields [ ] = $ r [ 'Field' ] ; if ( $ r [ 'Key' ] == 'PRI' ) $ this -> _primaryKey = $ r [ 'Field' ] ; } return true ; } } return false ; }
|
for now this method is intended just for tables with one primary key
|
4,287
|
public function insert ( $ data ) { unset ( $ this -> _error ) ; if ( is_array ( $ data ) ) { $ fields = '' ; $ values = '' ; reset ( $ data ) ; for ( $ counter = 0 , $ maxIndex = count ( $ data ) , $ valid = true ; $ counter < $ maxIndex && $ valid == true ; $ counter ++ ) { $ elementKey = key ( $ data ) ; $ elementKey = $ this -> _db -> escape ( $ elementKey ) ; $ valid = in_array ( $ elementKey , $ this -> _fields ) ; if ( $ valid == true ) { $ element = $ data [ $ elementKey ] ; $ element = $ this -> _db -> escape ( $ element ) ; if ( is_object ( $ element ) == true ) { $ valid = false ; $ this -> _error = 'field: ' . $ elementKey . 'is an object (this method just accept strings)' ; } else { if ( is_numeric ( $ element ) == false ) $ values .= '\'' . $ element . '\'' ; else $ values .= $ element ; $ fields .= $ elementKey ; if ( ( $ counter + 1 ) < $ maxIndex ) { $ fields .= ',' ; $ values .= ',' ; } next ( $ data ) ; } } else { $ this -> _error = 'field: ' . $ elementKey . ' is not defined in ' . $ this -> _tableName ; } } if ( $ valid == true ) { $ this -> _query = 'INSERT INTO ' . $ this -> _tableName . '(' . $ fields . ') VALUES(' . $ values . ')' ; if ( $ this -> _db -> execute ( $ this -> _query ) !== false ) { return $ this -> _db -> insertId ( ) ; } else { $ this -> _error = $ this -> _db -> errorStr ( ) ; } } } return false ; }
|
data is an associative array containing the name of the field and its value
|
4,288
|
public function incrementTimer ( $ name , $ time ) { if ( ! isset ( $ this -> timers [ $ name ] ) ) { $ this -> timers [ $ name ] = 0 ; } $ this -> timers [ $ name ] += $ this -> getTime ( ) - $ time ; }
|
Increments named timer .
|
4,289
|
public function setVendorPrefix ( $ vendorPrefix ) { if ( is_string ( $ vendorPrefix ) ) { $ this -> vendorPrefix = $ vendorPrefix ; } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ vendorPrefix ) . "' for argument 'vendorPrefix' given." ) ; } }
|
Sets the vendor prefix .
|
4,290
|
public static function getVendorPrefixRegExp ( $ delimiter = null ) { $ vendorPrefixValues = self :: getVendorPrefixValues ( ) ; foreach ( $ vendorPrefixValues as $ vendorPrefixKey => $ vendorPrefixValue ) { $ vendorPrefixValues [ $ vendorPrefixKey ] = preg_quote ( $ vendorPrefixValue , $ delimiter ) ; } return implode ( '|' , $ vendorPrefixValues ) ; }
|
Returns a partial regular expression of known vendor prefixes .
|
4,291
|
public function count ( $ filters = [ ] , $ options = [ ] ) { return $ this -> collection -> count ( $ this -> castQuery ( $ filters ) , $ options ) ; }
|
Count corresponding documents for filters
|
4,292
|
public function distinct ( $ fieldName , $ filters = [ ] , $ options = [ ] ) { $ field = $ fieldName ; $ propInfos = $ this -> classMetadata -> getPropertyInfoForField ( $ fieldName ) ; if ( ! $ propInfos ) { $ propInfos = $ this -> classMetadata -> getPropertyInfo ( $ fieldName ) ; } if ( isset ( $ propInfos ) ) { $ field = $ propInfos -> getField ( ) ; if ( $ propInfos -> getMetadata ( ) ) { $ field = "metadata." . $ field ; } } $ filters = $ this -> castQuery ( $ filters ) ; $ result = $ this -> collection -> distinct ( $ field , $ filters , $ options ) ; return $ result ; }
|
Get distinct value for a field
|
4,293
|
public function findAll ( $ projections = [ ] , $ sorts = [ ] , $ options = [ ] ) { $ options = $ this -> createOption ( $ projections , $ sorts , $ options ) ; $ result = $ this -> collection -> find ( [ ] , $ options ) ; if ( ! isset ( $ options [ 'iterator' ] ) || $ options [ 'iterator' ] === false ) { $ objects = [ ] ; foreach ( $ result as $ datas ) { if ( null != ( $ object = $ this -> createObject ( $ datas , $ options ) ) ) { $ objects [ ] = $ object ; } } return $ objects ; } else { $ iteratorClass = $ options [ 'iterator' ] ; $ iterator = $ iteratorClass === true ? new DocumentIterator ( $ result , $ this -> modelName , $ this ) : new $ iteratorClass ( $ result , $ this -> modelName , $ this ) ; if ( isset ( $ options [ 'readOnly' ] ) && $ options [ 'readOnly' ] == true ) { $ iterator -> readOnly ( ) ; } return $ iterator ; } }
|
Find all document of the collection
|
4,294
|
public function findAndModifyOneBy ( $ filters = [ ] , $ update = [ ] , $ projections = [ ] , $ sorts = [ ] , $ options = [ ] ) { $ options = $ this -> createOption ( $ projections , $ sorts , $ options ) ; $ filters = $ this -> castQuery ( $ filters ) ; $ update = $ this -> castQuery ( $ update ) ; $ result = ( array ) $ this -> collection -> findOneAndUpdate ( $ filters , $ update , $ options ) ; return $ this -> createObject ( $ result , $ options ) ; }
|
Find a document and make specified update on it
|
4,295
|
public function getTailableCursor ( $ filters = [ ] , $ options = [ ] ) { $ options [ 'cursorType' ] = \ MongoDB \ Operation \ Find :: TAILABLE_AWAIT ; return $ this -> collection -> find ( $ this -> castQuery ( $ filters ) , $ options ) ; }
|
Get tailable cursor for query
|
4,296
|
public function insertOne ( $ document , $ options = [ ] ) { $ query = new InsertOne ( $ this -> documentManager , $ this , $ document , $ options ) ; if ( isset ( $ options [ 'getQuery' ] ) && $ options [ 'getQuery' ] ) { return $ query ; } else { return $ query -> execute ( ) ; } }
|
Insert a document in collection
|
4,297
|
public function insertMany ( $ documents , $ options = [ ] ) { $ insertQuery = [ ] ; foreach ( $ documents as $ document ) { $ this -> classMetadata -> getEventManager ( ) -> execute ( EventManager :: EVENT_PRE_INSERT , $ document ) ; $ query = $ this -> hydrator -> unhydrate ( $ document ) ; $ idGen = $ this -> classMetadata -> getIdGenerator ( ) ; if ( $ idGen !== null ) { if ( ! class_exists ( $ idGen ) || ! is_subclass_of ( $ idGen , AbstractIdGenerator :: class ) ) { throw new \ Exception ( 'Bad ID generator : class \'' . $ idGen . '\' not exists or not extends JPC\MongoDB\ODM\Id\AbstractIdGenerator' ) ; } $ generator = new $ idGen ( ) ; $ query [ '_id' ] = $ generator -> generate ( $ this -> documentManager , $ document ) ; } $ insertQuery [ ] = $ query ; } $ result = $ this -> collection -> insertMany ( $ insertQuery , $ options ) ; if ( $ result -> isAcknowledged ( ) ) { foreach ( $ result -> getInsertedIds ( ) as $ key => $ id ) { if ( $ id instanceof \ stdClass ) { $ id = ( array ) $ id ; } $ insertQuery [ $ key ] [ "_id" ] = $ id ; $ this -> hydrator -> hydrate ( $ documents [ $ key ] , $ insertQuery [ $ key ] ) ; $ this -> classMetadata -> getEventManager ( ) -> execute ( EventManager :: EVENT_POST_INSERT , $ documents [ $ key ] ) ; $ this -> cacheObject ( $ documents [ $ key ] ) ; } return true ; } else { foreach ( $ documents as $ document ) { $ this -> cacheObject ( $ document ) ; } return false ; } }
|
Insert multiple documents in collection
|
4,298
|
public function updateMany ( $ filters , $ update , $ options = [ ] ) { $ result = $ this -> collection -> updateMany ( $ this -> castQuery ( $ filters ) , $ update , $ options ) ; if ( $ result -> isAcknowledged ( ) ) { return true ; } else { return false ; } }
|
Update many document
|
4,299
|
public function deleteMany ( $ filter , $ options = [ ] ) { $ filter = $ this -> castQuery ( $ filter ) ; $ result = $ this -> collection -> deleteMany ( $ filter , $ options ) ; if ( $ result -> isAcknowledged ( ) ) { return true ; } else { return false ; } }
|
Delete many document
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.