idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
40,000 | public function actionSchedulerLog ( $ model , $ pk ) { return new ActiveDataProvider ( [ 'query' => Scheduler :: find ( ) -> where ( [ 'model_class' => $ model , 'primary_key' => $ pk ] ) , 'sort' => [ 'defaultOrder' => [ 'schedule_timestamp' => SORT_ASC ] ] , 'pagination' => false , ] ) ; } | Get all log entries for a given scheulder model with primary key . |
40,001 | public function actionSchedulerAdd ( ) { $ model = new Scheduler ( ) ; $ model -> attributes = Yii :: $ app -> request -> bodyParams ; if ( ! $ model -> hasTriggerPermission ( $ model -> model_class ) ) { throw new ForbiddenHttpException ( "Unable to schedule a task for the given model." ) ; } if ( $ model -> save ( ) ) { $ model -> pushQueue ( ) ; Yii :: $ app -> adminqueue -> run ( false ) ; Config :: set ( Config :: CONFIG_QUEUE_TIMESTAMP , time ( ) ) ; return $ model ; } return $ this -> sendModelError ( $ model ) ; } | Add a task to the scheduler . |
40,002 | public function actionSchedulerDelete ( $ id ) { $ job = Scheduler :: findOne ( $ id ) ; if ( $ job ) { return $ job -> delete ( ) ; } return false ; } | Remove a job for a given ID . |
40,003 | public function actionNgrestFilter ( ) { $ apiEndpoint = Yii :: $ app -> request -> getBodyParam ( 'apiEndpoint' ) ; $ filterName = Yii :: $ app -> request -> getBodyParam ( 'filterName' ) ; return Yii :: $ app -> adminuser -> identity -> setting -> set ( 'ngrestfilter.' . $ apiEndpoint , $ filterName ) ; } | Set the lastest ngrest filter selection in the User Settings . |
40,004 | public function actionNgrestOrder ( ) { $ apiEndpoint = Yii :: $ app -> request -> getBodyParam ( 'apiEndpoint' ) ; $ sort = Yii :: $ app -> request -> getBodyParam ( 'sort' ) ; $ field = Yii :: $ app -> request -> getBodyParam ( 'field' ) ; if ( $ sort == '-' ) { $ sort = SORT_DESC ; } else { $ sort = SORT_ASC ; } return Yii :: $ app -> adminuser -> identity -> setting -> set ( 'ngrestorder.' . $ apiEndpoint , [ 'sort' => $ sort , 'field' => $ field ] ) ; } | Set the lastest ngrest curd list order direction in the User Settings . |
40,005 | public function actionDataProperties ( ) { $ data = [ ] ; foreach ( Property :: find ( ) -> all ( ) as $ item ) { $ object = Property :: getObject ( $ item -> class_name ) ; $ data [ ] = [ 'id' => $ item -> id , 'var_name' => $ object -> varName ( ) , 'option_json' => $ object -> options ( ) , 'label' => $ object -> label ( ) , 'type' => $ object -> type ( ) , 'default_value' => $ object -> defaultValue ( ) , 'i18n' => $ object -> i18n , ] ; } return $ data ; } | Get all available administration regisetered properties . |
40,006 | public function actionCache ( ) { $ this -> flushHasCache ( ) ; $ user = Yii :: $ app -> adminuser -> identity ; $ user -> updateAttributes ( [ 'force_reload' => false ] ) ; Yii :: $ app -> trigger ( self :: EVENT_FLUSH_CACHE ) ; return true ; } | Triggerable action to flush the application cache and force user reload . |
40,007 | public function actionDataModules ( ) { $ data = [ ] ; foreach ( Yii :: $ app -> getFrontendModules ( ) as $ k => $ f ) { $ data [ ] = [ 'value' => $ k , 'label' => $ k ] ; } return $ data ; } | Get a list with all frontend modules which is used in several dropdowns in the admin ui . |
40,008 | public function actionSaveFilemanagerFolderState ( ) { $ folderId = Yii :: $ app -> request -> getBodyParam ( 'folderId' ) ; if ( $ folderId ) { return Yii :: $ app -> adminuser -> identity -> setting -> set ( 'filemanagerFolderId' , $ folderId ) ; } else { return Yii :: $ app -> adminuser -> identity -> setting -> remove ( 'filemanagerFolderId' ) ; } } | Save the last selected filemanager folder in the user settings . |
40,009 | public function actionFilemanagerFoldertreeHistory ( ) { $ this -> deleteHasCache ( 'storageApiDataFolders' ) ; $ data = Yii :: $ app -> request -> getBodyParam ( 'data' ) ; Yii :: $ app -> adminuser -> identity -> setting -> set ( 'foldertree.' . $ data [ 'id' ] , ( int ) $ data [ 'toggle_open' ] ) ; } | Store the open and closed folders from the filemanager tree in the user settings . |
40,010 | public function actionLastLogins ( ) { return UserLogin :: find ( ) -> select ( [ 'user_id' , 'max(timestamp_create) as maxdate' ] ) -> joinWith ( [ 'user' => function ( $ q ) { $ q -> select ( [ 'id' , 'firstname' , 'lastname' ] ) ; } ] ) -> limit ( 10 ) -> groupBy ( [ 'user_id' ] ) -> orderBy ( [ 'maxdate' => SORT_DESC ] ) -> asArray ( ) -> all ( ) ; } | Last User logins |
40,011 | public function getSetting ( ) { if ( $ this -> _setting === null ) { $ settingsArray = ( empty ( $ this -> settings ) ) ? [ ] : Json :: decode ( $ this -> settings ) ; $ this -> _setting = Yii :: createObject ( [ 'class' => UserSetting :: class , 'sender' => $ this , 'data' => $ settingsArray ] ) ; } return $ this -> _setting ; } | Get user settings objects . |
40,012 | private function generateToken ( $ length = 6 ) { $ token = Yii :: $ app -> security -> generateRandomString ( $ length ) ; $ replace = array_rand ( range ( 2 , 9 ) ) ; return str_replace ( [ '-' , '_' , 'l' , 1 ] , $ replace , strtolower ( $ token ) ) ; } | Generate an easy readable random token . |
40,013 | public function getAndStoreToken ( ) { $ token = $ this -> generateToken ( 6 ) ; $ this -> setAttribute ( 'secure_token' , sha1 ( $ token ) ) ; $ this -> setAttribute ( 'secure_token_timestamp' , time ( ) ) ; $ this -> update ( false ) ; return $ token ; } | Generate store and return the secure Login token . |
40,014 | public function encodePassword ( ) { if ( ! $ this -> validate ( [ 'password' ] ) ) { return false ; } $ this -> password_salt = Yii :: $ app -> getSecurity ( ) -> generateRandomString ( ) ; $ this -> password = Yii :: $ app -> getSecurity ( ) -> generatePasswordHash ( $ this -> password . $ this -> password_salt ) ; return true ; } | Encodes the current active record password field . |
40,015 | public function getTitleNamed ( ) { return ! isset ( self :: getTitles ( ) [ $ this -> title ] ) ? : self :: getTitles ( ) [ $ this -> title ] ; } | Get the title Mr Mrs . as string for the current user . |
40,016 | public function validatePassword ( $ password ) { return Yii :: $ app -> security -> validatePassword ( $ password . $ this -> password_salt , $ this -> password ) ; } | Validates the password for the current given user . |
40,017 | public function getAndStoreEmailVerificationToken ( ) { $ token = $ this -> generateToken ( 6 ) ; $ this -> updateAttributes ( [ 'email_verification_token' => sha1 ( $ token ) , 'email_verification_token_timestamp' => time ( ) , ] ) ; return $ token ; } | Generate and save a email verification token and return the token . |
40,018 | public function delete ( ) { if ( $ this -> beforeDelete ( ) ) { if ( ! Yii :: $ app -> storage -> fileSystemDeleteFile ( $ this -> name_new_compound ) ) { Logger :: error ( "Unable to remove file from filesystem: " . $ this -> name_new_compound ) ; } $ this -> updateAttributes ( [ 'is_deleted' => true ] ) ; $ this -> afterDelete ( ) ; return true ; } } | Delete a given file . |
40,019 | public function getCreateThumbnail ( ) { if ( ! $ this -> isImage ) { return false ; } $ tinyCrop = Yii :: $ app -> storage -> getFilterId ( TinyCrop :: identifier ( ) ) ; foreach ( $ this -> images as $ image ) { if ( $ image -> filter_id == $ tinyCrop ) { return [ 'source' => $ image -> source ] ; } } $ image = Yii :: $ app -> storage -> createImage ( $ this -> id , $ tinyCrop ) ; if ( $ image ) { return [ 'source' => $ image -> source ] ; } } | Create the thumbnail for this given file if its an image . |
40,020 | public function getCreateThumbnailMedium ( ) { if ( ! $ this -> isImage ) { return false ; } $ mediumThumbnail = Yii :: $ app -> storage -> getFilterId ( MediumThumbnail :: identifier ( ) ) ; foreach ( $ this -> images as $ image ) { if ( $ image -> filter_id == $ mediumThumbnail ) { return [ 'source' => $ image -> source ] ; } } $ image = Yii :: $ app -> storage -> createImage ( $ this -> id , $ mediumThumbnail ) ; if ( $ image ) { return [ 'source' => $ image -> source ] ; } } | Create the thumbnail medium for this given file if its an image . |
40,021 | public function findModel ( ) { $ model = StorageFilter :: find ( ) -> where ( [ 'identifier' => static :: identifier ( ) ] ) -> one ( ) ; if ( ! $ model ) { $ model = new StorageFilter ( ) ; $ model -> setAttributes ( [ 'name' => $ this -> name ( ) , 'identifier' => static :: identifier ( ) , ] ) ; $ model -> insert ( false ) ; $ this -> addLog ( "Added new filter '" . static :: identifier ( ) . "' with id '{$model->id}'." ) ; } return $ model ; } | Find the model based on the identifier . If the identifier does not exists in the database create new record in the database . |
40,022 | public function findEffect ( $ effectIdentifier ) { $ model = StorageEffect :: find ( ) -> where ( [ 'identifier' => $ effectIdentifier ] ) -> asArray ( ) -> one ( ) ; if ( ! $ model ) { throw new Exception ( "The requested effect '$effectIdentifier' does not exist." ) ; } return $ model ; } | Find the effect model based on the effect identifier . If the effect could not found an exception will be thrown . |
40,023 | public function getEffectParamsList ( $ effectParams ) { if ( $ this -> _effectParamsList === null ) { if ( ! array_key_exists ( 'vars' , $ effectParams ) ) { throw new Exception ( "Required 'vars' key not found in effect definition array." ) ; } foreach ( $ effectParams [ 'vars' ] as $ item ) { $ this -> _effectParamsList [ ] = $ item [ 'var' ] ; } } return $ this -> _effectParamsList ; } | Get an array with all the effect param options based on the effect params defintion . |
40,024 | public function getChain ( ) { $ data = [ ] ; foreach ( $ this -> chain ( ) as $ chainRow ) { $ effectIdentifier = $ chainRow [ 0 ] ; $ effectParams = $ chainRow [ 1 ] ; $ effect = $ this -> findEffect ( $ effectIdentifier ) ; foreach ( $ effectParams as $ effectParamVar => $ effectParamValue ) { if ( ! in_array ( $ effectParamVar , $ this -> getEffectParamsList ( Json :: decode ( $ effect [ 'imagine_json_params' ] ) ) ) ) { throw new Exception ( "Effect argument '$effectParamVar' does not exist in the effect definition of '{$effect['name']}'." ) ; } } $ data [ ] = [ 'effect_id' => $ effect [ 'id' ] , 'effect_json_values' => Json :: encode ( $ effectParams ) ] ; } return $ data ; } | Returns a parsed effect chain for the current Filter . The method verifys if the provieded effect parameters are available in the effect defintions of luya . |
40,025 | public function setServer ( ServerInterface $ server ) : void { $ this -> server = $ server ; $ this -> server -> configure ( $ this ) ; } | Change the server implementation |
40,026 | private static function parseDSN ( $ dsn ) { $ matches = [ ] ; if ( ! preg_match ( static :: DSN_REGEX , $ dsn , $ matches ) ) { throw new PDOException ( sprintf ( 'Invalid DSN %s' , $ dsn ) ) ; } return array_slice ( $ matches , 1 ) ; } | Extract servers and optional custom schema from DSN string |
40,027 | public static function toArray ( $ value ) { if ( is_array ( $ value ) ) { return $ value ; } if ( $ value === null ) { return [ ] ; } if ( ! $ value instanceof Traversable ) { throw new Exception \ InvalidArgumentException ( 'An invalid value was provided, should either be an null, array or Traversable' ) ; } return iterator_to_array ( $ value ) ; } | Convert a optional value that when used is expected to be an array |
40,028 | public function configure ( PDOInterface $ pdo ) : void { $ sslMode = $ pdo -> getAttribute ( PDO :: CRATE_ATTR_SSL_MODE ) ; $ protocol = $ sslMode === PDO :: CRATE_ATTR_SSL_MODE_DISABLED ? 'http' : 'https' ; $ options = [ RequestOptions :: TIMEOUT => $ pdo -> getAttribute ( PDO :: ATTR_TIMEOUT ) , RequestOptions :: CONNECT_TIMEOUT => $ pdo -> getAttribute ( PDO :: ATTR_TIMEOUT ) , RequestOptions :: AUTH => $ pdo -> getAttribute ( PDO :: CRATE_ATTR_HTTP_BASIC_AUTH ) ? : null , RequestOptions :: HEADERS => [ 'Default-Schema' => $ pdo -> getAttribute ( PDO :: CRATE_ATTR_DEFAULT_SCHEMA ) , ] , ] ; if ( $ sslMode === PDO :: CRATE_ATTR_SSL_MODE_ENABLED_BUT_WITHOUT_HOST_VERIFICATION ) { $ options [ 'verify' ] = false ; } $ ca = $ pdo -> getAttribute ( PDO :: CRATE_ATTR_SSL_CA_PATH ) ; $ caPassword = $ pdo -> getAttribute ( PDO :: CRATE_ATTR_SSL_CA_PASSWORD ) ; if ( $ ca ) { if ( $ caPassword ) { $ options [ RequestOptions :: VERIFY ] = [ $ ca , $ caPassword ] ; } else { $ options [ RequestOptions :: VERIFY ] = $ ca ; } } $ cert = $ pdo -> getAttribute ( PDO :: CRATE_ATTR_SSL_CERT_PATH ) ; $ certPassword = $ pdo -> getAttribute ( PDO :: CRATE_ATTR_SSL_CERT_PASSWORD ) ; if ( $ cert ) { if ( $ certPassword ) { $ options [ RequestOptions :: CERT ] = [ $ cert , $ certPassword ] ; } else { $ options [ RequestOptions :: CERT ] = $ cert ; } } $ key = $ pdo -> getAttribute ( PDO :: CRATE_ATTR_SSL_KEY_PATH ) ; $ keyPassword = $ pdo -> getAttribute ( PDO :: CRATE_ATTR_SSL_KEY_PASSWORD ) ; if ( $ key ) { if ( $ keyPassword ) { $ options [ RequestOptions :: SSL_KEY ] = [ $ key , $ keyPassword ] ; } else { $ options [ RequestOptions :: SSL_KEY ] = $ key ; } } $ this -> protocol = $ protocol ; $ this -> httpOptions = $ options ; } | Reconfigure the the server pool based on the attributes in PDO |
40,029 | private function updateBoundColumns ( array $ row ) { foreach ( $ this -> columnBinding as $ column => & $ metadata ) { $ index = $ this -> collection -> getColumnIndex ( $ column ) ; if ( $ index === null ) { continue ; } $ value = $ this -> typedValue ( $ row [ $ index ] , $ metadata [ 'type' ] ) ; $ metadata [ 'ref' ] = $ value ; } } | Update all the bound column references |
40,030 | private function getObjectResult ( array $ columns , array $ row ) { $ obj = new \ stdClass ( ) ; foreach ( $ columns as $ key => $ column ) { $ obj -> { $ column } = $ row [ $ key ] ; } return $ obj ; } | Generate object from array |
40,031 | private static function esc_sql_value ( $ values ) { $ quote = function ( $ v ) { if ( preg_match ( '/^[+-]?[0-9]{1,20}$/' , $ v ) ) { return esc_sql ( $ v ) ; } return "'" . esc_sql ( $ v ) . "'" ; } ; if ( is_array ( $ values ) ) { return array_map ( $ quote , $ values ) ; } return $ quote ( $ values ) ; } | Puts MySQL string values in single quotes to avoid them being interpreted as column names . |
40,032 | private function preg_error_message ( $ error ) { static $ error_names = null ; if ( null === $ error_names ) { $ definitions = get_defined_constants ( true ) ; $ pcre_constants = array_key_exists ( 'pcre' , $ definitions ) ? $ definitions [ 'pcre' ] : array ( ) ; $ error_names = array_flip ( $ pcre_constants ) ; } return isset ( $ error_names [ $ error ] ) ? $ error_names [ $ error ] : '<unknown error>' ; } | Get the PCRE error constant name from an error value . |
40,033 | protected function eventExpired ( $ event ) { $ cachedDiff = $ this -> getCachedEvent ( $ event ) -> diffInSeconds ( Carbon :: now ( ) ) ; return $ cachedDiff < $ this -> config ( 'root.cache.event_timeout' , 10 ) ; } | Check if the event has expired . |
40,034 | protected function getCachedEvent ( $ event ) { $ path = $ event -> getResource ( ) -> getPath ( ) ; return isset ( $ this -> eventCache [ $ path ] ) ? $ this -> eventCache [ $ path ] : $ this -> eventCache [ $ path ] = Carbon :: now ( ) -> subDay ( ) ; } | Get an event from cache . |
40,035 | protected function eventWasProcessed ( $ event ) { if ( $ this -> eventExpired ( $ event ) ) { return true ; } $ this -> resetEventCache ( $ event ) ; return false ; } | Check if the event was processed recently . |
40,036 | protected function firedOnlyOne ( $ event , $ path ) { if ( $ test = $ this -> dataRepository -> isTestFile ( $ path ) ) { if ( $ test -> sha1Changed ( ) && ! $ this -> dataRepository -> isEnqueued ( $ test ) ) { $ this -> dataRepository -> addTestToQueue ( $ test ) ; $ this -> showProgress ( 'QUEUE: test added to queue' ) ; } return true ; } return false ; } | Check if has changed and add test to queue . |
40,037 | protected function isConfig ( $ path ) { if ( $ this -> config ( ) -> isConfigFile ( $ path ) ) { $ this -> config ( ) -> invalidateConfig ( ) ; $ this -> loader -> loadEverything ( ) ; return true ; } return false ; } | Check if the changed file is the config file and reload . |
40,038 | public function run ( Command $ command , $ showTests = false ) { $ this -> setCommand ( $ command ) ; $ this -> initialize ( $ showTests ) ; $ this -> watch ( ) ; return true ; } | Watch for file changes . |
40,039 | protected function initialize ( $ showTests ) { $ this -> showComment ( $ this -> config ( 'root.names.watcher' ) , 'info' ) ; if ( ! $ this -> is_initialized ) { $ this -> loader -> loadEverything ( $ showTests ) ; $ this -> is_initialized = true ; } } | Initialize the Watcher . |
40,040 | protected function showEventMessage ( $ event , $ path ) { $ type = $ this -> config ( ) -> isConfigFile ( $ path ) ? 'CONFIGURATION' : 'FILE' ; $ change = strtoupper ( $ this -> getEventName ( $ event -> getCode ( ) ) ) ; $ this -> showProgress ( "{$type} {$change}: {$path}" , 'error' ) ; } | Display a message about the event on terminal . |
40,041 | protected function watch ( ) { $ this -> showProgress ( 'BOOT: booting watchers...' ) ; if ( is_null ( $ this -> loader -> watchFolders ) ) { $ this -> showProgress ( 'No watch folders found.' , 'error' ) ; return ; } foreach ( $ this -> loader -> watchFolders as $ folder ) { if ( ! file_exists ( $ folder ) ) { $ this -> showProgress ( "ERROR: folder {$folder} does not exists" , 'error' ) ; continue ; } $ this -> showProgress ( 'WATCHING ' . $ folder ) ; $ this -> listeners [ $ folder ] = $ this -> watcher -> watch ( $ folder ) ; $ this -> listeners [ $ folder ] -> anything ( function ( $ event , $ resource , $ path ) { if ( ! $ this -> isExcluded ( $ path ) ) { $ this -> fireEvent ( $ event , $ resource , $ path ) ; } } ) ; } $ this -> watchConfigFile ( ) ; $ this -> watcher -> start ( ) ; } | Watch folders for changes . |
40,042 | public function fireEvent ( $ event , $ resource , $ path ) { if ( $ this -> eventWasProcessed ( $ event , $ resource , $ path ) ) { return ; } $ this -> showEventMessage ( $ event , $ path ) ; if ( $ this -> isConfig ( $ path ) ) { return ; } if ( $ this -> firedOnlyOne ( $ event , $ path ) ) { return ; } $ this -> loader -> loadEverything ( ) ; if ( $ this -> queueTestSuites ( $ path ) ) { return ; } $ this -> dataRepository -> queueAllTests ( ) ; } | Fire file modified event . |
40,043 | protected function watchConfigFile ( ) { $ this -> showProgress ( 'WATCHING CONFIG FILES' ) ; $ this -> config ( ) -> getConfigFiles ( ) -> each ( function ( $ file ) { $ this -> watcher -> watch ( $ file ) ; } ) ; } | Watch the config file for changes . |
40,044 | protected function createLinkToEditFile ( $ test , $ fileName , $ line , $ occurrence ) { if ( ! $ this -> fileExistsOnTest ( $ fileName , $ test ) ) { return $ line [ $ occurrence ] ; } $ fileName = base64_encode ( $ fileName ) ; $ tag = sprintf ( '<a href="javascript:jQuery.get(\'%s\');" class="file">%s</a>' , route ( 'tests-watcher.file.edit' , [ 'filename' => $ fileName , 'suite_id' => $ test -> suite -> id , 'line' => $ line [ 2 ] , ] ) , $ line [ $ occurrence ] ) ; return $ tag ; } | Create link to call the editor for a file . |
40,045 | protected function createLinks ( $ lines , $ matches , $ test ) { foreach ( $ matches as $ line ) { if ( ! empty ( $ line ) && is_array ( $ line ) && count ( $ line ) > 0 && is_array ( $ line [ 0 ] ) && count ( $ line [ 0 ] ) > 0 ) { $ occurence = strpos ( $ lines , $ line [ 0 ] ) === false ? 1 : 0 ; $ lines = str_replace ( $ line [ $ occurence ] , $ this -> createLinkToEditFile ( $ test , $ line [ 1 ] , $ line , $ occurence ) , $ lines ) ; } } return $ lines ; } | Create links . |
40,046 | protected function findSourceCodeReferences ( $ lines , $ test ) { preg_match_all ( config ( 'tddd.root.regex_file_matcher' ) , strip_tags ( $ this -> brToCR ( $ lines ) ) , $ matches , PREG_SET_ORDER ) ; return array_filter ( $ matches ) ; } | Find source code references . |
40,047 | protected function getEditor ( $ suite ) { if ( empty ( $ suite ) || is_null ( $ editor = config ( "tddd.editors.{$suite->editor}" ) ) ) { return $ this -> getDefaultEditor ( ) ; } return $ editor ; } | Get the editor . |
40,048 | public function getJavascriptClientData ( ) { $ data = [ 'routes' => [ 'prefixes' => config ( 'tddd.routes.prefixes' ) , ] , 'project_id' => request ( ) -> get ( 'project_id' ) , 'test_id' => request ( ) -> get ( 'test_id' ) , 'root' => config ( 'tddd.root' ) , ] ; return json_encode ( $ data ) ; } | Generates data for the javascript client . |
40,049 | protected function getScreenshots ( $ test , $ log ) { $ screenshots = $ test -> suite -> tester -> name !== 'dusk' ? $ this -> getOutput ( $ test , $ test -> suite -> tester -> output_folder , $ test -> suite -> tester -> output_png_fail_extension ) : $ this -> parseDuskScreenshots ( $ log , $ test -> suite -> tester -> output_folder ) ; if ( is_null ( $ screenshots ) ) { return ; } $ screenshots = collect ( $ screenshots ) -> map ( function ( $ path ) use ( $ test ) { return replace_suite_paths ( $ test -> suite , $ path ) ; } ) ; return json_encode ( $ screenshots -> toArray ( ) ) ; } | Get a list of png files to store in database . |
40,050 | protected function linkFiles ( $ lines , $ test ) { $ matches = $ this -> findSourceCodeReferences ( $ lines , $ test ) ; if ( count ( $ matches ) != 0 ) { $ lines = $ this -> createLinks ( $ lines , $ matches , $ test ) ; } return $ this -> CRToBr ( $ lines ) ; } | Create links for files . |
40,051 | protected function parseDuskScreenshots ( $ log , $ folder ) { preg_match_all ( '/[0-9]\)+\s(.+::.*)/' , $ log , $ matches , PREG_SET_ORDER ) ; $ result = [ ] ; foreach ( $ matches as $ line ) { $ name = str_replace ( "\r" , '' , $ line [ 1 ] ) ; $ name = str_replace ( '\\' , '_' , $ name ) ; $ name = str_replace ( '::' , '_' , $ name ) ; $ result [ ] = $ folder . DIRECTORY_SEPARATOR . "failure-{$name}-0.png" ; } return count ( $ result ) == 0 ? null : $ result ; } | Generate a lista of screenshots . |
40,052 | public function isExcluded ( $ exclusions , $ path , $ file = '' ) { if ( $ file ) { if ( ! $ file instanceof SplFileInfo ) { $ path = make_path ( [ $ path , $ file ] ) ; } else { $ path = $ file -> getPathname ( ) ; } } foreach ( $ exclusions ? : [ ] as $ excluded ) { if ( starts_with ( $ path , $ excluded ) ) { return true ; } } return false ; } | Check if a path is excluded . |
40,053 | public function formatLog ( $ log , $ test ) { return ! empty ( $ log ) ? $ this -> linkFiles ( $ this -> ansi2Html ( $ log ) , $ test ) : $ log ; } | Format output log . |
40,054 | protected function ansi2Html ( $ log ) { $ string = html_entity_decode ( $ this -> ansiConverter -> convert ( $ log ) ) ; $ string = str_replace ( "\r\n" , '<br>' , $ string ) ; $ string = str_replace ( "\n" , '<br>' , $ string ) ; return $ string ; } | Convert output ansi chars to html . |
40,055 | protected function getOutput ( $ test , $ outputFolder , $ extension ) { if ( empty ( $ outputFolder ) ) { return ; } $ file = replace_suite_paths ( $ test -> suite , make_path ( [ make_path ( [ $ test -> suite -> project -> path , $ outputFolder ] ) , str_replace ( [ '.php' , '::' , '\\' , '/' ] , [ '' , '.' , '' , '' ] , $ test -> name ) . $ extension , ] ) ) ; return file_exists ( $ file ) ? $ this -> renderHtml ( file_get_contents ( $ file ) ) : null ; } | Get the test output . |
40,056 | protected function encodeFile ( $ file ) { $ type = pathinfo ( $ file , PATHINFO_EXTENSION ) ; $ data = file_get_contents ( $ file ) ; if ( $ type == 'html' ) { return $ data ; } return 'data:image/' . $ type . ';base64,' . base64_encode ( $ data ) ; } | Encode a image or html for database storage . |
40,057 | public function makeEditFileCommand ( $ file , $ line , $ suite_id ) { $ suite = $ this -> findSuiteById ( $ suite_id ) ; $ file = $ this -> addProjectRootPath ( base64_decode ( $ file ) , $ suite ) ; $ command = trim ( str_replace ( [ '{file}' , '{line}' ] , [ $ file , $ line ] , $ this -> getEditorBinary ( $ suite ) ) ) ; return ends_with ( $ command , ':' ) ? substr ( $ command , 0 , - 1 ) : $ command ; } | Make open file command . |
40,058 | public function addProjectRootPath ( $ fileName , $ suite ) { if ( starts_with ( $ fileName , DIRECTORY_SEPARATOR ) || empty ( $ suite ) ) { return $ fileName ; } return $ suite -> project -> path . DIRECTORY_SEPARATOR . $ fileName ; } | Add project root to path . |
40,059 | public function normalizePath ( $ path ) { $ path = trim ( $ path ) ; $ path = str_replace ( DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR , DIRECTORY_SEPARATOR , $ path ) ; if ( ends_with ( $ path , DIRECTORY_SEPARATOR ) ) { $ path = substr ( $ path , 0 , - 1 ) ; } return $ path ; } | Normalize a path removing inconsistences . |
40,060 | public function put ( $ key , $ value , $ minutes = 525600 ) { $ this -> getCacheInstance ( ) -> put ( $ key , $ value , $ minutes ) ; return $ value ; } | Put a value to the cache store . |
40,061 | protected function getCacheInstance ( ) { if ( ! $ this -> cache ) { $ this -> cache = app ( $ this -> config ( 'root.cache.instance' ) ) ; } return $ this -> cache ; } | Get the cache instance . |
40,062 | public function notify ( $ project_id ) { $ this -> notifier -> notifyViaChannels ( $ this -> getProjectTests ( $ project_id ) -> reject ( function ( $ item ) { return $ item [ 'state' ] != 'failed' && is_null ( $ item [ 'notified_at' ] ) ; } ) ) ; } | Notify users . |
40,063 | public function deleteMissingProjects ( $ projects ) { foreach ( Project :: all ( ) as $ project ) { if ( ! in_array ( $ project -> name , $ projects ) ) { $ project -> delete ( ) ; } } } | Delete unavailable projects . |
40,064 | public function projectSha1HasChanged ( ) { $ currentSha1 = sha1 ( $ projectsJson = $ this -> getProjects ( ) -> toJson ( ) ) ; $ oldSha1 = app ( 'tddd.cache' ) -> get ( Constants :: CACHE_PROJECTS_KEY ) ; if ( $ hasChanged = $ currentSha1 != $ oldSha1 ) { app ( 'tddd.cache' ) -> put ( Constants :: CACHE_PROJECTS_KEY , sha1 ( $ projectsJson ) ) ; } return $ hasChanged ; } | Get a SHA1 for all projects . |
40,065 | public function getProjectState ( $ tests ) { if ( $ tests -> contains ( 'state' , 'running' ) ) { return 'running' ; } if ( $ tests -> contains ( 'state' , 'queued' ) ) { return 'queued' ; } if ( $ tests -> contains ( 'state' , 'failed' ) ) { return 'failed' ; } if ( $ tests -> every ( 'state' , 'ok' ) ) { return 'ok' ; } return 'idle' ; } | The the project state . |
40,066 | protected function enableProject ( $ enable , $ project ) { $ project -> timestamps = false ; $ project -> enabled = $ enable ; $ project -> save ( ) ; } | Enable a test . |
40,067 | public function reset ( $ project_id = null ) { foreach ( $ this -> queryTests ( $ project_id ) -> get ( ) as $ test ) { $ this -> resetTest ( $ test ) ; } } | Run all tests or projects tests . |
40,068 | public function toggleAll ( ) { Project :: all ( ) -> each ( function ( $ project ) { $ this -> enableProject ( ! $ project -> enabled , $ project ) ; } ) ; } | Toggle the enabled state of all projects . |
40,069 | public function loadConfig ( ) { if ( $ this -> configIsValid ( ) ) { return ; } $ this -> yaml -> loadToConfig ( $ this -> getConfigPath ( ) , 'tddd' , true ) -> toArray ( ) ; } | Load the config . |
40,070 | public function getConfigPath ( ) { if ( is_null ( $ this -> configPath ) ) { $ this -> configPath = replace_laravel_paths ( config ( 'tddd-base.path' ) ) ; } return $ this -> configPath ; } | Get the config path . |
40,071 | public function set ( $ data ) { $ this -> config = array_merge ( $ data , $ this -> config ) ; $ this -> mergeWithLaravelConfig ( ) ; } | Set the config item . |
40,072 | public function isEnqueued ( $ test ) { return $ test -> state == Constants :: STATE_QUEUED && QueueModel :: where ( 'test_id' , $ test -> id ) -> first ( ) ; } | Is the test in the queue? |
40,073 | public function boot ( ) { $ this -> publishConfiguration ( ) ; $ this -> loadConfig ( ) ; $ this -> loadMigrations ( ) ; $ this -> loadRoutes ( ) ; $ this -> loadViews ( ) ; } | Boot Service Provider . |
40,074 | protected function registerConfig ( ) { $ config = $ this -> config = app ( 'PragmaRX\Tddd\Package\Services\Config' ) ; $ this -> app -> singleton ( 'tddd.config' , function ( ) use ( $ config ) { return $ config ; } ) ; } | Register service tester . |
40,075 | public function on ( $ event , Closure $ callback ) { if ( ! in_array ( $ event , [ '*' , 'modify' , 'delete' , 'create' ] ) ) { throw new RuntimeException ( 'Could not bind to unknown event ' . $ event ) ; } $ this -> registerBinding ( $ event , $ callback ) ; } | Bind to a given event . |
40,076 | public function getBindings ( $ binding = null ) { if ( is_null ( $ binding ) ) { return $ this -> bindings ; } return $ this -> bindings [ $ binding ] ; } | Get the bindings or a specific array of bindings . |
40,077 | public function determineEventBinding ( Event $ event ) { switch ( $ event -> getCode ( ) ) { case Event :: RESOURCE_DELETED : return 'delete' ; break ; case Event :: RESOURCE_CREATED : return 'create' ; break ; case Event :: RESOURCE_MODIFIED : return 'modify' ; break ; } } | Determine the binding for a given event . |
40,078 | public function exec ( $ command , $ runDir = null , Closure $ callback = null , $ timeout = null ) { $ process = new Process ( $ command , $ runDir ) ; $ process -> setTimeout ( $ timeout ) ; $ this -> startedAt = Carbon :: now ( ) ; $ process -> run ( $ callback ) ; $ this -> endedAt = Carbon :: now ( ) ; return $ process ; } | Execute one command . |
40,079 | private function createSuite ( $ suite_name , $ project , $ suite_data ) { $ this -> showProgress ( " -- suite '{$suite_name}'" ) ; if ( ! $ this -> dataRepository -> createOrUpdateSuite ( $ suite_name , $ project -> id , $ suite_data ) ) { $ this -> displayMessages ( $ this -> dataRepository -> getMessages ( ) ) ; die ; } } | Create or update the suite . |
40,080 | public function loadEverything ( $ showTests = false ) { $ this -> showProgress ( 'Config loaded from ' . Config :: getConfigPath ( ) ) ; $ this -> loadTesters ( ) ; $ this -> loadProjects ( ) ; $ this -> loadTests ( $ showTests ) ; } | Read configuration and load testers projects suites ... |
40,081 | public function loadProjects ( ) { $ this -> showProgress ( 'Loading projects and suites...' , 'info' ) ; if ( ! is_arrayable ( $ projects = $ this -> config ( 'projects' ) ) or count ( $ projects ) == 0 ) { $ this -> showProgress ( 'No projects found.' , 'error' ) ; return ; } foreach ( $ projects as $ data ) { $ this -> showProgress ( "Project '{$data['name']}'" , 'comment' ) ; $ project = $ this -> dataRepository -> createOrUpdateProject ( $ data [ 'name' ] , $ data [ 'path' ] , $ data [ 'tests_path' ] ) ; $ this -> refreshProjectSuites ( $ data , $ project ) ; $ this -> addToWatchFolders ( $ data [ 'path' ] , $ data [ 'watch_folders' ] ) ; $ this -> addToExclusions ( $ data [ 'path' ] , $ data [ 'exclude' ] ) ; } $ this -> dataRepository -> deleteMissingProjects ( collect ( $ this -> config ( 'projects' ) ) -> pluck ( 'name' ) -> toArray ( ) ) ; } | Load all projects to database . |
40,082 | public function addToWatchFolders ( $ path , $ watch_folders ) { collect ( $ watch_folders ) -> each ( function ( $ folder ) use ( $ path ) { $ this -> watchFolders [ ] = ! file_exists ( $ new = make_path ( [ $ path , $ folder ] ) ) && file_exists ( $ folder ) ? $ folder : $ new ; } ) ; } | Add folders to the watch list . |
40,083 | public function addToExclusions ( $ path , $ exclude ) { collect ( $ exclude ) -> each ( function ( $ folder ) use ( $ path ) { $ this -> exclusions [ ] = $ excluded = make_path ( [ $ path , $ folder ] ) ; $ this -> showProgress ( "EXCLUDED: {$excluded}" ) ; } ) ; } | Add path to exclusions list . |
40,084 | private function refreshProjectSuites ( $ data , $ project ) { $ this -> dataRepository -> removeMissingSuites ( $ suites = $ data [ 'suites' ] , $ project ) ; collect ( $ suites ) -> map ( function ( $ data , $ name ) use ( $ project ) { $ this -> createSuite ( $ name , $ project , $ data ) ; } ) ; } | Refresh all suites for a project . |
40,085 | protected function config ( $ key = null , $ default = null ) { if ( is_null ( $ key ) ) { return app ( 'tddd.config' ) ; } return ConfigFacade :: get ( $ key , $ default ) ; } | Get a configuration key . |
40,086 | protected function displayMessages ( $ messages ) { $ fatal = $ messages -> reduce ( function ( $ carry , $ message ) { $ prefix = $ message [ 'type' ] == 'error' ? 'FATAL ERROR: ' : '' ; $ this -> command -> { $ message [ 'type' ] } ( $ prefix . $ message [ 'body' ] ) ; if ( $ message [ 'type' ] == 'error' ) { return true ; } return $ carry ; } ) ; if ( $ fatal == true ) { die ; } } | Display messages in terminal . |
40,087 | protected function setCommand ( $ command ) { $ this -> command = $ command ; if ( ! is_null ( $ this -> loader ) ) { $ this -> loader -> setCommand ( $ this -> command ) ; } } | Set the command . |
40,088 | public function drawLine ( $ len = 80 ) { if ( is_string ( $ len ) ) { $ len = strlen ( $ len ) ; } $ this -> line ( str_repeat ( '-' , max ( $ len , 80 ) ) ) ; } | Draw a line in console . |
40,089 | public function editFile ( $ fileName , $ suite_id , $ line = null ) { $ this -> executor -> exec ( $ command = $ this -> dataRepository -> makeEditFileCommand ( $ fileName , $ line , $ suite_id ) ) ; return $ this -> success ( ) ; } | Open a file in the editor . |
40,090 | public function register ( ResourceInterface $ resource , Listener $ listener ) { $ this -> tracked [ $ resource -> getKey ( ) ] = [ $ resource , $ listener ] ; } | Register a resource with the tracker . |
40,091 | public function checkTrackings ( ) { foreach ( $ this -> tracked as $ name => $ tracked ) { list ( $ resource , $ listener ) = $ tracked ; if ( ! $ events = $ resource -> detectChanges ( ) ) { continue ; } foreach ( $ events as $ event ) { if ( $ event instanceof Event ) { $ this -> callListenerBindings ( $ listener , $ event ) ; } } } } | Detect any changes on the tracked resources . |
40,092 | protected function callListenerBindings ( Listener $ listener , Event $ event ) { $ binding = $ listener -> determineEventBinding ( $ event ) ; if ( $ listener -> hasBinding ( $ binding ) ) { foreach ( $ listener -> getBindings ( $ binding ) as $ callback ) { $ resource = $ event -> getResource ( ) ; call_user_func ( $ callback , $ resource , $ resource -> getPath ( ) ) ; } } if ( $ listener -> hasBinding ( '*' ) ) { foreach ( $ listener -> getBindings ( '*' ) as $ callback ) { $ resource = $ event -> getResource ( ) ; call_user_func ( $ callback , $ event , $ resource , $ resource -> getPath ( ) ) ; } } } | Call the bindings on the listener for a given event . |
40,093 | public function watch ( $ resource ) { if ( ! $ this -> files -> exists ( $ resource ) ) { throw new RuntimeException ( 'Resource must exist before you can watch it.' ) ; } elseif ( $ this -> files -> isDirectory ( $ resource ) ) { $ resource = new DirectoryResource ( new SplFileInfo ( $ resource ) , $ this -> files ) ; $ resource -> setupDirectory ( ) ; } else { $ resource = new FileResource ( new SplFileInfo ( $ resource ) , $ this -> files ) ; } $ listener = new Listener ( ) ; $ this -> tracker -> register ( $ resource , $ listener ) ; return $ listener ; } | Register a resource to be watched . |
40,094 | public function startWatch ( $ interval = 1000000 , $ timeout = null , Closure $ callback = null ) { $ this -> watching = true ; $ timeWatching = 0 ; while ( $ this -> watching ) { if ( is_callable ( $ callback ) ) { call_user_func ( $ callback , $ this ) ; } usleep ( $ interval ) ; $ this -> tracker -> checkTrackings ( ) ; $ timeWatching += $ interval ; if ( ! is_null ( $ timeout ) and $ timeWatching >= $ timeout ) { $ this -> stopWatch ( ) ; } } } | Start watching for a given interval . The interval and timeout and measured in microseconds so 1 000 000 microseconds is equal to 1 second . |
40,095 | public function start ( $ interval = 1000000 , $ timeout = null , Closure $ callback = null ) { $ this -> startWatch ( $ interval , $ timeout , $ callback ) ; } | Alias of startWatch . |
40,096 | public function run ( Request $ request ) { $ this -> dataRepository -> runProjectTests ( $ request -> get ( 'projects' ) ) ; return $ this -> success ( ) ; } | Run project tests . |
40,097 | public function reset ( Request $ request ) { $ this -> dataRepository -> reset ( $ request -> get ( 'projects' ) ) ; return $ this -> success ( ) ; } | Reset projects tests states . |
40,098 | public function createOrUpdateSuite ( $ name , $ project_id , $ suite_data ) { $ project_id = $ project_id instanceof Project ? $ project_id -> id : $ project_id ; if ( is_null ( $ tester = Tester :: where ( 'name' , $ suite_data [ 'tester' ] ) -> first ( ) ) ) { $ this -> addMessage ( "Tester {$suite_data['tester']} not found." , 'error' ) ; return false ; } return Suite :: updateOrCreate ( [ 'name' => $ name , 'project_id' => $ project_id , ] , [ 'tester_id' => $ tester -> id , 'tests_path' => array_get ( $ suite_data , 'tests_path' ) , 'command_options' => array_get ( $ suite_data , 'command_options' ) , 'file_mask' => array_get ( $ suite_data , 'file_mask' ) , 'retries' => array_get ( $ suite_data , 'retries' ) , 'editor' => array_get ( $ suite_data , 'editor' ) , 'coverage_enabled' => array_get ( $ suite_data , 'coverage.enabled' , false ) , 'coverage_index' => array_get ( $ suite_data , 'coverage.index' ) , ] ) ; } | Create or update a suite . |
40,099 | public function removeMissingSuites ( $ suites , $ project ) { Suite :: where ( 'project_id' , $ project -> id ) -> whereNotIn ( 'name' , collect ( $ suites ) -> keys ( ) ) -> each ( function ( $ suite ) { $ suite -> delete ( ) ; } ) ; } | Remove suites that are not in present in config . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.