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\\DependencyInjection\\SimpleXMLElement' ) ; $ parsedConfig = [ ] ; /** @var \Symfony\Component\DependencyInjection\SimpleXMLElement $smartyFilterDefinition */ foreach ( $ xml -> smartyfilter as $ smartyFilterDefinition ) { $ descriptive = [ ] ; /** @var \Symfony\Component\DependencyInjection\SimpleXMLElement $descriptiveDefinition */ foreach ( $ smartyFilterDefinition -> descriptive as $ descriptiveDefinition ) { $ descriptive [ ] = [ 'locale' => $ descriptiveDefinition -> getAttributeAsPhp ( 'locale' ) , 'title' => ( string ) $ descriptiveDefinition -> title , 'description' => ( string ) $ descriptiveDefinition -> description , 'type' => ( string ) $ descriptiveDefinition -> type ] ; } $ parsedConfig [ 'smarty_filter' ] [ ] = [ 'code' => $ smartyFilterDefinition -> getAttributeAsPhp ( 'code' ) , 'descriptive' => $ descriptive ] ; } return $ parsedConfig ; }
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 [ 'code' ] ) ; foreach ( $ smartyFilterData [ 'descriptive' ] as $ descriptiveData ) { $ smartyFilter -> setLocale ( $ descriptiveData [ 'locale' ] ) -> setTitle ( $ descriptiveData [ 'title' ] ) -> setDescription ( $ descriptiveData [ 'description' ] ) -> setFiltertype ( $ descriptiveData [ 'type' ] ) ; } $ smartyFilter -> save ( ) ; } } }
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 ( ! $ this -> validateToken ( $ token ) ) { return false ; } return true ; }
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' ) ) { return false ; } if ( ! isset ( $ args [ 'app_key' ] ) or $ args [ 'app_key' ] !== env ( 'APP_KEY' ) ) { return false ; } return true ; }
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_' . snake_case ( $ query ) ; $ formated = [ ] ; try { //$formated = Cache::remember($cacheKey, 5, function() use($query) { $ datatables = config ( 'search.datatables' , [ ] ) ; foreach ( $ datatables as $ classname ) { $ datatable = $ this -> getDatatableInstance ( $ classname ) ; if ( ! $ datatable ) { continue ; } request ( ) -> merge ( [ 'inline_search' => [ 'value' => $ query , 'regex' => false ] ] ) ; $ formated = array_merge ( $ formated , app ( 'antares-search-row-decorator' ) -> setDatatable ( $ datatable ) -> getRows ( ) ) ; } if ( empty ( $ formated ) ) { $ formated [ ] = [ 'content' => '<div class="type--datarow"><div class="datarow__left"><span>No results found...</span></div></div>' , 'url' => '#' , 'category' => '' , 'total' => 0 ] ; } $ jsonResponse = new JsonResponse ( $ formated , 200 ) ; } catch ( Exception $ e ) { $ jsonResponse = new JsonResponse ( [ 'message' => $ e -> getMessage ( ) ] , 500 ) ; } $ jsonResponse -> send ( ) ; return exit ( ) ; }
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 ( 'antares.extension' ) -> getActiveExtensionByPath ( $ filename ) ) { return false ; } } return $ datatable ; }
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 should be used instead of the admin store id - should be // available in the session $ storeEnv = $ quoteSession -> getStore ( ) ; } return $ storeEnv -> getId ( ) ; }
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 ( ) ] = $ param -> getName ( ) ; } } return $ dependencies ; }
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 [ $ interface ] = $ this -> $ memberName ; } return $ dependencies ; }
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 ) ; } $ endpoint = implode ( '/' , [ 'repos' , rawurlencode ( $ username ) , rawurlencode ( $ repository ) , 'tarball' , rawurlencode ( $ commit ) , ] ) ; $ options = [ 'sink' => new LazyOpenStream ( $ targetFile , 'w+' ) , ] ; try { $ response = $ this -> guzzle -> request ( 'GET' , $ endpoint , $ options ) ; } catch ( Exception $ e ) { throw new VCSException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } return ( $ response -> getStatusCode ( ) === 200 ) ; }
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 ( "Login was cancelled by the system." ) ; } $ token = $ provider -> getAccessToken ( 'authorization_code' , array ( 'code' => require_get ( "code" ) , ) ) ; // now find the relevant user return $ provider -> getUserDetails ( $ token ) ; } }
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 ( array ( $ user -> getId ( ) , $ provider , $ uid ) ) ; }
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 $ query ; }
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 -> files [ ] = array ( 'file' => $ fileInfo , 'preserve' => $ preserve ) ; $ this -> filesystem -> chmod ( $ fileInfo , 0600 ) ; return $ fileInfo ; }
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 ) ; $ this -> filesystem -> chmod ( $ fileInfo , 0600 ) ; return $ fileInfo ; }
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 [ $ index ] ) ; continue ; } $ ckey = substr ( $ index , 1 ) ; if ( $ ckey === 'unset' ) { $ data [ $ index ] = array_fill_keys ( array_values ( ( array ) $ value ) , '' ) ; } elseif ( in_array ( $ ckey , [ 'setOnInsert' , 'addToSet' , 'push' ] ) ) { $ data [ $ index ] = $ this -> processData ( $ value ) ; } } if ( empty ( $ data [ $ set ] ) ) { unset ( $ data [ $ set ] ) ; } else { $ data [ $ set ] = $ this -> processData ( $ data [ $ set ] ) ; } return $ data ; }
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 condition!' ) ; } if ( is_array ( $ condition ) ) { $ parsed = array_merge ( $ parsed , $ this -> processCondition ( $ condition , $ depth + 1 ) ) ; } else { $ parsed [ ] = $ this -> parseCondition ( $ condition ) ; } } else { $ parsed [ ] = $ this -> parseCondition ( $ key , $ condition ) ; } } return $ depth > 0 ? $ parsed : ( count ( $ parsed ) > 1 ? [ $ this -> formatCmd ( 'and' ) => $ parsed ] : $ parsed [ 0 ] ) ; }
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 \s(.+) ## value )?$~xs' , $ condition , $ cond ) ; //['cond IN' => [...]], ['cond = %s' => 'param'], ['cond $gt' => 20] if ( ! empty ( $ match ) ) { if ( substr ( $ cond [ 1 ] , 0 , 1 ) === $ this -> cmd ) { throw new InvalidArgumentException ( "Field name cannot start with '{$this->cmd}'" ) ; } if ( $ parameters === [ ] && ! isset ( $ cond [ 4 ] ) ) { throw new InvalidArgumentException ( "Missing value for item '{$cond[1]}'" ) ; } return $ this -> formatCondition ( $ cond [ 1 ] , trim ( $ cond [ 2 ] , $ this -> cmd ) , isset ( $ cond [ 4 ] ) ? $ cond [ 4 ] : $ parameters , isset ( $ cond [ 3 ] ) ? $ cond [ 3 ] : NULL ) ; } } if ( $ parameters === [ ] ) { throw new InvalidArgumentException ( "Missing value for item '{$condition}'" ) ; } if ( is_array ( $ parameters ) && ( $ value = reset ( $ parameters ) ) ) { //['$cond' => $param[]] if ( substr ( $ condition , 0 , 1 ) === $ this -> cmd ) { return [ $ condition => $ this -> parseDeepCondition ( $ parameters , TRUE ) ] ; } //['cond' => ['param', ...]] if ( substr ( $ key = key ( $ parameters ) , 0 , 1 ) !== $ this -> cmd ) { return $ this -> formatCondition ( $ condition , 'IN' , $ parameters ) ; } //['cond' => ['$param' => [...]]] if ( is_array ( $ value ) ) { return [ $ condition => [ $ key => $ this -> parseDeepCondition ( $ value ) ] ] ; } } // [cond => param] return [ $ condition => $ parameters ] ; }
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 ( $ ccond ) ; $ opcond [ key ( $ ccond ) ] = current ( $ ccond ) ; } } return $ opcond ; }
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 -> processModifier ( $ parts [ 2 ] , $ item ) ; } elseif ( $ item instanceof \ DateTime || $ item instanceof \ DateTimeImmutable ) { $ item = $ this -> processModifier ( 'dt' , $ item ) ; } elseif ( is_array ( $ item ) ) { $ item = $ this -> processData ( $ item ) ; } if ( $ expand && strpos ( $ key , '.' ) !== FALSE ) { Helpers :: expandRow ( $ return , $ key , $ item ) ; } else { $ return [ $ key ] = $ item ; } } return $ return ; }
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 ) : $ value ) ; return '/' . $ value . '/i' ; }
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 :: class , SessionOptions :: class => SessionOptionsFactory :: class , SessionMiddleware :: class => SessionMiddlewareFactory :: class , ] , 'abstract_factories' => [ ContainerAbstractServiceFactory :: class , ] ] ; }
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 :: $ scriptName = ltrim ( $ this -> request -> GetScriptName ( ) , '/.' ) ; $ app = $ view -> GetController ( ) -> GetApplication ( ) ; $ configClass = $ app -> GetConfigClass ( ) ; self :: $ loggingAndExceptions = $ configClass :: IsDevelopment ( TRUE ) ; $ mvcCoreCompiledMode = $ app -> GetCompiled ( ) ; self :: $ ctrlActionKey = $ this -> request -> GetControllerName ( ) . '/' . $ this -> request -> GetActionName ( ) ; // file checking is true only for classic development mode, not for single file mode if ( ! $ mvcCoreCompiledMode ) self :: $ fileChecking = TRUE ; // file rendering is true for classic development state, SFU app mode if ( ! $ mvcCoreCompiledMode || $ mvcCoreCompiledMode == 'SFU' ) { self :: $ fileRendering = TRUE ; } if ( is_null ( self :: $ assetsUrlCompletion ) ) { // set URL addresses completion to true by default for: // - all package modes outside PHP_STRICT_HDD and outside development if ( $ mvcCoreCompiledMode && $ mvcCoreCompiledMode != 'PHP_STRICT_HDD' ) { self :: $ assetsUrlCompletion = TRUE ; } else { self :: $ assetsUrlCompletion = FALSE ; } } self :: $ systemConfigHash = md5 ( json_encode ( self :: $ globalOptions ) ) ; return $ this ; }
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 \MvcCore\Application::GetInstance()->GetCompiled() equal to: '' (development), 'PHP_STRICT_HDD' $ result = self :: $ basePath . $ path ; } return $ result ; }
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 & $ item ) { $ itemArr = array_merge ( ( array ) $ item , [ ] ) ; unset ( $ itemArr [ 'path' ] ) ; if ( isset ( $ itemArr [ 'render' ] ) ) unset ( $ itemArr [ 'render' ] ) ; if ( isset ( $ itemArr [ 'external' ] ) ) unset ( $ itemArr [ 'external' ] ) ; $ renderArrayKey = md5 ( json_encode ( $ itemArr ) ) ; if ( $ itemArr [ 'doNotMinify' ] ) { if ( isset ( $ itemsToRenderSeparately [ $ renderArrayKey ] ) ) { $ itemsToRenderSeparately [ $ renderArrayKey ] [ ] = $ item ; } else { $ itemsToRenderSeparately [ $ renderArrayKey ] = [ $ item ] ; } } else { if ( isset ( $ itemsToRenderMinimized [ $ renderArrayKey ] ) ) { $ itemsToRenderMinimized [ $ renderArrayKey ] [ ] = $ item ; } else { $ itemsToRenderMinimized [ $ renderArrayKey ] = [ $ item ] ; } } } return [ $ itemsToRenderMinimized , $ itemsToRenderSeparately , ] ; }
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 ( $ strippedUrl , strlen ( self :: $ basePath ) ) ; if ( self :: $ globalOptions [ 'fileChecking' ] == 'filemtime' ) { $ fileMTime = self :: getFileImprint ( $ srcPath ) ; $ url .= $ separator . '_fmt=' . date ( self :: FILE_MODIFICATION_DATE_FORMAT , ( int ) $ fileMTime ) ; } else { $ url .= $ separator . '_md5=' . self :: getFileImprint ( $ srcPath ) ; } return $ url ; }
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 { @ chmod ( $ tmpDir , 0777 ) ; } catch ( \ Exception $ e ) { $ selfClass = version_compare ( PHP_VERSION , '5.5' , '>' ) ? self :: class : __CLASS__ ; throw new \ Exception ( '[' . $ selfClass . '] ' . $ e -> getMessage ( ) ) ; } } } self :: $ tmpDir = $ tmpDir ; } return self :: $ tmpDir ; }
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 ) , '.' . $ extension ] ) ; }
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 ] ) ; } while ( count ( $ this -> currentJobs ) ) { sleep ( $ this -> sleepTime ) ; } }
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 ] ) ) { $ this -> childSignalHandler ( SIGCHLD , $ pid , $ this -> signalQueue [ $ pid ] ) ; unset ( $ this -> signalQueue [ $ pid ] ) ; } } else { $ exitStatus = 0 ; //Error code if you need to or whatever exit ( $ exitStatus ) ; } return true ; }
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 ( $ row ) ; } return $ tableAndViewNames ; }
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 ) , \ RecursiveIteratorIterator :: SELF_FIRST | \ FilesystemIterator :: CURRENT_AS_FILEINFO | \ FilesystemIterator :: SKIP_DOTS ) ; foreach ( $ iterator as $ item ) { if ( in_array ( $ item -> getFilename ( ) , array ( '.' , '..' ) ) ) { continue ; } if ( $ item -> isDir ( ) ) { $ ok = self :: remove ( $ item ) ; } else { $ ok = @ unlink ( $ item ) ; } } if ( $ ok && $ parent ) { @ rmdir ( $ path ) ; } @ clearstatcache ( ) ; } return $ ok ; }
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 . '/' . $ filename . '.php' ; if ( file_exists ( $ path ) ) { throw new MigrationFileInvalidException ( sprintf ( 'Migration file [%s] exists.' , $ filename ) ) ; } $ templateTags [ 'phx:class' ] = Helper :: getQualifiedClassName ( $ filename ) ; $ builder = new TemplateBuilder ( $ this -> cmd , $ this -> env ) ; $ builder -> createClassTemplate ( 'migration' , $ filename , $ migrationsDirectory , $ templateTags ) ; // After migration class has been created, the record needs to go to the database and be set to pending. $ model = new Model ( ) ; $ model -> class_name = $ templateTags [ 'phx:class' ] ; $ model -> status = Attribute :: STATUS_PENDING ; $ model -> path = $ path ; $ model -> save ( ) ; $ this -> env -> sendOutput ( 'Created migration is now pending' , 'green' ) ; }
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 ( $ arguments [ 1 ] ) && $ arguments [ 1 ] == '--down' ) { self :: $ migrationType = Attribute :: DOWNGRADE ; } $ this -> migrator -> runSingleMigration ( $ migration ) ; }
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 , $ lastmodified ) ; }
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' => ( int ) $ basename , 'file' => $ file , 'size' => filesize ( $ file ) ] ; } , glob ( $ this -> blocks . "*" ) ) ) ; uasort ( $ files , function ( $ a , $ b ) { return $ a [ 'offset' ] - $ b [ 'offset' ] ; } ) ; return $ files ; }
Returns all the wrote blocks of files . All the blocks are sorted by their offset .
179
17