idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
58,900
|
protected function createPDOMySQL ( $ location , $ database , $ username , $ password , $ errorMode , $ charset ) { $ dsn = 'mysql:host=' . $ location . ';dbname=' . $ database ; if ( $ charset !== null ) { $ dsn .= ';charset=' . $ charset ; } $ db = new \ Parable \ ORM \ Database \ PDOMySQL ( $ dsn , $ username , $ password ) ; $ db -> setAttribute ( \ PDO :: ATTR_ERRMODE , $ errorMode ) ; return $ db ; }
|
Create and return a MySQL PDO instance .
|
58,901
|
public function setConfig ( array $ config ) { foreach ( $ config as $ type => $ value ) { $ property = ucwords ( str_replace ( '-' , ' ' , $ type ) ) ; $ property = lcfirst ( str_replace ( ' ' , '' , $ property ) ) ; $ method = 'set' . ucfirst ( $ property ) ; if ( method_exists ( $ this , $ method ) ) { $ this -> { $ method } ( $ value ) ; } else { throw new \ Parable \ ORM \ Exception ( "Tried to set non-existing property '{$property}' with value '{$value}' on " . get_class ( $ this ) ) ; } } return $ this ; }
|
Use an array to pass multiple config values at the same time . The values must correspond to setters defined on this class . If not an exception is thrown .
|
58,902
|
public function success ( Request $ request ) { $ user = $ this -> getUser4Id ( $ request -> getUserId ( ) ) ; if ( ! $ user ) { throw new InValidUserException ( 'User not found' ) ; } if ( $ this -> isStatusSuccess ( $ request ) && $ this -> isDonateAlreadyAdded ( $ request ) ) { throw new AlreadyAddedException ( 'already added' ) ; } $ request -> setAmount ( abs ( $ request -> getAmount ( ) ) ) ; $ coins = $ this -> isStatusSuccess ( $ request ) ? $ request -> getAmount ( ) : - $ request -> getAmount ( ) ; $ request -> setAmount ( $ this -> paymentNotifyCoins -> getAmount ( $ user , ( int ) $ coins ) ) ; $ errorMessage = '' ; $ throwable = null ; try { $ this -> coinService -> addCoins ( $ user , $ request -> getAmount ( ) ) ; } catch ( Throwable $ throwable ) { $ request -> setStatus ( $ request :: STATUS_ERROR ) ; $ errorMessage = $ throwable -> getMessage ( ) ; } if ( $ request -> isReasonToBan ( ) ) { $ expire = ( int ) $ this -> collectionOptions -> getConfig ( ) [ 'payment-api' ] [ 'ban-time' ] + time ( ) ; $ reason = 'Donate - ChargeBack' ; $ this -> userBlockService -> blockUser ( $ user , $ expire , $ reason ) ; } $ this -> saveDonateLog ( $ request , $ user , $ errorMessage ) ; if ( null !== $ throwable ) { throw $ throwable ; } return true ; }
|
Method the add the reward
|
58,903
|
protected function mapPaymentProvider2DonateType ( Request $ request ) { $ result = '' ; switch ( $ request -> getProvider ( ) ) { case Request :: PROVIDER_PAYMENT_WALL : $ result = DonateLog :: TYPE_PAYMENT_WALL ; break ; case Request :: PROVIDER_SUPER_REWARD : $ result = DonateLog :: TYPE_SUPER_REWARD ; break ; case Request :: PROVIDER_XSOLLA : $ result = DonateLog :: TYPE_XSOLLA ; break ; case Request :: PROVIDER_PAY_PAL : $ result = DonateLog :: TYPE_PAY_PAL ; break ; case Request :: PROVIDER_SOFORT : $ result = DonateLog :: TYPE_SOFORT ; break ; } return $ result ; }
|
Helper to map the PaymentProvider 2 DonateType
|
58,904
|
protected function isDonateAlreadyAdded ( Request $ request ) { $ donateEntity = $ this -> entityManager -> getRepository ( $ this -> collectionOptions -> getEntityOptions ( ) -> getDonateLog ( ) ) ; return $ donateEntity -> isDonateAlreadyAdded ( $ request -> getTransactionId ( ) , $ this -> mapPaymentProvider2DonateType ( $ request ) ) ; }
|
check is donate already added if the provider ask more than 1 time this only works with a transactionId
|
58,905
|
public function generate ( string $ subject , string $ status , string $ color , string $ format ) { $ badge = new Badge ( $ subject , $ status , $ color , $ format ) ; return $ this -> getRendererForFormat ( $ badge -> getFormat ( ) ) -> render ( $ badge ) ; }
|
Generates a badge .
|
58,906
|
public function generateFromString ( string $ string ) { $ badge = Badge :: fromString ( $ string ) ; return $ this -> getRendererForFormat ( $ badge -> getFormat ( ) ) -> render ( $ badge ) ; }
|
Generates a badge from a string .
|
58,907
|
protected function addRenderFormat ( RenderInterface $ renderer ) { foreach ( $ renderer -> getSupportedFormats ( ) as $ format ) { $ this -> renderers [ $ format ] = $ renderer ; } }
|
Adds each renderer to its supported format .
|
58,908
|
protected function getRendererForFormat ( string $ format ) { if ( ! isset ( $ this -> renderers [ $ format ] ) ) { throw new InvalidRendererException ( 'No renders found for the given format: ' . $ format ) ; } return $ this -> renderers [ $ format ] ; }
|
Returns the renderer for the given format .
|
58,909
|
public function load ( $ class ) { $ path = str_replace ( '\\' , DS , $ class ) ; $ path = '##replace##/' . trim ( $ path , DS ) . '.php' ; $ path = str_replace ( '/' , DS , $ path ) ; foreach ( $ this -> getLocations ( ) as $ subPath ) { $ actualPath = str_replace ( '##replace##' , $ subPath , $ path ) ; if ( file_exists ( $ actualPath ) ) { require_once $ actualPath ; return true ; } } return false ; }
|
Attempts to load the class if it exists .
|
58,910
|
public function setHttpCode ( $ httpCode ) { if ( ! array_key_exists ( $ httpCode , $ this -> httpCodes ) ) { throw new \ Parable \ Http \ Exception ( "Invalid HTTP code set: '{$httpCode}'" ) ; } $ this -> httpCode = $ httpCode ; return $ this ; }
|
Set the HTTP code to set when the response is sent .
|
58,911
|
public function setOutput ( \ Parable \ Http \ Output \ OutputInterface $ output ) { $ this -> output = $ output ; $ this -> output -> init ( $ this ) ; return $ this ; }
|
Set the output class to use and initialize it with the current response state .
|
58,912
|
public function prependContent ( $ content ) { if ( ! empty ( $ content ) ) { if ( is_array ( $ this -> content ) ) { array_unshift ( $ this -> content , $ content ) ; } else { $ this -> content = $ content . $ this -> content ; } } return $ this ; }
|
Prepend content to the currently set content whether it s currently array or string data .
|
58,913
|
public function appendContent ( $ content ) { if ( ! empty ( $ content ) ) { if ( is_array ( $ this -> content ) ) { $ this -> content [ ] = $ content ; } else { $ this -> content .= $ content ; } } return $ this ; }
|
Append content to the currently set content whether it s currently array or string data .
|
58,914
|
public function returnAllOutputBuffers ( ) { $ content = '' ; if ( $ this -> isOutputBufferingEnabled ( ) ) { while ( $ this -> isOutputBufferingEnabled ( ) ) { $ content .= $ this -> returnOutputBuffer ( ) ; } } return $ content ; }
|
Return all open output buffering levels currently open .
|
58,915
|
public function removeHeader ( $ key ) { if ( isset ( $ this -> headers [ $ key ] ) ) { unset ( $ this -> headers [ $ key ] ) ; } return $ this ; }
|
Remove a header by key .
|
58,916
|
public function send ( ) { $ buffered_content = $ this -> returnAllOutputBuffers ( ) ; if ( ! empty ( $ buffered_content ) && is_string ( $ this -> content ) ) { $ this -> content = $ buffered_content . $ this -> content ; } $ this -> content = $ this -> output -> prepare ( $ this ) ; if ( ! is_string ( $ this -> content ) && $ this -> content !== null ) { $ output = get_class ( $ this -> output ) ; throw new \ Parable \ Http \ Exception ( "Output class '{$output}' did not result in string or null content." ) ; } if ( ! headers_sent ( ) ) { header ( "{$this->request->getProtocol()} {$this->getHttpCode()} {$this->getHttpCodeText()}" ) ; header ( "Content-type: {$this->getContentType()}" ) ; foreach ( $ this -> getHeaders ( ) as $ key => $ value ) { header ( "{$key}: {$value}" ) ; } } if ( $ this -> isHeaderAndFooterContentEnabled ( ) ) { echo $ this -> getHeaderContent ( ) ; } echo $ this -> getContent ( ) ; if ( $ this -> isHeaderAndFooterContentEnabled ( ) ) { echo $ this -> getFooterContent ( ) ; } $ this -> terminate ( ) ; }
|
Build and send the response .
|
58,917
|
public function getDir ( $ directory ) { $ directory = str_replace ( '/' , DS , $ directory ) ; if ( strpos ( $ directory , $ this -> getBaseDir ( ) ) === false || ! file_exists ( $ directory ) ) { $ directory = $ this -> getBaseDir ( ) . DS . ltrim ( $ directory , DS ) ; } return $ directory ; }
|
Return dir based on the base dir .
|
58,918
|
public function addRight ( $ name ) { $ rights = $ this -> getRights ( ) ; if ( count ( $ rights ) === 0 ) { $ value = 1 ; } else { $ value = 2 * end ( $ rights ) ; } $ this -> rights [ $ name ] = $ value ; return $ this ; }
|
Add a right to the list . The correct value is calculated automatically .
|
58,919
|
public function getRight ( $ name ) { if ( ! isset ( $ this -> rights [ $ name ] ) ) { return false ; } return $ this -> rights [ $ name ] ; }
|
Return a specific right by name .
|
58,920
|
public function run ( ) { if ( ! $ this -> initialized ) { $ this -> initialize ( ) ; } $ currentUrl = $ this -> toolkit -> getCurrentUrl ( ) ; $ currentFullUrl = $ this -> toolkit -> getCurrentUrlFull ( ) ; $ this -> hook -> trigger ( self :: HOOK_ROUTE_MATCH_BEFORE , $ currentUrl ) ; $ route = $ this -> router -> matchUrl ( $ currentUrl ) ; $ this -> hook -> trigger ( self :: HOOK_ROUTE_MATCH_AFTER , $ route ) ; if ( $ route ) { $ this -> dispatchRoute ( $ route ) ; } else { $ this -> response -> setHttpCode ( 404 ) ; $ this -> hook -> trigger ( self :: HOOK_HTTP_404 , $ currentFullUrl ) ; } $ this -> loadLayout ( ) ; $ this -> hook -> trigger ( self :: HOOK_RESPONSE_SEND ) ; $ this -> response -> send ( ) ; return $ this ; }
|
Do all the setup and then attempt to match and dispatch the current url .
|
58,921
|
public function initialize ( ) { if ( $ this -> initialized ) { throw new \ Parable \ Framework \ Exception ( "App has already been initialized." ) ; } $ this -> packageManager -> registerPackages ( ) ; $ this -> loadConfig ( ) ; if ( $ this -> config -> get ( 'parable.debug' ) === true ) { $ this -> setErrorReportingEnabled ( true ) ; } else { $ this -> setErrorReportingEnabled ( false ) ; } if ( $ this -> config -> get ( 'parable.session.auto-enable' ) !== false ) { $ this -> startSession ( ) ; } if ( $ this -> config -> get ( 'parable.database.type' ) ) { $ this -> loadDatabase ( ) ; } if ( $ this -> config -> get ( 'parable.app.homedir' ) ) { $ homedir = trim ( $ this -> config -> get ( 'parable.app.homedir' ) , DS ) ; $ this -> url -> setBasePath ( $ homedir ) ; } if ( $ this -> config -> get ( 'parable.inits' ) ) { $ this -> loadInits ( ) ; } if ( $ this -> config -> get ( 'parable.timezone' ) ) { date_default_timezone_set ( $ this -> config -> get ( 'parable.timezone' ) ) ; } $ this -> url -> buildBaseurl ( ) ; $ this -> loadRoutes ( ) ; $ this -> initialized = true ; return $ this ; }
|
Initialize the App to prepare it for being run .
|
58,922
|
public function setErrorReportingEnabled ( $ enabled ) { ini_set ( 'log_errors' , 1 ) ; if ( $ enabled ) { ini_set ( 'display_errors' , 1 ) ; error_reporting ( E_ALL ) ; } else { ini_set ( 'display_errors' , 0 ) ; error_reporting ( E_ALL | ~ E_DEPRECATED ) ; } $ this -> errorReportingEnabled = $ enabled ; return $ this ; }
|
Enable error reporting setting display_errors to on and reporting to E_ALL
|
58,923
|
protected function loadRoutes ( ) { $ this -> hook -> trigger ( self :: HOOK_LOAD_ROUTES_BEFORE ) ; if ( $ this -> config -> get ( 'parable.routes' ) ) { foreach ( $ this -> config -> get ( 'parable.routes' ) as $ routesClass ) { $ routes = \ Parable \ DI \ Container :: create ( $ routesClass ) ; if ( ! ( $ routes instanceof \ Parable \ Framework \ Routing \ AbstractRouting ) ) { throw new \ Parable \ Framework \ Exception ( "{$routesClass} does not extend \Parable\Framework\Routing\AbstractRouting" ) ; } $ routes -> load ( ) ; } } else { $ this -> hook -> trigger ( self :: HOOK_LOAD_ROUTES_NO_ROUTES_FOUND ) ; } $ this -> hook -> trigger ( self :: HOOK_LOAD_ROUTES_AFTER ) ; return $ this ; }
|
Load all the routes if possible .
|
58,924
|
protected function loadConfig ( ) { $ this -> hook -> trigger ( self :: HOOK_LOAD_CONFIG_BEFORE ) ; $ this -> config -> load ( ) ; $ this -> hook -> trigger ( self :: HOOK_LOAD_CONFIG_AFTER ) ; }
|
Load the config and trigger hooks .
|
58,925
|
protected function loadInits ( ) { $ this -> hook -> trigger ( self :: HOOK_LOAD_INITS_BEFORE ) ; if ( $ this -> config -> get ( 'parable.inits' ) ) { $ initLoader = \ Parable \ DI \ Container :: create ( \ Parable \ Framework \ Loader \ InitLoader :: class ) ; $ initLoader -> load ( $ this -> config -> get ( 'parable.inits' ) ) ; } $ this -> hook -> trigger ( self :: HOOK_LOAD_INITS_AFTER ) ; return $ this ; }
|
Create instances of given init classes .
|
58,926
|
protected function loadDatabase ( ) { $ this -> hook -> trigger ( self :: HOOK_INIT_DATABASE_BEFORE ) ; $ database = \ Parable \ DI \ Container :: get ( \ Parable \ ORM \ Database :: class ) ; $ database -> setConfig ( $ this -> config -> get ( 'parable.database' ) ) ; $ this -> hook -> trigger ( self :: HOOK_INIT_DATABASE_AFTER ) ; return $ this ; }
|
Initialize the database instance with data from the config .
|
58,927
|
public function get ( $ url , $ callable , $ name = null , $ templatePath = null ) { $ this -> multiple ( [ \ Parable \ Http \ Request :: METHOD_GET ] , $ url , $ callable , $ name , $ templatePath ) ; return $ this ; }
|
Add a GET route with a callable and optionally a templatePath .
|
58,928
|
public function post ( $ url , $ callable , $ name = null , $ templatePath = null ) { $ this -> multiple ( [ \ Parable \ Http \ Request :: METHOD_POST ] , $ url , $ callable , $ name , $ templatePath ) ; return $ this ; }
|
Add a POST route with a callable and optionally a templatePath .
|
58,929
|
public function put ( $ url , $ callable , $ name = null , $ templatePath = null ) { $ this -> multiple ( [ \ Parable \ Http \ Request :: METHOD_PUT ] , $ url , $ callable , $ name , $ templatePath ) ; return $ this ; }
|
Add a PUT route with a callable and optionally a templatePath .
|
58,930
|
public function patch ( $ url , $ callable , $ name = null , $ templatePath = null ) { $ this -> multiple ( [ \ Parable \ Http \ Request :: METHOD_PATCH ] , $ url , $ callable , $ name , $ templatePath ) ; return $ this ; }
|
Add a PATCH route with a callable and optionally a templatePath .
|
58,931
|
public function delete ( $ url , $ callable , $ name = null , $ templatePath = null ) { $ this -> multiple ( [ \ Parable \ Http \ Request :: METHOD_DELETE ] , $ url , $ callable , $ name , $ templatePath ) ; return $ this ; }
|
Add a DELETE route with a callable and optionally a templatePath .
|
58,932
|
public function options ( $ url , $ callable , $ name = null , $ templatePath = null ) { $ this -> multiple ( [ \ Parable \ Http \ Request :: METHOD_OPTIONS ] , $ url , $ callable , $ name , $ templatePath ) ; return $ this ; }
|
Add an OPTIONS route with a callable and optionally a templatePath .
|
58,933
|
public function prepare ( \ Parable \ Console \ App $ app , \ Parable \ Console \ Output $ output , \ Parable \ Console \ Input $ input , \ Parable \ Console \ Parameter $ parameter ) { $ this -> app = $ app ; $ this -> output = $ output ; $ this -> input = $ input ; $ this -> parameter = $ parameter ; return $ this ; }
|
Prepare the command setting all classes the command is dependant on .
|
58,934
|
public function addOption ( $ name , $ valueRequired = Parameter :: OPTION_VALUE_OPTIONAL , $ defaultValue = null , $ flagOption = false ) { $ this -> options [ $ name ] = new \ Parable \ Console \ Parameter \ Option ( $ name , $ valueRequired , $ defaultValue , $ flagOption ) ; return $ this ; }
|
Add an option for this command .
|
58,935
|
public function addArgument ( $ name , $ required = Parameter :: PARAMETER_OPTIONAL , $ defaultValue = null ) { $ this -> arguments [ ] = new \ Parable \ Console \ Parameter \ Argument ( $ name , $ required , $ defaultValue ) ; return $ this ; }
|
Add an argument for this command .
|
58,936
|
public function getUsage ( ) { $ string = [ ] ; $ string [ ] = $ this -> getName ( ) ; foreach ( $ this -> getArguments ( ) as $ argument ) { if ( $ argument -> isRequired ( ) ) { $ string [ ] = $ argument -> getName ( ) ; } else { $ string [ ] = "[{$argument->getName()}]" ; } } foreach ( $ this -> getOptions ( ) as $ option ) { $ dashes = '-' ; if ( ! $ option -> isFlagOption ( ) ) { $ dashes .= '-' ; } if ( $ option -> isValueRequired ( ) ) { $ optionString = "{$option->getName()}=value" ; } else { $ optionString = "{$option->getName()}[=value]" ; } $ string [ ] = "[{$dashes}{$optionString}]" ; } return implode ( ' ' , $ string ) ; }
|
Build a usage string out of the arguments and options set on the command . Is automatically called when an exception is caught by App .
|
58,937
|
public function run ( ) { $ callable = $ this -> getCallable ( ) ; if ( is_callable ( $ callable ) ) { return $ callable ( $ this -> app , $ this -> output , $ this -> input , $ this -> parameter ) ; } return false ; }
|
Run the callable if it s set . This can be overridden by implementing the run method on a Command class .
|
58,938
|
protected function runCommand ( \ Parable \ Console \ Command $ command , array $ parameters = [ ] ) { $ parameter = new \ Parable \ Console \ Parameter ( ) ; $ parameter -> setParameters ( $ parameters ) ; $ command -> prepare ( $ this -> app , $ this -> output , $ this -> input , $ parameter ) ; return $ command -> run ( ) ; }
|
Run another command from the current command passing parameters as an array .
|
58,939
|
public static function fromString ( string $ format ) { if ( preg_match ( '/^(([^-]|--)+)-(([^-]|--)+)-(([^-]|--)+)\.(svg|png|gif|jpg)$/' , $ format , $ match ) === false && ( 7 != count ( $ match ) ) ) { throw new InvalidArgumentException ( 'The given format string is invalid: ' . $ format ) ; } $ subject = $ match [ 1 ] ; $ status = $ match [ 3 ] ; $ color = $ match [ 5 ] ; $ format = $ match [ 7 ] ; return new self ( $ subject , $ status , $ color , $ format ) ; }
|
Generates a badge from a string format .
|
58,940
|
protected function getColorMapOrAsHex ( string $ color ) { return isset ( $ this -> colorMap [ $ color ] ) ? $ this -> colorMap [ $ color ] : $ color ; }
|
Check if the color is within the color map or return it as normal .
|
58,941
|
public static function setKeywordFormattingOptions ( array $ keywords ) { $ keyword_map = array ( self :: KEYWORD_NEWLINE => & self :: $ reserved_newline , self :: KEYWORD_TOPLEVEL => & self :: $ reserved_toplevel ) ; foreach ( $ keywords as $ keyword => $ type ) { if ( ! array_key_exists ( $ type , $ keyword_map ) ) { throw new \ InvalidArgumentException ( "Unexpected type '{$type}' : type must be a KEYWORD_* class constant" ) ; } foreach ( $ keyword_map as $ keyword_type => $ registered_keywords ) { if ( in_array ( $ keyword , $ registered_keywords ) ) { if ( $ type === $ keyword_type ) { continue ( 2 ) ; } $ keyword_map [ $ keyword_type ] = array_diff ( $ keyword_map [ $ keyword_type ] , array ( $ keyword ) ) ; } } $ keyword_map [ $ type ] [ ] = $ keyword ; } }
|
Sets the formatting options of the SQL keywords .
|
58,942
|
public function setWriter ( \ Parable \ Log \ Writer \ WriterInterface $ writer ) { $ this -> writer = $ writer ; return $ this ; }
|
Set a writer class to use .
|
58,943
|
public function write ( $ message ) { if ( ! $ this -> writer ) { throw new \ Parable \ Log \ Exception ( "Can't write without a valid \Log\Writer instance set." ) ; } $ message = $ this -> stringifyMessage ( $ message ) ; $ this -> writer -> write ( $ message ) ; return $ this ; }
|
Write a message to the log writer .
|
58,944
|
public function writeLines ( array $ messages ) { if ( ! $ this -> writer ) { throw new \ Parable \ Log \ Exception ( "Can't writeLines without a valid \Log\Writer instance set." ) ; } foreach ( $ messages as $ message ) { $ this -> write ( $ message ) ; } return $ this ; }
|
Write an array of messages to the log writer .
|
58,945
|
protected function stringifyMessage ( $ message ) { if ( is_array ( $ message ) || is_object ( $ message ) || is_bool ( $ message ) ) { return ( string ) var_export ( $ message , true ) ; } return ( string ) $ message ; }
|
Stringify a message so it can be written .
|
58,946
|
public function getDonateHistorySuccess ( \ DateTime $ dateTime ) { $ query = $ this -> createQueryBuilder ( 'p' ) -> select ( 'SUM(p.coins) as coins, p.type, COUNT(p.coins) as amount, p.created' ) -> where ( 'p.success = :success' ) -> setParameter ( 'success' , Entity :: STATUS_SUCCESS ) -> andWhere ( 'p.created >= :created' ) -> setParameter ( 'created' , $ dateTime ) -> groupBy ( 'p.type, p.created' ) -> orderBy ( 'p.created' , 'asc' ) -> getQuery ( ) ; return $ query -> getResult ( ) ; }
|
Group date does not realy work on different DBMS so we must do that in PHP
|
58,947
|
public function parseParameters ( ) { $ this -> reset ( ) ; $ this -> scriptName = array_shift ( $ this -> parameters ) ; foreach ( $ this -> parameters as $ parameter ) { $ optionString = ltrim ( $ parameter , '-' ) ; if ( substr ( $ parameter , 0 , 2 ) === "--" ) { $ this -> parseOption ( $ optionString ) ; } elseif ( substr ( $ parameter , 0 , 1 ) === "-" ) { $ this -> parseFlagOption ( $ optionString ) ; } else { $ this -> parseArgument ( $ parameter ) ; } } return $ this ; }
|
Split the parameters into script name command name options and arguments .
|
58,948
|
protected function parseArgument ( $ parameter ) { if ( $ this -> commandNameEnabled && ! $ this -> commandName ) { $ this -> commandName = $ parameter ; } else { $ this -> arguments [ ] = $ parameter ; } return $ this ; }
|
Parse argument . If no command name set and commands are enabled interpret as command name . Otherwise add to argument list .
|
58,949
|
public function setCommandOptions ( array $ options ) { foreach ( $ options as $ name => $ option ) { if ( ( ! $ option instanceof Parameter \ Option ) ) { throw new \ Parable \ Console \ Exception ( "Options must be instances of Parameter\\Option. {$name} is not." ) ; } $ this -> commandOptions [ $ option -> getName ( ) ] = $ option ; } return $ this ; }
|
Set the options from a command .
|
58,950
|
public function checkCommandOptions ( ) { foreach ( $ this -> commandOptions as $ option ) { if ( $ option -> isFlagOption ( ) ) { $ parameters = $ this -> flagOptions ; } else { $ parameters = $ this -> options ; } $ option -> addParameters ( $ parameters ) ; if ( $ option -> isValueRequired ( ) && $ option -> hasBeenProvided ( ) && ! $ option -> getValue ( ) ) { if ( $ option -> isFlagOption ( ) ) { $ message = "Option '-{$option->getName()}' requires a value, which is not provided." ; } else { $ message = "Option '--{$option->getName()}' requires a value, which is not provided." ; } throw new \ Parable \ Console \ Exception ( $ message ) ; } } }
|
Checks the options set against the parameters set . Takes into account whether an option is required to be passed or not or a value is required if it s passed or sets the defaultValue if given and necessary .
|
58,951
|
public function getOption ( $ name ) { if ( ! array_key_exists ( $ name , $ this -> commandOptions ) ) { return null ; } $ option = $ this -> commandOptions [ $ name ] ; if ( $ option -> hasBeenProvided ( ) && $ option -> getProvidedValue ( ) === null && $ option -> getDefaultValue ( ) === null ) { return true ; } return $ option -> getValue ( ) ; }
|
Returns null if the value doesn t exist . Otherwise it s whatever was passed to it or set as a default value .
|
58,952
|
public function getOptions ( ) { $ returnArray = [ ] ; foreach ( $ this -> commandOptions as $ option ) { $ returnArray [ $ option -> getName ( ) ] = $ this -> getOption ( $ option -> getName ( ) ) ; } return $ returnArray ; }
|
Return all option values .
|
58,953
|
public function setCommandArguments ( array $ arguments ) { $ orderedArguments = [ ] ; foreach ( $ arguments as $ index => $ argument ) { if ( ! ( $ argument instanceof Parameter \ Argument ) ) { throw new \ Parable \ Console \ Exception ( "Arguments must be instances of Parameter\\Argument. The item at index {$index} is not." ) ; } $ argument -> setOrder ( $ index ) ; $ orderedArguments [ $ index ] = $ argument ; } $ this -> commandArguments = $ orderedArguments ; return $ this ; }
|
Set the arguments from a command .
|
58,954
|
public function checkCommandArguments ( ) { foreach ( $ this -> commandArguments as $ index => $ argument ) { $ argument -> addParameters ( $ this -> arguments ) ; if ( $ argument -> isRequired ( ) && ! $ argument -> hasBeenProvided ( ) ) { throw new \ Parable \ Console \ Exception ( "Required argument with index #{$index} '{$argument->getName()}' not provided." ) ; } } }
|
Checks the arguments set against the parameters set . Takes into account whether an argument is required to be passed or not .
|
58,955
|
public function getArgument ( $ name ) { foreach ( $ this -> commandArguments as $ argument ) { if ( $ argument -> getName ( ) === $ name ) { return $ argument -> getValue ( ) ; } } return null ; }
|
Returns null if the value doesn t exist . Returns default value if set from command and the actual value if passed on the command line .
|
58,956
|
public function getArguments ( ) { $ returnArray = [ ] ; foreach ( $ this -> commandArguments as $ argument ) { $ returnArray [ $ argument -> getName ( ) ] = $ argument -> getValue ( ) ; } return $ returnArray ; }
|
Return all arguments passed .
|
58,957
|
protected function reset ( ) { $ this -> scriptName = null ; $ this -> commandName = null ; $ this -> options = [ ] ; $ this -> arguments = [ ] ; return $ this ; }
|
Reset the class to a fresh state .
|
58,958
|
public function enableCommandName ( ) { if ( ! $ this -> commandNameEnabled && $ this -> commandName && isset ( $ this -> arguments [ 0 ] ) && $ this -> arguments [ 0 ] === $ this -> commandName ) { unset ( $ this -> arguments [ 0 ] ) ; $ this -> arguments = array_values ( $ this -> arguments ) ; } $ this -> commandNameEnabled = true ; return $ this ; }
|
Remove the command name from the arguments if a command name is actually set .
|
58,959
|
public function disableCommandName ( ) { if ( $ this -> commandNameEnabled && $ this -> commandName ) { array_unshift ( $ this -> arguments , $ this -> commandName ) ; } $ this -> commandNameEnabled = false ; return $ this ; }
|
Add the command name to the arguments if a command name is set .
|
58,960
|
public function setJson ( $ key , $ value = null ) : void { if ( is_array ( $ key ) ) { foreach ( $ key as $ k => $ v ) { $ this -> setJson ( $ k , $ v ) ; } return ; } $ this -> _jsonData [ $ key ] = $ value ; }
|
Pass data to the frontend controller
|
58,961
|
public function addAppData ( string $ key , $ value = null ) : void { $ this -> _additionalAppData [ $ key ] = $ value ; }
|
Adds additional data to the appData
|
58,962
|
public function setBoth ( $ key , $ value = null ) : void { $ this -> _controller -> set ( $ key , $ value ) ; $ this -> setJson ( $ key , $ value ) ; }
|
Set a variable to both the frontend controller and the backend view
|
58,963
|
public function setValueType ( $ valueType ) { if ( ! in_array ( $ valueType , [ \ Parable \ Console \ Parameter :: OPTION_VALUE_REQUIRED , \ Parable \ Console \ Parameter :: OPTION_VALUE_OPTIONAL , ] ) ) { throw new \ Parable \ Console \ Exception ( 'Value type must be one of the OPTION_* constants.' ) ; } $ this -> valueType = $ valueType ; return $ this ; }
|
Set whether the option s value is required .
|
58,964
|
public function redirectToRoute ( $ routeName , array $ parameters = [ ] ) { $ url = $ this -> router -> getRouteUrlByName ( $ routeName , $ parameters ) ; if ( ! $ url ) { throw new \ Parable \ Framework \ Exception ( "Can't redirect to route, '{$routeName}' does not exist." ) ; } $ this -> response -> redirect ( $ this -> url -> getUrl ( $ url ) ) ; }
|
Redirect directly by using a route name .
|
58,965
|
protected function getLayout ( string $ layout = null ) : string { if ( $ layout === null ) { $ frontendBridgeComponentExists = isset ( $ this -> FrontendBridge ) ; $ layout = 'FrontendBridge.json_action' ; if ( $ frontendBridgeComponentExists ) { $ layout = $ this -> FrontendBridge -> config ( 'templatePaths.jsonAction' ) ; } if ( $ this -> request -> is ( 'dialog' ) ) { $ layout = 'FrontendBridge.dialog_action' ; if ( $ frontendBridgeComponentExists ) { $ layout = $ this -> FrontendBridge -> config ( 'templatePaths.dialogAction' ) ; } } } return $ layout ; }
|
Returns a layout to render .
|
58,966
|
protected function redirectJsonAction ( $ url ) : ServiceResponse { if ( is_array ( $ url ) ) { $ url = $ this -> prepareUrl ( $ url ) ; } $ response = [ 'code' => 'success' , 'data' => [ 'inDialog' => $ this -> request -> is ( 'dialog' ) && ! $ this -> FrontendBridge -> _closeDialog , 'redirect' => $ url ] ] ; return new ServiceResponse ( $ response ) ; }
|
Json action redirect
|
58,967
|
private function prepareUrl ( array $ url ) : array { $ pass = [ ] ; foreach ( $ url as $ key => $ value ) { if ( is_int ( $ key ) ) { $ pass [ $ key ] = $ value ; unset ( $ url [ $ key ] ) ; } } $ url [ 'pass' ] = $ pass ; return $ url ; }
|
Prepare a url array for the JS router
|
58,968
|
protected function renderSvg ( array $ params , $ format ) { $ template = file_get_contents ( $ this -> path . '/' . $ this -> getTemplate ( ) ) ; foreach ( $ params as $ key => $ param ) { $ template = str_replace ( sprintf ( '{{ %s }}' , $ key ) , $ param , $ template ) ; } return BadgeImage :: createFromString ( $ template , $ format ) ; }
|
Render the badge from the parameters and format given .
|
58,969
|
protected function registerClassesFromMagicProperties ( ) { $ reflection = new \ ReflectionClass ( self :: class ) ; $ docComment = $ reflection -> getDocComment ( ) ; $ magicProperties = $ docComment ? explode ( PHP_EOL , $ docComment ) : [ ] ; foreach ( $ magicProperties as $ magicProperty ) { if ( strpos ( $ magicProperty , '@property' ) === false ) { continue ; } $ partsString = trim ( str_replace ( '* @property' , '' , $ magicProperty ) ) ; $ parts = explode ( '$' , $ partsString ) ; list ( $ className , $ property ) = $ parts ; $ this -> registerClass ( trim ( $ property ) , trim ( $ className ) ) ; } return $ this ; }
|
For all the magic properties defined at the start of this class loop through them and add them to our list of magic properties .
|
58,970
|
public function registerClass ( $ property , $ className ) { $ className = '\\' . ltrim ( $ className , '\\' ) ; $ this -> classes [ $ property ] = $ className ; return $ this ; }
|
Register a class with the View for property lazy - loading .
|
58,971
|
public function partial ( $ templatePath ) { $ this -> response -> startOutputBuffer ( ) ; $ this -> loadTemplatePath ( $ templatePath ) ; return $ this -> response -> returnOutputBuffer ( ) ; }
|
Load a template path interpret it fully and then return the resulting output as a string .
|
58,972
|
protected function loadTemplatePath ( $ templatePath ) { $ templatePath = $ this -> path -> getDir ( $ templatePath ) ; if ( file_exists ( $ templatePath ) ) { require $ templatePath ; } return $ this ; }
|
Attempt to load the templatePath .
|
58,973
|
public function buildBaseUrl ( ) { $ domain = $ this -> request -> getScheme ( ) . '://' . $ this -> request -> getHttpHost ( ) ; $ url = $ this -> request -> getScriptName ( ) ; if ( $ this -> getBasePath ( ) ) { $ basePathPos = strpos ( $ url , $ this -> getBasePath ( ) ) ; if ( $ basePathPos !== false ) { $ url = substr_replace ( $ url , '' , $ basePathPos , strlen ( $ this -> getBasePath ( ) ) ) ; } } $ url = str_replace ( $ this -> getScriptName ( ) , '' , $ url ) ; $ this -> baseUrl = $ domain . '/' . ltrim ( $ url , '/' ) ; return $ this ; }
|
Build the correct baseUrl based on data from the request .
|
58,974
|
public function addMap ( $ pattern , $ controller ) { $ pattern = explode ( '/' , trim ( parse_url ( ( string ) $ pattern , PHP_URL_PATH ) , ' /' ) ) ; $ vars = array ( ) ; $ regex = array ( ) ; foreach ( $ pattern as $ segment ) { if ( $ segment == '*' ) { $ regex [ ] = '.*' ; } elseif ( $ segment [ 0 ] == '*' ) { $ vars [ ] = substr ( $ segment , 1 ) ; $ regex [ ] = '(.*)' ; } elseif ( $ segment [ 0 ] == '\\' && $ segment [ 1 ] == '*' ) { $ regex [ ] = '\*' . preg_quote ( substr ( $ segment , 2 ) ) ; } elseif ( $ segment == ':' ) { $ regex [ ] = '[^/]*' ; } elseif ( $ segment [ 0 ] == ':' ) { $ vars [ ] = substr ( $ segment , 1 ) ; $ regex [ ] = '([^/]*)' ; } elseif ( $ segment [ 0 ] == '\\' && $ segment [ 1 ] == ':' ) { $ regex [ ] = preg_quote ( substr ( $ segment , 1 ) ) ; } else { $ regex [ ] = preg_quote ( $ segment ) ; } } $ this -> maps [ ] = array ( 'regex' => \ chr ( 1 ) . '^' . implode ( '/' , $ regex ) . '$' . \ chr ( 1 ) , 'vars' => $ vars , 'controller' => ( string ) $ controller , ) ; return $ this ; }
|
Add a route map to the router . If the pattern already exists it will be overwritten .
|
58,975
|
public function addMaps ( $ maps ) { foreach ( $ maps as $ pattern => $ controller ) { $ this -> addMap ( $ pattern , $ controller ) ; } return $ this ; }
|
Add an array of route maps to the router . If the pattern already exists it will be overwritten .
|
58,976
|
protected function fetchController ( $ name ) { $ class = $ this -> controllerPrefix . ucfirst ( $ name ) ; if ( ! class_exists ( $ class ) ) { throw new \ RuntimeException ( sprintf ( 'Unable to locate controller `%s`.' , $ class ) , 404 ) ; } if ( ! is_subclass_of ( $ class , 'Joomla\\Controller\\ControllerInterface' ) ) { throw new \ RuntimeException ( sprintf ( 'Invalid Controller. Controllers must implement Joomla\Controller\ControllerInterface. `%s`.' , $ class ) , 500 ) ; } $ controller = new $ class ( $ this -> input ) ; return $ controller ; }
|
Get a Controller object for a given name .
|
58,977
|
public function run ( ) { if ( $ this -> app -> getName ( ) ) { $ this -> output -> writeln ( $ this -> app -> getName ( ) ) ; $ this -> output -> newline ( ) ; } $ commandName = $ this -> parameter -> getArgument ( 'command_name' ) ; if ( $ this -> parameter -> getCommandName ( ) === $ this -> name && $ commandName ) { $ this -> showCommandHelp ( $ this -> parameter -> getArgument ( 'command_name' ) ) ; } else { $ this -> showGeneralHelp ( ) ; } return $ this ; }
|
Show the names and descriptions of all commands set on the application at this moment .
|
58,978
|
protected function showGeneralHelp ( ) { $ this -> output -> writeln ( "<yellow>Available commands:</yellow>" ) ; $ longestName = 0 ; foreach ( $ this -> app -> getCommands ( ) as $ command ) { $ strlen = strlen ( $ command -> getName ( ) ) ; if ( $ strlen > $ longestName ) { $ longestName = $ strlen ; } } foreach ( $ this -> app -> getCommands ( ) as $ command ) { $ name = $ command -> getName ( ) ; $ this -> output -> write ( str_pad ( " <green>{$name}</green>" , $ longestName + 22 , ' ' , STR_PAD_RIGHT ) ) ; $ this -> output -> write ( "{$command->getDescription()}" ) ; $ this -> output -> newline ( ) ; } }
|
Show information about all commands .
|
58,979
|
protected function showCommandHelp ( $ commandName ) { $ command = $ this -> app -> getCommand ( $ commandName ) ; if ( ! $ command ) { $ this -> output -> writeln ( "<red>Unknown command:</red> {$commandName}" ) ; return ; } if ( $ command -> getDescription ( ) ) { $ this -> output -> writeln ( "<yellow>Description:</yellow>" ) ; $ this -> output -> writeln ( " {$command->getDescription()}" ) ; $ this -> output -> newline ( ) ; } $ this -> output -> writeln ( "<yellow>Usage:</yellow>" ) ; $ this -> output -> writeln ( " {$command->getUsage()}" ) ; }
|
Show the usage and description for a specific command .
|
58,980
|
public function blockUser ( UserInterface $ user , $ expire , $ reason , $ creator = null ) { $ class = $ this -> entityOptions -> getUserBlock ( ) ; $ userBlock = new $ class ; $ userBlock -> setUser ( $ user ) ; $ userBlock -> setCreator ( $ creator ) ; $ userBlock -> setReason ( $ reason ) ; $ userBlock -> setExpire ( $ expire ) ; $ this -> blockUserWithEntity ( $ userBlock ) ; }
|
We want to block a user
|
58,981
|
public function calculateWidth ( string $ text , int $ size = null ) { $ size = round ( ( $ size ? : static :: TEXT_SIZE ) * 0.75 , 1 ) ; $ box = imagettfbbox ( $ size , 0 , $ this -> path , $ text ) ; return round ( abs ( $ box [ 2 ] - $ box [ 0 ] ) + static :: SHIELD_PADDING_EXTERNAL + static :: SHIELD_PADDING_INTERNAL , 1 ) ; }
|
Calculate the width of the text box .
|
58,982
|
public function getHidden ( ) { if ( strtoupper ( substr ( PHP_OS , 0 , 3 ) ) === 'WIN' ) { throw new \ Parable \ Console \ Exception ( "Hidden input is not supported on windows." ) ; } $ this -> disableShowInput ( ) ; $ input = $ this -> get ( ) ; $ this -> enableShowInput ( ) ; return $ input ; }
|
Request input from the user while hiding the actual input . Use this to request passwords for example .
|
58,983
|
protected function readFromSession ( ) { if ( is_array ( $ this -> session -> get ( self :: SESSION_KEY ) ) ) { $ this -> messages = $ this -> session -> get ( self :: SESSION_KEY ) ; } return $ this ; }
|
Read messages stored in the session and load them into SessionMessage .
|
58,984
|
public function setMainConfigClassName ( $ className ) { if ( ! class_exists ( $ className ) ) { throw new \ Parable \ Framework \ Exception ( "Main Config class '{$className}' does not exist." ) ; } $ this -> mainConfigClass = $ className ; return $ this ; }
|
Set the main config name to use .
|
58,985
|
public function load ( ) { try { $ this -> addConfig ( \ Parable \ DI \ Container :: get ( $ this -> mainConfigClass ) ) ; } catch ( \ Exception $ e ) { return $ this ; } if ( $ this -> get ( 'parable.configs' ) ) { foreach ( $ this -> get ( 'parable.configs' ) as $ configClass ) { $ this -> addConfig ( \ Parable \ DI \ Container :: get ( $ configClass ) ) ; } } return $ this ; }
|
Load the main config and load all its values . If there are any child configs defined under parable . configs load all of those too .
|
58,986
|
public function addConfig ( \ Parable \ Framework \ Interfaces \ Config $ config ) { $ this -> setMany ( $ config -> get ( ) ) ; return $ this ; }
|
Add a config and load all of its values .
|
58,987
|
public function write ( $ string ) { $ string = $ this -> parseTags ( $ string ) ; $ this -> enableClearLine ( ) ; echo $ string ; return $ this ; }
|
Write a string to the console and make sure clear line is enabled .
|
58,988
|
public function getTerminalWidth ( ) { if ( $ this -> isInteractiveShell ( ) || ( strtoupper ( substr ( PHP_OS , 0 , 3 ) ) === 'WIN' && getenv ( 'shell' ) ) ) { return ( int ) shell_exec ( 'tput cols' ) ; } return self :: TERMINAL_DEFAULT_WIDTH ; }
|
Return the terminal width . If not an interactive shell return default .
|
58,989
|
public function getTerminalHeight ( ) { if ( $ this -> isInteractiveShell ( ) || ( strtoupper ( substr ( PHP_OS , 0 , 3 ) ) === 'WIN' && getenv ( 'shell' ) ) ) { return ( int ) shell_exec ( 'tput lines' ) ; } return self :: TERMINAL_DEFAULT_HEIGHT ; }
|
Return the terminal height . If not an interactive shell return default .
|
58,990
|
public function writeln ( $ lines ) { if ( ! is_array ( $ lines ) ) { $ lines = [ $ lines ] ; } foreach ( $ lines as $ line ) { $ this -> write ( $ line ) ; $ this -> newline ( ) ; } return $ this ; }
|
Write a line or array of lines to the console . This will always end in a newline .
|
58,991
|
public function clearLine ( ) { if ( ! $ this -> isClearLineEnabled ( ) ) { return $ this ; } $ this -> cursorReset ( ) ; $ this -> write ( str_repeat ( ' ' , $ this -> getTerminalWidth ( ) ) ) ; $ this -> cursorReset ( ) ; $ this -> disableClearLine ( ) ; return $ this ; }
|
Clear the line based on the terminal width and disable clear line .
|
58,992
|
public function parseTags ( $ string ) { foreach ( $ this -> tags as $ tag => $ code ) { if ( strpos ( $ string , "<{$tag}>" ) !== false || strpos ( $ string , "</{$tag}>" ) !== false ) { $ string = str_replace ( "<{$tag}>" , $ code , $ string ) ; $ string = str_replace ( "</{$tag}>" , $ this -> tags [ 'default' ] , $ string ) ; } } return $ string . $ this -> tags [ 'default' ] ; }
|
Parse tags in a string to turn them into bash escape codes .
|
58,993
|
public function delete ( $ route ) { if ( file_exists ( $ this -> getRouteCachePath ( $ route ) ) ) { unlink ( $ this -> getRouteCachePath ( $ route ) ) ; } }
|
Removes the cache for a given route
|
58,994
|
public function deleteAll ( ) { foreach ( scandir ( $ this -> directory ) as $ file ) { if ( ! in_array ( $ file , [ '.' , '..' , 'keep' ] ) ) { unlink ( $ this -> directory . '/' . $ file ) ; } } }
|
Removes all cache entries
|
58,995
|
public function render ( Badge $ badge ) { $ subjectWidth = $ this -> stringWidth ( $ badge -> getSubject ( ) ) ; $ statusWidth = $ this -> stringWidth ( $ badge -> getStatus ( ) ) ; $ params = [ 'vendorWidth' => $ subjectWidth , 'valueWidth' => $ statusWidth , 'totalWidth' => ( $ subjectWidth + $ statusWidth ) + 7 , 'vendorColor' => $ this -> color , 'valueColor' => $ badge -> getHexColor ( ) , 'vendor' => $ badge -> getSubject ( ) , 'value' => $ badge -> getStatus ( ) , 'vendorStartPosition' => round ( $ subjectWidth / 2 , 1 ) + 1 , 'valueStartPosition' => $ subjectWidth + $ statusWidth / 2 + 6 , 'arrowStartPosition' => $ subjectWidth + 6 , 'arrowPathPosition' => $ subjectWidth + 6.5 , ] ; return $ this -> renderSvg ( $ params , $ badge -> getFormat ( ) ) ; }
|
Render a badge .
|
58,996
|
public function addRoutes ( array $ routes ) { foreach ( $ routes as $ name => $ route ) { $ this -> addRoute ( $ name , $ route ) ; } return $ this ; }
|
Add an array of routes to the routes list where key is the route name .
|
58,997
|
public function addRouteFromArray ( $ name , array $ routeArray ) { $ route = \ Parable \ Routing \ Route :: createFromDataArray ( $ routeArray ) ; $ route -> setName ( $ name ) ; $ this -> addRoute ( $ name , $ route ) ; return $ this ; }
|
Add a route to the routes list from array data .
|
58,998
|
public function addRoutesFromArray ( array $ routes ) { foreach ( $ routes as $ name => $ route ) { $ this -> addRouteFromArray ( $ name , $ route ) ; } return $ this ; }
|
Add an array of routes defined by array data to the router .
|
58,999
|
public function getRouteByName ( $ name ) { if ( ! isset ( $ this -> routes [ $ name ] ) ) { return null ; } return $ this -> routes [ $ name ] ; }
|
Return a route by its name .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.