idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
42,600
public function hydrate ( $ model , array $ fields = array ( ) ) { if ( is_array ( $ model ) ) { return $ this -> getRepository ( $ this -> resolveModelClassName ( reset ( $ model ) ) ) -> hydrate ( $ model , $ fields ) ; } $ row = $ this -> getRepository ( $ this -> resolveModelClassName ( $ model ) ) -> hydrate ( array ( $ model ) , $ fields ) ; if ( empty ( $ row ) ) { return null ; } return $ row [ 0 ] ; }
Hydrate a model .
42,601
public function resolveModelClassName ( $ model ) { foreach ( $ this -> metadataFactory -> getAllMetadata ( ) as $ metadata ) { foreach ( $ metadata -> getFieldMappings ( ) as $ mapping ) { if ( is_a ( $ model , $ mapping -> getName ( ) ) ) { return $ metadata -> getName ( ) ; } } } return null ; }
Resolve model class name by sub model .
42,602
public function contains ( $ model ) { $ class = $ this -> getClassMetadata ( get_class ( $ model ) ) ; foreach ( $ class -> getFieldManagerNames ( ) as $ manager ) { if ( ! $ this -> pool -> getManager ( $ manager ) -> contains ( $ model -> { 'get' . ucfirst ( $ manager ) } ( ) ) ) { return false ; } } return true ; }
Determines whether a model instance is managed in this ModelManager .
42,603
protected function getIdentifierRepository ( $ className ) { $ class = $ this -> getClassMetadata ( $ className ) ; return $ this -> pool -> getManager ( $ class -> getManagerIdentifier ( ) ) -> getRepository ( $ class -> getFieldMapping ( $ class -> getManagerIdentifier ( ) ) -> getName ( ) ) ; }
Returns repository model given by identifier .
42,604
public function evaluateRule ( $ rule , $ limit = null ) { return $ this -> rulesEngineProvider -> evaluate ( $ rule ) -> getQueryResults ( $ limit ) ; }
Get the view for the placeholder
42,605
public function evaluateQueryRule ( QueryValue $ query , $ params = [ ] ) { if ( ( $ rule = $ query -> getRule ( ) ) instanceof Rule ) { $ environment = $ this -> rulesEngineProvider -> evaluate ( $ rule ) ; $ this -> rulesEngineProvider -> setQueryParams ( $ query -> getId ( ) , $ params ) ; return $ environment -> getQueryResults ( ) ; } return [ ] ; }
Evaluate rule with query parameters
42,606
public static function exists ( $ name ) { if ( isset ( $ _COOKIE [ $ name ] ) && ! empty ( $ _COOKIE [ $ name ] ) ) { return true ; } else { return false ; } }
Check if a cookie exists .
42,607
public static function create ( $ name , $ value , $ lifetime , $ path = '/' ) { $ expire = self :: lifetime ( $ lifetime ) ; return setcookie ( $ name , $ value , $ expire , $ path ) ; }
Create new cookie .
42,608
public function process ( TemplateInterface $ template ) { $ image = $ this -> imageManager -> make ( $ this -> image ) ; $ image = $ template -> process ( $ image ) ; if ( ! $ image -> isEncoded ( ) ) { $ image -> encode ( ) ; } return $ image ; }
Run the named template against the image .
42,609
public function setRequest ( Request $ request ) { $ this -> request = $ request ; $ this -> getContainer ( ) -> register ( 'request' , $ request ) ; return $ this ; }
Sets a new request
42,610
public function getContainer ( ) { if ( is_null ( self :: $ container ) ) { self :: $ container = $ this -> checkContainer ( ) ; } return self :: $ container ; }
Gets the application dependency injection container
42,611
public function getResponse ( ) { if ( is_null ( $ this -> response ) ) { $ this -> response = $ this -> getRunner ( ) -> run ( ) ; } return $ this -> response ; }
Returns the processed response
42,612
public function getRunner ( ) { if ( null === $ this -> runner ) { $ runner = $ this -> getContainer ( ) -> get ( 'middleware.runner' ) -> setRequest ( $ this -> getRequest ( ) ) ; $ this -> setRunner ( $ runner ) ; } return $ this -> runner ; }
Gets the HTTP middleware runner for this application
42,613
public function getConfigPath ( ) { if ( null == $ this -> configPath ) { $ this -> configPath = getcwd ( ) . '/Configuration' ; Configuration :: addPath ( $ this -> configPath ) ; } return $ this -> configPath ; }
Gets configuration path
42,614
protected function checkContainer ( ) { $ container = self :: $ defaultContainer ; if ( null != $ this -> configPath && file_exists ( $ this -> configPath . '/services.php' ) ) { $ definitions = include $ this -> configPath . '/services.php' ; $ container = ( new ContainerBuilder ( $ definitions , true ) ) -> getContainer ( ) ; } return $ container ; }
Gets container with user overridden settings
42,615
public function detect ( $ str , $ encodingList = [ 'UTF-8' , 'CP1252' ] ) { $ charset = mb_detect_encoding ( $ str , $ encodingList ) ; if ( $ charset === false ) { return false ; } $ this -> from = $ charset ; return true ; }
Attempts to detect the encoding of the given string from the encodingList .
42,616
public function convert ( $ str ) { if ( $ this -> from != $ this -> to ) { $ str = iconv ( $ this -> from , $ this -> to , $ str ) ; } if ( $ str === false ) { throw new Exception ( 'The convertion from "' . $ this -> from . '" to "' . $ this -> to . '" was a failure.' ) ; } if ( $ this -> to == 'UTF-8' ) { if ( substr ( $ str , 0 , 3 ) == "\xef\xbb\xbf" ) { $ str = substr ( $ str , 3 ) ; } if ( substr ( $ str , - 3 , 3 ) == "\xef\xbb\xbf" ) { $ str = substr ( $ str , 0 , - 3 ) ; } } return $ str ; }
Attempts to convert the string to the proper charset .
42,617
public function add ( $ child , $ other = null ) { if ( $ other ) { throw new \ Exception ( 'Inserting before not supported' ) ; } else { $ this -> children [ ] = $ child ; } return $ child ; }
Adds an child to this group
42,618
public function getDetails ( $ purchaseId ) { $ purchase = Purchase :: findOrFail ( $ purchaseId ) ; if ( ! in_array ( Auth :: user ( ) -> userId , [ $ purchase -> item -> seller -> userId , $ purchase -> buyer -> userId ] ) ) { return redirect ( '/inventory' ) -> withErrors ( [ "You are not the buyer or seller of this item." ] ) ; } return view ( 'mustard::purchase.details' , [ 'purchase' => $ purchase , ] ) ; }
Return the purchase details view .
42,619
public function getCheckout ( $ itemId ) { $ item = Item :: findOrFail ( $ itemId ) ; if ( $ item -> seller -> userId == Auth :: user ( ) -> userId ) { return redirect ( $ item -> url ) -> withErrors ( [ 'You cannot purchase your own items.' ] ) ; } if ( $ item -> auction && ! $ item -> isActive ( ) && $ item -> purchases -> count ( ) ) { return redirect ( '/pay/' . $ item -> purchases -> first ( ) -> purchaseId ) ; } if ( $ unpaid = $ item -> purchases ( ) -> where ( 'user_id' , Auth :: user ( ) -> userId ) -> where ( 'paid' , 0 ) -> first ( ) ) { return redirect ( '/pay/' . $ unpaid -> purchaseId ) ; } if ( ! $ item -> isActive ( ) && ! $ item -> auction ) { return redirect ( $ item -> url ) -> withErrors ( [ 'This item has ended.' ] ) ; } if ( $ item -> isActive ( ) && ! $ item -> hasFixed ( ) ) { return redirect ( $ item -> url ) -> withErrors ( [ 'This auction has no fixed price, so cannot be bought outright.' ] ) ; } if ( ! $ item -> isActive ( ) && $ item -> auction && ! $ item -> winningBid ) { return redirect ( $ item -> url ) -> withStatus ( 'Please wait while this auction is processed.' ) ; } return view ( 'mustard::purchase.checkout' , [ 'countries' => Iso3166 :: all ( ) , 'item' => $ item , 'item_total' => ( $ item -> auction && ! $ item -> isActive ( ) ) ? $ item -> biddingPrice : $ item -> fixedPrice , ] ) ; }
Return the item checkout view .
42,620
public function getPay ( $ purchaseId ) { $ purchase = Purchase :: findOrFail ( $ purchaseId ) ; if ( $ purchase -> buyer -> userId != Auth :: user ( ) -> userId ) { return redirect ( '/inventory/bought' ) -> withErrors ( [ "You are not the buyer of this item." ] ) ; } if ( $ purchase -> isPaid ( ) ) { return redirect ( '/inventory/bought' ) -> withStatus ( 'You have already successfully paid for this item.' ) ; } return view ( 'mustard::purchase.pay' , [ 'purchase' => $ purchase , ] ) ; }
Return the purchase pay view .
42,621
public function getDispatched ( $ purchaseId ) { $ purchase = Purchase :: findOrFail ( $ purchaseId ) ; if ( $ purchase -> item -> seller -> userId != Auth :: user ( ) -> userId ) { return redirect ( '/inventory/sold' ) -> withErrors ( [ "You are not seller of this item." ] ) ; } if ( $ purchase -> isDispatched ( ) ) { return redirect ( '/inventory/sold' ) -> withStatus ( 'You have already marked this item as dispatched.' ) ; } if ( ! $ purchase -> deliveryOption ) { return redirect ( ) -> back ( ) -> withErrors ( [ "This item is due to be collected." ] ) ; } return view ( 'mustard::purchase.dispatched' , [ 'purchase' => $ purchase , ] ) ; }
Return the purchase dispatched view .
42,622
public function getCollectionAddress ( $ purchaseId ) { $ purchase = Purchase :: findOrFail ( $ purchaseId ) ; if ( $ purchase -> item -> seller -> userId != Auth :: user ( ) -> userId ) { return redirect ( '/inventory/sold' ) -> withErrors ( [ "You are not the seller of this item." ] ) ; } if ( $ purchase -> deliveryOption ) { return redirect ( '/inventory/sold' ) -> withErrors ( [ "This item is not due to be collected." ] ) ; } if ( $ purchase -> hasAddress ( ) ) { return redirect ( '/inventory/sold' ) -> withErrors ( [ "You have already provided a collection address for this item." ] ) ; } return view ( 'mustard::purchase.collection-address' , [ 'countries' => Iso3166 :: all ( ) , 'purchase' => $ purchase , ] ) ; }
Return the purchase collection address view .
42,623
public function postDispatched ( Request $ request ) { $ purchase = Purchase :: findOrFail ( $ request -> input ( 'purchase_id' ) ) ; if ( $ purchase -> item -> seller -> userId != Auth :: user ( ) -> userId ) { return redirect ( '/inventory/sold' ) -> withErrors ( [ "You are not seller of this item." ] ) ; } if ( $ purchase -> isDispatched ( ) ) { return redirect ( '/inventory/sold' ) -> withErrors ( [ "This item has already been marked as dispatched." ] ) ; } if ( ! $ purchase -> deliveryOption ) { return redirect ( '/inventory/sold' ) -> withErrors ( [ "This item is due to be collected." ] ) ; } $ purchase -> dispatched = time ( ) ; $ purchase -> trackingNumber = $ request -> input ( 'tracking_number' ) ; $ purchase -> save ( ) ; $ purchase -> buyer -> sendEmail ( 'Your item has been dispatched' , 'emails.item.dispatched' , [ 'item_name' => $ purchase -> item -> name , 'delivery_service' => $ purchase -> deliveryOption -> name , 'tracking_number' => $ purchase -> trackingNumber , 'arrival_time' => $ purchase -> deliveryOption -> humanArrivalTime , ] ) ; return redirect ( '/inventory/sold' ) -> withStatus ( "This item has been marked as dispatched and the buyer notified." ) ; }
Mark a purchase dispatched .
42,624
public static function paymentReceived ( Purchase $ purchase , $ amount ) { $ purchase -> received += $ amount ; if ( $ purchase -> received >= $ purchase -> grandTotal ) { $ purchase -> paid = time ( ) ; $ purchase -> item -> seller -> sendEmail ( 'You have received a payment' , 'emails.item.paid' , [ 'total' => $ purchase -> received , 'item_name' => $ purchase -> item -> name , 'buyer_name' => $ purchase -> name , 'buyer_street1' => $ purchase -> street1 , 'buyer_street2' => $ purchase -> street2 , 'buyer_city' => $ purchase -> city , 'buyer_county' => $ purchase -> county , 'buyer_postcode' => $ purchase -> postcode , 'buyer_country' => Iso3166 :: get ( $ purchase -> country ) -> name , 'has_delivery' => $ purchase -> hasDelivery ( ) , 'has_address' => $ purchase -> hasAddress ( ) , 'purchase_id' => $ purchase -> purchaseId , 'full' => $ purchase -> received == 0 , ] ) ; $ purchase -> buyer -> sendEmail ( 'Receipt for your item' , 'emails.item.receipt' , [ 'total' => $ purchase -> received , 'item_name' => $ purchase -> item -> name , 'seller_name' => $ purchase -> name , 'seller_street1' => $ purchase -> street1 , 'seller_street2' => $ purchase -> street2 , 'seller_city' => $ purchase -> city , 'seller_county' => $ purchase -> county , 'seller_postcode' => $ purchase -> postcode , 'seller_country' => Iso3166 :: get ( $ purchase -> country ) -> name , 'full' => $ purchase -> received == 0 , 'has_delivery' => $ purchase -> hasDelivery ( ) , 'has_address' => $ purchase -> hasAddress ( ) , 'is_paid' => $ purchase -> isPaid ( ) ] ) ; } $ purchase -> save ( ) ; }
Register a received amount against a purchase .
42,625
public static function paymentRefunded ( Purchase $ purchase , $ amount ) { $ purchase -> refunded = time ( ) ; $ purchase -> refundedAmount = $ amount ; $ purchase -> buyer -> sendEmail ( 'You have been refunded' , 'emails.item.refunded' , [ 'total' => $ purchase -> refundedAmount , 'item_name' => $ purchase -> item -> name , ] ) ; $ purchase -> save ( ) ; }
Register a refunded amount against a purchase .
42,626
public static function paymentFailed ( Purchase $ purchase , $ amount ) { Log :: info ( "Payment failed ({$purchase->purchaseId})" ) ; $ purchase -> buyer -> sendEmail ( 'Your payment has failed' , 'emails.item.failed' , [ 'total' => $ amount , 'item_name' => $ purchase -> item -> name , 'payment_id' => $ purchase -> purchaseId , ] ) ; }
Register a failed amount against a purchase .
42,627
public function instance ( $ name , $ instance ) { list ( $ name , $ alias ) = $ this -> extractName ( $ name ) ; $ componentName = $ this -> getAlias ( $ name ) ; if ( $ this -> isSingleton ( $ componentName ) && $ this -> resolved ( $ componentName ) ) { throw new ComponentRegisterException ( 'Can\'t register component, The ' . $ name . ' component is singleton, and it had resolved' ) ; } if ( ! is_null ( $ alias ) ) { $ this -> alias ( $ alias , $ name ) ; } $ this -> instances [ $ name ] = $ instance ; }
Register component instance
42,628
public function extend ( $ name , Closure $ extender ) { $ name = $ this -> getAlias ( $ name ) ; $ component = & $ this -> components [ $ name ] ; if ( ! isset ( $ component [ 'extender' ] ) ) { $ component [ 'extender' ] = [ ] ; } if ( $ this -> isSingleton ( $ name ) ) { $ component = $ this -> make ( $ name ) ; $ component = $ this -> resolveExtend ( $ name , $ component ) ; return $ this -> instance ( $ name , $ component ) ; } array_push ( $ component [ 'extender' ] , $ extender ) ; }
Extend component . If component is singleton this method will resolve extend and return new instance .
42,629
public function make ( $ name , $ parameters = [ ] ) { $ name = $ this -> getAlias ( $ name ) ; if ( is_string ( $ name ) && $ this -> resolved ( $ name ) ) { return $ this -> instances [ $ name ] ; } if ( is_callable ( $ name ) || ( is_string ( $ name ) && ! $ this -> registered ( $ name ) ) ) { return $ this -> build ( $ name , $ parameters ? : [ ] ) ; } list ( $ builder , $ singleton ) = $ this -> extractComponentBuilder ( $ name ) ; $ component = $ this -> build ( $ builder , $ parameters ) ; if ( $ this -> hasExtender ( $ name ) ) { $ extenders = $ this -> getExtenders ( $ name ) ; $ component = $ this -> resolveExtend ( $ component , $ extenders ) ; } if ( $ singleton ) { $ this -> instance ( $ name , $ component ) ; } return $ component ; }
Make component instance
42,630
public function resolveExtend ( $ component , $ extenders ) { foreach ( $ extenders as $ extender ) { $ component = $ extender ( $ component ) ; } return $ component ; }
Resolve component extention
42,631
protected function extractComponentBuilder ( $ name ) { $ componentBuilder = $ this -> components [ $ name ] ; if ( ! $ componentBuilder ) { return [ $ name , false ] ; } return [ $ componentBuilder [ 'builder' ] , $ componentBuilder [ 'singleton' ] ] ; }
Extract component builder .
42,632
public function alias ( $ alias , $ name ) { if ( is_array ( $ alias ) ) { foreach ( $ alias as $ key ) { $ this -> alias ( $ key , $ name ) ; } return ; } $ this -> aliases [ $ alias ] = $ name ; }
Register component alias
42,633
public function getAlias ( $ alias ) { if ( ! is_string ( $ alias ) ) { return $ alias ; } if ( array_key_exists ( $ alias , $ this -> aliases ) ) { return $ this -> aliases [ $ alias ] ; } return $ alias ; }
Get component name by alias
42,634
public function registered ( $ name ) { $ name = $ this -> getAlias ( $ name ) ; return array_key_exists ( $ name , $ this -> components ) ; }
Determine component has been registered
42,635
public function resolved ( $ name ) { $ name = $ this -> getAlias ( $ name ) ; return array_key_exists ( $ name , $ this -> instances ) ; }
Determine component has been resolved
42,636
private function extractName ( $ name ) { if ( is_string ( $ name ) ) { return [ $ name , null ] ; } if ( is_array ( $ name ) ) { return [ key ( $ name ) , current ( $ name ) ] ; } throw new ComponentRegisterException ( 'The services\'s name must be a string or an array, ' . gettype ( $ name ) . ' given.' ) ; }
Extract Name and Aliases .
42,637
public function getAttributes ( $ updated = false ) { if ( ! $ updated ) return $ this -> attributes ; $ attributes = array ( ) ; foreach ( $ this -> attributes as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ this -> o_attributes ) || $ value != $ this -> o_attributes [ $ key ] ) { $ attributes [ $ key ] = $ value ; } } return $ attributes ; }
get attributes .
42,638
public function toArray ( ) { $ args = func_get_args ( ) ; if ( $ args ) { $ attributes = [ ] ; foreach ( $ args as $ key ) { if ( $ this -> hasAttribute ( $ key ) ) { $ attributes [ $ key ] = $ this -> get ( $ key ) ; } } return $ attributes ; } else { return $ this -> attributes ; } }
convert to Array
42,639
public static function mergeArrayIntoEntity ( $ targetEntity , $ array ) { foreach ( $ array as $ property => $ value ) { if ( ! empty ( $ value ) ) { if ( is_a ( $ targetEntity -> { 'get' . ucfirst ( $ property ) } ( ) , '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage' ) ) { $ targetEntity -> { 'set' . ucfirst ( $ property ) } ( new ObjectStorage ( ) ) ; if ( is_array ( $ value ) ) { $ singular = ( preg_match ( '~s$~i' , $ property ) > 0 ) ? rtrim ( $ property , 's' ) : sprintf ( '%ss' , $ property ) ; foreach ( $ value as $ item ) { $ targetEntity -> { 'add' . ucfirst ( $ singular ) } ( $ item ) ; } } } else { $ targetEntity -> { 'set' . ucfirst ( $ property ) } ( $ value ) ; } } } return $ targetEntity ; }
Merges array data into an entity
42,640
public static function arrayToObjectStorage ( $ entity , $ array ) { $ storage = GeneralUtility :: makeInstance ( 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage' ) ; foreach ( $ array as $ item ) { $ storage -> attach ( EntityUtility :: mergeArrayIntoEntity ( $ entity , $ item ) ) ; } return $ storage ; }
Transforms an array into ObjectStorage
42,641
public static function mergeEntities ( $ targetEntity , $ mergeEntity ) { $ reflect = new \ ReflectionClass ( $ mergeEntity ) ; $ properties = $ reflect -> getProperties ( \ ReflectionProperty :: IS_PUBLIC | \ ReflectionProperty :: IS_PROTECTED ) ; foreach ( $ properties as $ property ) { if ( ! method_exists ( $ mergeEntity , 'get' . ucfirst ( $ property -> getName ( ) ) ) ) { continue ; } $ value = $ mergeEntity -> { 'get' . ucfirst ( $ property -> getName ( ) ) } ( ) ; if ( is_a ( $ value , '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage' ) ) { $ targetEntity -> { 'set' . ucfirst ( $ property -> getName ( ) ) } ( new ObjectStorage ( ) ) ; $ singular = ( preg_match ( '~s$~i' , $ property -> getName ( ) ) > 0 ) ? rtrim ( $ property -> getName ( ) , 's' ) : sprintf ( '%ss' , $ property -> getName ( ) ) ; foreach ( $ value -> toArray ( ) as $ item ) { $ targetEntity -> { 'add' . ucfirst ( $ singular ) } ( $ item ) ; } } elseif ( ! empty ( trim ( $ value ) ) ) { $ targetEntity -> { 'set' . ucfirst ( $ property -> getName ( ) ) } ( $ value ) ; } } return $ targetEntity ; }
Merges two equal entities into the target entity
42,642
public function run ( ) { if ( PHP_SAPI === 'cli' && is_subclass_of ( $ this , ConsoleAppInterface :: class ) ) { $ this -> execConsoleApp ( ) ; } else if ( is_subclass_of ( $ this , WebAppInterface :: class ) ) { $ this -> execWebApp ( ) ; } else { throw new \ Exception ( "No interface was implemented" ) ; } }
Executes the application
42,643
protected function execWebApp ( ) { $ config = $ this -> getConfigArray ( ) ; $ container = new Container ( [ "settings" => $ config ] ) ; $ app = new App ( $ container ) ; $ this -> setupDependencies ( $ container ) ; $ this -> setupMiddlewares ( $ app , $ container ) ; $ this -> setupErrorHandler ( $ container ) ; $ this -> setupRoutes ( $ app , $ container ) ; $ app -> run ( ) ; }
Executes a web application
42,644
protected function execConsoleApp ( ) { $ app = new Application ( ) ; $ config = $ this -> getConfigArray ( ) ; $ container = new Container ( [ "settings" => $ config ] ) ; $ this -> setupDependencies ( $ container ) ; $ this -> setupCommands ( $ app , $ container ) ; $ app -> run ( ) ; }
Executes a console application
42,645
public function add ( View $ view ) { $ this -> stack -> append ( $ view ) ; if ( $ view -> getType ( ) === View :: PART_BODY_PLACEHOLDER ) { $ this -> bodyKey = ( count ( $ this -> stack ) - 1 ) ; } return count ( $ this -> stack ) ; }
Add a view instance to the stack .
42,646
public function body ( View $ view ) { if ( $ view -> getType ( ) !== View :: PART_BODY ) { throw new RendererException ( "You are replacing the body with a non-body view!" ) ; } if ( $ this -> bodyKey === null ) { throw new RendererException ( "No body is defined in the template!" ) ; } $ this -> stack [ $ this -> bodyKey ] = $ view ; }
Set the body replacement view .
42,647
public function hasBodyPlaceholderEmpty ( ) { if ( $ this -> bodyKey !== null ) { if ( isset ( $ this -> stack [ $ this -> bodyKey ] ) ) { if ( $ this -> stack [ $ this -> bodyKey ] -> getType ( ) === View :: PART_BODY_PLACEHOLDER ) { return true ; } } } return false ; }
Check if we have a body placeholder still empty .
42,648
public function replaceAll ( $ stack , $ resetBodyKey = true ) { if ( ! $ stack instanceof DataCollection ) { $ stack = new DataCollection ( $ stack ) ; } $ this -> stack = $ stack ; if ( $ resetBodyKey ) { $ this -> bodyKey = null ; foreach ( $ stack as $ key => $ view ) { if ( $ view -> getType ( ) === View :: PART_BODY_PLACEHOLDER ) { $ this -> bodyKey = $ key ; } } } }
Replace all stack items for the array given
42,649
public function run ( $ return = false ) { $ output = "" ; foreach ( $ this -> stack as $ view ) { $ data = $ view -> getData ( ) ; if ( ! is_array ( $ data ) ) { $ data = array ( ) ; } if ( $ view -> getType ( ) === View :: PART_BODY_PLACEHOLDER ) { throw new RendererException ( "The body placeholder isn't replaced!" ) ; } if ( ! empty ( $ this -> globalData ) ) { $ data = array_merge ( $ data , $ this -> globalData ) ; } $ engineClass = $ view -> getEngine ( ) ; $ engine = $ engineClass -> newInstance ( ) ; if ( ! $ engine instanceof RendererInterface ) { throw new RendererException ( "Engine is not instance of the RendererInterface." ) ; } $ output .= $ engine -> render ( $ view , $ data ) ; } if ( $ return ) { return $ output ; } return new Response ( $ output , 200 ) ; }
Render all views in the stack .
42,650
protected function setExceptionDetails ( string $ reason , int $ code , array $ stack = [ ] ) { $ this -> setErrorDetails ( $ reason , $ code ) ; $ this -> setDebugDetails ( $ stack ) ; }
Set the exception details building its error and debug entry .
42,651
protected function setDebugDetails ( array $ stack ) { $ stackInfo = new StackInfo ( $ stack ) ; $ this -> setDebug ( ArrayContainer :: make ( [ 'class' => $ stackInfo -> getClassNameFromLastStack ( ) , 'method' => $ stackInfo -> getMethodNameFromLastStack ( ) , 'args' => $ stackInfo -> getArgsFromLastStack ( ) , ] ) ) ; }
Set the exception debug details
42,652
protected function setErrorDetails ( string $ reason , int $ code ) { $ this -> setError ( ArrayContainer :: make ( [ 'code' => $ code , 'message' => $ reason , ] ) ) ; }
Set the exception error details
42,653
public function setUrl ( $ date , $ urlFormat = ':year/:month/:date/:title' ) { $ year = date ( 'Y' , strtotime ( $ date ) ) ; $ month = date ( 'm' , strtotime ( $ date ) ) ; $ day = date ( 'd' , strtotime ( $ date ) ) ; $ title = explode ( '-' , $ this -> getFileName ( ) , 4 ) ; $ this -> url = '/' . str_replace ( array ( ':date' , ':month' , ':year' , ':title' ) , array ( $ day , $ month , $ year , $ title [ 3 ] . '.html' ) , $ urlFormat ) ; }
Set URL to Post
42,654
public function buildFilterCallback ( array $ except = [ ] ) { $ filter = $ this ; return function ( $ path ) use ( $ filter , $ except ) { return ! $ filter -> filter ( [ $ path ] , $ except , true ) ; } ; }
Returns callable which can be used by third - party code for determining what some file should be excluded from result set .
42,655
public function getCollections ( $ options = [ ] ) { $ list = [ ] ; foreach ( $ this -> db -> listCollections ( $ options ) as $ coll ) { $ list [ ] = $ coll -> getName ( ) ; } return $ list ; }
Get collections list .
42,656
public function collection ( $ name ) { $ builder = new Builder ( $ this , $ name , $ this -> db -> selectCollection ( $ name ) ) ; return $ builder ; }
Get collection by name .
42,657
public function getIndexs ( $ collection , $ options = [ ] ) { if ( ! $ this -> hasCollection ( $ collection ) ) { return [ ] ; } $ list = [ ] ; foreach ( $ this -> db -> selectCollection ( $ collection ) -> listIndexes ( $ options ) as $ index ) { $ list [ ] = $ index -> getName ( ) ; } return $ list ; }
Get index list in collection .
42,658
public function createIndex ( $ collection , $ columns , array $ options = [ ] ) { $ col = $ this -> db -> selectCollection ( $ collection ) ; return $ col -> createIndex ( $ columns , $ options ) ; }
Create new index .
42,659
public function dropIndex ( $ collection , $ indexName , array $ options = [ ] ) { $ col = $ this -> db -> selectCollection ( $ collection ) ; return $ col -> dropIndex ( $ indexName , $ options ) ; }
Drop a index .
42,660
protected function createClient ( $ dsn , array $ config , array $ options ) { $ driverOptions = [ ] ; if ( isset ( $ config [ 'driver_options' ] ) && is_array ( $ config [ 'driver_options' ] ) ) { $ driverOptions = $ config [ 'driver_options' ] ; } if ( ! isset ( $ options [ 'username' ] ) && ! empty ( $ config [ 'username' ] ) ) { $ options [ 'username' ] = $ config [ 'username' ] ; } if ( ! isset ( $ options [ 'password' ] ) && ! empty ( $ config [ 'password' ] ) ) { $ options [ 'password' ] = $ config [ 'password' ] ; } return new Client ( $ dsn , $ options , $ driverOptions ) ; }
Create a new MongoDB client connection .
42,661
public function isPathCovered ( $ path ) { foreach ( $ this -> patterns as $ pattern ) { if ( 1 === preg_match ( '{' . $ pattern . '}' , $ path ) ) { return true ; } } return false ; }
Check if the provided path is covered by this firewall or not
42,662
public function addAuthenticationFactory ( AuthenticationFactoryInterface $ authFactory , UserProviderInterface $ userProvider ) { $ id = $ authFactory -> getId ( ) ; $ this -> authFactories [ $ id ] = array ( 'factory' => $ authFactory , 'userProvider' => $ userProvider , ) ; $ this -> userProviders [ ] = $ userProvider ; if ( $ this -> provider ) { $ this -> registerAuthenticationFactory ( $ this -> provider -> getApp ( ) , $ id , $ authFactory , $ userProvider ) ; } return $ this ; }
Add additional authentication factory and corresponding user provider .
42,663
public function register ( SecurityServiceProvider $ provider ) { $ this -> provider = $ provider ; if ( $ this -> loginPath ) { $ this -> provider -> addUnsecurePattern ( "^{$this->loginPath}$" ) ; } $ config = array ( 'logout' => array ( 'logout_path' => $ this -> logoutPath ) , 'pattern' => implode ( '|' , $ this -> patterns ) ) ; $ app = $ this -> provider -> getApp ( ) ; foreach ( $ this -> authFactories as $ id => $ authFactory ) { $ this -> registerAuthenticationFactory ( $ app , $ id , $ authFactory [ 'factory' ] , $ authFactory [ 'userProvider' ] ) ; $ config [ $ id ] = array ( ) ; if ( $ this -> loginPath ) { $ config [ $ id ] [ 'login_path' ] = $ this -> loginPath ; $ config [ $ id ] [ 'check_path' ] = $ this -> loginCheckPath ; } } $ this -> registerUserProvider ( $ app ) ; $ this -> registerContextListener ( $ app ) ; $ this -> registerEntryPoint ( $ app ) ; $ this -> provider -> appendFirewallConfig ( $ this -> name , $ config ) ; }
Register the Firewall
42,664
protected function registerAuthenticationFactory ( \ Silex \ Application $ app , $ id , AuthenticationFactoryInterface $ authFactory , UserProviderInterface $ userProvider ) { $ fac = 'security.authentication_listener.factory.' . $ id ; if ( isset ( $ app [ $ fac ] ) ) { return ; } $ app [ $ fac ] = $ app -> protect ( function ( $ name , $ options ) use ( $ app , $ id , $ authFactory , $ userProvider ) { $ type = ( isset ( $ options [ 'login_path' ] ) ? 'form' : 'http' ) ; $ entry_point = "security.entry_point.$name.$type" ; if ( $ type == 'form' ) { $ options [ 'failure_forward' ] = true ; } $ auth_provider = "security.authentication_provider.$name.$id" ; $ app [ $ auth_provider ] = $ app -> share ( function ( ) use ( $ app , $ name , $ authFactory , $ userProvider ) { return $ authFactory -> createAuthenticationProvider ( $ app , $ userProvider , $ name ) ; } ) ; $ auth_listener = "security.authentication_listener.$name.$type" ; if ( ! isset ( $ app [ $ auth_listener ] ) ) { $ app [ $ auth_listener ] = $ app [ "security.authentication_listener.$type._proto" ] ( $ name , $ options ) ; } return array ( $ auth_provider , $ auth_listener , $ entry_point , 'pre_auth' ) ; } ) ; }
Register authentication factory and user provider .
42,665
protected function registerUserProvider ( \ Silex \ Application $ app ) { $ user_provider = 'security.user_provider.' . $ this -> name ; $ app [ $ user_provider ] = $ app -> share ( function ( ) { return new ChainUserProvider ( $ this -> userProviders ) ; } ) ; return $ user_provider ; }
Register User Provider
42,666
protected function registerContextListener ( \ Silex \ Application $ app ) { $ context_listener = 'security.context_listener.' . $ this -> name ; $ app [ $ context_listener ] = $ app -> share ( function ( ) use ( $ app ) { return new ContextListener ( $ app [ 'security.token_storage' ] , $ this -> userProviders , $ this -> name , $ app [ 'logger' ] , $ app [ 'dispatcher' ] ) ; } ) ; return $ context_listener ; }
Register Context Listener
42,667
protected function registerEntryPoint ( \ Silex \ Application $ app ) { $ entry_point = 'security.entry_point.' . $ this -> name . ( empty ( $ this -> loginPath ) ? '.http' : '.form' ) ; $ app [ $ entry_point ] = $ app -> share ( function ( ) use ( $ app ) { return $ this -> loginPath ? new FormAuthenticationEntryPoint ( $ app , $ app [ 'security.http_utils' ] , $ this -> loginPath , true ) : new BasicAuthenticationEntryPoint ( 'Secured' ) ; } ) ; return $ entry_point ; }
Register Entry Point
42,668
protected function generatePaths ( ) { if ( $ this -> loginPath && ! $ this -> loginCheckPath ) { foreach ( $ this -> patterns as $ pattern ) { $ base = substr ( $ pattern , 1 ) ; if ( preg_quote ( $ base ) != $ base ) { continue ; } if ( substr ( $ base , - 1 ) != '/' ) { $ base .= '/' ; } $ this -> loginCheckPath = $ base . 'login_check' ; $ this -> logoutPath = $ base . 'logout' ; break ; } if ( ! $ this -> loginCheckPath ) { static $ underscorePad = 0 ; $ underscorePad ++ ; $ this -> loginCheckPath = '/' . str_repeat ( '_' , $ underscorePad ) . 'login_check' ; $ this -> logoutPath = '/' . str_repeat ( '_' , $ underscorePad ) . 'logout' ; $ this -> patterns [ ] = "^{$this->loginCheckPath}$" ; $ this -> patterns [ ] = "^{$this->logoutPath}$" ; } } }
Generate loginCheckPath & logoutPath .
42,669
protected function startResourcesPlugin ( ) { $ this -> requiresPlugins ( Paths :: class ) ; $ this -> onBoot ( 'resources' , function ( ) { foreach ( $ this -> viewDirs as $ dirName => $ namespace ) { $ viewPath = $ this -> resolvePath ( 'viewsPath' , compact ( 'dirName' ) ) ; $ this -> loadViewsFrom ( $ viewPath , $ namespace ) ; $ this -> publishes ( [ $ viewPath => $ this -> resolvePath ( 'viewsDestinationPath' , compact ( 'namespace' ) ) ] , 'views' ) ; } foreach ( $ this -> translationDirs as $ dirName => $ namespace ) { $ transPath = $ this -> resolvePath ( 'translationPath' , compact ( 'dirName' ) ) ; $ this -> loadTranslationsFrom ( $ transPath , $ namespace ) ; $ this -> publishes ( [ $ transPath => $ this -> resolvePath ( 'translationDestinationPath' , compact ( 'namespace' ) ) ] , 'translations' ) ; } foreach ( $ this -> assetDirs as $ dirName => $ namespace ) { $ this -> publishes ( [ $ this -> resolvePath ( 'assetsPath' , compact ( 'dirName' ) ) => $ this -> resolvePath ( 'assetsDestinationPath' , compact ( 'namespace' ) ) , ] , 'public' ) ; } foreach ( $ this -> migrationDirs as $ dirName ) { $ migrationPaths = $ this -> resolvePath ( 'migrationsPath' , compact ( 'dirName' ) ) ; $ this -> loadMigrationsFrom ( $ migrationPaths ) ; if ( $ this -> publishMigrations ) { $ this -> publishes ( [ $ migrationPaths => $ this -> resolvePath ( 'migrationDestinationPath' ) ] , 'database' ) ; } } foreach ( $ this -> seedDirs as $ dirName ) { $ this -> publishes ( [ $ this -> resolvePath ( 'seedsPath' , compact ( 'dirName' ) ) => $ this -> resolvePath ( 'seedsDestinationPath' ) ] , 'database' ) ; } } ) ; }
startPathsPlugin method .
42,670
private function generateFormData ( ) { $ files = $ this -> getConfigFiles ( ) ; $ formDataHolder = [ ] ; if ( ! empty ( $ files ) ) { foreach ( $ files as $ file ) { $ file = json_decode ( file_get_contents ( $ file ) , true ) ; if ( isset ( $ file [ 'formData' ] ) ) $ formDataHolder = array_merge ( $ formDataHolder , $ file [ 'formData' ] ) ; } } Cache :: forget ( 'hc-forms' ) ; Cache :: put ( 'hc-forms' , $ formDataHolder , Carbon :: now ( ) -> addMonth ( ) ) ; }
Generating form data
42,671
public function add ( string $ name , string $ value ) : void { $ key = strtolower ( $ name ) ; if ( ! isset ( $ this -> headers [ $ key ] ) ) { $ this -> headers [ $ key ] = [ $ name , $ value ] ; return ; } $ this -> headers [ $ key ] = [ $ name , $ this -> headers [ $ key ] [ 1 ] . ', ' . $ value ] ; }
Adds a header value by header name .
42,672
public function get ( string $ name ) : ? string { $ key = strtolower ( $ name ) ; if ( ! isset ( $ this -> headers [ $ key ] ) ) { return null ; } return $ this -> headers [ $ key ] [ 1 ] ; }
Returns the header value by header name if it exists null otherwise .
42,673
public function set ( string $ name , string $ value ) : void { $ key = strtolower ( $ name ) ; $ this -> headers [ $ key ] = [ $ name , $ value ] ; }
Sets a header value by header name .
42,674
public function put ( $ name , $ value ) { if ( is_object ( $ value ) && ! $ this -> isValidObjectInstance ( $ value ) ) { throw new InvalidCollectionItemInstanceException ( sprintf ( '%s must implement %s' , $ name , $ this -> classname ) ) ; } $ this -> items [ $ name ] = $ value ; return $ this -> items [ $ name ] ; }
Add a new item to collection .
42,675
private function isValidObjectInstance ( $ object ) { if ( ! is_null ( $ this -> classname ) && ! $ this -> isInstanceOrSubclassOf ( $ object ) ) { return false ; } return true ; }
Verify s if the given object has a valid instance .
42,676
public function findOrFail ( $ name ) { $ result = $ this -> find ( $ name ) ; if ( is_null ( $ result ) ) { throw new CollectionItemNotFoundException ( sprintf ( 'Collection item "%s" not found' , $ name ) ) ; } return $ result ; }
Find a specific collection item or throw s an exception .
42,677
private function filterByKeys ( array $ keys ) { $ results = [ ] ; foreach ( $ this -> items as $ key => $ value ) { if ( ! in_array ( $ key , $ keys ) ) { continue ; } $ results [ $ key ] = $ value ; } return $ results ; }
Filter items by key name .
42,678
public function only ( $ key ) { $ keys = is_array ( $ key ) ? $ key : func_get_args ( ) ; return new static ( $ this -> classname , $ this -> filterByKeys ( $ keys ) ) ; }
Get all items with the specified keys .
42,679
public function filter ( callable $ callback = null ) { if ( is_null ( $ callback ) ) { return new static ( $ this -> classname , array_filter ( $ this -> items ) ) ; } return new static ( $ this -> classname , array_filter ( $ this -> items , $ callback ) ) ; }
Filter the elements in the collection using a callback function .
42,680
public function nest ( ) { $ target = $ this -> getCurrentPredicate ( ) ; if ( $ operator = $ this -> getDefaultOperator ( ) ) { $ target -> $ operator ; } $ this -> nestings [ ] = $ target -> nest ( ) ; $ this -> nestedOperators [ ] = $ this -> getDefaultOperator ( ) ; return $ this ; }
Begings a new nesting .
42,681
public function wOr ( ) { $ this -> setDefaultOperator ( PredicateSet :: OP_OR ) ; if ( func_num_args ( ) ) { call_user_func_array ( [ $ this , 'condition' ] , func_get_args ( ) ) ; $ this -> endOr ( ) ; } return $ this ; }
Same as wAnd .
42,682
protected function addCondition ( $ method , array $ params ) { $ target = $ this -> getCurrentPredicate ( ) ; if ( $ operator = $ this -> getDefaultOperator ( ) ) { $ target -> $ operator ; } call_user_func_array ( [ $ target , $ method ] , $ params ) ; }
Actually adds the condition to the proper target .
42,683
private function newCart ( ) { $ this -> clearCart ( ) ; $ this -> setCart ( $ this -> repository -> createNew ( OrderTypes :: TYPE_CART ) ) ; return $ this -> cart ; }
Creates a new cart .
42,684
public static function getOpenStatusCodes ( ) { return array ( self :: STATUS_NEW , self :: STATUS_ACCEPTED_BY_SELLER , self :: STATUS_REJECTED_BY_SELLER , self :: STATUS_IN_PICK_AT_SELLER , self :: STATUS_READY_FOR_DISPATCH_TO_HUB , self :: STATUS_IN_TRANSIT_TO_HUB , self :: STATUS_READY_FOR_PICKUP_FROM_HUB , self :: STATUS_AT_HUB , ) ; }
Get open status codes
42,685
public function getSumOfLineItems ( ) { $ amount = 0 ; foreach ( $ this -> getLineItems ( ) as $ lineItem ) { $ amount += $ lineItem -> getPrice ( ) * $ lineItem -> getQuantity ( ) ; } return round ( $ amount , 2 ) ; }
Get sum of line items
42,686
public function getLineItemForProduct ( Product $ product ) { foreach ( $ this -> getLineItems ( ) as $ lineItem ) { if ( $ lineItem -> getProduct ( ) -> getId ( ) == $ product -> getId ( ) ) { return $ lineItem ; } } return $ this -> createLineItemForProduct ( $ product ) ; }
Get OrderLineItem for given Product
42,687
public function createLineItemForProduct ( Product $ product ) { $ lineItem = new OrderLineItem ( ) ; $ lineItem -> setProduct ( $ product ) ; $ lineItem -> setQuantity ( 0 ) ; $ this -> addLineItem ( $ lineItem ) ; if ( $ this -> getSellerWindow ( ) ) { $ lineItem -> setSellerWindow ( $ this -> getSellerWindow ( ) ) ; } return $ lineItem ; }
Create OrderLineItem for given Product
42,688
public function getInvoiceIdForPaymentGateway ( ) { return implode ( str_split ( str_pad ( $ this -> getSeller ( ) -> getId ( ) , 6 , 0 , STR_PAD_LEFT ) , 3 ) , '-' ) . ' / ' . implode ( str_split ( str_pad ( $ this -> getId ( ) , 6 , 0 , STR_PAD_LEFT ) , 3 ) , '-' ) . ' / ' . $ this -> getSeller ( ) -> getName ( ) ; }
Get invoiceId for PaymentGateway
42,689
public function canBeDispatchedBySeller ( ) { switch ( $ this -> getStatusCode ( ) ) { case self :: STATUS_ACCEPTED_BY_SELLER : case self :: STATUS_IN_PICK_AT_SELLER : case self :: STATUS_READY_FOR_DISPATCH_TO_HUB : return true ; default : return false ; } }
Can be dispatched by Seller
42,690
protected function error ( Request $ request , \ Exception $ exception ) { return $ request -> getTarget ( ) . ' threw ' . get_class ( $ exception ) . ': ' . $ exception -> getMessage ( ) . "\n" . $ exception -> getTraceAsString ( ) ; }
Is called if an error is caught while running the delivery
42,691
public function getValue ( ) { $ grammar = Manager :: connection ( ) -> getQueryGrammar ( ) ; return vsprintf ( $ this -> value , array_map ( function ( $ val ) use ( $ grammar ) { return $ grammar -> wrap ( $ val ) ; } , $ this -> replace ) ) ; }
Get the value of the expression .
42,692
public function clearCache ( ) { $ objects = scandir ( $ this -> getCachePath ( ) ) ; $ dir = $ this -> getCachePath ( ) ; foreach ( $ objects as $ object ) { if ( $ object != "." && $ object != ".." ) { if ( is_dir ( $ dir . $ object ) ) { self :: rrmdir ( $ dir . $ object ) ; } elseif ( $ object !== 'cache_config' ) { unlink ( $ dir . $ object ) ; } } } return $ this ; }
Removes all entries in the cache . Keeps cache_config and cache s folder .
42,693
private function buildLevelsString ( $ levels ) { $ this -> levelsString = join ( DIRECTORY_SEPARATOR , array_fill ( 0 , $ levels , '%s' ) ) . DIRECTORY_SEPARATOR ; return $ this ; }
Builds a string with placeholders and directory separators required to create a path for saving a final cache entry .
42,694
public static function create ( DictionaryInterface $ sourceDictionary , WritableDictionaryInterface $ targetDictionary , LoggerInterface $ logger = null ) : CopyDictionaryJob { $ instance = new static ( $ sourceDictionary , $ targetDictionary ) ; if ( $ logger ) { $ instance -> setLogger ( $ logger ) ; } return $ instance ; }
Static helper for fluent coding .
42,695
public function setCopySource ( int $ copySource = self :: COPY ) : CopyDictionaryJob { $ this -> copySource = $ copySource ; return $ this ; }
Set copySource .
42,696
public function setCopyTarget ( int $ copyTarget = self :: COPY ) : CopyDictionaryJob { $ this -> copyTarget = $ copyTarget ; return $ this ; }
Set copyTarget .
42,697
public function addFilter ( string $ expression ) : CopyDictionaryJob { if ( $ expression [ 0 ] !== substr ( $ expression , - 1 ) ) { $ expression = '/' . $ expression . '/' ; } try { preg_match ( $ expression , '' ) ; } catch ( \ Throwable $ error ) { throw new \ InvalidArgumentException ( sprintf ( 'Filter "%s" is not a valid regular expression - Error: %s' , $ expression , $ error -> getMessage ( ) ) , 0 , $ error ) ; } $ this -> filters [ ] = $ expression ; return $ this ; }
Add a regular expression .
42,698
public function setFilters ( array $ expressions ) : CopyDictionaryJob { $ this -> filters = [ ] ; foreach ( $ expressions as $ expression ) { $ this -> addFilter ( $ expression ) ; } return $ this ; }
Set the filter expressions .
42,699
private function copyKey ( string $ key ) : void { $ source = $ this -> sourceDictionary -> get ( $ key ) ; if ( $ source -> isSourceEmpty ( ) ) { $ this -> logger -> debug ( '{key}: Is empty in source language and therefore skipped.' , [ 'key' => $ key ] ) ; return ; } if ( ! $ this -> targetDictionary -> has ( $ key ) ) { $ this -> logger -> log ( $ this -> logLevel , 'Adding key {key}.' , [ 'key' => $ key ] ) ; if ( $ this -> dryRun ) { return ; } $ this -> targetDictionary -> add ( $ key ) ; } $ target = $ this -> targetDictionary -> getWritable ( $ key ) ; $ this -> copySource ( $ source , $ target ) ; $ this -> copyTarget ( $ source , $ target ) ; }
Copy a key .