idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
300
public static function forMethod ( string $ class , string $ method , array $ classParameters = [ ] , array $ methodParameters = [ ] ) : RouteMatch { try { $ controller = new \ ReflectionMethod ( $ class , $ method ) ; } catch ( \ ReflectionException $ e ) { throw RoutingException :: invalidControllerClassMethod ( $ e , $ class , $ method ) ; } return new RouteMatch ( $ controller , $ classParameters , $ methodParameters ) ; }
Returns a RouteMatch for the given class and method .
301
public static function forFunction ( $ function , array $ functionParameters = [ ] ) : RouteMatch { try { $ controller = new \ ReflectionFunction ( $ function ) ; } catch ( \ ReflectionException $ e ) { throw RoutingException :: invalidControllerFunction ( $ e , $ function ) ; } return new self ( $ controller , [ ] , $ functionParameters ) ; }
Returns a RouteMatch for the given function or closure .
302
public function withClassParameters ( array $ parameters ) : RouteMatch { $ routeMatch = clone $ this ; $ routeMatch -> classParameters = $ parameters + $ this -> classParameters ; return $ routeMatch ; }
Returns a copy of this RouteMatch with additional class parameters .
303
public function withFunctionParameters ( array $ parameters ) : RouteMatch { $ routeMatch = clone $ this ; $ routeMatch -> functionParameters = $ parameters + $ this -> functionParameters ; return $ routeMatch ; }
Returns a copy of this RouteMatch with additional function parameters .
304
protected function getConfigFromInput ( ) { $ config_file_parse [ 'separator' ] = $ this -> form_input [ 'separator' ] ; $ config_file_parse [ 'file_path' ] = $ this -> form_input [ 'file_csv' ] -> getRealPath ( ) ; $ config [ "file_parse" ] = $ config_file_parse ; $ config_builder [ 'first_line_headers' ] = ( $ this -> form_input [ 'headers' ] != '' ) ; $ config [ "builder" ] = $ config_builder ; $ config_model = array ( ) ; $ config [ "model" ] = $ config_model ; return $ config ; }
get the config from form input
305
private function assertValidClientID ( $ value , $ fromPacket ) { if ( strlen ( $ value ) > 23 ) { $ this -> throwException ( sprintf ( 'Expected client id shorter than 24 bytes but got "%s".' , $ value ) , $ fromPacket ) ; } if ( $ value !== '' && ! ctype_alnum ( $ value ) ) { $ this -> throwException ( sprintf ( 'Expected a client id containing characters 0-9, a-z or A-Z but got "%s".' , $ value ) , $ fromPacket ) ; } }
Asserts that a client id is shorter than 24 bytes and only contains characters 0 - 9 a - z or A - Z .
306
public function fill ( array $ input , bool $ force = false ) { foreach ( $ input as $ key => $ value ) { if ( $ force ) { $ this -> setAttribute ( $ key , $ value ) ; continue ; } if ( ( empty ( $ this -> fillable ) || in_array ( $ key , $ this -> fillable ) ) && ! in_array ( $ key , $ this -> guarded ) ) { $ this -> setAttribute ( $ key , $ value ) ; } } }
Set the model attributes using an array .
307
protected function hasMutatorMethod ( $ key , $ prefix ) { $ method = $ this -> buildMutatorMethod ( $ key , $ prefix ) ; return method_exists ( $ this , $ method ) ; }
Verify if model has a mutator method defined .
308
private function handleHttpException ( HttpException $ exception , Request $ request ) : Response { $ response = new Response ( ) ; $ response -> setContent ( $ exception ) ; $ response -> setStatusCode ( $ exception -> getStatusCode ( ) ) ; $ response -> setHeaders ( $ exception -> getHeaders ( ) ) ; $ response -> setHeader ( 'Content-Type' , 'text/plain' ) ; $ event = new ExceptionCaughtEvent ( $ exception , $ request , $ response ) ; $ this -> eventDispatcher -> dispatch ( ExceptionCaughtEvent :: class , $ event ) ; return $ response ; }
Converts an HttpException to a Response .
309
private function handleUncaughtException ( \ Throwable $ exception , Request $ request ) : Response { $ httpException = new HttpInternalServerErrorException ( 'Uncaught exception' , $ exception ) ; return $ this -> handleHttpException ( $ httpException , $ request ) ; }
Wraps an uncaught exception in an HttpInternalServerErrorException and converts it to a Response .
310
private function route ( Request $ request ) : RouteMatch { foreach ( $ this -> routes as $ route ) { try { $ match = $ route -> match ( $ request ) ; } catch ( RoutingException $ e ) { throw new HttpNotFoundException ( $ e -> getMessage ( ) , $ e ) ; } if ( $ match !== null ) { if ( $ match instanceof RouteMatch ) { return $ match ; } throw $ this -> invalidReturnValue ( 'route' , Route :: class . ' or NULL' , $ match ) ; } } throw new HttpNotFoundException ( 'No route matches the request.' ) ; }
Routes the given Request .
311
public static function nameCase ( $ string = '' , array $ options = [ ] ) { if ( $ string == '' ) return $ string ; self :: $ options = array_merge ( self :: $ options , $ options ) ; if ( self :: $ options [ 'lazy' ] && self :: skipMixed ( $ string ) ) return $ string ; $ string = self :: capitalize ( $ string ) ; $ string = self :: updateIrish ( $ string ) ; foreach ( self :: $ replacements as $ pattern => $ replacement ) { $ string = mb_ereg_replace ( $ pattern , $ replacement , $ string ) ; } $ string = self :: updateRoman ( $ string ) ; $ string = self :: fixConjunction ( $ string ) ; return $ string ; }
Main function for NameCase .
312
private static function capitalize ( $ string ) { $ string = mb_strtolower ( $ string ) ; $ string = mb_ereg_replace_callback ( '\b\w' , function ( $ matches ) { return mb_strtoupper ( $ matches [ 0 ] ) ; } , $ string ) ; $ string = mb_ereg_replace_callback ( '\'\w\b' , function ( $ matches ) { return mb_strtolower ( $ matches [ 0 ] ) ; } , $ string ) ; return $ string ; }
Capitalize first letters .
313
private static function skipMixed ( $ string ) { $ firstLetterLower = $ string [ 0 ] == mb_strtolower ( $ string [ 0 ] ) ; $ allLowerOrUpper = ( mb_strtolower ( $ string ) == $ string || mb_strtoupper ( $ string ) == $ string ) ; return ! ( $ firstLetterLower || $ allLowerOrUpper ) ; }
Skip if string is mixed case .
314
private static function updateIrish ( $ string ) { if ( ! self :: $ options [ 'irish' ] ) return $ string ; if ( mb_ereg_match ( '.*?\bMac[A-Za-z]{2,}[^aciozj]\b' , $ string ) || mb_ereg_match ( '.*?\bMc' , $ string ) ) { $ string = self :: updateMac ( $ string ) ; } return mb_ereg_replace ( 'Macmurdo' , 'MacMurdo' , $ string ) ; }
Update for Irish names .
315
private static function fixConjunction ( $ string ) { if ( ! self :: $ options [ 'spanish' ] ) return $ string ; foreach ( self :: $ conjunctions as $ conjunction ) { $ string = mb_ereg_replace ( '\b' . $ conjunction . '\b' , mb_strtolower ( $ conjunction ) , $ string ) ; } return $ string ; }
Fix Spanish conjunctions .
316
private static function updateMac ( $ string ) { $ string = mb_ereg_replace_callback ( '\b(Ma?c)([A-Za-z]+)' , function ( $ matches ) { return $ matches [ 1 ] . mb_strtoupper ( mb_substr ( $ matches [ 2 ] , 0 , 1 ) ) . mb_substr ( $ matches [ 2 ] , 1 ) ; } , $ string ) ; foreach ( self :: $ exceptions as $ pattern => $ replacement ) { $ string = mb_ereg_replace ( $ pattern , $ replacement , $ string ) ; } return $ string ; }
Updates irish Mac & Mc .
317
public function reduce ( $ tolerance ) { $ this -> points = $ this -> _reduce ( $ this -> points , ( double ) $ tolerance ) ; return $ this -> points ; }
Public visible method to reduce points .
318
private function _reduce ( $ points , $ tolerance ) { $ distanceMax = $ index = 0 ; $ pointsEnd = key ( array_slice ( $ points , - 1 , 1 , true ) ) ; for ( $ i = 1 ; $ i < $ pointsEnd ; $ i ++ ) { $ distance = $ this -> shortestDistanceToSegment ( $ points [ $ i ] , $ points [ 0 ] , $ points [ $ pointsEnd ] ) ; if ( $ distance > $ distanceMax ) { $ index = $ i ; $ distanceMax = $ distance ; } } if ( $ distanceMax > $ tolerance ) { $ firstHalf = $ this -> _reduce ( array_slice ( $ points , 0 , $ index + 1 ) , $ tolerance ) ; $ secondHalf = $ this -> _reduce ( array_slice ( $ points , $ index ) , $ tolerance ) ; array_shift ( $ secondHalf ) ; $ points = array_merge ( $ firstHalf , $ secondHalf ) ; } else { $ points = array ( $ points [ 0 ] , $ points [ $ pointsEnd ] ) ; } return $ points ; }
Reduce points with Ramer - Douglas - Peucker algorithm .
319
public function reduce ( $ tolerance , $ lookAhead = null ) { if ( $ lookAhead ) { $ this -> lookAhead = ( int ) $ lookAhead ; } $ key = 0 ; $ endPoint = min ( $ this -> lookAhead , $ this -> lastKey ( ) ) ; do { if ( $ key + 1 == $ endPoint ) { if ( $ endPoint != $ this -> lastKey ( ) ) { $ key = $ endPoint ; $ endPoint = min ( $ endPoint + $ this -> lookAhead , $ this -> lastKey ( ) ) ; } else { } } else { $ maxIndex = $ key + 1 ; $ d = $ this -> shortestDistanceToSegment ( $ this -> points [ $ maxIndex ] , $ this -> points [ $ key ] , $ this -> points [ $ endPoint ] ) ; $ maxD = $ d ; for ( $ i = $ maxIndex + 1 ; $ i < $ endPoint ; $ i ++ ) { $ d = $ this -> shortestDistanceToSegment ( $ this -> points [ $ i ] , $ this -> points [ $ key ] , $ this -> points [ $ endPoint ] ) ; if ( $ d > $ maxD ) { $ maxD = $ d ; $ maxIndex = $ i ; } } if ( $ maxD > $ tolerance ) { $ endPoint -- ; } else { for ( $ i = $ key + 1 ; $ i < $ endPoint ; $ i ++ ) { unset ( $ this -> points [ $ i ] ) ; } $ key = $ endPoint ; $ endPoint = min ( $ endPoint + $ this -> lookAhead , $ this -> lastKey ( ) ) ; } } } while ( $ key < $ this -> lastKey ( - 2 ) || $ endPoint != $ this -> lastKey ( ) ) ; return $ this -> reindex ( ) ; }
Reduce points with Lang algorithm .
320
public function initializeState ( ) { if ( Session :: has ( $ this -> session_key ) ) { $ this -> setStateArray ( Session :: get ( $ this -> session_key ) ) ; } else { $ this -> resetState ( ) ; } return $ this -> getStateArray ( ) ; }
Initialize starting import state from session
321
public function setContent ( $ layout ) { $ content = '' ; $ state_array = $ this -> getStateArray ( ) ; foreach ( $ state_array as $ state_key => $ state ) { $ content .= $ state -> getForm ( ) ; } $ layout -> content = $ content ; }
Fill layout content with forms
322
public function processForm ( ) { $ current_state = $ this -> getCurrent ( ) ; $ executed_process = $ current_state -> processForm ( ) ; $ executed_next_state = $ this -> setNextState ( $ current_state , $ executed_process ) ; return ( $ executed_process && $ executed_next_state ) ; }
Process the current form
323
protected function setNextState ( $ current_state , $ executed ) { try { $ next_state = $ current_state -> getNextState ( ) ; } catch ( ClassNotFoundException $ e ) { Session :: put ( 'Errors' , new MessageBag ( array ( "Class" => "Class not found" ) ) ) ; return false ; } if ( $ executed ) { $ this -> append ( $ next_state ) ; } else { $ this -> replaceCurrent ( $ next_state ) ; } return true ; }
Set the next state
324
public function replaceCurrent ( $ value ) { $ key = $ this -> getLastKey ( ) ; if ( $ key >= 0 ) { $ this -> getStateArray ( ) -> offsetSet ( $ key , $ value ) ; } else { throw new NoDataException ; } }
Replace the current state
325
protected function & getAttributeValue ( string $ key ) { if ( isset ( $ this -> attributes [ $ key ] ) ) { return $ this -> attributes [ $ key ] ; } $ null = null ; return $ null ; }
Get a plain attribute
326
public function setAttributes ( array $ attributes ) : void { $ this -> checkAttributeAssignable ( array_keys ( $ attributes ) ) ; $ this -> setRawAttributes ( $ attributes ) ; }
Mass assignment of attributes
327
protected function recursiveToArray ( $ item ) { if ( is_array ( $ item ) ) { foreach ( $ item as & $ subitem ) { $ subitem = $ this -> recursiveToArray ( $ subitem ) ; } unset ( $ subitem ) ; return $ item ; } if ( $ item instanceof Arrayable ) { return $ item -> toArray ( ) ; } return $ item ; }
Recursively converts parameter to array
328
public function offsetSet ( $ offset , $ value ) { if ( ! $ this -> magicAssignment ) { throw new UnassignableAttributeException ( "Not allowed to assign value by magic with array access" ) ; } $ this -> checkAttributeAssignable ( $ offset ) ; $ this -> attributes [ $ offset ] = $ value ; }
Set the value for a given offset .
329
public function reduce ( $ tolerance ) { $ this -> _tolerance = $ tolerance ; $ sentinelKey = 0 ; while ( $ sentinelKey < $ this -> count ( ) - 1 ) { $ testKey = $ sentinelKey + 1 ; while ( $ sentinelKey < $ this -> count ( ) - 1 && $ this -> _isInTolerance ( $ sentinelKey , $ testKey ) ) { unset ( $ this -> points [ $ testKey ] ) ; $ testKey ++ ; } $ this -> reindex ( ) ; $ sentinelKey ++ ; } return $ this -> reindex ( ) ; }
Remove points with a distance under a given tolerance .
330
private function _isInTolerance ( $ basePointIndex , $ subjectPointIndex ) { $ radius = $ this -> distanceBetweenPoints ( $ this -> points [ $ basePointIndex ] , $ this -> points [ $ subjectPointIndex ] ) ; return $ radius < $ this -> _tolerance ; }
Helper method to ensure clean code .
331
public function createVote ( RatingInterface $ rating , UserInterface $ voter ) { $ class = $ this -> getClass ( ) ; $ vote = new $ class ; $ vote -> setRating ( $ rating ) ; $ vote -> setVoter ( $ voter ) ; $ this -> dispatcher -> dispatch ( DCSRatingEvents :: VOTE_CREATE , new Event \ VoteEvent ( $ vote ) ) ; return $ vote ; }
Creates an empty vote instance
332
public function onDispatcherReady ( ) { if ( $ this -> dispatcher && $ this -> dispatcher -> isReady ( ) ) { $ context = $ this -> currentContext ; $ event = $ this -> currentEvent ; $ this -> dispatcher = null ; $ this -> currentContext = null ; $ this -> currentEvent = null ; $ this -> doCheckTransitions ( $ context , $ event ) ; $ this -> mutex -> releaseLock ( ) ; } }
is called after dispatcher was executed .
333
public function setPathFilter ( $ path_filter ) { if ( empty ( $ path_filter ) ) { $ this -> clearPathFilter ( ) ; } else { $ this -> path_filter = $ path_filter . '/' ; } return $ this ; }
Set Path Filter
334
public function getIframeURL ( ) { $ info = $ this -> parseLink ( ) ; if ( ! $ info ) { return false ; } $ params = $ this -> Config ( ) -> get ( 'service' ) ; if ( $ this -> Service == 'Vimeo' ) { $ url = 'https://player.vimeo.com/video/' . $ this -> VideoID ; if ( $ params && ! empty ( $ params [ strtolower ( $ this -> Service ) ] ) ) { $ url .= '?' . http_build_query ( $ params [ strtolower ( $ this -> Service ) ] , '' , '&' ) ; } return $ url ; } if ( $ this -> Service == 'YouTube' ) { $ url = 'https://www.youtube.com/embed/' . $ this -> VideoID ; if ( $ params && ! empty ( $ params [ strtolower ( $ this -> Service ) ] ) ) { $ url .= '?' . http_build_query ( $ params [ strtolower ( $ this -> Service ) ] , '' , '&' ) ; } return $ url ; } }
Return the iframe URL
335
public function iFrame ( $ maxwidth = '100%' , $ height = '56%' ) { $ url = $ this -> getIFrameURL ( ) ; if ( ! $ url ) { return false ; } if ( is_numeric ( $ maxwidth ) ) { $ maxwidth .= 'px' ; } if ( is_numeric ( $ height ) ) { $ height .= 'px' ; } return $ this -> customise ( [ 'URL' => $ url , 'MaxWidth' => $ maxwidth , 'Height' => $ height , ] ) -> renderWith ( 'Axllent\\FormFields\\Layout\\VideoIframe' ) ; }
Return populated iframe template
336
public function getTitle ( ) { if ( $ this -> getService ( ) == 'YouTube' ) { $ data = $ this -> getCachedJsonResponse ( 'https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=' . $ this -> VideoID . '&format=json' ) ; if ( $ data && ! empty ( $ data [ 'title' ] ) ) { return $ data [ 'title' ] ; } } if ( $ this -> getService ( ) == 'Vimeo' ) { $ data = $ this -> getCachedJsonResponse ( 'https://vimeo.com/api/v2/video/' . $ this -> VideoID . '.json' ) ; if ( $ data && ! empty ( $ data [ 0 ] ) && ! empty ( $ data [ 0 ] [ 'title' ] ) ) { return $ data [ 0 ] [ 'title' ] ; } } }
Scrape Video information from hosting sites
337
public function thumbnailURL ( $ size = 'large' ) { if ( ! in_array ( $ size , [ 'large' , 'medium' , 'small' ] ) ) { return false ; } $ info = $ this -> parseLink ( ) ; $ service = $ this -> getService ( ) ; if ( ! $ info || ! $ service ) { return false ; } if ( $ service == 'YouTube' ) { if ( $ size == 'large' ) { $ img = 'hqdefault.jpg' ; } elseif ( $ size == 'medium' ) { $ img = 'mqdefault.jpg' ; } else { $ img = 'default.jpg' ; } return 'https://i.ytimg.com/vi/' . $ this -> VideoID . '/' . $ img ; } if ( $ service == 'Vimeo' ) { $ data = $ this -> getCachedJsonResponse ( 'https://vimeo.com/api/v2/video/' . $ this -> VideoID . '.json' ) ; if ( ! $ data ) { return false ; } if ( $ size == 'large' && ( ! empty ( $ data [ 0 ] [ 'thumbnail_large' ] ) ) ) { return $ data [ 0 ] [ 'thumbnail_large' ] ; } elseif ( $ size == 'medium' && ( ! empty ( $ data [ 0 ] [ 'thumbnail_medium' ] ) ) ) { return $ data [ 0 ] [ 'thumbnail_medium' ] ; } elseif ( ! empty ( $ data [ 0 ] [ 'thumbnail_small' ] ) ) { return $ data [ 0 ] [ 'thumbnail_small' ] ; } } return false ; }
Return thumbnail URL
338
private function getCachedJsonResponse ( $ url ) { if ( ! class_exists ( 'GuzzleHttp\Client' ) ) { return false ; } $ cache_seconds = $ this -> config ( ) -> get ( 'cache_seconds' ) ; if ( ! is_numeric ( $ cache_seconds ) ) { $ cache_seconds = 604800 ; } $ cache = Injector :: inst ( ) -> get ( CacheInterface :: class . '.videoImgCache' ) ; $ key = md5 ( $ url ) ; if ( ! $ json = $ cache -> get ( $ key ) ) { $ client = new \ GuzzleHttp \ Client ( [ 'timeout' => 5 , 'headers' => [ 'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0' , 'Accept-Language' => 'en-US,en;q=0.5' , ] , ] ) ; try { $ res = $ client -> request ( 'GET' , $ url ) ; $ json = ( string ) $ res -> getBody ( ) ; } catch ( \ GuzzleHttp \ Exception \ RequestException $ e ) { return false ; } $ cache -> set ( $ key , $ json , $ cache_seconds ) ; } $ data = @ json_decode ( $ json , true ) ; return ( ! empty ( $ data ) ) ? $ data : false ; }
Return cached json response
339
private function parseLink ( ) { $ value = $ this -> RAW ( ) ; if ( ! $ value ) { return false ; } $ output = false ; if ( preg_match ( '/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/i' , $ value , $ matches ) ) { foreach ( $ matches as $ match ) { if ( preg_match ( '/^[0-9]{6,12}$/' , $ match ) ) { $ output = [ 'VideoID' => $ match , 'VideoService' => 'Vimeo' , ] ; } } } elseif ( preg_match ( '/https?:\/\/youtu\.be\/([a-z0-9\_\-]+)/i' , $ value , $ matches ) ) { $ output = [ 'VideoID' => $ matches [ 1 ] , 'VideoService' => 'YouTube' , ] ; } elseif ( preg_match ( '/youtu\.?be/i' , $ value ) ) { $ query_string = [ ] ; parse_str ( parse_url ( $ value , PHP_URL_QUERY ) , $ query_string ) ; if ( ! empty ( $ query_string [ 'v' ] ) ) { $ output = [ 'VideoID' => $ query_string [ 'v' ] , 'VideoService' => 'YouTube' , ] ; } } return ( $ output ) ? $ output : false ; }
Parse video link
340
public function buildUrl ( string $ url , array $ parameters = [ ] ) : string { if ( $ parameters ) { foreach ( $ parameters as $ key => $ value ) { if ( $ value === null ) { unset ( $ parameters [ $ key ] ) ; } if ( is_object ( $ value ) ) { $ packedObject = $ this -> objectPacker -> pack ( $ value ) ; if ( $ packedObject === null ) { throw new \ RuntimeException ( 'Cannot pack object ' . get_class ( $ value ) ) ; } $ parameters [ $ key ] = $ packedObject -> getData ( ) ; } } } $ pos = strpos ( $ url , '?' ) ; if ( $ pos !== false ) { parse_str ( substr ( $ url , $ pos + 1 ) , $ query ) ; $ parameters += $ query ; $ url = substr ( $ url , 0 , $ pos ) ; } if ( $ parameters ) { return $ url . '?' . http_build_query ( $ parameters ) ; } return $ url ; }
Builds a URL with the given parameters .
341
public function has ( string $ key ) : bool { if ( array_key_exists ( $ key , $ this -> ttl ) && $ this -> time ( ) - $ this -> ttl [ $ key ] > 0 ) { unset ( $ this -> ttl [ $ key ] ) ; unset ( $ this -> storage [ $ key ] ) ; return false ; } return array_key_exists ( $ key , $ this -> storage ) ; }
Determine if an item exists in the cache . This method will also check if the ttl of the given cache key has been expired and will free the memory if so .
342
public function getKey ( $ key ) { $ out = NULL ; if ( $ this -> hasKey ( $ key ) ) { $ out = $ this -> key [ $ key ] ; unset ( $ this -> key [ $ key ] ) ; } return $ out ; }
get and clear a flash key if it s existing
343
protected function findDefaultDatabase ( string $ connectionString ) { preg_match ( '/\S+\/(\w*)/' , $ connectionString , $ matches ) ; if ( $ matches [ 1 ] ?? null ) { $ this -> defaultDatabase = $ matches [ 1 ] ; } }
Find and stores the default database in the connection string .
344
protected function contains ( $ token ) { return stripos ( $ this -> whois , sprintf ( $ token , $ this -> domain ) ) !== false ; }
Checks if whois contains given token .
345
public function getErrorName ( ) { if ( isset ( self :: $ returnCodes [ $ this -> returnCode ] ) ) { return self :: $ returnCodes [ $ this -> returnCode ] [ 0 ] ; } return 'Error ' . $ this -> returnCode ; }
Returns a string representation of the returned error code .
346
public function save ( $ entity , array $ options = [ ] ) { if ( false === $ this -> fireEvent ( 'saving' , $ entity , true ) ) { return false ; } $ data = $ this -> parseToDocument ( $ entity ) ; $ queryResult = $ this -> getCollection ( ) -> replaceOne ( [ '_id' => $ data [ '_id' ] ] , $ data , $ this -> mergeOptions ( $ options , [ 'upsert' => true ] ) ) ; $ result = $ queryResult -> isAcknowledged ( ) && ( $ queryResult -> getModifiedCount ( ) || $ queryResult -> getUpsertedCount ( ) ) ; if ( $ result ) { $ this -> afterSuccess ( $ entity ) ; $ this -> fireEvent ( 'saved' , $ entity ) ; } return $ result ; }
Upserts the given object into database . Returns success if write concern is acknowledged .
347
public function insert ( $ entity , array $ options = [ ] , bool $ fireEvents = true ) : bool { if ( $ fireEvents && false === $ this -> fireEvent ( 'inserting' , $ entity , true ) ) { return false ; } $ data = $ this -> parseToDocument ( $ entity ) ; $ queryResult = $ this -> getCollection ( ) -> insertOne ( $ data , $ this -> mergeOptions ( $ options ) ) ; $ result = $ queryResult -> isAcknowledged ( ) && $ queryResult -> getInsertedCount ( ) ; if ( $ result ) { $ this -> afterSuccess ( $ entity ) ; if ( $ fireEvents ) { $ this -> fireEvent ( 'inserted' , $ entity ) ; } } return $ result ; }
Inserts the given object into database . Returns success if write concern is acknowledged . Since it s an insert it will fail if the _id already exists .
348
public function update ( $ entity , array $ options = [ ] ) : bool { if ( false === $ this -> fireEvent ( 'updating' , $ entity , true ) ) { return false ; } if ( ! $ entity -> _id ) { if ( $ result = $ this -> insert ( $ entity , $ options , false ) ) { $ this -> afterSuccess ( $ entity ) ; $ this -> fireEvent ( 'updated' , $ entity ) ; } return $ result ; } $ data = $ this -> parseToDocument ( $ entity ) ; $ queryResult = $ this -> getCollection ( ) -> updateOne ( [ '_id' => $ data [ '_id' ] ] , [ '$set' => $ data ] , $ this -> mergeOptions ( $ options ) ) ; $ result = $ queryResult -> isAcknowledged ( ) && $ queryResult -> getModifiedCount ( ) ; if ( $ result ) { $ this -> afterSuccess ( $ entity ) ; $ this -> fireEvent ( 'updated' , $ entity ) ; } return $ result ; }
Updates the given object into database . Returns success if write concern is acknowledged . Since it s an update it will fail if the document with the given _id did not exists .
349
public function delete ( $ entity , array $ options = [ ] ) : bool { if ( false === $ this -> fireEvent ( 'deleting' , $ entity , true ) ) { return false ; } $ data = $ this -> parseToDocument ( $ entity ) ; $ queryResult = $ this -> getCollection ( ) -> deleteOne ( [ '_id' => $ data [ '_id' ] ] , $ this -> mergeOptions ( $ options ) ) ; if ( $ queryResult -> isAcknowledged ( ) && $ queryResult -> getDeletedCount ( ) ) { $ this -> fireEvent ( 'deleted' , $ entity ) ; return true ; } return false ; }
Removes the given document from the collection .
350
protected function parseToDocument ( $ entity ) { $ schemaMapper = $ this -> getSchemaMapper ( ) ; $ parsedDocument = $ schemaMapper -> map ( $ entity ) ; if ( is_object ( $ entity ) ) { foreach ( $ parsedDocument as $ field => $ value ) { $ entity -> $ field = $ value ; } } return $ parsedDocument ; }
Parses an object with SchemaMapper and the given Schema .
351
protected function getCollection ( ) : Collection { $ conn = $ this -> connPool -> getConnection ( ) ; $ database = $ conn -> defaultDatabase ; $ collection = $ this -> schema -> collection ; return $ conn -> getRawConnection ( ) -> $ database -> $ collection ; }
Retrieves the Collection object .
352
protected function prepareArrayFieldOfQuery ( array $ value ) : array { foreach ( [ '$in' , '$nin' ] as $ operator ) { if ( isset ( $ value [ $ operator ] ) && is_array ( $ value [ $ operator ] ) ) { foreach ( $ value [ $ operator ] as $ index => $ id ) { if ( ObjectIdUtils :: isObjectId ( $ id ) ) { $ value [ $ operator ] [ $ index ] = new ObjectId ( $ id ) ; } } } } return $ value ; }
Prepares an embedded array of an query . It will convert string ObjectIds in operators into actual objects .
353
protected function getAssembler ( ) { if ( ! $ this -> assembler ) { $ this -> assembler = Ioc :: make ( EntityAssembler :: class ) ; } return $ this -> assembler ; }
Retrieves an EntityAssembler instance .
354
protected function fireEvent ( string $ event , $ entity , bool $ halt = false ) { $ event = "mongolid.{$event}: " . get_class ( $ entity ) ; $ this -> eventService ? $ this -> eventService : $ this -> eventService = Ioc :: make ( EventTriggerService :: class ) ; return $ this -> eventService -> fire ( $ event , $ entity , $ halt ) ; }
Triggers an event . May return if that event had success .
355
protected function prepareProjection ( array $ fields ) { $ projection = [ ] ; foreach ( $ fields as $ key => $ value ) { if ( is_string ( $ key ) ) { if ( is_bool ( $ value ) ) { $ projection [ $ key ] = $ value ; continue ; } if ( is_int ( $ value ) ) { $ projection [ $ key ] = ( $ value >= 1 ) ; continue ; } } if ( is_int ( $ key ) && is_string ( $ value ) ) { $ key = $ value ; if ( 0 === strpos ( $ value , '-' ) ) { $ key = substr ( $ key , 1 ) ; $ value = false ; } else { $ value = true ; } $ projection [ $ key ] = $ value ; continue ; } throw new InvalidArgumentException ( sprintf ( "Invalid projection: '%s' => '%s'" , $ key , $ value ) ) ; } return $ projection ; }
Converts the given projection fields to Mongo driver format .
356
public function check ( $ domain ) { return $ this -> client -> query ( $ domain ) -> then ( function ( $ result ) use ( $ domain ) { return Factory :: create ( $ domain , $ result ) -> isAvailable ( ) ; } ) ; }
Checks domain availability .
357
public function checkAll ( array $ domains ) { return When :: map ( $ domains , array ( $ this , 'check' ) ) -> then ( function ( $ statuses ) use ( $ domains ) { ksort ( $ statuses ) ; return array_combine ( $ domains , $ statuses ) ; } ) ; }
Checks domain availability of multiple domains .
358
public function end ( ) { if ( $ this -> buffering === false ) { throw new ParserBufferingException ( 'Markdown buffering have not been started.' ) ; } $ markdown = ob_get_clean ( ) ; $ this -> buffering = false ; return $ this -> parse ( $ markdown ) ; }
Stop buffering output & return the parsed markdown string .
359
protected function referencesOne ( string $ entity , string $ field , bool $ cacheable = true ) { $ referenced_id = $ this -> $ field ; if ( is_array ( $ referenced_id ) && isset ( $ referenced_id [ 0 ] ) ) { $ referenced_id = $ referenced_id [ 0 ] ; } $ entityInstance = Ioc :: make ( $ entity ) ; if ( $ entityInstance instanceof Schema ) { $ dataMapper = Ioc :: make ( DataMapper :: class ) ; $ dataMapper -> setSchema ( $ entityInstance ) ; return $ dataMapper -> first ( [ '_id' => $ referenced_id ] , [ ] , $ cacheable ) ; } return $ entityInstance :: first ( [ '_id' => $ referenced_id ] , [ ] , $ cacheable ) ; }
Returns the referenced documents as objects .
360
protected function referencesMany ( string $ entity , string $ field , bool $ cacheable = true ) { $ referencedIds = ( array ) $ this -> $ field ; if ( ObjectIdUtils :: isObjectId ( $ referencedIds [ 0 ] ?? '' ) ) { foreach ( $ referencedIds as $ key => $ value ) { $ referencedIds [ $ key ] = new ObjectId ( $ value ) ; } } $ query = [ '_id' => [ '$in' => array_values ( $ referencedIds ) ] ] ; $ entityInstance = Ioc :: make ( $ entity ) ; if ( $ entityInstance instanceof Schema ) { $ dataMapper = Ioc :: make ( DataMapper :: class ) ; $ dataMapper -> setSchema ( $ entityInstance ) ; return $ dataMapper -> where ( $ query , [ ] , $ cacheable ) ; } return $ entityInstance :: where ( $ query , [ ] , $ cacheable ) ; }
Returns the cursor for the referenced documents as objects .
361
protected function embedsOne ( string $ entity , string $ field ) { if ( is_subclass_of ( $ entity , Schema :: class ) ) { $ entity = ( new $ entity ( ) ) -> entityClass ; } $ items = ( array ) $ this -> $ field ; if ( false === empty ( $ items ) && false === array_key_exists ( 0 , $ items ) ) { $ items = [ $ items ] ; } return Ioc :: make ( CursorFactory :: class ) -> createEmbeddedCursor ( $ entity , $ items ) -> first ( ) ; }
Return a embedded documents as object .
362
private function renderErrors ( Base $ base ) : string { if ( ! $ base -> hasErrors ( ) ) { return '' ; } $ html = '' ; foreach ( $ base -> getErrors ( ) as $ error ) { $ li = new Tag ( 'li' ) ; $ li -> setTextContent ( $ error ) ; $ html .= $ li -> render ( ) ; } $ ul = new Tag ( 'ul' ) ; $ ul -> setHtmlContent ( $ html ) ; return $ ul -> render ( ) ; }
Renders the errors of a Form or an Element as an unordered list .
363
private function _distance ( $ out , $ key ) { return $ this -> distanceBetweenPoints ( $ this -> points [ $ out ] , $ this -> points [ $ key ] ) ; }
Short - cut function for distanceBetweenPoints method
364
public function execute ( $ writeConcern = 1 ) { $ connection = Ioc :: make ( Pool :: class ) -> getConnection ( ) ; $ manager = $ connection -> getRawManager ( ) ; $ namespace = $ connection -> defaultDatabase . '.' . $ this -> schema -> collection ; return $ manager -> executeBulkWrite ( $ namespace , $ this -> getBulkWrite ( ) , [ 'writeConcern' => new WriteConcern ( $ writeConcern ) ] ) ; }
Execute the BulkWrite using a connection from the Pool . The collection is inferred from entity s collection name .
365
public function push ( $ data ) { $ this -> buffer -> write ( $ data ) ; $ result = [ ] ; while ( $ this -> buffer -> getRemainingBytes ( ) > 0 ) { $ type = $ this -> buffer -> readByte ( ) >> 4 ; try { $ packet = $ this -> factory -> build ( $ type ) ; } catch ( UnknownPacketTypeException $ e ) { $ this -> handleError ( $ e ) ; continue ; } $ this -> buffer -> seek ( - 1 ) ; $ position = $ this -> buffer -> getPosition ( ) ; try { $ packet -> read ( $ this -> buffer ) ; $ result [ ] = $ packet ; $ this -> buffer -> cut ( ) ; } catch ( EndOfStreamException $ e ) { $ this -> buffer -> setPosition ( $ position ) ; break ; } catch ( MalformedPacketException $ e ) { $ this -> handleError ( $ e ) ; } } return $ result ; }
Appends the given data to the internal buffer and parses it .
366
private function handleError ( $ exception ) { if ( $ this -> errorCallback !== null ) { $ callback = $ this -> errorCallback ; $ callback ( $ exception ) ; } }
Executes the registered error callback .
367
final public function partial ( View $ view ) : string { if ( $ this -> injector ) { $ this -> injector -> inject ( $ view ) ; } return $ view -> render ( ) ; }
Renders a partial View .
368
public static function deleteAllButLive ( ) { $ query = new SQLSelect ( ) ; $ query -> setFrom ( 'SiteTree_Versions' ) ; $ versionsToDelete = [ ] ; $ results = $ query -> execute ( ) ; foreach ( $ results as $ row ) { $ ID = $ row [ 'ID' ] ; $ RecordID = $ row [ 'RecordID' ] ; $ Version = $ row [ 'Version' ] ; $ ClassName = $ row [ 'ClassName' ] ; $ query = new SQLSelect ( ) ; $ query -> setSelect ( 'Count(*) as Count' ) ; $ query -> setFrom ( 'SiteTree_Live' ) ; $ query -> addWhere ( 'ID = ' . $ RecordID ) ; $ query -> addWhere ( 'Version = ' . $ Version ) ; $ is_live = $ query -> execute ( ) -> value ( ) ; if ( ! $ is_live ) { array_push ( $ versionsToDelete , [ 'RecordID' => $ RecordID , 'Version' => $ Version , 'ClassName' => $ ClassName , ] ) ; } } $ affected_rows = 0 ; if ( count ( $ versionsToDelete ) > 0 ) { $ table_list = DB :: table_list ( ) ; $ affected_tables = [ ] ; $ doschema = new DataObjectSchema ( ) ; foreach ( $ versionsToDelete as $ d ) { $ subclasses = ClassInfo :: dataClassesFor ( $ d [ 'ClassName' ] ) ; foreach ( $ subclasses as $ subclass ) { $ table_name = strtolower ( $ doschema -> tableName ( $ subclass ) ) ; if ( ! empty ( $ table_list [ $ table_name . '_versions' ] ) ) { DB :: query ( 'DELETE FROM "' . $ table_list [ $ table_name . '_versions' ] . '" WHERE "RecordID" = ' . $ d [ 'RecordID' ] . ' AND "Version" = ' . $ d [ 'Version' ] ) ; $ affected_rows = $ affected_rows + DB :: affected_rows ( ) ; } } } } return $ affected_rows ; }
Remove ALL previous versions of a SiteTree record
369
function get ( $ countryCode = false , $ separator = '' ) { if ( $ countryCode == false ) { $ formattedNumber = '0' . $ this -> msisdn ; if ( ! empty ( $ separator ) ) { $ formattedNumber = substr_replace ( $ formattedNumber , $ separator , 4 , 0 ) ; $ formattedNumber = substr_replace ( $ formattedNumber , $ separator , 8 , 0 ) ; } return $ formattedNumber ; } else { $ formattedNumber = $ this -> countryPrefix . $ this -> msisdn ; if ( ! empty ( $ separator ) ) { $ formattedNumber = substr_replace ( $ formattedNumber , $ separator , strlen ( $ this -> countryPrefix ) , 0 ) ; $ formattedNumber = substr_replace ( $ formattedNumber , $ separator , 7 , 0 ) ; $ formattedNumber = substr_replace ( $ formattedNumber , $ separator , 11 , 0 ) ; } return $ formattedNumber ; } }
Returns a formatted mobile number
370
public function getPrefix ( ) { if ( $ this -> prefix == null ) { $ this -> prefix = substr ( $ this -> msisdn , 0 , 3 ) ; } return $ this -> prefix ; }
Returns the prefix of the MSISDN number .
371
public function getOperator ( ) { $ this -> setPrefixes ( ) ; if ( ! empty ( $ this -> operator ) ) { return $ this -> operator ; } if ( in_array ( $ this -> getPrefix ( ) , $ this -> smartPrefixes ) ) { $ this -> operator = 'SMART' ; } else if ( in_array ( $ this -> getPrefix ( ) , $ this -> globePrefixes ) ) { $ this -> operator = 'GLOBE' ; } else if ( in_array ( $ this -> getPrefix ( ) , $ this -> sunPrefixes ) ) { $ this -> operator = 'SUN' ; } else { $ this -> operator = 'UNKNOWN' ; } return $ this -> operator ; }
Determines the operator of this number
372
public static function validate ( $ mobileNumber ) { $ mobileNumber = Msisdn :: clean ( $ mobileNumber ) ; return ! empty ( $ mobileNumber ) && strlen ( $ mobileNumber ) === 10 && is_numeric ( $ mobileNumber ) ; }
Validate a given mobile number
373
private static function clean ( $ msisdn ) { $ msisdn = preg_replace ( "/[^0-9]/" , "" , $ msisdn ) ; if ( substr ( $ msisdn , 0 , 1 ) == '0' ) { $ msisdn = substr ( $ msisdn , 1 , strlen ( $ msisdn ) ) ; } else if ( substr ( $ msisdn , 0 , 2 ) == '63' ) { $ msisdn = substr ( $ msisdn , 2 , strlen ( $ msisdn ) ) ; } return $ msisdn ; }
Cleans the string
374
public function exec ( $ command ) { if ( ! $ this -> connected ) { throw new NotAuthenticatedException ( 'Client has not connected to the Rcon server.' ) ; } $ this -> write ( self :: SERVERDATA_EXECCOMMAND , $ command ) ; return $ this -> read ( ) [ 0 ] [ 'S1' ] ; }
Executes a command on the server .
375
public function read ( ) { $ rarray = [ ] ; $ count = 0 ; while ( $ data = fread ( $ this -> socket , 4 ) ) { $ data = unpack ( 'V1Size' , $ data ) ; if ( $ data [ 'Size' ] > 4096 ) { $ packet = '' ; for ( $ i = 0 ; $ i < 8 ; $ i ++ ) { $ packet .= "\x00" ; } $ packet .= fread ( $ this -> socket , 4096 ) ; } else { $ packet = fread ( $ this -> socket , $ data [ 'Size' ] ) ; } $ rarray [ ] = unpack ( 'V1ID/V1Response/a*S1/a*S2' , $ packet ) ; } return $ rarray ; }
Reads from the socket .
376
public function close ( ) { if ( ! $ this -> connected ) { return false ; } $ this -> connected = false ; fclose ( $ this -> socket ) ; return true ; }
Closes the socket .
377
public function createTable ( $ name , Array $ columns , $ safe_create = false ) { if ( ( ! $ safe_create ) || ( $ safe_create && ! Schema :: connection ( $ this -> connection ) -> hasTable ( 'users' ) ) ) { if ( Schema :: connection ( $ this -> connection ) -> hasTable ( $ name ) ) { Schema :: connection ( $ this -> connection ) -> drop ( $ name ) ; } Schema :: connection ( $ this -> connection ) -> create ( $ name , function ( $ table ) use ( $ columns ) { foreach ( $ columns as $ name => $ type ) { $ table -> $ type ( $ name ) ; } } ) ; } }
Create a table schme with the given columns
378
public function getReturnCodeName ( $ returnCode ) { if ( isset ( self :: $ qosLevels [ $ returnCode ] ) ) { return self :: $ qosLevels [ $ returnCode ] [ 0 ] ; } return 'Unknown ' . $ returnCode ; }
Indicates if the given return code is an error .
379
public function setReturnCodes ( array $ value ) { foreach ( $ value as $ returnCode ) { $ this -> assertValidReturnCode ( $ returnCode , false ) ; } $ this -> returnCodes = $ value ; }
Sets the return codes .
380
private function assertValidReturnCode ( $ returnCode , $ fromPacket = true ) { if ( ! in_array ( $ returnCode , [ 0 , 1 , 2 , 128 ] ) ) { $ this -> throwException ( sprintf ( 'Malformed return code %02x.' , $ returnCode ) , $ fromPacket ) ; } }
Asserts that a return code is valid .
381
public function setConfig ( array $ configs ) { foreach ( $ configs as $ config_key => $ config_value ) { if ( property_exists ( get_class ( $ this ) , $ config_key ) ) { $ this -> $ config_key = $ config_value ; } else { throw new \ InvalidArgumentException ; } } }
set parameters of the object
382
protected function createDataObjectFrom ( $ value , $ className ) { if ( $ value instanceof $ className ) { return $ value ; } if ( $ value instanceof Arrayable ) { $ value = $ value -> toArray ( ) ; } elseif ( is_object ( $ value ) ) { $ value = json_decode ( json_encode ( $ value ) , true ) ; } if ( ! is_array ( $ value ) ) { return false ; } $ dataObjectClass = $ className ; try { $ dataObject = new $ dataObjectClass ( $ value ) ; } catch ( Throwable $ e ) { throw new InvalidArgumentException ( $ dataObjectClass . ' is not instantiable as a DataObject' , 0 , $ e ) ; } if ( ! ( $ dataObject instanceof DataObjectInterface ) ) { throw new InvalidArgumentException ( $ dataObjectClass . ' is not a validatable DataObject' ) ; } return $ dataObject ; }
Creates a DataObject with the given class name
383
public function assemble ( $ document , Schema $ schema ) { $ entityClass = $ schema -> entityClass ; $ model = Ioc :: make ( $ entityClass ) ; foreach ( $ document as $ field => $ value ) { $ fieldType = $ schema -> fields [ $ field ] ?? null ; if ( $ fieldType && 'schema.' == substr ( $ fieldType , 0 , 7 ) ) { $ value = $ this -> assembleDocumentsRecursively ( $ value , substr ( $ fieldType , 7 ) ) ; } $ model -> $ field = $ value ; } $ entity = $ this -> morphingTime ( $ model ) ; return $ this -> prepareOriginalAttributes ( $ entity ) ; }
Builds an object from the provided data .
384
private function destructEventEmitterTrait ( ) { $ this -> emitterBlocked = EventEmitter :: EVENTS_FORWARD ; $ this -> eventPointers = [ ] ; $ this -> eventListeners = [ ] ; $ this -> forwardListeners = [ ] ; }
Destruct method .
385
private function getTransactionalAnnotation ( RouteMatch $ routeMatch ) : ? Transactional { $ method = $ routeMatch -> getControllerReflection ( ) ; if ( $ method instanceof \ ReflectionMethod ) { $ annotations = $ this -> annotationReader -> getMethodAnnotations ( $ method ) ; foreach ( $ annotations as $ annotation ) { if ( $ annotation instanceof Transactional ) { return $ annotation ; } } } return null ; }
Returns the Transactional annotation for the controller .
386
public function build ( $ type ) { if ( ! isset ( self :: $ mapping [ $ type ] ) ) { throw new UnknownPacketTypeException ( sprintf ( 'Unknown packet type %d.' , $ type ) ) ; } $ class = self :: $ mapping [ $ type ] ; return new $ class ( ) ; }
Builds a packet object for the given type .
387
public function getNextState ( ) { if ( $ this -> getIsExecuted ( ) ) { if ( class_exists ( $ next = $ this -> getNextStateClass ( ) ) ) { return ( new $ next ) ; } else { throw new ClassNotFoundException ; } } else { return $ this ; } }
Return the next state
388
public function getErrorHeader ( ) { $ err_str = '' ; $ error_class = $ this -> getErrors ( ) ; $ error_session = Session :: get ( $ this -> errors_key ) ; if ( $ error_class ) { foreach ( $ error_class -> all ( ) as $ error_key => $ error ) { $ err_str .= "<div class=\"alert alert-danger\">{$error}</div>" ; } } if ( $ error_session ) { foreach ( $ error_session -> all ( ) as $ error_key => $ error ) { $ err_str .= "<div class=\"alert alert-danger\">{$error}</div>" ; } } $ this -> resetErrors ( ) ; return $ err_str ; }
Print the form errors if exists
389
public function appendError ( $ error_key , $ error_string ) { if ( $ this -> getErrors ( ) ) { $ this -> errors -> add ( $ error_key , $ error_string ) ; } else { $ this -> errors = new MessageBag ( array ( $ error_key => $ error_string ) ) ; } }
Append error to the MessageBag
390
public function setProtocolLevel ( $ value ) { if ( $ value < 3 || $ value > 4 ) { throw new \ InvalidArgumentException ( sprintf ( 'Unknown protocol level %d.' , $ value ) ) ; } $ this -> protocolLevel = $ value ; if ( $ this -> protocolLevel === 3 ) { $ this -> protocolName = 'MQIsdp' ; } elseif ( $ this -> protocolLevel === 4 ) { $ this -> protocolName = 'MQTT' ; } }
Sets the protocol level .
391
public function setWill ( $ topic , $ message , $ qosLevel = 0 , $ isRetained = false ) { $ this -> assertValidString ( $ topic , false ) ; if ( $ topic === '' ) { throw new \ InvalidArgumentException ( 'The topic must not be empty.' ) ; } $ this -> assertValidStringLength ( $ message , false ) ; if ( $ message === '' ) { throw new \ InvalidArgumentException ( 'The message must not be empty.' ) ; } $ this -> assertValidQosLevel ( $ qosLevel , false ) ; $ this -> willTopic = $ topic ; $ this -> willMessage = $ message ; $ this -> flags |= 4 ; $ this -> flags |= ( $ qosLevel << 3 ) ; if ( $ isRetained ) { $ this -> flags |= 32 ; } else { $ this -> flags &= ~ 32 ; } }
Sets the will .
392
public function setUsername ( $ value ) { $ this -> assertValidString ( $ value , false ) ; $ this -> username = $ value ; if ( $ this -> username !== '' ) { $ this -> flags |= 64 ; } else { $ this -> flags &= ~ 64 ; } }
Sets the username .
393
private function assertValidWill ( ) { if ( $ this -> hasWill ( ) ) { $ this -> assertValidQosLevel ( $ this -> getWillQosLevel ( ) , true ) ; } else { if ( $ this -> getWillQosLevel ( ) > 0 ) { $ this -> throwException ( sprintf ( 'Expected a will quality of service level of zero but got %d.' , $ this -> getWillQosLevel ( ) ) , true ) ; } if ( $ this -> isWillRetained ( ) ) { $ this -> throwException ( 'There is not will but the will retain flag is set.' , true ) ; } } }
Asserts that all will flags and quality of service are correct .
394
public function display ( ) : void { $ templateParameters = [ ] ; foreach ( $ this -> params as $ param ) { if ( $ param instanceof PostParameter ) { $ templateParameters [ $ param -> getName ( ) ] = $ param ; } else { if ( $ param instanceof GenericParameter ) { $ templateParameters [ $ param -> getName ( ) ] = $ param -> getValue ( ) ; } } } try { $ this -> twig -> display ( $ this -> templateName , $ templateParameters ) ; } catch ( LoaderError $ e ) { trigger_error ( $ e -> getMessage ( ) , E_USER_ERROR ) ; error_log ( $ e -> getMessage ( ) ) ; } catch ( RuntimeError $ e ) { trigger_error ( $ e -> getMessage ( ) , E_USER_ERROR ) ; error_log ( $ e -> getMessage ( ) ) ; } catch ( SyntaxError $ e ) { trigger_error ( $ e -> getMessage ( ) , E_USER_ERROR ) ; error_log ( $ e -> getMessage ( ) ) ; } }
Displays the current view . Iterates over all the parameters and stores them in a temporary associative array . Twig then displays the main template using the array with the parameters . Exceptions generated by Twig are shown as errors and logged accordingly for simplification .
395
public function call ( $ call , $ format = null , $ timeout = 6000 , $ pagination = true ) { $ service = $ this -> getService ( ) ; $ service -> setLogger ( $ this -> getLogger ( ) ) ; return $ service -> process ( $ call , $ format , $ timeout , $ pagination ) ; }
Facade d appel Navitia
396
public function setConfiguration ( $ config ) { $ this -> config = $ config ; $ service = $ this -> getService ( ) ; return $ service -> processConfiguration ( $ this -> config ) ; }
Facade de setter de la configuration
397
public function beforeModeration ( ) : bool { if ( method_exists ( $ this -> owner , 'beforeModeration' ) ) { if ( ! $ this -> owner -> beforeModeration ( ) ) { return false ; } } $ event = new ModelEvent ( ) ; $ this -> owner -> trigger ( self :: EVENT_BEFORE_MODERATION , $ event ) ; return $ event -> isValid ; }
This method is invoked before moderating a record .
398
public function markApproved ( ) : bool { $ this -> owner -> { $ this -> statusAttribute } = Status :: APPROVED ; if ( $ this -> beforeModeration ( ) ) { return $ this -> owner -> save ( ) ; } return false ; }
Change model status to Approved
399
public function markRejected ( ) : bool { $ this -> owner -> { $ this -> statusAttribute } = Status :: REJECTED ; if ( $ this -> beforeModeration ( ) ) { return $ this -> owner -> save ( ) ; } return false ; }
Change model status to Rejected