idx
int64
0
241k
question
stringlengths
92
3.54k
target
stringlengths
5
803
len_question
int64
27
891
len_target
int64
3
240
240,800
protected function commandCallback ( $ callback ) { return ( function ( $ output ) use ( $ callback ) { $ this -> output .= $ output ; if ( is_callable ( $ callback ) ) { return call_user_func ( $ callback , $ output ) ; } } ) ; }
Wrap the callback so we can print the output .
62
11
240,801
protected function parseXml ( SplFileInfo $ file ) { $ dom = XmlUtils :: loadFile ( $ file , realpath ( dirname ( __DIR__ ) . DS . 'Schema' . DS . 'smarty_filter.xsd' ) ) ; /** @var \Symfony\Component\DependencyInjection\SimpleXMLElement $xml */ $ xml = simplexml_import_dom ( $ dom , '\\Symfony\\Component\\DependencyIn...
Get config from xml file
335
5
240,802
protected function applyConfig ( array $ moduleConfiguration ) { foreach ( $ moduleConfiguration [ 'smarty_filter' ] as $ smartyFilterData ) { if ( SmartyFilterQuery :: create ( ) -> findOneByCode ( $ smartyFilterData [ 'code' ] ) === null ) { $ smartyFilter = ( new SmartyFilter ( ) ) -> setCode ( $ smartyFilterData [ ...
Save new smarty filter to database
187
7
240,803
protected function isValid ( ) { if ( ! $ this -> request -> ajax ( ) ) { return false ; } $ search = $ this -> request -> input ( 'search' ) ; if ( ! is_string ( $ search ) or strlen ( $ this -> request -> input ( 'search' ) ) <= 0 ) { return false ; } $ token = $ this -> request -> header ( 'search-protection' ) ; if...
validates submitted data from search form
114
7
240,804
private function validateToken ( $ token = null ) { if ( is_null ( $ token ) ) { return false ; } $ decrypted = Crypt :: decrypt ( $ token ) ; $ args = unserialize ( $ decrypted ) ; if ( ! isset ( $ args [ 'protection_string' ] ) or $ args [ 'protection_string' ] !== config ( 'antares/search::protection_string' ) ) { r...
validates protection token
143
4
240,805
public function boot ( ) { if ( ! $ this -> isValid ( ) ) { return false ; } $ serviceProvider = new \ Antares \ Customfields \ CustomFieldsServiceProvider ( app ( ) ) ; $ serviceProvider -> register ( ) ; $ serviceProvider -> boot ( ) ; $ query = e ( $ this -> request -> input ( 'search' ) ) ; $ cacheKey = 'search_' ....
Boots search query in lucene indexes
406
8
240,806
protected function getDatatableInstance ( $ classname ) { if ( ! class_exists ( $ classname ) ) { return false ; } $ datatable = app ( $ classname ) ; $ reflection = new ReflectionClass ( $ datatable ) ; if ( ( $ filename = $ reflection -> getFileName ( ) ) && ! str_contains ( $ filename , 'core' ) ) { if ( ! app ( 'an...
Gets instance of datatable
122
6
240,807
protected function _getStoreId ( ) { $ storeEnv = Mage :: app ( ) -> getStore ( ) ; if ( $ storeEnv -> isAdmin ( ) ) { /** @var Mage_Adminhtml_Model_Session_Quote */ $ quoteSession = $ this -> _orderHelper -> getAdminQuoteSessionModel ( ) ; // when in the admin, the store id the order is actually being created // for s...
Get the store id for the order . In non - admin stores can use the current store . In admin stores must get the order the quote is actually being created in .
132
34
240,808
public function getNextId ( ) { // remove any order prefixes from the last increment id $ last = $ this -> _orderHelper -> removeOrderIncrementPrefix ( $ this -> getLastId ( ) ) ; // Using bcmath to avoid float/integer overflow. return $ this -> format ( bcadd ( $ last , 1 ) ) ; }
Get the next increment id by incrementing the last id
74
11
240,809
protected function getDependencyMapping ( ) { $ constructor = ( new ReflectionClass ( $ this -> className ) ) -> getConstructor ( ) ; $ dependencies = [ ] ; if ( ! is_null ( $ constructor ) ) { foreach ( $ constructor -> getParameters ( ) as $ param ) { $ dependencies [ $ param -> getClass ( ) -> getName ( ) ] = $ para...
Get a mapping of class name = > member name dependencies .
99
12
240,810
protected function mockDependencies ( ) { $ dependencies = $ this -> getDependencyMapping ( ) ; foreach ( $ dependencies as $ interface => $ memberName ) { if ( ! isset ( $ this -> $ memberName ) ) { $ this -> $ memberName = Mockery :: mock ( $ interface ) ; } // Update with the actual instance. $ dependencies [ $ inte...
Mock all dependencies that were not set yet
97
9
240,811
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
235
7
240,812
static function auth ( ProviderInterface $ provider ) { if ( ! require_get ( "code" , false ) ) { redirect ( $ provider -> getAuthorizationUrl ( ) ) ; return false ; } else { // optionally check for abuse etc if ( ! \ Openclerk \ Events :: trigger ( 'oauth2_auth' , $ provider ) ) { throw new UserAuthenticationException...
Execute OAuth2 authentication and return the user .
148
11
240,813
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 .
117
12
240,814
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 .
97
9
240,815
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
82
5
240,816
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
141
7
240,817
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
113
5
240,818
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
268
3
240,819
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
214
11
240,820
private function parseCondition ( $ condition , $ parameters = [ ] ) { if ( strpos ( $ condition , ' ' ) ) { $ match = preg_match ( '~^ (.+)\s ## identifier ( (?:\$\w+) | ## $mongoOperator (?:[A-Z]+(?:_[A-Z]+)*) | ## NAMED_OPERATOR or (?:[\<\>\!]?\=|\>|\<\>?) ## logical operator ) (?: \s%(\w+(?:\[\])?) | ## modifier or...
Parses single condition
559
5
240,821
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
126
5
240,822
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
248
6
240,823
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
127
8
240,824
protected function processArray ( $ modifier , array & $ values ) { foreach ( $ values as & $ item ) { $ item = $ this -> processModifier ( $ modifier , $ item ) ; } }
Applies modifier to the inner array via reference
44
9
240,825
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
116
9
240,826
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
425
12
240,827
public function CssJsFileUrl ( $ path = '' ) { $ result = '' ; if ( self :: $ assetsUrlCompletion ) { // for \MvcCore\Application::GetInstance()->GetCompiled() equal to: 'PHAR', 'SFU', 'PHP_STRICT_PACKAGE', 'PHP_PRESERVE_PACKAGE', 'PHP_PRESERVE_HDD' $ result = $ this -> view -> AssetUrl ( $ path ) ; } else { // for \Mv...
Completes CSS or JS file url .
162
9
240,828
protected function filterItemsForNotPossibleMinifiedAndPossibleMinifiedItems ( $ items ) { $ itemsToRenderMinimized = [ ] ; $ itemsToRenderSeparately = [ ] ; // some configurations is not possible to render together and minimized // go for every item to complete existing combinations in attributes foreach ( $ items as ...
Look for every item to render if there is any doNotMinify record to render item separately
358
19
240,829
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
224
10
240,830
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
109
3
240,831
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
207
11
240,832
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
72
17
240,833
protected function log ( $ msg = '' , $ logType = 'debug' ) { if ( self :: $ loggingAndExceptions ) { \ MvcCore \ Debug :: Log ( $ msg , $ logType ) ; } }
Log any render messages with optional log file name
48
9
240,834
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
62
11
240,835
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
112
12
240,836
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
130
4
240,837
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
170
7
240,838
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 .
122
9
240,839
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
65
10
240,840
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
83
10
240,841
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
59
12
240,842
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
235
5
240,843
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
64
8
240,844
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
90
7
240,845
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 .
296
5
240,846
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 .
131
6
240,847
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 .
92
18
240,848
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 .
72
25
240,849
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 .
62
17
240,850
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 .
179
17