idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
51,500
public function customFieldsGet ( $ entity , $ code ) { if ( empty ( $ code ) ) { throw new \ InvalidArgumentException ( 'Parameter `code` must be not empty' ) ; } if ( empty ( $ entity ) || ! in_array ( $ entity , [ 'customer' , 'order' ] ) ) { throw new \ InvalidArgumentException ( 'Parameter `entity` must contain a data & value must be `order` or `customer`' ) ; } return $ this -> client -> makeRequest ( "/custom-fields/$entity/$code" , "GET" ) ; }
Get custom field
51,501
public function customDictionariesEdit ( $ customDictionary ) { if ( ! count ( $ customDictionary ) || empty ( $ customDictionary [ 'code' ] ) || empty ( $ customDictionary [ 'elements' ] ) ) { throw new \ InvalidArgumentException ( 'Parameter `dictionary` must contain a data & fields `code` & `elemets` must be set' ) ; } return $ this -> client -> makeRequest ( "/custom-fields/dictionaries/{$customDictionary['code']}/edit" , "POST" , [ 'customDictionary' => json_encode ( $ customDictionary ) ] ) ; }
Edit custom dictionary
51,502
public function deliveryTracking ( $ code , array $ statusUpdate ) { if ( empty ( $ code ) ) { throw new \ InvalidArgumentException ( 'Parameter `code` must be set' ) ; } if ( ! count ( $ statusUpdate ) ) { throw new \ InvalidArgumentException ( 'Parameter `statusUpdate` must contains a data' ) ; } return $ this -> client -> makeRequest ( sprintf ( '/delivery/generic/%s/tracking' , $ code ) , "POST" , [ 'statusUpdate' => json_encode ( $ statusUpdate ) ] ) ; }
Delivery tracking update
51,503
public function ordersPaymentCreate ( array $ payment , $ site = null ) { if ( ! count ( $ payment ) ) { throw new \ InvalidArgumentException ( 'Parameter `payment` must contains a data' ) ; } return $ this -> client -> makeRequest ( '/orders/payments/create' , "POST" , $ this -> fillSite ( $ site , [ 'payment' => json_encode ( $ payment ) ] ) ) ; }
Create an order payment
51,504
public function ordersPaymentEdit ( array $ payment , $ by = 'id' , $ site = null ) { if ( ! count ( $ payment ) ) { throw new \ InvalidArgumentException ( 'Parameter `payment` must contains a data' ) ; } $ this -> checkIdParameter ( $ by ) ; if ( ! array_key_exists ( $ by , $ payment ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Order array must contain the "%s" parameter.' , $ by ) ) ; } return $ this -> client -> makeRequest ( sprintf ( '/orders/payments/%s/edit' , $ payment [ $ by ] ) , "POST" , $ this -> fillSite ( $ site , [ 'payment' => json_encode ( $ payment ) , 'by' => $ by ] ) ) ; }
Edit an order payment
51,505
public function makeRequest ( $ path , $ method , array $ parameters = [ ] , $ fullPath = false ) { $ allowedMethods = [ self :: METHOD_GET , self :: METHOD_POST ] ; if ( ! in_array ( $ method , $ allowedMethods , false ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Method "%s" is not valid. Allowed methods are %s' , $ method , implode ( ', ' , $ allowedMethods ) ) ) ; } $ parameters = array_merge ( $ this -> defaultParameters , $ parameters ) ; $ url = $ fullPath ? $ path : $ this -> url . $ path ; if ( self :: METHOD_GET === $ method && count ( $ parameters ) ) { $ url .= '?' . http_build_query ( $ parameters , '' , '&' ) ; } $ curlHandler = curl_init ( ) ; curl_setopt ( $ curlHandler , CURLOPT_URL , $ url ) ; curl_setopt ( $ curlHandler , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ curlHandler , CURLOPT_FOLLOWLOCATION , 1 ) ; curl_setopt ( $ curlHandler , CURLOPT_FAILONERROR , false ) ; curl_setopt ( $ curlHandler , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt ( $ curlHandler , CURLOPT_SSL_VERIFYHOST , false ) ; curl_setopt ( $ curlHandler , CURLOPT_TIMEOUT , 30 ) ; curl_setopt ( $ curlHandler , CURLOPT_CONNECTTIMEOUT , 30 ) ; if ( self :: METHOD_POST === $ method ) { curl_setopt ( $ curlHandler , CURLOPT_POST , true ) ; curl_setopt ( $ curlHandler , CURLOPT_POSTFIELDS , $ parameters ) ; } $ responseBody = curl_exec ( $ curlHandler ) ; $ statusCode = curl_getinfo ( $ curlHandler , CURLINFO_HTTP_CODE ) ; if ( $ statusCode == 503 ) { throw new LimitException ( "Service temporary unavalable" ) ; } $ errno = curl_errno ( $ curlHandler ) ; $ error = curl_error ( $ curlHandler ) ; curl_close ( $ curlHandler ) ; if ( $ errno ) { throw new CurlException ( $ error , $ errno ) ; } return new ApiResponse ( $ statusCode , $ responseBody ) ; }
Make HTTP request
51,506
public function storePricesUpload ( array $ prices , $ site = null ) { if ( ! count ( $ prices ) ) { throw new \ InvalidArgumentException ( 'Parameter `prices` must contains array of the prices' ) ; } return $ this -> client -> makeRequest ( '/store/prices/upload' , "POST" , $ this -> fillSite ( $ site , [ 'prices' => json_encode ( $ prices ) ] ) ) ; }
Upload store prices
51,507
public function storeInventoriesUpload ( array $ offers , $ site = null ) { if ( ! count ( $ offers ) ) { throw new \ InvalidArgumentException ( 'Parameter `offers` must contains array of the offers' ) ; } return $ this -> client -> makeRequest ( '/store/inventories/upload' , "POST" , $ this -> fillSite ( $ site , [ 'offers' => json_encode ( $ offers ) ] ) ) ; }
Upload store inventories
51,508
protected function checkIdParameter ( $ by ) { $ allowedForBy = [ 'externalId' , 'id' ] ; if ( ! in_array ( $ by , $ allowedForBy , false ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Value "%s" for "by" param is not valid. Allowed values are %s.' , $ by , implode ( ', ' , $ allowedForBy ) ) ) ; } return true ; }
Check ID parameter
51,509
protected function fillSite ( $ site , array $ params ) { if ( $ site ) { $ params [ 'site' ] = $ site ; } elseif ( $ this -> siteCode ) { $ params [ 'site' ] = $ this -> siteCode ; } return $ params ; }
Fill params by site value
51,510
public function getChunkPath ( $ index ) { return $ this -> config -> getTempDir ( ) . DIRECTORY_SEPARATOR . basename ( $ this -> identifier ) . '_' . ( int ) $ index ; }
Return chunk path
51,511
public function validateChunk ( ) { $ file = $ this -> request -> getFile ( ) ; if ( ! $ file ) { return false ; } if ( ! isset ( $ file [ 'tmp_name' ] ) || ! isset ( $ file [ 'size' ] ) || ! isset ( $ file [ 'error' ] ) ) { return false ; } if ( $ this -> request -> getCurrentChunkSize ( ) != $ file [ 'size' ] ) { return false ; } if ( $ file [ 'error' ] !== UPLOAD_ERR_OK ) { return false ; } return true ; }
Validate file request
51,512
public function validateFile ( ) { $ totalChunks = $ this -> request -> getTotalChunks ( ) ; $ totalChunksSize = 0 ; for ( $ i = $ totalChunks ; $ i >= 1 ; $ i -- ) { $ file = $ this -> getChunkPath ( $ i ) ; if ( ! file_exists ( $ file ) ) { return false ; } $ totalChunksSize += filesize ( $ file ) ; } return $ this -> request -> getTotalSize ( ) == $ totalChunksSize ; }
Check if file upload is complete
51,513
public function deleteChunks ( ) { $ totalChunks = $ this -> request -> getTotalChunks ( ) ; for ( $ i = 1 ; $ i <= $ totalChunks ; $ i ++ ) { $ path = $ this -> getChunkPath ( $ i ) ; if ( file_exists ( $ path ) ) { unlink ( $ path ) ; } } }
Delete chunks dir
51,514
public function send ( SenderManagerContract $ sender ) { $ model = app ( 'notifynder.resolver.model' ) -> getModel ( Notification :: class ) ; $ table = ( new $ model ( ) ) -> getTable ( ) ; $ this -> database -> beginTransaction ( ) ; $ stackId = $ this -> database -> table ( $ table ) -> max ( 'stack_id' ) + 1 ; foreach ( $ this -> notifications as $ key => $ notification ) { $ this -> notifications [ $ key ] = $ this -> notifications [ $ key ] -> toDbArray ( ) ; $ this -> notifications [ $ key ] [ 'stack_id' ] = $ stackId ; } $ insert = $ this -> database -> table ( $ table ) -> insert ( $ this -> notifications ) ; $ this -> database -> commit ( ) ; return ( bool ) $ insert ; }
Send all notifications .
51,515
protected function bindContracts ( ) { $ this -> app -> bind ( NotifynderManagerContract :: class , 'notifynder' ) ; $ this -> app -> bind ( SenderManagerContract :: class , 'notifynder.sender' ) ; $ this -> app -> bind ( ConfigContract :: class , 'notifynder.config' ) ; }
Bind contracts .
51,516
public function registerSenders ( ) { app ( 'notifynder' ) -> extend ( 'sendSingle' , function ( array $ notifications ) { return new SingleSender ( $ notifications ) ; } ) ; app ( 'notifynder' ) -> extend ( 'sendMultiple' , function ( array $ notifications ) { return new MultipleSender ( $ notifications ) ; } ) ; app ( 'notifynder' ) -> extend ( 'sendOnce' , function ( array $ notifications ) { return new OnceSender ( $ notifications ) ; } ) ; }
Register the default senders .
51,517
protected function publishMigration ( $ filename ) { $ extension = '.php' ; $ filename = trim ( $ filename , $ extension ) . $ extension ; $ stub = __DIR__ . '/../migrations/' . $ filename ; $ target = $ this -> getMigrationFilepath ( $ filename ) ; $ this -> publishes ( [ $ stub => $ target ] , 'migrations' ) ; }
Publish a single migration file .
51,518
public function parse ( $ notification ) { $ category = $ notification -> category ; if ( is_null ( $ category ) ) { throw ( new ModelNotFoundException ) -> setModel ( NotificationCategory :: class , $ notification -> category_id ) ; } $ text = $ category -> template_body ; $ specialValues = $ this -> getValues ( $ text ) ; if ( count ( $ specialValues ) > 0 ) { $ specialValues = array_filter ( $ specialValues , function ( $ value ) use ( $ notification ) { return ( ( is_array ( $ notification ) && isset ( $ notification [ $ value ] ) ) || ( is_object ( $ notification ) && isset ( $ notification -> $ value ) ) ) || starts_with ( $ value , [ 'extra.' , 'to.' , 'from.' ] ) ; } ) ; foreach ( $ specialValues as $ replacer ) { $ replace = $ this -> mixedGet ( $ notification , $ replacer ) ; if ( empty ( $ replace ) && notifynder_config ( ) -> isStrict ( ) ) { throw new ExtraParamsException ( "The following [$replacer] param required from your category is missing." ) ; } $ text = $ this -> replace ( $ text , $ replace , $ replacer ) ; } } return $ text ; }
Parse a notification and return the body text .
51,519
protected function replace ( $ body , $ valueMatch , $ replacer ) { $ body = str_replace ( '{' . $ replacer . '}' , $ valueMatch , $ body ) ; return $ body ; }
Replace a single placeholder .
51,520
public function category ( $ category ) { $ categoryId = NotificationCategory :: getIdByCategory ( $ category ) ; $ this -> setNotificationData ( 'category_id' , $ categoryId ) ; return $ this ; }
Set the category for this notification .
51,521
public function expire ( Carbon $ datetime ) { TypeChecker :: isDate ( $ datetime ) ; $ carbon = new Carbon ( $ datetime ) ; $ this -> setNotificationData ( 'expires_at' , $ carbon ) ; return $ this ; }
Set the expire date for this notification .
51,522
public function setDates ( ) { $ date = Carbon :: now ( ) ; $ this -> setNotificationData ( 'updated_at' , $ date ) ; $ this -> setNotificationData ( 'created_at' , $ date ) ; }
Set updated_at and created_at fields .
51,523
public function setField ( $ key , $ value ) { $ additionalFields = notifynder_config ( ) -> getAdditionalFields ( ) ; if ( in_array ( $ key , $ additionalFields ) ) { $ this -> setNotificationData ( $ key , $ value ) ; } return $ this ; }
Set a single field value .
51,524
protected function setEntityData ( $ entity , $ property ) { if ( is_array ( $ entity ) && count ( $ entity ) == 2 ) { TypeChecker :: isString ( $ entity [ 0 ] ) ; TypeChecker :: isNumeric ( $ entity [ 1 ] ) ; $ type = $ entity [ 0 ] ; $ id = $ entity [ 1 ] ; } elseif ( $ entity [ 0 ] instanceof Model ) { $ type = $ entity [ 0 ] -> getMorphClass ( ) ; $ id = $ entity [ 0 ] -> getKey ( ) ; } else { TypeChecker :: isNumeric ( $ entity [ 0 ] ) ; $ type = notifynder_config ( ) -> getNotifiedModel ( ) ; $ id = $ entity [ 0 ] ; } $ this -> setNotificationData ( "{$property}_type" , $ type ) ; $ this -> setNotificationData ( "{$property}_id" , $ id ) ; }
Set polymorphic model values .
51,525
public function getNotification ( ) { if ( ! $ this -> notification -> isValid ( ) ) { throw new UnvalidNotificationException ( $ this -> notification ) ; } $ this -> setDates ( ) ; return $ this -> notification ; }
Get the current notification .
51,526
public function getNotifications ( ) { if ( count ( $ this -> notifications ) == 0 ) { $ this -> addNotification ( $ this -> getNotification ( ) ) ; } return $ this -> notifications ; }
Get all notifications .
51,527
public function loop ( $ data , Closure $ callback ) { TypeChecker :: isIterable ( $ data ) ; foreach ( $ data as $ key => $ value ) { $ builder = new static ( ) ; $ callback ( $ builder , $ value , $ key ) ; $ this -> addNotification ( $ builder -> getNotification ( ) ) ; } return $ this ; }
Loop over data and call the callback with a new Builder instance and the key and value of the iterated data .
51,528
public function send ( SenderManagerContract $ sender ) { $ success = true ; foreach ( $ this -> notifications as $ notification ) { $ query = $ this -> getQuery ( $ notification ) ; if ( ! $ query -> exists ( ) ) { $ success = $ sender -> send ( [ $ notification ] ) ? $ success : false ; continue ; } $ success = $ query -> firstOrFail ( ) -> resend ( ) ? $ success : false ; } return $ success ; }
Send the notification once .
51,529
protected function getQuery ( Notification $ notification ) { $ query = $ this -> getQueryInstance ( ) ; $ query -> where ( 'from_id' , $ notification -> from_id ) -> where ( 'from_type' , $ notification -> from_type ) -> where ( 'to_id' , $ notification -> to_id ) -> where ( 'to_type' , $ notification -> to_type ) -> where ( 'category_id' , $ notification -> category_id ) ; $ extra = $ notification -> extra ; if ( ! is_null ( $ extra ) && ! empty ( $ extra ) ) { if ( is_array ( $ extra ) ) { $ extra = json_encode ( $ extra ) ; } $ query -> where ( 'extra' , $ extra ) ; } return $ query ; }
Get the base query .
51,530
public function getNotifications ( $ limit = null , $ order = 'desc' ) { $ query = $ this -> getNotificationRelation ( ) -> orderBy ( 'created_at' , $ order ) ; if ( ! is_null ( $ limit ) ) { $ query -> limit ( $ limit ) ; } return $ query -> get ( ) ; }
Get all Notifications ordered by creation and optional limit .
51,531
public function getNotificationsNotRead ( $ limit = null , $ order = 'desc' ) { $ query = $ this -> getNotificationRelation ( ) -> byRead ( 0 ) -> orderBy ( 'created_at' , $ order ) ; if ( ! is_null ( $ limit ) ) { $ query -> limit ( $ limit ) ; } return $ query -> get ( ) ; }
Get all unread Notifications .
51,532
public function send ( SenderManagerContract $ sender ) { $ model = app ( 'notifynder.resolver.model' ) -> getModel ( Notification :: class ) ; $ notification = new $ model ( $ this -> notification ) ; return $ notification -> save ( ) ; }
Send the single notification .
51,533
public function overlaps ( \ DateTime $ start , \ DateTime $ end ) { $ overlaps = FALSE ; if ( $ this -> dateIsEarlier ( $ start ) && ( $ this -> dateIsInRange ( $ end ) || $ this -> dateIsLater ( $ end ) ) ) { $ overlaps = TRUE ; } elseif ( $ this -> dateIsInRange ( $ start ) && ( $ this -> dateIsInRange ( $ end ) || $ this -> dateIsLater ( $ end ) ) ) { $ overlaps = TRUE ; } return $ overlaps ; }
Returns true if the event overlaps at all with the time period within the start and end time .
51,534
public function dateIsInRange ( \ DateTime $ date ) { $ dateInRange = FALSE ; $ t1 = $ this -> start_date -> getTimeStamp ( ) ; $ t2 = $ this -> end_date -> getTimeStamp ( ) ; $ t3 = $ date -> getTimeStamp ( ) ; if ( ( $ t3 >= $ t1 ) && ( $ t3 <= $ t2 ) ) { $ dateInRange = TRUE ; } return $ dateInRange ; }
Checks if date supplied is in range of event
51,535
public function dateIsEarlier ( \ DateTime $ date ) { $ dateEarlier = FALSE ; $ t1 = $ this -> start_date -> getTimeStamp ( ) ; $ t3 = $ date -> getTimeStamp ( ) ; if ( $ t3 < $ t1 ) { $ dateEarlier = TRUE ; } return $ dateEarlier ; }
Checks if the date supplied starts earlier than our event
51,536
public function dateIsLater ( \ DateTime $ date ) { $ dateLater = FALSE ; $ t2 = $ this -> end_date -> getTimeStamp ( ) ; $ t4 = $ date -> getTimestamp ( ) ; if ( $ t2 < $ t4 ) { $ dateLater = TRUE ; } return $ dateLater ; }
Checks if the date supplied ends after our event ends
51,537
public function endsLater ( \ DateTime $ date ) { $ later = FALSE ; $ t2 = $ this -> end_date -> getTimeStamp ( ) ; $ t4 = $ date -> getTimestamp ( ) ; if ( $ t2 > $ t4 ) { $ later = TRUE ; } return $ later ; }
Checks if our event ends after the date supplied
51,538
public function startsEarlier ( \ DateTime $ date ) { $ earlier = FALSE ; $ t1 = $ this -> start_date -> getTimeStamp ( ) ; $ t3 = $ date -> getTimestamp ( ) ; if ( $ t1 < $ t3 ) { $ earlier = TRUE ; } return $ earlier ; }
Checks if our event starts earlier than the date supplied
51,539
public function saveEvent ( Store $ store , $ granularity = AbstractEvent :: BAT_HOURLY ) { return $ store -> storeEvent ( $ this , $ granularity ) ; }
Saves an event using the Store object
51,540
public static function divide ( \ DateTime $ start_date , \ DateTime $ end_date , \ DateInterval $ duration ) { $ temp_end_date = clone ( $ end_date ) ; $ temp_end_date -> add ( new \ DateInterval ( 'PT1M' ) ) ; $ duration_seconds = $ duration -> d * 86400 + $ duration -> h * 3600 + $ duration -> i * 60 + $ duration -> s ; $ diff = $ start_date -> diff ( $ temp_end_date ) ; $ diff_seconds = $ diff -> days * 86400 + $ diff -> h * 3600 + $ diff -> i * 60 + $ diff -> s ; return $ diff_seconds / $ duration_seconds ; }
Return the number of times a duration fits into the start and end date taking into account BAT s consideration that the end time for a BAT event includes that last minute .
51,541
public function getEvents ( \ DateTime $ start_date , \ DateTime $ end_date , $ reset = TRUE ) { if ( $ reset || empty ( $ this -> itemized_events ) ) { $ this -> itemized_events = $ this -> getEventsItemized ( $ start_date , $ end_date ) ; } return $ this -> getEventsNormalized ( $ start_date , $ end_date , $ this -> itemized_events ) ; }
Given a start and end time will retrieve events from the defined store .
51,542
public function getStates ( \ DateTime $ start_date , \ DateTime $ end_date , $ reset = TRUE ) { $ events = $ this -> getEvents ( $ start_date , $ end_date , $ reset ) ; $ states = array ( ) ; foreach ( $ events as $ unit => $ unit_events ) { foreach ( $ unit_events as $ event ) { $ states [ $ unit ] [ $ event -> getValue ( ) ] = $ event -> getValue ( ) ; } } return $ states ; }
Given a start and end time this will return the states units find themselves in for that range .
51,543
public function getMatchingUnits ( \ DateTime $ start_date , \ DateTime $ end_date , $ valid_states , $ constraints = array ( ) , $ intersect = FALSE , $ reset = TRUE ) { $ units = array ( ) ; $ response = new CalendarResponse ( $ start_date , $ end_date , $ valid_states ) ; $ keyed_units = $ this -> keyUnitsById ( ) ; $ states = $ this -> getStates ( $ start_date , $ end_date , $ reset ) ; foreach ( $ states as $ unit => $ unit_states ) { $ current_states = array_keys ( $ unit_states ) ; if ( $ intersect ) { $ remaining_states = array_intersect ( $ current_states , $ valid_states ) ; } else { $ remaining_states = array_diff ( $ current_states , $ valid_states ) ; } if ( ( count ( $ remaining_states ) == 0 && ! $ intersect ) || ( count ( $ remaining_states ) > 0 && $ intersect ) ) { $ units [ $ unit ] = $ unit ; $ response -> addMatch ( $ keyed_units [ $ unit ] , CalendarResponse :: VALID_STATE ) ; } else { $ response -> addMiss ( $ keyed_units [ $ unit ] , CalendarResponse :: INVALID_STATE ) ; } $ unit_constraints = $ keyed_units [ $ unit ] -> getConstraints ( ) ; $ response -> applyConstraints ( $ unit_constraints ) ; } $ response -> applyConstraints ( $ constraints ) ; return $ response ; }
Given a date range and a set of valid states it will return all units within the set of valid states . If intersect is set to TRUE a unit will report as matched as long as within the time period requested it finds itself at least once within a valid state . Alternatively units will match ONLY if they find themselves withing the valid states and no other state .
51,544
public function getEventsItemized ( \ DateTime $ start_date , \ DateTime $ end_date , $ granularity = Event :: BAT_HOURLY ) { $ events = array ( ) ; $ keyed_units = $ this -> keyUnitsById ( ) ; $ db_events = $ this -> store -> getEventData ( $ start_date , $ end_date , array_keys ( $ keyed_units ) ) ; $ mock_event = new Event ( $ start_date , $ end_date , new Unit ( 0 , 0 ) , $ this -> default_value ) ; $ itemized = $ mock_event -> itemize ( new EventItemizer ( $ mock_event , $ granularity ) ) ; foreach ( $ db_events as $ unit => $ event ) { $ events [ $ unit ] = $ itemized ; $ events [ $ unit ] [ Event :: BAT_DAY ] = $ this -> itemizeDays ( $ db_events , $ itemized , $ unit , $ keyed_units ) ; if ( isset ( $ itemized [ Event :: BAT_HOUR ] ) || isset ( $ db_events [ $ unit ] [ Event :: BAT_HOUR ] ) ) { $ events [ $ unit ] [ Event :: BAT_HOUR ] = $ this -> itemizeHours ( $ db_events , $ itemized , $ unit , $ keyed_units ) ; } else { $ events [ $ unit ] [ Event :: BAT_HOUR ] = array ( ) ; } if ( isset ( $ itemized [ Event :: BAT_MINUTE ] ) || isset ( $ db_events [ $ unit ] [ Event :: BAT_MINUTE ] ) ) { $ events [ $ unit ] [ Event :: BAT_MINUTE ] = $ this -> itemizeMinutes ( $ db_events , $ itemized , $ unit , $ keyed_units ) ; } else { $ events [ $ unit ] [ Event :: BAT_MINUTE ] = array ( ) ; } } foreach ( $ keyed_units as $ id => $ unit ) { if ( ( isset ( $ events [ $ id ] ) && count ( $ events [ $ id ] ) == 0 ) || ! isset ( $ events [ $ id ] ) ) { $ empty_event = new Event ( $ start_date , $ end_date , $ unit , $ unit -> getDefaultValue ( ) ) ; $ events [ $ id ] = $ empty_event -> itemize ( new EventItemizer ( $ empty_event , $ granularity ) ) ; } } return $ events ; }
Provides an itemized array of events keyed by the unit_id and divided by day hour and minute .
51,545
private function itemizeDays ( $ db_events , $ itemized , $ unit , $ keyed_units ) { $ result = array ( ) ; foreach ( $ itemized [ Event :: BAT_DAY ] as $ year => $ months ) { foreach ( $ months as $ month => $ days ) { if ( isset ( $ db_events [ $ unit ] [ Event :: BAT_DAY ] [ $ year ] [ $ month ] ) ) { foreach ( $ days as $ day => $ value ) { $ result [ $ year ] [ $ month ] [ $ day ] = ( ( int ) $ db_events [ $ unit ] [ Event :: BAT_DAY ] [ $ year ] [ $ month ] [ $ day ] == 0 ? $ keyed_units [ $ unit ] -> getDefaultValue ( ) : ( int ) $ db_events [ $ unit ] [ Event :: BAT_DAY ] [ $ year ] [ $ month ] [ $ day ] ) ; } } else { foreach ( $ days as $ day => $ value ) { $ result [ $ year ] [ $ month ] [ $ day ] = $ keyed_units [ $ unit ] -> getDefaultValue ( ) ; } } } } return $ result ; }
Helper function that cycles through db results and setups the BAT_DAY itemized array
51,546
private function itemizeMinutes ( $ db_events , $ itemized , $ unit , $ keyed_units ) { $ result = array ( ) ; if ( isset ( $ itemized [ Event :: BAT_MINUTE ] ) ) { foreach ( $ itemized [ Event :: BAT_MINUTE ] as $ year => $ months ) { foreach ( $ months as $ month => $ days ) { foreach ( $ days as $ day => $ hours ) { foreach ( $ hours as $ hour => $ minutes ) { foreach ( $ minutes as $ minute => $ value ) { if ( isset ( $ db_events [ $ unit ] [ Event :: BAT_MINUTE ] [ $ year ] [ $ month ] [ $ day ] [ $ hour ] [ $ minute ] ) ) { $ result [ $ year ] [ $ month ] [ $ day ] [ $ hour ] [ $ minute ] = ( ( int ) $ db_events [ $ unit ] [ Event :: BAT_MINUTE ] [ $ year ] [ $ month ] [ $ day ] [ $ hour ] [ $ minute ] == 0 ? $ keyed_units [ $ unit ] -> getDefaultValue ( ) : ( int ) $ db_events [ $ unit ] [ Event :: BAT_MINUTE ] [ $ year ] [ $ month ] [ $ day ] [ $ hour ] [ $ minute ] ) ; } else { $ result [ $ year ] [ $ month ] [ $ day ] [ $ hour ] [ $ minute ] = ( int ) $ keyed_units [ $ unit ] -> getDefaultValue ( ) ; } } } } } } } if ( isset ( $ db_events [ $ unit ] [ Event :: BAT_MINUTE ] ) ) { foreach ( $ db_events [ $ unit ] [ Event :: BAT_MINUTE ] as $ year => $ months ) { foreach ( $ months as $ month => $ days ) { foreach ( $ days as $ day => $ hours ) { foreach ( $ hours as $ hour => $ minutes ) { foreach ( $ minutes as $ minute => $ value ) { $ result [ $ year ] [ $ month ] [ $ day ] [ $ hour ] [ $ minute ] = ( ( int ) $ value == 0 ? $ keyed_units [ $ unit ] -> getDefaultValue ( ) : ( int ) $ value ) ; } ksort ( $ result [ $ year ] [ $ month ] [ $ day ] [ $ hour ] , SORT_NATURAL ) ; } } } } } return $ result ; }
Helper function that cycles through db results and setups the BAT_MINUTE itemized array
51,547
public function groupData ( $ data , $ length ) { $ flipped = array ( ) ; $ e = 0 ; $ j = 0 ; $ old_value = NULL ; foreach ( $ data as $ datum => $ value ) { $ j ++ ; if ( $ j <= $ length ) { if ( ( $ value != $ old_value ) ) { $ e ++ ; $ flipped [ $ e ] [ $ value ] [ $ datum ] = $ datum ; $ old_value = $ value ; } else { $ flipped [ $ e ] [ $ value ] [ $ datum ] = $ datum ; } } } }
A simple utility function that given an array of datum = > value will group results based on those that have the same value . Useful for grouping events based on state .
51,548
protected function getUnitIds ( ) { $ unit_ids = array ( ) ; foreach ( $ this -> units as $ unit ) { $ unit_ids [ ] = $ unit -> getUnitId ( ) ; } return $ unit_ids ; }
Return an array of unit ids from the set of units supplied to the Calendar .
51,549
protected function keyUnitsById ( ) { $ keyed_units = array ( ) ; foreach ( $ this -> units as $ unit ) { $ keyed_units [ $ unit -> getUnitId ( ) ] = $ unit ; } return $ keyed_units ; }
Return an array of units keyed by unit id
51,550
public function respond ( string $ text , $ endSession = false ) : Response { $ outputSpeech = OutputSpeech :: createByText ( $ text ) ; $ this -> responseBody -> outputSpeech = $ outputSpeech ; $ this -> responseBody -> shouldEndSession = $ endSession ; return $ this -> response ; }
Add a plaintext respond to response .
51,551
public function respondSsml ( string $ ssml , $ endSession = false ) : Response { $ outputSpeech = OutputSpeech :: createBySsml ( $ ssml ) ; $ this -> responseBody -> outputSpeech = $ outputSpeech ; $ this -> responseBody -> shouldEndSession = $ endSession ; return $ this -> response ; }
Add a ssml respond to response .
51,552
public function reprompt ( string $ text ) { $ outputSpeech = OutputSpeech :: createByText ( $ text ) ; $ reprompt = new Reprompt ( $ outputSpeech ) ; $ this -> responseBody -> reprompt = $ reprompt ; return $ this -> response ; }
Add a plaintext reprompt to response .
51,553
public function repromptSsml ( string $ ssml ) { $ outputSpeech = OutputSpeech :: createBySsml ( $ ssml ) ; $ reprompt = new Reprompt ( $ outputSpeech ) ; $ this -> responseBody -> reprompt = $ reprompt ; return $ this -> response ; }
Add a ssml reprompt to response .
51,554
public function addSessionAttribute ( string $ key , string $ value ) { $ this -> response -> sessionAttributes [ $ key ] = $ value ; }
Add a new attribute to response session attributes .
51,555
public function supportsApplication ( Request $ request ) : bool { return in_array ( $ request -> getApplicationId ( ) , $ this -> supportedApplicationIds , true ) ; }
Check if the request handler can handle given request from skill .
51,556
public function validate ( Request $ request ) { $ this -> validateTimestamp ( $ request ) ; try { $ this -> validateSignature ( $ request ) ; } catch ( OutdatedCertExceptionException $ e ) { $ this -> validateSignature ( $ request ) ; } }
Validate request data .
51,557
private function validateSignature ( Request $ request ) { if ( null === $ request -> request || ! $ request -> request -> validateSignature ( ) ) { return ; } $ this -> validateCertUrl ( $ request ) ; $ localCertPath = sys_get_temp_dir ( ) . DIRECTORY_SEPARATOR . md5 ( $ request -> signatureCertChainUrl ) . '.pem' ; $ certData = $ this -> fetchCertData ( $ request , $ localCertPath ) ; $ this -> verifyCert ( $ request , $ certData ) ; $ certContent = $ this -> parseCertData ( $ certData ) ; $ this -> validateCertContent ( $ certContent , $ localCertPath ) ; }
Validate request signature . The steps for signature validation are described at developer page .
51,558
public function initClient ( ) { list ( $ this -> queueName , , ) = $ this -> channel -> queue_declare ( '' , false , false , true , true ) ; $ this -> requests = 0 ; $ this -> replies = array ( ) ; }
Initialize client .
51,559
public function addRequest ( $ messageBody , $ server , $ requestId , $ routingKey = '' ) { if ( empty ( $ requestId ) ) { throw new \ InvalidArgumentException ( "You must provide a request ID" ) ; } $ this -> setParameter ( 'correlation_id' , $ requestId ) ; $ this -> setParameter ( 'reply_to' , $ this -> queueName ) ; $ message = new AMQPMessage ( $ messageBody , $ this -> getParameters ( ) ) ; $ this -> channel -> basic_publish ( $ message , $ server . '-exchange' , $ routingKey ) ; $ this -> requests ++ ; }
Add request to be sent to RPC Server .
51,560
public function getReplies ( ) { $ this -> channel -> basic_consume ( $ this -> queueName , $ this -> queueName , false , true , false , false , array ( $ this , 'processMessage' ) ) ; while ( count ( $ this -> replies ) < $ this -> requests ) { $ this -> channel -> wait ( null , false , $ this -> requestTimeout ) ; } $ this -> channel -> basic_cancel ( $ this -> queueName ) ; return $ this -> replies ; }
Get replies .
51,561
public function start ( ) { $ this -> setUpConsumer ( ) ; while ( count ( $ this -> channel -> callbacks ) ) { $ this -> channel -> wait ( ) ; } }
Start server .
51,562
public function processMessage ( AMQPMessage $ message ) { try { $ message -> delivery_info [ 'channel' ] -> basic_ack ( $ message -> delivery_info [ 'delivery_tag' ] ) ; $ result = call_user_func ( $ this -> callback , $ message -> body ) ; $ this -> sendReply ( $ result , $ message -> get ( 'reply_to' ) , $ message -> get ( 'correlation_id' ) ) ; } catch ( AMQPRuntimeException $ exception ) { $ this -> sendReply ( 'error: ' . $ exception -> getMessage ( ) , $ message -> get ( 'reply_to' ) , $ message -> get ( 'correlation_id' ) ) ; } catch ( AMQPInvalidArgumentException $ exception ) { $ this -> sendReply ( 'error: ' . $ exception -> getMessage ( ) , $ message -> get ( 'reply_to' ) , $ message -> get ( 'correlation_id' ) ) ; } }
Process message .
51,563
protected function sendReply ( $ result , $ client , $ correlationId ) { $ this -> setParameter ( 'correlation_id' , $ correlationId ) ; $ reply = new AMQPMessage ( $ result , $ this -> getParameters ( ) ) ; $ this -> channel -> basic_publish ( $ reply , '' , $ client ) ; }
Send reply .
51,564
protected function setUpConsumer ( ) { if ( isset ( $ this -> exchangeOptions [ 'name' ] ) ) { $ this -> channel -> exchange_declare ( $ this -> exchangeOptions [ 'name' ] , $ this -> exchangeOptions [ 'type' ] , $ this -> exchangeOptions [ 'passive' ] , $ this -> exchangeOptions [ 'durable' ] , $ this -> exchangeOptions [ 'auto_delete' ] , $ this -> exchangeOptions [ 'internal' ] , $ this -> exchangeOptions [ 'nowait' ] , $ this -> exchangeOptions [ 'arguments' ] , $ this -> exchangeOptions [ 'ticket' ] ) ; if ( ! empty ( $ this -> consumerOptions [ 'qos' ] ) ) { $ this -> channel -> basic_qos ( $ this -> consumerOptions [ 'qos' ] [ 'prefetch_size' ] , $ this -> consumerOptions [ 'qos' ] [ 'prefetch_count' ] , $ this -> consumerOptions [ 'qos' ] [ 'global' ] ) ; } } list ( $ queueName , , ) = $ this -> channel -> queue_declare ( $ this -> queueOptions [ 'name' ] , $ this -> queueOptions [ 'passive' ] , $ this -> queueOptions [ 'durable' ] , $ this -> queueOptions [ 'exclusive' ] , $ this -> queueOptions [ 'auto_delete' ] , $ this -> queueOptions [ 'nowait' ] , $ this -> queueOptions [ 'arguments' ] , $ this -> queueOptions [ 'ticket' ] ) ; if ( isset ( $ this -> exchangeOptions [ 'name' ] ) ) { $ this -> channel -> queue_bind ( $ queueName , $ this -> exchangeOptions [ 'name' ] , $ this -> routingKey ) ; } $ this -> channel -> basic_consume ( $ queueName , $ this -> getConsumerTag ( ) , false , false , false , false , array ( $ this , 'processMessage' ) ) ; }
Setup consumer .
51,565
public static function upload ( $ fileRoute , $ options = NULL ) { if ( is_null ( $ options ) ) { $ options = Image :: $ defaultUploadOptions ; } else { $ options = array_merge ( Image :: $ defaultUploadOptions , $ options ) ; } return DiskManagement :: upload ( $ fileRoute , $ options ) ; }
Image upload to disk .
51,566
public static function getList ( $ folderPath , $ thumbPath = null ) { if ( empty ( $ thumbPath ) ) { $ thumbPath = $ folderPath ; } $ response = array ( ) ; $ absoluteFolderPath = $ _SERVER [ 'DOCUMENT_ROOT' ] . $ folderPath ; $ image_types = Image :: $ defaultUploadOptions [ 'validation' ] [ 'allowedMimeTypes' ] ; $ fnames = scandir ( $ absoluteFolderPath ) ; if ( $ fnames ) { foreach ( $ fnames as $ name ) { if ( ! is_dir ( $ name ) ) { if ( in_array ( mime_content_type ( $ absoluteFolderPath . $ name ) , $ image_types ) ) { $ img = new \ StdClass ; $ img -> url = $ folderPath . $ name ; $ img -> thumb = $ thumbPath . $ name ; $ img -> name = $ name ; array_push ( $ response , $ img ) ; } } } } else { throw new Exception ( 'Images folder does not exist!' ) ; } return $ response ; }
List images from disk
51,567
private static function isFileValid ( $ filename , $ mimeType , $ allowedExts , $ allowedMimeTypes ) { if ( ! $ allowedExts || ! $ allowedMimeTypes ) { return false ; } $ extension = end ( $ filename ) ; return in_array ( strtolower ( $ mimeType ) , $ allowedMimeTypes ) && in_array ( strtolower ( $ extension ) , $ allowedExts , true ) ; }
Check if file is matching the specified allowed extensions and mime types .
51,568
public static function getMimeType ( $ tmpName ) { $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mimeType = finfo_file ( $ finfo , $ tmpName ) ; return $ mimeType ; }
Get the mime type of a file .
51,569
public static function isValid ( $ validation , $ fieldname ) { if ( ! $ validation ) { return true ; } $ filename = explode ( "." , $ _FILES [ $ fieldname ] [ "name" ] ) ; $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mimeType = self :: getMimeType ( $ _FILES [ $ fieldname ] [ "tmp_name" ] ) ; if ( $ validation instanceof \ Closure ) { return $ validation ( $ _FILES [ $ fieldname ] [ "tmp_name" ] , $ mimeType ) ; } if ( is_array ( $ validation ) ) { return self :: isFileValid ( $ filename , $ mimeType , $ validation [ 'allowedExts' ] , $ validation [ 'allowedMimeTypes' ] ) ; } return false ; }
Check if a file is valid .
51,570
public static function upload ( $ fileRoute , $ options ) { $ fieldname = $ options [ 'fieldname' ] ; if ( empty ( $ fieldname ) || empty ( $ _FILES [ $ fieldname ] ) ) { throw new \ Exception ( 'Fieldname is not correct. It must be: ' . $ fieldname ) ; } if ( isset ( $ options [ 'validation' ] ) && ! Utils :: isValid ( $ options [ 'validation' ] , $ fieldname ) ) { throw new \ Exception ( 'File does not meet the validation.' ) ; } $ temp = explode ( "." , $ _FILES [ $ fieldname ] [ "name" ] ) ; $ extension = end ( $ temp ) ; $ name = sha1 ( microtime ( ) ) . "." . $ extension ; $ fullNamePath = $ _SERVER [ 'DOCUMENT_ROOT' ] . $ fileRoute . $ name ; $ mimeType = Utils :: getMimeType ( $ _FILES [ $ fieldname ] [ "tmp_name" ] ) ; if ( isset ( $ options [ 'resize' ] ) && $ mimeType != 'image/svg+xml' ) { $ resize = $ options [ 'resize' ] ; $ columns = $ resize [ 'columns' ] ; $ rows = $ resize [ 'rows' ] ; $ filter = isset ( $ resize [ 'filter' ] ) ? $ resize [ 'filter' ] : \ Imagick :: FILTER_UNDEFINED ; $ blur = isset ( $ resize [ 'blur' ] ) ? $ resize [ 'blur' ] : 1 ; $ bestfit = isset ( $ resize [ 'bestfit' ] ) ? $ resize [ 'bestfit' ] : false ; $ imagick = new \ Imagick ( $ _FILES [ $ fieldname ] [ "tmp_name" ] ) ; $ imagick -> resizeImage ( $ columns , $ rows , $ filter , $ blur , $ bestfit ) ; $ imagick -> writeImage ( $ fullNamePath ) ; $ imagick -> destroy ( ) ; } else { move_uploaded_file ( $ _FILES [ $ fieldname ] [ "tmp_name" ] , $ fullNamePath ) ; } $ response = new \ StdClass ; $ response -> link = $ fileRoute . $ name ; return $ response ; }
Upload a file to the specified location .
51,571
public static function delete ( $ src ) { $ filePath = $ _SERVER [ 'DOCUMENT_ROOT' ] . $ src ; if ( file_exists ( $ filePath ) ) { return unlink ( $ filePath ) ; } return true ; }
Delete file from disk .
51,572
protected static function invoke ( $ method , array $ arguments ) { $ target = [ self :: $ engine , $ method , ] ; return call_user_func_array ( $ target , $ arguments ) ; }
Invoke Engine methods .
51,573
public function message ( $ message = '' , $ type = 'info' ) { if ( is_array ( $ message ) ) { foreach ( $ message as $ issue ) { $ this -> addMessage ( $ issue , $ type ) ; } return $ this ; } return $ this -> addMessage ( $ message , $ type ) ; }
Base method for adding messages to flash .
51,574
public function display ( $ type = null ) { $ result = '' ; if ( ! is_null ( $ type ) && ! in_array ( $ type , $ this -> types ) ) { return $ result ; } if ( in_array ( $ type , $ this -> types ) ) { $ result .= $ this -> buildMessages ( $ _SESSION [ $ this -> key ] [ $ type ] , $ type ) ; } elseif ( is_null ( $ type ) ) { foreach ( $ _SESSION [ $ this -> key ] as $ messageType => $ messages ) { $ result .= $ this -> buildMessages ( $ messages , $ messageType ) ; } } $ this -> clear ( $ type ) ; return $ result ; }
Returns Bootstrap ready HTML for Engine messages .
51,575
public function hasMessages ( $ type = null ) { if ( ! is_null ( $ type ) ) { return ! empty ( $ _SESSION [ $ this -> key ] [ $ type ] ) ; } foreach ( $ this -> types as $ type ) { if ( ! empty ( $ _SESSION [ $ this -> key ] [ $ type ] ) ) { return true ; } } return false ; }
Returns if there are any messages in container .
51,576
public function clear ( $ type = null ) { if ( is_null ( $ type ) ) { $ _SESSION [ $ this -> key ] = [ ] ; } else { unset ( $ _SESSION [ $ this -> key ] [ $ type ] ) ; } return $ this ; }
Clears messages from session store .
51,577
protected function buildMessages ( array $ flashes , $ type ) { $ messages = '' ; foreach ( $ flashes as $ msg ) { $ messages .= $ this -> template -> wrapMessage ( $ msg ) ; } return $ this -> template -> wrapMessages ( $ messages , $ type ) ; }
Builds messages for a single type .
51,578
protected function APICallWithOptions ( $ requestType , $ endpoint , $ options , $ params = null ) { $ postkey = $ this -> httpClientVersionCheck ( ) ; $ response = $ this -> getHttpClient ( ) -> { $ requestType } ( $ this -> buildRequestUrl ( $ endpoint , $ params ) , [ 'headers' => $ this -> getResponseHeaders ( $ this -> user -> token ) , $ postkey => $ options ] ) ; $ return = json_decode ( $ response -> getBody ( ) , true ) ; return $ return ; }
API call function for endpoints that require request body
51,579
protected function buildRequestUrl ( $ endpoint , $ params = null ) { if ( $ this -> user == null ) throw new Exception ( "Please authenticate user first!" ) ; $ requestPath = $ this -> requestPath . $ endpoint . ".json" . $ this -> getParams ( $ params ) ; return $ requestPath ; }
Build the URL for the specific API request
51,580
public function delete ( $ myshopify , $ token , $ id ) { $ this -> setRequestPath ( $ myshopify ) ; $ url = $ this -> getChargeEndpoint ( ) . '/' . $ id . '.json' ; $ this -> getHttpClient ( ) -> delete ( $ url , [ 'headers' => $ this -> getResponseHeaders ( $ token ) ] ) ; }
delete a specific charge
51,581
public function findEndpoint ( $ name ) { $ endpointArr = null ; foreach ( $ this -> endpoints as $ key => $ value ) { if ( strpos ( $ name , $ key ) !== false ) { $ endpointArr = [ $ key => $ value ] ; break ; } } return $ endpointArr ; }
Find the associated endpoint array from the config file given string consist of the first level key .
51,582
protected function removeSuffix ( $ name ) { $ currSuffix = $ this -> getString ( $ name , $ this -> suffix ) ; return str_replace ( $ currSuffix , '' , $ name ) ; }
Remove the suffix of each std class properties
51,583
protected function getString ( $ name , $ inputArr ) { foreach ( $ inputArr as $ input ) { if ( strpos ( $ name , $ input ) !== false ) { return $ currAction = $ input ; } } }
Remove part of the given string that s the same to an element in the given array .
51,584
public function register ( ) { $ this -> app -> singleton ( ShopifyContract :: class , function ( $ app ) { $ shopifyAuth = new ShopifyAuth ( $ app [ 'request' ] , config ( 'shopify.key' ) , config ( 'shopify.secret' ) , config ( 'shopify.redirectURL' ) ) ; return new Shopify ( $ shopifyAuth ) ; } ) ; }
Register Shopify service .
51,585
public function setBase ( RecurringBilling $ recurringBase ) { $ baseCharge = $ recurringBase -> activated [ 'recurring_application_charge' ] ; if ( ! in_array ( 'capped_amount' , array_keys ( $ baseCharge ) ) ) throw new \ Exception ( "'capped_amount' and 'terms' must be included in the base recurring charge as an option" ) ; $ this -> baseId = $ baseCharge [ 'id' ] ; return $ this ; }
set the recurring base charge
51,586
public function create ( $ authorized , array $ options ) { if ( $ authorized instanceof Shopify ) { if ( ! $ authorized -> getUser ( ) ) throw new Exception ( 'Cannot charge user without getting their installation permissions!' ) ; $ this -> setRequestPath ( $ authorized ) ; $ token = $ authorized -> getUser ( ) -> token ; } elseif ( $ authorized instanceof User ) { $ this -> setRequestPath ( $ authorized -> name ) ; $ token = $ authorized -> token ; } else throw new \ InvalidArgumentException ( 'Argumant must be an instance of Shopify or Laravel\Socialite\Two\User' ) ; $ this -> options = $ options ; $ createURL = $ this -> getChargeEndpoint ( ) . '.json' ; $ this -> charge = $ this -> getCreateChargeResponse ( $ createURL , $ token ) ; return $ this ; }
Create a Charge
51,587
protected function getCreateChargeResponse ( $ url , $ token ) { $ postKey = $ this -> httpClientVersionCheck ( ) ; $ response = $ this -> getHttpClient ( ) -> post ( $ url , [ 'headers' => $ this -> getResponseHeaders ( $ token ) , $ postKey => $ this -> getOptions ( ) ] ) ; return json_decode ( $ response -> getBody ( ) , true ) ; }
get the Create Charge response for the given url and access token
51,588
public function getChargeById ( $ myshopify , $ token , $ id ) { $ this -> setRequestPath ( $ myshopify ) ; $ url = $ this -> getChargeEndpoint ( ) . '/' . $ id . '.json' ; $ response = $ this -> getHttpClient ( ) -> get ( $ url , [ 'headers' => $ this -> getResponseHeaders ( $ token ) ] ) ; return json_decode ( $ response -> getBody ( ) , true ) ; }
retrieve a specific charge by id myshopify domain and access token
51,589
public function getAllCharges ( $ myshopify , $ token , $ sinceId = null ) { $ this -> setRequestPath ( $ myshopify ) ; if ( $ sinceId != null && $ this -> chargeType == 'application_charge' ) { $ url = $ this -> getChargeEndpoint ( ) . '.json?since_id=' . $ sinceId ; } else $ url = $ this -> getChargeEndpoint ( ) . '.json' ; $ response = $ this -> getHttpClient ( ) -> get ( $ url , [ 'headers' => $ this -> getResponseHeaders ( $ token ) ] ) ; return json_decode ( $ response -> getBody ( ) , true ) ; }
Get all the charges from a specific shop
51,590
public function activate ( $ myshopify , $ token , $ id ) { $ this -> setRequestPath ( $ myshopify ) ; $ url = $ this -> getChargeEndpoint ( ) . '/' . $ id . '/activate.json' ; $ postkey = $ this -> httpClientVersionCheck ( ) ; $ response = $ this -> getHttpClient ( ) -> post ( $ url , [ 'headers' => $ this -> getResponseHeaders ( $ token ) , $ postkey => $ this -> getChargeById ( $ myshopify , $ token , $ id ) ] ) ; $ this -> activated = json_decode ( $ response -> getBody ( ) , true ) ; return $ this ; }
Activate a specific charge
51,591
protected function setRequestPath ( $ param ) { if ( $ param instanceof Shopify ) { $ this -> requestPath = $ param -> getRequestPath ( ) ; } elseif ( is_string ( $ param ) && strpos ( $ param , 'myshopify' ) != false ) { $ this -> requestPath = 'https://' . $ param . '/admin/' ; } else throw new Exception ( 'invalid request path' ) ; return $ this ; }
Set the request path of the API call
51,592
public function requestPath ( ) { if ( $ this -> shopURL != null ) $ this -> requestPath = 'https://' . $ this -> shopURL . $ this -> adminPath ; return $ this -> requestPath ; }
Get the API request path
51,593
public function checkCurrentApiLimit ( ) : int { $ limit = $ this -> responseHeaders [ 'X-Shopify-Shop-Api-Call-Limit' ] ?? $ this -> responseHeaders [ 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' ] ?? [ '1/40' ] ; return ( int ) explode ( '/' , $ limit [ 0 ] ) [ 0 ] ; }
Return current shopify api limit - 1 is lower
51,594
public function toArray ( ) { $ data = [ ] ; for ( $ this -> rewind ( ) ; $ this -> valid ( ) ; $ this -> next ( ) ) { $ data [ ] = $ this -> current ( ) ; } return $ data ; }
Convert the iterator into an array .
51,595
protected function isPerfectNumber ( $ number ) { $ d = 0 ; $ max = \ sqrt ( $ number ) ; for ( $ n = 2 ; $ n <= $ max ; ++ $ n ) { if ( ! ( $ number % $ n ) ) { $ d += $ n ; if ( $ number / $ n !== $ n ) { $ d += $ number / $ n ; } } } return ++ $ d === $ number ; }
Test if a number is perfect or not .
51,596
public function setLength ( $ length = null ) { $ length = ( null === $ length ) ? $ this -> datasetCount : $ length ; $ this -> length = ( \ abs ( $ length ) > $ this -> datasetCount ) ? $ this -> datasetCount : $ length ; return $ this ; }
Set the length .
51,597
protected function fact ( $ n , $ total = 1 ) { return ( 2 > $ n ) ? $ total : $ this -> fact ( $ n - 1 , $ total * $ n ) ; }
Compute the factorial of an integer .
51,598
protected function doShift ( $ length = 1 ) { $ parameters = [ ] ; if ( 0 > $ length ) { $ parameters [ ] = [ 'start' => \ abs ( $ length ) , 'end' => null ] ; $ parameters [ ] = [ 'start' => 0 , 'end' => \ abs ( $ length ) ] ; } else { $ parameters [ ] = [ 'start' => - 1 * $ length , 'end' => null ] ; $ parameters [ ] = [ 'start' => 0 , 'end' => $ this -> datasetCount + $ length * - 1 ] ; } $ this -> current = \ array_merge ( \ array_slice ( $ this -> current , $ parameters [ 0 ] [ 'start' ] , $ parameters [ 0 ] [ 'end' ] ) , \ array_slice ( $ this -> current , $ parameters [ 1 ] [ 'start' ] , $ parameters [ 1 ] [ 'end' ] ) ) ; }
Internal function to do the shift .
51,599
protected function isPrimeNumber ( $ number ) { $ number = \ abs ( $ number ) ; if ( 2 === $ number ) { return true ; } if ( ! ( $ number & 1 ) ) { return false ; } $ sqrtNumber = \ sqrt ( $ number ) ; for ( $ divisor = 3 ; $ divisor <= $ sqrtNumber ; $ divisor += 2 ) { if ( 0 === $ number % $ divisor ) { return false ; } } return true ; }
Test if a number is prime or not .