repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
crisu83/yii-auth | controllers/AuthItemController.php | AuthItemController.actionDelete | public function actionDelete()
{
if (isset($_GET['name'])) {
$name = $_GET['name'];
/* @var $am CAuthManager|AuthBehavior */
$am = Yii::app()->getAuthManager();
$item = $am->getAuthItem($name);
if ($item instanceof CAuthItem) {
$am->removeAuthItem($name);
if ($am instanceof CPhpAuthManager) {
$am->save();
}
if (!isset($_POST['ajax'])) {
$this->redirect(array('index'));
}
} else {
throw new CHttpException(404, Yii::t('AuthModule.main', 'Item does not exist.'));
}
} else {
throw new CHttpException(400, Yii::t('AuthModule.main', 'Invalid request.'));
}
} | php | public function actionDelete()
{
if (isset($_GET['name'])) {
$name = $_GET['name'];
/* @var $am CAuthManager|AuthBehavior */
$am = Yii::app()->getAuthManager();
$item = $am->getAuthItem($name);
if ($item instanceof CAuthItem) {
$am->removeAuthItem($name);
if ($am instanceof CPhpAuthManager) {
$am->save();
}
if (!isset($_POST['ajax'])) {
$this->redirect(array('index'));
}
} else {
throw new CHttpException(404, Yii::t('AuthModule.main', 'Item does not exist.'));
}
} else {
throw new CHttpException(400, Yii::t('AuthModule.main', 'Invalid request.'));
}
} | [
"public",
"function",
"actionDelete",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"name",
"=",
"$",
"_GET",
"[",
"'name'",
"]",
";",
"/* @var $am CAuthManager|AuthBehavior */",
"$",
"am",
"=",
"Yii",
"::... | Deletes the item with the given name.
@throws CHttpException if the item does not exist or if the request is invalid. | [
"Deletes",
"the",
"item",
"with",
"the",
"given",
"name",
"."
] | c1b9108a41f78a46c77e073866410d10e283ac9a | https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/controllers/AuthItemController.php#L172-L196 | train |
crisu83/yii-auth | controllers/AuthItemController.php | AuthItemController.actionRemoveParent | public function actionRemoveParent($itemName, $parentName)
{
/* @var $am CAuthManager|AuthBehavior */
$am = Yii::app()->getAuthManager();
if ($am->hasItemChild($parentName, $itemName)) {
$am->removeItemChild($parentName, $itemName);
if ($am instanceof CPhpAuthManager) {
$am->save();
}
}
$this->redirect(array('view', 'name' => $itemName));
} | php | public function actionRemoveParent($itemName, $parentName)
{
/* @var $am CAuthManager|AuthBehavior */
$am = Yii::app()->getAuthManager();
if ($am->hasItemChild($parentName, $itemName)) {
$am->removeItemChild($parentName, $itemName);
if ($am instanceof CPhpAuthManager) {
$am->save();
}
}
$this->redirect(array('view', 'name' => $itemName));
} | [
"public",
"function",
"actionRemoveParent",
"(",
"$",
"itemName",
",",
"$",
"parentName",
")",
"{",
"/* @var $am CAuthManager|AuthBehavior */",
"$",
"am",
"=",
"Yii",
"::",
"app",
"(",
")",
"->",
"getAuthManager",
"(",
")",
";",
"if",
"(",
"$",
"am",
"->",
... | Removes the parent from the item with the given name.
@param string $itemName name of the item.
@param string $parentName name of the parent. | [
"Removes",
"the",
"parent",
"from",
"the",
"item",
"with",
"the",
"given",
"name",
"."
] | c1b9108a41f78a46c77e073866410d10e283ac9a | https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/controllers/AuthItemController.php#L203-L216 | train |
crisu83/yii-auth | controllers/AuthItemController.php | AuthItemController.actionRemoveChild | public function actionRemoveChild($itemName, $childName)
{
/* @var $am CAuthManager|AuthBehavior */
$am = Yii::app()->getAuthManager();
if ($am->hasItemChild($itemName, $childName)) {
$am->removeItemChild($itemName, $childName);
if ($am instanceof CPhpAuthManager) {
$am->save();
}
}
$this->redirect(array('view', 'name' => $itemName));
} | php | public function actionRemoveChild($itemName, $childName)
{
/* @var $am CAuthManager|AuthBehavior */
$am = Yii::app()->getAuthManager();
if ($am->hasItemChild($itemName, $childName)) {
$am->removeItemChild($itemName, $childName);
if ($am instanceof CPhpAuthManager) {
$am->save();
}
}
$this->redirect(array('view', 'name' => $itemName));
} | [
"public",
"function",
"actionRemoveChild",
"(",
"$",
"itemName",
",",
"$",
"childName",
")",
"{",
"/* @var $am CAuthManager|AuthBehavior */",
"$",
"am",
"=",
"Yii",
"::",
"app",
"(",
")",
"->",
"getAuthManager",
"(",
")",
";",
"if",
"(",
"$",
"am",
"->",
"... | Removes the child from the item with the given name.
@param string $itemName name of the item.
@param string $childName name of the child. | [
"Removes",
"the",
"child",
"from",
"the",
"item",
"with",
"the",
"given",
"name",
"."
] | c1b9108a41f78a46c77e073866410d10e283ac9a | https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/controllers/AuthItemController.php#L223-L236 | train |
crisu83/yii-auth | controllers/AuthItemController.php | AuthItemController.getItemChildOptions | protected function getItemChildOptions($itemName)
{
$options = array();
/* @var $am CAuthManager|AuthBehavior */
$am = Yii::app()->getAuthManager();
$item = $am->getAuthItem($itemName);
if ($item instanceof CAuthItem) {
$exclude = $am->getAncestors($itemName);
$exclude[$itemName] = $item;
$exclude = array_merge($exclude, $item->getChildren());
$authItems = $am->getAuthItems();
$validChildTypes = $this->getValidChildTypes();
foreach ($authItems as $childName => $childItem) {
if (in_array($childItem->type, $validChildTypes) && !isset($exclude[$childName])) {
$options[$this->capitalize(
$this->getItemTypeText($childItem->type, true)
)][$childName] = $childItem->description;
}
}
}
return $options;
} | php | protected function getItemChildOptions($itemName)
{
$options = array();
/* @var $am CAuthManager|AuthBehavior */
$am = Yii::app()->getAuthManager();
$item = $am->getAuthItem($itemName);
if ($item instanceof CAuthItem) {
$exclude = $am->getAncestors($itemName);
$exclude[$itemName] = $item;
$exclude = array_merge($exclude, $item->getChildren());
$authItems = $am->getAuthItems();
$validChildTypes = $this->getValidChildTypes();
foreach ($authItems as $childName => $childItem) {
if (in_array($childItem->type, $validChildTypes) && !isset($exclude[$childName])) {
$options[$this->capitalize(
$this->getItemTypeText($childItem->type, true)
)][$childName] = $childItem->description;
}
}
}
return $options;
} | [
"protected",
"function",
"getItemChildOptions",
"(",
"$",
"itemName",
")",
"{",
"$",
"options",
"=",
"array",
"(",
")",
";",
"/* @var $am CAuthManager|AuthBehavior */",
"$",
"am",
"=",
"Yii",
"::",
"app",
"(",
")",
"->",
"getAuthManager",
"(",
")",
";",
"$",... | Returns a list of possible children for the item with the given name.
@param string $itemName name of the item.
@return array the child options. | [
"Returns",
"a",
"list",
"of",
"possible",
"children",
"for",
"the",
"item",
"with",
"the",
"given",
"name",
"."
] | c1b9108a41f78a46c77e073866410d10e283ac9a | https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/controllers/AuthItemController.php#L243-L268 | train |
crisu83/yii-auth | controllers/AuthItemController.php | AuthItemController.getValidChildTypes | protected function getValidChildTypes()
{
$validTypes = array();
switch ($this->type) {
case CAuthItem::TYPE_OPERATION:
break;
case CAuthItem::TYPE_TASK:
$validTypes[] = CAuthItem::TYPE_OPERATION;
break;
case CAuthItem::TYPE_ROLE:
$validTypes[] = CAuthItem::TYPE_OPERATION;
$validTypes[] = CAuthItem::TYPE_TASK;
break;
}
if (!$this->module->strictMode) {
$validTypes[] = $this->type;
}
return $validTypes;
} | php | protected function getValidChildTypes()
{
$validTypes = array();
switch ($this->type) {
case CAuthItem::TYPE_OPERATION:
break;
case CAuthItem::TYPE_TASK:
$validTypes[] = CAuthItem::TYPE_OPERATION;
break;
case CAuthItem::TYPE_ROLE:
$validTypes[] = CAuthItem::TYPE_OPERATION;
$validTypes[] = CAuthItem::TYPE_TASK;
break;
}
if (!$this->module->strictMode) {
$validTypes[] = $this->type;
}
return $validTypes;
} | [
"protected",
"function",
"getValidChildTypes",
"(",
")",
"{",
"$",
"validTypes",
"=",
"array",
"(",
")",
";",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"CAuthItem",
"::",
"TYPE_OPERATION",
":",
"break",
";",
"case",
"CAuthItem",
"::",
"... | Returns a list of the valid child types for the given type.
@return array the valid types. | [
"Returns",
"a",
"list",
"of",
"the",
"valid",
"child",
"types",
"for",
"the",
"given",
"type",
"."
] | c1b9108a41f78a46c77e073866410d10e283ac9a | https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/controllers/AuthItemController.php#L274-L297 | train |
crisu83/yii-auth | components/CachedDbAuthManager.php | CachedDbAuthManager.flushAccess | public function flushAccess($itemName, $userId)
{
if (($cache = $this->getCache()) !== null) {
$cacheKey = $this->resolveCacheKey($itemName, $userId);
return $cache->delete($cacheKey);
}
return false;
} | php | public function flushAccess($itemName, $userId)
{
if (($cache = $this->getCache()) !== null) {
$cacheKey = $this->resolveCacheKey($itemName, $userId);
return $cache->delete($cacheKey);
}
return false;
} | [
"public",
"function",
"flushAccess",
"(",
"$",
"itemName",
",",
"$",
"userId",
")",
"{",
"if",
"(",
"(",
"$",
"cache",
"=",
"$",
"this",
"->",
"getCache",
"(",
")",
")",
"!==",
"null",
")",
"{",
"$",
"cacheKey",
"=",
"$",
"this",
"->",
"resolveCach... | Flushes the access cache for the specified user.
@param string $itemName the name of the operation that need access check.
@param integer $userId the user id.
@return boolean whether access was flushed. | [
"Flushes",
"the",
"access",
"cache",
"for",
"the",
"specified",
"user",
"."
] | c1b9108a41f78a46c77e073866410d10e283ac9a | https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/components/CachedDbAuthManager.php#L71-L78 | train |
crisu83/yii-auth | components/CachedDbAuthManager.php | CachedDbAuthManager.getCache | protected function getCache()
{
return $this->cachingDuration > 0 && $this->cacheID !== false ? Yii::app()->getComponent($this->cacheID) : null;
} | php | protected function getCache()
{
return $this->cachingDuration > 0 && $this->cacheID !== false ? Yii::app()->getComponent($this->cacheID) : null;
} | [
"protected",
"function",
"getCache",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"cachingDuration",
">",
"0",
"&&",
"$",
"this",
"->",
"cacheID",
"!==",
"false",
"?",
"Yii",
"::",
"app",
"(",
")",
"->",
"getComponent",
"(",
"$",
"this",
"->",
"cacheID"... | Returns the caching component for this component.
@return CCache|null the caching component. | [
"Returns",
"the",
"caching",
"component",
"for",
"this",
"component",
"."
] | c1b9108a41f78a46c77e073866410d10e283ac9a | https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/components/CachedDbAuthManager.php#L96-L99 | train |
rdohms/dms-filter | src/DMS/Filter/Mapping/ClassMetadataFactory.php | ClassMetadataFactory.parseClassMetadata | private function parseClassMetadata($class)
{
$metadata = new ClassMetadata($class);
//Load up parent and interfaces
$this->loadParentMetadata($metadata);
$this->loadInterfaceMetadata($metadata);
//Load Annotations from Reader
$this->loader->loadClassMetadata($metadata);
//Store internally
$this->setParsedClass($class, $metadata);
if ($this->cache !== null) {
$this->cache->save($class, $metadata);
}
return $metadata;
} | php | private function parseClassMetadata($class)
{
$metadata = new ClassMetadata($class);
//Load up parent and interfaces
$this->loadParentMetadata($metadata);
$this->loadInterfaceMetadata($metadata);
//Load Annotations from Reader
$this->loader->loadClassMetadata($metadata);
//Store internally
$this->setParsedClass($class, $metadata);
if ($this->cache !== null) {
$this->cache->save($class, $metadata);
}
return $metadata;
} | [
"private",
"function",
"parseClassMetadata",
"(",
"$",
"class",
")",
"{",
"$",
"metadata",
"=",
"new",
"ClassMetadata",
"(",
"$",
"class",
")",
";",
"//Load up parent and interfaces",
"$",
"this",
"->",
"loadParentMetadata",
"(",
"$",
"metadata",
")",
";",
"$"... | Reads class metadata for a new and unparsed class
@param string $class
@return ClassMetadataInterface | [
"Reads",
"class",
"metadata",
"for",
"a",
"new",
"and",
"unparsed",
"class"
] | 3eb0942a68fa023e0d7378fa825447e7a47219b1 | https://github.com/rdohms/dms-filter/blob/3eb0942a68fa023e0d7378fa825447e7a47219b1/src/DMS/Filter/Mapping/ClassMetadataFactory.php#L71-L90 | train |
rdohms/dms-filter | src/DMS/Filter/Mapping/ClassMetadataFactory.php | ClassMetadataFactory.loadParentMetadata | protected function loadParentMetadata(ClassMetadataInterface $metadata)
{
$parent = $metadata->getReflectionClass()->getParentClass();
if ($parent) {
$metadata->mergeRules($this->getClassMetadata($parent->getName()));
}
} | php | protected function loadParentMetadata(ClassMetadataInterface $metadata)
{
$parent = $metadata->getReflectionClass()->getParentClass();
if ($parent) {
$metadata->mergeRules($this->getClassMetadata($parent->getName()));
}
} | [
"protected",
"function",
"loadParentMetadata",
"(",
"ClassMetadataInterface",
"$",
"metadata",
")",
"{",
"$",
"parent",
"=",
"$",
"metadata",
"->",
"getReflectionClass",
"(",
")",
"->",
"getParentClass",
"(",
")",
";",
"if",
"(",
"$",
"parent",
")",
"{",
"$"... | Checks if the class being parsed has a parent and cascades parsing
to its parent
@param ClassMetadataInterface $metadata | [
"Checks",
"if",
"the",
"class",
"being",
"parsed",
"has",
"a",
"parent",
"and",
"cascades",
"parsing",
"to",
"its",
"parent"
] | 3eb0942a68fa023e0d7378fa825447e7a47219b1 | https://github.com/rdohms/dms-filter/blob/3eb0942a68fa023e0d7378fa825447e7a47219b1/src/DMS/Filter/Mapping/ClassMetadataFactory.php#L135-L142 | train |
contributte/facebook | src/FacebookLogin.php | FacebookLogin.getLoginUrl | public function getLoginUrl(string $redirectUrl, array $permissions = ['public_profile'], ?string $stateParam = null): string
{
// Create redirect URL with econea return URL
$helper = $this->facebook->getRedirectLoginHelper();
// Set our own state param
if (isset($stateParam)) {
$helper->getPersistentDataHandler()->set('state', $stateParam);
}
$url = $helper->getLoginUrl($redirectUrl, $permissions);
return $url;
} | php | public function getLoginUrl(string $redirectUrl, array $permissions = ['public_profile'], ?string $stateParam = null): string
{
// Create redirect URL with econea return URL
$helper = $this->facebook->getRedirectLoginHelper();
// Set our own state param
if (isset($stateParam)) {
$helper->getPersistentDataHandler()->set('state', $stateParam);
}
$url = $helper->getLoginUrl($redirectUrl, $permissions);
return $url;
} | [
"public",
"function",
"getLoginUrl",
"(",
"string",
"$",
"redirectUrl",
",",
"array",
"$",
"permissions",
"=",
"[",
"'public_profile'",
"]",
",",
"?",
"string",
"$",
"stateParam",
"=",
"null",
")",
":",
"string",
"{",
"// Create redirect URL with econea return URL... | Creates Response that redirects person to FB for authorization and back
@param string[] $permissions | [
"Creates",
"Response",
"that",
"redirects",
"person",
"to",
"FB",
"for",
"authorization",
"and",
"back"
] | c08153c1b6e2890660ce27e2f1cdf217155925a3 | https://github.com/contributte/facebook/blob/c08153c1b6e2890660ce27e2f1cdf217155925a3/src/FacebookLogin.php#L34-L47 | train |
platformsh/platformsh-client-php | src/Model/Git/Tree.php | Tree.fromSha | public static function fromSha($sha, $baseUrl, ClientInterface $client)
{
$url = Project::getProjectBaseFromUrl($baseUrl) . '/git/trees';
return static::get($sha, $url, $client);
} | php | public static function fromSha($sha, $baseUrl, ClientInterface $client)
{
$url = Project::getProjectBaseFromUrl($baseUrl) . '/git/trees';
return static::get($sha, $url, $client);
} | [
"public",
"static",
"function",
"fromSha",
"(",
"$",
"sha",
",",
"$",
"baseUrl",
",",
"ClientInterface",
"$",
"client",
")",
"{",
"$",
"url",
"=",
"Project",
"::",
"getProjectBaseFromUrl",
"(",
"$",
"baseUrl",
")",
".",
"'/git/trees'",
";",
"return",
"stat... | Get the Tree object for an SHA hash.
@param string $sha
@param string $baseUrl
@param ClientInterface $client
@return static|false | [
"Get",
"the",
"Tree",
"object",
"for",
"an",
"SHA",
"hash",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Git/Tree.php#L28-L33 | train |
platformsh/platformsh-client-php | src/Model/Git/Tree.php | Tree.getObject | public function getObject($path)
{
if ($path === '' || $path === '.') {
return $this;
}
$data = $this->getObjectData($path);
if ($data === false) {
return false;
}
if ($data['type'] === 'blob') {
return Blob::fromSha($data['sha'], $this->getUri(), $this->client);
} elseif ($data['type'] === 'tree') {
return Tree::fromSha($data['sha'], $this->getUri(), $this->client);
}
throw new \RuntimeException('Unrecognised object type: ' . $data['type']);
} | php | public function getObject($path)
{
if ($path === '' || $path === '.') {
return $this;
}
$data = $this->getObjectData($path);
if ($data === false) {
return false;
}
if ($data['type'] === 'blob') {
return Blob::fromSha($data['sha'], $this->getUri(), $this->client);
} elseif ($data['type'] === 'tree') {
return Tree::fromSha($data['sha'], $this->getUri(), $this->client);
}
throw new \RuntimeException('Unrecognised object type: ' . $data['type']);
} | [
"public",
"function",
"getObject",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"path",
"===",
"''",
"||",
"$",
"path",
"===",
"'.'",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"getObjectData",
"(",
"$",
"path"... | Get an object in this tree.
@param string $path The path to an object in the tree.
@return Blob|Tree|false
A Blob or Tree object, or false if the object does not exist. | [
"Get",
"an",
"object",
"in",
"this",
"tree",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Git/Tree.php#L43-L60 | train |
platformsh/platformsh-client-php | src/Model/Git/Tree.php | Tree.getObjectData | private function getObjectData($path)
{
foreach ($this->tree as $objectData) {
if ($objectData['path'] === $path) {
return $objectData;
}
}
return false;
} | php | private function getObjectData($path)
{
foreach ($this->tree as $objectData) {
if ($objectData['path'] === $path) {
return $objectData;
}
}
return false;
} | [
"private",
"function",
"getObjectData",
"(",
"$",
"path",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tree",
"as",
"$",
"objectData",
")",
"{",
"if",
"(",
"$",
"objectData",
"[",
"'path'",
"]",
"===",
"$",
"path",
")",
"{",
"return",
"$",
"objectDa... | Find an object definition by its path.
@param string $path
@return array|false | [
"Find",
"an",
"object",
"definition",
"by",
"its",
"path",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Git/Tree.php#L69-L78 | train |
platformsh/platformsh-client-php | src/Model/Git/Tree.php | Tree.getObjectRecursive | private function getObjectRecursive($path)
{
$tree = $object = $this;
foreach ($this->splitPath($path) as $part) {
$object = $tree->getObject($part);
if (!$object instanceof Tree) {
return $object;
}
$tree = $object;
}
return $object;
} | php | private function getObjectRecursive($path)
{
$tree = $object = $this;
foreach ($this->splitPath($path) as $part) {
$object = $tree->getObject($part);
if (!$object instanceof Tree) {
return $object;
}
$tree = $object;
}
return $object;
} | [
"private",
"function",
"getObjectRecursive",
"(",
"$",
"path",
")",
"{",
"$",
"tree",
"=",
"$",
"object",
"=",
"$",
"this",
";",
"foreach",
"(",
"$",
"this",
"->",
"splitPath",
"(",
"$",
"path",
")",
"as",
"$",
"part",
")",
"{",
"$",
"object",
"=",... | Get an object recursively in this tree.
@param string $path
@return Blob|Tree|false | [
"Get",
"an",
"object",
"recursively",
"in",
"this",
"tree",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Git/Tree.php#L87-L99 | train |
platformsh/platformsh-client-php | src/Model/Integration.php | Integration.triggerHook | public function triggerHook()
{
$hookUrl = $this->getLink('#hook');
$options = [];
// The API needs us to send an empty JSON object.
$options['json'] = new \stdClass();
// Switch off authentication for this request (none is required).
$options['auth'] = null;
$this->sendRequest($hookUrl, 'post', $options);
} | php | public function triggerHook()
{
$hookUrl = $this->getLink('#hook');
$options = [];
// The API needs us to send an empty JSON object.
$options['json'] = new \stdClass();
// Switch off authentication for this request (none is required).
$options['auth'] = null;
$this->sendRequest($hookUrl, 'post', $options);
} | [
"public",
"function",
"triggerHook",
"(",
")",
"{",
"$",
"hookUrl",
"=",
"$",
"this",
"->",
"getLink",
"(",
"'#hook'",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"// The API needs us to send an empty JSON object.",
"$",
"options",
"[",
"'json'",
"]",
"=",... | Trigger the integration's web hook.
Normally the external service should do this in response to events, but
it may be useful to trigger the hook manually in certain cases. | [
"Trigger",
"the",
"integration",
"s",
"web",
"hook",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Integration.php#L50-L62 | train |
platformsh/platformsh-client-php | src/Model/Integration.php | Integration.listValidationErrors | public static function listValidationErrors(BadResponseException $exception)
{
$response = $exception->getResponse();
if ($response && $response->getStatusCode() === 400) {
$response->getBody()->seek(0);
$data = $response->json();
if (isset($data['detail']) && is_array($data['detail'])) {
return $data['detail'];
}
}
throw $exception;
} | php | public static function listValidationErrors(BadResponseException $exception)
{
$response = $exception->getResponse();
if ($response && $response->getStatusCode() === 400) {
$response->getBody()->seek(0);
$data = $response->json();
if (isset($data['detail']) && is_array($data['detail'])) {
return $data['detail'];
}
}
throw $exception;
} | [
"public",
"static",
"function",
"listValidationErrors",
"(",
"BadResponseException",
"$",
"exception",
")",
"{",
"$",
"response",
"=",
"$",
"exception",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"$",
"response",
"&&",
"$",
"response",
"->",
"getStatusCode... | Process an API exception to list integration validation errors.
@param \GuzzleHttp\Exception\BadResponseException $exception
An exception received during integration create, update, or validate.
@see \Platformsh\Client\Model\Integration::validate()
@throws \GuzzleHttp\Exception\BadResponseException
The original exception is re-thrown if specific validation errors
cannot be found.
@return string[] A list of errors. | [
"Process",
"an",
"API",
"exception",
"to",
"list",
"integration",
"validation",
"errors",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Integration.php#L100-L112 | train |
platformsh/platformsh-client-php | src/Model/Result.php | Result.getActivities | public function getActivities()
{
if (!isset($this->data['_embedded']['activities'])) {
return [];
}
$activities = [];
foreach ($this->data['_embedded']['activities'] as $data) {
$activities[] = new Activity($data, $this->baseUrl, $this->client);
}
return $activities;
} | php | public function getActivities()
{
if (!isset($this->data['_embedded']['activities'])) {
return [];
}
$activities = [];
foreach ($this->data['_embedded']['activities'] as $data) {
$activities[] = new Activity($data, $this->baseUrl, $this->client);
}
return $activities;
} | [
"public",
"function",
"getActivities",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"'_embedded'",
"]",
"[",
"'activities'",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"activities",
"=",
"[",
"]",
";",
... | Get activities embedded in the result.
A result could embed 0, 1, or many activities.
@return Activity[] | [
"Get",
"activities",
"embedded",
"in",
"the",
"result",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Result.php#L60-L72 | train |
platformsh/platformsh-client-php | src/Model/Result.php | Result.getEntity | public function getEntity()
{
if (!isset($this->data['_embedded']['entity']) || !isset($this->resourceClass)) {
throw new \Exception("No entity found in result");
}
$data = $this->data['_embedded']['entity'];
$resourceClass = $this->resourceClass;
return new $resourceClass($data, $this->baseUrl, $this->client);
} | php | public function getEntity()
{
if (!isset($this->data['_embedded']['entity']) || !isset($this->resourceClass)) {
throw new \Exception("No entity found in result");
}
$data = $this->data['_embedded']['entity'];
$resourceClass = $this->resourceClass;
return new $resourceClass($data, $this->baseUrl, $this->client);
} | [
"public",
"function",
"getEntity",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"'_embedded'",
"]",
"[",
"'entity'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"resourceClass",
")",
")",
"{",
"throw",
"new... | Get the entity embedded in the result.
@throws \Exception If no entity was embedded.
@return ApiResourceBase
An instance of ApiResourceBase - the implementing class name was set
when this Result was instantiated. | [
"Get",
"the",
"entity",
"embedded",
"in",
"the",
"result",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Result.php#L83-L92 | train |
platformsh/platformsh-client-php | src/Model/Git/Blob.php | Blob.getRawContent | public function getRawContent()
{
if ($this->size == 0) {
return '';
}
if ($this->encoding === 'base64') {
$raw = base64_decode($this->content, true);
if ($raw === false) {
throw new \RuntimeException('Failed to decode content');
}
return $raw;
}
throw new \RuntimeException('Unrecognised blob encoding: ' . $this->encoding);
} | php | public function getRawContent()
{
if ($this->size == 0) {
return '';
}
if ($this->encoding === 'base64') {
$raw = base64_decode($this->content, true);
if ($raw === false) {
throw new \RuntimeException('Failed to decode content');
}
return $raw;
}
throw new \RuntimeException('Unrecognised blob encoding: ' . $this->encoding);
} | [
"public",
"function",
"getRawContent",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"size",
"==",
"0",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"encoding",
"===",
"'base64'",
")",
"{",
"$",
"raw",
"=",
"base64_decode",
"(",... | Get the raw content of the file.
@return string | [
"Get",
"the",
"raw",
"content",
"of",
"the",
"file",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Git/Blob.php#L40-L56 | train |
koenpunt/php-inflector | lib/Inflector/Methods.php | Methods.underscore | public static function underscore($camel_cased_word){
$word = $camel_cased_word;
$word = preg_replace('/\\\/', '/', $word);
$acronym_regex = static::inflections()->acronym_regex;
$word = preg_replace_callback("/(?:([A-Za-z\d])|^)({$acronym_regex})(?=\b|[^a-z])/", function($matches){
return "{$matches[1]}" . ($matches[1] ? '_' : '') . strtolower($matches[2]);
}, $word);
$word = preg_replace('/([A-Z\d]+)([A-Z][a-z])/','$1_$2', $word);
$word = preg_replace('/([a-z\d])([A-Z])/','$1_$2', $word);
$word = strtr($word, '-', '_');
$word = strtolower($word);
return $word;
} | php | public static function underscore($camel_cased_word){
$word = $camel_cased_word;
$word = preg_replace('/\\\/', '/', $word);
$acronym_regex = static::inflections()->acronym_regex;
$word = preg_replace_callback("/(?:([A-Za-z\d])|^)({$acronym_regex})(?=\b|[^a-z])/", function($matches){
return "{$matches[1]}" . ($matches[1] ? '_' : '') . strtolower($matches[2]);
}, $word);
$word = preg_replace('/([A-Z\d]+)([A-Z][a-z])/','$1_$2', $word);
$word = preg_replace('/([a-z\d])([A-Z])/','$1_$2', $word);
$word = strtr($word, '-', '_');
$word = strtolower($word);
return $word;
} | [
"public",
"static",
"function",
"underscore",
"(",
"$",
"camel_cased_word",
")",
"{",
"$",
"word",
"=",
"$",
"camel_cased_word",
";",
"$",
"word",
"=",
"preg_replace",
"(",
"'/\\\\\\/'",
",",
"'/'",
",",
"$",
"word",
")",
";",
"$",
"acronym_regex",
"=",
... | Makes an underscored, lowercase form from the expression in the string.
Changes '\' to '/' to convert namespaces to paths.
Examples:
underscore("ActiveRecord") # => "active_record"
underscore("ActiveRecord\Errors") # => "active_record/errors"
As a rule of thumb you can think of +underscore+ as the inverse of +camelize+,
though there are cases where that does not hold:
camelize(underscore("SSLError")) # => "SslError"
@param string $camel_cased_word
@return string Underscored $camel_cased_word
@author Koen Punt | [
"Makes",
"an",
"underscored",
"lowercase",
"form",
"from",
"the",
"expression",
"in",
"the",
"string",
"."
] | 8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1 | https://github.com/koenpunt/php-inflector/blob/8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1/lib/Inflector/Methods.php#L100-L112 | train |
koenpunt/php-inflector | lib/Inflector/Methods.php | Methods.humanize | public static function humanize($lower_case_and_underscored_word){
$result = $lower_case_and_underscored_word;
foreach(static::inflections()->humans as $rule => $replacement){
if(($result = preg_replace($rule, $replacement, $result, 1)))break;
};
$result = preg_replace('/_id$/', "", $result);
$result = strtr($result, '_', ' ');
return ucfirst(preg_replace_callback('/([a-z\d]*)/i', function($matches){
return isset(static::inflections()->acronyms[$matches[0]]) ? static::inflections()->acronyms[$matches[0]] : strtolower($matches[0]);
}, $result));
} | php | public static function humanize($lower_case_and_underscored_word){
$result = $lower_case_and_underscored_word;
foreach(static::inflections()->humans as $rule => $replacement){
if(($result = preg_replace($rule, $replacement, $result, 1)))break;
};
$result = preg_replace('/_id$/', "", $result);
$result = strtr($result, '_', ' ');
return ucfirst(preg_replace_callback('/([a-z\d]*)/i', function($matches){
return isset(static::inflections()->acronyms[$matches[0]]) ? static::inflections()->acronyms[$matches[0]] : strtolower($matches[0]);
}, $result));
} | [
"public",
"static",
"function",
"humanize",
"(",
"$",
"lower_case_and_underscored_word",
")",
"{",
"$",
"result",
"=",
"$",
"lower_case_and_underscored_word",
";",
"foreach",
"(",
"static",
"::",
"inflections",
"(",
")",
"->",
"humans",
"as",
"$",
"rule",
"=>",
... | Capitalizes the first word and turns underscores into spaces and strips a
trailing "_id", if any. Like +titleize+, this is meant for creating pretty output.
Examples:
titleize("employee_salary") # => "Employee salary"
titleize("author_id") # => "Author"
@param string $lower_case_and_underscored_word
@return string Humanized $lower_case_and_underscored_word
@author Koen Punt | [
"Capitalizes",
"the",
"first",
"word",
"and",
"turns",
"underscores",
"into",
"spaces",
"and",
"strips",
"a",
"trailing",
"_id",
"if",
"any",
".",
"Like",
"+",
"titleize",
"+",
"this",
"is",
"meant",
"for",
"creating",
"pretty",
"output",
"."
] | 8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1 | https://github.com/koenpunt/php-inflector/blob/8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1/lib/Inflector/Methods.php#L126-L136 | train |
koenpunt/php-inflector | lib/Inflector/Methods.php | Methods.apply_inflections | private static function apply_inflections($word, $rules){
$result = $word;
preg_match('/\b\w+\Z/', strtolower($result), $matches);
if( empty($word) || array_search($matches[0], static::inflections()->uncountables) !== false ){
return $result;
}else{
foreach($rules as $rule_replacement){
list($rule, $replacement) = $rule_replacement;
$result = preg_replace($rule, $replacement, $result, -1, $count);
if($count){
break;
}
}
return $result;
}
} | php | private static function apply_inflections($word, $rules){
$result = $word;
preg_match('/\b\w+\Z/', strtolower($result), $matches);
if( empty($word) || array_search($matches[0], static::inflections()->uncountables) !== false ){
return $result;
}else{
foreach($rules as $rule_replacement){
list($rule, $replacement) = $rule_replacement;
$result = preg_replace($rule, $replacement, $result, -1, $count);
if($count){
break;
}
}
return $result;
}
} | [
"private",
"static",
"function",
"apply_inflections",
"(",
"$",
"word",
",",
"$",
"rules",
")",
"{",
"$",
"result",
"=",
"$",
"word",
";",
"preg_match",
"(",
"'/\\b\\w+\\Z/'",
",",
"strtolower",
"(",
"$",
"result",
")",
",",
"$",
"matches",
")",
";",
"... | Applies inflection rules for +singularize+ and +pluralize+.
Examples:
apply_inflections("post", inflections()->plurals) # => "posts"
apply_inflections("posts", inflections()->singulars) # => "post"
@param string $word
@param array $rules
@return string inflected $word
@author Koen Punt | [
"Applies",
"inflection",
"rules",
"for",
"+",
"singularize",
"+",
"and",
"+",
"pluralize",
"+",
"."
] | 8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1 | https://github.com/koenpunt/php-inflector/blob/8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1/lib/Inflector/Methods.php#L294-L309 | train |
platformsh/platformsh-client-php | src/Session/Session.php | Session.load | private function load()
{
if (!$this->loaded && isset($this->storage)) {
$this->data = $this->storage->load($this->id);
$this->original = $this->data;
$this->loaded = true;
}
} | php | private function load()
{
if (!$this->loaded && isset($this->storage)) {
$this->data = $this->storage->load($this->id);
$this->original = $this->data;
$this->loaded = true;
}
} | [
"private",
"function",
"load",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"loaded",
"&&",
"isset",
"(",
"$",
"this",
"->",
"storage",
")",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"this",
"->",
"storage",
"->",
"load",
"(",
"$",
"t... | Load session data, if storage is defined. | [
"Load",
"session",
"data",
"if",
"storage",
"is",
"defined",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Session/Session.php#L41-L48 | train |
platformsh/platformsh-client-php | src/Model/SshKey.php | SshKey.validatePublicKey | public static function validatePublicKey($value)
{
$value = preg_replace('/\s+/', ' ', $value);
if (!strpos($value, ' ')) {
return false;
}
list($type, $key) = explode(' ', $value, 3);
if (!in_array($type, static::$allowedAlgorithms) || base64_decode($key, true) === false) {
return false;
}
return true;
} | php | public static function validatePublicKey($value)
{
$value = preg_replace('/\s+/', ' ', $value);
if (!strpos($value, ' ')) {
return false;
}
list($type, $key) = explode(' ', $value, 3);
if (!in_array($type, static::$allowedAlgorithms) || base64_decode($key, true) === false) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"validatePublicKey",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"'/\\s+/'",
",",
"' '",
",",
"$",
"value",
")",
";",
"if",
"(",
"!",
"strpos",
"(",
"$",
"value",
",",
"' '",
")",
")",
"{",
"... | Validate an SSH public key.
@param string $value
@return bool | [
"Validate",
"an",
"SSH",
"public",
"key",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/SshKey.php#L44-L56 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.get | public static function get($id, $collectionUrl = null, ClientInterface $client)
{
try {
$url = $collectionUrl ? rtrim($collectionUrl, '/') . '/' . urlencode($id) : $id;
$request = new Request('get', $url);
$data = self::send($request, $client);
return new static($data, $url, $client, true);
} catch (BadResponseException $e) {
$response = $e->getResponse();
if ($response && $response->getStatusCode() === 404) {
return false;
}
throw $e;
}
} | php | public static function get($id, $collectionUrl = null, ClientInterface $client)
{
try {
$url = $collectionUrl ? rtrim($collectionUrl, '/') . '/' . urlencode($id) : $id;
$request = new Request('get', $url);
$data = self::send($request, $client);
return new static($data, $url, $client, true);
} catch (BadResponseException $e) {
$response = $e->getResponse();
if ($response && $response->getStatusCode() === 404) {
return false;
}
throw $e;
}
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"id",
",",
"$",
"collectionUrl",
"=",
"null",
",",
"ClientInterface",
"$",
"client",
")",
"{",
"try",
"{",
"$",
"url",
"=",
"$",
"collectionUrl",
"?",
"rtrim",
"(",
"$",
"collectionUrl",
",",
"'/'",
")",... | Get a resource by its ID.
@param string $id The ID of the resource, or the
full URL.
@param string $collectionUrl The URL of the collection.
@param ClientInterface $client A suitably configured Guzzle
client.
@return static|false The resource object, or false if the resource is
not found. | [
"Get",
"a",
"resource",
"by",
"its",
"ID",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L165-L180 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.send | public static function send(RequestInterface $request, ClientInterface $client, array $options = [])
{
$response = null;
try {
$response = $client->send($request, $options);
$body = $response->getBody()->getContents();
$data = [];
if ($body) {
$response->getBody()->seek(0);
$body = $response->getBody()->getContents();
$data = \GuzzleHttp\json_decode($body, true);
}
return (array) $data;
} catch (BadResponseException $e) {
throw ApiResponseException::create($e->getRequest(), $e->getResponse());
} catch (\InvalidArgumentException $e) {
throw ApiResponseException::create($request, $response);
}
} | php | public static function send(RequestInterface $request, ClientInterface $client, array $options = [])
{
$response = null;
try {
$response = $client->send($request, $options);
$body = $response->getBody()->getContents();
$data = [];
if ($body) {
$response->getBody()->seek(0);
$body = $response->getBody()->getContents();
$data = \GuzzleHttp\json_decode($body, true);
}
return (array) $data;
} catch (BadResponseException $e) {
throw ApiResponseException::create($e->getRequest(), $e->getResponse());
} catch (\InvalidArgumentException $e) {
throw ApiResponseException::create($request, $response);
}
} | [
"public",
"static",
"function",
"send",
"(",
"RequestInterface",
"$",
"request",
",",
"ClientInterface",
"$",
"client",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"response",
"=",
"null",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"cl... | Send a Guzzle request.
Using this method allows exceptions to be standardized.
@param RequestInterface $request
@param ClientInterface $client
@param array $options
@internal
@return array | [
"Send",
"a",
"Guzzle",
"request",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L217-L236 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.sendRequest | protected function sendRequest($url, $method = 'get', array $options = [])
{
return $this->send(
new Request($method, $url),
$this->client,
$options
);
} | php | protected function sendRequest($url, $method = 'get', array $options = [])
{
return $this->send(
new Request($method, $url),
$this->client,
$options
);
} | [
"protected",
"function",
"sendRequest",
"(",
"$",
"url",
",",
"$",
"method",
"=",
"'get'",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"send",
"(",
"new",
"Request",
"(",
"$",
"method",
",",
"$",
"url",
")",
... | A simple helper function to send an HTTP request.
@param string $url
@param string $method
@param array $options
@return array | [
"A",
"simple",
"helper",
"function",
"to",
"send",
"an",
"HTTP",
"request",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L247-L254 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.checkNew | protected static function checkNew(array $data)
{
$errors = [];
if ($missing = array_diff(static::getRequired(), array_keys($data))) {
$errors[] = 'Missing: ' . implode(', ', $missing);
}
foreach ($data as $key => $value) {
$errors += static::checkProperty($key, $value);
}
return $errors;
} | php | protected static function checkNew(array $data)
{
$errors = [];
if ($missing = array_diff(static::getRequired(), array_keys($data))) {
$errors[] = 'Missing: ' . implode(', ', $missing);
}
foreach ($data as $key => $value) {
$errors += static::checkProperty($key, $value);
}
return $errors;
} | [
"protected",
"static",
"function",
"checkNew",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"missing",
"=",
"array_diff",
"(",
"static",
"::",
"getRequired",
"(",
")",
",",
"array_keys",
"(",
"$",
"data",
")... | Validate a new resource.
@param array $data
@return string[] An array of validation errors. | [
"Validate",
"a",
"new",
"resource",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L273-L283 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.wrapCollection | public static function wrapCollection(array $data, $baseUrl, ClientInterface $client)
{
$resources = [];
foreach ($data as $item) {
$resources[] = new static($item, $baseUrl, $client);
}
return $resources;
} | php | public static function wrapCollection(array $data, $baseUrl, ClientInterface $client)
{
$resources = [];
foreach ($data as $item) {
$resources[] = new static($item, $baseUrl, $client);
}
return $resources;
} | [
"public",
"static",
"function",
"wrapCollection",
"(",
"array",
"$",
"data",
",",
"$",
"baseUrl",
",",
"ClientInterface",
"$",
"client",
")",
"{",
"$",
"resources",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"item",
")",
"{",
"$",
"r... | Create an array of resource instances from a collection's JSON data.
@param array $data The deserialized JSON from the
collection (i.e. a list of resources,
each of which is an array of data).
@param string $baseUrl The URL to the collection.
@param ClientInterface $client A suitably configured Guzzle client.
@return static[] | [
"Create",
"an",
"array",
"of",
"resource",
"instances",
"from",
"a",
"collection",
"s",
"JSON",
"data",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L338-L346 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.runOperation | protected function runOperation($op, $method = 'post', array $body = [])
{
if (!$this->operationAvailable($op, true)) {
throw new OperationUnavailableException("Operation not available: $op");
}
$options = [];
if (!empty($body)) {
$options['json'] = $body;
}
$request= new Request($method, $this->getLink("#$op"));
$data = $this->send($request, $this->client, $options);
return new Result($data, $this->baseUrl, $this->client, get_called_class());
} | php | protected function runOperation($op, $method = 'post', array $body = [])
{
if (!$this->operationAvailable($op, true)) {
throw new OperationUnavailableException("Operation not available: $op");
}
$options = [];
if (!empty($body)) {
$options['json'] = $body;
}
$request= new Request($method, $this->getLink("#$op"));
$data = $this->send($request, $this->client, $options);
return new Result($data, $this->baseUrl, $this->client, get_called_class());
} | [
"protected",
"function",
"runOperation",
"(",
"$",
"op",
",",
"$",
"method",
"=",
"'post'",
",",
"array",
"$",
"body",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"operationAvailable",
"(",
"$",
"op",
",",
"true",
")",
")",
"{",
"... | Execute an operation on the resource.
@param string $op
@param string $method
@param array $body
@return Result | [
"Execute",
"an",
"operation",
"on",
"the",
"resource",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L357-L370 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.runLongOperation | protected function runLongOperation($op, $method = 'post', array $body = [])
{
$result = $this->runOperation($op, $method, $body);
$activities = $result->getActivities();
if (count($activities) !== 1) {
trigger_error(sprintf("Expected one activity, found %d", count($activities)), E_USER_WARNING);
}
return reset($activities);
} | php | protected function runLongOperation($op, $method = 'post', array $body = [])
{
$result = $this->runOperation($op, $method, $body);
$activities = $result->getActivities();
if (count($activities) !== 1) {
trigger_error(sprintf("Expected one activity, found %d", count($activities)), E_USER_WARNING);
}
return reset($activities);
} | [
"protected",
"function",
"runLongOperation",
"(",
"$",
"op",
",",
"$",
"method",
"=",
"'post'",
",",
"array",
"$",
"body",
"=",
"[",
"]",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"runOperation",
"(",
"$",
"op",
",",
"$",
"method",
",",
"$",... | Run a long-running operation.
@param string $op
@param string $method
@param array $body
@return Activity | [
"Run",
"a",
"long",
"-",
"running",
"operation",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L381-L390 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.hasProperty | public function hasProperty($property, $lazyLoad = true)
{
if (!$this->isProperty($property)) {
return false;
}
if (!array_key_exists($property, $this->data) && $lazyLoad) {
$this->ensureFull();
}
return array_key_exists($property, $this->data);
} | php | public function hasProperty($property, $lazyLoad = true)
{
if (!$this->isProperty($property)) {
return false;
}
if (!array_key_exists($property, $this->data) && $lazyLoad) {
$this->ensureFull();
}
return array_key_exists($property, $this->data);
} | [
"public",
"function",
"hasProperty",
"(",
"$",
"property",
",",
"$",
"lazyLoad",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isProperty",
"(",
"$",
"property",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"array_key_exis... | Check whether a property exists in the resource.
@param string $property
@param bool $lazyLoad
@return bool | [
"Check",
"whether",
"a",
"property",
"exists",
"in",
"the",
"resource",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L400-L410 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.getProperty | public function getProperty($property, $required = true, $lazyLoad = true)
{
if (!$this->hasProperty($property, $lazyLoad)) {
if ($required) {
throw new \InvalidArgumentException("Property not found: $property");
}
return null;
}
return $this->data[$property];
} | php | public function getProperty($property, $required = true, $lazyLoad = true)
{
if (!$this->hasProperty($property, $lazyLoad)) {
if ($required) {
throw new \InvalidArgumentException("Property not found: $property");
}
return null;
}
return $this->data[$property];
} | [
"public",
"function",
"getProperty",
"(",
"$",
"property",
",",
"$",
"required",
"=",
"true",
",",
"$",
"lazyLoad",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"property",
",",
"$",
"lazyLoad",
")",
")",
"{",
... | Get a property of the resource.
@param string $property
@param bool $required
@param bool $lazyLoad
@throws \InvalidArgumentException If $required is true and the property
is not found.
@return mixed|null
The property value, or null if the property does not exist (and
$required is false). | [
"Get",
"a",
"property",
"of",
"the",
"resource",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L426-L436 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.delete | public function delete()
{
$data = $this->sendRequest($this->getUri(), 'delete');
return new Result($data, $this->getUri(), $this->client, get_called_class());
} | php | public function delete()
{
$data = $this->sendRequest($this->getUri(), 'delete');
return new Result($data, $this->getUri(), $this->client, get_called_class());
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"sendRequest",
"(",
"$",
"this",
"->",
"getUri",
"(",
")",
",",
"'delete'",
")",
";",
"return",
"new",
"Result",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"getUri",... | Delete the resource.
@return Result | [
"Delete",
"the",
"resource",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L443-L448 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.update | public function update(array $values)
{
if ($errors = $this->checkUpdate($values)) {
$message = "Cannot update resource due to validation error(s): " . implode('; ', $errors);
throw new \InvalidArgumentException($message);
}
$data = $this->runOperation('edit', 'patch', $values)->getData();
if (isset($data['_embedded']['entity'])) {
$this->setData($data['_embedded']['entity']);
$this->isFull = true;
}
return new Result($data, $this->baseUrl, $this->client, get_called_class());
} | php | public function update(array $values)
{
if ($errors = $this->checkUpdate($values)) {
$message = "Cannot update resource due to validation error(s): " . implode('; ', $errors);
throw new \InvalidArgumentException($message);
}
$data = $this->runOperation('edit', 'patch', $values)->getData();
if (isset($data['_embedded']['entity'])) {
$this->setData($data['_embedded']['entity']);
$this->isFull = true;
}
return new Result($data, $this->baseUrl, $this->client, get_called_class());
} | [
"public",
"function",
"update",
"(",
"array",
"$",
"values",
")",
"{",
"if",
"(",
"$",
"errors",
"=",
"$",
"this",
"->",
"checkUpdate",
"(",
"$",
"values",
")",
")",
"{",
"$",
"message",
"=",
"\"Cannot update resource due to validation error(s): \"",
".",
"i... | Update the resource.
This updates the resource's internal data with the API response.
@param array $values
@return Result | [
"Update",
"the",
"resource",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L459-L472 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.checkUpdate | protected static function checkUpdate(array $values)
{
$errors = [];
foreach ($values as $key => $value) {
$errors += static::checkProperty($key, $value);
}
return $errors;
} | php | protected static function checkUpdate(array $values)
{
$errors = [];
foreach ($values as $key => $value) {
$errors += static::checkProperty($key, $value);
}
return $errors;
} | [
"protected",
"static",
"function",
"checkUpdate",
"(",
"array",
"$",
"values",
")",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"errors",
"+=",
"static",
"::",
"checkProp... | Validate values for update.
@param array $values
@return string[] An array of validation errors. | [
"Validate",
"values",
"for",
"update",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L481-L488 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.refresh | public function refresh(array $options = [])
{
$request = new Request('get', $this->getUri());
$this->setData(self::send($request, $this->client, $options));
$this->isFull = true;
} | php | public function refresh(array $options = [])
{
$request = new Request('get', $this->getUri());
$this->setData(self::send($request, $this->client, $options));
$this->isFull = true;
} | [
"public",
"function",
"refresh",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"request",
"=",
"new",
"Request",
"(",
"'get'",
",",
"$",
"this",
"->",
"getUri",
"(",
")",
")",
";",
"$",
"this",
"->",
"setData",
"(",
"self",
"::",
"s... | Refresh the resource.
@param array $options | [
"Refresh",
"the",
"resource",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L507-L512 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.operationAvailable | public function operationAvailable($op, $refreshDuringCheck = false)
{
// Ensure this resource is a full representation.
if (!$this->isFull) {
$this->refresh();
$refreshDuringCheck = false;
}
// Check if the operation is available in the HAL links.
$available = $this->isOperationAvailable($op);
if ($available) {
return true;
}
// If not, and $refreshDuringCheck is on, then refresh the resource.
if ($refreshDuringCheck) {
$this->refresh();
$available = $this->isOperationAvailable($op);
}
return $available;
} | php | public function operationAvailable($op, $refreshDuringCheck = false)
{
// Ensure this resource is a full representation.
if (!$this->isFull) {
$this->refresh();
$refreshDuringCheck = false;
}
// Check if the operation is available in the HAL links.
$available = $this->isOperationAvailable($op);
if ($available) {
return true;
}
// If not, and $refreshDuringCheck is on, then refresh the resource.
if ($refreshDuringCheck) {
$this->refresh();
$available = $this->isOperationAvailable($op);
}
return $available;
} | [
"public",
"function",
"operationAvailable",
"(",
"$",
"op",
",",
"$",
"refreshDuringCheck",
"=",
"false",
")",
"{",
"// Ensure this resource is a full representation.",
"if",
"(",
"!",
"$",
"this",
"->",
"isFull",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
"... | Check whether an operation is available on the resource.
@param string $op
@param bool $refreshDuringCheck
@return bool | [
"Check",
"whether",
"an",
"operation",
"is",
"available",
"on",
"the",
"resource",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L530-L551 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.getLink | public function getLink($rel, $absolute = true)
{
if (!$this->hasLink($rel)) {
throw new \InvalidArgumentException("Link not found: $rel");
}
$url = $this->data['_links'][$rel]['href'];
if ($absolute && strpos($url, '//') === false) {
$url = $this->makeAbsoluteUrl($url);
}
return $url;
} | php | public function getLink($rel, $absolute = true)
{
if (!$this->hasLink($rel)) {
throw new \InvalidArgumentException("Link not found: $rel");
}
$url = $this->data['_links'][$rel]['href'];
if ($absolute && strpos($url, '//') === false) {
$url = $this->makeAbsoluteUrl($url);
}
return $url;
} | [
"public",
"function",
"getLink",
"(",
"$",
"rel",
",",
"$",
"absolute",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLink",
"(",
"$",
"rel",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Link not found: $rel\""... | Get a link for a given resource relation.
@param string $rel
@param bool $absolute
@return string | [
"Get",
"a",
"link",
"for",
"a",
"given",
"resource",
"relation",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L585-L595 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.makeAbsoluteUrl | protected function makeAbsoluteUrl($relativeUrl, $baseUrl = null)
{
$baseUrl = $baseUrl ?: $this->baseUrl;
if (empty($baseUrl)) {
throw new \RuntimeException('No base URL');
}
$base = \GuzzleHttp\Psr7\uri_for($baseUrl);
return $base->withPath($relativeUrl)->__toString();
} | php | protected function makeAbsoluteUrl($relativeUrl, $baseUrl = null)
{
$baseUrl = $baseUrl ?: $this->baseUrl;
if (empty($baseUrl)) {
throw new \RuntimeException('No base URL');
}
$base = \GuzzleHttp\Psr7\uri_for($baseUrl);
return $base->withPath($relativeUrl)->__toString();
} | [
"protected",
"function",
"makeAbsoluteUrl",
"(",
"$",
"relativeUrl",
",",
"$",
"baseUrl",
"=",
"null",
")",
"{",
"$",
"baseUrl",
"=",
"$",
"baseUrl",
"?",
":",
"$",
"this",
"->",
"baseUrl",
";",
"if",
"(",
"empty",
"(",
"$",
"baseUrl",
")",
")",
"{",... | Make a URL absolute, based on the base URL.
@param string $relativeUrl
@param string $baseUrl
@return string | [
"Make",
"a",
"URL",
"absolute",
"based",
"on",
"the",
"base",
"URL",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L605-L614 | train |
platformsh/platformsh-client-php | src/Model/ApiResourceBase.php | ApiResourceBase.getProperties | public function getProperties($lazyLoad = true)
{
if ($lazyLoad) {
$this->ensureFull();
}
$keys = $this->getPropertyNames();
return array_intersect_key($this->data, array_flip($keys));
} | php | public function getProperties($lazyLoad = true)
{
if ($lazyLoad) {
$this->ensureFull();
}
$keys = $this->getPropertyNames();
return array_intersect_key($this->data, array_flip($keys));
} | [
"public",
"function",
"getProperties",
"(",
"$",
"lazyLoad",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"lazyLoad",
")",
"{",
"$",
"this",
"->",
"ensureFull",
"(",
")",
";",
"}",
"$",
"keys",
"=",
"$",
"this",
"->",
"getPropertyNames",
"(",
")",
";",
"... | Get an array of this resource's properties and their values.
@param bool $lazyLoad
@return array | [
"Get",
"an",
"array",
"of",
"this",
"resource",
"s",
"properties",
"and",
"their",
"values",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/ApiResourceBase.php#L634-L642 | train |
platformsh/platformsh-client-php | src/Model/Variable.php | Variable.disable | public function disable()
{
if (!$this->getProperty('is_enabled')) {
return new Result([], $this->baseUrl, $this->client, get_called_class());
}
return $this->update(['is_enabled' => false]);
} | php | public function disable()
{
if (!$this->getProperty('is_enabled')) {
return new Result([], $this->baseUrl, $this->client, get_called_class());
}
return $this->update(['is_enabled' => false]);
} | [
"public",
"function",
"disable",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getProperty",
"(",
"'is_enabled'",
")",
")",
"{",
"return",
"new",
"Result",
"(",
"[",
"]",
",",
"$",
"this",
"->",
"baseUrl",
",",
"$",
"this",
"->",
"client",
","... | Disable the variable.
This is only useful if the variable is both inherited and enabled.
Non-inherited variables can be deleted.
@return Result | [
"Disable",
"the",
"variable",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Variable.php#L45-L52 | train |
platformsh/platformsh-client-php | src/Session/Storage/File.php | File.getDefaultDirectory | protected function getDefaultDirectory()
{
// Default to ~/.platformsh/.session, but if it's not writable, fall
// back to the temporary directory.
$default = $this->getHomeDirectory() . '/.platformsh/.session';
if ($this->canWrite($default)) {
return $default;
}
$temp = sys_get_temp_dir() . '/.platformsh-client/.session';
if ($this->canWrite($temp)) {
return $temp;
}
throw new \RuntimeException('Unable to find a writable session storage directory');
} | php | protected function getDefaultDirectory()
{
// Default to ~/.platformsh/.session, but if it's not writable, fall
// back to the temporary directory.
$default = $this->getHomeDirectory() . '/.platformsh/.session';
if ($this->canWrite($default)) {
return $default;
}
$temp = sys_get_temp_dir() . '/.platformsh-client/.session';
if ($this->canWrite($temp)) {
return $temp;
}
throw new \RuntimeException('Unable to find a writable session storage directory');
} | [
"protected",
"function",
"getDefaultDirectory",
"(",
")",
"{",
"// Default to ~/.platformsh/.session, but if it's not writable, fall",
"// back to the temporary directory.",
"$",
"default",
"=",
"$",
"this",
"->",
"getHomeDirectory",
"(",
")",
".",
"'/.platformsh/.session'",
";... | Get the default directory for session files.
@return string | [
"Get",
"the",
"default",
"directory",
"for",
"session",
"files",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Session/Storage/File.php#L28-L42 | train |
platformsh/platformsh-client-php | src/Session/Storage/File.php | File.getHomeDirectory | protected function getHomeDirectory()
{
$home = getenv('HOME');
if (!$home && ($userProfile = getenv('USERPROFILE'))) {
$home = $userProfile;
}
if (!$home || !is_dir($home)) {
throw new \RuntimeException('Could not determine home directory');
}
return $home;
} | php | protected function getHomeDirectory()
{
$home = getenv('HOME');
if (!$home && ($userProfile = getenv('USERPROFILE'))) {
$home = $userProfile;
}
if (!$home || !is_dir($home)) {
throw new \RuntimeException('Could not determine home directory');
}
return $home;
} | [
"protected",
"function",
"getHomeDirectory",
"(",
")",
"{",
"$",
"home",
"=",
"getenv",
"(",
"'HOME'",
")",
";",
"if",
"(",
"!",
"$",
"home",
"&&",
"(",
"$",
"userProfile",
"=",
"getenv",
"(",
"'USERPROFILE'",
")",
")",
")",
"{",
"$",
"home",
"=",
... | Finds the user's home directory.
@return string | [
"Finds",
"the",
"user",
"s",
"home",
"directory",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Session/Storage/File.php#L73-L84 | train |
platformsh/platformsh-client-php | src/Model/Project.php | Project.getSubscriptionId | public function getSubscriptionId()
{
if ($this->hasProperty('subscription_id', false)) {
return $this->getProperty('subscription_id');
}
if (isset($this->data['subscription']['license_uri'])) {
return basename($this->data['subscription']['license_uri']);
}
throw new \RuntimeException('Subscription ID not found');
} | php | public function getSubscriptionId()
{
if ($this->hasProperty('subscription_id', false)) {
return $this->getProperty('subscription_id');
}
if (isset($this->data['subscription']['license_uri'])) {
return basename($this->data['subscription']['license_uri']);
}
throw new \RuntimeException('Subscription ID not found');
} | [
"public",
"function",
"getSubscriptionId",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasProperty",
"(",
"'subscription_id'",
",",
"false",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getProperty",
"(",
"'subscription_id'",
")",
";",
"}",
"if",
"(",
... | Get the subscription ID for the project.
@todo when APIs are unified, this can be a property
@return int | [
"Get",
"the",
"subscription",
"ID",
"for",
"the",
"project",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Project.php#L35-L46 | train |
platformsh/platformsh-client-php | src/Model/Project.php | Project.getGitUrl | public function getGitUrl()
{
// The collection doesn't provide a Git URL, but it does provide the
// right host, so the URL can be calculated.
if (!$this->hasProperty('repository', false)) {
$host = parse_url($this->getUri(), PHP_URL_HOST);
return "{$this->id}@git.{$host}:{$this->id}.git";
}
$repository = $this->getProperty('repository');
return $repository['url'];
} | php | public function getGitUrl()
{
// The collection doesn't provide a Git URL, but it does provide the
// right host, so the URL can be calculated.
if (!$this->hasProperty('repository', false)) {
$host = parse_url($this->getUri(), PHP_URL_HOST);
return "{$this->id}@git.{$host}:{$this->id}.git";
}
$repository = $this->getProperty('repository');
return $repository['url'];
} | [
"public",
"function",
"getGitUrl",
"(",
")",
"{",
"// The collection doesn't provide a Git URL, but it does provide the",
"// right host, so the URL can be calculated.",
"if",
"(",
"!",
"$",
"this",
"->",
"hasProperty",
"(",
"'repository'",
",",
"false",
")",
")",
"{",
"$... | Get the Git URL for the project.
@return string | [
"Get",
"the",
"Git",
"URL",
"for",
"the",
"project",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Project.php#L53-L65 | train |
platformsh/platformsh-client-php | src/Model/Project.php | Project.addUser | public function addUser($user, $role, $byUuid = false)
{
$property = $byUuid ? 'user' : 'email';
$body = [$property => $user, 'role' => $role];
return ProjectAccess::create($body, $this->getLink('access'), $this->client);
} | php | public function addUser($user, $role, $byUuid = false)
{
$property = $byUuid ? 'user' : 'email';
$body = [$property => $user, 'role' => $role];
return ProjectAccess::create($body, $this->getLink('access'), $this->client);
} | [
"public",
"function",
"addUser",
"(",
"$",
"user",
",",
"$",
"role",
",",
"$",
"byUuid",
"=",
"false",
")",
"{",
"$",
"property",
"=",
"$",
"byUuid",
"?",
"'user'",
":",
"'email'",
";",
"$",
"body",
"=",
"[",
"$",
"property",
"=>",
"$",
"user",
"... | Add a new user to a project.
@param string $user The user's UUID or email address (see $byUuid).
@param string $role One of ProjectAccess::$roles.
@param bool $byUuid Set true if $user is a UUID, or false (default) if
$user is an email address.
Note that for legacy reasons, the default for $byUuid is false for
Project::addUser(), but true for Environment::addUser().
@return Result | [
"Add",
"a",
"new",
"user",
"to",
"a",
"project",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Project.php#L90-L96 | train |
platformsh/platformsh-client-php | src/Model/Project.php | Project.addDomain | public function addDomain($name, array $ssl = [])
{
$body = ['name' => $name];
if (!empty($ssl)) {
$body['ssl'] = $ssl;
}
return Domain::create($body, $this->getLink('domains'), $this->client);
} | php | public function addDomain($name, array $ssl = [])
{
$body = ['name' => $name];
if (!empty($ssl)) {
$body['ssl'] = $ssl;
}
return Domain::create($body, $this->getLink('domains'), $this->client);
} | [
"public",
"function",
"addDomain",
"(",
"$",
"name",
",",
"array",
"$",
"ssl",
"=",
"[",
"]",
")",
"{",
"$",
"body",
"=",
"[",
"'name'",
"=>",
"$",
"name",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"ssl",
")",
")",
"{",
"$",
"body",
"[",
... | Add a domain to the project.
@param string $name
@param array $ssl
@return Result | [
"Add",
"a",
"domain",
"to",
"the",
"project",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Project.php#L181-L189 | train |
platformsh/platformsh-client-php | src/Model/Project.php | Project.addIntegration | public function addIntegration($type, array $data = [])
{
$body = ['type' => $type] + $data;
return Integration::create($body, $this->getLink('integrations'), $this->client);
} | php | public function addIntegration($type, array $data = [])
{
$body = ['type' => $type] + $data;
return Integration::create($body, $this->getLink('integrations'), $this->client);
} | [
"public",
"function",
"addIntegration",
"(",
"$",
"type",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"body",
"=",
"[",
"'type'",
"=>",
"$",
"type",
"]",
"+",
"$",
"data",
";",
"return",
"Integration",
"::",
"create",
"(",
"$",
"body",... | Add an integration to the project.
@param string $type
@param array $data
@return Result | [
"Add",
"an",
"integration",
"to",
"the",
"project",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Project.php#L223-L228 | train |
platformsh/platformsh-client-php | src/Model/Project.php | Project.getActivities | public function getActivities($limit = 0, $type = null, $startsAt = null)
{
$options = [];
if ($type !== null) {
$options['query']['type'] = $type;
}
if ($startsAt !== null) {
$options['query']['starts_at'] = Activity::formatStartsAt($startsAt);
}
$activities = Activity::getCollection($this->getUri() . '/activities', $limit, $options, $this->client);
// Guarantee the type filter (works around a temporary bug).
if ($type !== null) {
$activities = array_filter($activities, function (Activity $activity) use ($type) {
return $activity->type === $type;
});
}
return $activities;
} | php | public function getActivities($limit = 0, $type = null, $startsAt = null)
{
$options = [];
if ($type !== null) {
$options['query']['type'] = $type;
}
if ($startsAt !== null) {
$options['query']['starts_at'] = Activity::formatStartsAt($startsAt);
}
$activities = Activity::getCollection($this->getUri() . '/activities', $limit, $options, $this->client);
// Guarantee the type filter (works around a temporary bug).
if ($type !== null) {
$activities = array_filter($activities, function (Activity $activity) use ($type) {
return $activity->type === $type;
});
}
return $activities;
} | [
"public",
"function",
"getActivities",
"(",
"$",
"limit",
"=",
"0",
",",
"$",
"type",
"=",
"null",
",",
"$",
"startsAt",
"=",
"null",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"type",
"!==",
"null",
")",
"{",
"$",
"options",
... | Get a list of project activities.
@param int $limit
Limit the number of activities to return.
@param string $type
Filter activities by type.
@param int $startsAt
A UNIX timestamp for the maximum created date of activities to return.
@return Activity[] | [
"Get",
"a",
"list",
"of",
"project",
"activities",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Project.php#L254-L274 | train |
platformsh/platformsh-client-php | src/Model/Project.php | Project.setVariable | public function setVariable(
$name,
$value,
$json = false,
$visibleBuild = true,
$visibleRuntime = true,
$sensitive = false
) {
// If $value isn't a scalar, assume it's supposed to be JSON.
if (!is_scalar($value)) {
$value = json_encode($value);
$json = true;
}
$values = [
'value' => $value,
'is_json' => $json,
'visible_build' => $visibleBuild,
'visible_runtime' => $visibleRuntime];
if ($sensitive) {
$values['is_sensitive'] = $sensitive;
}
$existing = $this->getVariable($name);
if ($existing) {
return $existing->update($values);
}
$values['name'] = $name;
return ProjectLevelVariable::create($values, $this->getLink('#manage-variables'), $this->client);
} | php | public function setVariable(
$name,
$value,
$json = false,
$visibleBuild = true,
$visibleRuntime = true,
$sensitive = false
) {
// If $value isn't a scalar, assume it's supposed to be JSON.
if (!is_scalar($value)) {
$value = json_encode($value);
$json = true;
}
$values = [
'value' => $value,
'is_json' => $json,
'visible_build' => $visibleBuild,
'visible_runtime' => $visibleRuntime];
if ($sensitive) {
$values['is_sensitive'] = $sensitive;
}
$existing = $this->getVariable($name);
if ($existing) {
return $existing->update($values);
}
$values['name'] = $name;
return ProjectLevelVariable::create($values, $this->getLink('#manage-variables'), $this->client);
} | [
"public",
"function",
"setVariable",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"json",
"=",
"false",
",",
"$",
"visibleBuild",
"=",
"true",
",",
"$",
"visibleRuntime",
"=",
"true",
",",
"$",
"sensitive",
"=",
"false",
")",
"{",
"// If $value isn't a... | Set a variable.
@param string $name
The name of the variable to set.
@param mixed $value
The value of the variable to set. If non-scalar it will be JSON-encoded automatically.
@param bool $json
Whether this variable's value is JSON-encoded.
@param bool $visibleBuild
Whether this this variable should be exposed during the build phase.
@param bool $visibleRuntime
Whether this variable should be exposed during deploy and runtime.
@param bool $sensitive
Whether this variable's value should be readable via the API.
@return Result | [
"Set",
"a",
"variable",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Project.php#L319-L349 | train |
platformsh/platformsh-client-php | src/Model/Project.php | Project.addCertificate | public function addCertificate($certificate, $key, array $chain = [])
{
$options = ['key' => $key, 'certificate' => $certificate, 'chain' => $chain];
return Certificate::create($options, $this->getUri() . '/certificates', $this->client);
} | php | public function addCertificate($certificate, $key, array $chain = [])
{
$options = ['key' => $key, 'certificate' => $certificate, 'chain' => $chain];
return Certificate::create($options, $this->getUri() . '/certificates', $this->client);
} | [
"public",
"function",
"addCertificate",
"(",
"$",
"certificate",
",",
"$",
"key",
",",
"array",
"$",
"chain",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'certificate'",
"=>",
"$",
"certificate",
",",
"'chain'",
... | Add a certificate to the project.
@param string $certificate
@param string $key
@param array $chain
@return Result | [
"Add",
"a",
"certificate",
"to",
"the",
"project",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Project.php#L395-L400 | train |
platformsh/platformsh-client-php | src/Model/Project.php | Project.getProjectBaseFromUrl | public static function getProjectBaseFromUrl($url)
{
if (preg_match('#/api/projects/([^/]+)#', $url, $matches)) {
return uri_for($url)->withPath('/api/projects/' . $matches[1])->__toString();
}
throw new \RuntimeException('Failed to find project ID from URL: ' . $url);
} | php | public static function getProjectBaseFromUrl($url)
{
if (preg_match('#/api/projects/([^/]+)#', $url, $matches)) {
return uri_for($url)->withPath('/api/projects/' . $matches[1])->__toString();
}
throw new \RuntimeException('Failed to find project ID from URL: ' . $url);
} | [
"public",
"static",
"function",
"getProjectBaseFromUrl",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'#/api/projects/([^/]+)#'",
",",
"$",
"url",
",",
"$",
"matches",
")",
")",
"{",
"return",
"uri_for",
"(",
"$",
"url",
")",
"->",
"withPath",... | Find the project base URL from another project resource's URL.
@param string $url
@return string | [
"Find",
"the",
"project",
"base",
"URL",
"from",
"another",
"project",
"resource",
"s",
"URL",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Project.php#L409-L416 | train |
platformsh/platformsh-client-php | src/Model/Billing/PlanRecordQuery.php | PlanRecordQuery.getParams | public function getParams()
{
$filters = array_filter($this->filters, function ($value) {
return $value !== null;
});
$filters = array_map(function ($value) {
return is_array($value) ? ['value' => $value, 'operator' => 'IN'] : $value;
}, $filters);
return count($filters) ? ['filter' => $filters] : [];
} | php | public function getParams()
{
$filters = array_filter($this->filters, function ($value) {
return $value !== null;
});
$filters = array_map(function ($value) {
return is_array($value) ? ['value' => $value, 'operator' => 'IN'] : $value;
}, $filters);
return count($filters) ? ['filter' => $filters] : [];
} | [
"public",
"function",
"getParams",
"(",
")",
"{",
"$",
"filters",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"filters",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"!==",
"null",
";",
"}",
")",
";",
"$",
"filters",
"=",
... | Get the URL query parameters.
@return array | [
"Get",
"the",
"URL",
"query",
"parameters",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Billing/PlanRecordQuery.php#L46-L57 | train |
ezsystems/CommentsBundle | Comments/CommentsRenderer.php | CommentsRenderer.getDefaultProvider | public function getDefaultProvider()
{
if (isset($this->defaultProvider)) {
return $this->getProvider($this->defaultProvider);
}
$providerLabels = array_keys($this->providers);
return $this->providers[$providerLabels[0]];
} | php | public function getDefaultProvider()
{
if (isset($this->defaultProvider)) {
return $this->getProvider($this->defaultProvider);
}
$providerLabels = array_keys($this->providers);
return $this->providers[$providerLabels[0]];
} | [
"public",
"function",
"getDefaultProvider",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"defaultProvider",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getProvider",
"(",
"$",
"this",
"->",
"defaultProvider",
")",
";",
"}",
"$",
"providerL... | Returns the default provider.
If no default provider is set, the first one will be returned.
@return ProviderInterface | [
"Returns",
"the",
"default",
"provider",
".",
"If",
"no",
"default",
"provider",
"is",
"set",
"the",
"first",
"one",
"will",
"be",
"returned",
"."
] | 8475275596fe16ffe467374f19da158d32174521 | https://github.com/ezsystems/CommentsBundle/blob/8475275596fe16ffe467374f19da158d32174521/Comments/CommentsRenderer.php#L107-L116 | train |
ezsystems/CommentsBundle | Twig/Extension/CommentsExtension.php | CommentsExtension.render | public function render(array $options = array(), $provider = null)
{
if (isset($provider)) {
$options['provider'] = $provider;
}
$request = $this->getCurrentRequest();
if (!isset($request)) {
throw new RuntimeException('Comments rendering needs the Request.');
}
return $this->commentsRenderer->render($request, $options);
} | php | public function render(array $options = array(), $provider = null)
{
if (isset($provider)) {
$options['provider'] = $provider;
}
$request = $this->getCurrentRequest();
if (!isset($request)) {
throw new RuntimeException('Comments rendering needs the Request.');
}
return $this->commentsRenderer->render($request, $options);
} | [
"public",
"function",
"render",
"(",
"array",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"provider",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"provider",
")",
")",
"{",
"$",
"options",
"[",
"'provider'",
"]",
"=",
"$",
"provider"... | Triggers comments rendering.
@param array $options
@param string|null $provider Label of the provider to use. If null, the default provider will be used.
@throws \RuntimeException
@return string | [
"Triggers",
"comments",
"rendering",
"."
] | 8475275596fe16ffe467374f19da158d32174521 | https://github.com/ezsystems/CommentsBundle/blob/8475275596fe16ffe467374f19da158d32174521/Twig/Extension/CommentsExtension.php#L71-L83 | train |
ezsystems/CommentsBundle | Twig/Extension/CommentsExtension.php | CommentsExtension.renderForContent | public function renderForContent(ContentInfo $contentInfo, array $options = array(), $provider = null)
{
if (isset($provider)) {
$options['provider'] = $provider;
}
$request = $this->getCurrentRequest();
if (!isset($request)) {
throw new RuntimeException('Comments rendering needs the Request.');
}
return $this->commentsRenderer->renderForContent($contentInfo, $request, $options);
} | php | public function renderForContent(ContentInfo $contentInfo, array $options = array(), $provider = null)
{
if (isset($provider)) {
$options['provider'] = $provider;
}
$request = $this->getCurrentRequest();
if (!isset($request)) {
throw new RuntimeException('Comments rendering needs the Request.');
}
return $this->commentsRenderer->renderForContent($contentInfo, $request, $options);
} | [
"public",
"function",
"renderForContent",
"(",
"ContentInfo",
"$",
"contentInfo",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"provider",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"provider",
")",
")",
"{",
"$",
"options"... | Triggers comments rendering for a given ContentInfo object.
@param ContentInfo $contentInfo
@param array $options
@param string|null $provider Label of the provider to use. If null, the default provider will be used.
@return mixed
@throws \RuntimeException | [
"Triggers",
"comments",
"rendering",
"for",
"a",
"given",
"ContentInfo",
"object",
"."
] | 8475275596fe16ffe467374f19da158d32174521 | https://github.com/ezsystems/CommentsBundle/blob/8475275596fe16ffe467374f19da158d32174521/Twig/Extension/CommentsExtension.php#L96-L108 | train |
platformsh/platformsh-client-php | src/Connection/Connector.php | Connector.revokeTokens | private function revokeTokens()
{
$revocations = array_filter([
'refresh_token' => $this->session->get('refreshToken'),
'access_token' => $this->session->get('accessToken'),
]);
$url = uri_for($this->config['accounts'])
->withPath($this->config['revoke_url'])
->__toString();
foreach ($revocations as $type => $token) {
$this->getClient()->request('post', $url, [
'form_params' => [
'token' => $token,
'token_type_hint' => $type,
],
]);
}
} | php | private function revokeTokens()
{
$revocations = array_filter([
'refresh_token' => $this->session->get('refreshToken'),
'access_token' => $this->session->get('accessToken'),
]);
$url = uri_for($this->config['accounts'])
->withPath($this->config['revoke_url'])
->__toString();
foreach ($revocations as $type => $token) {
$this->getClient()->request('post', $url, [
'form_params' => [
'token' => $token,
'token_type_hint' => $type,
],
]);
}
} | [
"private",
"function",
"revokeTokens",
"(",
")",
"{",
"$",
"revocations",
"=",
"array_filter",
"(",
"[",
"'refresh_token'",
"=>",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"'refreshToken'",
")",
",",
"'access_token'",
"=>",
"$",
"this",
"->",
"session"... | Revokes the access and refresh tokens saved in the session.
@see Connector::logOut()
@throws \GuzzleHttp\Exception\GuzzleException | [
"Revokes",
"the",
"access",
"and",
"refresh",
"tokens",
"saved",
"in",
"the",
"session",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Connection/Connector.php#L149-L166 | train |
platformsh/platformsh-client-php | src/Connection/Connector.php | Connector.saveToken | protected function saveToken(AccessToken $token)
{
if ($this->config['api_token'] && $this->config['api_token_type'] === 'access') {
return;
}
foreach ($token->jsonSerialize() as $name => $value) {
if (isset($this->storageKeys[$name])) {
$this->session->set($this->storageKeys[$name], $value);
}
}
$this->session->save();
} | php | protected function saveToken(AccessToken $token)
{
if ($this->config['api_token'] && $this->config['api_token_type'] === 'access') {
return;
}
foreach ($token->jsonSerialize() as $name => $value) {
if (isset($this->storageKeys[$name])) {
$this->session->set($this->storageKeys[$name], $value);
}
}
$this->session->save();
} | [
"protected",
"function",
"saveToken",
"(",
"AccessToken",
"$",
"token",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'api_token'",
"]",
"&&",
"$",
"this",
"->",
"config",
"[",
"'api_token_type'",
"]",
"===",
"'access'",
")",
"{",
"return",
";"... | Save an access token to the session.
@param AccessToken $token | [
"Save",
"an",
"access",
"token",
"to",
"the",
"session",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Connection/Connector.php#L221-L232 | train |
platformsh/platformsh-client-php | src/Connection/Connector.php | Connector.loadToken | protected function loadToken()
{
if ($this->config['api_token'] && $this->config['api_token_type'] === 'access') {
return new AccessToken([
'access_token' => $this->config['api_token'],
// Skip local expiry checking.
'expires' => 2147483647,
]);
}
if (!$this->session->get($this->storageKeys['access_token'])) {
return null;
}
// These keys are used for saving in the session for backwards
// compatibility with the commerceguys/guzzle-oauth2-plugin package.
$values = [];
foreach ($this->storageKeys as $tokenKey => $sessionKey) {
$value = $this->session->get($sessionKey);
if ($value !== null) {
$values[$tokenKey] = $value;
}
}
return new AccessToken($values);
} | php | protected function loadToken()
{
if ($this->config['api_token'] && $this->config['api_token_type'] === 'access') {
return new AccessToken([
'access_token' => $this->config['api_token'],
// Skip local expiry checking.
'expires' => 2147483647,
]);
}
if (!$this->session->get($this->storageKeys['access_token'])) {
return null;
}
// These keys are used for saving in the session for backwards
// compatibility with the commerceguys/guzzle-oauth2-plugin package.
$values = [];
foreach ($this->storageKeys as $tokenKey => $sessionKey) {
$value = $this->session->get($sessionKey);
if ($value !== null) {
$values[$tokenKey] = $value;
}
}
return new AccessToken($values);
} | [
"protected",
"function",
"loadToken",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'api_token'",
"]",
"&&",
"$",
"this",
"->",
"config",
"[",
"'api_token_type'",
"]",
"===",
"'access'",
")",
"{",
"return",
"new",
"AccessToken",
"(",
"[",
... | Load the current access token.
@return AccessToken|null | [
"Load",
"the",
"current",
"access",
"token",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Connection/Connector.php#L239-L263 | train |
platformsh/platformsh-client-php | src/Connection/Connector.php | Connector.getOauthMiddleware | protected function getOauthMiddleware()
{
if (!$this->oauthMiddleware) {
if (!$this->isLoggedIn()) {
throw new \RuntimeException('Not logged in');
}
$grant = new ClientCredentials();
$grantOptions = [];
// Set up the "exchange" (normal) API token type.
if ($this->config['api_token'] && $this->config['api_token_type'] !== 'access') {
$grant = new ApiToken();
$grantOptions['api_token'] = $this->config['api_token'];
}
$this->oauthMiddleware = new GuzzleMiddleware($this->getProvider(), $grant, $grantOptions);
$this->oauthMiddleware->setTokenSaveCallback(function (AccessToken $token) {
$this->saveToken($token);
});
// If an access token is already available (via an API token or via
// the session) then set it in the middleware in advance.
if ($accessToken = $this->loadToken()) {
$this->oauthMiddleware->setAccessToken($accessToken);
}
}
return $this->oauthMiddleware;
} | php | protected function getOauthMiddleware()
{
if (!$this->oauthMiddleware) {
if (!$this->isLoggedIn()) {
throw new \RuntimeException('Not logged in');
}
$grant = new ClientCredentials();
$grantOptions = [];
// Set up the "exchange" (normal) API token type.
if ($this->config['api_token'] && $this->config['api_token_type'] !== 'access') {
$grant = new ApiToken();
$grantOptions['api_token'] = $this->config['api_token'];
}
$this->oauthMiddleware = new GuzzleMiddleware($this->getProvider(), $grant, $grantOptions);
$this->oauthMiddleware->setTokenSaveCallback(function (AccessToken $token) {
$this->saveToken($token);
});
// If an access token is already available (via an API token or via
// the session) then set it in the middleware in advance.
if ($accessToken = $this->loadToken()) {
$this->oauthMiddleware->setAccessToken($accessToken);
}
}
return $this->oauthMiddleware;
} | [
"protected",
"function",
"getOauthMiddleware",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"oauthMiddleware",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isLoggedIn",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Not logged... | Get an OAuth2 middleware to add to Guzzle clients.
@throws \RuntimeException
@return GuzzleMiddleware | [
"Get",
"an",
"OAuth2",
"middleware",
"to",
"add",
"to",
"Guzzle",
"clients",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Connection/Connector.php#L280-L309 | train |
ezsystems/CommentsBundle | Comments/Provider/TemplateBasedProvider.php | TemplateBasedProvider.doRender | protected function doRender(array $options)
{
$template = isset($options['template']) ? $options['template'] : $this->getDefaultTemplate();
unset($options['template']);
return $this->templateEngine->render($template, $options);
} | php | protected function doRender(array $options)
{
$template = isset($options['template']) ? $options['template'] : $this->getDefaultTemplate();
unset($options['template']);
return $this->templateEngine->render($template, $options);
} | [
"protected",
"function",
"doRender",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"template",
"=",
"isset",
"(",
"$",
"options",
"[",
"'template'",
"]",
")",
"?",
"$",
"options",
"[",
"'template'",
"]",
":",
"$",
"this",
"->",
"getDefaultTemplate",
"(",
... | Renders the template with provided options.
"template" option allows to override the default template for rendering.
@param array $options
@return string | [
"Renders",
"the",
"template",
"with",
"provided",
"options",
".",
"template",
"option",
"allows",
"to",
"override",
"the",
"default",
"template",
"for",
"rendering",
"."
] | 8475275596fe16ffe467374f19da158d32174521 | https://github.com/ezsystems/CommentsBundle/blob/8475275596fe16ffe467374f19da158d32174521/Comments/Provider/TemplateBasedProvider.php#L82-L88 | train |
platformsh/platformsh-client-php | src/Model/Backups/BackupConfig.php | BackupConfig.fromData | public static function fromData(array $data)
{
$policies = [];
foreach (isset($data['schedule']) ? $data['schedule'] : [] as $policyData) {
$policies[] = new Policy($policyData['interval'], $policyData['count']);
}
return new static($policies, isset($data['manual_count']) ? $data['manual_count'] : 1);
} | php | public static function fromData(array $data)
{
$policies = [];
foreach (isset($data['schedule']) ? $data['schedule'] : [] as $policyData) {
$policies[] = new Policy($policyData['interval'], $policyData['count']);
}
return new static($policies, isset($data['manual_count']) ? $data['manual_count'] : 1);
} | [
"public",
"static",
"function",
"fromData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"policies",
"=",
"[",
"]",
";",
"foreach",
"(",
"isset",
"(",
"$",
"data",
"[",
"'schedule'",
"]",
")",
"?",
"$",
"data",
"[",
"'schedule'",
"]",
":",
"[",
"]",
... | Instantiates a backup configuration object from config data.
@param array $data
@return static | [
"Instantiates",
"a",
"backup",
"configuration",
"object",
"from",
"config",
"data",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Backups/BackupConfig.php#L32-L40 | train |
koenpunt/php-inflector | lib/Utils.php | Utils.array_flatten | public static function array_flatten(array $array){
$index = 0;
$count = count($array);
while ($index < $count) {
if (is_array($array[$index])) {
array_splice($array, $index, 1, $array[$index]);
} else {
++$index;
}
$count = count($array);
}
return $array;
} | php | public static function array_flatten(array $array){
$index = 0;
$count = count($array);
while ($index < $count) {
if (is_array($array[$index])) {
array_splice($array, $index, 1, $array[$index]);
} else {
++$index;
}
$count = count($array);
}
return $array;
} | [
"public",
"static",
"function",
"array_flatten",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"index",
"=",
"0",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"array",
")",
";",
"while",
"(",
"$",
"index",
"<",
"$",
"count",
")",
"{",
"if",
"(",
"is_a... | Make multidimensional array flat
@param array $array
@return array
@author Koen Punt | [
"Make",
"multidimensional",
"array",
"flat"
] | 8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1 | https://github.com/koenpunt/php-inflector/blob/8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1/lib/Utils.php#L14-L27 | train |
koenpunt/php-inflector | lib/Utils.php | Utils.array_delete | public static function array_delete(array &$data, $key){
if(array_key_exists($key, $data)){
$value = $data[$key];
unset($data[$key]);
return $value;
}
} | php | public static function array_delete(array &$data, $key){
if(array_key_exists($key, $data)){
$value = $data[$key];
unset($data[$key]);
return $value;
}
} | [
"public",
"static",
"function",
"array_delete",
"(",
"array",
"&",
"$",
"data",
",",
"$",
"key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"data",
")",
")",
"{",
"$",
"value",
"=",
"$",
"data",
"[",
"$",
"key",
"]",
";",... | Deletes entry from array and return its value
@param array $data
@param string $key
@return mixed
@author Koen Punt | [
"Deletes",
"entry",
"from",
"array",
"and",
"return",
"its",
"value"
] | 8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1 | https://github.com/koenpunt/php-inflector/blob/8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1/lib/Utils.php#L37-L43 | train |
platformsh/platformsh-client-php | src/Model/Environment.php | Environment.getCurrentDeployment | public function getCurrentDeployment()
{
$deployment = EnvironmentDeployment::get('current', $this->getUri() . '/deployments', $this->client);
if (!$deployment) {
throw new EnvironmentStateException('Current deployment not found', $this);
}
return $deployment;
} | php | public function getCurrentDeployment()
{
$deployment = EnvironmentDeployment::get('current', $this->getUri() . '/deployments', $this->client);
if (!$deployment) {
throw new EnvironmentStateException('Current deployment not found', $this);
}
return $deployment;
} | [
"public",
"function",
"getCurrentDeployment",
"(",
")",
"{",
"$",
"deployment",
"=",
"EnvironmentDeployment",
"::",
"get",
"(",
"'current'",
",",
"$",
"this",
"->",
"getUri",
"(",
")",
".",
"'/deployments'",
",",
"$",
"this",
"->",
"client",
")",
";",
"if"... | Get the current deployment of this environment.
@throws \RuntimeException if no current deployment is found.
@return EnvironmentDeployment | [
"Get",
"the",
"current",
"deployment",
"of",
"this",
"environment",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Environment.php#L66-L74 | train |
platformsh/platformsh-client-php | src/Model/Environment.php | Environment.getHeadCommit | public function getHeadCommit()
{
$base = Project::getProjectBaseFromUrl($this->getUri()) . '/git/commits';
return Commit::get($this->head_commit, $base, $this->client);
} | php | public function getHeadCommit()
{
$base = Project::getProjectBaseFromUrl($this->getUri()) . '/git/commits';
return Commit::get($this->head_commit, $base, $this->client);
} | [
"public",
"function",
"getHeadCommit",
"(",
")",
"{",
"$",
"base",
"=",
"Project",
"::",
"getProjectBaseFromUrl",
"(",
"$",
"this",
"->",
"getUri",
"(",
")",
")",
".",
"'/git/commits'",
";",
"return",
"Commit",
"::",
"get",
"(",
"$",
"this",
"->",
"head_... | Get the Git commit for the HEAD of this environment.
@return Commit|false | [
"Get",
"the",
"Git",
"commit",
"for",
"the",
"HEAD",
"of",
"this",
"environment",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Environment.php#L81-L86 | train |
platformsh/platformsh-client-php | src/Model/Environment.php | Environment.getSshUrl | public function getSshUrl($app = '')
{
$urls = $this->getSshUrls();
if (isset($urls[$app])) {
return $urls[$app];
}
return $this->constructLegacySshUrl($app);
} | php | public function getSshUrl($app = '')
{
$urls = $this->getSshUrls();
if (isset($urls[$app])) {
return $urls[$app];
}
return $this->constructLegacySshUrl($app);
} | [
"public",
"function",
"getSshUrl",
"(",
"$",
"app",
"=",
"''",
")",
"{",
"$",
"urls",
"=",
"$",
"this",
"->",
"getSshUrls",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"urls",
"[",
"$",
"app",
"]",
")",
")",
"{",
"return",
"$",
"urls",
"[",
... | Get the SSH URL for the environment.
@param string $app An application name.
@throws EnvironmentStateException
@throws OperationUnavailableException
@return string | [
"Get",
"the",
"SSH",
"URL",
"for",
"the",
"environment",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Environment.php#L98-L106 | train |
platformsh/platformsh-client-php | src/Model/Environment.php | Environment.constructLegacySshUrl | private function constructLegacySshUrl()
{
if (!$this->hasLink('ssh')) {
$id = $this->data['id'];
if (!$this->isActive()) {
throw new EnvironmentStateException("No SSH URL found for environment '$id'. It is not currently active.", $this);
}
throw new OperationUnavailableException("No SSH URL found for environment '$id'. You may not have permission to SSH.");
}
return $this->convertSshUrl($this->getLink('ssh'));
} | php | private function constructLegacySshUrl()
{
if (!$this->hasLink('ssh')) {
$id = $this->data['id'];
if (!$this->isActive()) {
throw new EnvironmentStateException("No SSH URL found for environment '$id'. It is not currently active.", $this);
}
throw new OperationUnavailableException("No SSH URL found for environment '$id'. You may not have permission to SSH.");
}
return $this->convertSshUrl($this->getLink('ssh'));
} | [
"private",
"function",
"constructLegacySshUrl",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLink",
"(",
"'ssh'",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"data",
"[",
"'id'",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isActi... | Get the SSH URL via the legacy 'ssh' link.
@return string | [
"Get",
"the",
"SSH",
"URL",
"via",
"the",
"legacy",
"ssh",
"link",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Environment.php#L113-L124 | train |
platformsh/platformsh-client-php | src/Model/Environment.php | Environment.getSshUrls | public function getSshUrls()
{
$prefix = 'pf:ssh:';
$prefixLength = strlen($prefix);
$sshUrls = [];
foreach ($this->data['_links'] as $rel => $link) {
if (strpos($rel, $prefix) === 0 && isset($link['href'])) {
$sshUrls[substr($rel, $prefixLength)] = $this->convertSshUrl($link['href']);
}
}
if (empty($sshUrls) && $this->hasLink('ssh')) {
$sshUrls[''] = $this->convertSshUrl($this->getLink('ssh'));
}
return $sshUrls;
} | php | public function getSshUrls()
{
$prefix = 'pf:ssh:';
$prefixLength = strlen($prefix);
$sshUrls = [];
foreach ($this->data['_links'] as $rel => $link) {
if (strpos($rel, $prefix) === 0 && isset($link['href'])) {
$sshUrls[substr($rel, $prefixLength)] = $this->convertSshUrl($link['href']);
}
}
if (empty($sshUrls) && $this->hasLink('ssh')) {
$sshUrls[''] = $this->convertSshUrl($this->getLink('ssh'));
}
return $sshUrls;
} | [
"public",
"function",
"getSshUrls",
"(",
")",
"{",
"$",
"prefix",
"=",
"'pf:ssh:'",
";",
"$",
"prefixLength",
"=",
"strlen",
"(",
"$",
"prefix",
")",
";",
"$",
"sshUrls",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"[",
"'_links'",... | Returns a list of SSH URLs, keyed by app name.
@return string[] | [
"Returns",
"a",
"list",
"of",
"SSH",
"URLs",
"keyed",
"by",
"app",
"name",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Environment.php#L149-L164 | train |
platformsh/platformsh-client-php | src/Model/Environment.php | Environment.getPublicUrl | public function getPublicUrl()
{
if (!$this->hasLink('public-url')) {
$id = $this->data['id'];
if (!$this->isActive()) {
throw new EnvironmentStateException("No public URL found for environment '$id'. It is not currently active.", $this);
}
throw new OperationUnavailableException("No public URL found for environment '$id'.");
}
return $this->getLink('public-url');
} | php | public function getPublicUrl()
{
if (!$this->hasLink('public-url')) {
$id = $this->data['id'];
if (!$this->isActive()) {
throw new EnvironmentStateException("No public URL found for environment '$id'. It is not currently active.", $this);
}
throw new OperationUnavailableException("No public URL found for environment '$id'.");
}
return $this->getLink('public-url');
} | [
"public",
"function",
"getPublicUrl",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLink",
"(",
"'public-url'",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"data",
"[",
"'id'",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isActive"... | Get the public URL for the environment.
@throws EnvironmentStateException
@deprecated You should use routes to get the correct URL(s)
@see self::getRouteUrls()
@return string | [
"Get",
"the",
"public",
"URL",
"for",
"the",
"environment",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Environment.php#L176-L187 | train |
platformsh/platformsh-client-php | src/Model/Environment.php | Environment.synchronize | public function synchronize($data = false, $code = false, $rebase = false)
{
if (!$data && !$code) {
throw new \InvalidArgumentException('Nothing to synchronize: you must specify $data or $code');
}
$body = [
'synchronize_data' => $data,
'synchronize_code' => $code,
];
if ($rebase) {
// @todo always add this (when the rebase option is GA)
$body['rebase'] = $rebase;
}
return $this->runLongOperation('synchronize', 'post', $body);
} | php | public function synchronize($data = false, $code = false, $rebase = false)
{
if (!$data && !$code) {
throw new \InvalidArgumentException('Nothing to synchronize: you must specify $data or $code');
}
$body = [
'synchronize_data' => $data,
'synchronize_code' => $code,
];
if ($rebase) {
// @todo always add this (when the rebase option is GA)
$body['rebase'] = $rebase;
}
return $this->runLongOperation('synchronize', 'post', $body);
} | [
"public",
"function",
"synchronize",
"(",
"$",
"data",
"=",
"false",
",",
"$",
"code",
"=",
"false",
",",
"$",
"rebase",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"data",
"&&",
"!",
"$",
"code",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentEx... | Synchronize an environment with its parent.
@param bool $code Synchronize code.
@param bool $data Synchronize data.
@param bool $rebase Synchronize code by rebasing instead of merging.
@throws \InvalidArgumentException
@return Activity | [
"Synchronize",
"an",
"environment",
"with",
"its",
"parent",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Environment.php#L322-L337 | train |
platformsh/platformsh-client-php | src/Model/Environment.php | Environment.setVariable | public function setVariable(
$name,
$value,
$json = false,
$enabled = true,
$sensitive = false
)
{
if (!is_scalar($value)) {
$value = json_encode($value);
$json = true;
}
$values = ['value' => $value, 'is_json' => $json, 'is_enabled' => $enabled];
if ($sensitive) {
$values['is_sensitive'] = $sensitive;
}
$existing = $this->getVariable($name);
if ($existing) {
return $existing->update($values);
}
$values['name'] = $name;
return Variable::create($values, $this->getLink('#manage-variables'), $this->client);
} | php | public function setVariable(
$name,
$value,
$json = false,
$enabled = true,
$sensitive = false
)
{
if (!is_scalar($value)) {
$value = json_encode($value);
$json = true;
}
$values = ['value' => $value, 'is_json' => $json, 'is_enabled' => $enabled];
if ($sensitive) {
$values['is_sensitive'] = $sensitive;
}
$existing = $this->getVariable($name);
if ($existing) {
return $existing->update($values);
}
$values['name'] = $name;
return Variable::create($values, $this->getLink('#manage-variables'), $this->client);
} | [
"public",
"function",
"setVariable",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"json",
"=",
"false",
",",
"$",
"enabled",
"=",
"true",
",",
"$",
"sensitive",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"... | Set a variable
@param string $name
@param mixed $value
@param bool $json
@param bool $enabled
@param bool $sensitive
@return Result | [
"Set",
"a",
"variable"
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Environment.php#L418-L441 | train |
platformsh/platformsh-client-php | src/Model/Environment.php | Environment.getRouteUrls | public function getRouteUrls()
{
$routes = [];
if (isset($this->data['_links']['pf:routes'])) {
foreach ($this->data['_links']['pf:routes'] as $route) {
$routes[] = $route['href'];
}
}
return $routes;
} | php | public function getRouteUrls()
{
$routes = [];
if (isset($this->data['_links']['pf:routes'])) {
foreach ($this->data['_links']['pf:routes'] as $route) {
$routes[] = $route['href'];
}
}
return $routes;
} | [
"public",
"function",
"getRouteUrls",
"(",
")",
"{",
"$",
"routes",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"'_links'",
"]",
"[",
"'pf:routes'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"... | Get the resolved URLs for the environment's routes.
@return string[] | [
"Get",
"the",
"resolved",
"URLs",
"for",
"the",
"environment",
"s",
"routes",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Environment.php#L472-L482 | train |
platformsh/platformsh-client-php | src/Model/Environment.php | Environment.addUser | public function addUser($user, $role, $byUuid = true)
{
$property = $byUuid ? 'user' : 'email';
$body = [$property => $user, 'role' => $role];
return EnvironmentAccess::create($body, $this->getLink('#manage-access'), $this->client);
} | php | public function addUser($user, $role, $byUuid = true)
{
$property = $byUuid ? 'user' : 'email';
$body = [$property => $user, 'role' => $role];
return EnvironmentAccess::create($body, $this->getLink('#manage-access'), $this->client);
} | [
"public",
"function",
"addUser",
"(",
"$",
"user",
",",
"$",
"role",
",",
"$",
"byUuid",
"=",
"true",
")",
"{",
"$",
"property",
"=",
"$",
"byUuid",
"?",
"'user'",
":",
"'email'",
";",
"$",
"body",
"=",
"[",
"$",
"property",
"=>",
"$",
"user",
",... | Add a new user to the environment.
@param string $user The user's UUID or email address (see $byUuid).
@param string $role One of EnvironmentAccess::$roles.
@param bool $byUuid Set true (default) if $user is a UUID, or false if
$user is an email address.
Note that for legacy reasons, the default for $byUuid is false for
Project::addUser(), but true for Environment::addUser().
@return Result | [
"Add",
"a",
"new",
"user",
"to",
"the",
"environment",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Environment.php#L543-L549 | train |
platformsh/platformsh-client-php | src/Model/Environment.php | Environment.addBackupPolicy | public function addBackupPolicy(Policy $policy)
{
$backups = isset($this->data['backups']) ? $this->data['backups'] : [];
$backups['schedule'][] = [
'interval' => $policy->getInterval(),
'count' => $policy->getCount(),
];
if (!isset($backups['manual_count'])) {
$backups['manual_count'] = 3;
}
return $this->update(['backups' => $backups]);
} | php | public function addBackupPolicy(Policy $policy)
{
$backups = isset($this->data['backups']) ? $this->data['backups'] : [];
$backups['schedule'][] = [
'interval' => $policy->getInterval(),
'count' => $policy->getCount(),
];
if (!isset($backups['manual_count'])) {
$backups['manual_count'] = 3;
}
return $this->update(['backups' => $backups]);
} | [
"public",
"function",
"addBackupPolicy",
"(",
"Policy",
"$",
"policy",
")",
"{",
"$",
"backups",
"=",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"'backups'",
"]",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"'backups'",
"]",
":",
"[",
"]",
";",
"$... | Add a scheduled backup policy.
@param \Platformsh\Client\Model\Backups\Policy $policy
@return \Platformsh\Client\Model\Result | [
"Add",
"a",
"scheduled",
"backup",
"policy",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Environment.php#L593-L605 | train |
koenpunt/php-inflector | lib/Inflector/Transliterate.php | Transliterate.parameterize | public static function parameterize($string, $sep = '-'){
# replace accented chars with their ascii equivalents
$parameterized_string = static::transliterate($string);
# Turn unwanted chars into the separator
$parameterized_string = preg_replace('/[^a-z0-9\-_]+/i', $sep, $parameterized_string);
if(!(is_null($sep) || empty($sep))){
$re_sep = preg_quote($sep); # CoreExt\Regexp::escape
# No more than one of the separator in a row.
$parameterized_string = preg_replace("/{$re_sep}{2,}/", $sep, $parameterized_string);
# Remove leading/trailing separator.
$parameterized_string = preg_replace("/^{$re_sep}|{$re_sep}$/i", '', $parameterized_string);
}
return strtolower($parameterized_string);
} | php | public static function parameterize($string, $sep = '-'){
# replace accented chars with their ascii equivalents
$parameterized_string = static::transliterate($string);
# Turn unwanted chars into the separator
$parameterized_string = preg_replace('/[^a-z0-9\-_]+/i', $sep, $parameterized_string);
if(!(is_null($sep) || empty($sep))){
$re_sep = preg_quote($sep); # CoreExt\Regexp::escape
# No more than one of the separator in a row.
$parameterized_string = preg_replace("/{$re_sep}{2,}/", $sep, $parameterized_string);
# Remove leading/trailing separator.
$parameterized_string = preg_replace("/^{$re_sep}|{$re_sep}$/i", '', $parameterized_string);
}
return strtolower($parameterized_string);
} | [
"public",
"static",
"function",
"parameterize",
"(",
"$",
"string",
",",
"$",
"sep",
"=",
"'-'",
")",
"{",
"# replace accented chars with their ascii equivalents",
"$",
"parameterized_string",
"=",
"static",
"::",
"transliterate",
"(",
"$",
"string",
")",
";",
"# ... | Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
==== Examples
parameterize("Donald E. Knuth") # => "donald-e-knuth"
@param string $string
@param string $sep
@return string $string with special characters replaced
@author Koen Punt | [
"Replaces",
"special",
"characters",
"in",
"a",
"string",
"so",
"that",
"it",
"may",
"be",
"used",
"as",
"part",
"of",
"a",
"pretty",
"URL",
"."
] | 8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1 | https://github.com/koenpunt/php-inflector/blob/8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1/lib/Inflector/Transliterate.php#L34-L47 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.getProject | public function getProject($id, $hostname = null, $https = true)
{
// Search for a project in the user's project list.
foreach ($this->getProjects() as $project) {
if ($project->id === $id) {
return $project;
}
}
// Look for a project directly if the hostname is known.
if ($hostname !== null) {
return $this->getProjectDirect($id, $hostname, $https);
}
// Use the project locator.
if ($url = $this->locateProject($id)) {
return Project::get($url, null, $this->connector->getClient());
}
return false;
} | php | public function getProject($id, $hostname = null, $https = true)
{
// Search for a project in the user's project list.
foreach ($this->getProjects() as $project) {
if ($project->id === $id) {
return $project;
}
}
// Look for a project directly if the hostname is known.
if ($hostname !== null) {
return $this->getProjectDirect($id, $hostname, $https);
}
// Use the project locator.
if ($url = $this->locateProject($id)) {
return Project::get($url, null, $this->connector->getClient());
}
return false;
} | [
"public",
"function",
"getProject",
"(",
"$",
"id",
",",
"$",
"hostname",
"=",
"null",
",",
"$",
"https",
"=",
"true",
")",
"{",
"// Search for a project in the user's project list.",
"foreach",
"(",
"$",
"this",
"->",
"getProjects",
"(",
")",
"as",
"$",
"pr... | Get a single project by its ID.
@param string $id
@param string $hostname
@param bool $https
@return Project|false | [
"Get",
"a",
"single",
"project",
"by",
"its",
"ID",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L55-L75 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.getProjects | public function getProjects($reset = false)
{
$data = $this->getAccountInfo($reset);
$client = $this->connector->getClient();
$projects = [];
foreach ($data['projects'] as $project) {
// Each project has its own endpoint on a Platform.sh region.
$projects[] = new Project($project, $project['endpoint'], $client);
}
return $projects;
} | php | public function getProjects($reset = false)
{
$data = $this->getAccountInfo($reset);
$client = $this->connector->getClient();
$projects = [];
foreach ($data['projects'] as $project) {
// Each project has its own endpoint on a Platform.sh region.
$projects[] = new Project($project, $project['endpoint'], $client);
}
return $projects;
} | [
"public",
"function",
"getProjects",
"(",
"$",
"reset",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getAccountInfo",
"(",
"$",
"reset",
")",
";",
"$",
"client",
"=",
"$",
"this",
"->",
"connector",
"->",
"getClient",
"(",
")",
";",
... | Get the logged-in user's projects.
@param bool $reset
@return Project[] | [
"Get",
"the",
"logged",
"-",
"in",
"user",
"s",
"projects",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L84-L95 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.getAccountInfo | public function getAccountInfo($reset = false)
{
if (!isset($this->accountInfo) || $reset) {
$url = $this->accountsEndpoint . 'me';
try {
$this->accountInfo = $this->simpleGet($url);
}
catch (BadResponseException $e) {
throw ApiResponseException::create($e->getRequest(), $e->getResponse(), $e->getPrevious());
}
}
return $this->accountInfo;
} | php | public function getAccountInfo($reset = false)
{
if (!isset($this->accountInfo) || $reset) {
$url = $this->accountsEndpoint . 'me';
try {
$this->accountInfo = $this->simpleGet($url);
}
catch (BadResponseException $e) {
throw ApiResponseException::create($e->getRequest(), $e->getResponse(), $e->getPrevious());
}
}
return $this->accountInfo;
} | [
"public",
"function",
"getAccountInfo",
"(",
"$",
"reset",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"accountInfo",
")",
"||",
"$",
"reset",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"accountsEndpoint",
".",
"'me'",... | Get account information for the logged-in user.
@param bool $reset
@return array | [
"Get",
"account",
"information",
"for",
"the",
"logged",
"-",
"in",
"user",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L104-L117 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.simpleGet | private function simpleGet($url, array $options = [])
{
return (array) \GuzzleHttp\json_decode(
$this->getConnector()
->getClient()
->request('get', $url, $options)
->getBody()
->getContents(),
true
);
} | php | private function simpleGet($url, array $options = [])
{
return (array) \GuzzleHttp\json_decode(
$this->getConnector()
->getClient()
->request('get', $url, $options)
->getBody()
->getContents(),
true
);
} | [
"private",
"function",
"simpleGet",
"(",
"$",
"url",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"(",
"array",
")",
"\\",
"GuzzleHttp",
"\\",
"json_decode",
"(",
"$",
"this",
"->",
"getConnector",
"(",
")",
"->",
"getClient",
"(",
... | Get a URL and return the JSON-decoded response.
@param string $url
@param array $options
@return array | [
"Get",
"a",
"URL",
"and",
"return",
"the",
"JSON",
"-",
"decoded",
"response",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L127-L137 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.getProjectDirect | public function getProjectDirect($id, $hostname, $https = true)
{
$scheme = $https ? 'https' : 'http';
$collection = "$scheme://$hostname/api/projects";
return Project::get($id, $collection, $this->connector->getClient());
} | php | public function getProjectDirect($id, $hostname, $https = true)
{
$scheme = $https ? 'https' : 'http';
$collection = "$scheme://$hostname/api/projects";
return Project::get($id, $collection, $this->connector->getClient());
} | [
"public",
"function",
"getProjectDirect",
"(",
"$",
"id",
",",
"$",
"hostname",
",",
"$",
"https",
"=",
"true",
")",
"{",
"$",
"scheme",
"=",
"$",
"https",
"?",
"'https'",
":",
"'http'",
";",
"$",
"collection",
"=",
"\"$scheme://$hostname/api/projects\"",
... | Get a single project at a known location.
@param string $id The project ID.
@param string $hostname The hostname of the Platform.sh regional API,
e.g. 'eu.platform.sh' or 'us.platform.sh'.
@param bool $https Whether to use HTTPS (default: true).
@internal It's now better to use getProject(). This method will be made
private in a future release.
@return Project|false | [
"Get",
"a",
"single",
"project",
"at",
"a",
"known",
"location",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L152-L157 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.locateProject | protected function locateProject($id)
{
$url = $this->accountsEndpoint . 'projects/' . rawurlencode($id);
try {
$result = $this->simpleGet($url);
}
catch (BadResponseException $e) {
$response = $e->getResponse();
// @todo Remove 400 from this array when the API is more liberal in validating project IDs.
$ignoredErrorCodes = [400, 403, 404];
if ($response && in_array($response->getStatusCode(), $ignoredErrorCodes)) {
return false;
}
throw ApiResponseException::create($e->getRequest(), $e->getResponse(), $e->getPrevious());
}
return isset($result['endpoint']) ? $result['endpoint'] : false;
} | php | protected function locateProject($id)
{
$url = $this->accountsEndpoint . 'projects/' . rawurlencode($id);
try {
$result = $this->simpleGet($url);
}
catch (BadResponseException $e) {
$response = $e->getResponse();
// @todo Remove 400 from this array when the API is more liberal in validating project IDs.
$ignoredErrorCodes = [400, 403, 404];
if ($response && in_array($response->getStatusCode(), $ignoredErrorCodes)) {
return false;
}
throw ApiResponseException::create($e->getRequest(), $e->getResponse(), $e->getPrevious());
}
return isset($result['endpoint']) ? $result['endpoint'] : false;
} | [
"protected",
"function",
"locateProject",
"(",
"$",
"id",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"accountsEndpoint",
".",
"'projects/'",
".",
"rawurlencode",
"(",
"$",
"id",
")",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"simpleGet... | Locate a project by ID.
@param string $id
The project ID.
@return string
The project's API endpoint. | [
"Locate",
"a",
"project",
"by",
"ID",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L168-L185 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.getSshKeys | public function getSshKeys($reset = false)
{
$data = $this->getAccountInfo($reset);
return SshKey::wrapCollection($data['ssh_keys'], $this->accountsEndpoint, $this->connector->getClient());
} | php | public function getSshKeys($reset = false)
{
$data = $this->getAccountInfo($reset);
return SshKey::wrapCollection($data['ssh_keys'], $this->accountsEndpoint, $this->connector->getClient());
} | [
"public",
"function",
"getSshKeys",
"(",
"$",
"reset",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getAccountInfo",
"(",
"$",
"reset",
")",
";",
"return",
"SshKey",
"::",
"wrapCollection",
"(",
"$",
"data",
"[",
"'ssh_keys'",
"]",
","... | Get the logged-in user's SSH keys.
@param bool $reset
@return SshKey[] | [
"Get",
"the",
"logged",
"-",
"in",
"user",
"s",
"SSH",
"keys",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L194-L199 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.getSshKey | public function getSshKey($id)
{
$url = $this->accountsEndpoint . 'ssh_keys';
return SshKey::get($id, $url, $this->connector->getClient());
} | php | public function getSshKey($id)
{
$url = $this->accountsEndpoint . 'ssh_keys';
return SshKey::get($id, $url, $this->connector->getClient());
} | [
"public",
"function",
"getSshKey",
"(",
"$",
"id",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"accountsEndpoint",
".",
"'ssh_keys'",
";",
"return",
"SshKey",
"::",
"get",
"(",
"$",
"id",
",",
"$",
"url",
",",
"$",
"this",
"->",
"connector",
"->",
... | Get a single SSH key by its ID.
@param string|int $id
@return SshKey|false | [
"Get",
"a",
"single",
"SSH",
"key",
"by",
"its",
"ID",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L208-L213 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.addSshKey | public function addSshKey($value, $title = null)
{
$values = $this->cleanRequest(['value' => $value, 'title' => $title]);
$url = $this->accountsEndpoint . 'ssh_keys';
return SshKey::create($values, $url, $this->connector->getClient());
} | php | public function addSshKey($value, $title = null)
{
$values = $this->cleanRequest(['value' => $value, 'title' => $title]);
$url = $this->accountsEndpoint . 'ssh_keys';
return SshKey::create($values, $url, $this->connector->getClient());
} | [
"public",
"function",
"addSshKey",
"(",
"$",
"value",
",",
"$",
"title",
"=",
"null",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"cleanRequest",
"(",
"[",
"'value'",
"=>",
"$",
"value",
",",
"'title'",
"=>",
"$",
"title",
"]",
")",
";",
"$",
... | Add an SSH public key to the logged-in user's account.
@param string $value The SSH key value.
@param string $title A title for the key (optional).
@return Result | [
"Add",
"an",
"SSH",
"public",
"key",
"to",
"the",
"logged",
"-",
"in",
"user",
"s",
"account",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L223-L229 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.createSubscription | public function createSubscription($region, $plan = 'development', $title = null, $storage = null, $environments = null, array $activationCallback = null)
{
$url = $this->accountsEndpoint . 'subscriptions';
$values = $this->cleanRequest([
'project_region' => $region,
'plan' => $plan,
'project_title' => $title,
'storage' => $storage,
'environments' => $environments,
'activation_callback' => $activationCallback,
]);
return Subscription::create($values, $url, $this->connector->getClient());
} | php | public function createSubscription($region, $plan = 'development', $title = null, $storage = null, $environments = null, array $activationCallback = null)
{
$url = $this->accountsEndpoint . 'subscriptions';
$values = $this->cleanRequest([
'project_region' => $region,
'plan' => $plan,
'project_title' => $title,
'storage' => $storage,
'environments' => $environments,
'activation_callback' => $activationCallback,
]);
return Subscription::create($values, $url, $this->connector->getClient());
} | [
"public",
"function",
"createSubscription",
"(",
"$",
"region",
",",
"$",
"plan",
"=",
"'development'",
",",
"$",
"title",
"=",
"null",
",",
"$",
"storage",
"=",
"null",
",",
"$",
"environments",
"=",
"null",
",",
"array",
"$",
"activationCallback",
"=",
... | Create a new Platform.sh subscription.
@param string $region The region ID. See getRegions().
@param string $plan The plan. See Subscription::$availablePlans.
@param string $title The project title.
@param int $storage The storage of each environment, in MiB.
@param int $environments The number of available environments.
@param array $activationCallback An activation callback for the subscription.
@see PlatformClient::getRegions()
@see Subscription::wait()
@return Subscription
A subscription, representing a project. Use Subscription::wait() or
similar code to wait for the subscription's project to be provisioned
and activated. | [
"Create",
"a",
"new",
"Platform",
".",
"sh",
"subscription",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L263-L276 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.getSubscriptions | public function getSubscriptions()
{
$url = $this->accountsEndpoint . 'subscriptions';
return Subscription::getCollection($url, 0, [], $this->connector->getClient());
} | php | public function getSubscriptions()
{
$url = $this->accountsEndpoint . 'subscriptions';
return Subscription::getCollection($url, 0, [], $this->connector->getClient());
} | [
"public",
"function",
"getSubscriptions",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"accountsEndpoint",
".",
"'subscriptions'",
";",
"return",
"Subscription",
"::",
"getCollection",
"(",
"$",
"url",
",",
"0",
",",
"[",
"]",
",",
"$",
"this",
"->... | Get a list of your Platform.sh subscriptions.
@return Subscription[] | [
"Get",
"a",
"list",
"of",
"your",
"Platform",
".",
"sh",
"subscriptions",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L283-L287 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.getSubscription | public function getSubscription($id)
{
$url = $this->accountsEndpoint . 'subscriptions';
return Subscription::get($id, $url, $this->connector->getClient());
} | php | public function getSubscription($id)
{
$url = $this->accountsEndpoint . 'subscriptions';
return Subscription::get($id, $url, $this->connector->getClient());
} | [
"public",
"function",
"getSubscription",
"(",
"$",
"id",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"accountsEndpoint",
".",
"'subscriptions'",
";",
"return",
"Subscription",
"::",
"get",
"(",
"$",
"id",
",",
"$",
"url",
",",
"$",
"this",
"->",
"con... | Get a subscription by its ID.
@param string|int $id
@return Subscription|false | [
"Get",
"a",
"subscription",
"by",
"its",
"ID",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L296-L300 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.getSubscriptionEstimate | public function getSubscriptionEstimate($plan, $storage, $environments, $users)
{
$options = [];
$options['query'] = [
'plan' => $plan,
'storage' => $storage,
'environments' => $environments,
'user_licenses' => $users,
];
try {
return $this->simpleGet($this->accountsEndpoint . 'estimate', $options);
} catch (BadResponseException $e) {
throw ApiResponseException::create($e->getRequest(), $e->getResponse(), $e->getPrevious());
}
} | php | public function getSubscriptionEstimate($plan, $storage, $environments, $users)
{
$options = [];
$options['query'] = [
'plan' => $plan,
'storage' => $storage,
'environments' => $environments,
'user_licenses' => $users,
];
try {
return $this->simpleGet($this->accountsEndpoint . 'estimate', $options);
} catch (BadResponseException $e) {
throw ApiResponseException::create($e->getRequest(), $e->getResponse(), $e->getPrevious());
}
} | [
"public",
"function",
"getSubscriptionEstimate",
"(",
"$",
"plan",
",",
"$",
"storage",
",",
"$",
"environments",
",",
"$",
"users",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"$",
"options",
"[",
"'query'",
"]",
"=",
"[",
"'plan'",
"=>",
"$",
"pl... | Estimate the cost of a subscription.
@param string $plan The plan (see Subscription::$availablePlans).
@param int $storage The allowed storage per environment (in GiB).
@param int $environments The number of environments.
@param int $users The number of users.
@return array An array containing at least 'total' (a formatted price). | [
"Estimate",
"the",
"cost",
"of",
"a",
"subscription",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L312-L326 | train |
platformsh/platformsh-client-php | src/PlatformClient.php | PlatformClient.getPlanRecords | public function getPlanRecords(PlanRecordQuery $query = null)
{
$url = $this->accountsEndpoint . 'records/plan';
$options = [];
if ($query) {
$options['query'] = $query->getParams();
}
return PlanRecord::getCollection($url, 0, $options, $this->connector->getClient());
} | php | public function getPlanRecords(PlanRecordQuery $query = null)
{
$url = $this->accountsEndpoint . 'records/plan';
$options = [];
if ($query) {
$options['query'] = $query->getParams();
}
return PlanRecord::getCollection($url, 0, $options, $this->connector->getClient());
} | [
"public",
"function",
"getPlanRecords",
"(",
"PlanRecordQuery",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"accountsEndpoint",
".",
"'records/plan'",
";",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"query",
")",
"... | Get plan records.
@param PlanRecordQuery|null $query A query to restrict the returned plans.
@return PlanRecord[] | [
"Get",
"plan",
"records",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/PlatformClient.php#L345-L355 | train |
koenpunt/php-inflector | lib/Inflector/Inflections.php | Inflections.acronym | public function acronym($word){
$this->acronyms[strtolower($word)] = $word;
$this->acronym_regex = implode('|', $this->acronyms);
} | php | public function acronym($word){
$this->acronyms[strtolower($word)] = $word;
$this->acronym_regex = implode('|', $this->acronyms);
} | [
"public",
"function",
"acronym",
"(",
"$",
"word",
")",
"{",
"$",
"this",
"->",
"acronyms",
"[",
"strtolower",
"(",
"$",
"word",
")",
"]",
"=",
"$",
"word",
";",
"$",
"this",
"->",
"acronym_regex",
"=",
"implode",
"(",
"'|'",
",",
"$",
"this",
"->"... | Specifies a new acronym. An acronym must be specified as it will appear in a camelized string. An underscore
string that contains the acronym will retain the acronym when passed to `camelize`, `humanize`, or `titleize`.
A camelized string that contains the acronym will maintain the acronym when titleized or humanized, and will
convert the acronym into a non-delimited single lowercase word when passed to +underscore+.
Examples:
acronym('HTML')
titleize('html') #=> 'HTML'
camelize('html') #=> 'HTML'
underscore('MyHTML') #=> 'my_html'
The acronym, however, must occur as a delimited unit and not be part of another word for conversions to recognize it:
acronym('HTTP')
camelize('my_http_delimited') #=> 'MyHTTPDelimited'
camelize('https') #=> 'Https', not 'HTTPs'
underscore('HTTPS') #=> 'http_s', not 'https'
acronym('HTTPS')
camelize('https') #=> 'HTTPS'
underscore('HTTPS') #=> 'https'
Note: Acronyms that are passed to `pluralize` will no longer be recognized, since the acronym will not occur as
a delimited unit in the pluralized result. To work around this, you must specify the pluralized form as an
acronym as well:
acronym('API')
camelize(pluralize('api')) #=> 'Apis'
acronym('APIs')
camelize(pluralize('api')) #=> 'APIs'
`acronym` may be used to specify any word that contains an acronym or otherwise needs to maintain a non-standard
capitalization. The only restriction is that the word must begin with a capital letter.
Examples:
acronym('RESTful')
underscore('RESTful') #=> 'restful'
underscore('RESTfulController') #=> 'restful_controller'
titleize('RESTfulController') #=> 'RESTful Controller'
camelize('restful') #=> 'RESTful'
camelize('restful_controller') #=> 'RESTfulController'
acronym('McDonald')
underscore('McDonald') #=> 'mcdonald'
camelize('mcdonald') #=> 'McDonald'
@param string $word
@return void
@author Koen Punt | [
"Specifies",
"a",
"new",
"acronym",
".",
"An",
"acronym",
"must",
"be",
"specified",
"as",
"it",
"will",
"appear",
"in",
"a",
"camelized",
"string",
".",
"An",
"underscore",
"string",
"that",
"contains",
"the",
"acronym",
"will",
"retain",
"the",
"acronym",
... | 8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1 | https://github.com/koenpunt/php-inflector/blob/8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1/lib/Inflector/Inflections.php#L102-L105 | train |
koenpunt/php-inflector | lib/Inflector/Inflections.php | Inflections.plural | public function plural($rule, $replacement){
if(is_string($rule)){
Utils::array_delete($this->uncountables, $rule);
}
Utils::array_delete($this->uncountables, $replacement);
array_unshift($this->plurals, array($rule, $replacement));
} | php | public function plural($rule, $replacement){
if(is_string($rule)){
Utils::array_delete($this->uncountables, $rule);
}
Utils::array_delete($this->uncountables, $replacement);
array_unshift($this->plurals, array($rule, $replacement));
} | [
"public",
"function",
"plural",
"(",
"$",
"rule",
",",
"$",
"replacement",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"rule",
")",
")",
"{",
"Utils",
"::",
"array_delete",
"(",
"$",
"this",
"->",
"uncountables",
",",
"$",
"rule",
")",
";",
"}",
"U... | Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
The replacement should always be a string that may include references to the matched data from the rule.
@param string $rule
@param string $replacement
@return void
@author Koen Punt | [
"Specifies",
"a",
"new",
"pluralization",
"rule",
"and",
"its",
"replacement",
".",
"The",
"rule",
"can",
"either",
"be",
"a",
"string",
"or",
"a",
"regular",
"expression",
".",
"The",
"replacement",
"should",
"always",
"be",
"a",
"string",
"that",
"may",
... | 8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1 | https://github.com/koenpunt/php-inflector/blob/8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1/lib/Inflector/Inflections.php#L116-L122 | train |
koenpunt/php-inflector | lib/Inflector/Inflections.php | Inflections.singular | public function singular($rule, $replacement){
if(is_string($rule)){
Utils::array_delete($this->uncountables, $rule);
}
Utils::array_delete($this->uncountables, $replacement);
array_unshift($this->singulars, array($rule, $replacement));
} | php | public function singular($rule, $replacement){
if(is_string($rule)){
Utils::array_delete($this->uncountables, $rule);
}
Utils::array_delete($this->uncountables, $replacement);
array_unshift($this->singulars, array($rule, $replacement));
} | [
"public",
"function",
"singular",
"(",
"$",
"rule",
",",
"$",
"replacement",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"rule",
")",
")",
"{",
"Utils",
"::",
"array_delete",
"(",
"$",
"this",
"->",
"uncountables",
",",
"$",
"rule",
")",
";",
"}",
... | Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
The replacement should always be a string that may include references to the matched data from the rule.
@param string $rule
@param string $replacement
@return void
@author Koen Punt | [
"Specifies",
"a",
"new",
"singularization",
"rule",
"and",
"its",
"replacement",
".",
"The",
"rule",
"can",
"either",
"be",
"a",
"string",
"or",
"a",
"regular",
"expression",
".",
"The",
"replacement",
"should",
"always",
"be",
"a",
"string",
"that",
"may",
... | 8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1 | https://github.com/koenpunt/php-inflector/blob/8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1/lib/Inflector/Inflections.php#L132-L138 | train |
koenpunt/php-inflector | lib/Inflector/Inflections.php | Inflections.irregular | public function irregular($singular, $plural){
Utils::array_delete($this->uncountables, $singular);
Utils::array_delete($this->uncountables, $plural);
$singular_char = substr($singular, 0, 1);
$singular_char_upcase = strtoupper(substr($singular, 0, 1));
$singular_char_downcase = strtolower(substr($singular, 0, 1));
$singular_word = substr($singular, 1);
$plural_char = substr($plural, 0, 1);
$plural_char_upcase = strtoupper(substr($plural, 0, 1));
$plural_char_downcase = strtolower(substr($plural, 0, 1));
$plural_word = substr($plural, 1);
if(strtoupper(substr($singular, 0, 1)) == strtoupper(substr($plural, 0, 1))){
$this->plural("/({$singular_char}){$singular_word}$/i", '$1' . $plural_word);
$this->plural("/({$plural_char}){$plural_word}$/i", '$1' . $plural_word);
$this->singular("/({$plural_char}){$plural_word}$/i", '$1' . $singular_word);
}else{
$this->plural("/{$singular_char_upcase}(?i){$singular_word}$/", $plural_char_upcase . $plural_word);
$this->plural("/{$singular_char_downcase}(?i){$singular_word}$/", $plural_char_downcase . $plural_word);
$this->plural("/{$plural_char_upcase}(?i){$plural_word}$/", $plural_char_upcase . $plural_word);
$this->plural("/{$plural_char_downcase}(?i){$plural_word}$/", $plural_char_downcase . $plural_word);
$this->singular("/{$plural_char_upcase}(?i){$plural_word}$/", $singular_char_upcase . $singular_word);
$this->singular("/{$plural_char_downcase}(?i){$plural_word}$/", $singular_char_downcase . $singular_word);
}
} | php | public function irregular($singular, $plural){
Utils::array_delete($this->uncountables, $singular);
Utils::array_delete($this->uncountables, $plural);
$singular_char = substr($singular, 0, 1);
$singular_char_upcase = strtoupper(substr($singular, 0, 1));
$singular_char_downcase = strtolower(substr($singular, 0, 1));
$singular_word = substr($singular, 1);
$plural_char = substr($plural, 0, 1);
$plural_char_upcase = strtoupper(substr($plural, 0, 1));
$plural_char_downcase = strtolower(substr($plural, 0, 1));
$plural_word = substr($plural, 1);
if(strtoupper(substr($singular, 0, 1)) == strtoupper(substr($plural, 0, 1))){
$this->plural("/({$singular_char}){$singular_word}$/i", '$1' . $plural_word);
$this->plural("/({$plural_char}){$plural_word}$/i", '$1' . $plural_word);
$this->singular("/({$plural_char}){$plural_word}$/i", '$1' . $singular_word);
}else{
$this->plural("/{$singular_char_upcase}(?i){$singular_word}$/", $plural_char_upcase . $plural_word);
$this->plural("/{$singular_char_downcase}(?i){$singular_word}$/", $plural_char_downcase . $plural_word);
$this->plural("/{$plural_char_upcase}(?i){$plural_word}$/", $plural_char_upcase . $plural_word);
$this->plural("/{$plural_char_downcase}(?i){$plural_word}$/", $plural_char_downcase . $plural_word);
$this->singular("/{$plural_char_upcase}(?i){$plural_word}$/", $singular_char_upcase . $singular_word);
$this->singular("/{$plural_char_downcase}(?i){$plural_word}$/", $singular_char_downcase . $singular_word);
}
} | [
"public",
"function",
"irregular",
"(",
"$",
"singular",
",",
"$",
"plural",
")",
"{",
"Utils",
"::",
"array_delete",
"(",
"$",
"this",
"->",
"uncountables",
",",
"$",
"singular",
")",
";",
"Utils",
"::",
"array_delete",
"(",
"$",
"this",
"->",
"uncounta... | Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
for strings, not regular expressions. You simply pass the irregular in singular and plural form.
Examples:
irregular('octopus', 'octopi')
irregular('person', 'people')
@param string $singular
@param string $plural
@return void
@author Koen Punt | [
"Specifies",
"a",
"new",
"irregular",
"that",
"applies",
"to",
"both",
"pluralization",
"and",
"singularization",
"at",
"the",
"same",
"time",
".",
"This",
"can",
"only",
"be",
"used",
"for",
"strings",
"not",
"regular",
"expressions",
".",
"You",
"simply",
... | 8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1 | https://github.com/koenpunt/php-inflector/blob/8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1/lib/Inflector/Inflections.php#L153-L180 | train |
koenpunt/php-inflector | lib/Inflector/Inflections.php | Inflections.uncountable | public function uncountable(/* *$words */){
$words = func_get_args();
array_push($this->uncountables, $words);
$this->uncountables = Utils::array_flatten($this->uncountables);
return $this->uncountables;
} | php | public function uncountable(/* *$words */){
$words = func_get_args();
array_push($this->uncountables, $words);
$this->uncountables = Utils::array_flatten($this->uncountables);
return $this->uncountables;
} | [
"public",
"function",
"uncountable",
"(",
"/* *$words */",
")",
"{",
"$",
"words",
"=",
"func_get_args",
"(",
")",
";",
"array_push",
"(",
"$",
"this",
"->",
"uncountables",
",",
"$",
"words",
")",
";",
"$",
"this",
"->",
"uncountables",
"=",
"Utils",
":... | Add uncountable words that shouldn't be attempted inflected.
Examples:
uncountable("money")
uncountable("money", "information")
uncountable(array('money', 'information', 'rice'))
@param array $words
@return array $uncountables
@author Koen Punt | [
"Add",
"uncountable",
"words",
"that",
"shouldn",
"t",
"be",
"attempted",
"inflected",
"."
] | 8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1 | https://github.com/koenpunt/php-inflector/blob/8bf0655b11d0c9d5a065928a1d4a4c627b0a09c1/lib/Inflector/Inflections.php#L194-L199 | train |
platformsh/platformsh-client-php | src/Exception/ApiResponseException.php | ApiResponseException.getErrorDetails | public static function getErrorDetails(ResponseInterface $response)
{
$responseInfoProperties = [
// Platform.sh API errors.
'message',
'detail',
// RESTful module errors.
'title',
'type',
// OAuth2 errors.
'error',
'error_description',
];
$details = '';
$response->getBody()->seek(0);
$contents = $response->getBody()->getContents();
try {
$json = \GuzzleHttp\json_decode($contents, true);
foreach ($responseInfoProperties as $property) {
if (!empty($json[$property])) {
$value = $json[$property];
$details .= " [$property] " . (is_scalar($value) ? $value : json_encode($value));
}
}
} catch (\InvalidArgumentException $parseException) {
// Occasionally the response body may not be JSON.
if ($contents) {
$details .= " [extra] Non-JSON response body";
$details .= " [body] " . $contents;
}
else {
$details .= " [extra] Empty response body";
}
}
return $details;
} | php | public static function getErrorDetails(ResponseInterface $response)
{
$responseInfoProperties = [
// Platform.sh API errors.
'message',
'detail',
// RESTful module errors.
'title',
'type',
// OAuth2 errors.
'error',
'error_description',
];
$details = '';
$response->getBody()->seek(0);
$contents = $response->getBody()->getContents();
try {
$json = \GuzzleHttp\json_decode($contents, true);
foreach ($responseInfoProperties as $property) {
if (!empty($json[$property])) {
$value = $json[$property];
$details .= " [$property] " . (is_scalar($value) ? $value : json_encode($value));
}
}
} catch (\InvalidArgumentException $parseException) {
// Occasionally the response body may not be JSON.
if ($contents) {
$details .= " [extra] Non-JSON response body";
$details .= " [body] " . $contents;
}
else {
$details .= " [extra] Empty response body";
}
}
return $details;
} | [
"public",
"static",
"function",
"getErrorDetails",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"responseInfoProperties",
"=",
"[",
"// Platform.sh API errors.",
"'message'",
",",
"'detail'",
",",
"// RESTful module errors.",
"'title'",
",",
"'type'",
",",
... | Get more details from the response body, to add to error messages.
@param ResponseInterface $response
@return string | [
"Get",
"more",
"details",
"from",
"the",
"response",
"body",
"to",
"add",
"to",
"error",
"messages",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Exception/ApiResponseException.php#L46-L85 | train |
platformsh/platformsh-client-php | src/Model/Git/Ref.php | Ref.fromName | public static function fromName($refName, Project $project, ClientInterface $client)
{
$url = $project->getUri() . '/git/refs';
return static::get($refName, $url, $client);
} | php | public static function fromName($refName, Project $project, ClientInterface $client)
{
$url = $project->getUri() . '/git/refs';
return static::get($refName, $url, $client);
} | [
"public",
"static",
"function",
"fromName",
"(",
"$",
"refName",
",",
"Project",
"$",
"project",
",",
"ClientInterface",
"$",
"client",
")",
"{",
"$",
"url",
"=",
"$",
"project",
"->",
"getUri",
"(",
")",
".",
"'/git/refs'",
";",
"return",
"static",
"::"... | Get a Ref object in a project.
@param string $refName
@param Project $project
@param ClientInterface $client
@return static|false | [
"Get",
"a",
"Ref",
"object",
"in",
"a",
"project",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Git/Ref.php#L30-L35 | train |
platformsh/platformsh-client-php | src/Model/Git/Ref.php | Ref.getCommit | public function getCommit()
{
$data = $this->object;
if ($data['type'] !== 'commit') {
throw new \RuntimeException('This ref is not a commit');
}
$url = Project::getProjectBaseFromUrl($this->getUri()) . '/git/commits';
return Commit::get($data['sha'], $url, $this->client);
} | php | public function getCommit()
{
$data = $this->object;
if ($data['type'] !== 'commit') {
throw new \RuntimeException('This ref is not a commit');
}
$url = Project::getProjectBaseFromUrl($this->getUri()) . '/git/commits';
return Commit::get($data['sha'], $url, $this->client);
} | [
"public",
"function",
"getCommit",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"object",
";",
"if",
"(",
"$",
"data",
"[",
"'type'",
"]",
"!==",
"'commit'",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'This ref is not a commit'",
")... | Get the commit for this ref.
@return Commit|false | [
"Get",
"the",
"commit",
"for",
"this",
"ref",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Git/Ref.php#L42-L51 | train |
platformsh/platformsh-client-php | src/Model/Subscription.php | Subscription.wait | public function wait(callable $onPoll = null, $interval = 2)
{
while ($this->isPending()) {
sleep($interval > 1 ? $interval : 1);
$this->refresh();
if ($onPoll !== null) {
$onPoll($this);
}
}
} | php | public function wait(callable $onPoll = null, $interval = 2)
{
while ($this->isPending()) {
sleep($interval > 1 ? $interval : 1);
$this->refresh();
if ($onPoll !== null) {
$onPoll($this);
}
}
} | [
"public",
"function",
"wait",
"(",
"callable",
"$",
"onPoll",
"=",
"null",
",",
"$",
"interval",
"=",
"2",
")",
"{",
"while",
"(",
"$",
"this",
"->",
"isPending",
"(",
")",
")",
"{",
"sleep",
"(",
"$",
"interval",
">",
"1",
"?",
"$",
"interval",
... | Wait for the subscription's project to be provisioned.
@param callable $onPoll A function that will be called every time the
subscription is refreshed. It will be passed
one argument: the Subscription object.
@param int $interval The polling interval, in seconds. | [
"Wait",
"for",
"the",
"subscription",
"s",
"project",
"to",
"be",
"provisioned",
"."
] | 7a0abb5ba796e6498e2364fae7860a0dcf58111c | https://github.com/platformsh/platformsh-client-php/blob/7a0abb5ba796e6498e2364fae7860a0dcf58111c/src/Model/Subscription.php#L61-L70 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.