idx
int64
0
241k
question
stringlengths
64
6.21k
target
stringlengths
5
803
241,200
protected function mockDependencies ( ) { $ dependencies = $ this -> getDependencyMapping ( ) ; foreach ( $ dependencies as $ interface => $ memberName ) { if ( ! isset ( $ this -> $ memberName ) ) { $ this -> $ memberName = Mockery :: mock ( $ interface ) ; } $ dependencies [ $ interface ] = $ this -> $ memberName ; }...
Mock all dependencies that were not set yet
241,201
public function download ( Application $ application , string $ commit , string $ targetFile ) : bool { $ username = $ application -> parameter ( 'gh.owner' ) ; $ repository = $ application -> parameter ( 'gh.repo' ) ; if ( ! $ username || ! $ repository ) { throw new VCSException ( self :: ERR_APP_MISCONFIGURED ) ; } ...
Get content of archives in a repository
241,202
static function auth ( ProviderInterface $ provider ) { if ( ! require_get ( "code" , false ) ) { redirect ( $ provider -> getAuthorizationUrl ( ) ) ; return false ; } else { if ( ! \ Openclerk \ Events :: trigger ( 'oauth2_auth' , $ provider ) ) { throw new UserAuthenticationException ( "Login was cancelled by the sys...
Execute OAuth2 authentication and return the user .
241,203
static function removeIdentity ( \ Db \ Connection $ db , User $ user , $ provider , $ uid ) { if ( ! $ user ) { throw new \ InvalidArgumentException ( "No user provided." ) ; } $ q = $ db -> prepare ( "DELETE FROM user_oauth2_identities WHERE user_id=? AND provider=? AND uid=? LIMIT 1" ) ; return $ q -> execute ( arra...
Remove the given OAuth2 identity from the given user .
241,204
public static function select ( array $ columns = [ '*' ] , ... $ joinsColumns ) { $ query = new static ( Query \ Type :: SELECT ) ; $ query -> columns [ 't' ] = $ columns ; $ alias = 'j1' ; foreach ( $ joinsColumns as $ joinColumns ) { $ query -> columns [ $ alias ] = ( array ) $ joinColumns ; $ alias ++ ; } return $ ...
Creates instance of select - type Query .
241,205
protected function getTmpPath ( ) { $ tmpDir = sys_get_temp_dir ( ) ; if ( ! empty ( $ this -> prefix ) ) { $ tmpDir .= DIRECTORY_SEPARATOR . $ this -> prefix ; } $ tmpDir .= DIRECTORY_SEPARATOR . uniqid ( 'run-' , true ) ; return $ tmpDir ; }
Get path to temp directory
241,206
public function createTmpFile ( $ suffix = null , $ preserve = false ) { $ this -> initRunFolder ( ) ; $ file = uniqid ( ) ; if ( $ suffix ) { $ file .= '-' . $ suffix ; } $ fileInfo = new \ SplFileInfo ( $ this -> tmpRunFolder . DIRECTORY_SEPARATOR . $ file ) ; $ this -> filesystem -> touch ( $ fileInfo ) ; $ this -> ...
Create empty file in TMP directory
241,207
public function createFile ( $ fileName , $ preserve = false ) { $ this -> initRunFolder ( ) ; $ fileInfo = new \ SplFileInfo ( $ this -> tmpRunFolder . DIRECTORY_SEPARATOR . $ fileName ) ; $ this -> filesystem -> touch ( $ fileInfo ) ; $ this -> files [ ] = array ( 'file' => $ fileInfo , 'preserve' => $ preserve ) ; $...
Creates named temporary file
241,208
public function processUpdate ( array $ data ) { $ set = $ this -> formatCmd ( 'set' ) ; $ data [ $ set ] = isset ( $ data [ $ set ] ) ? $ data [ $ set ] : [ ] ; foreach ( $ data as $ index => $ value ) { if ( substr ( $ index , 0 , 1 ) !== $ this -> cmd ) { $ data [ $ set ] [ $ index ] = $ value ; unset ( $ data [ $ i...
Process update data
241,209
public function processCondition ( array $ conditions , $ depth = 0 ) { if ( empty ( $ conditions ) ) { return [ ] ; } $ parsed = [ ] ; foreach ( $ conditions as $ key => $ condition ) { if ( is_int ( $ key ) ) { if ( $ depth > 0 && is_array ( $ condition ) ) { throw new InvalidArgumentException ( 'Too deep sets of con...
Process sets of conditions and merges them by AND operator
241,210
private function parseCondition ( $ condition , $ parameters = [ ] ) { if ( strpos ( $ condition , ' ' ) ) { $ match = preg_match ( '~^ (.+)\s ## identifier ( (?:\$\w+) | ## $mongoOperator (?:[A-Z]+(?:_[A-Z]+)*) | ## NAMED_OPERATOR or (?:[\<\>\!]?\=|\>|\<\...
Parses single condition
241,211
private function parseDeepCondition ( array $ parameters , $ toArray = FALSE ) { $ opcond = [ ] ; foreach ( $ parameters as $ key => $ param ) { $ ccond = is_int ( $ key ) ? $ this -> parseCondition ( $ param ) : $ this -> parseCondition ( $ key , $ param ) ; if ( $ toArray ) { $ opcond [ ] = $ ccond ; } else { reset (...
Parses inner conditions
241,212
public function processData ( array $ data , $ expand = FALSE ) { $ return = [ ] ; foreach ( $ data as $ key => $ item ) { list ( $ modified , $ key ) = $ this -> doubledModifier ( $ key , '%' ) ; if ( $ modified && preg_match ( '#^(.*)%(\w+(?:\[\])?)$#' , $ key , $ parts ) ) { $ key = $ parts [ 1 ] ; $ item = $ this -...
Formats data types by modifiers
241,213
protected function processLikeOperator ( $ value ) { $ value = preg_quote ( $ value ) ; $ value = substr ( $ value , 0 , 1 ) === '%' ? ( substr ( $ value , - 1 , 1 ) === '%' ? substr ( $ value , 1 , - 1 ) : substr ( $ value , 1 ) . '$' ) : ( substr ( $ value , - 1 , 1 ) === '%' ? '^' . substr ( $ value , 0 , - 1 ) : $ ...
Converts SQL LIKE to MongoRegex
241,214
protected function processArray ( $ modifier , array & $ values ) { foreach ( $ values as & $ item ) { $ item = $ this -> processModifier ( $ modifier , $ item ) ; } }
Applies modifier to the inner array via reference
241,215
public function getDependencyConfig ( ) : array { return [ 'aliases' => [ SessionManager :: class => ManagerInterface :: class , ] , 'factories' => [ ConfigInterface :: class => SessionConfigFactory :: class , ManagerInterface :: class => SessionManagerFactory :: class , StorageInterface :: class => StorageFactory :: c...
Merge our config with Zend Session dependencies
241,216
public function & SetView ( \ MvcCore \ IView & $ view ) { parent :: SetView ( $ view ) ; if ( self :: $ appRoot === NULL ) self :: $ appRoot = $ this -> request -> GetAppRoot ( ) ; if ( self :: $ basePath === NULL ) self :: $ basePath = $ this -> request -> GetBasePath ( ) ; if ( self :: $ scriptName === NULL ) self :...
Insert a \ MvcCore \ View in each helper constructing
241,217
public function CssJsFileUrl ( $ path = '' ) { $ result = '' ; if ( self :: $ assetsUrlCompletion ) { $ result = $ this -> view -> AssetUrl ( $ path ) ; } else { $ result = self :: $ basePath . $ path ; } return $ result ; }
Completes CSS or JS file url .
241,218
protected function filterItemsForNotPossibleMinifiedAndPossibleMinifiedItems ( $ items ) { $ itemsToRenderMinimized = [ ] ; $ itemsToRenderSeparately = [ ] ; foreach ( $ items as & $ item ) { $ itemArr = array_merge ( ( array ) $ item , [ ] ) ; unset ( $ itemArr [ 'path' ] ) ; if ( isset ( $ itemArr [ 'render' ] ) ) un...
Look for every item to render if there is any doNotMinify record to render item separately
241,219
protected function addFileModificationImprintToHrefUrl ( $ url , $ path ) { $ questionMarkPos = strpos ( $ url , '?' ) ; $ separator = ( $ questionMarkPos === FALSE ) ? '?' : '&' ; $ strippedUrl = $ questionMarkPos !== FALSE ? substr ( $ url , $ questionMarkPos ) : $ url ; $ srcPath = $ this -> getAppRoot ( ) . substr ...
Add to href URL file modification param by original file
241,220
protected function getIndentString ( $ indent = 0 ) { $ indentStr = '' ; if ( is_numeric ( $ indent ) ) { $ indInt = intval ( $ indent ) ; if ( $ indInt > 0 ) { $ i = 0 ; while ( $ i < $ indInt ) { $ indentStr .= "\t" ; $ i += 1 ; } } } else if ( is_string ( $ indent ) ) { $ indentStr = $ indent ; } return $ indentStr ...
Get indent string
241,221
protected function getTmpDir ( ) { if ( ! self :: $ tmpDir ) { $ tmpDir = $ this -> getAppRoot ( ) . self :: $ globalOptions [ 'tmpDir' ] ; if ( ! \ MvcCore \ Application :: GetInstance ( ) -> GetCompiled ( ) ) { if ( ! is_dir ( $ tmpDir ) ) mkdir ( $ tmpDir , 0777 , TRUE ) ; if ( ! is_writable ( $ tmpDir ) ) { try { @...
Return and store application document root from controller view request object
241,222
protected function saveFileContent ( $ fullPath = '' , & $ fileContent = '' ) { $ toolClass = \ MvcCore \ Application :: GetInstance ( ) -> GetToolClass ( ) ; $ toolClass :: SingleProcessWrite ( $ fullPath , $ fileContent ) ; @ chmod ( $ fullPath , 0766 ) ; }
Save atomically file content in full path by 1 MB to not overflow any memory limits
241,223
protected function log ( $ msg = '' , $ logType = 'debug' ) { if ( self :: $ loggingAndExceptions ) { \ MvcCore \ Debug :: Log ( $ msg , $ logType ) ; } }
Log any render messages with optional log file name
241,224
protected function warning ( $ msg ) { if ( self :: $ loggingAndExceptions ) { \ MvcCore \ Debug :: BarDump ( '[' . get_class ( $ this ) . '] ' . $ msg , \ MvcCore \ IDebug :: DEBUG ) ; } }
Throw exception with given message with actual helper class name before
241,225
protected function getTmpFileFullPathByPartFilesInfo ( $ filesGroupInfo = [ ] , $ minify = FALSE , $ extension = '' ) { return implode ( '' , [ $ this -> getTmpDir ( ) , '/' . ( $ minify ? 'minified' : 'rendered' ) . '_' . $ extension . '_' , md5 ( implode ( ',' , $ filesGroupInfo ) . '_' . $ minify ) , '.' . $ extensi...
Complete items group tmp directory file name by group source files info
241,226
public function run ( $ jobs ) { $ lenTab = count ( $ jobs ) ; for ( $ i = 0 ; $ i < $ lenTab ; $ i ++ ) { $ jobID = rand ( 0 , 100 ) ; while ( count ( $ this -> currentJobs ) >= $ this -> maxProcesses ) { sleep ( $ this -> sleepTime ) ; } $ launched = $ this -> launchJobProcess ( $ jobID , "Jobs" , $ jobs [ $ i ] ) ; ...
Run the Daemon
241,227
protected function launchJob ( $ jobID ) { $ pid = pcntl_fork ( ) ; if ( $ pid == - 1 ) { error_log ( 'Could not launch new job, exiting' ) ; echo 'Could not launch new job, exiting' ; return false ; } else if ( $ pid ) { $ this -> currentJobs [ $ pid ] = $ jobID ; if ( isset ( $ this -> signalQueue [ $ pid ] ) ) { $ t...
Launch a job from the job queue
241,228
protected function getTableNames ( ) : array { $ dbName = $ this -> config [ DbItf :: DB_CFG_DATABASE ] ; $ resp = $ this -> dbRunQuery ( sprintf ( 'SHOW FULL TABLES FROM `%s`' , $ dbName ) ) ; $ tableAndViewNames = [ ] ; while ( $ row = $ resp -> fetch_assoc ( ) ) { $ tableAndViewNames [ ] = array_change_key_case ( $ ...
Return table and view names form the database .
241,229
public static function slashDirname ( $ dirname = null ) { if ( is_null ( $ dirname ) || empty ( $ dirname ) ) { return '' ; } return rtrim ( $ dirname , '/ ' . DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; }
Get a dirname with one and only trailing slash
241,230
public static function isGitClone ( $ path = null ) { if ( is_null ( $ path ) || empty ( $ path ) ) { return false ; } $ dir_path = self :: slashDirname ( $ path ) . '.git' ; return ( bool ) ( file_exists ( $ dir_path ) && is_dir ( $ dir_path ) ) ; }
Test if a path seems to be a git clone
241,231
public static function isDotPath ( $ path = null ) { if ( is_null ( $ path ) || empty ( $ path ) ) { return false ; } return ( bool ) ( '.' === substr ( basename ( $ path ) , 0 , 1 ) ) ; }
Test if a filename seems to have a dot as first character
241,232
public static function remove ( $ path , $ parent = true ) { $ ok = true ; if ( true === self :: ensureExists ( $ path ) ) { if ( false === @ is_dir ( $ path ) || true === is_link ( $ path ) ) { return @ unlink ( $ path ) ; } $ iterator = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ path ) , \...
Try to remove a path
241,233
public static function parseIni ( $ path ) { if ( true === @ file_exists ( $ path ) ) { $ data = parse_ini_file ( $ path , true ) ; if ( $ data && ! empty ( $ data ) ) { return $ data ; } } return false ; }
Read and parse a INI content file
241,234
public static function parseJson ( $ path ) { if ( true === @ file_exists ( $ path ) ) { $ ctt = file_get_contents ( $ path ) ; if ( $ ctt !== false ) { $ data = json_decode ( $ ctt , true ) ; if ( $ data && ! empty ( $ data ) ) { return $ data ; } } } return false ; }
Read and parse a JSON content file
241,235
protected function create ( Array $ arguments = [ ] ) { $ migrationsDirectory = $ this -> cmd -> getConfigOpt ( 'migrations_storage' ) ; $ templateTags = [ ] ; $ migrationName = $ this -> cmd -> question ( 'Migration filename?' ) ; $ filename = trim ( $ migrationName ) ; $ path = $ migrationsDirectory . '/' . $ filenam...
Creates a migration .
241,236
protected function processMigration ( Array $ arguments ) { $ migrationClass = $ arguments [ 0 ] ; $ migration = Model :: findByclass_name ( $ migrationClass ) ; if ( ! $ migration ) { throw new MigrationClassNotFoundException ( sprintf ( 'Migration class [%s] does not exist' , $ migrationClass ) ) ; } if ( isset ( $ a...
Processes a specific migration .
241,237
protected function getCacheModificationDate ( $ file ) { $ storageKey = $ this -> getStorageKey ( ) . '.lasmodified' ; $ filemtime = filemtime ( $ file ) ; $ lastmodified = $ this -> storage -> has ( $ storageKey ) ? $ this -> storage -> get ( $ storageKey ) : $ filemtime - 1 ; return array ( $ filemtime , $ lastmodifi...
Returns the modification date of a given file and the the date of the last cache write .
241,238
public function create ( array $ metadata = array ( ) ) { if ( is_file ( $ this -> file ) ) { return false ; } $ this -> createTemporaryFolder ( ) ; file_put_contents ( $ this -> file , $ this -> placeholderContent ( $ metadata ) , LOCK_EX ) ; return true ; }
Creates the file . It creates a placeholder file with some metadata on it and will create all the temporary files and folders .
241,239
protected function createTemporaryFolder ( ) { Util :: mkdir ( $ this -> blocks ) ; Util :: mkdir ( dirname ( $ this -> file ) ) ; file_put_contents ( $ this -> tmp . '.lock' , '' , LOCK_EX ) ; }
Creates the needed temporary files and folders in prepartion for the file writer .
241,240
public function getWroteBlocks ( ) { if ( ! is_dir ( $ this -> blocks ) ) { throw new RuntimeException ( "cannot obtain the blocks ({$this->blocks})" ) ; } $ files = array_filter ( array_map ( function ( $ file ) { $ basename = basename ( $ file ) ; if ( ! is_numeric ( $ basename ) ) { return false ; } return [ 'offset...
Returns all the wrote blocks of files . All the blocks are sorted by their offset .