idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
51,300
public function copyAll ( $ source , $ destination , array $ skip = [ '.git' , '.DS_Store' ] , $ override = false ) { if ( is_dir ( $ source ) && ! is_dir ( $ destination ) ) { if ( ! mkdir ( $ destination , 0755 , true ) ) { throw new \ RuntimeException ( "Failed to create directory: " . $ destination ) ; } } if ( is_...
Copy all files and folders between directories .
51,301
public function symlink ( $ target , $ link ) { if ( ! file_exists ( $ target ) ) { throw new \ InvalidArgumentException ( 'Target not found: ' . $ target ) ; } if ( $ this -> relative ) { $ target = $ this -> makePathRelative ( $ target , dirname ( $ link ) ) ; } $ this -> fs -> symlink ( $ target , $ link , $ this ->...
Create a symbolic link to a file or directory .
51,302
protected function inBlacklist ( $ filename , array $ blacklist ) { foreach ( $ blacklist as $ pattern ) { if ( fnmatch ( $ pattern , $ filename , FNM_PATHNAME | FNM_CASEFOLD ) ) { return true ; } } return false ; }
Check if a filename is in the blacklist .
51,303
public function symlinkAll ( $ source , $ destination , $ skipExisting = true , $ recursive = false , $ blacklist = [ ] , $ copy = false ) { if ( ! is_dir ( $ destination ) ) { mkdir ( $ destination ) ; } $ source = realpath ( $ source ) ; $ skip = [ '.git' , '.DS_Store' ] ; $ skip = array_merge ( $ skip , $ blacklist ...
Symlink or copy all files and folders between two directories .
51,304
public function makePathAbsolute ( $ relativePath ) { if ( file_exists ( $ relativePath ) && ! is_link ( $ relativePath ) && ( $ realPath = realpath ( $ relativePath ) ) ) { $ absolute = $ realPath ; } else { $ parent = dirname ( $ relativePath ) ; if ( ! is_dir ( $ parent ) || ! ( $ parentRealPath = realpath ( $ paren...
Make a relative path into an absolute one .
51,305
public function writeFile ( $ filename , $ contents , $ backup = true ) { $ fs = new SymfonyFilesystem ( ) ; if ( file_exists ( $ filename ) && $ backup && $ contents !== file_get_contents ( $ filename ) ) { $ backupName = dirname ( $ filename ) . '/' . basename ( $ filename ) . '.bak' ; $ fs -> rename ( $ filename , $...
Write a file and create a backup if the contents have changed .
51,306
public function archiveDir ( $ dir , $ destination ) { $ tar = $ this -> getTarExecutable ( ) ; $ dir = $ this -> fixTarPath ( $ dir ) ; $ destination = $ this -> fixTarPath ( $ destination ) ; $ this -> shell -> execute ( [ $ tar , '-czp' , '-C' . $ dir , '-f' . $ destination , '.' ] , null , true ) ; }
Create a gzipped tar archive of a directory s contents .
51,307
public function extractArchive ( $ archive , $ destination ) { if ( ! file_exists ( $ archive ) ) { throw new \ InvalidArgumentException ( "Archive not found: $archive" ) ; } if ( ! file_exists ( $ destination ) && ! mkdir ( $ destination , 0755 , true ) ) { throw new \ InvalidArgumentException ( "Could not create dest...
Extract a gzipped tar archive into the specified destination directory .
51,308
protected function fixTarPath ( $ path ) { if ( OsUtil :: isWindows ( ) ) { $ path = preg_replace_callback ( '#^([A-Z]):/#i' , function ( array $ matches ) { return '/' . strtolower ( $ matches [ 1 ] ) . '/' ; } , str_replace ( '\\' , '/' , $ path ) ) ; } return $ path ; }
Fix a path so that it can be used with tar on Windows .
51,309
private function getAccessToken ( $ authCode , $ redirectUri , $ tokenUrl ) { return ( new Client ( ) ) -> post ( $ tokenUrl , [ 'json' => [ 'grant_type' => 'authorization_code' , 'code' => $ authCode , 'client_id' => $ this -> config ( ) -> get ( 'api.oauth2_client_id' ) , 'redirect_uri' => $ redirectUri , ] , 'auth' ...
Exchange the authorization code for an access token .
51,310
private function getCollections ( array $ service , $ sshUrl ) { $ relationshipsService = $ this -> getService ( 'relationships' ) ; $ ssh = $ this -> getService ( 'ssh' ) ; $ shell = $ this -> getService ( 'shell' ) ; $ js = 'printjson(db.getCollectionNames())' ; $ command = 'mongo ' . $ relationshipsService -> getDbC...
Get collections in the MongoDB database .
51,311
public function setOutput ( OutputInterface $ output ) { $ this -> output = $ output ; $ this -> stdErr = $ output instanceof ConsoleOutputInterface ? $ output -> getErrorOutput ( ) : $ output ; }
Change the output object .
51,312
public function executeSimple ( $ commandline , $ dir = null , array $ env = [ ] ) { $ this -> stdErr -> writeln ( 'Running command: <info>' . $ commandline . '</info>' , OutputInterface :: VERBOSITY_VERBOSE ) ; if ( ! empty ( $ env ) ) { $ this -> showEnvMessage ( $ env ) ; $ env = $ env + $ this -> getParentEnv ( ) ;...
Execute a command using STDIN STDERR and STDOUT directly .
51,313
protected function getParentEnv ( ) { if ( PHP_VERSION_ID >= 70100 ) { return getenv ( ) ; } if ( ! empty ( $ _ENV ) && stripos ( ini_get ( 'variables_order' ) , 'e' ) !== false ) { return $ _ENV ; } $ candidates = [ 'TERM' , 'TERM_SESSION_ID' , 'TMPDIR' , 'SSH_AGENT_PID' , 'SSH_AUTH_SOCK' , 'PATH' , 'LANG' , 'LC_ALL' ...
Attempt to read useful environment variables from the parent process .
51,314
protected function runProcess ( Process $ process , $ mustRun = false , $ quiet = true ) { try { $ process -> mustRun ( $ quiet ? null : function ( $ type , $ buffer ) { $ output = $ type === Process :: ERR ? $ this -> stdErr : $ this -> output ; $ output -> write ( preg_replace ( '/^/m' , ' ' , $ buffer ) ) ; } ) ; }...
Run a process .
51,315
protected function findWhere ( $ command , $ noticeOnError = true ) { static $ result ; if ( ! isset ( $ result [ $ command ] ) ) { if ( is_executable ( $ command ) ) { $ result [ $ command ] = $ command ; } else { $ args = [ 'command' , '-v' , $ command ] ; if ( OsUtil :: isWindows ( ) ) { $ args = [ 'where' , $ comma...
Run where or equivalent on a command .
51,316
public function resolveCommand ( $ command ) { if ( $ fullPaths = $ this -> findWhere ( $ command ) ) { $ fullPaths = preg_split ( '/[\r\n]/' , trim ( $ fullPaths ) ) ; $ command = end ( $ fullPaths ) ; } return $ command ; }
Find the absolute path to an executable .
51,317
protected function loadTokenFromFile ( $ filename ) { if ( strpos ( $ filename , '/' ) !== 0 && strpos ( $ filename , '\\' ) !== 0 ) { $ filename = $ this -> config -> getUserConfigDir ( ) . '/' . $ filename ; } $ content = file_get_contents ( $ filename ) ; if ( $ content === false ) { throw new \ RuntimeException ( '...
Load an API token from a file .
51,318
protected function getUserAgent ( ) { return sprintf ( '%s/%s (%s; %s; PHP %s)' , str_replace ( ' ' , '-' , $ this -> config -> get ( 'application.name' ) ) , $ this -> config -> getVersion ( ) , php_uname ( 's' ) , php_uname ( 'r' ) , PHP_VERSION ) ; }
Get an HTTP User Agent string representing this application .
51,319
public function getClient ( $ autoLogin = true , $ reset = false ) { if ( ! isset ( self :: $ client ) || $ reset ) { $ connectorOptions = [ ] ; $ connectorOptions [ 'accounts' ] = rtrim ( $ this -> config -> get ( 'api.accounts_api_url' ) , '/' ) . '/' ; $ connectorOptions [ 'verify' ] = ! $ this -> config -> get ( 'a...
Get the API client object .
51,320
public function getProjects ( $ refresh = null ) { $ cacheKey = sprintf ( '%s:projects' , $ this -> sessionId ) ; $ projects = [ ] ; $ cached = $ this -> cache -> fetch ( $ cacheKey ) ; if ( $ refresh === false && ! $ cached ) { return [ ] ; } elseif ( $ refresh || ! $ cached ) { foreach ( $ this -> getClient ( ) -> ge...
Return the user s projects .
51,321
public function getProject ( $ id , $ host = null , $ refresh = null ) { $ projects = $ this -> getProjects ( $ refresh ) ; if ( isset ( $ projects [ $ id ] ) ) { return $ projects [ $ id ] ; } $ cacheKey = sprintf ( '%s:project:%s:%s' , $ this -> sessionId , $ id , $ host ) ; $ cached = $ this -> cache -> fetch ( $ ca...
Return the user s project with the given ID .
51,322
public function getEnvironments ( Project $ project , $ refresh = null , $ events = true ) { $ projectId = $ project -> id ; if ( ! $ refresh && isset ( self :: $ environmentsCache [ $ projectId ] ) ) { return self :: $ environmentsCache [ $ projectId ] ; } $ cacheKey = 'environments:' . $ projectId ; $ cached = $ this...
Return the user s environments .
51,323
public function getEnvironment ( $ id , Project $ project , $ refresh = null , $ tryMachineName = false ) { $ cacheKey = $ project -> id . ':' . $ id . ( $ tryMachineName ? ':mn' : '' ) ; if ( ! $ refresh && isset ( self :: $ notFound [ $ cacheKey ] ) ) { return false ; } $ environments = $ this -> getEnvironments ( $ ...
Get a single environment .
51,324
public function getMyAccount ( $ reset = false ) { $ cacheKey = sprintf ( '%s:my-account' , $ this -> sessionId ) ; if ( $ reset || ! ( $ info = $ this -> cache -> fetch ( $ cacheKey ) ) ) { $ info = $ this -> getClient ( ) -> getAccountInfo ( $ reset ) ; $ this -> cache -> save ( $ cacheKey , $ info , $ this -> config...
Get the current user s account info .
51,325
public function getAccount ( ProjectAccess $ user , $ reset = false ) { if ( isset ( self :: $ accountsCache [ $ user -> id ] ) && ! $ reset ) { return self :: $ accountsCache [ $ user -> id ] ; } $ cacheKey = 'account:' . $ user -> id ; if ( $ reset || ! ( $ details = $ this -> cache -> fetch ( $ cacheKey ) ) ) { $ de...
Get a user s account info .
51,326
public function clearEnvironmentsCache ( $ projectId ) { $ this -> cache -> delete ( 'environments:' . $ projectId ) ; unset ( self :: $ environmentsCache [ $ projectId ] ) ; foreach ( array_keys ( self :: $ notFound ) as $ key ) { if ( strpos ( $ key , $ projectId . ':' ) === 0 ) { unset ( self :: $ notFound [ $ key ]...
Clear the environments cache for a project .
51,327
public function clearProjectsCache ( ) { $ this -> cache -> delete ( sprintf ( '%s:projects' , $ this -> sessionId ) ) ; $ this -> cache -> delete ( sprintf ( '%s:my-account' , $ this -> sessionId ) ) ; }
Clear the projects cache .
51,328
public static function getNestedProperty ( ApiResource $ resource , $ propertyPath , $ lazyLoad = true ) { if ( ! strpos ( $ propertyPath , '.' ) ) { return $ resource -> getProperty ( $ propertyPath , true , $ lazyLoad ) ; } $ parents = explode ( '.' , $ propertyPath ) ; $ propertyName = array_shift ( $ parents ) ; $ ...
Get a nested property of a resource via a dot - separated string path .
51,329
public function getProjectLabel ( Project $ project , $ tag = 'info' ) { $ title = $ project -> title ; $ pattern = strlen ( $ title ) > 0 ? '%2$s (%3$s)' : '%3$s' ; if ( $ tag !== false ) { $ pattern = strlen ( $ title ) > 0 ? '<%1$s>%2$s</%1$s> (%3$s)' : '<%1$s>%3$s</%1$s>' ; } return sprintf ( $ pattern , $ tag , $ ...
Returns a project label .
51,330
public function getEnvironmentLabel ( Environment $ environment , $ tag = 'info' ) { $ id = $ environment -> id ; $ title = $ environment -> title ; $ use_title = strlen ( $ title ) > 0 && $ title !== $ id ; $ pattern = $ use_title ? '%2$s (%3$s)' : '%3$s' ; if ( $ tag !== false ) { $ pattern = $ use_title ? '<%1$s>%2$...
Returns an environment label .
51,331
public function matchPartialId ( $ id , array $ resources , $ name = 'Resource' ) { $ matched = array_filter ( $ resources , function ( ApiResource $ resource ) use ( $ id ) { return strpos ( $ resource -> getProperty ( 'id' ) , $ id ) === 0 ; } ) ; if ( count ( $ matched ) > 1 ) { $ matchedIds = array_map ( function (...
Get a resource matching on the beginning of the ID .
51,332
public function getAccessToken ( ) { $ session = $ this -> getClient ( ) -> getConnector ( ) -> getSession ( ) ; $ token = $ session -> get ( 'accessToken' ) ; $ expires = $ session -> get ( 'expires' ) ; if ( ! $ token || $ expires < time ( ) ) { $ this -> getMyAccount ( true ) ; if ( ! $ token = $ session -> get ( 'a...
Returns the OAuth 2 access token .
51,333
public function urlSort ( $ a , $ b ) { $ result = 0 ; foreach ( [ $ a , $ b ] as $ key => $ url ) { if ( parse_url ( $ url , PHP_URL_SCHEME ) === 'https' ) { $ result += $ key === 0 ? - 2 : 2 ; } } $ result += strlen ( $ a ) <= strlen ( $ b ) ? - 1 : 1 ; return $ result ; }
Sort URLs preferring shorter ones with HTTPS .
51,334
public function getCurrentDeployment ( Environment $ environment , $ refresh = false ) { $ cacheKey = implode ( ':' , [ 'current-deployment' , $ environment -> project , $ environment -> id ] ) ; $ data = $ this -> cache -> fetch ( $ cacheKey ) ; if ( $ data === false || $ refresh ) { $ deployment = $ environment -> ge...
Get the current deployment for an environment .
51,335
public function getDefaultEnvironmentId ( array $ environments ) { if ( count ( $ environments ) <= 1 ) { $ environment = reset ( $ environments ) ; return $ environment ? $ environment -> id : null ; } $ main = array_filter ( $ environments , function ( Environment $ environment ) { return $ environment -> is_main ; }...
Get the default environment in a list .
51,336
public function getSiteUrl ( Environment $ environment , $ appName , EnvironmentDeployment $ deployment = null ) { $ deployment = $ deployment ? : $ this -> getCurrentDeployment ( $ environment ) ; $ routes = $ deployment -> routes ; $ appUrls = [ ] ; foreach ( $ routes as $ url => $ route ) { if ( $ route -> type === ...
Get the preferred site URL for an environment and app .
51,337
private function on403 ( ErrorEvent $ event ) { $ url = $ event -> getRequest ( ) -> getUrl ( ) ; $ path = parse_url ( $ url , PHP_URL_PATH ) ; if ( $ path && strpos ( $ path , '/api/projects/' ) === 0 ) { if ( preg_match ( '#^/api/projects/([^/]+?)/environments/#' , $ path , $ matches ) ) { $ this -> clearEnvironments...
React on an API 403 request .
51,338
public function identify ( $ url ) { $ result = $ this -> parseProjectId ( $ url ) ; if ( empty ( $ result [ 'projectId' ] ) && strpos ( $ url , '.' ) !== false ) { $ result = $ this -> identifyFromHeaders ( $ url ) ; } if ( empty ( $ result [ 'projectId' ] ) ) { throw new InvalidArgumentException ( 'Failed to identify...
Identify a project from an ID or URL .
51,339
private function identifyFromHeaders ( $ url ) { if ( ! strpos ( $ url , '.' ) ) { throw new \ InvalidArgumentException ( 'Invalid URL: ' . $ url ) ; } if ( strpos ( $ url , '//' ) === false ) { $ url = 'https://' . $ url ; } $ result = [ 'projectId' => null , 'environmentId' => null ] ; $ cluster = $ this -> getCluste...
Identify a project and environment from a URL s response headers .
51,340
private function getClusterHeader ( $ url ) { $ cacheKey = 'project-cluster:' . $ url ; $ cluster = $ this -> cache ? $ this -> cache -> fetch ( $ cacheKey ) : false ; if ( $ cluster === false ) { $ this -> debug ( 'Making a HEAD request to identify project from URL: ' . $ url ) ; try { $ response = $ this -> api -> ge...
Get a project cluster from its URL .
51,341
protected function getRequestedLevel ( InputInterface $ input ) { $ str = $ input -> getOption ( 'level' ) ; if ( empty ( $ str ) ) { return null ; } foreach ( [ self :: LEVEL_PROJECT , self :: LEVEL_ENVIRONMENT ] as $ validLevel ) { if ( stripos ( $ validLevel , $ str ) === 0 ) { return $ validLevel ; } } throw new In...
Get the requested variable level .
51,342
protected function getExistingVariable ( $ name , $ level = null , $ messages = true ) { $ output = $ messages ? $ this -> stdErr : new NullOutput ( ) ; if ( $ level === self :: LEVEL_ENVIRONMENT || ( $ this -> hasSelectedEnvironment ( ) && $ level === null ) ) { $ variable = $ this -> getSelectedEnvironment ( ) -> get...
Finds an existing variable by name .
51,343
protected function displayVariable ( ApiResource $ variable ) { $ table = $ this -> getService ( 'table' ) ; $ formatter = $ this -> getService ( 'property_formatter' ) ; $ properties = $ variable -> getProperties ( ) ; $ properties [ 'level' ] = $ this -> getVariableLevel ( $ variable ) ; $ headings = [ ] ; $ values =...
Display a variable to stdout .
51,344
protected function showDialogChecklist ( array $ options , $ text = 'Choose item(s)' ) { $ width = 80 ; $ height = 20 ; $ listHeight = 20 ; $ command = sprintf ( 'dialog --separate-output --checklist %s %d %d %d' , escapeshellarg ( $ text ) , $ height , $ width , $ listHeight ) ; foreach ( $ options as $ tag => $ optio...
Show a checklist using the dialog utility .
51,345
protected function getAllProjects ( InputInterface $ input ) { $ projects = $ this -> api ( ) -> getProjects ( ) ; if ( $ input -> getOption ( 'sort' ) ) { $ this -> api ( ) -> sortResources ( $ projects , $ input -> getOption ( 'sort' ) ) ; } if ( $ input -> getOption ( 'reverse' ) ) { $ projects = array_reverse ( $ p...
Get a list of the user s projects sorted according to the input .
51,346
protected function getSelectedProjects ( InputInterface $ input ) { $ projectList = $ input -> getOption ( 'projects' ) ; $ identifier = $ this -> getService ( 'identifier' ) ; if ( ! empty ( $ projectList ) ) { $ missing = [ ] ; $ selected = [ ] ; foreach ( $ this -> splitProjectList ( $ projectList ) as $ projectId )...
Get the projects selected by the user .
51,347
private function psqlQuery ( array $ database ) { $ query = 'SELECT' . ' sum(pg_relation_size(pg_class.oid))::bigint AS size' . ' FROM pg_class' . ' LEFT OUTER JOIN pg_namespace ON (pg_namespace.oid = pg_class.relnamespace)' . ' GROUP BY pg_class.relkind, nspname' . ' ORDER BY sum(pg_relation_size(pg_class.oid)) DESC;'...
Returns a command to query disk usage for a PostgreSQL database .
51,348
private function mysqlQuery ( array $ database ) { $ query = 'SELECT' . ' (' . 'SUM(data_length+index_length+data_free)' . ' + (COUNT(*) * 300 * 1024)' . ')' . '/' . ( 1048576 + 150 ) . ' AS estimated_actual_disk_usage' . ' FROM information_schema.tables' ; $ relationships = $ this -> getService ( 'relationships' ) ; $...
Returns a command to query disk usage for a MySQL database .
51,349
protected function adaptRows ( ) { $ maxColumnWidths = $ this -> getMaxColumnWidths ( ) ; $ this -> setRows ( $ this -> adaptCells ( $ this -> rowsCopy , $ maxColumnWidths ) ) ; }
Adapt rows based on the terminal width .
51,350
protected function adaptCells ( array $ rows , array $ maxColumnWidths ) { foreach ( $ rows as $ rowNum => & $ row ) { if ( $ row instanceof TableSeparator ) { continue ; } foreach ( $ row as $ column => & $ cell ) { $ cellWidth = $ this -> getCellWidth ( $ cell ) ; if ( $ cellWidth > $ maxColumnWidths [ $ column ] ) {...
Modify table rows wrapping their cells content to the max column width .
51,351
protected function wrapCell ( $ contents , $ width ) { if ( strpos ( $ contents , ' ' ) === 0 ) { $ trimmed = ltrim ( $ contents , ' ' ) ; $ indent = Helper :: strlen ( $ contents ) - Helper :: strlen ( $ trimmed ) ; return str_repeat ( ' ' , $ indent ) . $ this -> wrapWithDecoration ( $ trimmed , $ width - $ indent ) ...
Word - wrap the contents of a cell so that they fit inside a max width .
51,352
public function putEnv ( $ destination , array $ dependencies ) { $ env = [ ] ; $ paths = [ ] ; foreach ( $ dependencies as $ stack => $ stackDependencies ) { $ manager = $ this -> getManager ( $ stack ) ; $ path = $ destination . '/' . $ stack ; $ paths = array_merge ( $ paths , $ manager -> getBinPaths ( $ path ) ) ;...
Modify the environment to make the installed dependencies available .
51,353
public function installDependencies ( $ destination , array $ dependencies , $ global = false ) { $ success = true ; foreach ( $ dependencies as $ stack => $ stackDependencies ) { $ manager = $ this -> getManager ( $ stack ) ; $ this -> output -> writeln ( sprintf ( "Installing <info>%s</info> dependencies with '%s': %...
Install dependencies into a directory .
51,354
protected function getManager ( $ name ) { if ( strpos ( 'python' , $ name ) === 0 ) { return new DependencyManager \ Pip ( $ this -> shell ) ; } $ stacks = [ 'nodejs' => new DependencyManager \ Npm ( $ this -> shell ) , 'ruby' => new DependencyManager \ Bundler ( $ this -> shell ) , 'php' => new DependencyManager \ Co...
Finds the right dependency manager for a given stack .
51,355
protected function suggestSshRemedies ( ) { $ sshKeys = [ ] ; try { $ sshKeys = $ this -> api ( ) -> getClient ( false ) -> getSshKeys ( ) ; } catch ( \ Exception $ e ) { } if ( ! empty ( $ sshKeys ) ) { $ this -> stdErr -> writeln ( '' ) ; $ this -> stdErr -> writeln ( 'Please check your SSH credentials' ) ; $ this ->...
Suggest SSH key commands for the user if the Git connection fails .
51,356
public static function getPort ( $ start = 3000 , $ hostname = null , $ end = null ) { $ end = $ end ? : $ start + 30 ; for ( $ port = $ start ; $ port <= $ end ; $ port ++ ) { if ( static :: validatePort ( $ port ) && ! static :: isPortInUse ( $ port , $ hostname ) ) { return $ port ; } } throw new \ Exception ( sprin...
Get the next available valid port .
51,357
public static function validatePort ( $ port ) { if ( ! is_numeric ( $ port ) || $ port <= 1023 || $ port > 65535 ) { return false ; } return ! in_array ( $ port , self :: $ unsafePorts ) ; }
Validate a port number .
51,358
public static function isPortInUse ( $ port , $ hostname = null ) { $ fp = @ fsockopen ( $ hostname !== null ? $ hostname : '127.0.0.1' , $ port , $ errno , $ errstr , 10 ) ; if ( $ fp !== false ) { fclose ( $ fp ) ; return true ; } return false ; }
Check whether a port is open .
51,359
public function build ( array $ settings , $ sourceDir , $ destination = null , array $ apps = [ ] ) { $ this -> settings = $ settings ; $ this -> fsHelper -> setRelativeLinks ( empty ( $ settings [ 'abslinks' ] ) ) ; if ( file_exists ( $ sourceDir . '/.git' ) ) { ( new LocalProject ( ) ) -> writeGitExclude ( $ sourceD...
Build a project from any source directory targeting any destination .
51,360
public function getTreeId ( $ appRoot ) { $ hashes = [ ] ; $ tree = $ this -> gitHelper -> execute ( [ 'ls-files' , '-s' ] , $ appRoot ) ; if ( $ tree === false ) { return false ; } $ tree = preg_replace ( '#^|\n[^\n]+?' . preg_quote ( $ this -> config -> get ( 'service.project_config_dir' ) ) . '\n|$#' , "\n" , $ tree...
Get a hash of the application files .
51,361
protected function runPostBuildHooks ( array $ appConfig , $ buildDir ) { if ( ! isset ( $ appConfig [ 'hooks' ] [ 'build' ] ) ) { return null ; } if ( ! empty ( $ this -> settings [ 'no-build-hooks' ] ) ) { $ this -> output -> writeln ( 'Skipping post-build hooks' ) ; return null ; } $ this -> output -> writeln ( 'Run...
Run post - build hooks .
51,362
protected function runDeployHooks ( array $ appConfig , $ appDir ) { if ( empty ( $ this -> settings [ 'run-deploy-hooks' ] ) ) { return null ; } if ( empty ( $ appConfig [ 'hooks' ] [ 'deploy' ] ) && empty ( $ appConfig [ 'hooks' ] [ 'post_deploy' ] ) ) { $ this -> output -> writeln ( 'No deploy or post_deploy hooks f...
Run deploy and post_deploy hooks .
51,363
protected function runHook ( $ hook , $ dir ) { $ code = $ this -> shellHelper -> executeSimple ( implode ( "\n" , ( array ) $ hook ) , $ dir ) ; if ( $ code !== 0 ) { $ this -> output -> writeln ( "<comment>The hook failed with the exit code: $code</comment>" ) ; return false ; } return true ; }
Run a user - defined hook .
51,364
public function cleanBuilds ( $ projectRoot , $ maxAge = null , $ keepMax = 10 , $ includeActive = false , $ quiet = true ) { $ blacklist = [ ] ; if ( ! $ includeActive ) { $ blacklist = $ this -> getActiveBuilds ( $ projectRoot ) ; } return $ this -> cleanDirectory ( $ projectRoot . '/' . $ this -> config -> get ( 'lo...
Remove old builds .
51,365
public function cleanArchives ( $ projectRoot , $ maxAge = null , $ keepMax = 10 , $ quiet = true ) { return $ this -> cleanDirectory ( $ projectRoot . '/' . $ this -> config -> get ( 'local.archive_dir' ) , $ maxAge , $ keepMax , [ ] , $ quiet ) ; }
Remove old build archives .
51,366
protected function cleanDirectory ( $ directory , $ maxAge = null , $ keepMax = 5 , array $ blacklist = [ ] , $ quiet = true ) { if ( ! is_dir ( $ directory ) ) { return [ 0 , 0 ] ; } $ files = glob ( $ directory . '/*' ) ; if ( ! $ files ) { return [ 0 , 0 ] ; } usort ( $ files , function ( $ a , $ b ) { return filemt...
Remove old files from a directory .
51,367
public function getLocalWebRoot ( $ destination = null ) { $ destination = $ destination ? : $ this -> getSourceDir ( ) . '/' . $ this -> cliConfig -> get ( 'local.web_root' ) ; if ( $ this -> isSingle ( ) ) { return $ destination ; } return $ destination . '/' . str_replace ( '/' , '-' , $ this -> getId ( ) ) ; }
Get the absolute path to the local web root of this app .
51,368
private function getConfigObject ( ) { if ( ! isset ( $ this -> config ) ) { $ config = [ ] ; $ file = $ this -> appRoot . '/' . $ this -> cliConfig -> get ( 'service.app_config_file' ) ; if ( file_exists ( $ file ) ) { $ config = ( array ) ( new YamlParser ( ) ) -> parseFile ( $ file ) ; } $ this -> config = new AppCo...
Get the application s configuration as an object .
51,369
public function getBuildFlavor ( ) { $ appConfig = $ this -> getConfig ( ) ; if ( ! isset ( $ appConfig [ 'type' ] ) ) { throw new InvalidConfigException ( 'Application configuration key not found: `type`' ) ; } $ key = isset ( $ appConfig [ 'build' ] [ 'flavor' ] ) ? $ appConfig [ 'build' ] [ 'flavor' ] : 'default' ; ...
Get the build flavor for the application .
51,370
public static function getApplications ( $ directory , Config $ config = null ) { $ finder = new Finder ( ) ; $ config = $ config ? : new Config ( ) ; $ finder -> in ( $ directory ) -> ignoreDotFiles ( false ) -> name ( $ config -> get ( 'service.app_config_file' ) ) -> ignoreUnreadableDirs ( ) -> exclude ( [ '.idea' ,...
Get a list of applications in a directory .
51,371
public function shouldMoveToRoot ( ) { $ config = $ this -> getConfig ( ) ; if ( isset ( $ config [ 'move_to_root' ] ) && $ config [ 'move_to_root' ] === true ) { return true ; } return $ this -> getDocumentRoot ( ) === 'public' && ! is_dir ( $ this -> getRoot ( ) . '/public' ) ; }
Check whether the whole app should be moved into the document root .
51,372
private function getTagDate ( $ tagName ) { $ git = $ this -> getService ( 'git' ) ; $ date = $ git -> execute ( [ 'log' , '-1' , '--format=%aI' , 'refs/tags/' . $ tagName ] ) ; return is_string ( $ date ) ? strtotime ( trim ( $ date ) ) : false ; }
Returns the commit date associated with a tag .
51,373
private function hasGitDifferences ( $ since ) { $ git = $ this -> getService ( 'git' ) ; $ stat = $ git -> execute ( [ 'diff' , '--numstat' , $ since . '...HEAD' ] , CLI_ROOT , true ) ; if ( ! is_string ( $ stat ) ) { return false ; } foreach ( explode ( "\n" , trim ( $ stat ) ) as $ line ) { if ( strpos ( $ line , ' ...
Checks if there are relevant Git differences since the last version .
51,374
public function readProjectConfigFile ( $ dir , $ configFile ) { $ result = null ; $ filename = $ dir . '/' . $ this -> config -> get ( 'service.project_config_dir' ) . '/' . $ configFile ; if ( file_exists ( $ filename ) ) { $ parser = new Parser ( ) ; $ result = $ parser -> parse ( file_get_contents ( $ filename ) ) ...
Read a config file for a project .
51,375
public function ensureGitRemote ( $ dir , $ url ) { if ( ! file_exists ( $ dir . '/.git' ) ) { throw new \ InvalidArgumentException ( 'The directory is not a Git repository' ) ; } $ this -> git -> ensureInstalled ( ) ; $ currentUrl = $ this -> git -> getConfig ( sprintf ( 'remote.%s.url' , $ this -> config -> get ( 'de...
Ensure there is an appropriate Git remote in the repository .
51,376
protected static function findTopDirectoryContaining ( $ file , callable $ callback = null ) { static $ roots = [ ] ; $ cwd = getcwd ( ) ; if ( $ cwd === false ) { return false ; } if ( isset ( $ roots [ $ cwd ] [ $ file ] ) ) { return $ roots [ $ cwd ] [ $ file ] ; } $ roots [ $ cwd ] [ $ file ] = false ; $ root = & $...
Find the highest level directory that contains a file .
51,377
public function mapDirectory ( $ directory , Project $ project ) { if ( ! file_exists ( $ directory . '/.git' ) ) { throw new \ InvalidArgumentException ( 'Not a Git repository: ' . $ directory ) ; } $ projectConfig = [ 'id' => $ project -> id , ] ; if ( $ host = parse_url ( $ project -> getUri ( ) , PHP_URL_HOST ) ) {...
Initialize a directory as a project root .
51,378
public function getProjectRoot ( ) { if ( is_dir ( 'repository' ) && file_exists ( $ this -> config -> get ( 'local.project_config_legacy' ) ) ) { $ cwd = getcwd ( ) ; chdir ( 'repository' ) ; } $ dir = $ this -> findTopDirectoryContaining ( '.git' , function ( $ dir ) { $ config = $ this -> getProjectConfig ( $ dir ) ...
Find the root of the current project .
51,379
public function getProjectConfig ( $ projectRoot = null ) { $ projectRoot = $ projectRoot ? : $ this -> getProjectRoot ( ) ; if ( isset ( self :: $ projectConfigs [ $ projectRoot ] ) ) { return self :: $ projectConfigs [ $ projectRoot ] ; } $ projectConfig = null ; $ configFilename = $ this -> config -> get ( 'local.pr...
Get the configuration for the current project .
51,380
public function writeCurrentProjectConfig ( array $ config , $ projectRoot = null , $ merge = false ) { $ projectRoot = $ projectRoot ? : $ this -> getProjectRoot ( ) ; if ( ! $ projectRoot ) { throw new \ Exception ( 'Project root not found' ) ; } $ this -> ensureLocalDir ( $ projectRoot ) ; $ file = $ projectRoot . '...
Write configuration for a project .
51,381
public function writeGitExclude ( $ dir ) { $ filesToExclude = [ '/' . $ this -> config -> get ( 'local.local_dir' ) , '/' . $ this -> config -> get ( 'local.web_root' ) ] ; $ excludeFilename = $ dir . '/.git/info/exclude' ; $ existing = '' ; if ( file_exists ( $ excludeFilename ) ) { $ existing = file_get_contents ( $...
Write to the Git exclude file .
51,382
protected function getSshOptions ( ) { $ options = [ ] ; $ options [ 'SendEnv' ] = 'TERM' ; if ( $ this -> input -> hasOption ( 'identity-file' ) && $ this -> input -> getOption ( 'identity-file' ) ) { $ file = $ this -> input -> getOption ( 'identity-file' ) ; if ( ! file_exists ( $ file ) ) { throw new \ InvalidArgum...
Returns an array of SSH options based on the input options .
51,383
public function getSshCommand ( array $ extraOptions = [ ] ) { $ command = 'ssh' ; $ args = $ this -> getSshArgs ( $ extraOptions ) ; if ( ! empty ( $ args ) ) { $ command .= ' ' . implode ( ' ' , array_map ( 'escapeshellarg' , $ args ) ) ; } return $ command ; }
Returns an SSH command line .
51,384
private function hookNeedsUpdate ( Integration $ integration , array $ hook , array $ payload ) { if ( $ integration -> type === 'bitbucket' ) { foreach ( $ payload as $ item => $ value ) { if ( ! isset ( $ hook [ $ item ] ) ) { return true ; } if ( $ item === 'events' ) { sort ( $ value ) ; sort ( $ hook [ $ item ] ) ...
Check if a hook needs updating .
51,385
private function findWebHook ( Integration $ integration , array $ jsonResult ) { $ type = $ integration -> type ; $ hookUrl = $ integration -> getLink ( '#hook' ) ; if ( $ integration -> type === 'bitbucket' ) { $ hooks = $ jsonResult [ 'values' ] ; } else { $ hooks = $ jsonResult ; } foreach ( $ hooks as $ hook ) { i...
Find if a valid webhook exists in a service s hooks list .
51,386
protected function getBitbucketAccessToken ( array $ credentials ) { if ( isset ( $ this -> bitbucketAccessTokens [ $ credentials [ 'key' ] ] ) ) { return $ this -> bitbucketAccessTokens [ $ credentials [ 'key' ] ] ; } $ result = $ this -> api ( ) -> getHttpClient ( ) -> post ( 'https://bitbucket.org/site/oauth2/access...
Obtain an OAuth2 token for Bitbucket from the given app credentials .
51,387
protected function validateBitbucketCredentials ( array $ credentials ) { try { $ this -> getBitbucketAccessToken ( $ credentials ) ; } catch ( \ Exception $ e ) { $ message = '<error>Invalid Bitbucket credentials</error>' ; if ( $ e instanceof BadResponseException && $ e -> getResponse ( ) && $ e -> getResponse ( ) ->...
Validate Bitbucket credentials .
51,388
protected function listValidationErrors ( array $ errors , OutputInterface $ output ) { if ( count ( $ errors ) === 1 ) { $ this -> stdErr -> writeln ( 'The following error was found:' ) ; } else { $ this -> stdErr -> writeln ( sprintf ( 'The following %d errors were found:' , count ( $ errors ) ) ) ; } foreach ( $ err...
Lists validation errors found in an integration .
51,389
public function load ( Resource $ apiResource , $ limit , $ type , $ startsAt ) { $ activities = $ apiResource -> getActivities ( $ limit , $ type , $ startsAt ) ; $ progress = new ProgressBar ( $ this -> getProgressOutput ( ) ) ; $ progress -> setMessage ( $ type === 'environment.backup' ? 'Loading snapshots...' : 'Lo...
Load activities .
51,390
public function confirm ( $ questionText , $ default = true ) { $ questionText .= ' <question>' . ( $ default ? '[Y/n]' : '[y/N]' ) . '</question> ' ; $ yes = $ this -> input -> hasOption ( 'yes' ) && $ this -> input -> getOption ( 'yes' ) ; $ no = $ this -> input -> hasOption ( 'no' ) && $ this -> input -> getOption (...
Ask the user to confirm an action .
51,391
public function choose ( array $ items , $ text = 'Enter a number to choose an item:' , $ default = null , $ skipOnOne = true ) { if ( count ( $ items ) === 1 && $ skipOnOne ) { return key ( $ items ) ; } $ itemList = array_values ( $ items ) ; $ defaultKey = $ default !== null ? array_search ( $ default , $ itemList ,...
Provides an interactive choice question .
51,392
public function askInput ( $ questionText , $ default = null , array $ autoCompleterValues = [ ] , callable $ validator = null ) { if ( $ default !== null ) { $ questionText .= ' <question>[' . $ default . ']</question>' ; } $ questionText .= ': ' ; $ question = new Question ( $ questionText , $ default ) ; if ( ! empt...
Ask a simple question which requires input .
51,393
public function getEnvironmentsForCheckout ( ) { $ project = $ this -> getWelcomeCommand ( ) -> getCurrentProject ( ) ; if ( ! $ project ) { return [ ] ; } try { $ currentEnvironment = $ this -> getWelcomeCommand ( ) -> getCurrentEnvironment ( $ project , false ) ; } catch ( \ Exception $ e ) { $ currentEnvironment = f...
Get a list of environments IDs that can be checked out .
51,394
public function getAppNames ( ) { $ apps = [ ] ; if ( $ projectRoot = $ this -> getWelcomeCommand ( ) -> getProjectRoot ( ) ) { foreach ( LocalApplication :: getApplications ( $ projectRoot ) as $ app ) { $ name = $ app -> getName ( ) ; if ( $ name !== null ) { $ apps [ ] = $ name ; } } } elseif ( $ project = $ this ->...
Get a list of application names in the local project .
51,395
protected function getProject ( ) { if ( ! $ this -> projects ) { return false ; } $ commandLine = $ this -> handler -> getContext ( ) -> getCommandLine ( ) ; $ currentProjectId = $ this -> getProjectIdFromCommandLine ( $ commandLine ) ; if ( ! $ currentProjectId && ( $ currentProject = $ this -> getWelcomeCommand ( ) ...
Get the preferred project for autocompletion .
51,396
public function getEnvironments ( ) { $ project = $ this -> getProject ( ) ; if ( ! $ project ) { return [ ] ; } return array_keys ( $ this -> api -> getEnvironments ( $ project , false , false ) ) ; }
Get a list of environment IDs .
51,397
public function getUserEmails ( ) { $ project = $ this -> getProject ( ) ; if ( ! $ project ) { return [ ] ; } $ emails = [ ] ; foreach ( $ this -> api -> getProjectAccesses ( $ project ) as $ projectAccess ) { $ account = $ this -> api -> getAccount ( $ projectAccess ) ; $ emails [ ] = $ account [ 'email' ] ; } return...
Get a list of user email addresses .
51,398
private function getBrowser ( $ browserOption = null ) { if ( ! empty ( $ browserOption ) ) { list ( $ command , ) = explode ( ' ' , $ browserOption , 2 ) ; if ( ! $ this -> shell -> commandExists ( $ command ) ) { $ this -> stdErr -> writeln ( sprintf ( 'Command not found: <error>%s</error>' , $ command ) ) ; return f...
Finds the browser to use .
51,399
public function chooseDatabase ( $ sshUrl , InputInterface $ input , OutputInterface $ output ) { return $ this -> chooseService ( $ sshUrl , $ input , $ output , [ 'mysql' , 'pgsql' ] ) ; }
Choose a database for the user .