Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Last active September 1, 2016 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreymcmahon/d50fc25bf694c0e6932ac7d258b21fd1 to your computer and use it in GitHub Desktop.
Save coreymcmahon/d50fc25bf694c0e6932ac7d258b21fd1 to your computer and use it in GitHub Desktop.
Explode a resource identifier into its component parts
<?php
/**
* Parses resource identifiers of the format:
* RESOURCE=s3://username:password@domain/resource
*/
if ($resource = getenv('RESOURCE')) {
// strip off the namespace, assume it's not needed (e.g 's3', 'mysql')
$identifier = explode('://', $resource)[1];
list($credentials, $resource) = explode('@', $identifier);
list($username, $password) = explode(':', $credentials);
list($domain, $relative) = explode('/', $resource);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment