idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
27,100 | public function update ( $ table , array $ data ) { $ conditions = array ( ) ; foreach ( $ data as $ key => $ value ) { $ conditions [ ] = sprintf ( '%s = %s' , $ this -> quote ( $ key ) , $ value ) ; } $ query = sprintf ( 'UPDATE %s SET %s' , $ this -> quote ( $ table ) , implode ( ', ' , $ conditions ) ) ; $ this -> append ( $ query ) ; return $ this ; } | Builds UPDATE query |
27,101 | private function recountColumn ( $ table , $ column , $ operator , $ step = 1 ) { $ step = ( int ) $ step ; $ step = ( string ) $ step ; return $ this -> update ( $ table , array ( $ column => $ column . sprintf ( ' %s ' , $ operator ) . $ step ) ) ; } | Re - counts a column |
27,102 | private function createSelectData ( $ type ) { if ( $ type !== '*' && $ type !== null && ! is_array ( $ type ) ) { $ type = $ this -> quote ( $ type ) ; } if ( is_array ( $ type ) ) { $ collection = array ( ) ; foreach ( $ type as $ column => $ alias ) { if ( ! is_numeric ( $ column ) ) { $ push = sprintf ( '%s AS %s' , $ this -> quote ( $ column ) , $ this -> quote ( $ alias ) ) ; } else if ( $ alias instanceof RawSqlFragmentInterface ) { $ push = $ alias -> getFragment ( ) ; } else { $ push = $ this -> quote ( $ alias ) ; } array_push ( $ collection , $ push ) ; } $ type = implode ( ', ' , $ collection ) ; } return $ type ; } | Returns expression which needs to be followed right after SELECT |
27,103 | public function limit ( $ offset , $ amount = null ) { if ( is_null ( $ amount ) ) { $ this -> append ( ' LIMIT ' . $ offset ) ; } else { $ this -> append ( sprintf ( ' LIMIT %s, %s' , $ offset , $ amount ) ) ; } return $ this ; } | Appends LIMIT expression |
27,104 | public function from ( $ table = null ) { if ( $ table !== null ) { $ this -> table = $ table ; $ table = $ this -> quote ( $ table ) ; } $ this -> append ( ' FROM ' . $ table ) ; return $ this ; } | Appends FROM expression |
27,105 | public function compare ( $ column , $ operator , $ value , $ filter = false ) { if ( ! $ this -> isFilterable ( $ filter , $ value ) ) { return $ this ; } if ( $ value instanceof RawSqlFragmentInterface ) { $ value = $ value -> getFragment ( ) ; } if ( $ value instanceof RawBindingInterface ) { $ value = $ value -> getTarget ( ) ; } $ this -> append ( sprintf ( ' %s %s %s ' , $ this -> quote ( $ column ) , $ operator , $ value ) ) ; return $ this ; } | Appends a raw comparison |
27,106 | private function createConstraint ( $ token , $ column , $ operator , $ value , $ filter ) { if ( ! $ this -> isFilterable ( $ filter , $ value ) ) { return $ this ; } $ this -> append ( sprintf ( '%s %s %s %s ' , $ token , $ this -> quote ( $ column ) , $ operator , $ value ) ) ; return $ this ; } | Appends constraint string |
27,107 | public function where ( $ column , $ operator , $ value , $ filter = false ) { return $ this -> createConstraint ( ' WHERE' , $ column , $ operator , $ value , $ filter ) ; } | Appends WHERE expression |
27,108 | public function whereEqualsOrGreaterThan ( $ column , $ value , $ filter = false ) { return $ this -> where ( $ column , '>=' , $ value , $ filter ) ; } | Appends WHERE clause with Greater than or equals operator |
27,109 | public function whereEqualsOrLessThan ( $ column , $ value , $ filter = false ) { return $ this -> where ( $ column , '<=' , $ value , $ filter ) ; } | Appends WHERE clause with Less than or equals operator |
27,110 | public function join ( $ type , $ table , array $ relations = array ( ) ) { $ this -> append ( sprintf ( ' %s JOIN %s ' , $ type , $ table ) ) ; if ( ! empty ( $ relations ) ) { $ this -> on ( ) ; $ i = 0 ; $ count = count ( $ relations ) ; foreach ( $ relations as $ column => $ value ) { $ i ++ ; $ this -> equals ( $ column , $ value ) ; if ( $ i != $ count ) { $ this -> rawAnd ( ) ; } } } return $ this ; } | Appends JOIN statement |
27,111 | public function groupBy ( $ target ) { $ columns = null ; if ( is_string ( $ target ) ) { $ columns = $ target ; } elseif ( is_array ( $ target ) ) { $ columns = implode ( ', ' , $ target ) ; } else { throw new InvalidArgumentException ( sprintf ( 'groupBy() accepts only an array of columns or a plain column name. You supplied "%s"' , gettype ( $ target ) ) ) ; } $ this -> append ( sprintf ( ' GROUP BY %s ' , $ columns ) ) ; return $ this ; } | Appends GROUP BY statement |
27,112 | public function orderBy ( $ type = null ) { if ( $ type === null ) { $ target = null ; } elseif ( $ type instanceof RawSqlFragmentInterface ) { $ target = $ type -> getFragment ( ) ; } elseif ( is_array ( $ type ) ) { if ( ! ArrayUtils :: isAssoc ( $ type ) ) { foreach ( $ type as & $ option ) { if ( $ option instanceof RawSqlFragmentInterface ) { $ option = $ option -> getFragment ( ) ; } else { $ option = $ this -> quote ( $ option ) ; } } } else { $ result = array ( ) ; foreach ( $ type as $ column => $ sortOrder ) { $ sortOrder = strtoupper ( $ sortOrder ) ; if ( ! in_array ( $ sortOrder , array ( 'ASC' , 'DESC' ) ) ) { throw new LogicException ( sprintf ( 'Only ASC and DESC methods are supported. You provided "%s"' , $ sortOrder ) ) ; } array_push ( $ result , sprintf ( '%s %s' , $ this -> quote ( $ column ) , $ sortOrder ) ) ; } $ type = $ result ; } $ target = implode ( ', ' , $ type ) ; } else { $ target = $ this -> quote ( $ type ) ; } $ this -> append ( ' ORDER BY ' . $ target ) ; return $ this ; } | Appends ORDER BY expression |
27,113 | private function between ( $ column , $ a , $ b , $ prefix , $ not = false , $ operator = null , $ filter = false ) { if ( ! $ this -> isFilterable ( $ filter , array ( $ a , $ b ) ) ) { return $ this ; } if ( $ operator !== null ) { $ operator = sprintf ( ' %s' , $ operator ) ; } if ( $ not === true ) { $ not = 'NOT' ; } else { $ not = '' ; } $ this -> append ( $ operator . sprintf ( ' %s %s %s BETWEEN %s AND %s ' , $ prefix , $ this -> quote ( $ column ) , $ not , $ a , $ b ) ) ; return $ this ; } | Appends WHERE with BETWEEN operator |
27,114 | public function andWhereNotBetween ( $ column , $ a , $ b , $ filter = false ) { return $ this -> between ( $ column , $ a , $ b , null , true , 'AND' , $ filter ) ; } | Appends AND WHERE with NOT BETWEEN operator |
27,115 | public function delete ( array $ tables = array ( ) ) { $ this -> append ( ' DELETE ' ) ; if ( ! empty ( $ tables ) ) { $ tablesSequence = implode ( ', ' , $ tables ) ; $ this -> append ( $ tablesSequence ) ; } return $ this ; } | Appends DELETE expression |
27,116 | public function renameTable ( $ old , $ new ) { $ this -> append ( sprintf ( 'RENAME TABLE %s TO %s ' , $ this -> quote ( $ old ) , $ this -> quote ( $ new ) ) ) ; return $ this ; } | Appends RENAME TO statement |
27,117 | public function dropTable ( $ target , $ ifExists = true ) { $ query = 'DROP TABLE ' ; if ( $ ifExists === true ) { $ query .= 'IF EXISTS ' ; } if ( ! is_array ( $ target ) ) { $ target = array ( $ target ) ; } $ target = $ this -> quote ( $ target ) ; $ query .= sprintf ( '%s;' , implode ( ', ' , $ target ) ) ; $ this -> append ( $ query ) ; return $ this ; } | Generates DROP TABLE statement |
27,118 | public function renameColumn ( $ old , $ new ) { $ this -> append ( sprintf ( ' RENAME COLUMN %s TO %s ' , $ this -> quote ( $ old ) , $ this -> quote ( $ new ) ) ) ; return $ this ; } | Appends RENAME COLUMN TO statement |
27,119 | public function alterColumn ( $ column , $ type ) { $ column = $ this -> quote ( $ column ) ; $ this -> append ( sprintf ( ' CHANGE %s %s %s ' , $ column , $ column , $ type ) ) ; return $ this ; } | Appends CHANGE statement |
27,120 | public function dropIndex ( $ table , $ name ) { $ query = sprintf ( 'DROP INDEX %s ON %s ;' , $ this -> quote ( $ name ) , $ this -> quote ( $ table ) ) ; $ this -> append ( $ query ) ; return $ this ; } | Appends DROP INDEX expression |
27,121 | public function get_inline_css ( ) { if ( $ this -> get_pre_selectors ( ) ) { $ inline_css = sprintf ( '%1$s { %2$s }' , implode ( ',' , $ this -> get_selectors ( ) ) , $ this -> get_properties ( ) ) ; foreach ( $ this -> get_pre_selectors ( ) as $ pre_selector ) { $ inline_css = sprintf ( '%1$s { %2$s }' , $ pre_selector , $ inline_css ) ; } return $ inline_css ; } return sprintf ( '%1$s { %2$s }' , implode ( ',' , $ this -> get_selectors ( ) ) , $ this -> get_properties ( ) ) ; } | Return inline CSS |
27,122 | public function getModel ( $ name ) { if ( ! isset ( $ this -> models [ $ name ] ) ) { throw new RuntimeException ( sprintf ( "The model document name '%s' is not added in chain model '%s'" , $ name , $ this -> id ) ) ; } $ this -> models [ $ name ] -> setContainer ( $ this -> container ) ; return $ this -> models [ $ name ] ; } | Retorna el modelo de un documento por su nombre |
27,123 | public function getDirOutput ( ) { $ ds = DIRECTORY_SEPARATOR ; $ id = $ this -> getId ( ) ; $ documentsPath = $ this -> exporterManager -> getOption ( "documents_path" ) ; $ env = $ this -> exporterManager -> getOption ( "env" ) ; if ( $ this -> basePath === null ) { $ fullPath = $ documentsPath . $ ds . $ env . $ ds . $ id ; } else { $ fullPath = $ this -> basePath ; } if ( $ this -> subPath !== null ) { $ fullPath .= $ ds . $ this -> subPath ; } if ( ! $ this -> exporterManager -> getFs ( ) -> exists ( $ fullPath ) ) { $ this -> exporterManager -> getFs ( ) -> mkdir ( $ fullPath ) ; } return $ fullPath ; } | Retorna el directorio de salida de los documentos del model |
27,124 | public function getFiles ( ) { $ dir = $ this -> getDirOutput ( ) ; $ finder = new \ Symfony \ Component \ Finder \ Finder ( ) ; $ finder -> files ( ) -> in ( $ dir ) ; return $ finder ; } | Obtiene los archivos en la carpeta del chain en el modulo |
27,125 | public function deleteFile ( $ fileName ) { $ files = $ this -> getFiles ( ) ; $ success = false ; foreach ( $ files as $ file ) { if ( $ file -> getRelativePathname ( ) === $ fileName ) { if ( ! $ file -> isWritable ( ) ) { throw new RuntimeException ( sprintf ( "The file '%s' is not writable and can not be deleted." , $ fileName ) ) ; } unlink ( $ file -> getRealPath ( ) ) ; if ( $ file -> isReadable ( ) ) { throw new RuntimeException ( sprintf ( "The file '%s' could not be deleted" , $ fileName ) ) ; } $ success = true ; } } return $ success ; } | Elimina un archivo dentro del modulo con su nombre |
27,126 | public function getFile ( $ fileName ) { $ files = $ this -> getFiles ( ) ; $ found = null ; foreach ( $ files as $ file ) { if ( $ file -> getRelativePathname ( ) === $ fileName ) { if ( ! $ file -> isReadable ( ) ) { throw new RuntimeException ( sprintf ( "The file '%s' could not be read." , $ fileName ) ) ; } $ found = $ file ; break ; } } return $ found ; } | Busca un archivo por su nombre en la carpeta del exportador |
27,127 | public static function createFromFile ( \ SplFileInfo $ file_info ) { $ contents = file_get_contents ( $ file_info ) ; if ( ! $ contents ) { throw new \ RuntimeException ( sprintf ( 'Unable to retrieve contents from file (%s).' , $ file_info -> getRealPath ( ) ) ) ; } return self :: createFromString ( $ contents ) ; } | Create configuration object from file . |
27,128 | public static function build ( $ dir , array $ plugins ) { if ( count ( $ plugins ) === 0 ) { throw new InvalidArgumentException ( 'There must be at least one provided plugin for image uploader' ) ; } $ quality = 75 ; $ collection = array ( ) ; foreach ( $ plugins as $ plugin => $ options ) { switch ( $ plugin ) { case 'thumb' : $ thumb = new ThumbFactory ( ) ; $ collection [ ] = $ thumb -> build ( $ dir , $ quality , $ options ) ; break ; case 'original' : $ original = new OriginalSizeFactory ( ) ; $ collection [ ] = $ original -> build ( $ dir , $ quality , $ options ) ; break ; } } return new UploadChain ( $ collection ) ; } | Builds image uploader chain |
27,129 | public static function checkPermission ( string $ permissionName , bool $ checkForNested = false ) : bool { if ( self :: isAdmin ( ) ) { return true ; } $ user = \ Craft :: $ app -> getUser ( ) ; $ permissionName = strtolower ( $ permissionName ) ; if ( self :: permissionsEnabled ( ) ) { if ( $ checkForNested ) { if ( ! $ user -> getId ( ) ) { return false ; } $ permissionList = \ Craft :: $ app -> userPermissions -> getPermissionsByUserId ( $ user -> getId ( ) ) ; foreach ( $ permissionList as $ permission ) { if ( strpos ( $ permission , $ permissionName ) === 0 ) { return true ; } } } return $ user -> checkPermission ( $ permissionName ) ; } return false ; } | Checks a given permission for the currently logged in user |
27,130 | public static function getNestedPermissionIds ( string $ permissionName ) { if ( self :: isAdmin ( ) ) { return true ; } $ user = \ Craft :: $ app -> getUser ( ) ; $ permissionName = strtolower ( $ permissionName ) ; $ idList = [ ] ; if ( self :: permissionsEnabled ( ) ) { if ( ! $ user -> getId ( ) ) { return [ ] ; } $ permissionList = \ Craft :: $ app -> userPermissions -> getPermissionsByUserId ( $ user -> getId ( ) ) ; foreach ( $ permissionList as $ permission ) { if ( strpos ( $ permission , $ permissionName ) === 0 ) { if ( strpos ( $ permission , ':' ) === false ) { continue ; } list ( $ name , $ id ) = explode ( ':' , $ permission ) ; $ idList [ ] = $ id ; } } return $ idList ; } return self :: isAdmin ( ) ; } | Fetches all nested allowed permission IDs from a nested permission set |
27,131 | public function loadTemplate ( $ filename , $ format = null ) { $ contents = $ this -> getTemplateContent ( $ filename ) ; switch ( $ format ) { case 'json' : $ contents = json_decode ( $ contents , true ) ; break ; } return $ contents ; } | Load template file contents . |
27,132 | public function getTemplateFilePath ( $ filename ) { $ filepath = $ this -> locateTemplateFilePath ( $ filename ) ; if ( ! file_exists ( $ filepath ) ) { return false ; } return $ filepath ; } | Get template file path . |
27,133 | protected function locateTemplateFilePath ( $ filename ) { if ( $ this -> hasProjectTemplateDirectory ( ) ) { $ filepath = $ this -> templateProjectPath ( ) . "/{$filename}" ; if ( file_exists ( $ filepath ) ) { return $ filepath ; } } foreach ( $ this -> searchDirectories as $ directory ) { if ( ! file_exists ( $ directory ) ) { continue ; } $ filepath = "{$directory}/{$filename}" ; if ( file_exists ( $ filepath ) ) { return $ filepath ; } } return null ; } | Locate the template file path . |
27,134 | public function getMissingCoreModules ( ) { $ modules = array ( ) ; foreach ( $ this -> coreModules as $ module ) { if ( ! $ this -> isLoadedModule ( $ module ) ) { array_push ( $ modules , $ module ) ; } } return $ modules ; } | Returns a collection of missing modules |
27,135 | public function isCoreModule ( $ module ) { if ( ! is_string ( $ module ) ) { throw new InvalidArgumentException ( sprintf ( 'Module name must be a string, not "%s"' , gettype ( $ module ) ) ) ; } return in_array ( $ module , $ this -> coreModules ) ; } | Checks whether target module |
27,136 | public function isCoreModules ( array $ modules ) { foreach ( $ modules as $ module ) { if ( ! $ this -> isCoreModule ( $ module ) ) { return false ; } } return true ; } | Checks whether all collection consists of core modules |
27,137 | public function createInstance ( ) { $ classname = $ this -> getPlatformClassname ( ) ; if ( ! class_exists ( $ classname ) ) { throw new \ Exception ( sprintf ( 'Unable to locate class %s' , $ classname ) ) ; } return new $ classname ( ) ; } | Create a class instance . |
27,138 | public function filter ( QueryBuilder $ qb , $ alias , $ identifier , $ search ) { $ qb -> andWhere ( "LOWER({$alias}.{$identifier}) LIKE LOWER(:{$identifier})" ) ; $ qb -> setParameter ( $ identifier , "%{$search}%" ) ; } | Apply the filter in query builder . |
27,139 | public function setAcknowledgement ( string $ acknowledgement ) : SecurityTxt { if ( filter_var ( $ acknowledgement , FILTER_VALIDATE_URL ) === false ) { throw new Exception ( 'Acknowledgement must be a well-formed URL.' ) ; } $ this -> acknowledgement = $ acknowledgement ; return $ this ; } | Set the acknowledgement URL . |
27,140 | public function handle ( $ exception ) { $ file = $ exception -> getFile ( ) ; $ line = $ exception -> getLine ( ) ; $ message = $ exception -> getMessage ( ) ; $ trace = $ exception -> getTrace ( ) ; $ trace = array_reverse ( $ trace ) ; $ class = get_class ( $ exception ) ; require ( $ this -> templateFile ) ; } | Custom exception handler |
27,141 | public function webhook ( ) : void { if ( $ data = BotApi :: jsonValidate ( file_get_contents ( 'php://input' ) , true ) ) { $ update = Update :: fromResponse ( $ data ) ; $ this -> processUpdate ( $ update ) ; } } | Call this function to turn on the bot when processing via webhooks . |
27,142 | protected function addCommand ( Command $ handler ) : void { $ handler -> setBot ( $ this ) ; $ command = $ handler -> getName ( ) ; $ this -> commands [ strtoupper ( $ command ) ] = $ handler ; } | Add a command to the list of commands . |
27,143 | protected function setCallbackQueryHandler ( CallbackQueryHandler $ handler ) : void { $ handler -> setBot ( $ this ) ; $ this -> cqHandler = $ handler ; } | Set the handler to handle callback queries . |
27,144 | protected function setGenericMessageHandler ( GenericMessageHandler $ handler ) : void { $ handler -> setBot ( $ this ) ; $ this -> genericMessageHandler = $ handler ; } | Set the handler to handle plaintext messages . |
27,145 | public function increment ( $ key , $ step = 1 ) { $ value = $ this -> get ( $ key ) ; $ this -> set ( $ key , $ value + $ step ) ; } | Increments a numeric value |
27,146 | public function decrement ( $ key , $ step = 1 ) { $ value = $ this -> get ( $ key ) ; $ this -> set ( $ key , $ value - $ step ) ; } | Decrements a numeric value |
27,147 | public function get ( $ key , $ default = false ) { if ( $ this -> has ( $ key ) !== false ) { return $ this -> cache [ $ key ] ; } else { return $ default ; } } | Reads key s value from a cache if present |
27,148 | public function remove ( $ key ) { if ( $ this -> has ( $ key ) ) { unset ( $ this -> cache [ $ key ] ) ; return true ; } else { return false ; } } | Removes a key from the memory |
27,149 | private function buildColumns ( array $ columns ) { $ this -> columns = [ ] ; foreach ( $ columns as $ key => $ column ) { $ column = new DataTableColumn ( $ column ) ; $ this -> columns [ $ key ] = $ column ; if ( $ column -> getName ( ) != "" ) { $ this -> columns [ $ column -> getName ( ) ] = $ column ; } if ( $ column -> getData ( ) != "" ) { $ this -> columns [ $ column -> getData ( ) ] = $ column ; } } } | Construye una columna |
27,150 | public function getColumnByIndex ( $ index ) { if ( ! isset ( $ this -> columns [ $ index ] ) ) { throw new Exception ( sprintf ( "Column index %s is not valid" , $ index ) ) ; } return $ this -> columns [ $ index ] ; } | Retorna una columna por el indice |
27,151 | public function createInstance ( ) { $ classname = $ this -> getEngineClassname ( ) ; if ( ! class_exists ( $ classname ) ) { throw new \ Exception ( sprintf ( 'Unable to locate class %s' , $ classname ) ) ; } return new $ classname ( ) ; } | Create engine type instance . |
27,152 | public function supportsVersion ( Version $ version ) : bool { try { $ this -> getVersionUrl ( $ version ) ; } catch ( UnsupportedVersionException $ e ) { return false ; } return true ; } | Check if provider supports a specific version of the game . |
27,153 | public function callback ( $ request ) { $ this -> extend ( 'onBeforeCallback' ) ; $ data = $ this -> request -> postVars ( ) ; $ status = "error" ; $ order_id = 0 ; $ payment_id = 0 ; $ error_url = Controller :: join_links ( Director :: absoluteBaseURL ( ) , Payment_Controller :: config ( ) -> url_segment , 'complete' , 'error' ) ; if ( isset ( $ data ) && isset ( $ data [ 'custom' ] ) && isset ( $ data [ 'payment_status' ] ) ) { $ order_id = $ data [ 'custom' ] ; $ paypal_request = 'cmd=_notify-validate' ; $ final_response = "" ; if ( array_key_exists ( "txn_id" , $ data ) ) { $ payment_id = $ data [ "txn_id" ] ; } $ listener = new PaypalIPN ( ) ; if ( Director :: isDev ( ) ) { $ listener -> useSandbox ( ) ; } try { $ verified = $ listener -> verifyIPN ( ) ; } catch ( Exception $ e ) { error_log ( "Unable to verify IPN: " . $ e -> getMessage ( ) ) ; return $ this -> httpError ( 500 ) ; } if ( $ verified ) { switch ( $ data [ 'payment_status' ] ) { case 'Canceled_Reversal' : $ status = "canceled" ; break ; case 'Completed' : $ status = "paid" ; break ; case 'Denied' : $ status = "failed" ; break ; case 'Expired' : $ status = "failed" ; break ; case 'Failed' : $ status = "failed" ; break ; case 'Pending' : $ status = "pending" ; break ; case 'Processed' : $ status = "pending" ; break ; case 'Refunded' : $ status = "refunded" ; break ; case 'Reversed' : $ status = "canceled" ; break ; case 'Voided' : $ status = "canceled" ; break ; } } else { error_log ( "Invalid payment status" ) ; return $ this -> httpError ( 500 ) ; } } else { error_log ( "No payment details set" ) ; return $ this -> httpError ( 500 ) ; } $ payment_data = ArrayData :: array_to_object ( array ( "OrderID" => $ order_id , "PaymentProvider" => "PayPal" , "PaymentID" => $ payment_id , "Status" => $ status , "GatewayData" => $ data ) ) ; $ this -> setPaymentData ( $ payment_data ) ; $ this -> extend ( 'onAfterCallback' ) ; return $ this -> httpError ( 200 ) ; } | Process the callback data from the payment provider |
27,154 | public function setContext ( $ context ) { $ contexts = array ( self :: CONTEXT_CREDITCARD , self :: CONTEXT_TOKEN ) ; if ( ! in_array ( $ context , $ contexts ) ) { throw new RuntimeException ( sprintf ( "Invalid validation context '%s'" , $ context ) ) ; } $ this -> context = $ context ; } | Sets the context that the validator will validate a CreditCard . |
27,155 | public function validate ( CreditCard $ creditCard ) { $ this -> errors = array ( ) ; $ this -> creditCard = $ creditCard ; if ( $ this -> context == self :: CONTEXT_CREDITCARD ) { $ this -> validateNumber ( ) ; $ this -> validateExpiration ( ) ; $ this -> validateVerificationValue ( ) ; $ this -> validateBrand ( ) ; $ this -> validateCardHolder ( ) ; } elseif ( $ this -> context == self :: CONTEXT_TOKEN ) { $ this -> validateToken ( ) ; } return $ this -> errors ; } | Validates a CreditCard object . |
27,156 | public function tweak ( $ totalAmount , $ itemsPerPage , $ page ) { $ this -> totalAmount = ( int ) $ totalAmount ; $ this -> itemsPerPage = ( int ) $ itemsPerPage ; $ this -> setCurrentPage ( $ page ) ; return $ this ; } | Tweaks the service before it can be used |
27,157 | public function getUrl ( $ page ) { if ( is_null ( $ this -> url ) ) { throw new RuntimeException ( 'URL template must be defined' ) ; } if ( strpos ( $ this -> url , $ this -> placeholder ) !== false ) { return str_replace ( $ this -> placeholder , $ page , $ this -> url ) ; } else { throw new LogicException ( 'The URL string must contain at least one placeholder to make pagination links work' ) ; } } | Returns permanent URL substituting a placeholder with current page number |
27,158 | public function getSummary ( $ separator = '-' ) { if ( $ this -> getTotalAmount ( ) == 0 ) { return ( string ) 0 ; } else { return $ this -> getStart ( ) . $ separator . $ this -> getEnd ( ) ; } } | Returns a summary |
27,159 | public function reset ( ) { $ this -> itemsPerPage = null ; $ this -> currentPage = null ; $ this -> totalAmount = null ; $ this -> url = null ; return $ this ; } | Resets the paginator s instance |
27,160 | public function getPageNumbers ( ) { $ pages = range ( 1 , $ this -> getPagesCount ( ) ) ; if ( $ this -> getPagesCount ( ) > 10 && $ this -> hasAdapter ( ) ) { return $ this -> style -> getPageNumbers ( $ pages , $ this -> getCurrentPage ( ) ) ; } else { return $ pages ; } } | Returns total page numbers Style - adapter aware method |
27,161 | private function setCurrentPage ( $ currentPage , $ fixRange = true ) { if ( $ fixRange === true ) { if ( ! $ this -> pageInRange ( $ currentPage ) ) { $ currentPage = 1 ; } } $ this -> currentPage = ( int ) $ currentPage ; return $ this ; } | Defines current page |
27,162 | private function getPagesCount ( ) { if ( $ this -> getItemsPerPage ( ) != 0 ) { return ( int ) abs ( ceil ( $ this -> getTotalAmount ( ) / $ this -> getItemsPerPage ( ) ) ) ; } else { return 0 ; } } | Count total amount of pages |
27,163 | public function toArray ( ) { return array ( 'firstPage' => $ this -> getFirstPage ( ) , 'lastPage' => $ this -> getLastPage ( ) , 'offset' => $ this -> countOffset ( ) , 'summary' => $ this -> getSummary ( ) , 'hasPages' => $ this -> hasPages ( ) , 'hasAdapter' => $ this -> hasAdapter ( ) , 'hasNextPage' => $ this -> hasNextPage ( ) , 'hasPreviousPage' => $ this -> hasPreviousPage ( ) , 'nextPage' => $ this -> getNextPage ( ) , 'previousPage' => $ this -> getPreviousPage ( ) , 'nextPageUrl' => $ this -> getNextPageUrl ( ) , 'previousPageUrl' => $ this -> getPreviousPageUrl ( ) , 'currentPage' => $ this -> getCurrentPage ( ) , 'perPageCount' => $ this -> getItemsPerPage ( ) , 'total' => $ this -> getTotalAmount ( ) , 'pageNumbers' => $ this -> getPageNumbers ( ) ) ; } | Returns current state as array representation |
27,164 | protected function getPlatformOptions ( ) { $ config = $ this -> getConfigs ( ) ; $ options = $ config -> getOptions ( ) ; $ platform = $ config -> getPlatform ( ) ; return isset ( $ options [ $ platform ] ) ? $ options [ $ platform ] : [ ] ; } | Get platform options . |
27,165 | public function getPrice ( ) { $ price = $ this -> BasePrice ; foreach ( $ this -> getCustomisations ( ) as $ item ) { $ price += ( $ item -> Price ) ? $ item -> Price : 0 ; } return $ price ; } | Find the cost of all items in this line without any tax . |
27,166 | public function getDiscount ( ) { $ amount = 0 ; $ cart = ShoppingCart :: get ( ) ; $ items = $ cart -> TotalItems ; $ discount = $ cart -> getDiscount ( ) ; if ( $ this -> BasePrice && $ discount && $ discount -> Amount ) { if ( $ discount -> Type == "Fixed" ) { $ amount = ( $ discount -> Amount / $ items ) * $ this -> Quantity ; } elseif ( $ discount -> Type == "Percentage" ) { $ amount = ( ( $ this -> Price / 100 ) * $ discount -> Amount ) * $ this -> Quantity ; } } return $ amount ; } | Find the total discount amount for this line item |
27,167 | public function getTax ( ) { $ amount = 0 ; if ( $ this -> Price && $ this -> TaxRate ) { $ amount = ( ( $ this -> Price - $ this -> Discount ) / 100 ) * $ this -> TaxRate ; } return $ amount ; } | Find the tax cost for one instance of this item . |
27,168 | public function getTotalTax ( ) { $ amount = 0 ; if ( $ this -> Price && $ this -> TaxRate && $ this -> Quantity ) { $ amount = ( ( ( $ this -> Price * $ this -> Quantity ) - $ this -> Discount ) / 100 ) * $ this -> TaxRate ; } return $ amount ; } | Find the tax cost for all of the items in this line . |
27,169 | public function checkStockLevel ( $ qty ) { $ stock_param = $ this -> config ( ) -> stock_param ; $ item = $ this -> FindStockItem ( ) ; $ stock = ( $ item -> $ stock_param ) ? $ item -> $ stock_param : 0 ; if ( $ stock < $ qty ) { throw new ValidationException ( _t ( "Checkout.NotEnoughStock" , "There are not enough '{title}' in stock" , "Message to show that an item hasn't got enough stock" , array ( 'title' => $ item -> Title ) ) ) ; } } | Check stock levels for this item . |
27,170 | public function upload ( $ destination , array $ files ) { foreach ( $ files as $ file ) { if ( ! ( $ file instanceof FileEntity ) ) { throw new LogicException ( sprintf ( 'Each file entity must be an instance of \Krystal\Http\FileTransfer\FileInfoInterface, but received "%s"' , gettype ( $ file ) ) ) ; } if ( $ file -> getError ( ) == \ UPLOAD_ERR_OK ) { if ( ! $ this -> move ( $ destination , $ file -> getTmpName ( ) , $ file -> getUniqueName ( ) ) ) { return false ; } } else { return false ; } } return true ; } | Upload files from the input |
27,171 | private function move ( $ destination , $ tmp , $ filename ) { if ( ! is_dir ( $ destination ) ) { if ( $ this -> destinationAutoCreate === true ) { @ mkdir ( $ destination , 0777 , true ) ; } else { throw new RuntimeException ( sprintf ( 'Destination folder does not exist' , $ destination ) ) ; } } $ target = sprintf ( '%s/%s' , $ destination , $ filename ) ; if ( is_file ( $ target ) ) { if ( ! $ this -> override ) { return true ; } } return move_uploaded_file ( $ tmp , $ target ) ; } | Moves a singular file |
27,172 | public function quoteIdentifier ( $ value ) { if ( $ value instanceof Expr ) { return $ value -> getValue ( ) ; } if ( $ value === '*' ) { return $ value ; } $ pieces = explode ( '.' , $ value ) ; foreach ( $ pieces as $ key => $ piece ) { $ pieces [ $ key ] = '`' . $ piece . '`' ; } return implode ( '.' , $ pieces ) ; } | Wraps the input with identifiers when necessary . |
27,173 | public function quote ( $ value ) { switch ( true ) { case $ value === null : return 'null' ; case $ value === true : return '1' ; case $ value === false : return '0' ; case $ value instanceof Expr : return $ value -> getValue ( ) ; case is_int ( $ value ) || ctype_digit ( $ value ) : return ( int ) $ value ; case is_float ( $ value ) : return sprintf ( '%F' , $ value ) ; case is_array ( $ value ) : if ( ! count ( $ value ) ) { return '()' ; } return '(' . implode ( ',' , $ this -> quoteArr ( $ value ) ) . ')' ; } return $ this -> conn -> quote ( $ value ) ; } | Adds quotes around values when necessary . Based on FuelPHP s quoting function . |
27,174 | protected function setValueMap ( array $ map ) { $ lower = array_change_key_case ( $ map ) ; $ this -> caseSensitive = count ( $ lower ) !== count ( $ map ) ; $ this -> valueMap = $ this -> caseSensitive ? $ map : $ lower ; } | Sets the value map and determines if it s case sensitive . |
27,175 | public function resolveReferences ( stdClass $ schema , Uri $ uri ) { $ this -> resolver -> initialize ( $ schema , $ uri ) ; return $ this -> doResolveReferences ( $ schema , $ uri ) ; } | Recursively resolves JSON pointer references within a given schema . |
27,176 | public function applyConstraints ( $ instance , stdClass $ schema , Context $ context ) { $ cacheKey = gettype ( $ instance ) . spl_object_hash ( $ schema ) ; $ constraints = & $ this -> constraintsCache [ $ cacheKey ] ; if ( $ constraints === null ) { $ version = $ this -> getVersion ( $ schema ) ; $ instanceType = Types :: getPrimitiveTypeOf ( $ instance ) ; $ constraints = $ this -> registry -> getConstraintsForType ( $ version , $ instanceType ) ; $ constraints = $ this -> filterConstraintsForSchema ( $ constraints , $ schema ) ; } foreach ( $ constraints as $ constraint ) { $ constraint -> apply ( $ instance , $ schema , $ context , $ this ) ; } } | Validates an instance against a given schema populating a context with encountered violations . |
27,177 | private function isProcessed ( stdClass $ schema , SplObjectStorage $ storage ) { if ( $ storage -> contains ( $ schema ) ) { return true ; } $ storage -> attach ( $ schema ) ; return false ; } | Returns whether a schema has already been processed and stored in a given collection . This acts as an infinite recursion check . |
27,178 | private function filterConstraintsForSchema ( array $ constraints , stdClass $ schema ) { $ filtered = [ ] ; foreach ( $ constraints as $ constraint ) { foreach ( $ constraint -> keywords ( ) as $ keyword ) { if ( property_exists ( $ schema , $ keyword ) ) { $ filtered [ ] = $ constraint ; break ; } } } return $ filtered ; } | Filters constraints which should be triggered for given schema . |
27,179 | private function createUniqueNumericSlug ( $ slug ) { if ( $ this -> isNumericSlug ( $ slug ) ) { $ number = substr ( $ slug , - 1 , 1 ) ; $ number ++ ; $ string = substr ( $ slug , 0 , strlen ( $ slug ) - 1 ) . $ number ; return $ string ; } else { return $ slug ; } } | Creates unique slug |
27,180 | public function getUniqueSlug ( $ callback , $ slug , array $ args = array ( ) ) { if ( ! is_callable ( $ callback ) ) { throw new InvalidArgumentException ( sprintf ( 'First argument must be callable, received "%s"' , gettype ( $ callback ) ) ) ; } $ count = 0 ; while ( true ) { $ count ++ ; if ( call_user_func_array ( $ callback , array_merge ( array ( $ slug ) , $ args ) ) ) { if ( ! $ this -> isNumericSlug ( $ slug ) ) { $ slug = sprintf ( '%s-%s' , $ slug , $ count ) ; } else { $ slug = $ this -> createUniqueNumericSlug ( $ slug ) ; } } else { break ; } } return $ slug ; } | Returns unique slug |
27,181 | public function generate ( $ string ) { if ( $ this -> romanization === true ) { $ string = $ this -> romanize ( $ string ) ; } $ string = $ this -> lowercase ( $ string ) ; $ string = $ this -> removeUndesiredChars ( $ string ) ; $ string = $ this -> trim ( $ string ) ; $ string = $ this -> replaceWt ( $ string ) ; $ string = $ this -> removeExtraDashes ( $ string ) ; return $ string ; } | Generates a slug |
27,182 | public function init ( array $ options = array ( ) ) { $ this -> ch = curl_init ( ) ; if ( ! empty ( $ options ) ) { $ this -> setOptions ( $ options ) ; } } | Inits the cURL |
27,183 | public function exec ( ) { $ result = curl_exec ( $ this -> ch ) ; if ( $ result === false ) { $ this -> appendError ( ) ; return false ; } else { return $ result ; } } | Perform a cURL session This method should be called after initializing a cURL session and all the options for the session are set . |
27,184 | private function appendError ( ) { $ this -> errors [ ( string ) curl_errno ( $ this -> ch ) ] = curl_error ( $ this -> ch ) ; } | Appends an error with its own code |
27,185 | private static function getMonthSequence ( array $ months , $ target , $ withCurrent ) { if ( ! in_array ( $ target , $ months ) ) { throw new LogicException ( sprintf ( 'Target month "%s" is out of range. The range must be from 01 up to 12' , $ target ) ) ; } $ collection = array ( ) ; foreach ( $ months as $ month ) { if ( $ month == $ target ) { if ( $ withCurrent === true ) { $ collection [ ] = $ month ; } break ; } else { $ collection [ ] = $ month ; } } return $ collection ; } | Returns months sequence |
27,186 | public static function getPreviousMonths ( $ target , $ withCurrent = true ) { return self :: getMonthSequence ( array_keys ( self :: getMonths ( ) ) , $ target , $ withCurrent ) ; } | Returns a collection of previous months |
27,187 | public static function getNextMonths ( $ target , $ withCurrent = true ) { $ months = array_keys ( self :: getMonths ( ) ) ; $ months = array_reverse ( $ months ) ; $ result = self :: getMonthSequence ( $ months , $ target , $ withCurrent ) ; return array_reverse ( $ result ) ; } | Returns a collection of next months |
27,188 | public static function getAllMonthsByQuarter ( $ quarter ) { switch ( $ quarter ) { case 1 : return self :: getMonthsByQuarter ( 1 ) ; case 2 : return array_merge ( self :: getMonthsByQuarter ( 1 ) , self :: getMonthsByQuarter ( 2 ) ) ; case 3 : return array_merge ( self :: getMonthsByQuarter ( 1 ) , self :: getMonthsByQuarter ( 2 ) , self :: getMonthsByQuarter ( 3 ) ) ; case 4 : return array_merge ( self :: getMonthsByQuarter ( 1 ) , self :: getMonthsByQuarter ( 2 ) , self :: getMonthsByQuarter ( 3 ) , self :: getMonthsByQuarter ( 4 ) ) ; default : throw new LogicException ( sprintf ( 'Invalid quarter supplied - %s' , $ quarter ) ) ; } } | Returns a collection of months by associated quarter |
27,189 | public static function getQuarter ( $ month = null ) { if ( $ month === null ) { $ month = date ( 'n' , abs ( time ( ) ) ) ; } if ( in_array ( $ month , range ( 1 , 3 ) ) ) { return 1 ; } if ( in_array ( $ month , range ( 4 , 6 ) ) ) { return 2 ; } if ( in_array ( $ month , range ( 7 , 9 ) ) ) { return 3 ; } if ( in_array ( $ month , range ( 10 , 12 ) ) ) { return 4 ; } } | Returns current quarter |
27,190 | public function getEncoderForType ( string $ type ) : IEncoder { $ normalizedType = self :: normalizeType ( $ type ) ; if ( isset ( $ this -> encodersByType [ $ normalizedType ] ) ) { return $ this -> encodersByType [ $ normalizedType ] ; } if ( class_exists ( $ type ) ) { if ( $ this -> defaultObjectEncoder === null ) { throw new OutOfBoundsException ( 'No default object encoder is registered' ) ; } return $ this -> defaultObjectEncoder ; } if ( $ this -> defaultScalarEncoder === null ) { throw new OutOfBoundsException ( 'No default scalar encoder is registered' ) ; } return $ this -> defaultScalarEncoder ; } | Gets the encoder for a type |
27,191 | public function registerEncoder ( string $ type , IEncoder $ encoder ) : void { $ normalizedType = self :: normalizeType ( $ type ) ; $ this -> encodersByType [ $ normalizedType ] = $ encoder ; } | Registers an encoder |
27,192 | public function setDisclosure ( string $ disclosure ) : SecurityTxt { if ( ! $ this -> validDisclosure ( $ disclosure ) ) { throw new Exception ( 'Disclosure policy must be either "full", "partial", or "none".' ) ; } $ this -> disclosure = $ disclosure ; return $ this ; } | Set the disclosure policy . |
27,193 | public function isPortOpenRepeater ( $ seconds = 15 ) { $ start = time ( ) ; $ instance = $ this -> getPingInstance ( ) ; do { $ current = time ( ) - $ start ; $ latency = $ instance -> ping ( 'fsockopen' ) ; if ( $ latency !== false ) { return true ; } } while ( $ current <= $ seconds ) ; return false ; } | Check if the host port is opened within a timeframe . |
27,194 | protected function getPingInstance ( ) { if ( empty ( $ this -> port ) ) { throw new \ InvalidArgumentException ( 'Missing host port, ensure you called setPort().' ) ; } $ instance = $ this -> createPing ( ) ; $ instance -> setPort ( $ this -> port ) ; return $ instance ; } | Get the ping instance . |
27,195 | protected function createPing ( ) { if ( ! isset ( $ this -> host ) ) { throw new \ InvalidArgumentException ( 'Missing hostname, unable to conduct a ping request.' ) ; } return new Ping ( $ this -> host , $ this -> ttl , $ this -> timeout ) ; } | Create a ping instance . |
27,196 | public function getUser ( ) { $ info = $ this -> gitHubUserAuth ( ) -> getStoreData ( ) ; $ user = isset ( $ info [ 'user' ] ) ? $ info [ 'user' ] : getenv ( 'PROJECTX_GITHUB_USER' ) ? : null ; if ( ! isset ( $ user ) ) { throw new \ RuntimeException ( "GitHub authentication user is required. \r\n\n " . '[info] Run vendor/bin/project-x github::auth to get started.' ) ; } return $ user ; } | Get GitHub authentication user . |
27,197 | public function getToken ( ) { $ info = $ this -> gitHubUserAuth ( ) -> getStoreData ( ) ; $ token = isset ( $ info [ 'token' ] ) ? $ info [ 'token' ] : getenv ( 'PROJECTX_GITHUB_TOKEN' ) ? : null ; if ( ! isset ( $ token ) ) { throw new \ RuntimeException ( "GitHub user authentication token is required. \r\n\n " . '[info] Run vendor/bin/project-x github::auth to get started.' ) ; } return $ token ; } | Get GitHub user authentication token . |
27,198 | public function getGitHubUrlInfo ( ) { $ info = $ this -> getGithubInfo ( ) ; if ( isset ( $ info [ 'url' ] ) ) { $ matches = [ ] ; $ pattern = '/(?:https?:\/\/github.com\/|git\@.+\:)([\w\/\-\_]+)/' ; if ( preg_match ( $ pattern , $ info [ 'url' ] , $ matches ) ) { list ( $ account , $ repo ) = explode ( DIRECTORY_SEPARATOR , $ matches [ 1 ] ) ; return [ 'account' => $ account , 'repository' => $ repo , ] ; } } return [ ] ; } | Get GitHub information for URL . |
27,199 | protected function hasGitFlow ( ) { $ config = $ this -> gitConfig ( ) ; if ( isset ( $ config [ 'gitflow prefix' ] ) && ! empty ( $ config [ 'gitflow prefix' ] ) ) { return true ; } return false ; } | Has Git - flow enabled . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.