idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
58,600
|
public function replace ( $ key , $ value , $ time = 0 ) { return $ this -> cache -> replace ( $ key , $ value , intval ( $ time ) ) ; }
|
Replaces a stored value for a given key
|
58,601
|
public function prependArg ( $ arg ) { Assertion :: string ( $ arg ) ; $ this -> args = $ this -> args -> prepend ( $ arg ) ; }
|
Prepend an argument to the list of arguments to be passed to the program .
|
58,602
|
public function appendArg ( $ arg ) { Assertion :: string ( $ arg ) ; $ this -> args = $ this -> args -> append ( $ arg ) ; }
|
Append an argument to the list of arguments to be passed to the program .
|
58,603
|
public function typeOf ( $ actual , $ expected , $ message = '' ) { $ this -> assertion -> setActual ( $ actual ) ; return $ this -> assertion -> to -> be -> a ( $ expected , $ message ) ; }
|
Performs a type assertion .
|
58,604
|
public function notTypeOf ( $ actual , $ expected , $ message = '' ) { $ this -> assertion -> setActual ( $ actual ) ; return $ this -> assertion -> to -> not -> be -> a ( $ expected , $ message ) ; }
|
Performs a negated type assertion .
|
58,605
|
public function isTrue ( $ value , $ message = '' ) { $ this -> assertion -> setActual ( $ value ) ; return $ this -> assertion -> to -> be -> true ( $ message ) ; }
|
Perform a true assertion .
|
58,606
|
public function isFalse ( $ value , $ message = '' ) { $ this -> assertion -> setActual ( $ value ) ; return $ this -> assertion -> to -> be -> false ( $ message ) ; }
|
Perform a false assertion .
|
58,607
|
public function isNull ( $ value , $ message = '' ) { $ this -> assertion -> setActual ( $ value ) ; return $ this -> assertion -> to -> be -> null ( $ message ) ; }
|
Perform a null assertion .
|
58,608
|
public function isNotNull ( $ value , $ message = '' ) { $ this -> assertion -> setActual ( $ value ) ; return $ this -> assertion -> to -> not -> be -> null ( $ message ) ; }
|
Perform a negated null assertion .
|
58,609
|
public function isCallable ( $ value , $ message = '' ) { $ this -> assertion -> setActual ( $ value ) ; return $ this -> assertion -> to -> satisfy ( 'is_callable' , $ message ) ; }
|
Performs a predicate assertion to check if actual value is callable .
|
58,610
|
public function isNotCallable ( $ value , $ message = '' ) { $ this -> assertion -> setActual ( $ value ) ; return $ this -> assertion -> to -> not -> satisfy ( 'is_callable' , $ message ) ; }
|
Performs a negated predicate assertion to check if actual value is not a callable .
|
58,611
|
public function isNumeric ( $ value , $ message = '' ) { $ this -> assertion -> setActual ( $ value ) ; return $ this -> assertion -> to -> satisfy ( 'is_numeric' , $ message ) ; }
|
Performs a predicate assertion to check if actual value is numeric .
|
58,612
|
private function getElements ( array $ queries , StorageInterface $ storage ) { $ elements = [ ] ; foreach ( $ queries as $ query ) { $ elements [ ] = $ this -> getInterpreter ( $ query ) -> visit ( $ query , $ storage ) ; } return $ elements ; }
|
Interprets given queries into elements .
|
58,613
|
public static function typeMisMatch ( $ expected , $ actual ) { return new static ( sprintf ( 'Expected: "%s" Received: "%s"' , $ expected , is_object ( $ actual ) ? get_class ( $ actual ) : gettype ( $ actual ) ) ) ; }
|
Static constructor to create from the expected type & the actual value .
|
58,614
|
public static function notValidParameter ( $ parameterName , array $ allowedValues , $ actualValue ) { return new static ( sprintf ( 'Parameter: "%s" can only be one of: "%s" Received: "%s"' , $ parameterName , static :: stringify ( $ allowedValues ) , static :: stringify ( $ actualValue ) ) ) ; }
|
Static constructor to create from when a parameter should be one of a set of allowed values but was not .
|
58,615
|
public function request ( $ function_name , array $ arguments = [ ] , array $ options = null , $ input_headers = null ) { return $ this -> soap -> request ( $ function_name , $ arguments , $ options , $ input_headers ) ; }
|
Interpret the given method and arguments to a SOAP request message .
|
58,616
|
public function response ( $ response , $ function_name , array & $ output_headers = null ) { return $ this -> soap -> response ( $ response , $ function_name , $ output_headers ) ; }
|
Interpret a SOAP response message to PHP values .
|
58,617
|
protected function deleteModels ( ) : void { $ model = app ( $ this -> modelClass ) ; $ usesSoftDeletes = in_array ( SoftDeletes :: class , class_uses ( $ model ) ) ; foreach ( $ model -> all ( ) as $ value ) { try { if ( $ usesSoftDeletes ) { $ value -> forceDelete ( ) ; } else { $ value -> delete ( ) ; } } catch ( Exception $ exception ) { Log :: warning ( sprintf ( 'Error during deleting models. Table: %s. Error: %s' , $ model -> getTable ( ) , $ exception -> getMessage ( ) ) ) ; } } }
|
Removes all existing models .
|
58,618
|
public function setResponse ( $ response ) { $ xml = simplexml_load_string ( $ response ) ; if ( ! empty ( $ xml -> error ) ) { $ this -> message = ( string ) $ xml -> error ; } }
|
set exception message from response
|
58,619
|
protected function formatAmount ( ) { $ amount = $ this -> getAmount ( ) ; $ amount = str_replace ( '.' , '' , $ amount ) ; $ amount = str_pad ( $ amount , 12 , '0' , STR_PAD_LEFT ) ; return $ amount ; }
|
Returns the amount formatted to match FAC s expectations .
|
58,620
|
public function sendData ( $ data ) { $ httpResponse = $ this -> httpClient -> post ( $ this -> getEndpoint ( ) , [ 'Content-Type' => 'text/xml; charset=utf-8' ] , $ this -> xmlSerialize ( $ data ) ) -> send ( ) ; return $ this -> response = $ this -> newResponse ( $ httpResponse -> xml ( ) ) ; }
|
Send the request payload
|
58,621
|
protected function xmlSerialize ( $ data , $ xml = null ) { if ( ! $ xml instanceof SimpleXMLElement ) { $ xml = new SimpleXMLElement ( '<' . $ this -> requestName . ' xmlns="' . $ this -> namespace . '" />' ) ; } foreach ( $ data as $ key => $ value ) { if ( ! isset ( $ value ) ) { continue ; } if ( is_array ( $ value ) ) { $ node = $ xml -> addChild ( $ key ) ; $ this -> xmlSerialize ( $ value , $ node ) ; } else { $ xml -> addChild ( $ key , $ value ) ; } } return $ xml -> asXML ( ) ; }
|
Serializes an array into XML
|
58,622
|
public function verify ( Input $ input ) { $ this -> eventDispatcher -> dispatch ( new ExerciseRunnerEvent ( 'cgi.verify.start' , $ this -> exercise , $ input ) ) ; $ result = new CgiResult ( array_map ( function ( RequestInterface $ request ) use ( $ input ) { return $ this -> checkRequest ( $ request , $ input -> getArgument ( 'program' ) ) ; } , $ this -> exercise -> getRequests ( ) ) ) ; $ this -> eventDispatcher -> dispatch ( new ExerciseRunnerEvent ( 'cgi.verify.finish' , $ this -> exercise , $ input ) ) ; return $ result ; }
|
Verifies a solution by invoking PHP via the php - cgi binary populating all the super globals with the information from the request objects returned from the exercise . The exercise can return multiple requests so the solution will be invoked for however many requests there are .
|
58,623
|
public function run ( Input $ input , OutputInterface $ output ) { $ this -> eventDispatcher -> dispatch ( new ExerciseRunnerEvent ( 'cgi.run.start' , $ this -> exercise , $ input ) ) ; $ success = true ; foreach ( $ this -> exercise -> getRequests ( ) as $ i => $ request ) { $ event = $ this -> eventDispatcher -> dispatch ( new CgiExecuteEvent ( 'cgi.run.student-execute.pre' , $ request ) ) ; $ process = $ this -> getProcess ( $ input -> getArgument ( 'program' ) , $ event -> getRequest ( ) ) ; $ output -> writeTitle ( "Request" ) ; $ output -> emptyLine ( ) ; $ output -> write ( $ this -> requestRenderer -> renderRequest ( $ request ) ) ; $ output -> writeTitle ( "Output" ) ; $ output -> emptyLine ( ) ; $ process -> start ( ) ; $ this -> eventDispatcher -> dispatch ( new CgiExecuteEvent ( 'cgi.run.student.executing' , $ request , [ 'output' => $ output ] ) ) ; $ process -> wait ( function ( $ outputType , $ outputBuffer ) use ( $ output ) { $ output -> write ( $ outputBuffer ) ; } ) ; $ output -> emptyLine ( ) ; if ( ! $ process -> isSuccessful ( ) ) { $ success = false ; } $ output -> lineBreak ( ) ; } $ this -> eventDispatcher -> dispatch ( new ExerciseRunnerEvent ( 'cgi.run.finish' , $ this -> exercise , $ input ) ) ; return $ success ; }
|
Runs a student s solution by invoking PHP via the php - cgi binary populating all the super globals with the information from the request objects returned from the exercise . The exercise can return multiple requests so the solution will be invoked for however many requests there are .
|
58,624
|
public function lengthOf ( $ countable , $ length , $ message = '' ) { $ this -> assertion -> setActual ( $ countable ) ; return $ this -> assertion -> to -> have -> length ( $ length , $ message ) ; }
|
Perform a length assertion .
|
58,625
|
public function isIncluded ( $ haystack , $ needle , $ message = '' ) { $ this -> assertion -> setActual ( $ haystack ) ; return $ this -> assertion -> to -> include ( $ needle , $ message ) ; }
|
Perform an inclusion assertion .
|
58,626
|
public function notInclude ( $ haystack , $ needle , $ message = '' ) { $ this -> assertion -> setActual ( $ haystack ) ; return $ this -> assertion -> to -> not -> include ( $ needle , $ message ) ; }
|
Perform a negated inclusion assertion .
|
58,627
|
public function getTemplate ( $ key , $ language_id ) { if ( $ template = EmailTemplateTranslation :: findOne ( [ 'template_id' => EmailTemplate :: getIdByKey ( $ key ) , 'language_id' => $ language_id ] ) ) { return Template :: buildTemplate ( $ template ) ; } return null ; }
|
Getting email template model by key
|
58,628
|
public function getTemplates ( $ key ) { if ( $ templates = EmailTemplateTranslation :: findAll ( [ 'template_id' => EmailTemplate :: getIdByKey ( $ key ) ] ) ) { return Template :: buildTemplates ( $ templates ) ; } return null ; }
|
Getting email template models by key
|
58,629
|
public function collapse ( ) { $ results = [ ] ; foreach ( $ this -> array as $ item ) { if ( ! is_array ( $ item ) ) { continue ; } $ results = array_merge ( $ results , $ item ) ; } return new static ( $ results ) ; }
|
Collapse an array of arrays into a single array returning a new instance of ArrayObject with the collapsed items .
|
58,630
|
protected function doMatch ( $ actual ) { if ( $ this -> isCountable ( $ actual ) ) { $ this -> count = count ( $ actual ) ; } if ( is_string ( $ actual ) ) { $ this -> count = strlen ( $ actual ) ; } if ( isset ( $ this -> count ) ) { return $ this -> expected === $ this -> count ; } throw new InvalidArgumentException ( 'Length matcher requires a string, array, or Countable' ) ; }
|
Match the length of the countable interface or string against the expected value .
|
58,631
|
public function getPathParts ( $ path ) { $ path = preg_replace ( '/\[/' , '->[' , $ path ) ; if ( preg_match ( '/^->/' , $ path ) ) { $ path = substr ( $ path , 2 ) ; } return explode ( '->' , $ path ) ; }
|
Breaks a path expression into an array used for navigating a path .
|
58,632
|
protected function getPathValue ( $ key , $ properties ) { if ( ! array_key_exists ( $ key , $ properties ) ) { return null ; } return new ObjectPathValue ( $ key , $ properties [ $ key ] ) ; }
|
Given a key and a collection of properties this method will return an ObjectPathValue if possible .
|
58,633
|
public function renderRequest ( RequestInterface $ request ) { $ return = '' ; $ return .= sprintf ( "URL: %s\n" , $ request -> getUri ( ) ) ; $ return .= sprintf ( "METHOD: %s\n" , $ request -> getMethod ( ) ) ; if ( $ request -> getHeaders ( ) ) { $ return .= 'HEADERS:' ; } $ indent = false ; foreach ( $ request -> getHeaders ( ) as $ name => $ values ) { if ( $ indent ) { $ return .= str_repeat ( ' ' , 8 ) ; } $ return .= sprintf ( " %s: %s\n" , $ name , implode ( ', ' , $ values ) ) ; $ indent = true ; } if ( $ body = ( string ) $ request -> getBody ( ) ) { $ return .= 'BODY: ' ; switch ( $ request -> getHeaderLine ( 'Content-Type' ) ) { case 'application/json' : $ return .= json_encode ( json_decode ( $ body , true ) , JSON_PRETTY_PRINT ) ; break ; default : $ return .= $ body ; break ; } $ return .= "\n" ; } return $ return ; }
|
Render a PSR - 7 request .
|
58,634
|
public static function buildTemplates ( $ models ) { $ result = [ ] ; foreach ( $ models as $ model ) { $ result [ ] = self :: buildTemplate ( $ model ) ; } return $ result ; }
|
Builder for array of Template from Active Record model
|
58,635
|
public function addMethod ( $ name , callable $ method ) { $ this -> methods [ $ name ] = \ Closure :: bind ( $ method , $ this , $ this ) ; return $ this ; }
|
Add a method identified by the given name .
|
58,636
|
public function flag ( ) { $ args = func_get_args ( ) ; $ num = count ( $ args ) ; if ( $ num > 1 ) { $ this -> flags [ $ args [ 0 ] ] = $ args [ 1 ] ; return $ this ; } if ( array_key_exists ( $ args [ 0 ] , $ this -> flags ) ) { return $ this -> flags [ $ args [ 0 ] ] ; } }
|
A simple mechanism for storing arbitrary flags . Flags are useful for tweaking behavior based on their presence .
|
58,637
|
public function getFixture ( string $ name ) : Fixture { if ( $ this -> _fixtures === null ) { $ this -> _fixtures = $ this -> createFixtures ( $ this -> fixtures ( ) ) ; } $ name = ltrim ( $ name , '\\' ) ; return $ this -> _fixtures [ $ name ] ?? null ; }
|
Returns the named fixture .
|
58,638
|
protected function createFixtures ( array $ fixtures ) { $ config = [ ] ; $ aliases = [ ] ; foreach ( $ fixtures as $ name => $ fixture ) { if ( ! is_array ( $ fixture ) ) { $ class = ltrim ( $ fixture , '\\' ) ; $ fixtures [ $ name ] = [ 'class' => $ class ] ; $ aliases [ $ class ] = is_int ( $ name ) ? $ class : $ name ; } elseif ( isset ( $ fixture [ 'class' ] ) ) { $ class = ltrim ( $ fixture [ 'class' ] , '\\' ) ; $ config [ $ class ] = $ fixture ; $ aliases [ $ class ] = $ name ; } else { throw new InvalidConfigException ( "You must specify 'class' for the fixture '$name'." ) ; } } $ instances = [ ] ; $ stack = array_reverse ( $ fixtures ) ; while ( ( $ fixture = array_pop ( $ stack ) ) !== null ) { if ( $ fixture instanceof Fixture ) { $ class = get_class ( $ fixture ) ; $ name = isset ( $ aliases [ $ class ] ) ? $ aliases [ $ class ] : $ class ; unset ( $ instances [ $ name ] ) ; $ instances [ $ name ] = $ fixture ; } else { $ class = ltrim ( $ fixture [ 'class' ] , '\\' ) ; $ name = isset ( $ aliases [ $ class ] ) ? $ aliases [ $ class ] : $ class ; if ( ! isset ( $ instances [ $ name ] ) ) { $ instances [ $ name ] = false ; $ stack [ ] = $ fixture = app ( ) -> make ( $ fixture [ 'class' ] ) ; foreach ( $ fixture -> depends as $ dep ) { $ stack [ ] = isset ( $ config [ $ dep ] ) ? $ config [ $ dep ] : [ 'class' => $ dep ] ; } } elseif ( $ instances [ $ name ] === false ) { throw new InvalidConfigException ( "A circular dependency is detected for fixture '$class'." ) ; } } } return $ instances ; }
|
Creates the specified fixture instances . All dependent fixtures will also be created .
|
58,639
|
public function check ( ExerciseInterface $ exercise , Input $ input ) { $ process = new Process ( sprintf ( '%s -l %s' , PHP_BINARY , $ input -> getArgument ( 'program' ) ) ) ; $ process -> run ( ) ; if ( $ process -> isSuccessful ( ) ) { return Success :: fromCheck ( $ this ) ; } return Failure :: fromCheckAndReason ( $ this , $ process -> getErrorOutput ( ) ) ; }
|
Simply check the student s solution can be linted with php - l .
|
58,640
|
public function getSimilarity ( ) { if ( ! $ this -> calculated ) { $ this -> setupMatrix ( ) ; } return $ this -> matrix [ mb_strlen ( $ this -> compOne , 'UTF-8' ) ] [ mb_strlen ( $ this -> compTwo , 'UTF-8' ) ] ; }
|
Returns similarity of strings absolute number = Damerau Levenshtein distance .
|
58,641
|
public function getMaximalDistance ( ) { $ oneSize = mb_strlen ( $ this -> compOne , 'UTF-8' ) ; $ twoSize = mb_strlen ( $ this -> compTwo , 'UTF-8' ) ; $ subCost = min ( $ this -> subCost , $ this -> delCost + $ this -> insCost ) ; $ minSize = min ( $ oneSize , $ twoSize ) ; $ maxSize = max ( $ oneSize , $ twoSize ) ; $ extraSize = $ maxSize - $ minSize ; $ maxCost = $ subCost * $ minSize ; if ( $ oneSize > $ twoSize ) { $ maxCost += $ extraSize * $ this -> delCost ; } else { $ maxCost += $ extraSize * $ this -> insCost ; } return $ maxCost ; }
|
Returns maximal possible edit Damerau Levenshtein distance between texts .
|
58,642
|
public function setSubCost ( $ subCost ) { $ this -> calculated = $ subCost == $ this -> subCost ? $ this -> calculated : false ; $ this -> subCost = $ subCost ; }
|
Sets cost of substitution operation .
|
58,643
|
public function setTransCost ( $ transCost ) { $ this -> calculated = $ transCost == $ this -> transCost ? $ this -> calculated : false ; $ this -> transCost = $ transCost ; }
|
Sets cost of transposition operation .
|
58,644
|
public function attach ( EventDispatcher $ eventDispatcher ) { if ( file_exists ( $ this -> databaseDirectory ) ) { throw new \ RuntimeException ( sprintf ( 'Database directory: "%s" already exists' , $ this -> databaseDirectory ) ) ; } mkdir ( $ this -> databaseDirectory , 0777 , true ) ; try { $ db = new PDO ( $ this -> userDsn ) ; $ db -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION ) ; } catch ( \ PDOException $ e ) { rmdir ( $ this -> databaseDirectory ) ; throw $ e ; } $ eventDispatcher -> listen ( 'verify.start' , function ( Event $ e ) use ( $ db ) { $ e -> getParameter ( 'exercise' ) -> seed ( $ db ) ; copy ( $ this -> userDatabasePath , $ this -> solutionDatabasePath ) ; } ) ; $ eventDispatcher -> listen ( 'run.start' , function ( Event $ e ) use ( $ db ) { $ e -> getParameter ( 'exercise' ) -> seed ( $ db ) ; } ) ; $ eventDispatcher -> listen ( 'cli.verify.reference-execute.pre' , function ( CliExecuteEvent $ e ) { $ e -> prependArg ( $ this -> solutionDsn ) ; } ) ; $ eventDispatcher -> listen ( [ 'cli.verify.student-execute.pre' , 'cli.run.student-execute.pre' ] , function ( CliExecuteEvent $ e ) { $ e -> prependArg ( $ this -> userDsn ) ; } ) ; $ eventDispatcher -> insertVerifier ( 'verify.finish' , function ( Event $ e ) use ( $ db ) { $ verifyResult = $ e -> getParameter ( 'exercise' ) -> verify ( $ db ) ; if ( false === $ verifyResult ) { return Failure :: fromNameAndReason ( $ this -> getName ( ) , 'Database verification failed' ) ; } return new Success ( 'Database Verification Check' ) ; } ) ; $ eventDispatcher -> listen ( [ 'cli.verify.reference-execute.fail' , 'verify.finish' , 'run.finish' ] , function ( Event $ e ) use ( $ db ) { unset ( $ db ) ; @ unlink ( $ this -> userDatabasePath ) ; @ unlink ( $ this -> solutionDatabasePath ) ; rmdir ( $ this -> databaseDirectory ) ; } ) ; }
|
Here we attach to various events to seed verify and inject the DSN s to the student & reference solution programs s CLI arguments .
|
58,645
|
public function findIds ( ) { $ method = $ this -> getIdsCall ( ) ; $ response = $ this -> api -> $ method ( $ this -> params ) ; return json_decode ( $ response ) ; }
|
Get a array of realty employee or project ids
|
58,646
|
public function orderBy ( $ column , $ direction = 'asc' ) { return $ this -> order ( $ this -> mapper -> getFilterPropertyName ( $ column ) , $ direction ) ; }
|
translates and sets the order of a call
|
58,647
|
public function order ( $ column , $ direction = 'asc' ) { $ this -> set ( 'orderby' , $ column ) ; $ this -> set ( 'ordertype' , $ direction ) ; return $ this ; }
|
sets order for a call
|
58,648
|
public function filter ( $ key , $ value = null ) { if ( $ value === null ) { return $ this ; } if ( is_array ( $ value ) ) { if ( array_key_exists ( 'min' , $ value ) ) { $ this -> params [ 'filter' ] [ $ key . '_von' ] = $ value [ 'min' ] ; } if ( array_key_exists ( 'max' , $ value ) ) { $ this -> params [ 'filter' ] [ $ key . '_bis' ] = $ value [ 'max' ] ; } if ( array_key_exists ( 'min' , $ value ) || array_key_exists ( 'max' , $ value ) ) { return $ this ; } } $ this -> params [ 'filter' ] [ $ key ] = $ value ; return $ this ; }
|
adds a filter column
|
58,649
|
protected function doMatch ( $ actual ) { $ actual = $ this -> getArrayValue ( $ actual ) ; if ( $ this -> assertion -> flag ( 'contain' ) ) { $ this -> verb = 'contain' ; return $ this -> matchInclusion ( $ actual ) ; } $ keys = array_keys ( $ actual ) ; return $ keys == $ this -> expected ; }
|
Assert that the actual value is an array or object with the expected keys .
|
58,650
|
protected function getArrayValue ( $ actual ) { if ( is_object ( $ actual ) ) { return get_object_vars ( $ actual ) ; } if ( is_array ( $ actual ) ) { return $ actual ; } throw new \ InvalidArgumentException ( 'KeysMatcher expects object or array' ) ; }
|
Normalize the actual value into an array whether it is an object or an array .
|
58,651
|
protected function getKeyString ( ) { $ expected = $ this -> expected ; $ keys = '' ; $ tail = array_pop ( $ expected ) ; if ( ! empty ( $ expected ) ) { $ keys = implode ( '","' , $ expected ) . '", and "' ; } $ keys .= $ tail ; return $ keys ; }
|
Returns a formatted string of expected keys .
|
58,652
|
protected function matchInclusion ( $ actual ) { foreach ( $ this -> expected as $ key ) { if ( ! array_key_exists ( $ key , $ actual ) ) { return false ; } } return true ; }
|
Used when the contain flag exists on the Assertion . Checks if the expected keys are included in the object or array .
|
58,653
|
private function writeContributors ( array $ contributors ) { $ nameColumnSize = max ( array_map ( 'strlen' , array_values ( $ contributors ) ) ) ; $ columns = sprintf ( '%s GitHub Username' , str_pad ( 'Name' , $ nameColumnSize ) ) ; $ this -> output -> writeLine ( $ columns ) ; $ this -> output -> writeLine ( str_repeat ( '-' , strlen ( $ columns ) ) ) ; foreach ( $ contributors as $ gitHubUser => $ name ) { $ this -> output -> writeLine ( sprintf ( "%s %s" , str_pad ( $ name , $ nameColumnSize ) , $ gitHubUser ) ) ; } }
|
Output contributors in columns
|
58,654
|
public function getInfo ( $ key ) { if ( ! array_key_exists ( $ key , $ this -> infos ) ) { throw new CurlException ( 'Information ' . $ key . ' not found in CurlRequest' ) ; } return $ this -> infos [ $ key ] ; }
|
retrieve an info about this curl request
|
58,655
|
public function getOption ( $ key ) { if ( ! array_key_exists ( $ key , $ this -> options ) ) { throw new CurlException ( 'The Options ' . $ key . ' is not registered in this CurlRequest' ) ; } return $ this -> options [ $ key ] ; }
|
gets the value of an option in this curl request
|
58,656
|
public function post ( $ parameters = null ) { $ this -> setOption ( CURLOPT_POST , true ) ; if ( $ parameters !== null ) { $ this -> setParameters ( $ parameters ) ; } return $ this -> execute ( ) ; }
|
executes a post request
|
58,657
|
public function put ( $ parameters = null ) { $ this -> setOption ( CURLOPT_PUT , true ) ; if ( $ parameters !== null ) { $ this -> setParameters ( $ parameters ) ; } return $ this -> execute ( ) ; }
|
executes a put request
|
58,658
|
protected function execute ( ) { if ( $ this -> url === null ) { throw new CurlException ( 'You have to provide an URL for the CurlRequest' ) ; } $ ch = curl_init ( $ this -> url ) ; curl_setopt_array ( $ ch , $ this -> options ) ; $ this -> content = curl_exec ( $ ch ) ; $ this -> infos = curl_getinfo ( $ ch ) ; $ this -> error = curl_error ( $ ch ) ; curl_close ( $ ch ) ; return $ this -> content ; }
|
executes the curl request and fills in the information
|
58,659
|
public function setCookie ( ) { $ language = current ( $ this -> getLanguages ( ) ) ; if ( $ language !== Yii :: $ app -> language ) { $ this -> cookie -> value = Yii :: $ app -> language ; $ this -> response -> getCookies ( ) -> add ( $ this -> cookie ) ; } }
|
Sets the cookie .
|
58,660
|
public function registerDependencies ( ) { if ( empty ( $ this -> languageProvider ) ) { throw new InvalidConfigException ( "Invalid configuration of '$this->id' module" ) ; } Yii :: $ container -> set ( 'bl\emailTemplates\providers\LanguageProviderInterface' , $ this -> languageProvider ) ; }
|
Add language provider to DI container
|
58,661
|
public function render ( ResultsRenderer $ renderer ) { $ output = '' ; if ( count ( $ bannedFunctions = $ this -> result -> getBannedFunctions ( ) ) ) { $ output .= sprintf ( " %s\n%s\n" , $ renderer -> style ( "Some functions were used which should not be used in this exercise" , [ 'bold' , 'underline' , 'yellow' ] ) , implode ( "\n" , array_map ( function ( array $ call ) { return sprintf ( ' %s on line %s' , $ call [ 'function' ] , $ call [ 'line' ] ) ; } , $ bannedFunctions ) ) ) ; } if ( count ( $ missingFunctions = $ this -> result -> getMissingFunctions ( ) ) ) { $ output .= sprintf ( " %s\n%s\n" , $ renderer -> style ( "Some function requirements were missing. You should use the functions" , [ 'bold' , 'underline' , 'yellow' ] ) , implode ( "\n" , array_map ( function ( $ function ) { return sprintf ( ' %s' , $ function ) ; } , $ missingFunctions ) ) ) ; } return $ output ; }
|
Print a list of the missing required functions & print a list of used but banned functions .
|
58,662
|
public function actionList ( ) { $ templates = EmailTemplate :: find ( ) -> all ( ) ; return $ this -> render ( 'list' , [ 'templates' => $ templates , 'language' => $ this -> _languageProvider -> getDefault ( ) ] ) ; }
|
Rendering list of templates
|
58,663
|
protected function renderForm ( $ form , $ view ) { $ errors = [ ] ; if ( Yii :: $ app -> request -> isPost ) { $ form -> load ( Yii :: $ app -> request -> post ( ) ) ; if ( ! $ form -> save ( ) ) { $ errors = $ form -> getErrors ( ) ; } return $ this -> redirect ( 'list' ) ; } $ currentLanguage = [ $ form -> languageId => $ this -> _languageProvider -> getNameByID ( $ form -> languageId ) ] ; return $ this -> render ( $ view , [ 'model' => $ form , 'errors' => $ errors , 'currentLanguage' => $ currentLanguage ] ) ; }
|
Method for rendering form for create and edit of template
|
58,664
|
public function actionEdit ( $ templateId , $ languageId = null ) { $ editForm = new EditForm ( [ 'templateId' => $ templateId , 'languageId' => $ languageId ] ) ; return $ this -> renderForm ( $ editForm , 'edit' ) ; }
|
Editing of template
|
58,665
|
public function actionDelete ( $ templateId ) { if ( $ template = EmailTemplate :: findOne ( $ templateId ) ) { $ template -> delete ( ) ; } return $ this -> redirect ( Url :: toRoute ( 'list' ) ) ; }
|
Removing of template
|
58,666
|
public function throws ( callable $ fn , $ exceptionType , $ exceptionMessage = '' , $ message = '' ) { $ this -> assertion -> setActual ( $ fn ) ; return $ this -> assertion -> to -> throw ( $ exceptionType , $ exceptionMessage , $ message ) ; }
|
Performs a throw assertion .
|
58,667
|
public function doesNotThrow ( callable $ fn , $ exceptionType , $ exceptionMessage = '' , $ message = '' ) { $ this -> assertion -> setActual ( $ fn ) ; return $ this -> assertion -> not -> to -> throw ( $ exceptionType , $ exceptionMessage , $ message ) ; }
|
Performs a negated throw assertion .
|
58,668
|
public function ok ( $ object , $ message = '' ) { $ this -> assertion -> setActual ( $ object ) ; return $ this -> assertion -> to -> be -> ok ( $ message ) ; }
|
Perform an ok assertion .
|
58,669
|
public function strictEqual ( $ actual , $ expected , $ message = '' ) { $ this -> assertion -> setActual ( $ actual ) ; return $ this -> assertion -> to -> equal ( $ expected , $ message ) ; }
|
Perform a strict equality assertion .
|
58,670
|
public function notStrictEqual ( $ actual , $ expected , $ message = '' ) { $ this -> assertion -> setActual ( $ actual ) ; return $ this -> assertion -> to -> not -> equal ( $ expected , $ message ) ; }
|
Perform a negated strict equality assertion .
|
58,671
|
public function match ( $ value , $ pattern , $ message = '' ) { $ this -> assertion -> setActual ( $ value ) ; return $ this -> assertion -> to -> match ( $ pattern , $ message ) ; }
|
Perform a pattern assertion .
|
58,672
|
public function operator ( $ left , $ operator , $ right , $ message = '' ) { if ( ! isset ( static :: $ operators [ $ operator ] ) ) { throw new \ InvalidArgumentException ( "Invalid operator $operator" ) ; } $ this -> assertion -> setActual ( $ left ) ; return $ this -> assertion -> { static :: $ operators [ $ operator ] } ( $ right , $ message ) ; }
|
Compare two values using the given operator .
|
58,673
|
public function verifySignature ( ) { if ( isset ( $ this -> data [ 'CreditCardTransactionResults' ] [ 'ResponseCode' ] ) && ( '1' == $ this -> data [ 'CreditCardTransactionResults' ] [ 'ResponseCode' ] || '2' == $ this -> data [ 'CreditCardTransactionResults' ] [ 'ResponseCode' ] ) ) { $ signature = $ this -> request -> getMerchantPassword ( ) ; $ signature .= $ this -> request -> getMerchantId ( ) ; $ signature .= $ this -> request -> getAcquirerId ( ) ; $ signature .= $ this -> request -> getTransactionId ( ) ; $ signature = base64_encode ( sha1 ( $ signature , true ) ) ; if ( $ signature !== $ this -> data [ 'Signature' ] ) { throw new InvalidResponseException ( 'Signature verification failed' ) ; } } }
|
Verifies the signature for the response .
|
58,674
|
public function hasInstalledPackage ( $ packageName ) { foreach ( $ this -> contents [ 'packages' ] as $ packageDetails ) { if ( $ packageName === $ packageDetails [ 'name' ] ) { return true ; } } return false ; }
|
Check if a package name has been installed in any version .
|
58,675
|
public static function fromProcess ( Process $ process ) { $ message = 'PHP Code failed to execute. Error: "%s"' ; $ processOutput = $ process -> getErrorOutput ( ) ? $ process -> getErrorOutput ( ) : $ process -> getOutput ( ) ; return new static ( sprintf ( $ message , $ processOutput ) ) ; }
|
Static constructor to create an instance from a failed Symfony \ Component \ Process \ Process instance .
|
58,676
|
public static function traceLeoCall ( array $ trace ) { for ( $ i = count ( $ trace ) - 1 ; $ i >= 0 ; -- $ i ) { if ( self :: isLeoTraceEntry ( $ trace [ $ i ] ) ) { return $ trace [ $ i ] ; } } return null ; }
|
Find the Leo entry point call in a stack trace .
|
58,677
|
private function loadPucene ( array $ config , ContainerBuilder $ container ) : void { $ serviceIds = [ ] ; foreach ( $ config [ 'indices' ] as $ name => $ options ) { $ definition = new Definition ( DbalStorage :: class , [ $ name , new Reference ( $ config [ 'adapters' ] [ 'pucene' ] [ 'doctrine_dbal_connection' ] ) , new Reference ( 'pucene.pucene.compiler' ) , new Reference ( 'pucene.pucene.interpreter' ) , ] ) ; $ serviceIds [ $ name ] = 'pucene.pucene.doctrine_dbal.' . $ name ; $ container -> setDefinition ( $ serviceIds [ $ name ] , $ definition ) ; } $ container -> getDefinition ( 'pucene.pucene.storage_factory' ) -> replaceArgument ( 1 , $ serviceIds ) ; $ pass = new CollectorCompilerPass ( 'pucene.pucene.visitor' , 'pucene.pucene.visitor_pool' , 'query' ) ; $ pass -> process ( $ container ) ; $ pass = new CollectorCompilerPass ( 'pucene.pucene.interpreter' , 'pucene.pucene.interpreter_pool' , 'element' ) ; $ pass -> process ( $ container ) ; }
|
Load specific configuration for pucene .
|
58,678
|
private function loadElasticsearch ( array $ config , ContainerBuilder $ container ) : void { $ pass = new CollectorCompilerPass ( 'pucene.elasticsearch.visitor' , 'pucene.elasticsearch.visitor_pool' , 'query' ) ; $ pass -> process ( $ container ) ; }
|
Load specific configuration for elasticsearch .
|
58,679
|
public function saveAttribute ( ) { $ language = current ( $ this -> getLanguages ( ) ) ; if ( $ language !== Yii :: $ app -> language ) { $ this -> identity -> { $ this -> languageAttribute } = Yii :: $ app -> language ; $ this -> identity -> save ( true , [ $ this -> languageAttribute ] ) ; } }
|
Saves the language attribute .
|
58,680
|
protected function doMatch ( $ actual ) { if ( ! is_string ( $ actual ) ) { throw new \ InvalidArgumentException ( 'PatternMatcher expects a string' ) ; } return ( bool ) preg_match ( $ this -> expected , $ actual ) ; }
|
Match the actual value against a regular expression .
|
58,681
|
private function visitQueries ( array $ queries ) { $ result = [ ] ; foreach ( $ queries as $ query ) { $ result [ ] = $ this -> getInterpreter ( $ query ) -> visit ( $ query ) ; } return $ result ; }
|
Returns visited queries .
|
58,682
|
public function addHeaderToRequest ( $ header , $ value ) { $ this -> request = $ this -> request -> withHeader ( $ header , $ value ) ; }
|
Add a header to the request .
|
58,683
|
public function findByName ( $ name ) { foreach ( $ this -> exercises as $ exercise ) { if ( $ name === $ exercise -> getName ( ) ) { return $ exercise ; } } throw new InvalidArgumentException ( sprintf ( 'Exercise with name: "%s" does not exist' , $ name ) ) ; }
|
Find an exercise by it s name . If it does not exist an InvalidArgumentException exception is thrown .
|
58,684
|
protected function connectToServer ( $ username , $ password , $ database , $ hostname , $ persistent = false , $ type = 'mysql' , $ port = 3306 , $ options = [ ] ) { if ( ! $ this -> db ) { $ this -> database = $ database ; $ this -> db = new PDO ( sprintf ( self :: $ connectors [ $ type ] , $ hostname , $ port , $ database ) , $ username , $ password , array_merge ( ( $ persistent !== false ? array ( PDO :: ATTR_PERSISTENT => true ) : [ ] ) , ( $ type === 'mysql' ? array ( PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY => true , PDO :: ATTR_EMULATE_PREPARES => true ) : [ ] ) , ( is_array ( $ options ) ? $ options : [ ] ) ) ) ; $ this -> db -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION ) ; } }
|
Connect to the database using PDO connection
|
58,685
|
public function setCaching ( $ caching ) { if ( is_object ( $ caching ) ) { $ this -> cacheObj = $ caching ; $ this -> cacheEnabled = true ; } return $ this ; }
|
Enables the caching and set the caching object to the one provided
|
58,686
|
public function query ( $ sql , $ variables = array ( ) , $ cache = true ) { if ( ! empty ( trim ( $ sql ) ) ) { $ this -> sql = $ sql ; $ this -> key = md5 ( $ this -> sql . serialize ( $ variables ) ) ; if ( $ this -> logQueries ) { $ this -> writeQueryToLog ( ) ; } if ( $ cache && $ this -> cacheEnabled && $ this -> getCache ( $ this -> key ) ) { return $ this -> cacheValue ; } try { $ this -> query = $ this -> db -> prepare ( $ this -> sql ) ; $ result = $ this -> query -> execute ( $ variables ) ; if ( strpos ( $ this -> sql , 'SELECT' ) !== false ) { $ result = $ this -> query -> fetchAll ( PDO :: FETCH_ASSOC ) ; if ( $ cache && $ this -> cacheEnabled ) { $ this -> setCache ( $ this -> key , $ result ) ; } } return $ result ; } catch ( \ Exception $ e ) { $ this -> error ( $ e ) ; } } }
|
This query function is used for more advanced SQL queries for which non of the other methods fit
|
58,687
|
public function select ( $ table , $ where = array ( ) , $ fields = '*' , $ order = array ( ) , $ cache = true ) { return $ this -> selectAll ( $ table , $ where , $ fields , $ order , 1 , $ cache ) ; }
|
Returns a single record for a select query for the chosen table
|
58,688
|
public function selectAll ( $ table , $ where = array ( ) , $ fields = '*' , $ order = array ( ) , $ limit = 0 , $ cache = true ) { $ this -> buildSelectQuery ( SafeString :: makeSafe ( $ table ) , $ where , $ fields , $ order , $ limit ) ; $ result = $ this -> executeQuery ( $ cache ) ; if ( ! $ result ) { if ( $ limit === 1 ) { $ result = $ this -> query -> fetch ( PDO :: FETCH_ASSOC ) ; } else { $ result = $ this -> query -> fetchAll ( PDO :: FETCH_ASSOC ) ; } if ( $ cache && $ this -> cacheEnabled ) { $ this -> setCache ( $ this -> key , $ result ) ; } } return $ result ? $ result : false ; }
|
Returns a multidimensional array of the results from the selected table given the given parameters
|
58,689
|
public function fetchColumn ( $ table , $ where = array ( ) , $ fields = '*' , $ colNum = 0 , $ order = array ( ) , $ cache = true ) { $ this -> buildSelectQuery ( SafeString :: makeSafe ( $ table ) , $ where , $ fields , $ order , 1 ) ; $ result = $ this -> executeQuery ( $ cache ) ; if ( ! $ result ) { $ column = $ this -> query -> fetchColumn ( intval ( $ colNum ) ) ; if ( $ cache && $ this -> cacheEnabled ) { $ this -> setCache ( $ this -> key , $ column ) ; } return ( $ column ? $ column : false ) ; } return false ; }
|
Returns a single column value for a given query
|
58,690
|
public function insert ( $ table , $ records ) { unset ( $ this -> prepare ) ; $ this -> sql = sprintf ( "INSERT INTO `%s` (%s) VALUES (%s);" , SafeString :: makeSafe ( $ table ) , $ this -> fields ( $ records , true ) , implode ( ', ' , $ this -> prepare ) ) ; $ this -> executeQuery ( false ) ; return $ this -> numRows ( ) ? true : false ; }
|
Inserts into database using the prepared PDO statements
|
58,691
|
public function update ( $ table , $ records , $ where = array ( ) , $ limit = 0 ) { $ this -> sql = sprintf ( "UPDATE `%s` SET %s %s%s;" , SafeString :: makeSafe ( $ table ) , $ this -> fields ( $ records ) , $ this -> where ( $ where ) , $ this -> limit ( $ limit ) ) ; $ this -> executeQuery ( false ) ; return $ this -> numRows ( ) ? true : false ; }
|
Updates values in a database using the provide variables
|
58,692
|
public function delete ( $ table , $ where , $ limit = 0 ) { $ this -> sql = sprintf ( "DELETE FROM `%s` %s%s;" , SafeString :: makeSafe ( $ table ) , $ this -> where ( $ where ) , $ this -> limit ( $ limit ) ) ; $ this -> executeQuery ( false ) ; return $ this -> numRows ( ) ? true : false ; }
|
Deletes records from the given table based on the variables given
|
58,693
|
public function count ( $ table , $ where = array ( ) , $ cache = true ) { $ this -> sql = sprintf ( "SELECT count(*) FROM `%s`%s;" , SafeString :: makeSafe ( $ table ) , $ this -> where ( $ where ) ) ; $ this -> key = md5 ( $ this -> database . $ this -> sql . serialize ( $ this -> values ) ) ; $ result = $ this -> executeQuery ( $ cache ) ; if ( ! $ result ) { $ result = $ this -> query -> fetchColumn ( ) ; if ( $ cache && $ this -> cacheEnabled ) { $ this -> setCache ( $ this -> key , $ result ) ; } } return $ result ; }
|
Count the number of return results
|
58,694
|
public function truncate ( $ table ) { try { $ this -> sql = sprintf ( "TRUNCATE TABLE `%s`" , SafeString :: makeSafe ( $ table ) ) ; $ this -> executeQuery ( false ) ; } catch ( \ Exception $ e ) { $ this -> error ( $ e ) ; } return $ this -> numRows ( ) ? true : false ; }
|
Truncates a given table from the selected database so there are no values in the table
|
58,695
|
public function setLogLocation ( $ location = false ) { if ( $ location === false ) { $ location = dirname ( __FILE__ ) . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR ; } $ this -> logLocation = $ location ; if ( ! file_exists ( $ location ) ) { mkdir ( $ location , 0777 , true ) ; } return $ this ; }
|
Sets the location of the log files
|
58,696
|
private function error ( $ error ) { if ( $ this -> logErrors ) { $ file = $ this -> logLocation . 'db-errors.txt' ; $ current = file_get_contents ( $ file ) ; $ current .= date ( 'd/m/Y H:i:s' ) . " ERROR: " . $ error -> getMessage ( ) . " on " . $ this -> sql . "\n" ; file_put_contents ( $ file , $ current ) ; } die ( $ this -> displayErrors ? 'ERROR: ' . $ error -> getMessage ( ) . ' on ' . $ this -> sql : 0 ) ; }
|
Displays the error massage which occurs
|
58,697
|
public function writeQueryToLog ( ) { $ file = $ this -> logLocation . 'queries.txt' ; $ current = file_get_contents ( $ file ) ; $ current .= "SQL: " . $ this -> sql . ":" . serialize ( $ this -> values ) . "\n" ; file_put_contents ( $ file , $ current ) ; }
|
Writes all queries to a log file
|
58,698
|
protected function buildSelectQuery ( $ table , $ where = array ( ) , $ fields = '*' , $ order = array ( ) , $ limit = 0 ) { if ( is_array ( $ fields ) ) { $ selectfields = array ( ) ; foreach ( $ fields as $ field => $ value ) { $ selectfields [ ] = sprintf ( "`%s`" , SafeString :: makeSafe ( $ value ) ) ; } $ fieldList = implode ( ', ' , $ selectfields ) ; } else { $ fieldList = '*' ; } $ this -> sql = sprintf ( "SELECT %s FROM `%s`%s%s%s;" , $ fieldList , SafeString :: makeSafe ( $ table ) , $ this -> where ( $ where ) , $ this -> orderBy ( $ order ) , $ this -> limit ( $ limit ) ) ; $ this -> key = md5 ( $ this -> database . $ this -> sql . serialize ( $ this -> values ) ) ; }
|
Build the SQL query but doesn t execute it
|
58,699
|
protected function executeQuery ( $ cache = true ) { if ( $ this -> logQueries ) { $ this -> writeQueryToLog ( ) ; } if ( $ cache && $ this -> cacheEnabled && $ this -> getCache ( $ this -> key ) ) { return $ this -> cacheValue ; } try { $ this -> query = $ this -> db -> prepare ( $ this -> sql ) ; $ this -> bindValues ( $ this -> values ) ; $ this -> query -> execute ( ) ; unset ( $ this -> values ) ; $ this -> values = [ ] ; } catch ( \ Exception $ e ) { unset ( $ this -> values ) ; $ this -> values = [ ] ; $ this -> error ( $ e ) ; } }
|
Execute the current query if no cache value is available
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.