idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
35,300 | public function getSavedSearchesDestroy ( $ id , array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( "saved_searches/destroy/{$id}" , $ parameters , $ multipart , $ appOnlyAuth ) ; } | Destroys a saved search for the authenticating user . The authenticating user must be the owner of saved search id being destroyed . |
35,301 | private function getItemId ( $ args ) { $ entity = $ args -> getEntity ( ) ; if ( $ entity instanceof Item ) { return $ entity -> getId ( ) ; } return null ; } | Returns the id of an Item |
35,302 | public function index ( $ form = null ) { $ areaProviders = $ this -> twoFactorProvidersService -> getAreaProvidersCollection ( ) ; if ( is_null ( $ form ) ) { $ provider = app ( Provider :: class ) -> where ( 'name' , 'google2fa' ) -> where ( 'area' , area ( ) ) -> first ( ) ; $ provider -> setProviderGateway ( $ this -> twoFactorProvidersService -> getProviderGatewayByName ( $ provider -> name ) ) ; $ form = $ this -> presenter -> form ( $ provider ) ; } return $ this -> presenter -> index ( $ areaProviders , $ form ) ; } | Return a View object based on Presenter . |
35,303 | public function edit ( ConfigurationListener $ listener , AreaContract $ area , Provider $ provider ) { $ provider -> area = $ area -> getId ( ) ; $ provider -> enabled = true ; $ provider -> setProviderGateway ( $ this -> twoFactorProvidersService -> getProviderGatewayByName ( $ provider -> name ) ) ; $ form = $ this -> presenter -> form ( $ provider ) ; Event :: fire ( "antares.form: two_factor_auth" , [ $ provider , $ form ] ) ; Event :: fire ( "antares.form: foundation.two_factor_auth" , [ $ provider , $ form , "foundation.two_factor_auth" ] ) ; return $ listener -> showProviderConfiguration ( $ form ) ; } | Show edit form for given area and provider . |
35,304 | public function update ( ConfigurationListener $ listener , array $ input ) { try { $ this -> providersRepository -> update ( $ input ) ; $ msg = trans ( 'antares/two_factor_auth::configuration.responses.update.success' ) ; return $ listener -> updateSuccess ( $ msg ) ; } catch ( Exception $ e ) { Log :: emergency ( $ e ) ; $ msg = trans ( 'antares/two_factor_auth::configuration.responses.update.fail' ) ; return $ listener -> updateFailed ( $ msg ) ; } } | Update a configuration . The provider will be marked as enabled . Response will be returned . |
35,305 | public function addAsRelationSource ( ForeignKey $ foreignKey ) { $ foreignKey -> isSource ( true ) ; $ this -> relationSources [ ] = $ foreignKey ; return $ this ; } | Adds a foreign key where this table is the source . |
35,306 | protected function addForeignKeys ( DOMXPath $ rootPath ) { $ fields = $ this -> getFields ( ) ; $ idMap = array_flip ( array_map ( function ( MigrationField $ field ) { return $ field -> getId ( ) ; } , $ fields ) ) ; foreach ( $ fields as $ name => $ field ) { $ usedId = $ field -> getId ( ) ; $ indexNodes = $ this -> getForeignKeysForField ( $ field , $ rootPath ) ; if ( $ indexNodes && $ indexNodes -> length ) { foreach ( $ indexNodes as $ indexNode ) { $ call = new ForeignKey ( ) ; $ call -> foreign ( $ field -> getName ( ) ) -> references ( 'id' ) -> on ( $ rootPath -> evaluate ( 'string(.//link[@type="object" and @struct-name="db.mysql.Table" ' . 'and @key="referencedTable"])' , $ indexNode ) ) ; if ( $ rule = $ rootPath -> evaluate ( 'string(./value[@key="deleteRule"])' , $ indexNode ) ) { $ call -> onDelete ( strtolower ( $ rule ) ) ; } if ( $ rule = $ rootPath -> evaluate ( 'string(./value[@key="updateRule"])' , $ indexNode ) ) { $ call -> onUpdate ( strtolower ( $ rule ) ) ; } $ call -> isForMany ( ( int ) $ rootPath -> evaluate ( 'number(./value[@key="many"])' , $ indexNode ) === 1 ) ; } $ this -> addGenericCall ( $ call ) ; } } return $ this ; } | Adds the foreign keys to the field . |
35,307 | protected function addIndicesToFields ( DOMXPath $ rootPath ) { $ fetchedNodes = [ ] ; $ fields = $ this -> getFields ( ) ; $ multipleIndices = [ ] ; $ idMap = array_flip ( array_map ( function ( MigrationField $ field ) { return $ field -> getId ( ) ; } , $ fields ) ) ; foreach ( $ fields as $ name => $ field ) { $ usedId = $ field -> getId ( ) ; $ indexNodes = $ rootPath -> query ( './value[@content-struct-name="db.mysql.Index" and @key="indices"]/' . 'value[@type="object" and @struct-name="db.mysql.Index"]//' . 'value[@type="object" and @struct-name="db.mysql.IndexColumn"]//' . 'link[@type="object" and @struct-name="db.Column" and @key="referencedColumn" ' . 'and text() = "' . $ usedId . '"]/' . '../' . '../' . '..' ) ; if ( $ indexNodes && $ indexNodes -> length ) { $ fks = $ this -> getForeignKeysForField ( $ field , $ rootPath ) ; foreach ( $ indexNodes as $ indexNode ) { if ( in_array ( $ nodeId = $ indexNode -> attributes -> getNamedItem ( 'id' ) -> nodeValue , $ fetchedNodes ) ) { continue ; } $ fetchedNodes [ ] = $ nodeId ; $ indexColumns = $ rootPath -> query ( './/link[@type="object" and @struct-name="db.Column" and @key="referencedColumn"]' , $ indexNode ) ; $ isSingleColumn = $ indexColumns && $ indexColumns -> length <= 1 ; $ genericCall = ! $ isSingleColumn ? new Base ( ) : null ; if ( $ rootPath -> evaluate ( 'boolean(./value[@type="int" and @key="unique" and number() = 1])' , $ indexNode ) ) { if ( $ isSingleColumn ) { $ field -> addAdditionalOption ( 'unique' ) ; } else { $ genericMethod = 'unique' ; } } $ hasIndex = $ rootPath -> evaluate ( 'boolean(./value[@type="string" and @key="indexType" and text() = "INDEX"])' , $ indexNode ) ; if ( $ hasIndex && ( ! $ fks || ! $ fks -> length ) ) { if ( $ isSingleColumn ) { $ field -> addAdditionalOption ( 'index' ) ; } else { $ genericMethod = 'index' ; } } if ( $ rootPath -> evaluate ( 'boolean(./value[@type="string" and @key="indexType" and text() = "PRIMARY"])' , $ indexNode ) ) { if ( $ isSingleColumn ) { $ field -> addAdditionalOption ( 'primary' ) ; } else { $ genericMethod = 'primary' ; } } if ( $ genericCall && $ genericMethod ) { $ genericParams = [ ] ; foreach ( $ indexColumns as $ column ) { $ genericParams [ ] = $ idMap [ $ column -> nodeValue ] ; } $ this -> addGenericCall ( call_user_func_array ( [ $ genericCall , $ genericMethod ] , $ genericParams ? [ $ genericParams ] : [ ] ) ) ; } } } } return array_unique ( $ multipleIndices ) ; } | Adds the simple indices to the fields directly and returns the indices for multiple values . |
35,308 | protected function createMigrationFile ( ) { $ fieldObjects = $ this -> getFields ( ) ; if ( @ $ fieldObjects [ 'id' ] ) { unset ( $ fieldObjects [ 'id' ] ) ; } if ( @ $ fieldObjects [ 'created_at' ] && @ $ fieldObjects [ 'updated_at' ] ) { $ this -> addGenericCall ( ( new Base ( ) ) -> timestamps ( ) ) ; unset ( $ fieldObjects [ 'created_at' ] , $ fieldObjects [ 'updated_at' ] ) ; } if ( @ $ fieldObjects [ 'deleted_at' ] ) { $ this -> addGenericCall ( ( new Base ( ) ) -> softDeletes ( ) ) ; unset ( $ fieldObjects [ 'deleted_at' ] ) ; } $ schema = implode ( ', ' , $ fieldObjects ) ; if ( strpos ( $ schema , 'enum' ) !== false ) { $ this -> getCommand ( ) -> info ( sprintf ( 'Please change the enum field of table "%s" manually.' , $ this -> getName ( ) ) ) ; } if ( $ this -> isPivotTable ( ) ) { $ tables = array_keys ( $ this -> getForeignKeys ( ) ) ; Artisan :: call ( 'make:migration:pivot' , [ 'tableOne' => $ tables [ 0 ] , 'tableTwo' => $ tables [ 1 ] ] ) ; } else { Artisan :: call ( 'make:migration:schema' , [ 'name' => "create_{$this->getName()}_table" , '--model' => $ this -> needsLaravelModel ( ) , '--schema' => $ fieldObjects ? $ schema : '' ] ) ; $ migrationFiles = glob ( database_path ( 'migrations' ) . DIRECTORY_SEPARATOR . "*_create_{$this->getName()}_table.php" ) ; } return @ $ migrationFiles ? end ( $ migrationFiles ) : '' ; } | Creates the migration file for the given table . |
35,309 | public function getForeignKeys ( ) { $ return = [ ] ; $ table = $ this -> getName ( ) ; foreach ( $ this -> getGenericCalls ( ) as $ call ) { if ( isset ( $ call -> on ) && $ call -> on !== $ table ) { $ return [ ( string ) $ call -> on ] = $ call ; } } return $ return ; } | Returns the relations for foreign keys . |
35,310 | public function getModelName ( ) { if ( ! $ name = $ this -> modelName ) { $ tableName = $ this -> getName ( ) ; $ modelNames = [ ] ; foreach ( explode ( '_' , $ tableName ) as $ word ) { $ modelNames [ ] = ucfirst ( Inflector :: singularize ( $ word ) ) ; } $ modelName = implode ( '' , $ modelNames ) ; $ this -> setModelName ( $ name = ucfirst ( $ this -> isReservedPHPWord ( $ modelName ) ? $ tableName : $ modelName ) ) ; } return $ name ; } | Returns the model name . |
35,311 | protected function isReservedPHPWord ( $ word ) { $ word = strtolower ( $ word ) ; $ keywords = [ '__halt_compiler' , 'abstract' , 'and' , 'array' , 'as' , 'break' , 'callable' , 'case' , 'catch' , 'class' , 'clone' , 'const' , 'continue' , 'declare' , 'default' , 'die' , 'do' , 'echo' , 'else' , 'elseif' , 'empty' , 'enddeclare' , 'endfor' , 'endforeach' , 'endif' , 'endswitch' , 'endwhile' , 'eval' , 'exit' , 'extends' , 'final' , 'for' , 'foreach' , 'function' , 'global' , 'goto' , 'if' , 'implements' , 'include' , 'include_once' , 'instanceof' , 'insteadof' , 'interface' , 'isset' , 'list' , 'namespace' , 'new' , 'or' , 'print' , 'private' , 'protected' , 'public' , 'require' , 'require_once' , 'return' , 'static' , 'switch' , 'throw' , 'trait' , 'try' , 'unset' , 'use' , 'var' , 'while' , 'xor' ] ; $ predefined_constants = [ '__CLASS__' , '__DIR__' , '__FILE__' , '__FUNCTION__' , '__LINE__' , '__METHOD__' , '__NAMESPACE__' , '__TRAIT__' ] ; return in_array ( $ word , $ keywords ) || in_array ( $ word , $ predefined_constants ) ; } | Returns true if the given word is a php keyword . |
35,312 | public function load ( DOMNode $ node ) { $ return = true ; $ dom = new \ DOMDocument ( '1.0' ) ; $ dom -> importNode ( $ node , true ) ; $ dom -> appendChild ( $ node ) ; $ path = new \ DOMXPath ( $ dom ) ; $ this -> setName ( $ tableName = $ path -> evaluate ( 'string((./value[@key="name"])[1])' ) ) ; $ comment = $ path -> evaluate ( 'string((./value[@key="comment"])[1])' ) ; if ( $ comment ) { $ return = $ this -> loadAnnotations ( $ comment ) ; } if ( $ return ) { $ this -> setId ( $ tableId = $ node -> attributes -> getNamedItem ( 'id' ) -> nodeValue ) ; if ( ! $ tableId || ! $ tableName ) { throw new \ LogicException ( 'Table name or id could not be fond.' ) ; } $ return = $ this -> loadMigrationFields ( $ path ) ; } return $ return ; } | Load this table with its dom node . |
35,313 | public function loadAnnotations ( $ annotations ) { $ moreSettings = parse_ini_string ( $ annotations , true ) ? : [ ] ; if ( @ $ guardedFields = $ moreSettings [ 'blacklist' ] ) { $ this -> setBlacklist ( explode ( ',' , $ guardedFields ) ) ; } if ( @ $ moreSettings [ 'casting' ] && is_array ( $ moreSettings [ 'casting' ] ) ) { $ this -> setCastedFields ( $ moreSettings [ 'casting' ] ) ; } if ( @ $ modelName = $ moreSettings [ 'model' ] ) { $ this -> setModelName ( $ modelName ) ; } $ this -> isPivotTable ( @ ( bool ) $ moreSettings [ 'isPivot' ] ) ; $ this -> withoutTimestamps ( @ ( bool ) $ moreSettings [ 'withoutTimestamps' ] ) ; return ! @ $ moreSettings [ 'ignore' ] ; } | Loads the annotations for this table . |
35,314 | protected function loadMigrationFields ( DOMXPath $ rootPath ) { $ fields = $ rootPath -> query ( './value[@type="list" and @key="columns"]/value[@type="object" and @struct-name="db.mysql.Column"]' ) ; if ( $ fields && $ fields -> length ) { foreach ( $ fields as $ field ) { $ fieldName = $ rootPath -> query ( './value[@key="name"]' , $ field ) -> item ( 0 ) -> nodeValue ; $ this -> addField ( $ fieldName ) -> load ( $ field , $ rootPath ) ; } } $ this -> addIndicesToFields ( $ rootPath ) ; return $ this -> addForeignKeys ( $ rootPath ) ; } | Returns the migration fields of the model . |
35,315 | public function relateToOtherTables ( array $ otherTables ) { if ( $ calls = $ this -> getGenericCalls ( ) ) { $ tablesByModelName = [ ] ; foreach ( $ otherTables as $ tableObject ) { $ tablesByModelName [ $ tableObject -> getModelName ( ) ] = $ tableObject ; } foreach ( $ calls as $ call ) { if ( $ on = $ call -> on ) { $ otherTable = @ $ otherTables [ $ on ] ; $ call -> on = $ otherTable -> getName ( ) ; $ otherCall = clone $ call ; if ( $ this -> isPivotTable ( ) ) { $ modelNames = array_map ( 'ucfirst' , explode ( '_' , $ tableName = $ this -> getName ( ) ) ) ; $ matchedModelTables = array_intersect_key ( $ tablesByModelName , array_flip ( $ modelNames ) ) ; unset ( $ matchedModelTables [ $ otherTable -> getModelName ( ) ] ) ; $ otherCall -> isForMany ( true ) ; $ otherCall -> isForPivotTable ( true ) ; $ call -> on = current ( $ matchedModelTables ) -> getName ( ) ; $ otherTable -> addGenericCall ( $ otherCall -> setRelatedTable ( current ( $ matchedModelTables ) ) ) ; } else { $ call -> setRelatedTable ( $ otherTable ) ; $ otherTable -> addAsRelationSource ( $ otherCall -> setRelatedTable ( $ this ) ) ; } } } } return $ this ; } | Relates this table to others . |
35,316 | public function save ( ) { $ file = $ this -> createMigrationFile ( ) ; if ( ! $ written = ! $ file ) { $ written = $ this -> addCallsToMigrationFile ( $ file ) ; } if ( $ this -> needsLaravelModel ( ) ) { $ this -> saveModelForTable ( ) ; } return $ written ; } | Saves the table in the given migration file . |
35,317 | protected function saveModelForTable ( ) { $ table = $ this ; $ dates = [ ] ; $ fields = $ table -> getFields ( ) ; $ modelContent = ( new ModelContent ( $ table -> getModelName ( ) ) ) -> setTable ( $ table -> getName ( ) ) ; if ( array_key_exists ( $ field = 'deleted_at' , $ fields ) ) { unset ( $ fields [ $ field ] ) ; $ dates [ ] = $ field ; $ modelContent -> setTraits ( [ '\Illuminate\Database\Eloquent\SoftDeletes' ] ) ; } if ( array_key_exists ( $ field = 'created_at' , $ fields ) ) { unset ( $ fields [ $ field ] ) ; $ dates [ ] = $ field ; } if ( array_key_exists ( $ field = 'updated_at' , $ fields ) ) { unset ( $ fields [ $ field ] ) ; $ dates [ ] = $ field ; } if ( $ dates ) { $ modelContent -> setDates ( $ dates ) ; } unset ( $ fields [ 'id' ] ) ; $ modelContent -> setFillable ( array_diff ( array_keys ( $ fields ) , $ table -> getBlacklist ( ) ) ) ; $ modelContent -> setCasts ( $ table -> getCastedFields ( ) ) ; if ( $ genericCalls = $ table -> getGenericCalls ( ) ) { foreach ( $ genericCalls as $ call ) { if ( $ call instanceof ForeignKey ) { $ modelContent -> addForeignKey ( $ call ) ; } } } if ( $ sources = $ table -> getRelationSources ( ) ) { foreach ( $ sources as $ call ) { if ( $ call instanceof ForeignKey ) { $ modelContent -> addForeignKey ( $ call ) ; } } } $ modelContent -> save ( ) ; return $ this ; } | Saves the model content for a table . |
35,318 | public function withoutTimestamps ( $ newStatus = false ) { $ oldStatus = $ this -> withoutTimestamps ; if ( func_num_args ( ) ) { $ this -> withoutTimestamps = $ newStatus ; } return $ oldStatus ; } | Should this table be rendered without the timestamps? |
35,319 | public function save ( string $ role , ... $ options ) { $ resource = $ options [ 0 ] ; $ permission = $ options [ 1 ] ; $ status = ( isset ( $ options [ 2 ] ) ) ? $ options [ 2 ] : true ; $ this -> registry [ $ role ] [ $ resource ] [ $ permission ] [ "status" ] = $ status ; } | Overrides the global save method |
35,320 | public function bind ( AbstractAdmin $ admin , Request $ request ) { if ( $ this -> request ) { throw new \ RuntimeException ( 'A datagrid can only be bound once to a request' ) ; } $ resolver = new OptionsResolver ( ) ; $ this -> configureOptions ( $ resolver ) ; $ this -> options = $ resolver -> resolve ( $ admin -> getDatagridOptions ( ) ) ; $ this -> admin = $ admin ; $ this -> request = $ request ; $ this -> admin -> buildDatagrid ( $ this ) ; $ this -> applyFilters ( ) ; } | Bind the Request to the Datagrid |
35,321 | private function applyFilters ( ) { $ form = $ this -> getFiltersForm ( ) ; if ( ! $ form ) { return ; } $ this -> loadFilterValues ( ) ; $ form -> setData ( $ this -> filterValues ) ; $ form -> handleRequest ( $ this -> request ) ; if ( $ form -> isSubmitted ( ) ) { if ( $ form -> get ( 'reset' ) -> isClicked ( ) ) { $ this -> clearFilterValues ( ) ; $ this -> getFiltersForm ( true ) ; } else { $ this -> storeFilterValues ( $ form -> getData ( ) ) ; } } if ( is_array ( $ this -> filterValues ) ) { foreach ( $ this -> filters as $ filter ) { if ( array_key_exists ( $ filter -> getName ( ) , $ this -> filterValues ) ) { $ filter -> setValue ( $ this -> filterValues [ $ filter -> getName ( ) ] ) ; } } } } | Prepare filters form bind filter values to filters |
35,322 | public function getFiltersForm ( $ reset = false ) { if ( ! $ this -> filtersForm || $ reset ) { if ( empty ( $ this -> filters ) ) { return null ; } $ form = $ this -> factory -> createNamedBuilder ( 'filter' , FormType :: class , null , [ 'csrf_protection' => false , 'method' => 'GET' , ] ) ; foreach ( $ this -> filters as $ filter ) { $ filter -> buildForm ( $ form ) ; } $ form -> add ( 'submit' , SubmitType :: class , [ 'label' => 'Filter' , 'attr' => [ 'class' => 'btn-success' , ] ] ) ; $ form -> add ( 'reset' , SubmitType :: class , [ 'label' => 'Reset' ] ) ; $ this -> filtersForm = $ form -> getForm ( ) ; } return $ this -> filtersForm ; } | Get the form used to filter the list of entities displayed in the datagrid |
35,323 | public function getQueryBuilder ( ) { $ queryBuilder = $ this -> entityManager -> createQueryBuilder ( ) ; $ queryBuilder -> select ( 'e' ) -> from ( $ this -> admin -> getEntityClass ( ) , 'e' ) -> orderBy ( 'e.id' , 'DESC' ) ; $ expr = $ queryBuilder -> expr ( ) -> andX ( ) ; $ i = 0 ; foreach ( $ this -> filters as $ filter ) { $ filterExprName = $ filter -> getExpression ( ) ; if ( $ filterExprName && ! is_null ( $ filter -> getValue ( ) ) ) { $ filterExpr = $ queryBuilder -> expr ( ) -> { $ filterExprName } ( 'e.' . $ filter -> getName ( ) , ':param_' . $ i ) ; $ queryBuilder -> setParameter ( 'param_' . $ i , $ filter -> getValue ( ) ) ; $ expr -> add ( $ filterExpr ) ; $ i ++ ; } } if ( $ expr -> count ( ) > 0 ) { $ queryBuilder -> where ( $ expr ) ; } return $ queryBuilder ; } | Get QueryBuilder to populate Datagrid |
35,324 | private function storeFilterValues ( array $ data ) { $ this -> filterValues = $ data ; $ session = new Session ( ) ; foreach ( $ this -> filters as $ datagridFilter ) { if ( $ datagridFilter -> getType ( ) instanceof DatagridFilterTypeEntity ) { if ( ! empty ( $ this -> filterValues [ $ datagridFilter -> getName ( ) ] ) ) { $ this -> filterValues [ $ datagridFilter -> getName ( ) ] = $ this -> filterValues [ $ datagridFilter -> getName ( ) ] -> getId ( ) ; } } } $ session -> set ( $ this -> getStorageNamespace ( ) , $ this -> filterValues ) ; } | Store values for filters so user can change page and keep his filters Values are stored per admin |
35,325 | private function loadFilterValues ( ) { $ session = new Session ( ) ; $ this -> filterValues = $ session -> get ( $ this -> getStorageNamespace ( ) ) ; foreach ( $ this -> filters as $ datagridFilter ) { if ( $ datagridFilter -> getType ( ) instanceof DatagridFilterTypeEntity ) { if ( ! empty ( $ this -> filterValues [ $ datagridFilter -> getName ( ) ] ) ) { $ filterOptions = $ datagridFilter -> getOptions ( ) ; $ this -> filterValues [ $ datagridFilter -> getName ( ) ] = $ this -> entityManager -> getReference ( $ filterOptions [ 'class' ] , $ this -> filterValues [ $ datagridFilter -> getName ( ) ] ) ; } } } } | Retrieve values previously stored for filters Values are stored per admin |
35,326 | public function updateCartPrices ( $ items ) { $ hasChanged = $ this -> priceCalculation -> setPricesOfChanged ( $ items ) ; if ( $ hasChanged ) { $ this -> em -> flush ( ) ; } return $ hasChanged ; } | Updates changed prices |
35,327 | public function updateCart ( $ data , $ user , $ locale ) { $ cart = $ this -> getUserCart ( $ user , $ locale ) ; $ userId = $ user ? $ user -> getId ( ) : null ; $ this -> orderManager -> save ( $ data , $ locale , $ userId , $ cart -> getId ( ) , null , null , true ) ; $ this -> removeItemAddressesThatAreEqualToOrderAddress ( $ cart ) ; return $ cart ; } | Updates the cart |
35,328 | public function submit ( UserInterface $ user , $ locale , & $ orderWasSubmitted = true , & $ originalCart = null ) { $ orderWasSubmitted = true ; $ cart = $ this -> getUserCart ( $ user , $ locale , null , false , true ) ; $ originalCart = $ cart ; if ( count ( $ cart -> getCartErrorCodes ( ) ) > 0 ) { $ orderWasSubmitted = false ; return $ cart ; } $ orderWasSubmitted = $ this -> submitCartDirectly ( $ cart , $ user , $ locale ) ; return $ this -> getUserCart ( $ user , $ locale ) ; } | Submits a cart . |
35,329 | protected function checkIfCartIsValid ( UserInterface $ user , ApiOrderInterface $ cart , $ locale ) { if ( count ( $ cart -> getItems ( ) ) < 1 ) { throw new OrderException ( 'Empty Cart' ) ; } } | Checks if cart is valid |
35,330 | private function reApplyOrderAddresses ( $ cart , $ user ) { $ this -> validateOrCreateAddresses ( $ cart , $ user ) ; if ( $ cart -> getInvoiceAddress ( ) -> getContactAddress ( ) ) { $ this -> orderAddressManager -> getAndSetOrderAddressByContactAddress ( $ cart -> getInvoiceAddress ( ) -> getContactAddress ( ) , null , null , $ cart -> getInvoiceAddress ( ) ) ; } if ( $ cart -> getDeliveryAddress ( ) -> getContactAddress ( ) ) { $ this -> orderAddressManager -> getAndSetOrderAddressByContactAddress ( $ cart -> getDeliveryAddress ( ) -> getContactAddress ( ) , null , null , $ cart -> getDeliveryAddress ( ) ) ; } foreach ( $ cart -> getItems ( ) as $ item ) { if ( $ item -> getDeliveryAddress ( ) && $ item -> getDeliveryAddress ( ) -> getContactAddress ( ) ) { $ this -> orderAddressManager -> getAndSetOrderAddressByContactAddress ( $ item -> getDeliveryAddress ( ) -> getContactAddress ( ) , null , null , $ item -> getDeliveryAddress ( ) ) ; } } } | Reapplies order - addresses on submit |
35,331 | protected function validateOrCreateAddresses ( $ cart ) { if ( $ cart instanceof ApiOrderInterface ) { $ cart = $ cart -> getEntity ( ) ; } if ( ! $ cart -> getDeliveryAddress ( ) || ! $ cart -> getInvoiceAddress ( ) ) { $ addresses = $ cart -> getCustomerAccount ( ) -> getAccountAddresses ( ) ; if ( $ addresses -> isEmpty ( ) ) { throw new Exception ( 'customer has no addresses' ) ; } $ mainAddress = $ cart -> getCustomerAccount ( ) -> getMainAddress ( ) ; if ( ! $ mainAddress ) { throw new Exception ( 'customer has no main-address' ) ; } if ( ! $ cart -> getDeliveryAddress ( ) ) { $ newAddress = $ this -> orderAddressManager -> getAndSetOrderAddressByContactAddress ( $ mainAddress , $ cart -> getCustomerContact ( ) , $ cart -> getCustomerAccount ( ) ) ; $ cart -> setDeliveryAddress ( $ newAddress ) ; $ this -> em -> persist ( $ newAddress ) ; } if ( ! $ cart -> getInvoiceAddress ( ) ) { $ newAddress = $ this -> orderAddressManager -> getAndSetOrderAddressByContactAddress ( $ mainAddress , $ cart -> getCustomerContact ( ) , $ cart -> getCustomerAccount ( ) ) ; $ cart -> setInvoiceAddress ( $ newAddress ) ; $ this -> em -> persist ( $ newAddress ) ; } } } | Checks if addresses have been set and sets new ones |
35,332 | private function findCartBySessionId ( ) { $ sessionId = $ this -> session -> getId ( ) ; $ cartsArray = $ this -> orderRepository -> findBy ( array ( 'sessionId' => $ sessionId , 'status' => OrderStatus :: STATUS_IN_CART ) , array ( 'created' => 'DESC' ) ) ; return $ cartsArray ; } | Finds cart by session - id |
35,333 | private function findCartsByUser ( $ user , $ locale ) { $ cartsArray = $ this -> orderRepository -> findByStatusIdsAndUser ( $ locale , array ( OrderStatus :: STATUS_IN_CART , OrderStatus :: STATUS_CART_PENDING ) , $ user ) ; return $ cartsArray ; } | Finds cart by locale and user |
35,334 | private function cleanupCartsArray ( & $ cartsArray ) { if ( $ cartsArray && count ( $ cartsArray ) > 0 ) { foreach ( $ cartsArray as $ index => $ cart ) { if ( $ cart -> getChanged ( ) -> getTimestamp ( ) < strtotime ( static :: EXPIRY_MONTHS . ' months ago' ) ) { continue ; } if ( $ index === 0 ) { continue ; } } } } | removes all elements from database but the first |
35,335 | public function removeItem ( $ itemId , $ user = null , $ locale = null ) { $ cart = $ this -> getUserCart ( $ user , $ locale ) ; $ item = $ this -> orderManager -> getOrderItemById ( $ itemId , $ cart -> getEntity ( ) , $ hasMultiple ) ; $ this -> orderManager -> removeItem ( $ item , $ cart -> getEntity ( ) , ! $ hasMultiple ) ; $ this -> orderManager -> updateApiEntity ( $ cart , $ locale ) ; return $ cart ; } | Removes an item from cart |
35,336 | protected function removeItemAddressesThatAreEqualToOrderAddress ( $ order ) { $ deliveryAddressId = $ order -> getDeliveryAddress ( ) -> getContactAddress ( ) -> getId ( ) ; foreach ( $ order -> getItems ( ) as $ item ) { $ itemEntity = $ item -> getEntity ( ) ; $ this -> removeOrderAddressIfContactAddressIdIsEqualTo ( $ itemEntity , $ deliveryAddressId ) ; } } | Remove all item delivery - addresses that are the same as the default delivery address of the order |
35,337 | protected function removeOrderAddressIfContactAddressIdIsEqualTo ( $ item , $ contactAddressId ) { $ deliveryAddress = $ item -> getDeliveryAddress ( ) ; if ( $ deliveryAddress && $ deliveryAddress -> getContactAddress ( ) && $ deliveryAddress -> getContactAddress ( ) -> getID ( ) === $ contactAddressId ) { $ item -> setDeliveryAddress ( null ) ; $ this -> em -> remove ( $ deliveryAddress ) ; } } | Remove deliveryAddress if it has a relation to a certain contact - address - id |
35,338 | private function scriptSrc ( $ onload = null , $ render = null , $ hl = null ) { $ queryString = http_build_query ( compact ( 'onload' , 'render' , 'hl' ) ) ; return self :: SCRIPT_URL . ( $ queryString ? '?' . $ queryString : '' ) ; } | Generates the script source based on the options . |
35,339 | private function verificationUrl ( $ response , $ remoteIp = null ) { $ secret = $ this -> secret ; return self :: VERIFICATION_URL . '?' . http_build_query ( compact ( 'secret' , 'response' , 'remoteIp' ) ) ; } | Generates the url to verify the CAPTCHA response . |
35,340 | public function script ( $ onload = null , $ render = null , $ hl = null , array $ attributes = array ( ) ) { array_push ( $ attributes , 'async' , 'defer' ) ; return HtmlBuilder :: script ( $ this -> scriptSrc ( $ onload , $ render , $ hl ) , null , $ attributes ) ; } | Generates a script tag based on the options . |
35,341 | public function widget ( $ theme = null , $ type = null , $ callback = null , array $ attributes = array ( ) ) { $ attributes [ 'class' ] = implode ( ' ' , array_merge ( ( array ) ( isset ( $ attributes [ 'class' ] ) ? $ attributes [ 'class' ] : null ) , [ 'g-recaptcha' ] ) ) ; $ attributes [ 'data-sitekey' ] = $ this -> siteKey ; $ attributes [ 'data-theme' ] = $ theme ; $ attributes [ 'data-type' ] = $ type ; $ attributes [ 'data-callback' ] = $ callback ; return '<div' . HtmlBuilder :: attributes ( $ attributes ) . '></div>' ; } | Generates a div tag for the widget based on the options . |
35,342 | public function verify ( $ response , $ remoteIp = null ) { $ this -> errors = [ ] ; try { $ response = ( new Client ( ) ) -> get ( $ this -> verificationUrl ( $ response , $ remoteIp ) ) -> send ( ) ; } catch ( GuzzleException $ e ) { $ this -> errors [ ] = 'transfer-error' ; return false ; } if ( $ response -> getStatusCode ( ) !== 200 ) { $ this -> errors [ ] = 'api-error' ; return false ; } try { $ responseBody = $ response -> json ( ) ; } catch ( GuzzleException $ e ) { $ this -> errors [ ] = 'response-error' ; return false ; } if ( isset ( $ responseBody [ 'error-codes' ] ) ) { $ this -> errors = $ responseBody [ 'error-codes' ] ; } return $ responseBody [ 'success' ] ; } | Queries the Google API to determine if the CAPTCHA is valid . |
35,343 | public static function copy ( $ start_path , $ copy_path , $ dir_mode = 0777 ) { $ return = mkdir ( $ copy_path , $ dir_mode , true ) ; $ files = self :: getContent ( $ start_path ) ; foreach ( $ files as $ file ) { if ( is_dir ( $ start_path . DIRECTORY_SEPARATOR . $ file ) ) { $ return = self :: copy ( rtrim ( $ start_path , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ file , $ copy_path . DIRECTORY_SEPARATOR . $ file , $ dir_mode ) ; } else { $ return = copy ( rtrim ( $ start_path , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ file , $ copy_path . DIRECTORY_SEPARATOR . $ file ) ; } } return $ return ; } | Recursive path copy for php . |
35,344 | public static function delete ( $ path ) { $ files = self :: getContent ( $ path ) ; foreach ( $ files as $ file ) { if ( is_dir ( $ path . DIRECTORY_SEPARATOR . $ file ) ) { self :: delete ( $ path . DIRECTORY_SEPARATOR . $ file ) ; } else { @ unlink ( $ path . DIRECTORY_SEPARATOR . $ file ) ; } } return @ rmdir ( $ path ) ; } | rm - rf commande like . |
35,345 | public static function getContent ( $ path ) { if ( is_dir ( $ path ) ) { $ files = array_diff ( scandir ( $ path ) , array ( '.' , '..' ) ) ; return $ files ; } else { throw new \ Exception ( sprintf ( 'Incorrect path "%s" name in %s at line %s' , $ path , __FILE__ , __LINE__ ) ) ; } } | Parse dir content . |
35,346 | protected function setDate ( $ data , $ key , DateTIme $ currentDate , callable $ setCallback ) { $ date = $ this -> getProperty ( $ data , $ key , $ currentDate ) ; if ( $ date !== null ) { if ( is_string ( $ date ) ) { $ date = new DateTime ( $ data [ $ key ] ) ; } call_user_func ( $ setCallback , $ date ) ; } } | Sets a date if it s set in data . |
35,347 | public function postTriggerAction ( $ id , Request $ request ) { $ status = $ request -> get ( 'action' ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; try { $ order = $ this -> getManager ( ) -> findByIdAndLocale ( $ id , $ this -> getLocaleManager ( ) -> retrieveLocale ( $ this -> getUser ( ) , $ request -> get ( 'locale' ) ) ) ; if ( ! $ order ) { throw new OrderNotFoundException ( $ id ) ; } switch ( $ status ) { case 'confirm' : $ this -> getManager ( ) -> convertStatus ( $ order , OrderStatus :: STATUS_CONFIRMED ) ; break ; case 'edit' : $ this -> getManager ( ) -> convertStatus ( $ order , OrderStatus :: STATUS_CREATED ) ; break ; default : throw new RestException ( "Unrecognized status: " . $ status ) ; } $ em -> flush ( ) ; $ view = $ this -> view ( $ order , 200 ) ; } catch ( OrderNotFoundException $ exc ) { $ exception = new EntityNotFoundException ( $ exc -> getEntityName ( ) , $ exc -> getId ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 404 ) ; } return $ this -> handleView ( $ view ) ; } | Triggers actions like status conversion . |
35,348 | public function deleteAction ( $ id ) { $ delete = function ( $ id ) { $ this -> getManager ( ) -> delete ( $ id ) ; } ; $ view = $ this -> responseDelete ( $ id , $ delete ) ; return $ this -> handleView ( $ view ) ; } | Delete an order with the given id . |
35,349 | public function enterAttribute ( AttributePath $ path ) : void { if ( $ this -> done ) { return ; } $ name = $ path -> getName ( ) ; $ value = $ this -> getValue ( $ path , $ this -> attributes ) ; $ pattern = $ path -> getTypePattern ( ) ; $ this -> validateValue ( $ name , $ value , $ pattern ) ; $ this -> uri .= $ value ; } | Adds the attribute value to the URI . |
35,350 | public function enterOptional ( OptionalPath $ path ) : void { if ( ! $ this -> optionalAttributesProvided ( $ path ) ) { $ this -> done = true ; } } | Determines if the optional path should be present in the URI . |
35,351 | public function enterStatic ( StaticPath $ path ) : void { if ( $ this -> done ) { return ; } $ this -> uri .= $ path -> getStatic ( ) ; } | Adds the static part of the path to the URI . |
35,352 | private function validateValue ( string $ name , string $ value , string $ pattern ) : void { if ( ! preg_match ( "#^$pattern$#" , $ value ) ) { throw InvalidAttribute :: badFormat ( $ name , $ value , $ pattern ) ; } } | Checks whether the value matches the regular expression . |
35,353 | private function optionalAttributesProvided ( RoutePath $ path ) : bool { $ pathAttributes = array_map ( function ( Attribute $ attribute ) { return $ attribute -> getName ( ) ; } , $ path -> getAttributes ( ) ) ; $ specifiedAttributes = array_keys ( $ this -> attributes ) ; $ unfilledAttributes = array_intersect ( $ pathAttributes , $ specifiedAttributes ) ; return ! empty ( $ unfilledAttributes ) ; } | Determines if there were any optional attributes provided by the user . |
35,354 | public function trigger ( Payload $ payload ) { $ enabled = ( boolean ) ( TRUE === isset ( $ this -> settings [ self :: OPTION_ENABLED ] ) ? $ this -> settings [ self :: OPTION_ENABLED ] : TRUE ) ; $ matchesBranch = TRUE === isset ( $ this -> settings [ self :: OPTION_BRANCH ] ) ? 'refs/heads/' . $ this -> settings [ self :: OPTION_BRANCH ] === $ payload -> getRef ( ) : TRUE ; return $ enabled && $ matchesBranch ; } | This plugin will always trigger |
35,355 | public function process ( Payload $ payload ) { $ output = array ( ) ; $ command = $ this -> getCommand ( ) ; $ this -> invokeShellCommand ( $ command , $ output ) ; $ payload -> getResponse ( ) -> addOutputFromPlugin ( $ this , $ output ) ; } | Switch to repository root pull and do composer update . |
35,356 | static function catchErrorsOn ( $ wrappedCode , $ errorHandler = null , $ reset = true ) { if ( PHP_MAJOR_VERSION >= 7 ) { try { return $ wrappedCode ( ) ; } catch ( Throwable $ e ) { if ( isset ( $ errorHandler ) ) return $ errorHandler ( $ e ) ; throw $ e ; } } $ prevHandler = set_error_handler ( function ( $ errno , $ errstr , $ errfile , $ errline ) { if ( ! error_reporting ( ) ) return false ; throw new ErrorException ( $ errstr , $ errno , 0 , $ errfile , $ errline ) ; } ) ; try { $ r = $ wrappedCode ( ) ; set_error_handler ( $ prevHandler ) ; return $ r ; } catch ( Exception $ e ) { set_error_handler ( function ( ) { return false ; } ) ; if ( $ reset ) trigger_error ( "" ) ; set_error_handler ( $ prevHandler ) ; if ( isset ( $ errorHandler ) ) return $ errorHandler ( $ e ) ; throw $ e ; } } | Run the provided code intercepting PHP errors . |
35,357 | static function dump ( $ value , $ indent = 0 ) { return ltrim ( str_indent ( preg_replace ( '/^array \((.*)\)/ms' , '[$1]' , var_export ( $ value , true ) ) , $ indent ) ) ; } | Serializes a value to PHP source code . |
35,358 | static function evalConstant ( $ exp , & $ valid = null ) { $ exp = trim ( $ exp ) ; if ( $ exp !== '' ) { $ valid = true ; if ( $ exp [ 0 ] == '"' || $ exp [ 0 ] == "'" ) return substr ( $ exp , 1 , - 1 ) ; if ( is_numeric ( $ exp ) ) { return ctype_digit ( $ exp ) ? intval ( $ exp ) : floatVal ( $ exp ) ; } if ( defined ( $ exp ) ) return constant ( $ exp ) ; } $ valid = false ; return null ; } | Tries to evaluate a constant value expressed as a string . |
35,359 | static function highlight ( $ code ) { $ o = highlight_string ( "<?php;$code ?>" , true ) ; $ o = str_extract ( $ o , '%php</span>.*?</span>(.*)<span[^>]*>\?>%s' ) ; return $ o !== '' ? $ o : $ code ; } | Highlights syntax on a string of PHP source code . |
35,360 | static function run ( $ _code ) { if ( ctype_space ( $ _code [ 0 ] ) ) $ _code = ltrim ( $ _code ) ; if ( substr ( $ _code , 0 , 5 ) == '<?php' ) return eval ( substr ( $ _code , 5 ) ) ; return eval ( $ _code ) ; } | Runs PHP code . It supports code either beginning with <?php or not but if <?php is present it must be the first thing on the code string excluding white space . |
35,361 | static function validate ( $ code , & $ output = 0 ) { $ b = 0 ; foreach ( token_get_all ( $ code ) as $ token ) if ( '{' == $ token ) ++ $ b ; elseif ( '}' == $ token ) -- $ b ; if ( $ b ) return false ; ob_start ( ) ; $ code = eval ( 'if(0){' . $ code . '}' ) ; if ( func_num_args ( ) > 1 ) $ output = ob_get_clean ( ) ; else ob_end_clean ( ) ; return false !== $ code ; } | Checks if the given PHP source code is syntactically valid . |
35,362 | public function getStatus ( ) { if ( $ this -> entity && $ this -> entity -> getStatus ( ) ) { return new ApiOrderStatus ( $ this -> entity -> getStatus ( ) , $ this -> locale ) ; } else { return null ; } } | Get order status |
35,363 | public function getItem ( $ id ) { foreach ( $ this -> entity -> getItems ( ) as $ item ) { if ( $ item -> getId ( ) === $ id ) { return $ item ; } } return null ; } | Get item entity by id |
35,364 | public function paginate ( Query $ query , $ page = 1 , $ limit = 10 , $ fetchJoinCollection = false ) : array { $ paginator = new Paginator ( $ query , $ fetchJoinCollection ) ; $ totalItems = $ paginator -> count ( ) ; $ pagesCount = ceil ( $ totalItems / $ limit ) ; $ paginator -> getQuery ( ) -> setFirstResult ( $ limit * ( $ page - 1 ) ) -> setMaxResults ( $ limit ) ; return [ 'meta' => [ 'page' => $ page , 'total' => $ totalItems , 'pages' => $ pagesCount , 'limit' => $ limit , ] , 'data' => $ paginator ] ; } | Paginates a query |
35,365 | protected function deriveReceivedClass ( callable $ transformer ) { if ( is_array ( $ transformer ) ) { $ r = new \ ReflectionMethod ( $ transformer [ 0 ] , $ transformer [ 1 ] ) ; } elseif ( is_object ( $ transformer ) && ! $ transformer instanceof \ Closure ) { $ r = new \ ReflectionObject ( $ transformer ) ; $ r = $ r -> getMethod ( '__invoke' ) ; } else { $ r = new \ ReflectionFunction ( $ transformer ) ; } $ parameters = $ r -> getParameters ( ) ; if ( count ( $ parameters ) != 1 ) { throw new InvalidTransformerException ( 'A transformer must have one parameter and it must be typed to the input class type.' ) ; } $ class = $ parameters [ 0 ] -> getClass ( ) ; if ( ! $ class ) { throw new InvalidTransformerException ( ) ; } return $ class -> name ; } | Derives the receivable class type for the provided transformer . |
35,366 | protected function isNamespaceValid ( $ namespace ) { if ( $ namespace === '\\' ) { return true ; } if ( strpos ( $ namespace , '\\' ) === 0 ) { $ namespace = substr ( $ namespace , 1 ) ; } $ parts = explode ( '\\' , $ namespace ) ; foreach ( $ parts as $ part ) { $ match = preg_match ( self :: PATTERN_VALIDATE_NAMESPACE_NAME , $ part ) ; if ( $ match === false || $ match <= 0 || ReservedKeywords :: isReservedKeyword ( $ part ) !== false ) { return false ; } } return true ; } | Check if a namespace is valid . |
35,367 | protected function serializeFields ( array $ row ) { $ data = array ( ) ; $ columns = $ this -> getColumns ( ) ; $ builder = $ this -> newQueryBuilder ( $ this -> getName ( ) ) ; $ parts = $ builder -> getQueryPart ( 'from' ) ; $ part = reset ( $ parts ) ; $ alias = $ part [ 'alias' ] ; foreach ( $ columns as $ name => $ type ) { if ( ! empty ( $ alias ) ) { $ pos = strpos ( $ name , $ alias . '.' ) ; if ( $ pos !== false ) { $ name = substr ( $ name , strlen ( $ alias ) + 1 ) ; } } if ( isset ( $ row [ $ name ] ) ) { $ data [ $ name ] = $ this -> serializeType ( $ row [ $ name ] , $ type ) ; } } return $ data ; } | Returns an array which can be used by the dbal insert update and delete methods |
35,368 | private function setParameters ( ContainerBuilder $ container , $ basicPath , $ paramsArray ) { foreach ( $ paramsArray as $ key => $ params ) { $ container -> setParameter ( $ basicPath . '.' . $ key , $ paramsArray [ $ key ] ) ; } } | Sets parameters to container as specified by key value pair in params - array . |
35,369 | public function merge ( $ array , $ default = true ) { $ newarray = array ( ) ; foreach ( $ array as $ key => $ value ) { $ newKey = is_numeric ( $ key ) ? $ value : $ key ; $ newValue = is_numeric ( $ key ) ? true : $ value ; $ newarray [ $ newKey ] = $ newValue ; } $ this -> _options = array_merge ( $ this -> _options , $ newarray ) ; return $ this ; } | Merges a new array into the options structure |
35,370 | public static function fromString ( $ string , $ default = true ) { $ array = array ( ) ; foreach ( preg_split ( '/\s+/' , $ string , - 1 , PREG_SPLIT_NO_EMPTY ) as $ token ) { $ fragments = explode ( "=" , $ token ) ; $ value = isset ( $ fragments [ 1 ] ) ? trim ( $ fragments [ 1 ] , "' " ) : $ default ; $ array [ $ fragments [ 0 ] ] = $ value === 'null' ? null : $ value ; } return new self ( $ array , $ default ) ; } | Creates an options object from a flat string |
35,371 | public function toString ( $ default = true ) { $ options = array ( ) ; $ binder = new Database \ Binder ( ) ; foreach ( $ this as $ key => $ value ) { $ options [ ] = ( $ value === $ default ) ? $ key : sprintf ( "%s=%s" , $ key , urlencode ( $ value ) ) ; } return implode ( ' ' , $ options ) ; } | Serializes the options to a string . |
35,372 | public static function coerce ( $ from ) { if ( is_array ( $ from ) || is_null ( $ from ) ) { return new self ( ( array ) $ from ) ; } elseif ( is_string ( $ from ) ) { return self :: fromString ( $ from ) ; } elseif ( $ from instanceof Options ) { return $ from ; } else { throw new \ InvalidArgumentException ( "Unable to coerce provided type" ) ; } } | Convert either a null a string or an array into an Option |
35,373 | public function renderRelationMethods ( ) { $ output = '' ; foreach ( $ this -> relations as $ relation ) { $ output .= $ relation -> renderMethod ( ) ; } return $ output ; } | Render relation methods |
35,374 | public static function resolve ( array $ parameters , $ context = null ) { $ params = [ ] ; foreach ( $ parameters as $ key => $ value ) { if ( $ value instanceof Reference ) { $ val = $ value -> getValue ( ) ; if ( isset ( $ context [ $ val ] ) ) { $ params [ $ key ] = $ context [ $ val ] ; } else { throw new RuntimeException ( 'Reference invalid context key "' . $ val . '"' ) ; } } else { $ params [ $ key ] = $ value ; } } return $ params ; } | Resolves parameters agains a context |
35,375 | static public function scope ( $ name , array $ params ) { $ cn = self :: cn ( ) ; self :: $ preventInit = true ; $ scopes = ( new $ cn ( ) ) -> scopes ( ) ; if ( isset ( $ scopes [ $ name ] ) ) { $ lambda = $ scopes [ $ name ] ; $ relation = new Relation ( $ cn , static :: tableName ( ) ) ; $ lambda = $ lambda -> bindTo ( $ relation ) ; call_user_func_array ( $ lambda , $ params ) ; return $ relation ; } else return false ; } | Checks if scope exists . If it does executes it and returns the relation ; otherwise returns false . |
35,376 | private function createJsonBody ( array $ params ) { return ( 0 === \ count ( $ params ) ) ? null : \ json_encode ( $ params , empty ( $ params ) ? \ JSON_FORCE_OBJECT : 0 ) ; } | Create a JSON encoded version of an array of parameters . |
35,377 | public function build_url ( array $ params , $ raise_e = true ) { $ this -> build ( ) ; $ this -> _build_params = $ params ; $ this -> _build_url = $ this -> _url ; if ( ! $ this -> _check_main_vars ( ) ) { $ this -> _build_params = array ( ) ; $ this -> _build_url = '' ; return false ; } if ( ( $ groups = $ this -> _optional_groups ) && ( array_shift ( $ groups ) ? : true ) && $ groups ) { foreach ( $ groups as $ group ) { $ parsed_group = $ this -> _check_optional_groups ( $ group ) ; $ this -> _build_url = str_replace ( $ group [ 'part' ] , $ parsed_group , $ this -> _build_url ) ; } } $ this -> _build_url = str_replace ( array ( '(' , ')' ) , '' , $ this -> _build_url ) ; $ this -> _build_params = array_keys ( $ this -> _build_params ) ; return '/' . $ this -> _build_url ; } | Builds the URL with params passed and returns it . The params must include all variables defined for the route and also must pass the regex validation else an exception will be thrown . Any param that is not used by the route will be ignored . |
35,378 | public function namespaced_controller_file ( ) { if ( ! $ this -> _modules ) return false ; return Rails :: config ( ) -> paths -> controllers . '/' . $ this -> namespace_path ( ) . '/application_controller.php' ; } | Each namespace can have its own application controller . This is called by Rails_Application when checking for the file for ApplicationController ; If we re in a namespace the path to the application_controller file changes . |
35,379 | private function _set_default_vars_values ( ) { $ default_action = 'index' ; if ( ! $ this -> _assets_route ) { if ( $ this -> _to ) { try { $ token = new UrlToken ( $ this -> _to ) ; list ( $ controller , $ default_action ) = $ token -> parts ( ) ; } catch ( Exception $ e ) { } } } if ( ! isset ( $ this -> _defaults [ 'action' ] ) ) $ this -> _defaults [ 'action' ] = $ default_action ; foreach ( $ this -> _defaults as $ var => $ val ) { if ( $ var == 'action' ) { if ( $ val == ':action' ) { $ val = 'index' ; } $ this -> _action = $ val ; } elseif ( $ var == 'controller' ) $ this -> _controller = $ val ; $ this -> _vars [ $ var ] [ 'value' ] = $ val ; } if ( ! isset ( $ this -> _vars [ 'format' ] [ 'value' ] ) || $ this -> _vars [ 'format' ] [ 'value' ] === '' ) $ this -> _vars [ 'format' ] [ 'value' ] = 'html' ; $ this -> _format = $ this -> _vars [ 'format' ] [ 'value' ] ; $ this -> _defaults = null ; } | Set index = action by default . |
35,380 | private function _parse_variable_to ( ) { $ parts = explode ( '#' , $ this -> _to ) ; empty ( $ parts [ 1 ] ) && $ parts [ 1 ] = 'index' ; $ part = is_int ( strpos ( $ parts [ 0 ] , ':' ) ) ? $ parts [ 0 ] : $ parts [ 1 ] ; preg_match ( '/:(\w+)/' , $ part , $ m ) ; $ type = $ m [ 1 ] ; return $ type ; } | Returns the variable part of the _to attribute . |
35,381 | protected function parseAccount ( AccountInterface $ account ) { if ( $ account ) { $ data = [ ] ; $ data [ 'id' ] = $ account -> getId ( ) ; $ data [ 'name' ] = $ account -> getName ( ) ; $ data [ 'phone' ] = $ account -> getMainPhone ( ) ; $ data [ 'email' ] = $ account -> getMainEmail ( ) ; $ data [ 'url' ] = $ account -> getMainUrl ( ) ; if ( $ account -> getMainContact ( ) ) { $ data [ 'contact' ] = $ account -> getMainContact ( ) -> getFullName ( ) ; } $ accountAddress = $ account -> getMainAddress ( ) ; if ( $ accountAddress ) { $ data [ 'address' ] [ 'street' ] = $ accountAddress -> getStreet ( ) ; $ data [ 'address' ] [ 'number' ] = $ accountAddress -> getNumber ( ) ; $ data [ 'address' ] [ 'zip' ] = $ accountAddress -> getZip ( ) ; $ data [ 'address' ] [ 'city' ] = $ accountAddress -> getCity ( ) ; $ data [ 'address' ] [ 'country' ] = $ accountAddress -> getCountry ( ) -> getName ( ) ; } return $ data ; } else { return null ; } } | Parses the account data . |
35,382 | public function setBasePath ( $ basePath ) { $ this [ 'path.app' ] = rtrim ( $ basePath ) ; foreach ( [ 'config' , 'views' , 'logs' ] as $ v ) { $ this [ 'path.' . $ v ] = realpath ( rtrim ( $ basePath ) . '/' . $ v ) . DIRECTORY_SEPARATOR ; } $ this [ 'namespace.controller' ] = '' ; return $ this ; } | Set the base path for the application . |
35,383 | protected function orderDataByDate ( $ desc = true ) { usort ( $ this -> entries , function ( $ a , $ b ) use ( $ desc ) { if ( $ a [ 'date' ] > $ b [ 'date' ] ) { if ( ! $ desc ) { return 1 ; } return - 1 ; } elseif ( $ a [ 'date' ] < $ b [ 'date' ] ) { if ( ! $ desc ) { return - 1 ; } return 1 ; } return 0 ; } ) ; } | Sorts the data array by the date . |
35,384 | private function parseDates ( $ data , $ format ) { foreach ( $ data as $ key => $ entry ) { $ data [ $ key ] [ 'date' ] = $ data [ $ key ] [ 'date' ] -> format ( $ format ) ; } return $ data ; } | Parses dates according to a given format . |
35,385 | protected function getRoute ( $ id , $ subject , $ type ) { if ( ! is_null ( $ this -> routes ) && array_key_exists ( $ subject , $ this -> routes ) && array_key_exists ( $ type , $ this -> routes [ $ subject ] ) ) { return str_replace ( '[id]' , $ id , $ this -> routes [ $ subject ] [ $ type ] ) ; } return '' ; } | Returns uri for shippings . |
35,386 | protected function checkRequiredParameters ( array $ options = null , $ requiredParameters = [ ] ) { if ( empty ( $ options ) ) { throw new WidgetException ( 'No params found!' , $ this -> getName ( ) ) ; } foreach ( $ requiredParameters as $ parameter ) { if ( empty ( $ options [ $ parameter ] ) ) { throw new WidgetParameterException ( 'Required parameter ' . $ parameter . ' not found or invalid!' , $ this -> widgetName , $ parameter ) ; } } } | Checks for required parameters . |
35,387 | public function sendShopownerConfirmation ( $ recipient , ApiOrderInterface $ apiOrder , ContactInterface $ customerContact = null ) { if ( ! $ this -> sendEmailConfirmationToShopowner ) { return false ; } if ( empty ( $ recipient ) ) { $ recipient = $ this -> confirmationRecipientEmailAddress ; } return $ this -> sendConfirmationEmail ( $ recipient , $ apiOrder , $ this -> templateShopownerConfirmationPath , $ customerContact ) ; } | Sends a confirmation email to the shop - owner . |
35,388 | public function sendCustomerConfirmation ( $ recipient , ApiOrderInterface $ apiOrder , ContactInterface $ customerContact = null ) { if ( ! $ this -> sendEmailConfirmationToCustomer ) { return false ; } return $ this -> sendConfirmationEmail ( $ recipient , $ apiOrder , $ this -> templateCustomerConfirmationPath , $ customerContact ) ; } | Sends a confirmation email to the customer . |
35,389 | protected function applyOrderAttachments ( \ Swift_Message $ message , ApiOrderInterface $ apiOrder = null , $ sendXMLOrder = false ) { if ( $ apiOrder ) { $ pdf = $ this -> pdfManager -> createOrderConfirmation ( $ apiOrder ) ; $ pdfFileName = $ this -> pdfManager -> getPdfName ( $ apiOrder ) ; $ attachment = \ Swift_Attachment :: newInstance ( ) -> setFilename ( $ pdfFileName ) -> setContentType ( 'application/pdf' ) -> setBody ( $ pdf ) ; $ message -> attach ( $ attachment ) ; if ( $ sendXMLOrder ) { $ message -> attach ( $ this -> createXMLAttachment ( $ apiOrder ) ) ; } } } | Function adds attachments to the email message . |
35,390 | public function discount ( Product $ product ) { $ discount = $ this -> money ( $ product ) ; if ( $ product -> discount ) { $ discount = $ product -> discount -> product ( $ product ) ; $ discount = $ discount -> multiply ( $ product -> quantity ) ; } return $ discount ; } | Return the discount of the Product |
35,391 | public function delivery ( Product $ product ) { $ delivery = $ product -> delivery -> multiply ( $ product -> quantity ) ; return $ delivery ; } | Return the delivery charge of the Product |
35,392 | public function tax ( Product $ product ) { $ tax = $ this -> money ( $ product ) ; if ( ! $ product -> taxable || $ product -> freebie ) { return $ tax ; } $ value = $ this -> value ( $ product ) ; $ discount = $ this -> discount ( $ product ) ; $ value = $ value -> subtract ( $ discount ) ; $ tax = $ value -> multiply ( $ product -> rate -> float ( ) ) ; return $ tax ; } | Return the tax of the Product |
35,393 | public function subtotal ( Product $ product ) { $ subtotal = $ this -> money ( $ product ) ; if ( ! $ product -> freebie ) { $ value = $ this -> value ( $ product ) ; $ discount = $ this -> discount ( $ product ) ; $ subtotal = $ subtotal -> add ( $ value ) -> subtract ( $ discount ) ; } $ delivery = $ this -> delivery ( $ product ) ; $ subtotal = $ subtotal -> add ( $ delivery ) ; return $ subtotal ; } | Return the subtotal of the Product |
35,394 | public function total ( Product $ product ) { $ tax = $ this -> tax ( $ product ) ; $ subtotal = $ this -> subtotal ( $ product ) ; $ total = $ subtotal -> add ( $ tax ) ; return $ total ; } | Return the total of the Product |
35,395 | public function remove ( $ attrs ) { ! is_array ( $ attrs ) && $ attrs = array ( 'id' => $ attrs ) ; foreach ( $ this -> members ( ) as $ k => $ m ) { foreach ( $ attrs as $ a => $ v ) { if ( $ m -> getAttribute ( $ a ) != $ v ) continue 2 ; } unset ( $ this -> members [ $ k ] ) ; } $ this -> members = array_values ( $ this -> members ) ; return $ this ; } | Removes members according to attributes . |
35,396 | protected function drawTable1 ( ) { $ this -> drawBankHeader ( ) ; $ this -> drawGenericTable1 ( 'LB' , [ 80.8 , 35.4 , 11 , 16 , 33.8 , 52.8 , 37 , 37.4 , 49.8 , 32 , 32 , 32 , 31.2 , 49.8 , 177 ] ) ; $ dict = $ this -> dictionary ; $ fields = $ this -> fields ; $ this -> billetSetFont ( 'cell_title' ) ; $ this -> Cell ( 151 , 3.5 , $ fields [ 'demonstrative' ] [ 'text' ] , 0 , 0 ) ; $ this -> Cell ( 26 , 3.5 , $ dict [ 'mech_auth' ] , 0 , 1 ) ; $ this -> billetSetFont ( 'cell_data' ) ; $ y = $ this -> GetY ( ) ; $ this -> MultiCell ( 151 , 3.5 , $ fields [ 'demonstrative' ] [ 'value' ] ) ; $ y1 = $ this -> GetY ( ) ; $ this -> SetXY ( 161 , $ y ) ; $ this -> Cell ( 26 , 3.5 , '' , 0 , 1 ) ; $ y2 = $ this -> GetY ( ) ; $ this -> SetY ( max ( $ y + 14 , $ y1 , $ y2 ) ) ; $ this -> Ln ( 12 ) ; } | Table 1 stays with the Client |
35,397 | protected function drawTable2 ( ) { $ this -> drawBankHeader ( ) ; $ this -> drawGenericTable2 ( 'instructions' , 'LB' , [ 127.2 , 49.8 , 127.2 , 49.8 , 32 , 42.2 , 18 , 11 , 24 , 49.8 , 32 , 24 , 16 , 34.2 , 21 , 49.8 , 127.2 , 49.8 ] ) ; $ dict = $ this -> dictionary ; $ fields = $ this -> fields ; $ client_data = $ fields [ 'client' ] [ 'value' ] . "\n" . utf8_decode ( $ this -> title -> client -> address -> outputLong ( ) ) ; $ this -> billetSetFont ( 'cell_title' ) ; $ this -> Cell ( 127.2 , 7 , $ fields [ 'client' ] [ 'text' ] , 'L' , 1 ) ; $ this -> billetSetFont ( 'cell_data' ) ; $ this -> MultiCell ( 127.2 , 3.5 , $ client_data , 'LB' ) ; $ this -> SetXY ( 137.2 , $ this -> GetY ( ) - 3.5 ) ; $ this -> billetSetFont ( 'cell_title' ) ; $ this -> Cell ( 49.8 , 3.5 , $ dict [ 'cod_down' ] , 'LB' , 1 ) ; $ this -> Cell ( 17 , 3.5 , $ fields [ 'guarantor' ] [ 'text' ] ) ; $ this -> billetSetFont ( 'cell_data' ) ; $ this -> Cell ( 93 , 3.5 , $ fields [ 'guarantor' ] [ 'value' ] ) ; $ this -> billetSetFont ( 'cell_title' ) ; $ this -> Cell ( 39.5 , 3.5 , $ dict [ 'mech_auth' ] . ' - ' , 0 , 0 , 'R' ) ; $ this -> billetSetFont ( 'cell_data' ) ; $ this -> Cell ( 27.5 , 3.5 , $ dict [ 'compensation' ] , 0 , 1 , 'R' ) ; } | Table 2 stays in payment place |
35,398 | public static function fromReflection ( ReflectionClass $ reflectionClass ) { if ( $ reflectionClass -> isTrait ( ) !== true ) { throw new InvalidArgumentException ( 'The reflected class must be a trait.' ) ; } $ tg = new static ( $ reflectionClass -> getShortName ( ) , $ reflectionClass -> getNamespaceName ( ) ) ; if ( $ reflectionClass -> getReflectionDocComment ( ) -> isEmpty ( ) !== true ) { $ tg -> setDocumentation ( DocCommentGenerator :: fromReflection ( $ reflectionClass -> getReflectionDocComment ( ) ) ) ; } foreach ( $ reflectionClass -> getUses ( ) as $ use ) { $ use = UseTraitGenerator :: fromReflection ( $ use ) ; if ( $ tg -> getNamespace ( ) !== null && strpos ( $ use -> getTraitClass ( ) , $ tg -> getNamespace ( ) ) === 0 ) { $ use -> setTraitClass ( substr ( $ use -> getTraitClass ( ) , strlen ( $ tg -> getNamespace ( ) ) + 1 ) ) ; } $ tg -> addTraitUse ( $ use ) ; } foreach ( $ reflectionClass -> getOwnProperties ( ) as $ property ) { $ tg -> addProperty ( PropertyGenerator :: fromReflection ( $ property ) ) ; } foreach ( $ reflectionClass -> getOwnMethods ( ) as $ method ) { $ tg -> addMethod ( MethodGenerator :: fromReflection ( $ method ) ) ; } return $ tg ; } | Create a new trait from reflection . |
35,399 | public function filter ( array $ locales ) { $ this -> filtered = [ ] ; foreach ( $ locales as $ locale ) { $ this -> filterLocale ( $ locale ) ; } return $ this -> filtered ; } | Filter the locales . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.