idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
55,300
public static function findPlan ( $ id ) : Plan { $ plans = BraintreePlan :: all ( ) ; foreach ( $ plans as $ plan ) { if ( $ plan -> id === $ id ) { return $ plan ; } } throw new Exception ( "Unable to find Braintree plan with ID [{$id}]." ) ; }
Get the Braintree plan that has the given ID .
55,301
public function handleWebhook ( Request $ request ) { try { $ webhook = $ this -> parseBraintreeNotification ( $ request ) ; } catch ( Exception $ e ) { return ; } $ method = 'handle' . Str :: studly ( str_replace ( '.' , '_' , $ webhook -> kind ) ) ; if ( method_exists ( $ this , $ method ) ) { return $ this -> { $ me...
Handle a Braintree webhook call .
55,302
protected function cancelSubscription ( $ subscriptionId ) { $ subscription = $ this -> getSubscriptionById ( $ subscriptionId ) ; if ( $ subscription && ( ! $ subscription -> cancelled ( ) || $ subscription -> onGracePeriod ( ) ) ) { $ subscription -> markAsCancelled ( ) ; } return new Response ( 'Webhook Handled' , 2...
Handle a subscription cancellation notification from Braintree .
55,303
public function create ( $ token = null , array $ customerOptions = [ ] , array $ subscriptionOptions = [ ] ) : Subscription { $ payload = $ this -> getSubscriptionPayload ( $ this -> getBraintreeCustomer ( $ token , $ customerOptions ) , $ subscriptionOptions ) ; if ( $ this -> coupon ) { $ payload = $ this -> addCoup...
Create a new Braintree subscription .
55,304
protected function getSubscriptionPayload ( $ customer , array $ options = [ ] ) { $ plan = BraintreeService :: findPlan ( $ this -> plan ) ; if ( $ this -> skipTrial ) { $ trialDuration = 0 ; } else { $ trialDuration = $ this -> trialDays ? : 0 ; } return array_merge ( [ 'planId' => $ this -> plan , 'price' => number_...
Get the base subscription payload for Braintree .
55,305
protected function getBraintreeCustomer ( $ token = null , array $ options = [ ] ) : Customer { if ( ! $ this -> owner -> braintree_id ) { $ customer = $ this -> owner -> createAsBraintreeCustomer ( $ token , $ options ) ; } else { $ customer = $ this -> owner -> asBraintreeCustomer ( ) ; if ( $ token ) { $ this -> own...
Get the Braintree customer instance for the current user and token .
55,306
public function owner ( ) { $ model = getenv ( 'BRAINTREE_MODEL' ) ? : config ( 'services.braintree.model' , 'App\\User' ) ; $ model = new $ model ; return $ this -> belongsTo ( get_class ( $ model ) , $ model -> getForeignKey ( ) ) ; }
Get the model related to the subscription .
55,307
public function onTrial ( ) { if ( ! is_null ( $ this -> trial_ends_at ) ) { return Carbon :: today ( ) -> lt ( $ this -> trial_ends_at ) ; } return false ; }
Determine if the subscription is within its trial period .
55,308
public function swap ( $ plan ) { if ( $ this -> onGracePeriod ( ) && $ this -> braintree_plan === $ plan ) { return $ this -> resume ( ) ; } if ( ! $ this -> active ( ) ) { return $ this -> owner -> newSubscription ( $ this -> name , $ plan ) -> skipTrial ( ) -> create ( ) ; } $ plan = BraintreeService :: findPlan ( $...
Swap the subscription to a new Braintree plan .
55,309
protected function swapAcrossFrequencies ( $ plan ) : self { $ currentPlan = BraintreeService :: findPlan ( $ this -> braintree_plan ) ; $ discount = $ this -> switchingToMonthlyPlan ( $ currentPlan , $ plan ) ? $ this -> getDiscountForSwitchToMonthly ( $ currentPlan , $ plan ) : $ this -> getDiscountForSwitchToYearly ...
Swap the subscription to a new Braintree plan with a different frequency .
55,310
protected function getDiscountForSwitchToMonthly ( Plan $ currentPlan , Plan $ plan ) { return ( object ) [ 'amount' => $ plan -> price , 'numberOfBillingCycles' => floor ( $ this -> moneyRemainingOnYearlyPlan ( $ currentPlan ) / $ plan -> price ) , ] ; }
Get the discount to apply when switching to a monthly plan .
55,311
protected function moneyRemainingOnYearlyPlan ( Plan $ plan ) { return ( $ plan -> price / 365 ) * Carbon :: today ( ) -> diffInDays ( Carbon :: instance ( $ this -> asBraintreeSubscription ( ) -> billingPeriodEndDate ) , false ) ; }
Calculate the amount of discount to apply to a swap to monthly billing .
55,312
protected function getDiscountForSwitchToYearly ( ) { $ amount = 0 ; foreach ( $ this -> asBraintreeSubscription ( ) -> discounts as $ discount ) { if ( $ discount -> id == 'plan-credit' ) { $ amount += ( float ) $ discount -> amount * $ discount -> numberOfBillingCycles ; } } return ( object ) [ 'amount' => $ amount ,...
Get the discount to apply when switching to a yearly plan .
55,313
public function applyCoupon ( $ coupon , $ removeOthers = false ) { if ( ! $ this -> active ( ) ) { throw new InvalidArgumentException ( 'Unable to apply coupon. Subscription not active.' ) ; } BraintreeSubscription :: update ( $ this -> braintree_id , [ 'discounts' => [ 'add' => [ [ 'inheritedFromId' => $ coupon , ] ]...
Apply a coupon to the subscription .
55,314
protected function currentDiscounts ( ) { return collect ( $ this -> asBraintreeSubscription ( ) -> discounts ) -> map ( function ( $ discount ) { return $ discount -> id ; } ) -> all ( ) ; }
Get the current discounts for the subscription .
55,315
public function cancel ( ) { $ subscription = $ this -> asBraintreeSubscription ( ) ; if ( $ this -> onTrial ( ) ) { BraintreeSubscription :: cancel ( $ subscription -> id ) ; $ this -> markAsCancelled ( ) ; } else { BraintreeSubscription :: update ( $ subscription -> id , [ 'numberOfBillingCycles' => $ subscription ->...
Cancel the subscription .
55,316
public function cancelNow ( ) { $ subscription = $ this -> asBraintreeSubscription ( ) ; BraintreeSubscription :: cancel ( $ subscription -> id ) ; $ this -> markAsCancelled ( ) ; return $ this ; }
Cancel the subscription immediately .
55,317
public static function createFromArray ( array $ data ) { $ defaults = [ 'providedBy' => 'n/a' , 'latitude' => null , 'longitude' => null , 'bounds' => [ 'south' => null , 'west' => null , 'north' => null , 'east' => null , ] , 'streetNumber' => null , 'streetName' => null , 'locality' => null , 'postalCode' => null , ...
Create an Address with an array . Useful for testing .
55,318
public function registerProvider ( Provider $ provider ) : self { $ this -> providers [ $ provider -> getName ( ) ] = $ provider ; return $ this ; }
Registers a new provider to the aggregator .
55,319
public function registerProviders ( array $ providers = [ ] ) : self { foreach ( $ providers as $ provider ) { $ this -> registerProvider ( $ provider ) ; } return $ this ; }
Registers a set of providers .
55,320
public function using ( string $ name ) : self { if ( ! isset ( $ this -> providers [ $ name ] ) ) { throw ProviderNotRegistered :: create ( $ name ?? '' , $ this -> providers ) ; } $ this -> provider = $ this -> providers [ $ name ] ; return $ this ; }
Sets the default provider to use .
55,321
private static function getProvider ( $ query , array $ providers , Provider $ currentProvider = null ) : Provider { if ( null !== $ currentProvider ) { return $ currentProvider ; } if ( 0 === count ( $ providers ) ) { throw ProviderNotRegistered :: noProviderRegistered ( ) ; } $ key = key ( $ providers ) ; return $ pr...
Get a provider to use for this query .
55,322
public function format ( Location $ location , string $ format ) : string { $ countryName = null ; $ code = null ; if ( null !== $ country = $ location -> getCountry ( ) ) { $ countryName = $ country -> getName ( ) ; if ( null !== $ code = $ country -> getCode ( ) ) { $ code = strtoupper ( $ code ) ; } } $ replace = [ ...
Transform an Address instance into a string representation .
55,323
public static function getSymfonyVersion ( $ version ) { return implode ( '.' , \ array_slice ( array_map ( static function ( $ val ) { return ( int ) $ val ; } , explode ( '.' , $ version ) ) , 0 , 3 ) ) ; }
Returns a cleaned version number .
55,324
public function formatPercent ( $ number , array $ attributes = [ ] , array $ textAttributes = [ ] , $ locale = null ) { $ methodArgs = array_pad ( \ func_get_args ( ) , 5 , null ) ; list ( $ locale , $ symbols ) = $ this -> normalizeMethodSignature ( $ methodArgs [ 3 ] , $ methodArgs [ 4 ] ) ; return $ this -> format ...
Formats a number as percent according to the specified locale and \ NumberFormatter attributes .
55,325
public function formatDuration ( $ number , array $ attributes = [ ] , array $ textAttributes = [ ] , $ locale = null ) { $ methodArgs = array_pad ( \ func_get_args ( ) , 5 , null ) ; list ( $ locale , $ symbols ) = $ this -> normalizeMethodSignature ( $ methodArgs [ 3 ] , $ methodArgs [ 4 ] ) ; return $ this -> format...
Formats a number as duration according to the specified locale and \ NumberFormatter attributes .
55,326
public function formatDecimal ( $ number , array $ attributes = [ ] , array $ textAttributes = [ ] , $ locale = null ) { $ methodArgs = array_pad ( \ func_get_args ( ) , 5 , null ) ; list ( $ locale , $ symbols ) = $ this -> normalizeMethodSignature ( $ methodArgs [ 3 ] , $ methodArgs [ 4 ] ) ; return $ this -> format ...
Formats a number as decimal according to the specified locale and \ NumberFormatter attributes .
55,327
public function formatSpellout ( $ number , array $ attributes = [ ] , array $ textAttributes = [ ] , $ locale = null ) { $ methodArgs = array_pad ( \ func_get_args ( ) , 5 , null ) ; list ( $ locale , $ symbols ) = $ this -> normalizeMethodSignature ( $ methodArgs [ 3 ] , $ methodArgs [ 4 ] ) ; return $ this -> format...
Formats a number as spellout according to the specified locale and \ NumberFormatter attributes .
55,328
public function formatScientific ( $ number , array $ attributes = [ ] , array $ textAttributes = [ ] , $ locale = null ) { $ methodArgs = array_pad ( \ func_get_args ( ) , 5 , null ) ; list ( $ locale , $ symbols ) = $ this -> normalizeMethodSignature ( $ methodArgs [ 3 ] , $ methodArgs [ 4 ] ) ; return $ this -> form...
Formats a number in scientific notation according to the specified locale and \ NumberFormatter attributes .
55,329
public function formatOrdinal ( $ number , array $ attributes = [ ] , array $ textAttributes = [ ] , $ locale = null ) { $ methodArgs = array_pad ( \ func_get_args ( ) , 5 , null ) ; list ( $ locale , $ symbols ) = $ this -> normalizeMethodSignature ( $ methodArgs [ 3 ] , $ methodArgs [ 4 ] ) ; return $ this -> format ...
Formats a number as ordinal according to the specified locale and \ NumberFormatter attributes .
55,330
public function format ( $ number , $ style , array $ attributes = [ ] , array $ textAttributes = [ ] , $ locale = null ) { $ methodArgs = array_pad ( \ func_get_args ( ) , 6 , null ) ; list ( $ locale , $ symbols ) = $ this -> normalizeMethodSignature ( $ methodArgs [ 4 ] , $ methodArgs [ 5 ] ) ; $ formatter = $ this ...
Formats a number according to the specified locale and \ NumberFormatter attributes .
55,331
public function normalizeMethodSignature ( $ symbols , $ locale ) { $ oldSignature = ( null === $ symbols || \ is_string ( $ symbols ) ) && null === $ locale ; $ newSignature = \ is_array ( $ symbols ) && ( \ is_string ( $ locale ) || null === $ locale ) ; if ( ! $ oldSignature && ! $ newSignature ) { throw new \ BadMe...
Normalizes the given arguments according to the new function signature . It asserts if neither the new nor old signature matches . This function is public just to prevent code duplication inside the Twig Extension .
55,332
protected function getFormatter ( $ culture , $ style , $ attributes = [ ] , $ textAttributes = [ ] , $ symbols = [ ] ) { $ attributes = $ this -> parseAttributes ( array_merge ( $ this -> attributes , $ attributes ) ) ; $ textAttributes = $ this -> parseAttributes ( array_merge ( $ this -> textAttributes , $ textAttri...
Gets an instance of \ NumberFormatter set with the given attributes and style .
55,333
protected function parseAttributes ( array $ attributes ) { $ result = [ ] ; foreach ( $ attributes as $ attribute => $ value ) { $ result [ $ this -> parseConstantValue ( $ attribute ) ] = $ value ; } return $ result ; }
Converts keys of attributes array to values of \ NumberFormatter constants .
55,334
protected function parseConstantValue ( $ attribute ) { $ attribute = strtoupper ( $ attribute ) ; $ constantName = 'NumberFormatter::' . $ attribute ; if ( ! \ defined ( $ constantName ) ) { throw new \ InvalidArgumentException ( sprintf ( 'NumberFormatter has no constant "%s".' , $ attribute ) ) ; } return \ constant...
Parse the given value trying to get a match with a \ NumberFormatter constant .
55,335
public function getDatetime ( $ data , $ timezone = null ) { if ( $ data instanceof \ DateTime ) { return $ data ; } if ( $ data instanceof \ DateTimeImmutable ) { return \ DateTime :: createFromFormat ( \ DateTime :: ATOM , $ data -> format ( \ DateTime :: ATOM ) ) ; } if ( is_numeric ( $ data ) ) { $ data = ( int ) $...
Gets a date time instance by a given data and timezone .
55,336
private function validateTimezones ( array $ timezones ) { try { foreach ( $ timezones as $ timezone ) { $ tz = new \ DateTimeZone ( $ timezone ) ; } } catch ( \ Exception $ e ) { throw new \ RuntimeException ( sprintf ( 'Unknown timezone "%s". Please check your sonata_intl configuration.' , $ timezone ) ) ; } }
Validate timezones .
55,337
protected function fixCharset ( $ string ) { if ( 'UTF-8' !== $ this -> getCharset ( ) ) { $ string = mb_convert_encoding ( $ string , $ this -> getCharset ( ) , 'UTF-8' ) ; } return $ string ; }
Fixes the charset by converting a string from an UTF - 8 charset to the charset of the kernel .
55,338
public function resolveRouteBinding ( $ routeKey ) { if ( method_exists ( $ this -> wrappedObject , 'resolveRouteBinding' ) && is_callable ( [ $ this -> wrappedObject , 'resolveRouteBinding' ] ) ) { return $ this -> wrappedObject -> resolveRouteBinding ( $ routeKey ) ; } return $ this -> wrappedObject -> where ( $ this...
Retrieve model for route model binding .
55,339
public function __isset ( string $ key ) { if ( method_exists ( $ this , $ key ) ) { return true ; } return isset ( $ this -> wrappedObject -> $ key ) ; }
Is the key set on either the presenter or the wrapped object?
55,340
protected function setupEventFiring ( Container $ app ) { $ app [ 'view' ] -> composer ( '*' , function ( $ view ) use ( $ app ) { if ( $ view instanceof View ) { $ app [ 'events' ] -> dispatch ( 'content.rendering' , [ $ view ] ) ; } } ) ; }
Setup the event firing .
55,341
protected function setupEventListening ( Container $ app ) { $ app [ 'events' ] -> listen ( 'content.rendering' , function ( View $ view ) use ( $ app ) { if ( $ viewData = array_merge ( $ view -> getFactory ( ) -> getShared ( ) , $ view -> getData ( ) ) ) { $ decorator = $ app [ 'autopresenter' ] ; foreach ( $ viewDat...
Setup the event listening .
55,342
public function registerAutoPresenter ( Container $ app ) { $ app -> singleton ( 'autopresenter' , function ( Container $ app ) { $ autoPresenter = new AutoPresenter ( ) ; $ autoPresenter -> register ( new AtomDecorator ( $ autoPresenter , $ app ) ) ; $ autoPresenter -> register ( new ArrayDecorator ( $ autoPresenter )...
Register the presenter decorator .
55,343
protected function getItems ( Paginator $ subject ) { $ object = new ReflectionObject ( $ subject ) ; $ items = $ object -> getProperty ( 'items' ) ; $ items -> setAccessible ( true ) ; return $ items -> getValue ( $ subject ) ; }
Decorate a paginator instance .
55,344
public function getMock ( $ fqfn ) { if ( ! isset ( $ this -> mocks [ $ fqfn ] ) ) { return null ; } return $ this -> mocks [ $ fqfn ] ; }
Returns the registered mock .
55,345
public function setMicrotimeAsFloat ( $ timestamp ) { if ( ! is_numeric ( $ timestamp ) ) { throw new \ InvalidArgumentException ( "Timestamp should be numeric" ) ; } $ converter = new MicrotimeConverter ( ) ; $ this -> timestamp = $ converter -> convertFloatToString ( $ timestamp ) ; }
Set the timestamp as float .
55,346
public function getMicrotime ( $ get_as_float = false ) { if ( $ get_as_float ) { $ converter = new MicrotimeConverter ( ) ; return $ converter -> convertStringToFloat ( $ this -> timestamp ) ; } else { return $ this -> timestamp ; } }
Returns the microtime .
55,347
public function defineFunction ( ) { $ name = $ this -> mock -> getName ( ) ; $ parameterBuilder = new ParameterBuilder ( ) ; $ parameterBuilder -> build ( $ name ) ; $ data = [ "namespace" => $ this -> mock -> getNamespace ( ) , "name" => $ name , "fqfn" => $ this -> mock -> getFQFN ( ) , "signatureParameters" => $ pa...
Defines the mock function .
55,348
public static function removeDefaultArguments ( & $ arguments ) { foreach ( $ arguments as $ key => $ argument ) { if ( $ argument === self :: DEFAULT_ARGUMENT ) { unset ( $ arguments [ $ key ] ) ; } } }
Removes optional arguments .
55,349
public static function call ( $ functionName , $ fqfn , & $ arguments ) { $ registry = MockRegistry :: getInstance ( ) ; $ mock = $ registry -> getMock ( $ fqfn ) ; self :: removeDefaultArguments ( $ arguments ) ; if ( empty ( $ mock ) ) { return call_user_func_array ( $ functionName , $ arguments ) ; } else { return $...
Calls the enabled mock or the built - in function otherwise .
55,350
public function convertStringToFloat ( $ microtime ) { list ( $ usec , $ sec ) = sscanf ( $ microtime , "%f %d" ) ; return ( ( float ) $ usec + ( float ) $ sec ) ; }
Converts a string microtime into a float .
55,351
public function enable ( ) { $ registry = MockRegistry :: getInstance ( ) ; if ( $ registry -> isRegistered ( $ this ) ) { throw new MockEnabledException ( "$this->name is already enabled." . "Call disable() on the existing mock." ) ; } $ this -> define ( ) ; $ registry -> register ( $ this ) ; }
Enables this mock .
55,352
public function build ( $ functionName ) { if ( ! function_exists ( $ functionName ) ) { return ; } $ function = new \ ReflectionFunction ( $ functionName ) ; $ signatureParameters = [ ] ; $ bodyParameters = [ ] ; foreach ( $ function -> getParameters ( ) as $ reflectionParameter ) { if ( $ this -> isVariadic ( $ refle...
Builds the parameters for an existing function .
55,353
private function isVariadic ( \ ReflectionParameter $ parameter ) { if ( $ parameter -> name == "..." ) { return true ; } if ( method_exists ( $ parameter , "isVariadic" ) ) { return $ parameter -> isVariadic ( ) ; } return false ; }
Returns whether a parameter is variadic .
55,354
public function create ( $ file , $ purpose , array $ headers = [ ] ) { $ response = $ this -> getClient ( ) -> request ( 'POST' , 'v1/files' , [ 'headers' => $ headers , 'multipart' => [ [ 'name' => 'purpose' , 'contents' => $ purpose ] , [ 'name' => 'file' , 'contents' => fopen ( $ file , 'r' ) ] ] , ] ) ; return jso...
Creates a file upload .
55,355
public function verify ( $ accountId , $ file , $ purpose ) { $ upload = ( new FileUploads ( $ this -> config ) ) -> create ( $ file , $ purpose , [ 'Stripe-Account' => $ accountId ] ) ; $ this -> update ( $ accountId , [ 'legal_entity' => [ 'verification' => [ 'document' => $ upload [ 'id' ] , ] , ] , ] ) ; return $ t...
Updates an existing account .
55,356
public static function prepareParameters ( array $ parameters ) { $ toConvert = [ 'amount' , 'price' ] ; if ( self :: needsAmountConversion ( $ parameters ) ) { if ( $ converter = Stripe :: getAmountConverter ( ) ) { foreach ( $ toConvert as $ to ) { if ( isset ( $ parameters [ $ to ] ) ) { $ parameters [ $ to ] = forw...
Prepares the given parameters .
55,357
public function create ( $ subscription , $ plan , array $ parameters = [ ] ) { $ parameters = array_merge ( $ parameters , compact ( 'plan' , 'subscription' ) ) ; return $ this -> _post ( 'subscription_items' , $ parameters ) ; }
Creates a new item an existing subscription .
55,358
public function all ( $ subscription , array $ parameters = [ ] ) { $ parameters = array_merge ( $ parameters , compact ( 'subscription' ) ) ; return $ this -> _get ( 'subscription_items' , $ parameters ) ; }
Lists all subscription items .
55,359
public function reactivate ( $ customerId , $ subscriptionId , array $ attributes = [ ] ) { if ( ! isset ( $ attributes [ 'plan' ] ) ) { $ subscription = $ this -> find ( $ customerId , $ subscriptionId ) ; $ attributes [ 'plan' ] = $ subscription [ 'plan' ] [ 'id' ] ; } return $ this -> update ( $ customerId , $ subsc...
Reactivates an existing canceled subscription from the given customer .
55,360
public function create ( $ customerId , array $ parameters = [ ] ) { $ parameters = array_merge ( $ parameters , [ 'customer' => $ customerId , ] ) ; return $ this -> _post ( 'invoices' , $ parameters ) ; }
Creates a new invoice .
55,361
public function upcomingInvoice ( $ customerId , $ subscriptionId = null , array $ parameters = [ ] ) { $ parameters = array_merge ( $ parameters , [ 'customer' => $ customerId , 'subscription' => $ subscriptionId , ] ) ; return $ this -> _get ( 'invoices/upcoming' , $ parameters ) ; }
Retrieves the given customer upcoming invoices .
55,362
public function create ( $ chargeId , $ amount = null , array $ parameters = [ ] ) { $ parameters = array_merge ( $ parameters , array_filter ( compact ( 'amount' ) ) ) ; return $ this -> _post ( "charges/{$chargeId}/refunds" , $ parameters ) ; }
Creates a new refund for the given charge .
55,363
public function all ( $ chargeId = null , array $ parameters = [ ] ) { if ( ! $ chargeId ) { return $ this -> _get ( 'refunds' , $ parameters ) ; } return $ this -> _get ( "charges/{$chargeId}/refunds" , $ parameters ) ; }
Lists all the refunds of the current Stripe account or lists all the refunds for the given charge .
55,364
public static function convert ( $ number ) { $ number = preg_replace ( '/\,/i' , '' , $ number ) ; $ number = preg_replace ( '/([^0-9\.\-])/i' , '' , $ number ) ; if ( ! is_numeric ( $ number ) ) { return '0.00' ; } $ isCents = ( bool ) preg_match ( '/^0.\d+$/' , $ number ) ; return ( $ isCents ? '0' : null ) . number...
Converts the given number into cents .
55,365
public function create ( $ customerId , $ parameters = [ ] ) { if ( is_array ( $ parameters ) && isset ( $ parameters [ 'source' ] ) ) { $ parameters [ 'source' ] [ 'object' ] = 'bank_account' ; } elseif ( is_string ( $ parameters ) ) { $ parameters = [ 'source' => $ parameters ] ; } return $ this -> _post ( "customers...
Creates a new source on the given customer .
55,366
public function verify ( $ customerId , $ bankAccountId , array $ amounts , $ verificationMethod = null ) { return $ this -> _post ( "customers/{$customerId}/sources/{$bankAccountId}/verify" , [ 'amounts' => $ amounts , 'verification_method' => $ verificationMethod , ] ) ; }
Verifies the given bank account .
55,367
public function create ( $ fileId , array $ attributes = [ ] ) { $ attributes = array_merge ( $ attributes , [ 'file' => $ fileId , ] ) ; return $ this -> _post ( "file_links" , $ attributes ) ; }
Creates a new file link .
55,368
public function fetch ( array $ parameters = [ ] ) { $ this -> api -> setPerPage ( 100 ) ; $ results = $ this -> processRequest ( $ parameters ) ; while ( $ this -> nextToken ) { $ results = array_merge ( $ results , $ this -> processRequest ( $ parameters ) ) ; } return $ results ; }
Fetches all the objects of the given api .
55,369
protected function processRequest ( array $ parameters = [ ] ) { if ( $ this -> nextToken ) { $ parameters [ 'starting_after' ] = $ this -> nextToken ; } if ( isset ( $ parameters [ 0 ] ) ) { $ id = $ parameters [ 0 ] ; unset ( $ parameters [ 0 ] ) ; if ( isset ( $ parameters [ 1 ] ) ) { $ parameters = $ parameters [ 1...
Processes the api request .
55,370
public function setKeepAlive ( $ b ) { $ this -> _keepAlive = ( boolean ) $ b ; if ( ! $ this -> _keepAlive && $ this -> _sock ) { fclose ( $ this -> _sock ) ; } }
Define whether or not the FastCGI application should keep the connection alive at the end of a request
55,371
public function setPersistentSocket ( $ b ) { $ was_persistent = ( $ this -> _sock && $ this -> _persistentSocket ) ; $ this -> _persistentSocket = ( boolean ) $ b ; if ( ! $ this -> _persistentSocket && $ was_persistent ) { fclose ( $ this -> _sock ) ; } }
Define whether or not PHP should attempt to re - use sockets opened by previous request for efficiency
55,372
private function connect ( ) { if ( ! $ this -> _sock ) { if ( $ this -> _persistentSocket ) { $ this -> _sock = pfsockopen ( $ this -> _host , $ this -> _port , $ errno , $ errstr , $ this -> _connectTimeout / 1000 ) ; } else { $ this -> _sock = fsockopen ( $ this -> _host , $ this -> _port , $ errno , $ errstr , $ th...
Create a connection to the FastCGI application
55,373
private function buildPacket ( $ type , $ content , $ requestId = 1 ) { $ clen = strlen ( $ content ) ; return chr ( self :: VERSION_1 ) . chr ( $ type ) . chr ( ( $ requestId >> 8 ) & 0xFF ) . chr ( $ requestId & 0xFF ) . chr ( ( $ clen >> 8 ) & 0xFF ) . chr ( $ clen & 0xFF ) . chr ( 0 ) . chr ( 0 ) . $ content ; }
Build a FastCGI packet
55,374
private function readNvpair ( $ data , $ length = null ) { $ array = array ( ) ; if ( $ length === null ) { $ length = strlen ( $ data ) ; } $ p = 0 ; while ( $ p != $ length ) { $ nlen = ord ( $ data { $ p ++ } ) ; if ( $ nlen >= 128 ) { $ nlen = ( $ nlen & 0x7F << 24 ) ; $ nlen |= ( ord ( $ data { $ p ++ } ) << 16 ) ...
Read a set of FastCGI Name value pairs
55,375
private function decodePacketHeader ( $ data ) { $ ret = array ( ) ; $ ret [ 'version' ] = ord ( $ data { 0 } ) ; $ ret [ 'type' ] = ord ( $ data { 1 } ) ; $ ret [ 'requestId' ] = ( ord ( $ data { 2 } ) << 8 ) + ord ( $ data { 3 } ) ; $ ret [ 'contentLength' ] = ( ord ( $ data { 4 } ) << 8 ) + ord ( $ data { 5 } ) ; $ ...
Decode a FastCGI Packet
55,376
private function readPacket ( ) { if ( $ packet = fread ( $ this -> _sock , self :: HEADER_LEN ) ) { $ resp = $ this -> decodePacketHeader ( $ packet ) ; $ resp [ 'content' ] = '' ; if ( $ resp [ 'contentLength' ] ) { $ len = $ resp [ 'contentLength' ] ; while ( $ len && ( $ buf = fread ( $ this -> _sock , $ len ) ) !=...
Read a FastCGI Packet
55,377
public function getValues ( array $ requestedInfo ) { $ this -> connect ( ) ; $ request = '' ; foreach ( $ requestedInfo as $ info ) { $ request .= $ this -> buildNvpair ( $ info , '' ) ; } fwrite ( $ this -> _sock , $ this -> buildPacket ( self :: GET_VALUES , $ request , 0 ) ) ; $ resp = $ this -> readPacket ( ) ; if...
Get Informations on the FastCGI application
55,378
public function request ( array $ params , $ stdin ) { $ id = $ this -> async_request ( $ params , $ stdin ) ; return $ this -> wait_for_response ( $ id ) ; }
Execute a request to the FastCGI application
55,379
public function async_request ( array $ params , $ stdin ) { $ this -> connect ( ) ; $ id = mt_rand ( 1 , ( 1 << 16 ) - 1 ) ; $ keepAlive = intval ( $ this -> _keepAlive || $ this -> _persistentSocket ) ; $ request = $ this -> buildPacket ( self :: BEGIN_REQUEST , chr ( 0 ) . chr ( self :: RESPONDER ) . chr ( $ keepAli...
Execute a request to the FastCGI application asyncronously
55,380
public function wait_for_response ( $ requestId , $ timeoutMs = 0 ) { if ( ! isset ( $ this -> _requests [ $ requestId ] ) ) { throw new \ Exception ( 'Invalid request id given' ) ; } if ( $ this -> _requests [ $ requestId ] [ 'state' ] == self :: REQ_STATE_OK || $ this -> _requests [ $ requestId ] [ 'state' ] == self ...
Blocking call that waits for response to specific request
55,381
private function get_dimensions ( $ new_width , $ new_height , $ option ) { switch ( $ option ) { case 'exact' : $ optimal_width = $ new_width ; $ optimal_height = $ new_height ; break ; case 'portrait' : $ optimal_width = $ this -> get_size_by_fixed_height ( $ new_height ) ; $ optimal_height = $ new_height ; break ; c...
Return the image dimentions based on the option that was chosen .
55,382
private function get_size_by_fixed_height ( $ new_height ) { $ ratio = $ this -> width / $ this -> height ; $ new_width = $ new_height * $ ratio ; return $ new_width ; }
Returns the width based on the image height .
55,383
private function get_size_by_fixed_width ( $ new_width ) { $ ratio = $ this -> height / $ this -> width ; $ new_height = $ new_width * $ ratio ; return $ new_height ; }
Returns the height based on the image width .
55,384
public function make ( $ name , array $ options ) { $ options = $ this -> parseDefaults ( $ name , $ options ) ; return $ this -> getActionObject ( $ options ) ; }
Takes the model and an info array of options for the specific action .
55,385
public function getByName ( $ name , $ global = false ) { $ actions = $ global ? $ this -> getGlobalActions ( ) : $ this -> getActions ( ) ; foreach ( $ actions as $ action ) { if ( $ action -> getOption ( 'action_name' ) === $ name ) { return $ action ; } } return false ; }
Gets an action by name .
55,386
public function getActions ( $ override = false ) { if ( empty ( $ this -> actions ) || $ override ) { $ this -> actions = array ( ) ; foreach ( $ this -> config -> getOption ( 'actions' ) as $ name => $ options ) { $ this -> actions [ ] = $ this -> make ( $ name , $ options ) ; } } return $ this -> actions ; }
Gets all actions .
55,387
public function getActionsOptions ( $ override = false ) { if ( empty ( $ this -> actionsOptions ) || $ override ) { $ this -> actionsOptions = array ( ) ; foreach ( $ this -> getActions ( $ override ) as $ name => $ action ) { $ this -> actionsOptions [ ] = $ action -> getOptions ( true ) ; } } return $ this -> action...
Gets all actions as arrays of options .
55,388
public function setUpConstraints ( & $ options ) { $ constraints = $ this -> validator -> arrayGet ( $ options , 'constraints' ) ; $ model = $ this -> config -> getDataModel ( ) ; if ( is_array ( $ constraints ) && sizeof ( $ constraints ) ) { $ validConstraints = array ( ) ; foreach ( $ constraints as $ field => $ rel...
Sets up the constraints for a relationship field if provided . We do this so we can assume later that it will just work .
55,389
public function loadRelationshipOptions ( & $ options ) { $ items = array ( ) ; $ model = $ this -> config -> getDataModel ( ) ; $ relationship = $ model -> { $ options [ 'field_name' ] } ( ) ; $ relatedModel = $ relationship -> getRelated ( ) ; if ( $ this -> validator -> arrayGet ( $ options , 'load_relationships' ) ...
Loads the relationship options and sets the options option if load_relationships is true .
55,390
public function mapRelationshipOptions ( $ items , $ nameField , $ keyField ) { $ result = array ( ) ; foreach ( $ items as $ option ) { $ result [ ] = array ( 'id' => $ option -> { $ keyField } , 'text' => strval ( $ option -> { $ nameField } ) , ) ; } return $ result ; }
Maps the relationship options to an array with id and text keys .
55,391
public function filterQuery ( QueryBuilder & $ query , & $ selects = null ) { parent :: filterQuery ( $ query , $ selects ) ; if ( ! $ this -> getOption ( 'value' ) ) { return ; } $ query -> where ( $ this -> getOption ( 'foreign_key' ) , '=' , $ this -> getOption ( 'value' ) ) ; }
Filters a query object with this item s data given a model .
55,392
public function make ( $ name , $ primary = false ) { $ this -> name = $ primary ? $ name : $ this -> name ; $ options = $ this -> searchMenu ( $ name ) ; $ config = $ options ? $ this -> getItemConfigObject ( $ options ) : ( $ this -> type === 'page' ? true : false ) ; $ this -> config = $ primary ? $ config : $ this ...
Makes a config instance given an input string .
55,393
public function updateConfigOptions ( ) { $ options = $ this -> searchMenu ( $ this -> name ) ; $ this -> getConfig ( ) -> setOptions ( $ options ) ; }
Updates the current item config s options .
55,394
public function parseType ( $ name ) { if ( strpos ( $ name , $ this -> settingsPrefix ) === 0 ) { return $ this -> type = 'settings' ; } elseif ( strpos ( $ name , $ this -> pagePrefix ) === 0 ) { return $ this -> type = 'page' ; } else { return $ this -> type = 'model' ; } }
Determines whether a string is a model or settings config .
55,395
public function searchMenu ( $ name , $ menu = false ) { if ( $ menu === false ) { $ this -> parseType ( $ name ) ; } $ config = false ; $ menu = $ menu ? $ menu : $ this -> options [ 'menu' ] ; foreach ( $ menu as $ key => $ item ) { if ( is_string ( $ item ) && $ item === $ name ) { $ config = $ this -> fetchConfigFi...
Recursively searches the menu array for the desired settings config name .
55,396
public function getPath ( ) { $ path = $ this -> type === 'settings' ? $ this -> options [ 'settings_config_path' ] : $ this -> options [ 'model_config_path' ] ; return rtrim ( $ path , '/' ) . '/' ; }
Gets the config directory path for the currently - searched item .
55,397
public function getItemConfigObject ( array $ options ) { if ( $ this -> type === 'settings' ) { return new SettingsConfig ( $ this -> validator , $ this -> customValidator , $ options ) ; } else { return new ModelConfig ( $ this -> validator , $ this -> customValidator , $ options ) ; } }
Gets an instance of the config .
55,398
public function fetchConfigFile ( $ name ) { $ name = str_replace ( $ this -> getPrefix ( ) , '' , $ name ) ; $ path = $ this -> getPath ( ) . $ name . '.php' ; if ( is_file ( $ path ) ) { $ options = require $ path ; $ options [ 'name' ] = $ name ; return $ options ; } return false ; }
Fetches a config file given a path .
55,399
public function make ( $ name , $ options , $ loadRelationships = true ) { $ options = $ this -> prepareOptions ( $ name , $ options , $ loadRelationships ) ; return $ this -> getFieldObject ( $ options ) ; }
Makes a field given an array of options .