idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
3,600
|
public function darken ( Color $ color , $ amount = null ) { $ current = $ color -> lightness ; $ amount = ( $ amount === null ) ? self :: DEFAULT_ADJUST : $ amount ; $ amount = intval ( $ amount ) / 100 ; $ new = $ current - $ amount ; $ new = ( $ new < 0 ) ? 0 : $ new ; $ new = ( $ new > 1 ) ? 1 : $ new ; $ color -> lightness = floatval ( $ new ) ; return $ color ; }
|
Darkens color by a percentage a given Color object
|
3,601
|
public function merge ( Color $ color1 , Color $ color2 , $ percentage = 50 ) { return new Color ( array ( 'red' => $ this -> getMergedColorPart ( 'red' , $ color1 , $ color2 , $ percentage ) , 'green' => $ this -> getMergedColorPart ( 'green' , $ color1 , $ color2 , $ percentage ) , 'blue' => $ this -> getMergedColorPart ( 'blue' , $ color1 , $ color2 , $ percentage ) ) ) ; }
|
Merges the current color with a second color with an optional percentage
|
3,602
|
public static function getMapStyleJSON ( ) { $ folders = [ 'client/dist/js/' , 'client/dist/javascript/' , 'dist/js/' , 'dist/javascript/' , 'src/javascript/thirdparty' , 'js/' , 'javascript/' , ] ; $ file = 'mapStyle.json' ; foreach ( $ folders as $ folder ) { if ( $ style = ThemeResourceLoader :: inst ( ) -> findThemedResource ( "{$folder}{$file}" , SSViewer :: get_themes ( ) ) ) { return $ style ; } } return false ; }
|
Gets the style of the map
|
3,603
|
public static function getIconImage ( $ svg = true ) { $ folders = [ 'client/dist/img/' , 'client/dist/images/' , 'dist/img/' , 'dist/images/' , 'img/' , 'images/' , ] ; $ extensions = [ 'png' , 'jpg' , 'jpeg' , 'gif' , ] ; if ( $ svg === true ) { array_unshift ( $ extensions , 'svg' ) ; } $ file = 'mapIcon' ; foreach ( $ folders as $ folder ) { foreach ( $ extensions as $ extension ) { if ( $ icon = ThemeResourceLoader :: inst ( ) -> findThemedResource ( "{$folder}{$file}.{$extension}" , SSViewer :: get_themes ( ) ) ) { return ModuleResourceLoader :: resourceURL ( $ icon ) ; } } } return false ; }
|
Gets the maker icon image
|
3,604
|
public function isAddressChanged ( $ level = 1 ) { $ fields = [ 'Address' , 'Address2' , 'City' , 'State' , 'PostalCode' , 'Country' ] ; $ changed = $ this -> owner -> getChangedFields ( false , $ level ) ; foreach ( $ fields as $ field ) { if ( array_key_exists ( $ field , $ changed ) ) { return true ; } } return false ; }
|
Returns TRUE if any of the address fields have changed .
|
3,605
|
private function writeTracks ( \ XMLWriter $ xmlWriter , Workout $ workout ) { $ xmlWriter -> startElement ( 'Activities' ) ; foreach ( $ workout -> tracks ( ) as $ track ) { $ xmlWriter -> startElement ( 'Activity' ) ; $ xmlWriter -> writeAttribute ( 'Sport' , ucfirst ( $ track -> sport ( ) ) ) ; $ xmlWriter -> writeElement ( 'Id' , $ this -> formatDateTime ( $ track -> startDateTime ( ) ) ) ; $ xmlWriter -> startElement ( 'Lap' ) ; $ xmlWriter -> writeAttribute ( 'StartTime' , $ this -> formatDateTime ( $ track -> startDateTime ( ) ) ) ; $ xmlWriter -> writeElement ( 'TotalTimeSeconds' , ( string ) $ track -> duration ( ) -> totalSeconds ( ) ) ; $ xmlWriter -> writeElement ( 'DistanceMeters' , ( string ) $ track -> length ( ) ) ; $ this -> writeLapHeartRateDate ( $ xmlWriter , $ track ) ; $ xmlWriter -> startElement ( 'Track' ) ; $ this -> writeTrackPoints ( $ xmlWriter , $ track -> trackPoints ( ) ) ; $ xmlWriter -> endElement ( ) ; $ xmlWriter -> endElement ( ) ; $ xmlWriter -> endElement ( ) ; } $ xmlWriter -> endElement ( ) ; }
|
Write the tracks to the TCX .
|
3,606
|
private function writeTrackPoints ( \ XMLWriter $ xmlWriter , array $ trackPoints ) { $ previousTrackPoint = null ; foreach ( $ trackPoints as $ trackPoint ) { $ xmlWriter -> startElement ( 'Trackpoint' ) ; $ dateTime = clone $ trackPoint -> dateTime ( ) ; $ dateTime -> setTimezone ( new \ DateTimeZone ( 'UTC' ) ) ; $ xmlWriter -> writeElement ( 'Time' , $ this -> formatDateTime ( $ dateTime ) ) ; $ xmlWriter -> startElement ( 'Position' ) ; $ xmlWriter -> writeElement ( 'LatitudeDegrees' , ( string ) $ trackPoint -> latitude ( ) ) ; $ xmlWriter -> writeElement ( 'LongitudeDegrees' , ( string ) $ trackPoint -> longitude ( ) ) ; $ xmlWriter -> endElement ( ) ; $ xmlWriter -> writeElement ( 'AltitudeMeters' , ( string ) $ trackPoint -> elevation ( ) ) ; if ( $ previousTrackPoint !== null ) { $ xmlWriter -> writeElement ( 'DistanceMeters' , ( string ) $ trackPoint -> distanceFromPoint ( $ previousTrackPoint ) ) ; } else { $ xmlWriter -> writeElement ( 'DistanceMeters' , '0' ) ; } $ this -> writeExtensions ( $ xmlWriter , $ trackPoint -> extensions ( ) ) ; $ xmlWriter -> endElement ( ) ; $ previousTrackPoint = $ trackPoint ; } }
|
Write the track points to the TCX .
|
3,607
|
protected function writeLapHeartRateDate ( \ XMLWriter $ xmlWriter , Track $ track ) { $ averageHeartRate = array ( ) ; $ maxHearRate = null ; foreach ( $ track -> trackPoints ( ) as $ trackPoint ) { if ( $ trackPoint -> hasExtension ( HR :: ID ( ) ) === true ) { $ pointHearRate = $ trackPoint -> extension ( HR :: ID ( ) ) -> value ( ) ; $ maxHearRate = max ( $ maxHearRate , $ pointHearRate ) ; $ averageHeartRate [ ] = $ pointHearRate ; } } if ( $ averageHeartRate !== array ( ) ) { $ xmlWriter -> startElement ( 'AverageHeartRateBpm' ) ; $ xmlWriter -> writeAttributeNS ( 'xsi' , 'type' , null , 'HeartRateInBeatsPerMinute_t' ) ; $ hearRateValue = array_sum ( $ averageHeartRate ) / count ( $ averageHeartRate ) ; $ xmlWriter -> writeElement ( 'Value' , ( string ) $ hearRateValue ) ; $ xmlWriter -> endElement ( ) ; } if ( $ maxHearRate !== null ) { $ xmlWriter -> startElement ( 'MaximumHeartRateBpm' ) ; $ xmlWriter -> writeAttributeNS ( 'xsi' , 'type' , null , 'HeartRateInBeatsPerMinute_t' ) ; $ xmlWriter -> writeElement ( 'Value' , ( string ) $ maxHearRate ) ; $ xmlWriter -> endElement ( ) ; } }
|
Write the heart rate data for a lap .
|
3,608
|
protected function writeExtensions ( \ XMLWriter $ xmlWriter , array $ extensions ) { foreach ( $ extensions as $ extension ) { switch ( $ extension :: ID ( ) ) { case HR :: ID ( ) : $ xmlWriter -> startElement ( 'HeartRateBpm' ) ; $ xmlWriter -> writeElement ( 'Value' , ( string ) $ extension -> value ( ) ) ; $ xmlWriter -> endElement ( ) ; break ; } } }
|
Write the extensions into the TCX .
|
3,609
|
protected function cleanToken ( ) { if ( $ token_name = $ this -> getToken ( ) ) { $ path = substr ( $ this -> path , strlen ( $ token_name ) ) ; return preg_replace ( '/<.*>/' , '' , $ path ) ; } $ message = sprintf ( 'No token could be found in "%s". Available tokens are: %s.' , $ this -> path , implode ( ', ' , array_keys ( $ this -> supportedTokens ) ) ) ; throw new ClassLoaderException ( $ message ) ; }
|
Removes the token from the tokenized path .
|
3,610
|
protected function getToken ( ) { foreach ( array_keys ( $ this -> supportedTokens ) as $ token_name ) { if ( strpos ( $ this -> path , $ token_name ) !== FALSE ) { return $ token_name ; } } return NULL ; }
|
Checks if the current tokenized path contains a known token .
|
3,611
|
protected function parseArguments ( ) { $ token_name = $ this -> getToken ( ) ; $ delimiter = '/' ; $ matches = array ( ) ; if ( preg_match ( $ delimiter . preg_quote ( $ token_name ) . '<(.+)>.*' . $ delimiter , $ this -> path , $ matches ) ) { return explode ( ',' , $ matches [ 1 ] ) ; } return array ( ) ; }
|
Gets the arguments in the token .
|
3,612
|
private function arrayFrom ( $ requestMethod ) : array { if ( is_string ( $ requestMethod ) ) { return [ $ requestMethod ] ; } if ( null === $ requestMethod ) { return [ Http :: GET , Http :: HEAD , Http :: POST , Http :: PUT , Http :: DELETE ] ; } if ( is_array ( $ requestMethod ) ) { return $ requestMethod ; } throw new \ InvalidArgumentException ( 'Given request method must be null, a string or an array, but received ' . typeOf ( $ requestMethod ) ) ; }
|
turns given value into a list
|
3,613
|
public function matches ( CalledUri $ calledUri ) : bool { if ( ! $ this -> matchesPath ( $ calledUri ) ) { return false ; } if ( in_array ( $ calledUri -> method ( ) , $ this -> allowedRequestMethods ) ) { return true ; } if ( in_array ( Http :: GET , $ this -> allowedRequestMethods ) ) { return $ calledUri -> methodEquals ( Http :: HEAD ) ; } return false ; }
|
checks if this route is applicable for given request
|
3,614
|
public function preIntercept ( $ preInterceptor ) : ConfigurableRoute { if ( ! is_callable ( $ preInterceptor ) && ! ( $ preInterceptor instanceof PreInterceptor ) && ! class_exists ( ( string ) $ preInterceptor ) ) { throw new \ InvalidArgumentException ( 'Given pre interceptor must be a callable, an instance of ' . PreInterceptor :: class . ' or a class name of an existing pre interceptor class' ) ; } $ this -> preInterceptors [ ] = $ preInterceptor ; return $ this ; }
|
add a pre interceptor for this route
|
3,615
|
public function postIntercept ( $ postInterceptor ) : ConfigurableRoute { if ( ! is_callable ( $ postInterceptor ) && ! ( $ postInterceptor instanceof PostInterceptor ) && ! class_exists ( ( string ) $ postInterceptor ) ) { throw new \ InvalidArgumentException ( 'Given pre interceptor must be a callable, an instance of ' . PostInterceptor :: class . ' or a class name of an existing post interceptor class' ) ; } $ this -> postInterceptors [ ] = $ postInterceptor ; return $ this ; }
|
add a post interceptor for this route
|
3,616
|
public function requiresHttps ( ) : bool { if ( $ this -> requiresHttps ) { return true ; } $ this -> requiresHttps = $ this -> routingAnnotations ( ) -> requiresHttps ( ) ; return $ this -> requiresHttps ; }
|
whether route is only available via https
|
3,617
|
public function authConstraint ( ) : AuthConstraint { if ( null === $ this -> authConstraint ) { $ this -> authConstraint = new AuthConstraint ( $ this -> routingAnnotations ( ) ) ; } return $ this -> authConstraint ; }
|
returns auth constraint for this route
|
3,618
|
public function supportsMimeType ( string $ mimeType , string $ class = null ) : ConfigurableRoute { if ( null === $ class && ! SupportedMimeTypes :: provideDefaultClassFor ( $ mimeType ) ) { throw new \ InvalidArgumentException ( 'No default class known for mime type ' . $ mimeType . ', please provide a class' ) ; } $ this -> mimeTypes [ ] = $ mimeType ; if ( null !== $ class ) { $ this -> mimeTypeClasses [ $ mimeType ] = $ class ; } return $ this ; }
|
add a mime type which this route supports
|
3,619
|
public function supportedMimeTypes ( array $ globalMimeTypes = [ ] , array $ globalClasses = [ ] ) : SupportedMimeTypes { if ( $ this -> disableContentNegotation || $ this -> routingAnnotations ( ) -> isContentNegotiationDisabled ( ) ) { return SupportedMimeTypes :: createWithDisabledContentNegotation ( ) ; } return new SupportedMimeTypes ( array_merge ( $ this -> routingAnnotations ( ) -> mimeTypes ( ) , $ this -> mimeTypes , $ globalMimeTypes ) , array_merge ( $ globalClasses , $ this -> routingAnnotations ( ) -> mimeTypeClasses ( ) , $ this -> mimeTypeClasses ) ) ; }
|
returns list of mime types supported by this route
|
3,620
|
private function routingAnnotations ( ) : RoutingAnnotations { if ( null === $ this -> routingAnnotations ) { $ this -> routingAnnotations = new RoutingAnnotations ( $ this -> target ) ; } return $ this -> routingAnnotations ; }
|
returns list of callback annotations
|
3,621
|
public function asResource ( HttpUri $ uri , array $ globalMimeTypes = [ ] ) : Resource { $ routeUri = $ uri -> withPath ( $ this -> normalizePath ( ) ) ; return new Resource ( $ this -> resourceName ( ) , $ this -> allowedRequestMethods , $ this -> requiresHttps ( ) ? $ routeUri -> toHttps ( ) : $ routeUri , $ this -> supportedMimeTypes ( $ globalMimeTypes ) -> asArray ( ) , $ this -> routingAnnotations ( ) , $ this -> authConstraint ( ) ) ; }
|
returns route as resource
|
3,622
|
private function normalizePath ( ) : string { $ path = $ this -> path ; if ( substr ( $ path , - 1 ) === '$' ) { $ path = substr ( $ path , 0 , strlen ( $ path ) - 1 ) ; } if ( substr ( $ path , - 1 ) === '?' ) { $ path = substr ( $ path , 0 , strlen ( $ path ) - 1 ) ; } return $ path ; }
|
normalizes path for better understanding
|
3,623
|
private function resourceName ( ) { if ( $ this -> routingAnnotations ( ) -> hasName ( ) ) { return $ this -> routingAnnotations ( ) -> name ( ) ; } if ( is_string ( $ this -> target ) && class_exists ( $ this -> target ) ) { return substr ( $ this -> target , strrpos ( $ this -> target , '\\' ) + 1 ) ; } elseif ( ! is_callable ( $ this -> target ) && is_object ( $ this -> target ) ) { return substr ( get_class ( $ this -> target ) , strrpos ( get_class ( $ this -> target ) , '\\' ) + 1 ) ; } return null ; }
|
returns useful name for resource
|
3,624
|
public function registerXPathNamespace ( $ prefix , $ uri ) { $ this -> el -> registerXPathNamespace ( $ prefix , $ uri ) ; $ this -> namespaces [ $ prefix ] = $ uri ; }
|
Register a new xpath namespace .
|
3,625
|
public function registerXPathNamespaces ( $ namespaces ) { foreach ( $ namespaces as $ prefix => $ uri ) { $ this -> registerXPathNamespace ( $ prefix , $ uri ) ; } }
|
Register an array of new xpath namespaces .
|
3,626
|
public function children ( $ ns = null ) { $ ch = is_null ( $ ns ) ? $ this -> el -> children ( ) : $ this -> el -> children ( $ this -> namespaces [ $ ns ] ) ; $ o = [ ] ; foreach ( $ ch as $ c ) { $ o [ ] = new static ( $ c , $ this ) ; } return $ o ; }
|
Returns child elements .
|
3,627
|
public function attributes ( $ ns = null , $ is_prefix = false ) { return $ this -> el -> attributes ( $ ns , $ is_prefix ) ; }
|
Returns and element s attributes .
|
3,628
|
protected static function handleDELETE ( $ parameters , $ method , $ headers , $ id , $ modelClass , $ primaryDataParameters = [ ] , $ validationCallbacks = [ ] , $ viewCallback = null ) { if ( $ viewCallback !== null && ! is_callable ( $ viewCallback ) ) { throw new ServerException ( 'View callback is not callable!' ) ; } $ resource = $ modelClass :: getById ( $ id , null , ... $ primaryDataParameters ) ; static :: exists ( $ resource ) ; foreach ( $ validationCallbacks as $ callback ) { call_user_func ( $ callback , $ id , $ resource ) ; } $ delete = $ modelClass :: delete ( $ id , $ primaryDataParameters ) ; if ( ! $ delete ) { throw new RequestException ( 'Unable to delete record' ) ; } if ( $ viewCallback !== null ) { return call_user_func ( $ viewCallback , $ id ) ; } \ Phramework \ JSONAPI \ Viewers \ JSONAPI :: header ( ) ; \ Phramework \ Models \ Response :: noContent ( ) ; return true ; }
|
Handle DELETE method On success will respond with 204 No Content
|
3,629
|
public function setupMustache ( ) { $ mustacheLoader = new MustacheLoader ( $ this -> viewManager ) ; $ config = [ 'loader' => $ mustacheLoader ] ; if ( $ this -> viewManager -> cachePath ) { $ config [ 'cache' ] = $ this -> viewManager -> cachePath . 'mustache/' ; } $ this -> mustache = new Mustache_Engine ( $ config ) ; }
|
Sets up Mustache_Engine
|
3,630
|
public function preBuild ( ) { $ build_path = $ this -> getBuildPath ( ) ; if ( $ build_path ) { if ( is_dir ( $ build_path ) ) { $ build_path = rtrim ( $ build_path , DIRECTORY_SEPARATOR ) ; if ( ! is_dir ( "$build_path/Manager/Base" ) ) { $ old_umask = umask ( 0 ) ; $ dir_created = mkdir ( "$build_path/Manager/Base" ) ; umask ( $ old_umask ) ; if ( $ dir_created ) { $ this -> triggerEvent ( 'on_dir_created' , [ "$build_path/Manager/Base" ] ) ; } else { throw new RuntimeException ( "Failed to create '$build_path/Manager/Base' directory" ) ; } } } else { throw new InvalidArgumentException ( "Directory '$build_path' not found" ) ; } } }
|
Execute prior to type build .
|
3,631
|
public function add ( string $ name , $ value ) : self { $ this -> headers [ $ name ] = $ value ; return $ this ; }
|
adds header with given name
|
3,632
|
public function location ( $ uri ) : self { return $ this -> add ( 'Location' , ( ( $ uri instanceof HttpUri ) ? ( $ uri -> asStringWithNonDefaultPort ( ) ) : ( $ uri ) ) ) ; }
|
adds location header with given uri
|
3,633
|
public function acceptable ( array $ supportedMimeTypes ) : self { if ( count ( $ supportedMimeTypes ) > 0 ) { $ this -> add ( 'X-Acceptable' , join ( ', ' , $ supportedMimeTypes ) ) ; } return $ this ; }
|
adds non - standard acceptable header with list of supported mime types
|
3,634
|
public function cacheControl ( ) : CacheControl { $ cacheControl = new CacheControl ( ) ; $ this -> add ( CacheControl :: HEADER_NAME , $ cacheControl ) ; return $ cacheControl ; }
|
enables the Cache - Control header
|
3,635
|
protected function collectNormalBelongsToRelationAccessors ( ) { $ accessors = [ ] ; foreach ( $ this -> data [ 'relationships' ] [ 'normal' ] as $ name => $ relationship ) { if ( $ relationship [ 'type' ] != Generator :: RELATIONSHIP_BELONGS_TO ) continue ; if ( ! empty ( $ relationship [ 'key' ] ) && snake_case ( $ name ) !== $ relationship [ 'key' ] ) continue ; $ attributeName = snake_case ( $ name ) ; $ content = $ this -> tab ( 2 ) . "return \$this->getBelongsToRelationAttributeValue('{$name}');\n" ; $ accessors [ $ name ] = [ 'attribute' => $ attributeName , 'content' => $ content , ] ; } return $ accessors ; }
|
For belongs - to relationships that share foreign key & relation name
|
3,636
|
public function getDeviceForRequest ( WURFL_Request_GenericRequest $ request ) { $ deviceId = $ this -> deviceIdForRequest ( $ request ) ; return $ this -> getWrappedDevice ( $ deviceId , $ request ) ; }
|
Returns the Device for the given WURFL_Request_GenericRequest
|
3,637
|
public function fromRelationshipType ( $ type ) { $ relationships = $ this -> getRelationshipsThatMatchType ( $ type ) ; if ( count ( $ relationships ) === 0 ) { return null ; } $ resource = reset ( $ relationships ) ; return new RelationshipResource ( key ( $ relationships ) , $ resource ) ; }
|
Get a resource from just the relationship type .
|
3,638
|
protected function getRelationshipsThatMatchType ( $ type ) { return array_filter ( $ this -> mapRelationshipsToIdAndData ( ) , function ( $ relationship ) use ( $ type ) { $ relationshipType = Arr :: get ( $ relationship , 'type' ) ; return Str :: snakeCase ( $ type ) === Str :: snakeCase ( $ relationshipType ) ; } ) ; }
|
Get all the relationships that their type matches the given type .
|
3,639
|
protected function getRelationshipResourceForReference ( $ fullRelationshipReference ) { $ relationshipParts = explode ( '.' , $ fullRelationshipReference ) ; if ( count ( $ relationshipParts ) !== 3 ) { return null ; } if ( $ this -> resourceType ( ) !== array_shift ( $ relationshipParts ) ) { return null ; } $ relationshipName = array_shift ( $ relationshipParts ) ; $ relationshipReference = Arr :: get ( $ this -> mapRelationshipsToIdAndData ( ) , $ relationshipName ) ; if ( $ relationshipReference === null ) { return null ; } if ( Arr :: get ( $ relationshipReference , 'type' ) === array_shift ( $ relationshipParts ) ) { return new RelationshipResource ( $ relationshipName , $ relationshipReference ) ; } return null ; }
|
Get a relationship resource for a fully qualified reference .
|
3,640
|
public function setStateListener ( $ event , $ listener ) { $ js = sprintf ( 'uLogin.setStateListener("%s", "%s", %s);' , $ this -> id , $ event , $ listener ) ; $ this -> getView ( ) -> registerJs ( $ js ) ; return $ this ; }
|
Sets the event handler in the event ulogin
|
3,641
|
public function call ( array $ params ) { $ this -> initResolver ( ) ; $ defaults = array_merge ( array ( 'format' => $ this -> format ) , $ this -> defaultParams ) ; $ this -> resolver -> setDefaults ( $ defaults ) ; $ this -> resolver -> setMandatory ( array ( 'module' => 'API' , 'method' => $ this -> name ( ) ) ) ; return $ this -> piwikClient -> call ( $ this -> url ( ) , $ this -> resolver -> resolve ( $ params ) ) ; }
|
calls piwik api
|
3,642
|
public function dropSchemaFor ( StreamName $ streamName , $ returnSql = false ) { $ dropTable = new DropTable ( $ this -> getTable ( $ streamName ) ) ; if ( $ returnSql ) { return $ dropTable -> getSqlString ( $ this -> dbAdapter -> getPlatform ( ) ) ; } $ this -> dbAdapter -> getDriver ( ) -> getConnection ( ) -> execute ( $ dropTable -> getSqlString ( $ this -> dbAdapter -> getPlatform ( ) ) ) ; }
|
Drops a stream table
|
3,643
|
protected function insertEvent ( StreamName $ streamName , DomainEvent $ e ) { $ eventData = array ( 'event_id' => $ e -> uuid ( ) -> toString ( ) , 'version' => $ e -> version ( ) , 'event_name' => $ e -> messageName ( ) , 'event_class' => get_class ( $ e ) , 'payload' => Serializer :: serialize ( $ e -> payload ( ) , $ this -> serializerAdapter ) , 'created_at' => $ e -> createdAt ( ) -> format ( \ DateTime :: ISO8601 ) ) ; foreach ( $ e -> metadata ( ) as $ key => $ value ) { $ eventData [ $ key ] = ( string ) $ value ; } $ tableGateway = $ this -> getTablegateway ( $ streamName ) ; $ tableGateway -> insert ( $ eventData ) ; }
|
Insert an event
|
3,644
|
protected function getTablegateway ( StreamName $ streamName ) { if ( ! isset ( $ this -> tableGateways [ $ streamName -> toString ( ) ] ) ) { $ this -> tableGateways [ $ streamName -> toString ( ) ] = new TableGateway ( $ this -> getTable ( $ streamName ) , $ this -> dbAdapter ) ; } return $ this -> tableGateways [ $ streamName -> toString ( ) ] ; }
|
Get the corresponding Tablegateway of the given stream name
|
3,645
|
protected function getTable ( StreamName $ streamName ) { if ( isset ( $ this -> streamTableMap [ $ streamName -> toString ( ) ] ) ) { $ tableName = $ this -> streamTableMap [ $ streamName -> toString ( ) ] ; } else { $ tableName = strtolower ( $ this -> getShortStreamName ( $ streamName ) ) ; if ( strpos ( $ tableName , "_stream" ) === false ) { $ tableName .= "_stream" ; } } return $ tableName ; }
|
Get table name for given stream name
|
3,646
|
private function read ( ) { if ( $ this -> request -> hasParam ( $ this -> sessionName ) ) { return $ this -> request -> readParam ( $ this -> sessionName ) -> ifMatches ( self :: SESSION_ID_REGEX ) ; } elseif ( $ this -> request -> hasCookie ( $ this -> sessionName ) ) { return $ this -> request -> readCookie ( $ this -> sessionName ) -> ifMatches ( self :: SESSION_ID_REGEX ) ; } return null ; }
|
reads session id
|
3,647
|
public function regenerate ( ) : SessionId { $ this -> id = $ this -> create ( ) ; $ this -> response -> addCookie ( Cookie :: create ( $ this -> sessionName , $ this -> id ) -> forPath ( '/' ) ) ; return $ this ; }
|
stores session id for given session name
|
3,648
|
public static function render ( SQL \ Aliased $ aliased ) { $ content = $ aliased -> getContent ( ) ; if ( $ content instanceof Query \ Select ) { $ content = "(" . Select :: render ( $ content ) . ")" ; } else { $ content = Compiler :: name ( $ content ) ; } return Compiler :: expression ( array ( $ content , Compiler :: word ( 'AS' , Compiler :: name ( $ aliased -> getAlias ( ) ) ) ) ) ; }
|
Render SQL for Aliased
|
3,649
|
public function interceptMethodCall ( ProceedingJoinPointInterface $ jointPoint ) { $ time = $ this -> monitor -> getTime ( ) ; if ( $ this -> namePrefix ) { $ name = $ this -> namePrefix ; } else { $ name = get_class ( $ jointPoint -> getTarget ( ) ) ; } if ( $ this -> metricPerMethod ) { $ name .= '.' . $ jointPoint -> getMethodName ( ) ; } try { $ result = $ jointPoint -> proceed ( ) ; $ this -> monitor -> incrementTimer ( $ name . self :: SUFFIX_SUCCESS , $ time ) ; $ this -> monitor -> incrementCounter ( $ name . self :: SUFFIX_SUCCESS ) ; return $ result ; } catch ( Exception $ e ) { $ this -> monitor -> incrementTimer ( $ name . self :: SUFFIX_EXCEPTION , $ time ) ; $ this -> monitor -> incrementCounter ( $ name . self :: SUFFIX_EXCEPTION ) ; throw $ e ; } }
|
In this implementation we measure time and count every method call
|
3,650
|
protected function setValue ( $ value ) { if ( is_string ( $ value ) ) { $ this -> value = $ value ; } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ value ) . "' for argument 'value' given." ) ; } return $ this ; }
|
Sets the condition value .
|
3,651
|
public function getUser ( ) { $ resource = '/users/' . $ this -> userId ; $ response = $ this -> makeAuthenticatedApiRequest ( $ resource ) ; return $ response -> user ; }
|
get a user
|
3,652
|
public function getBadges ( ) { $ uri = $ this -> buildUserResourceUri ( 'badges' ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri ) ; return $ response -> badges ; }
|
Returns badges for a given user .
|
3,653
|
public function getCheckins ( array $ options = array ( ) ) { $ uri = $ this -> buildUserResourceUri ( 'checkins' ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri , $ options ) ; return $ response -> checkins -> items ; }
|
Returns a history of checkins for the authenticated user .
|
3,654
|
public function getFriends ( array $ options = array ( ) ) { $ uri = $ this -> buildUserResourceUri ( 'friends' ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri , $ options ) ; return $ response -> friends -> items ; }
|
Returns an array of a user s friends .
|
3,655
|
public function getTips ( array $ options = array ( ) ) { $ uri = $ this -> buildUserResourceUri ( 'tips' ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri , $ options ) ; return $ response -> tips -> items ; }
|
Returns an array of a user s tips .
|
3,656
|
public function getLists ( array $ options = array ( ) ) { $ uri = $ this -> buildUserResourceUri ( 'lists' ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri , $ options ) ; return $ response -> lists ; }
|
A User s Lists .
|
3,657
|
public function getMayorships ( ) { $ uri = $ this -> buildUserResourceUri ( 'mayorships' ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri ) ; return $ response -> mayorships -> items ; }
|
Returns a user s mayorships .
|
3,658
|
public function getPhotos ( array $ options = array ( ) ) { $ uri = $ this -> buildUserResourceUri ( 'photos' ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri ) ; return $ response -> photos -> items ; }
|
Returns photos from a user .
|
3,659
|
public function getVenueHistory ( array $ options = array ( ) ) { $ uri = $ this -> buildUserResourceUri ( 'venuehistory' ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri ) ; return $ response -> venues -> items ; }
|
Returns a list of all venues visited by the specified user along with how many visits and when they were last there .
|
3,660
|
public function approve ( $ friendId ) { $ uri = $ this -> buildUserResourceUri ( 'approve' , $ friendId ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri ) ; return $ response -> user ; }
|
Approves a pending friend request from another user .
|
3,661
|
public function deny ( $ friendId ) { $ uri = $ this -> buildUserResourceUri ( 'deny' , $ friendId ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri ) ; return $ response -> user ; }
|
Denies a pending friend request from another user .
|
3,662
|
public function request ( $ friendId ) { $ uri = $ this -> buildUserResourceUri ( 'request' , $ friendId ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri ) ; return $ response -> user ; }
|
Sends a friend request to another user . If the other user is a page then the requesting user will automatically start following the page .
|
3,663
|
public function unfriend ( $ friendId ) { $ uri = $ this -> buildUserResourceUri ( 'unfriend' , $ friendId ) ; $ response = $ this -> makeAuthenticatedApiRequest ( $ uri ) ; return $ response -> user ; }
|
Cancels any relationship between the acting user and the specified user Removes a friend unfollows a celebrity or cancels a pending friend request .
|
3,664
|
protected function buildUserResourceUri ( $ resource , $ userId = null ) { $ userId = is_null ( $ userId ) ? $ this -> userId : $ userId ; return '/users/' . $ userId . '/' . $ resource ; }
|
build the resource URI
|
3,665
|
public function & offsetGet ( $ n ) { if ( ! $ this -> offsetExists ( $ n ) ) { throw new IndexNotFoundException ( ( string ) $ n ) ; } return $ this -> data [ $ n ] ; }
|
Get the nth entry .
|
3,666
|
public function addPoint ( array $ point ) { if ( ! isset ( $ point [ 1 ] ) ) { $ point = array ( time ( ) , $ point [ 0 ] ) ; } if ( ! is_integer ( $ point [ 0 ] ) ) { throw new InvalidPointException ( 'Timestamp must be an integer' ) ; } if ( ! is_int ( $ point [ 1 ] ) && ! is_float ( $ point [ 1 ] ) ) { throw new InvalidPointException ( 'Value must be integer or float' ) ; } $ this -> points [ ] = $ point ; return $ this ; }
|
Add a new measure point to the metric .
|
3,667
|
public function changeExtension ( $ extension ) { $ pathname = $ this -> createPathname ( $ this -> getPath ( ) , $ this -> getBasename ( ) , $ extension ) ; return new static ( $ pathname ) ; }
|
Changes file extension .
|
3,668
|
protected function initializeBinding ( Binding $ binding ) { $ binding -> initialize ( $ this -> getBindingType ( $ binding -> getTypeName ( ) ) ) ; $ bindingClass = get_class ( $ binding ) ; if ( ! isset ( $ this -> initializersByBindingClass [ $ bindingClass ] ) ) { $ this -> initializersByBindingClass [ $ bindingClass ] = array ( ) ; foreach ( $ this -> initializers as $ initializer ) { if ( $ initializer -> acceptsBinding ( $ bindingClass ) ) { $ this -> initializersByBindingClass [ $ bindingClass ] [ ] = $ initializer ; } } } foreach ( $ this -> initializersByBindingClass [ $ bindingClass ] as $ initializer ) { $ initializer -> initializeBinding ( $ binding ) ; } }
|
Initializes a binding .
|
3,669
|
public function getAdditionalProperties ( ) { if ( $ this -> decoded_additional_properties === false ) { $ raw = trim ( $ this -> getRawAdditionalProperties ( ) ) ; $ this -> decoded_additional_properties = empty ( $ raw ) ? [ ] : json_decode ( $ raw , true ) ; if ( ! is_array ( $ this -> decoded_additional_properties ) ) { $ this -> decoded_additional_properties = [ ] ; } } return $ this -> decoded_additional_properties ; }
|
Return additional log properties as array .
|
3,670
|
public function & setAdditionalProperties ( array $ value = null ) { $ this -> decoded_additional_properties = false ; $ this -> setRawAdditionalProperties ( json_encode ( $ value ) ) ; return $ this ; }
|
Set attributes value .
|
3,671
|
public function getAdditionalProperty ( $ name , $ default = null ) { $ additional_properties = $ this -> getAdditionalProperties ( ) ; return $ additional_properties && isset ( $ additional_properties [ $ name ] ) ? $ additional_properties [ $ name ] : $ default ; }
|
Returna attribute value .
|
3,672
|
protected function checkFloatTypes ( NumericTypeInterface $ a , NumericTypeInterface $ b ) { $ a1 = ( $ a instanceof FloatType ? $ a : $ a -> asFloatType ( ) ) ; $ b1 = ( $ b instanceof FloatType ? $ b : $ b -> asFloatType ( ) ) ; return [ $ a1 , $ b1 ] ; }
|
Check for float type converting if necessary
|
3,673
|
protected function checkRationalTypes ( NumericTypeInterface $ a , NumericTypeInterface $ b ) { $ a1 = ( $ a instanceof RationalType ? $ a : $ a -> asRational ( ) ) ; $ b1 = ( $ b instanceof RationalType ? $ b : $ b -> asRational ( ) ) ; return [ $ a1 , $ b1 ] ; }
|
Check for rational type converting if necessary
|
3,674
|
public function matchParams ( array $ params ) { $ result = [ ] ; foreach ( $ this -> explodedParams as $ name => list ( $ default , $ pattern , $ patternName ) ) { if ( ! \ array_key_exists ( $ name , $ params ) ) { if ( \ is_null ( $ default ) ) { return false ; } $ currentParam = $ default ; } else { $ currentParam = $ params [ $ name ] ; } if ( ! \ is_null ( $ patternName ) ) { $ patternObj = $ this -> patterns [ $ patternName ] ; try { $ result [ $ name ] = $ patternObj -> toUrl ( $ currentParam ) ; } catch ( PatternException $ exception ) { return false ; } } else { if ( \ is_object ( $ currentParam ) && \ method_exists ( $ currentParam , '__toString' ) ) { $ currentParam = ( string ) $ currentParam ; } if ( ! $ this -> pregMatchMultiType ( $ pattern , $ currentParam ) ) { return false ; } $ result [ $ name ] = $ currentParam ; } } return $ result ; }
|
Returns false or converted params
|
3,675
|
public function resolve ( DefinitionInterface $ definition ) { switch ( true ) { case $ definition instanceof ReferenceDefinitionInterface : return $ this -> container -> get ( $ definition -> getTarget ( ) ) ; case $ definition instanceof ParameterDefinitionInterface : return $ definition -> getValue ( ) ; case $ definition instanceof ObjectDefinitionInterface : $ reflection = new \ ReflectionClass ( $ definition -> getClassName ( ) ) ; $ constructorArguments = $ definition -> getConstructorArguments ( ) ; $ constructorArguments = array_map ( [ $ this , 'resolveSubDefinition' ] , $ constructorArguments ) ; $ service = $ reflection -> newInstanceArgs ( $ constructorArguments ) ; foreach ( $ definition -> getPropertyAssignments ( ) as $ propertyAssignment ) { $ propertyName = $ propertyAssignment -> getPropertyName ( ) ; $ service -> $ propertyName = $ this -> resolveSubDefinition ( $ propertyAssignment -> getValue ( ) ) ; } foreach ( $ definition -> getMethodCalls ( ) as $ methodCall ) { $ methodArguments = $ methodCall -> getArguments ( ) ; $ methodArguments = array_map ( [ $ this , 'resolveSubDefinition' ] , $ methodArguments ) ; call_user_func_array ( [ $ service , $ methodCall -> getMethodName ( ) ] , $ methodArguments ) ; } return $ service ; case $ definition instanceof FactoryCallDefinitionInterface : $ factory = $ definition -> getFactory ( ) ; $ methodName = $ definition -> getMethodName ( ) ; $ arguments = ( array ) $ definition -> getArguments ( ) ; $ arguments = array_map ( [ $ this , 'resolveSubDefinition' ] , $ arguments ) ; if ( is_string ( $ factory ) ) { return call_user_func_array ( [ $ factory , $ methodName ] , $ arguments ) ; } elseif ( $ factory instanceof ReferenceDefinitionInterface ) { $ factory = $ this -> container -> get ( $ factory -> getTarget ( ) ) ; return call_user_func_array ( [ $ factory , $ methodName ] , $ arguments ) ; } throw new InvalidDefinition ( sprintf ( 'Definition "%s" does not return a valid factory' ) ) ; default : throw UnsupportedDefinition :: fromDefinition ( $ definition ) ; } }
|
Resolve a definition and return the resulting value .
|
3,676
|
private function resolveSubDefinition ( $ value ) { if ( is_array ( $ value ) ) { return array_map ( [ $ this , 'resolveSubDefinition' ] , $ value ) ; } elseif ( $ value instanceof DefinitionInterface ) { return $ this -> resolve ( $ value ) ; } return $ value ; }
|
Resolve a variable that can be a sub - definition .
|
3,677
|
public function set ( string $ container , $ object , ConfigInterface $ config = null ) : ContainersInterface { if ( ! $ this -> has ( $ container ) ) { if ( \ is_object ( $ object ) ) { $ this -> setContainer ( $ container , $ object ) ; } else { $ class = '\\DrMVC\\' . $ object ; $ this -> setContainer ( $ container , new $ class ( $ config ) ) ; } } return $ this ; }
|
PSR - 11 set container
|
3,678
|
protected function getControllerClass ( $ name ) { $ controllerClass = $ name ; if ( ! class_exists ( $ name ) ) { $ controllerClass = $ this -> controllerClasspath . '\\' . $ name ; if ( ! class_exists ( $ controllerClass ) ) { $ controllerClass = '\\FatPanda\\Illuminate\\WordPress\\Http\\Controllers\\' . $ name ; if ( ! class_exists ( $ controllerClass ) ) { $ controllerClass = new \ WP_Error ( 'class_not_found' , "Class Not Found: {$name}" ) ; } } } return $ controllerClass ; }
|
Given the classname of a controller seek out a proper namespace ; start with the set controller classpath then move on to the core default then try looking for the class without any classpath at all .
|
3,679
|
private function invokeControllerAction ( $ controllerClassNamed , $ actionNamed , array $ givenArgs = [ ] ) { if ( is_wp_error ( $ controllerClass = $ this -> getControllerClass ( $ controllerClassNamed ) ) ) { return $ controllerClass ; } $ reflection = new \ ReflectionClass ( $ controllerClass ) ; $ controller = new $ controllerClass ( $ this ) ; if ( ! $ reflection -> hasMethod ( $ actionNamed ) ) { return new \ WP_Error ( 'method_not_found' , "Method Not Found: {$controllerClassNamed}@{$actionNamed}" , [ 'status' => 404 ] ) ; } $ method = $ reflection -> getMethod ( $ actionNamed ) ; $ args = [ ] ; if ( ! empty ( $ givenArgs ) ) { $ args [ ] = $ givenArgs [ 0 ] ; } if ( count ( $ givenArgs ) > 1 ) { $ params = $ method -> getParameters ( ) ; for ( $ i = 1 ; $ i < count ( $ params ) ; $ i ++ ) { $ param = $ params [ $ i ] ; if ( ! $ param -> hasType ( ) ) { if ( $ this -> getPlugin ( ) -> bound ( $ param -> name ) ) { $ args [ ] = $ this -> getPlugin ( ) -> make ( $ param -> name ) ; } } else { $ class = $ param -> getClass ( ) ; if ( $ class -> isSubclassOf ( \ Illuminate \ Container \ Container :: class ) ) { $ args [ ] = $ this -> getPlugin ( ) ; } else { $ args [ ] = $ this -> getPlugin ( ) -> make ( $ class -> name ) ; } } } } return $ method -> invokeArgs ( $ controller , $ args ) ; }
|
Invoke the given action on the given class after resolving an existing Class that matches the given class as named ; map arguments to controller action by dependency injection .
|
3,680
|
function resource ( $ name , $ controllerClass , $ options = [ ] ) { if ( empty ( $ options [ 'idString' ] ) ) { $ options [ 'idString' ] = '{id}' ; } $ actions = array_keys ( $ this -> resourceActions ) ; if ( ! empty ( $ options [ 'only' ] ) ) { $ actions = $ options [ 'only' ] ; } else if ( ! empty ( $ options [ 'except' ] ) ) { $ actions = array_diff ( $ actions , $ options [ 'except' ] ) ; } if ( ! is_array ( $ actions ) ) { $ actions = [ $ actions ] ; } $ group = new RouteGroup ( ) ; foreach ( $ actions as $ action ) { if ( empty ( $ this -> resourceActions [ $ action ] ) ) { throw new \ Exception ( "Action [$action] is unrecognized; please use one of: " . implode ( ',' , array_keys ( $ this -> resourceActions ) ) ) ; } $ def = $ this -> resourceActions [ $ action ] ; $ route = call_user_func_array ( [ $ this , 'route' ] , [ $ def [ 'methods' ] , $ name . sprintf ( $ def [ 'route' ] , $ options [ 'idString' ] ) , function ( ) use ( $ controllerClass , $ action ) { return $ this -> invokeControllerAction ( $ controllerClass , $ action , func_get_args ( ) ) ; } , $ options ] ) ; if ( ! empty ( $ def [ 'args' ] ) ) { $ route -> args ( $ def [ 'args' ] ) ; } $ group [ ] = $ route ; } return $ group ; }
|
Create a resource endpoint set bound to the given controller for handling all requests
|
3,681
|
public function unserialize ( $ data ) { $ injector = \ Injector :: inst ( ) ; $ extraData = null ; if ( empty ( self :: $ objectConstructorReflectionMethods [ __CLASS__ ] ) ) { self :: $ objectConstructorReflectionMethods [ __CLASS__ ] = new \ ReflectionMethod ( __CLASS__ , '__construct' ) ; } if ( empty ( self :: $ classConfigs [ __CLASS__ ] ) ) { self :: $ classConfigs [ __CLASS__ ] = $ injector -> getConfigLocator ( ) -> locateConfigFor ( __CLASS__ ) ; } if ( $ this instanceof ExtraDataInterface ) { $ unserialized = \ Heystack \ Core \ unserialize ( $ data ) ; self :: $ objectConstructorReflectionMethods [ __CLASS__ ] -> invoke ( $ this , $ unserialized [ 0 ] ) ; $ extraData = $ unserialized [ 1 ] ; } else { self :: $ objectConstructorReflectionMethods [ __CLASS__ ] -> invoke ( $ this , \ Heystack \ Core \ unserialize ( $ data ) ) ; } if ( self :: $ classConfigs [ __CLASS__ ] ) { $ injector -> load ( [ __CLASS__ => self :: $ classConfigs [ __CLASS__ ] ] ) ; } $ injector -> inject ( $ this , __CLASS__ ) ; if ( $ extraData ) { $ this -> setExtraData ( $ extraData ) ; } }
|
This routine simulates what would happen when a object is constructed
|
3,682
|
public function add ( string $ rel , HttpUri $ uri ) : Link { $ link = new Link ( $ rel , $ uri ) ; if ( isset ( $ this -> links [ $ rel ] ) ) { if ( ! is_array ( $ this -> links [ $ rel ] ) ) { $ this -> links [ $ rel ] = [ $ this -> links [ $ rel ] ] ; } $ this -> links [ $ rel ] [ ] = $ link ; } else { $ this -> links [ $ rel ] = $ link ; } return $ link ; }
|
adds link to collection of links
|
3,683
|
public function with ( string $ rel ) : array { if ( isset ( $ this -> links [ $ rel ] ) ) { if ( is_array ( $ this -> links [ $ rel ] ) ) { return $ this -> links [ $ rel ] ; } return [ $ this -> links [ $ rel ] ] ; } return [ ] ; }
|
returns all links with given relation
|
3,684
|
public function getIterator ( ) : \ Traversable { $ result = [ ] ; foreach ( $ this -> links as $ link ) { if ( is_array ( $ link ) ) { $ result = array_merge ( $ result , $ link ) ; } else { $ result [ ] = $ link ; } } return new \ ArrayIterator ( $ result ) ; }
|
allows to iterate over all resources
|
3,685
|
private function registerServices ( ) { $ this -> app -> singleton ( 'pluggables' , function ( $ app ) { return new Pluggables ( $ app [ 'config' ] , $ app [ 'files' ] ) ; } ) ; $ this -> app -> booting ( function ( $ app ) { $ app [ 'pluggables' ] -> register ( ) ; } ) ; }
|
Register services of the package .
|
3,686
|
private function registerRepository ( ) { $ this -> app -> singleton ( 'migration.repository' , function ( $ app ) { $ table = $ app [ 'config' ] [ 'database.migrations' ] ; return new DatabaseMigrationRepository ( $ app [ 'db' ] , $ table ) ; } ) ; }
|
Register the repository service .
|
3,687
|
private function registerConsoleCommands ( ) { $ this -> registerMakeCommand ( ) ; $ this -> registerEnableCommand ( ) ; $ this -> registerDisableCommand ( ) ; $ this -> registerListCommand ( ) ; $ this -> registerMigrateCommand ( ) ; $ this -> registerMigrateRefreshCommand ( ) ; $ this -> registerMakeMigrationCommand ( ) ; $ this -> registerMakeRequestCommand ( ) ; $ this -> registerMakeModelCommand ( ) ; $ this -> commands ( [ 'pluggables.makeMigration' , 'pluggables.enable' , 'pluggables.disable' , 'pluggables.list' , 'pluggables.make' , 'pluggables.make.request' , 'pluggables.make.model' , 'pluggables.migrate' , 'pluggables.migrateRefresh' , ] ) ; }
|
Register the package console commands .
|
3,688
|
public static function getPluginDirsInDir ( $ dir = null ) { if ( $ dir === null ) { $ dir = self :: $ config [ 'pluginspath' ] ; } $ plugin_dirs = array ( ) ; $ handle = opendir ( $ dir ) ; if ( $ handle ) { while ( $ plugin_dir = readdir ( $ handle ) ) { if ( substr ( $ plugin_dir , 0 , 1 ) !== '.' && is_dir ( $ dir . $ plugin_dir ) ) { $ plugin_dirs [ ] = $ plugin_dir ; } } } sort ( $ plugin_dirs ) ; return $ plugin_dirs ; }
|
Returns a list of plugin directory names from a base directory . Copied from 1 . 9 core due to elgg_get_plugin_ids_in_dir removal in 1 . 9
|
3,689
|
protected function createConsoleRequest ( ) : Request { $ requestStack = $ this -> getRequestStack ( ) ; $ request = $ requestStack -> getCurrentRequest ( ) ; if ( ! $ request instanceof Request ) { $ request = new Request ( ) ; $ requestStack -> push ( $ request ) ; } $ request -> attributes -> set ( 'pbjx_console' , true ) ; $ request -> attributes -> set ( 'pbjx_bind_unrestricted' , true ) ; return $ request ; }
|
Some pbjx binders validators etc . expect a request to exist . Create one if nothing has been created yet .
|
3,690
|
public function lastTrackPoint ( ) : TrackPoint { $ lastTrackPoint = end ( $ this -> trackPoints ) ; if ( ! $ lastTrackPoint instanceof TrackPoint ) { throw new \ OutOfBoundsException ( 'No track points points defined.' ) ; } reset ( $ this -> trackPoints ) ; return $ lastTrackPoint ; }
|
Get the last track point .
|
3,691
|
public function duration ( ) { $ start = $ this -> startDateTime ( ) ; $ end = $ this -> endDateTime ( ) ; $ dateDifference = $ start -> diff ( $ end ) ; $ dateInterval = new DateInterval ( 'PT1S' ) ; $ dateInterval -> y = $ dateDifference -> y ; $ dateInterval -> m = $ dateDifference -> m ; $ dateInterval -> d = $ dateDifference -> d ; $ dateInterval -> h = $ dateDifference -> h ; $ dateInterval -> i = $ dateDifference -> i ; $ dateInterval -> s = $ dateDifference -> s ; $ dateInterval -> invert = $ dateDifference -> invert ; $ dateInterval -> days = $ dateDifference -> days ; return $ dateInterval ; }
|
Get the duration of the track .
|
3,692
|
public function length ( ) : float { if ( $ this -> length === 0 ) { $ this -> length = $ this -> recomputeLength ( ) ; } return $ this -> length ; }
|
Get the length of the track in meters .
|
3,693
|
private function recomputeLength ( ) : float { $ this -> length = 0 ; $ trackPoints = $ this -> trackPoints ( ) ; $ trackPointsCount = count ( $ trackPoints ) ; if ( $ trackPointsCount < 2 ) { return 0 ; } for ( $ i = 1 ; $ i < $ trackPointsCount ; $ i ++ ) { $ previousTrack = $ trackPoints [ $ i - 1 ] ; $ currentTrack = $ trackPoints [ $ i ] ; $ this -> length += $ currentTrack -> distanceFromPoint ( $ previousTrack ) ; } $ this -> length = round ( $ this -> length , 6 ) ; return $ this -> length ; }
|
Recompute the length of the track .
|
3,694
|
public function verifyCode ( $ clientID , $ clientSecret , $ redirectURI , $ code ) { $ response = $ this -> get ( 'oauth2/access_token' , [ 'client_id' => $ clientID , 'client_secret' => $ clientSecret , 'grant_type' => 'authorization_code' , 'redirect_uri' => $ redirectURI , 'code' => $ code ] ) ; $ result = \ false ; if ( ! empty ( $ response [ 'access_token' ] ) ) { $ result = $ response [ 'access_token' ] ; } return $ result ; }
|
Second step of OAuth . This verifies the code obtained by the first function . If valid this function returns the user s access token which you need to save for all upcoming API requests .
|
3,695
|
private function setArray ( $ object ) : array { $ data = [ ] ; $ configurationObject = $ this -> configuration -> getConfigurationObjectForClass ( new ClassName ( get_class ( $ object ) ) ) ; $ identifier = $ configurationObject -> getIdentifier ( ) ; if ( $ identifier !== '' ) { $ data [ $ this -> configuration -> getIdentifierAttribute ( ) ] = $ identifier ; } foreach ( $ configurationObject -> getAttributes ( ) as $ attribute ) { $ type = $ configurationObject -> getTypeForAttribute ( $ attribute ) ; $ data = $ this -> processSerializeForType ( $ type , $ object , $ data , $ attribute ) ; } return $ data ; }
|
Create array from object
|
3,696
|
protected function checkNullForAttribute ( $ value , $ attribute ) : bool { if ( $ value === null ) { return true ; } if ( is_array ( $ value ) === true && $ value === [ ] ) { return true ; } if ( $ value instanceof \ Countable && count ( $ value ) === 0 ) { return true ; } return false ; }
|
Set attribute with value when value is not considered as a null value
|
3,697
|
public function extension ( $ idExtension ) : ExtensionInterface { if ( $ this -> hasExtension ( $ idExtension ) !== true ) { throw new \ OutOfBoundsException ( sprintf ( 'Extension "%s" not found.' , $ idExtension ) ) ; } return $ this -> extensions [ $ idExtension ] ; }
|
Get an extension by ID .
|
3,698
|
public function distanceFromPoint ( TrackPoint $ trackPoint ) : float { $ earthRadius = 6371000 ; $ latFrom = deg2rad ( $ this -> latitude ( ) ) ; $ lonFrom = deg2rad ( $ this -> longitude ( ) ) ; $ latTo = deg2rad ( $ trackPoint -> latitude ( ) ) ; $ lonTo = deg2rad ( $ trackPoint -> longitude ( ) ) ; $ latDelta = $ latTo - $ latFrom ; $ lonDelta = $ lonTo - $ lonFrom ; $ angle = 2 * asin ( sqrt ( pow ( sin ( $ latDelta / 2 ) , 2 ) + cos ( $ latFrom ) * cos ( $ latTo ) * pow ( sin ( $ lonDelta / 2 ) , 2 ) ) ) ; return $ angle * $ earthRadius ; }
|
Get the distance between this point and another point in meters .
|
3,699
|
public static function newFromTimeString ( $ timeString ) { try { $ dateTime = new DateTime ( $ timeString ) ; } catch ( \ Exception $ e ) { throw new InvalidArgumentException ( 'Time string must be valid, see DateTime for documentation' ) ; } return new self ( $ dateTime -> format ( 'G' ) , $ dateTime -> format ( 'i' ) ) ; }
|
Creates new DailyDateRepetition from string readable by DateTime
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.