id
int32
0
241k
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
29,700
Blobfolio/blob-common
lib/blobfolio/common/dom.php
dom.get_nodes_by_class
public static function get_nodes_by_class($parent, $class=null, bool $all=false) { $nodes = array(); if (! \method_exists($parent, 'getElementsByTagName')) { return $nodes; } ref\cast::array($class); $class = \array_map('trim', $class); foreach ($class as $k=>$v) { $class[$k] = \ltrim($class[$k], '.'); } $class = \array_filter($class, 'strlen'); \sort($class); $class = \array_unique($class); if (! \count($class)) { return $nodes; } $possible = $parent->getElementsByTagName('*'); if ($possible->length) { foreach ($possible as $child) { if ($child->hasAttribute('class')) { $classes = $child->getAttribute('class'); ref\sanitize::whitespace($classes); $classes = \explode(' ', $classes); $overlap = \array_intersect($classes, $class); if (\count($overlap) && (! $all || \count($overlap) === \count($class))) { $nodes[] = $child; } } } } return $nodes; }
php
public static function get_nodes_by_class($parent, $class=null, bool $all=false) { $nodes = array(); if (! \method_exists($parent, 'getElementsByTagName')) { return $nodes; } ref\cast::array($class); $class = \array_map('trim', $class); foreach ($class as $k=>$v) { $class[$k] = \ltrim($class[$k], '.'); } $class = \array_filter($class, 'strlen'); \sort($class); $class = \array_unique($class); if (! \count($class)) { return $nodes; } $possible = $parent->getElementsByTagName('*'); if ($possible->length) { foreach ($possible as $child) { if ($child->hasAttribute('class')) { $classes = $child->getAttribute('class'); ref\sanitize::whitespace($classes); $classes = \explode(' ', $classes); $overlap = \array_intersect($classes, $class); if (\count($overlap) && (! $all || \count($overlap) === \count($class))) { $nodes[] = $child; } } } } return $nodes; }
[ "public", "static", "function", "get_nodes_by_class", "(", "$", "parent", ",", "$", "class", "=", "null", ",", "bool", "$", "all", "=", "false", ")", "{", "$", "nodes", "=", "array", "(", ")", ";", "if", "(", "!", "\\", "method_exists", "(", "$", "parent", ",", "'getElementsByTagName'", ")", ")", "{", "return", "$", "nodes", ";", "}", "ref", "\\", "cast", "::", "array", "(", "$", "class", ")", ";", "$", "class", "=", "\\", "array_map", "(", "'trim'", ",", "$", "class", ")", ";", "foreach", "(", "$", "class", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "class", "[", "$", "k", "]", "=", "\\", "ltrim", "(", "$", "class", "[", "$", "k", "]", ",", "'.'", ")", ";", "}", "$", "class", "=", "\\", "array_filter", "(", "$", "class", ",", "'strlen'", ")", ";", "\\", "sort", "(", "$", "class", ")", ";", "$", "class", "=", "\\", "array_unique", "(", "$", "class", ")", ";", "if", "(", "!", "\\", "count", "(", "$", "class", ")", ")", "{", "return", "$", "nodes", ";", "}", "$", "possible", "=", "$", "parent", "->", "getElementsByTagName", "(", "'*'", ")", ";", "if", "(", "$", "possible", "->", "length", ")", "{", "foreach", "(", "$", "possible", "as", "$", "child", ")", "{", "if", "(", "$", "child", "->", "hasAttribute", "(", "'class'", ")", ")", "{", "$", "classes", "=", "$", "child", "->", "getAttribute", "(", "'class'", ")", ";", "ref", "\\", "sanitize", "::", "whitespace", "(", "$", "classes", ")", ";", "$", "classes", "=", "\\", "explode", "(", "' '", ",", "$", "classes", ")", ";", "$", "overlap", "=", "\\", "array_intersect", "(", "$", "classes", ",", "$", "class", ")", ";", "if", "(", "\\", "count", "(", "$", "overlap", ")", "&&", "(", "!", "$", "all", "||", "\\", "count", "(", "$", "overlap", ")", "===", "\\", "count", "(", "$", "class", ")", ")", ")", "{", "$", "nodes", "[", "]", "=", "$", "child", ";", "}", "}", "}", "}", "return", "$", "nodes", ";", "}" ]
Get Nodes By Class This will return an array of DOMNode objects containing the specified class(es). This does not use DOMXPath. @param mixed $parent DOMDocument, DOMElement, etc. @param string|array $class One or more classes. @param bool $all Matches must contain *all* passed classes instead of *any*. @return array Nodes.
[ "Get", "Nodes", "By", "Class" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/dom.php#L145-L181
29,701
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.cancel
public function cancel($paymentId, $contractId = null, $amount = null, $reduceStakeholderPayment = false) { $object = [ 'contract' => $contractId, 'amount' => $amount, 'reduce_stakeholder_payment' => $reduceStakeholderPayment ]; $res = $this->execute($paymentId, 'cancel', null, $object); if (is_object($res)) { return $res; } return $res; }
php
public function cancel($paymentId, $contractId = null, $amount = null, $reduceStakeholderPayment = false) { $object = [ 'contract' => $contractId, 'amount' => $amount, 'reduce_stakeholder_payment' => $reduceStakeholderPayment ]; $res = $this->execute($paymentId, 'cancel', null, $object); if (is_object($res)) { return $res; } return $res; }
[ "public", "function", "cancel", "(", "$", "paymentId", ",", "$", "contractId", "=", "null", ",", "$", "amount", "=", "null", ",", "$", "reduceStakeholderPayment", "=", "false", ")", "{", "$", "object", "=", "[", "'contract'", "=>", "$", "contractId", ",", "'amount'", "=>", "$", "amount", ",", "'reduce_stakeholder_payment'", "=>", "$", "reduceStakeholderPayment", "]", ";", "$", "res", "=", "$", "this", "->", "execute", "(", "$", "paymentId", ",", "'cancel'", ",", "null", ",", "$", "object", ")", ";", "if", "(", "is_object", "(", "$", "res", ")", ")", "{", "return", "$", "res", ";", "}", "return", "$", "res", ";", "}" ]
Cancel or Refund an existing transaction. Currently, partial refunds are are not allowed for all payment products. @param string $paymentId The payment transaction id. @param string $contractId The id of the contract that was used to create this transaction. @param int $amount The amount that you want to refund to the payer. Use '0' for a full refund. @param bool $reduceStakeholderPayment TRUE if you want to change the amount of the stakeholder positions too (on partial refund) @return array ['result', 'demo', 'new_trans_id', 'remaining_amount', 'refund_waiting_for_payment'] @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Cancel", "or", "Refund", "an", "existing", "transaction", ".", "Currently", "partial", "refunds", "are", "are", "not", "allowed", "for", "all", "payment", "products", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L36-L50
29,702
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.capture
public function capture($paymentId, $contractId = null) { $class = $this->resourceMetadata->resourceClass; $object = [ 'contract' => $contractId, ]; $res = $this->execute($paymentId, 'capture', null, $object, $class); if ($res) { return true; } return false; }
php
public function capture($paymentId, $contractId = null) { $class = $this->resourceMetadata->resourceClass; $object = [ 'contract' => $contractId, ]; $res = $this->execute($paymentId, 'capture', null, $object, $class); if ($res) { return true; } return false; }
[ "public", "function", "capture", "(", "$", "paymentId", ",", "$", "contractId", "=", "null", ")", "{", "$", "class", "=", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ";", "$", "object", "=", "[", "'contract'", "=>", "$", "contractId", ",", "]", ";", "$", "res", "=", "$", "this", "->", "execute", "(", "$", "paymentId", ",", "'capture'", ",", "null", ",", "$", "object", ",", "$", "class", ")", ";", "if", "(", "$", "res", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Capture a pre-authorized payment transaction. @param string $paymentId The payment transaction id @param string $contractId The id of the contract that was used to create this transaction. @return bool TRUE if successful, FALSE otherwise. @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Capture", "a", "pre", "-", "authorized", "payment", "transaction", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L63-L78
29,703
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.updateBasket
public function updateBasket($paymentId, array $basket, $contractId = null) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->basket = $basket; $object->contract = $contractId; $res = $this->updateWithAction($paymentId, 'basket', null, $object, $class); if ($res) { return true; } return false; }
php
public function updateBasket($paymentId, array $basket, $contractId = null) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->basket = $basket; $object->contract = $contractId; $res = $this->updateWithAction($paymentId, 'basket', null, $object, $class); if ($res) { return true; } return false; }
[ "public", "function", "updateBasket", "(", "$", "paymentId", ",", "array", "$", "basket", ",", "$", "contractId", "=", "null", ")", "{", "$", "class", "=", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ";", "/**\n * @var $object Transaction\n */", "$", "object", "=", "new", "$", "class", "(", ")", ";", "$", "object", "->", "id", "=", "$", "paymentId", ";", "$", "object", "->", "basket", "=", "$", "basket", ";", "$", "object", "->", "contract", "=", "$", "contractId", ";", "$", "res", "=", "$", "this", "->", "updateWithAction", "(", "$", "paymentId", ",", "'basket'", ",", "null", ",", "$", "object", ",", "$", "class", ")", ";", "if", "(", "$", "res", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Add additional basket items to the payment transaction. F.e. for adding stakeholder payment items. @param string $paymentId The payment transaction id @param Basket[] $basket @param string $contractId The id of the contract that was used to create this transaction. @return bool TRUE if successful, FALSE otherwise. @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Add", "additional", "basket", "items", "to", "the", "payment", "transaction", ".", "F", ".", "e", ".", "for", "adding", "stakeholder", "payment", "items", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L92-L109
29,704
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.reverseAccrual
public function reverseAccrual($paymentId) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->accrual = false; $res = $this->updateWithAction($paymentId, 'accrual', null, $object, $class); if ($res) { return true; } return false; }
php
public function reverseAccrual($paymentId) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->accrual = false; $res = $this->updateWithAction($paymentId, 'accrual', null, $object, $class); if ($res) { return true; } return false; }
[ "public", "function", "reverseAccrual", "(", "$", "paymentId", ")", "{", "$", "class", "=", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ";", "/**\n * @var $object Transaction\n */", "$", "object", "=", "new", "$", "class", "(", ")", ";", "$", "object", "->", "id", "=", "$", "paymentId", ";", "$", "object", "->", "accrual", "=", "false", ";", "$", "res", "=", "$", "this", "->", "updateWithAction", "(", "$", "paymentId", ",", "'accrual'", ",", "null", ",", "$", "object", ",", "$", "class", ")", ";", "if", "(", "$", "res", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Remove the accrual flag of an existing payment transaction. @param string $paymentId The payment transaction id @return bool @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Remove", "the", "accrual", "flag", "of", "an", "existing", "payment", "transaction", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L121-L137
29,705
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.initSubsequent
public function initSubsequent($paymentId, $amount, array $basket) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->amount = $amount; $object->basket = $basket; $res = $this->execute($paymentId, 'subsequent', null, $object, $class); if ($res) { return true; } return false; }
php
public function initSubsequent($paymentId, $amount, array $basket) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->amount = $amount; $object->basket = $basket; $res = $this->execute($paymentId, 'subsequent', null, $object, $class); if ($res) { return true; } return false; }
[ "public", "function", "initSubsequent", "(", "$", "paymentId", ",", "$", "amount", ",", "array", "$", "basket", ")", "{", "$", "class", "=", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ";", "/**\n * @var $object Transaction\n */", "$", "object", "=", "new", "$", "class", "(", ")", ";", "$", "object", "->", "id", "=", "$", "paymentId", ";", "$", "object", "->", "amount", "=", "$", "amount", ";", "$", "object", "->", "basket", "=", "$", "basket", ";", "$", "res", "=", "$", "this", "->", "execute", "(", "$", "paymentId", ",", "'subsequent'", ",", "null", ",", "$", "object", ",", "$", "class", ")", ";", "if", "(", "$", "res", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Subsequent posting to a approved transaction. This can only be executed once per payment transaction. @param string $paymentId The payment transaction id @param int $amount The new total amount (max. 120% of the old amount) @param Basket[] $basket The new basket items @return bool TRUE if successful, FALSE otherwise. @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Subsequent", "posting", "to", "a", "approved", "transaction", ".", "This", "can", "only", "be", "executed", "once", "per", "payment", "transaction", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L151-L168
29,706
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.updateSubscription
public function updateSubscription($paymentId, $purpose) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->subscription = new Subscription(); $object->subscription->purpose = $purpose; $res = $this->updateWithAction($paymentId, 'subscription', null, $object, $class); if ($res) { return true; } return false; }
php
public function updateSubscription($paymentId, $purpose) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->subscription = new Subscription(); $object->subscription->purpose = $purpose; $res = $this->updateWithAction($paymentId, 'subscription', null, $object, $class); if ($res) { return true; } return false; }
[ "public", "function", "updateSubscription", "(", "$", "paymentId", ",", "$", "purpose", ")", "{", "$", "class", "=", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ";", "/**\n * @var $object Transaction\n */", "$", "object", "=", "new", "$", "class", "(", ")", ";", "$", "object", "->", "id", "=", "$", "paymentId", ";", "$", "object", "->", "subscription", "=", "new", "Subscription", "(", ")", ";", "$", "object", "->", "subscription", "->", "purpose", "=", "$", "purpose", ";", "$", "res", "=", "$", "this", "->", "updateWithAction", "(", "$", "paymentId", ",", "'subscription'", ",", "null", ",", "$", "object", ",", "$", "class", ")", ";", "if", "(", "$", "res", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Create or update a subscription for a existing transaction @param string $paymentId The payment transaction id @param string $purpose The purpose of the subscription @return bool TRUE if successful, FALSE otherwise. @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Create", "or", "update", "a", "subscription", "for", "a", "existing", "transaction" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L212-L229
29,707
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.onStatusChange
public function onStatusChange($fn) { $this->registerEventHandler(static::class, $fn === null ? null : new PaymentChanged($fn, $this)); }
php
public function onStatusChange($fn) { $this->registerEventHandler(static::class, $fn === null ? null : new PaymentChanged($fn, $this)); }
[ "public", "function", "onStatusChange", "(", "$", "fn", ")", "{", "$", "this", "->", "registerEventHandler", "(", "static", "::", "class", ",", "$", "fn", "===", "null", "?", "null", ":", "new", "PaymentChanged", "(", "$", "fn", ",", "$", "this", ")", ")", ";", "}" ]
Set a callback to be notified when a creditcard has changed. Pass null to remove a previous setting. @param callable|null $fn Any function which accepts a "Transaction" model class argument.
[ "Set", "a", "callback", "to", "be", "notified", "when", "a", "creditcard", "has", "changed", ".", "Pass", "null", "to", "remove", "a", "previous", "setting", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L236-L239
29,708
acdh-oeaw/repo-php-util
src/acdhOeaw/util/RepoConfig.php
RepoConfig.get
static public function get(string $property, bool $noException = false) { $value = @self::$config->get($property); if ($value === null && $noException === false) { throw new InvalidArgumentException('configuration property ' . $property . ' does not exist'); } return $value; }
php
static public function get(string $property, bool $noException = false) { $value = @self::$config->get($property); if ($value === null && $noException === false) { throw new InvalidArgumentException('configuration property ' . $property . ' does not exist'); } return $value; }
[ "static", "public", "function", "get", "(", "string", "$", "property", ",", "bool", "$", "noException", "=", "false", ")", "{", "$", "value", "=", "@", "self", "::", "$", "config", "->", "get", "(", "$", "property", ")", ";", "if", "(", "$", "value", "===", "null", "&&", "$", "noException", "===", "false", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'configuration property '", ".", "$", "property", ".", "' does not exist'", ")", ";", "}", "return", "$", "value", ";", "}" ]
Returns given configuration property value. If property is not set, throws an error. Property value can be a literal as well as an composed object (e.g. array depending on the parsed ini file content). @param string $property configuration property name @param bool $noException should exception be avoided when property is not defined? @return mixed configuration property value @throws InvalidArgumentException
[ "Returns", "given", "configuration", "property", "value", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/RepoConfig.php#L72-L78
29,709
acdh-oeaw/repo-php-util
src/acdhOeaw/util/RepoConfig.php
RepoConfig.askForUserConfirmation
static public function askForUserConfirmation(bool $throwException = false): bool { echo "\n######################################################\n\n"; echo "Are you sure that you want to import data to the following instance?! \n\n "; echo "Type 'yes' to continue! \n\n"; echo self::get('sparqlUrl') . "\n"; echo self::get('fedoraApiUrl') . "\n"; $handle = fopen ("php://stdin","r"); $line = trim(fgets($handle)); fclose($handle); if ($line !== 'yes' && $throwException) { throw new RuntimeException('Configuration revoked by the user'); } return $line === 'yes'; }
php
static public function askForUserConfirmation(bool $throwException = false): bool { echo "\n######################################################\n\n"; echo "Are you sure that you want to import data to the following instance?! \n\n "; echo "Type 'yes' to continue! \n\n"; echo self::get('sparqlUrl') . "\n"; echo self::get('fedoraApiUrl') . "\n"; $handle = fopen ("php://stdin","r"); $line = trim(fgets($handle)); fclose($handle); if ($line !== 'yes' && $throwException) { throw new RuntimeException('Configuration revoked by the user'); } return $line === 'yes'; }
[ "static", "public", "function", "askForUserConfirmation", "(", "bool", "$", "throwException", "=", "false", ")", ":", "bool", "{", "echo", "\"\\n######################################################\\n\\n\"", ";", "echo", "\"Are you sure that you want to import data to the following instance?! \\n\\n \"", ";", "echo", "\"Type 'yes' to continue! \\n\\n\"", ";", "echo", "self", "::", "get", "(", "'sparqlUrl'", ")", ".", "\"\\n\"", ";", "echo", "self", "::", "get", "(", "'fedoraApiUrl'", ")", ".", "\"\\n\"", ";", "$", "handle", "=", "fopen", "(", "\"php://stdin\"", ",", "\"r\"", ")", ";", "$", "line", "=", "trim", "(", "fgets", "(", "$", "handle", ")", ")", ";", "fclose", "(", "$", "handle", ")", ";", "if", "(", "$", "line", "!==", "'yes'", "&&", "$", "throwException", ")", "{", "throw", "new", "RuntimeException", "(", "'Configuration revoked by the user'", ")", ";", "}", "return", "$", "line", "===", "'yes'", ";", "}" ]
Displays Fedora and SPARQL endpoint URLs to the user and asks for confirmation. @param bool $throwException should an exception be thrown on lack of confirmation? @return bool
[ "Displays", "Fedora", "and", "SPARQL", "endpoint", "URLs", "to", "the", "user", "and", "asks", "for", "confirmation", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/RepoConfig.php#L145-L158
29,710
locomotivemtl/charcoal-ui
src/Charcoal/Ui/Layout/LayoutBuilder.php
LayoutBuilder.build
public function build($options) { $container = $this->container; $objType = isset($options['type']) ? $options['type'] : self::DEFAULT_TYPE; $obj = $this->factory->create($objType, [ 'logger' => $container['logger'], 'view' => $container['view'] ]); $obj->setData($options); return $obj; }
php
public function build($options) { $container = $this->container; $objType = isset($options['type']) ? $options['type'] : self::DEFAULT_TYPE; $obj = $this->factory->create($objType, [ 'logger' => $container['logger'], 'view' => $container['view'] ]); $obj->setData($options); return $obj; }
[ "public", "function", "build", "(", "$", "options", ")", "{", "$", "container", "=", "$", "this", "->", "container", ";", "$", "objType", "=", "isset", "(", "$", "options", "[", "'type'", "]", ")", "?", "$", "options", "[", "'type'", "]", ":", "self", "::", "DEFAULT_TYPE", ";", "$", "obj", "=", "$", "this", "->", "factory", "->", "create", "(", "$", "objType", ",", "[", "'logger'", "=>", "$", "container", "[", "'logger'", "]", ",", "'view'", "=>", "$", "container", "[", "'view'", "]", "]", ")", ";", "$", "obj", "->", "setData", "(", "$", "options", ")", ";", "return", "$", "obj", ";", "}" ]
Build and return a new layout. @param array|\ArrayAccess $options The layout build options. @return LayoutInterface
[ "Build", "and", "return", "a", "new", "layout", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/Layout/LayoutBuilder.php#L55-L67
29,711
hiqdev/yii2-language
src/Module.php
Module.detectLanguage
public function detectLanguage() { $acceptableLanguages = Yii::$app->getRequest()->getAcceptableLanguages(); foreach ($acceptableLanguages as $language) { if ($this->isValidLanguage($language)) { return $language; } } foreach ($acceptableLanguages as $language) { $pattern = preg_quote(substr($language, 0, 2), '/'); foreach ($this->languages as $key => $value) { if (preg_match('/^' . $pattern . '/', $value) || preg_match('/^' . $pattern . '/', $key)) { return $this->isValidLanguage($key) ? $key : $value; } } } return false; }
php
public function detectLanguage() { $acceptableLanguages = Yii::$app->getRequest()->getAcceptableLanguages(); foreach ($acceptableLanguages as $language) { if ($this->isValidLanguage($language)) { return $language; } } foreach ($acceptableLanguages as $language) { $pattern = preg_quote(substr($language, 0, 2), '/'); foreach ($this->languages as $key => $value) { if (preg_match('/^' . $pattern . '/', $value) || preg_match('/^' . $pattern . '/', $key)) { return $this->isValidLanguage($key) ? $key : $value; } } } return false; }
[ "public", "function", "detectLanguage", "(", ")", "{", "$", "acceptableLanguages", "=", "Yii", "::", "$", "app", "->", "getRequest", "(", ")", "->", "getAcceptableLanguages", "(", ")", ";", "foreach", "(", "$", "acceptableLanguages", "as", "$", "language", ")", "{", "if", "(", "$", "this", "->", "isValidLanguage", "(", "$", "language", ")", ")", "{", "return", "$", "language", ";", "}", "}", "foreach", "(", "$", "acceptableLanguages", "as", "$", "language", ")", "{", "$", "pattern", "=", "preg_quote", "(", "substr", "(", "$", "language", ",", "0", ",", "2", ")", ",", "'/'", ")", ";", "foreach", "(", "$", "this", "->", "languages", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "preg_match", "(", "'/^'", ".", "$", "pattern", ".", "'/'", ",", "$", "value", ")", "||", "preg_match", "(", "'/^'", ".", "$", "pattern", ".", "'/'", ",", "$", "key", ")", ")", "{", "return", "$", "this", "->", "isValidLanguage", "(", "$", "key", ")", "?", "$", "key", ":", "$", "value", ";", "}", "}", "}", "return", "false", ";", "}" ]
Determine language based on UserAgent.
[ "Determine", "language", "based", "on", "UserAgent", "." ]
c4aec9dafe13f4d96e0bf4a8997b74bf49663fa3
https://github.com/hiqdev/yii2-language/blob/c4aec9dafe13f4d96e0bf4a8997b74bf49663fa3/src/Module.php#L109-L127
29,712
hiqdev/yii2-language
src/Module.php
Module.saveLanguageIntoCookie
private function saveLanguageIntoCookie($language) { $cookie = new Cookie([ 'name' => $this->cookieName, 'value' => $language, 'expire' => time() + 86400 * $this->expireDays, ]); Yii::$app->response->cookies->add($cookie); }
php
private function saveLanguageIntoCookie($language) { $cookie = new Cookie([ 'name' => $this->cookieName, 'value' => $language, 'expire' => time() + 86400 * $this->expireDays, ]); Yii::$app->response->cookies->add($cookie); }
[ "private", "function", "saveLanguageIntoCookie", "(", "$", "language", ")", "{", "$", "cookie", "=", "new", "Cookie", "(", "[", "'name'", "=>", "$", "this", "->", "cookieName", ",", "'value'", "=>", "$", "language", ",", "'expire'", "=>", "time", "(", ")", "+", "86400", "*", "$", "this", "->", "expireDays", ",", "]", ")", ";", "Yii", "::", "$", "app", "->", "response", "->", "cookies", "->", "add", "(", "$", "cookie", ")", ";", "}" ]
Save language into cookie. @param string $language
[ "Save", "language", "into", "cookie", "." ]
c4aec9dafe13f4d96e0bf4a8997b74bf49663fa3
https://github.com/hiqdev/yii2-language/blob/c4aec9dafe13f4d96e0bf4a8997b74bf49663fa3/src/Module.php#L133-L141
29,713
Blobfolio/blob-common
lib/blobfolio/common/format.php
format.excerpt
public static function excerpt($str='', $args=null) { ref\cast::string($str, true); ref\sanitize::whitespace($str, 0); $str = \strip_tags($str); $options = data::parse_args($args, constants::EXCERPT); if ($options['length'] < 1) { return ''; } $options['unit'] = \strtolower($options['unit']); switch (\substr($options['unit'], 0, 4)) { case 'char': $options['unit'] = 'character'; break; case 'word': $options['unit'] = 'word'; break; } // Character limit. if ( ('character' === $options['unit']) && mb::strlen($str) > $options['length'] ) { $str = \trim(mb::substr($str, 0, $options['length'])) . $options['suffix']; } // Word limit. elseif ( ('word' === $options['unit']) && \substr_count($str, ' ') > $options['length'] - 1 ) { $str = \explode(' ', $str); $str = \array_slice($str, 0, $options['length']); $str = \implode(' ', $str) . $options['suffix']; } return $str; }
php
public static function excerpt($str='', $args=null) { ref\cast::string($str, true); ref\sanitize::whitespace($str, 0); $str = \strip_tags($str); $options = data::parse_args($args, constants::EXCERPT); if ($options['length'] < 1) { return ''; } $options['unit'] = \strtolower($options['unit']); switch (\substr($options['unit'], 0, 4)) { case 'char': $options['unit'] = 'character'; break; case 'word': $options['unit'] = 'word'; break; } // Character limit. if ( ('character' === $options['unit']) && mb::strlen($str) > $options['length'] ) { $str = \trim(mb::substr($str, 0, $options['length'])) . $options['suffix']; } // Word limit. elseif ( ('word' === $options['unit']) && \substr_count($str, ' ') > $options['length'] - 1 ) { $str = \explode(' ', $str); $str = \array_slice($str, 0, $options['length']); $str = \implode(' ', $str) . $options['suffix']; } return $str; }
[ "public", "static", "function", "excerpt", "(", "$", "str", "=", "''", ",", "$", "args", "=", "null", ")", "{", "ref", "\\", "cast", "::", "string", "(", "$", "str", ",", "true", ")", ";", "ref", "\\", "sanitize", "::", "whitespace", "(", "$", "str", ",", "0", ")", ";", "$", "str", "=", "\\", "strip_tags", "(", "$", "str", ")", ";", "$", "options", "=", "data", "::", "parse_args", "(", "$", "args", ",", "constants", "::", "EXCERPT", ")", ";", "if", "(", "$", "options", "[", "'length'", "]", "<", "1", ")", "{", "return", "''", ";", "}", "$", "options", "[", "'unit'", "]", "=", "\\", "strtolower", "(", "$", "options", "[", "'unit'", "]", ")", ";", "switch", "(", "\\", "substr", "(", "$", "options", "[", "'unit'", "]", ",", "0", ",", "4", ")", ")", "{", "case", "'char'", ":", "$", "options", "[", "'unit'", "]", "=", "'character'", ";", "break", ";", "case", "'word'", ":", "$", "options", "[", "'unit'", "]", "=", "'word'", ";", "break", ";", "}", "// Character limit.", "if", "(", "(", "'character'", "===", "$", "options", "[", "'unit'", "]", ")", "&&", "mb", "::", "strlen", "(", "$", "str", ")", ">", "$", "options", "[", "'length'", "]", ")", "{", "$", "str", "=", "\\", "trim", "(", "mb", "::", "substr", "(", "$", "str", ",", "0", ",", "$", "options", "[", "'length'", "]", ")", ")", ".", "$", "options", "[", "'suffix'", "]", ";", "}", "// Word limit.", "elseif", "(", "(", "'word'", "===", "$", "options", "[", "'unit'", "]", ")", "&&", "\\", "substr_count", "(", "$", "str", ",", "' '", ")", ">", "$", "options", "[", "'length'", "]", "-", "1", ")", "{", "$", "str", "=", "\\", "explode", "(", "' '", ",", "$", "str", ")", ";", "$", "str", "=", "\\", "array_slice", "(", "$", "str", ",", "0", ",", "$", "options", "[", "'length'", "]", ")", ";", "$", "str", "=", "\\", "implode", "(", "' '", ",", "$", "str", ")", ".", "$", "options", "[", "'suffix'", "]", ";", "}", "return", "$", "str", ";", "}" ]
Generate Text Except @param string $str String. @param mixed $args Arguments. @arg int $length Length limit. @arg string $unit Unit to examine, "character" or "word". @arg string $suffix Suffix, e.g. ... @return string Excerpt.
[ "Generate", "Text", "Except" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/format.php#L214-L252
29,714
Blobfolio/blob-common
lib/blobfolio/common/format.php
format.list_to_array
public static function list_to_array($list, $args=null) { ref\format::list_to_array($list, $args); return $list; }
php
public static function list_to_array($list, $args=null) { ref\format::list_to_array($list, $args); return $list; }
[ "public", "static", "function", "list_to_array", "(", "$", "list", ",", "$", "args", "=", "null", ")", "{", "ref", "\\", "format", "::", "list_to_array", "(", "$", "list", ",", "$", "args", ")", ";", "return", "$", "list", ";", "}" ]
List to Array Convert a delimited list into a proper array. @param mixed $list List. @param mixed $args Arguments or delimiter. @args string $delimiter Delimiter. @args bool $trim Trim. @args bool $unique Unique. @args bool $sort Sort output. @args string $cast Cast to type. @args mixed $min Minimum value. @args mixed $max Maximum value. @return array List.
[ "List", "to", "Array" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/format.php#L419-L422
29,715
Blobfolio/blob-common
lib/blobfolio/common/format.php
format.to_csv
public static function to_csv($data=null, $headers=null, string $delimiter=',', string $eol="\n") { ref\cast::array($data); $data = \array_values(\array_filter($data, 'is_array')); ref\cast::array($headers); $out = array(); // Grab headers from data? if ( ! \count($headers) && \count($data) && (cast::array_type($data[0]) === 'associative') ) { $headers = \array_keys($data[0]); } // Output headers, if applicable. if (\count($headers)) { foreach ($headers as $k=>$v) { ref\cast::string($headers[$k], true); } ref\sanitize::csv($headers); $out[] = '"' . \implode('"' . $delimiter . '"', $headers) . '"'; } // Output data. if (\count($data)) { foreach ($data as $line) { foreach ($line as $k=>$v) { ref\cast::string($line[$k], true); } ref\sanitize::csv($line); $out[] = '"' . \implode('"' . $delimiter . '"', $line) . '"'; } } return \implode($eol, $out); }
php
public static function to_csv($data=null, $headers=null, string $delimiter=',', string $eol="\n") { ref\cast::array($data); $data = \array_values(\array_filter($data, 'is_array')); ref\cast::array($headers); $out = array(); // Grab headers from data? if ( ! \count($headers) && \count($data) && (cast::array_type($data[0]) === 'associative') ) { $headers = \array_keys($data[0]); } // Output headers, if applicable. if (\count($headers)) { foreach ($headers as $k=>$v) { ref\cast::string($headers[$k], true); } ref\sanitize::csv($headers); $out[] = '"' . \implode('"' . $delimiter . '"', $headers) . '"'; } // Output data. if (\count($data)) { foreach ($data as $line) { foreach ($line as $k=>$v) { ref\cast::string($line[$k], true); } ref\sanitize::csv($line); $out[] = '"' . \implode('"' . $delimiter . '"', $line) . '"'; } } return \implode($eol, $out); }
[ "public", "static", "function", "to_csv", "(", "$", "data", "=", "null", ",", "$", "headers", "=", "null", ",", "string", "$", "delimiter", "=", "','", ",", "string", "$", "eol", "=", "\"\\n\"", ")", "{", "ref", "\\", "cast", "::", "array", "(", "$", "data", ")", ";", "$", "data", "=", "\\", "array_values", "(", "\\", "array_filter", "(", "$", "data", ",", "'is_array'", ")", ")", ";", "ref", "\\", "cast", "::", "array", "(", "$", "headers", ")", ";", "$", "out", "=", "array", "(", ")", ";", "// Grab headers from data?", "if", "(", "!", "\\", "count", "(", "$", "headers", ")", "&&", "\\", "count", "(", "$", "data", ")", "&&", "(", "cast", "::", "array_type", "(", "$", "data", "[", "0", "]", ")", "===", "'associative'", ")", ")", "{", "$", "headers", "=", "\\", "array_keys", "(", "$", "data", "[", "0", "]", ")", ";", "}", "// Output headers, if applicable.", "if", "(", "\\", "count", "(", "$", "headers", ")", ")", "{", "foreach", "(", "$", "headers", "as", "$", "k", "=>", "$", "v", ")", "{", "ref", "\\", "cast", "::", "string", "(", "$", "headers", "[", "$", "k", "]", ",", "true", ")", ";", "}", "ref", "\\", "sanitize", "::", "csv", "(", "$", "headers", ")", ";", "$", "out", "[", "]", "=", "'\"'", ".", "\\", "implode", "(", "'\"'", ".", "$", "delimiter", ".", "'\"'", ",", "$", "headers", ")", ".", "'\"'", ";", "}", "// Output data.", "if", "(", "\\", "count", "(", "$", "data", ")", ")", "{", "foreach", "(", "$", "data", "as", "$", "line", ")", "{", "foreach", "(", "$", "line", "as", "$", "k", "=>", "$", "v", ")", "{", "ref", "\\", "cast", "::", "string", "(", "$", "line", "[", "$", "k", "]", ",", "true", ")", ";", "}", "ref", "\\", "sanitize", "::", "csv", "(", "$", "line", ")", ";", "$", "out", "[", "]", "=", "'\"'", ".", "\\", "implode", "(", "'\"'", ".", "$", "delimiter", ".", "'\"'", ",", "$", "line", ")", ".", "'\"'", ";", "}", "}", "return", "\\", "implode", "(", "$", "eol", ",", "$", "out", ")", ";", "}" ]
Generate CSV from Data @param array $data Data (row=>cells). @param array $headers Headers. @param string $delimiter Delimiter. @param string $eol Line ending type. @return string CSV content.
[ "Generate", "CSV", "from", "Data" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/format.php#L521-L562
29,716
Blobfolio/blob-common
lib/blobfolio/common/sanitize.php
sanitize.domain
public static function domain($str='', bool $unicode=false) { ref\sanitize::domain($str, $unicode); return $str; }
php
public static function domain($str='', bool $unicode=false) { ref\sanitize::domain($str, $unicode); return $str; }
[ "public", "static", "function", "domain", "(", "$", "str", "=", "''", ",", "bool", "$", "unicode", "=", "false", ")", "{", "ref", "\\", "sanitize", "::", "domain", "(", "$", "str", ",", "$", "unicode", ")", ";", "return", "$", "str", ";", "}" ]
Domain Name. This locates the domain name portion of a URL, removes leading "www." subdomains, and ignores IP addresses. @param string $str Domain. @param bool $unicode Unicode. @return string Domain.
[ "Domain", "Name", "." ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/sanitize.php#L131-L134
29,717
Blobfolio/blob-common
lib/blobfolio/common/sanitize.php
sanitize.to_range
public static function to_range($value, $min=null, $max=null) { ref\sanitize::to_range($value, $min, $max); return $value; }
php
public static function to_range($value, $min=null, $max=null) { ref\sanitize::to_range($value, $min, $max); return $value; }
[ "public", "static", "function", "to_range", "(", "$", "value", ",", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "ref", "\\", "sanitize", "::", "to_range", "(", "$", "value", ",", "$", "min", ",", "$", "max", ")", ";", "return", "$", "value", ";", "}" ]
Confine a Value to a Range @param mixed $value Value. @param mixed $min Min. @param mixed $max Max. @return mixed Value.
[ "Confine", "a", "Value", "to", "a", "Range" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/sanitize.php#L385-L388
29,718
secucard/secucard-connect-php-sdk
src/SecucardConnect/Event/DefaultEventHandler.php
DefaultEventHandler.accept
protected function accept(Event $event) { return $event->target === $this->eventTarget && $event->type === $this->eventType; }
php
protected function accept(Event $event) { return $event->target === $this->eventTarget && $event->type === $this->eventType; }
[ "protected", "function", "accept", "(", "Event", "$", "event", ")", "{", "return", "$", "event", "->", "target", "===", "$", "this", "->", "eventTarget", "&&", "$", "event", "->", "type", "===", "$", "this", "->", "eventType", ";", "}" ]
Can be used by handlers to determine if a handler should process the given event. The default decision is made by comparing the given and this instances event target and event type. May be overridden to adapt. @param Event $event The event to process. @return bool True if can handle, false else.
[ "Can", "be", "used", "by", "handlers", "to", "determine", "if", "a", "handler", "should", "process", "the", "given", "event", ".", "The", "default", "decision", "is", "made", "by", "comparing", "the", "given", "and", "this", "instances", "event", "target", "and", "event", "type", ".", "May", "be", "overridden", "to", "adapt", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Event/DefaultEventHandler.php#L55-L58
29,719
ventoviro/windwalker-core
src/Core/Schedule/ScheduleEvent.php
ScheduleEvent.setExpression
public function setExpression($expression) { if (is_string($expression)) { $expression = CronExpression::factory($expression); } $this->expression = $expression; return $this; }
php
public function setExpression($expression) { if (is_string($expression)) { $expression = CronExpression::factory($expression); } $this->expression = $expression; return $this; }
[ "public", "function", "setExpression", "(", "$", "expression", ")", "{", "if", "(", "is_string", "(", "$", "expression", ")", ")", "{", "$", "expression", "=", "CronExpression", "::", "factory", "(", "$", "expression", ")", ";", "}", "$", "this", "->", "expression", "=", "$", "expression", ";", "return", "$", "this", ";", "}" ]
Method to set property expression @param CronExpression|string $expression @return static Return self to support chaining. @since 3.5.3
[ "Method", "to", "set", "property", "expression" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Schedule/ScheduleEvent.php#L151-L160
29,720
secucard/secucard-connect-php-sdk
src/SecucardConnect/ApiClientConfiguration.php
ApiClientConfiguration.isValid
public function isValid() { $data = $this->toArray(); $missing = array_diff(self::$REQUIRED_FIELDS, array_keys($data)); if ($missing) { throw new \InvalidArgumentException('Config is missing the following keys: ' . implode(', ', $missing)); } return true; }
php
public function isValid() { $data = $this->toArray(); $missing = array_diff(self::$REQUIRED_FIELDS, array_keys($data)); if ($missing) { throw new \InvalidArgumentException('Config is missing the following keys: ' . implode(', ', $missing)); } return true; }
[ "public", "function", "isValid", "(", ")", "{", "$", "data", "=", "$", "this", "->", "toArray", "(", ")", ";", "$", "missing", "=", "array_diff", "(", "self", "::", "$", "REQUIRED_FIELDS", ",", "array_keys", "(", "$", "data", ")", ")", ";", "if", "(", "$", "missing", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Config is missing the following keys: '", ".", "implode", "(", "', '", ",", "$", "missing", ")", ")", ";", "}", "return", "true", ";", "}" ]
Validates the configuration for the api client @throws \InvalidArgumentException If some required param is missing @return true
[ "Validates", "the", "configuration", "for", "the", "api", "client" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/ApiClientConfiguration.php#L120-L131
29,721
secucard/secucard-connect-php-sdk
src/SecucardConnect/ApiClientConfiguration.php
ApiClientConfiguration.setAuth
public function setAuth($auth) { $auth = strtolower($auth); if (!in_array($auth, [self::AUTHENTICATION_METHOD_OAUTH])) { throw new \InvalidArgumentException('Parameter "auth" must be filled and valid'); } $this->auth = $auth; return $this; }
php
public function setAuth($auth) { $auth = strtolower($auth); if (!in_array($auth, [self::AUTHENTICATION_METHOD_OAUTH])) { throw new \InvalidArgumentException('Parameter "auth" must be filled and valid'); } $this->auth = $auth; return $this; }
[ "public", "function", "setAuth", "(", "$", "auth", ")", "{", "$", "auth", "=", "strtolower", "(", "$", "auth", ")", ";", "if", "(", "!", "in_array", "(", "$", "auth", ",", "[", "self", "::", "AUTHENTICATION_METHOD_OAUTH", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Parameter \"auth\" must be filled and valid'", ")", ";", "}", "$", "this", "->", "auth", "=", "$", "auth", ";", "return", "$", "this", ";", "}" ]
Define the authentication method @param string $auth @throws \InvalidArgumentException If some required param is missing or invalid @return self
[ "Define", "the", "authentication", "method" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/ApiClientConfiguration.php#L264-L274
29,722
secucard/secucard-connect-php-sdk
src/SecucardConnect/ApiClientConfiguration.php
ApiClientConfiguration.setAcceptLanguage
public function setAcceptLanguage($accept_language) { $accept_language = strtolower($accept_language); if (!in_array($accept_language, [self::ACCEPT_LANGUAGE_EN, self::ACCEPT_LANGUAGE_DE])) { throw new \InvalidArgumentException('Parameter "accept_language" must be valid'); } $this->accept_language = $accept_language; return $this; }
php
public function setAcceptLanguage($accept_language) { $accept_language = strtolower($accept_language); if (!in_array($accept_language, [self::ACCEPT_LANGUAGE_EN, self::ACCEPT_LANGUAGE_DE])) { throw new \InvalidArgumentException('Parameter "accept_language" must be valid'); } $this->accept_language = $accept_language; return $this; }
[ "public", "function", "setAcceptLanguage", "(", "$", "accept_language", ")", "{", "$", "accept_language", "=", "strtolower", "(", "$", "accept_language", ")", ";", "if", "(", "!", "in_array", "(", "$", "accept_language", ",", "[", "self", "::", "ACCEPT_LANGUAGE_EN", ",", "self", "::", "ACCEPT_LANGUAGE_DE", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Parameter \"accept_language\" must be valid'", ")", ";", "}", "$", "this", "->", "accept_language", "=", "$", "accept_language", ";", "return", "$", "this", ";", "}" ]
Define the language of the error and other api messages @param string $accept_language @throws \InvalidArgumentException If the given param is invalid @return self
[ "Define", "the", "language", "of", "the", "error", "and", "other", "api", "messages" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/ApiClientConfiguration.php#L318-L328
29,723
diff-sniffer/core
src/Diff.php
Diff.filter
public function filter(string $path, array $report) : array { $report['messages'] = isset($this->paths[$path]) ? array_intersect_key( $report['messages'], array_flip($this->paths[$path]) ) : []; $errors = $warnings = $fixable = 0; foreach ($report['messages'] as $line) { foreach ($line as $messages) { foreach ($messages as $message) { switch ($message['type']) { case 'ERROR': $errors++; break; case 'WARNING': $warnings++; break; } if ($message['fixable']) { $fixable++; } } } } return array_merge($report, [ 'errors' => $errors, 'warnings' => $warnings, 'fixable' => $fixable, ]); }
php
public function filter(string $path, array $report) : array { $report['messages'] = isset($this->paths[$path]) ? array_intersect_key( $report['messages'], array_flip($this->paths[$path]) ) : []; $errors = $warnings = $fixable = 0; foreach ($report['messages'] as $line) { foreach ($line as $messages) { foreach ($messages as $message) { switch ($message['type']) { case 'ERROR': $errors++; break; case 'WARNING': $warnings++; break; } if ($message['fixable']) { $fixable++; } } } } return array_merge($report, [ 'errors' => $errors, 'warnings' => $warnings, 'fixable' => $fixable, ]); }
[ "public", "function", "filter", "(", "string", "$", "path", ",", "array", "$", "report", ")", ":", "array", "{", "$", "report", "[", "'messages'", "]", "=", "isset", "(", "$", "this", "->", "paths", "[", "$", "path", "]", ")", "?", "array_intersect_key", "(", "$", "report", "[", "'messages'", "]", ",", "array_flip", "(", "$", "this", "->", "paths", "[", "$", "path", "]", ")", ")", ":", "[", "]", ";", "$", "errors", "=", "$", "warnings", "=", "$", "fixable", "=", "0", ";", "foreach", "(", "$", "report", "[", "'messages'", "]", "as", "$", "line", ")", "{", "foreach", "(", "$", "line", "as", "$", "messages", ")", "{", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "switch", "(", "$", "message", "[", "'type'", "]", ")", "{", "case", "'ERROR'", ":", "$", "errors", "++", ";", "break", ";", "case", "'WARNING'", ":", "$", "warnings", "++", ";", "break", ";", "}", "if", "(", "$", "message", "[", "'fixable'", "]", ")", "{", "$", "fixable", "++", ";", "}", "}", "}", "}", "return", "array_merge", "(", "$", "report", ",", "[", "'errors'", "=>", "$", "errors", ",", "'warnings'", "=>", "$", "warnings", ",", "'fixable'", "=>", "$", "fixable", ",", "]", ")", ";", "}" ]
Filters file report producing another one containing only the lines affected by diff @param string $path File path @param array $report Report data @return array
[ "Filters", "file", "report", "producing", "another", "one", "containing", "only", "the", "lines", "affected", "by", "diff" ]
583369a5f5c91496862f6bdf60b69565da4bc05d
https://github.com/diff-sniffer/core/blob/583369a5f5c91496862f6bdf60b69565da4bc05d/src/Diff.php#L56-L89
29,724
diff-sniffer/core
src/Diff.php
Diff.parse
private function parse(string $diff) : array { $diff = preg_split("/((\r?\n)|(\r\n?))/", $diff); $paths = []; $number = 0; $path = null; foreach ($diff as $line) { if (preg_match('~^\+\+\+\s(.*)~', $line, $matches)) { $path = substr($matches[1], strpos($matches[1], '/') + 1); } elseif (preg_match( '~^@@ -[0-9]+,[0-9]+? \+([0-9]+),[0-9]+? @@.*$~', $line, $matches )) { $number = (int) $matches[1]; } elseif (preg_match('~^\+(.*)~', $line, $matches)) { $paths[$path][] = $number; $number++; } elseif (preg_match('~^[^-]+(.*)~', $line, $matches)) { $number++; } } return $paths; }
php
private function parse(string $diff) : array { $diff = preg_split("/((\r?\n)|(\r\n?))/", $diff); $paths = []; $number = 0; $path = null; foreach ($diff as $line) { if (preg_match('~^\+\+\+\s(.*)~', $line, $matches)) { $path = substr($matches[1], strpos($matches[1], '/') + 1); } elseif (preg_match( '~^@@ -[0-9]+,[0-9]+? \+([0-9]+),[0-9]+? @@.*$~', $line, $matches )) { $number = (int) $matches[1]; } elseif (preg_match('~^\+(.*)~', $line, $matches)) { $paths[$path][] = $number; $number++; } elseif (preg_match('~^[^-]+(.*)~', $line, $matches)) { $number++; } } return $paths; }
[ "private", "function", "parse", "(", "string", "$", "diff", ")", ":", "array", "{", "$", "diff", "=", "preg_split", "(", "\"/((\\r?\\n)|(\\r\\n?))/\"", ",", "$", "diff", ")", ";", "$", "paths", "=", "[", "]", ";", "$", "number", "=", "0", ";", "$", "path", "=", "null", ";", "foreach", "(", "$", "diff", "as", "$", "line", ")", "{", "if", "(", "preg_match", "(", "'~^\\+\\+\\+\\s(.*)~'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "$", "path", "=", "substr", "(", "$", "matches", "[", "1", "]", ",", "strpos", "(", "$", "matches", "[", "1", "]", ",", "'/'", ")", "+", "1", ")", ";", "}", "elseif", "(", "preg_match", "(", "'~^@@ -[0-9]+,[0-9]+? \\+([0-9]+),[0-9]+? @@.*$~'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "$", "number", "=", "(", "int", ")", "$", "matches", "[", "1", "]", ";", "}", "elseif", "(", "preg_match", "(", "'~^\\+(.*)~'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "$", "paths", "[", "$", "path", "]", "[", "]", "=", "$", "number", ";", "$", "number", "++", ";", "}", "elseif", "(", "preg_match", "(", "'~^[^-]+(.*)~'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "$", "number", "++", ";", "}", "}", "return", "$", "paths", ";", "}" ]
Parses diff and returns array containing affected paths and line numbers @param string $diff Diff output @return array
[ "Parses", "diff", "and", "returns", "array", "containing", "affected", "paths", "and", "line", "numbers" ]
583369a5f5c91496862f6bdf60b69565da4bc05d
https://github.com/diff-sniffer/core/blob/583369a5f5c91496862f6bdf60b69565da4bc05d/src/Diff.php#L98-L123
29,725
polyfony-inc/polyfony
Private/Polyfony/Bundles.php
Bundles.init
public static function init() :void { // marker Profiler::setMarker('Bundles.init', 'framework'); // if cache is enabled and in prod load the cache, else parse bundles Config::isProd() && Cache::has('Includes') ? self::loadCachedDependencies() : self::loadDependencies(); // now that we have the list of config files, pass them to the config class Config::includeBundlesConfigs(self::$_configs); // now that we have the list of route files, pass them to the router class Router::includeBundlesRoutes(self::$_routes); // marker Profiler::releaseMarker('Bundles.init'); }
php
public static function init() :void { // marker Profiler::setMarker('Bundles.init', 'framework'); // if cache is enabled and in prod load the cache, else parse bundles Config::isProd() && Cache::has('Includes') ? self::loadCachedDependencies() : self::loadDependencies(); // now that we have the list of config files, pass them to the config class Config::includeBundlesConfigs(self::$_configs); // now that we have the list of route files, pass them to the router class Router::includeBundlesRoutes(self::$_routes); // marker Profiler::releaseMarker('Bundles.init'); }
[ "public", "static", "function", "init", "(", ")", ":", "void", "{", "// marker", "Profiler", "::", "setMarker", "(", "'Bundles.init'", ",", "'framework'", ")", ";", "// if cache is enabled and in prod load the cache, else parse bundles", "Config", "::", "isProd", "(", ")", "&&", "Cache", "::", "has", "(", "'Includes'", ")", "?", "self", "::", "loadCachedDependencies", "(", ")", ":", "self", "::", "loadDependencies", "(", ")", ";", "// now that we have the list of config files, pass them to the config class", "Config", "::", "includeBundlesConfigs", "(", "self", "::", "$", "_configs", ")", ";", "// now that we have the list of route files, pass them to the router class", "Router", "::", "includeBundlesRoutes", "(", "self", "::", "$", "_routes", ")", ";", "// marker", "Profiler", "::", "releaseMarker", "(", "'Bundles.init'", ")", ";", "}" ]
will get the list of bundles and get their routes and runtimes
[ "will", "get", "the", "list", "of", "bundles", "and", "get", "their", "routes", "and", "runtimes" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Bundles.php#L12-L29
29,726
polyfony-inc/polyfony
Private/Polyfony/Bundles.php
Bundles.getLocales
public static function getLocales(string $bundle) :array { // declare an array to hold the list $locales = array(); // set the locales path $locales_path = "../Private/Bundles/{$bundle}/Locales/"; // if the directory exists if(file_exists($locales_path) && is_dir($locales_path)) { // for each file in the directory foreach(scandir($locales_path) as $locales_file) { // if the file is a normal one if(substr($locales_file,0,1) != '.' ) { // push it into the array of locales $locales[] = $locales_path . $locales_file ; } } } // return all found locales return($locales); }
php
public static function getLocales(string $bundle) :array { // declare an array to hold the list $locales = array(); // set the locales path $locales_path = "../Private/Bundles/{$bundle}/Locales/"; // if the directory exists if(file_exists($locales_path) && is_dir($locales_path)) { // for each file in the directory foreach(scandir($locales_path) as $locales_file) { // if the file is a normal one if(substr($locales_file,0,1) != '.' ) { // push it into the array of locales $locales[] = $locales_path . $locales_file ; } } } // return all found locales return($locales); }
[ "public", "static", "function", "getLocales", "(", "string", "$", "bundle", ")", ":", "array", "{", "// declare an array to hold the list", "$", "locales", "=", "array", "(", ")", ";", "// set the locales path", "$", "locales_path", "=", "\"../Private/Bundles/{$bundle}/Locales/\"", ";", "// if the directory exists", "if", "(", "file_exists", "(", "$", "locales_path", ")", "&&", "is_dir", "(", "$", "locales_path", ")", ")", "{", "// for each file in the directory", "foreach", "(", "scandir", "(", "$", "locales_path", ")", "as", "$", "locales_file", ")", "{", "// if the file is a normal one", "if", "(", "substr", "(", "$", "locales_file", ",", "0", ",", "1", ")", "!=", "'.'", ")", "{", "// push it into the array of locales", "$", "locales", "[", "]", "=", "$", "locales_path", ".", "$", "locales_file", ";", "}", "}", "}", "// return all found locales", "return", "(", "$", "locales", ")", ";", "}" ]
get locales for a bundle
[ "get", "locales", "for", "a", "bundle" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Bundles.php#L70-L90
29,727
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/CustomersService.php
CustomersService.process
private function process(Customer &$customer) { if (isset($customer->contact) && isset($customer->contact->picture)) { $customer->contact->pictureObject = $this->initMediaResource($customer->contact->picture); } }
php
private function process(Customer &$customer) { if (isset($customer->contact) && isset($customer->contact->picture)) { $customer->contact->pictureObject = $this->initMediaResource($customer->contact->picture); } }
[ "private", "function", "process", "(", "Customer", "&", "$", "customer", ")", "{", "if", "(", "isset", "(", "$", "customer", "->", "contact", ")", "&&", "isset", "(", "$", "customer", "->", "contact", "->", "picture", ")", ")", "{", "$", "customer", "->", "contact", "->", "pictureObject", "=", "$", "this", "->", "initMediaResource", "(", "$", "customer", "->", "contact", "->", "picture", ")", ";", "}", "}" ]
Handles proper picture object initialization after retrieval of a customer. @param Customer $customer
[ "Handles", "proper", "picture", "object", "initialization", "after", "retrieval", "of", "a", "customer", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/CustomersService.php#L43-L48
29,728
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/CheckAcess.php
CheckAcess.check
static public function check(FedoraResource $res): bool { if (self::$client === null) { self::$client = new Client([ 'verify' => false, ]); } $headers = []; if (isset($_SERVER['PHP_AUTH_USER'])) { $headers['Authorization'] = 'Basic ' . base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']); } $cookies = []; foreach ($_COOKIE as $k => $v) { $cookies[] = $k . '=' . $v; } if (count($cookies) > 0) { $headers['Cookie'] = implode('; ', $cookies); } $req = new Request('GET', $res->getUri() . '/fcr:metadata', $headers); try { $resp = self::$client->send($req); return true; } catch (RequestException $ex) { if ($ex->hasResponse()) { $resp = $ex->getResponse(); if (in_array($resp->getStatusCode(), [401, 403])) { return false; } } throw $ex; } }
php
static public function check(FedoraResource $res): bool { if (self::$client === null) { self::$client = new Client([ 'verify' => false, ]); } $headers = []; if (isset($_SERVER['PHP_AUTH_USER'])) { $headers['Authorization'] = 'Basic ' . base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']); } $cookies = []; foreach ($_COOKIE as $k => $v) { $cookies[] = $k . '=' . $v; } if (count($cookies) > 0) { $headers['Cookie'] = implode('; ', $cookies); } $req = new Request('GET', $res->getUri() . '/fcr:metadata', $headers); try { $resp = self::$client->send($req); return true; } catch (RequestException $ex) { if ($ex->hasResponse()) { $resp = $ex->getResponse(); if (in_array($resp->getStatusCode(), [401, 403])) { return false; } } throw $ex; } }
[ "static", "public", "function", "check", "(", "FedoraResource", "$", "res", ")", ":", "bool", "{", "if", "(", "self", "::", "$", "client", "===", "null", ")", "{", "self", "::", "$", "client", "=", "new", "Client", "(", "[", "'verify'", "=>", "false", ",", "]", ")", ";", "}", "$", "headers", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "_SERVER", "[", "'PHP_AUTH_USER'", "]", ")", ")", "{", "$", "headers", "[", "'Authorization'", "]", "=", "'Basic '", ".", "base64_encode", "(", "$", "_SERVER", "[", "'PHP_AUTH_USER'", "]", ".", "':'", ".", "$", "_SERVER", "[", "'PHP_AUTH_PW'", "]", ")", ";", "}", "$", "cookies", "=", "[", "]", ";", "foreach", "(", "$", "_COOKIE", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "cookies", "[", "]", "=", "$", "k", ".", "'='", ".", "$", "v", ";", "}", "if", "(", "count", "(", "$", "cookies", ")", ">", "0", ")", "{", "$", "headers", "[", "'Cookie'", "]", "=", "implode", "(", "'; '", ",", "$", "cookies", ")", ";", "}", "$", "req", "=", "new", "Request", "(", "'GET'", ",", "$", "res", "->", "getUri", "(", ")", ".", "'/fcr:metadata'", ",", "$", "headers", ")", ";", "try", "{", "$", "resp", "=", "self", "::", "$", "client", "->", "send", "(", "$", "req", ")", ";", "return", "true", ";", "}", "catch", "(", "RequestException", "$", "ex", ")", "{", "if", "(", "$", "ex", "->", "hasResponse", "(", ")", ")", "{", "$", "resp", "=", "$", "ex", "->", "getResponse", "(", ")", ";", "if", "(", "in_array", "(", "$", "resp", "->", "getStatusCode", "(", ")", ",", "[", "401", ",", "403", "]", ")", ")", "{", "return", "false", ";", "}", "}", "throw", "$", "ex", ";", "}", "}" ]
Checks if a given resource is accessible with same credentials as ones provided in the current request. @param FedoraResource $res @return bool @throws RequestException
[ "Checks", "if", "a", "given", "resource", "is", "accessible", "with", "same", "credentials", "as", "ones", "provided", "in", "the", "current", "request", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/CheckAcess.php#L55-L87
29,729
polyfony-inc/polyfony
Private/Polyfony/Router.php
Router.redirect
public static function redirect(string $source_url, string $redirection_url, int $status_code=301) { // create a new route $route = new Route(); // add it to the list of known routes self::$_routes[$route->name] = $route ->setUrl($source_url) ->setRedirect($redirection_url, $status_code); // return the route for finer tuning return self::$_routes[$route->name]; }
php
public static function redirect(string $source_url, string $redirection_url, int $status_code=301) { // create a new route $route = new Route(); // add it to the list of known routes self::$_routes[$route->name] = $route ->setUrl($source_url) ->setRedirect($redirection_url, $status_code); // return the route for finer tuning return self::$_routes[$route->name]; }
[ "public", "static", "function", "redirect", "(", "string", "$", "source_url", ",", "string", "$", "redirection_url", ",", "int", "$", "status_code", "=", "301", ")", "{", "// create a new route", "$", "route", "=", "new", "Route", "(", ")", ";", "// add it to the list of known routes", "self", "::", "$", "_routes", "[", "$", "route", "->", "name", "]", "=", "$", "route", "->", "setUrl", "(", "$", "source_url", ")", "->", "setRedirect", "(", "$", "redirection_url", ",", "$", "status_code", ")", ";", "// return the route for finer tuning", "return", "self", "::", "$", "_routes", "[", "$", "route", "->", "name", "]", ";", "}" ]
new syntax for quick redirects
[ "new", "syntax", "for", "quick", "redirects" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Router.php#L103-L112
29,730
polyfony-inc/polyfony
Private/Polyfony/Router.php
Router.getRoute
public static function getRoute(string $route_name) { // return the route of false return self::hasRoute($route_name) ? self::$_routes[$route_name] : false; }
php
public static function getRoute(string $route_name) { // return the route of false return self::hasRoute($route_name) ? self::$_routes[$route_name] : false; }
[ "public", "static", "function", "getRoute", "(", "string", "$", "route_name", ")", "{", "// return the route of false", "return", "self", "::", "hasRoute", "(", "$", "route_name", ")", "?", "self", "::", "$", "_routes", "[", "$", "route_name", "]", ":", "false", ";", "}" ]
get a specific route
[ "get", "a", "specific", "route" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Router.php#L121-L124
29,731
polyfony-inc/polyfony
Private/Polyfony/Router.php
Router.routeMatch
private static function routeMatch(string $request_url, string $request_method, Route $route) :bool { // if the method is set for that route, and it doesn't match if(!$route->hasMethod($request_method)) { return false; } // if the url doesn't begin with the static segment or that route if(!$route->hasStaticUrlSegment($request_url)) { return false; } // if we've got a redirect, let's go for it $route->redirectIfItIsOne(); // get a list of current request parameters, with numerical indexes $indexed_request_parameters = Request::getUrlIndexedParameters($route->staticSegment); // if restricttion against url parameters don't match if(!$route->validatesTheseParameters($indexed_request_parameters)) { return false; } // send the named parameters to the request class $route->sendNamedParametersToRequest($indexed_request_parameters); // deduce the dynamic action from the url parameters if necessary $route->deduceAction(); // check if they match defined constraints return true; }
php
private static function routeMatch(string $request_url, string $request_method, Route $route) :bool { // if the method is set for that route, and it doesn't match if(!$route->hasMethod($request_method)) { return false; } // if the url doesn't begin with the static segment or that route if(!$route->hasStaticUrlSegment($request_url)) { return false; } // if we've got a redirect, let's go for it $route->redirectIfItIsOne(); // get a list of current request parameters, with numerical indexes $indexed_request_parameters = Request::getUrlIndexedParameters($route->staticSegment); // if restricttion against url parameters don't match if(!$route->validatesTheseParameters($indexed_request_parameters)) { return false; } // send the named parameters to the request class $route->sendNamedParametersToRequest($indexed_request_parameters); // deduce the dynamic action from the url parameters if necessary $route->deduceAction(); // check if they match defined constraints return true; }
[ "private", "static", "function", "routeMatch", "(", "string", "$", "request_url", ",", "string", "$", "request_method", ",", "Route", "$", "route", ")", ":", "bool", "{", "// if the method is set for that route, and it doesn't match", "if", "(", "!", "$", "route", "->", "hasMethod", "(", "$", "request_method", ")", ")", "{", "return", "false", ";", "}", "// if the url doesn't begin with the static segment or that route", "if", "(", "!", "$", "route", "->", "hasStaticUrlSegment", "(", "$", "request_url", ")", ")", "{", "return", "false", ";", "}", "// if we've got a redirect, let's go for it", "$", "route", "->", "redirectIfItIsOne", "(", ")", ";", "// get a list of current request parameters, with numerical indexes", "$", "indexed_request_parameters", "=", "Request", "::", "getUrlIndexedParameters", "(", "$", "route", "->", "staticSegment", ")", ";", "// if restricttion against url parameters don't match", "if", "(", "!", "$", "route", "->", "validatesTheseParameters", "(", "$", "indexed_request_parameters", ")", ")", "{", "return", "false", ";", "}", "// send the named parameters to the request class", "$", "route", "->", "sendNamedParametersToRequest", "(", "$", "indexed_request_parameters", ")", ";", "// deduce the dynamic action from the url parameters if necessary", "$", "route", "->", "deduceAction", "(", ")", ";", "// check if they match defined constraints", "return", "true", ";", "}" ]
Test to see if this route is valid against the URL. @access private @param array $requestUrl The URL to test the route against. @param Core\Route $route A Route declared by the application. @return boolean
[ "Test", "to", "see", "if", "this", "route", "is", "valid", "against", "the", "URL", "." ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Router.php#L178-L203
29,732
polyfony-inc/polyfony
Private/Polyfony/Router.php
Router.reverse
public static function reverse( string $route_name, array $parameters = [], bool $is_absolute = false, bool $force_tls = false ) :string { // if the specified route doesn't exist if(!self::hasRoute($route_name)) { // we cannot reverse a route that does not exist throw new Exception("Router::reverse() : The [{$route_name}] route does not exist"); } // return the reversed url return self::$_routes[$route_name]->getAssembledUrl($parameters, $is_absolute, $force_tls); }
php
public static function reverse( string $route_name, array $parameters = [], bool $is_absolute = false, bool $force_tls = false ) :string { // if the specified route doesn't exist if(!self::hasRoute($route_name)) { // we cannot reverse a route that does not exist throw new Exception("Router::reverse() : The [{$route_name}] route does not exist"); } // return the reversed url return self::$_routes[$route_name]->getAssembledUrl($parameters, $is_absolute, $force_tls); }
[ "public", "static", "function", "reverse", "(", "string", "$", "route_name", ",", "array", "$", "parameters", "=", "[", "]", ",", "bool", "$", "is_absolute", "=", "false", ",", "bool", "$", "force_tls", "=", "false", ")", ":", "string", "{", "// if the specified route doesn't exist", "if", "(", "!", "self", "::", "hasRoute", "(", "$", "route_name", ")", ")", "{", "// we cannot reverse a route that does not exist", "throw", "new", "Exception", "(", "\"Router::reverse() : The [{$route_name}] route does not exist\"", ")", ";", "}", "// return the reversed url", "return", "self", "::", "$", "_routes", "[", "$", "route_name", "]", "->", "getAssembledUrl", "(", "$", "parameters", ",", "$", "is_absolute", ",", "$", "force_tls", ")", ";", "}" ]
Reverse the router. Make a URL out of a route name and parameters, rather than parsing one. Note that this function does not care about URL paths! @access public @param string $route_name The name of the route we wish to generate a URL for. @param array $parameters The parameters that the route requires. @return string @throws \Exception If the route does not exist. @static
[ "Reverse", "the", "router", "." ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Router.php#L218-L231
29,733
ventoviro/windwalker-core
src/Core/Error/ErrorManager.php
ErrorManager.error
public function error($code, $message, $file, $line, $context = null) { if (error_reporting() === 0) { return; } $content = sprintf('%s. File: %s (line: %s)', $message, $file, $line); throw new \ErrorException($content, 500, $code, $file, $line, new \Error()); }
php
public function error($code, $message, $file, $line, $context = null) { if (error_reporting() === 0) { return; } $content = sprintf('%s. File: %s (line: %s)', $message, $file, $line); throw new \ErrorException($content, 500, $code, $file, $line, new \Error()); }
[ "public", "function", "error", "(", "$", "code", ",", "$", "message", ",", "$", "file", ",", "$", "line", ",", "$", "context", "=", "null", ")", "{", "if", "(", "error_reporting", "(", ")", "===", "0", ")", "{", "return", ";", "}", "$", "content", "=", "sprintf", "(", "'%s. File: %s (line: %s)'", ",", "$", "message", ",", "$", "file", ",", "$", "line", ")", ";", "throw", "new", "\\", "ErrorException", "(", "$", "content", ",", "500", ",", "$", "code", ",", "$", "file", ",", "$", "line", ",", "new", "\\", "Error", "(", ")", ")", ";", "}" ]
The error handler. @param integer $code The level of the error raised, as an integer. @param string $message The error message, as a string. @param string $file The filename that the error was raised in, as a string. @param integer $line The line number the error was raised at, as an integer. @param mixed $context An array that contains variables in the scope which this error occurred. @throws \ErrorException @return void @see http://php.net/manual/en/function.set-error-handler.php
[ "The", "error", "handler", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Error/ErrorManager.php#L115-L124
29,734
ventoviro/windwalker-core
src/Core/Error/ErrorManager.php
ErrorManager.exception
public function exception($exception) { try { foreach ($this->handlers as $handler) { $handler($exception); } } catch (\Throwable $e) { $msg = "Infinity loop in exception & error handler. \nMessage:\n" . $e; if ($this->app->get('system.debug')) { exit($msg); } exit($e->getMessage()); } exit(); }
php
public function exception($exception) { try { foreach ($this->handlers as $handler) { $handler($exception); } } catch (\Throwable $e) { $msg = "Infinity loop in exception & error handler. \nMessage:\n" . $e; if ($this->app->get('system.debug')) { exit($msg); } exit($e->getMessage()); } exit(); }
[ "public", "function", "exception", "(", "$", "exception", ")", "{", "try", "{", "foreach", "(", "$", "this", "->", "handlers", "as", "$", "handler", ")", "{", "$", "handler", "(", "$", "exception", ")", ";", "}", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "$", "msg", "=", "\"Infinity loop in exception & error handler. \\nMessage:\\n\"", ".", "$", "e", ";", "if", "(", "$", "this", "->", "app", "->", "get", "(", "'system.debug'", ")", ")", "{", "exit", "(", "$", "msg", ")", ";", "}", "exit", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "exit", "(", ")", ";", "}" ]
The exception handler. @param \Throwable|\Exception $exception The exception object. @return void @link http://php.net/manual/en/function.set-exception-handler.php
[ "The", "exception", "handler", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Error/ErrorManager.php#L135-L152
29,735
ventoviro/windwalker-core
src/Core/Error/ErrorManager.php
ErrorManager.setErrorTemplate
public function setErrorTemplate($errorTemplate, $engine = null) { if (!\is_string($errorTemplate)) { throw new \InvalidArgumentException('Please use string as template name (Example: "folder.file").'); } $this->errorTemplate = $errorTemplate; if ($engine) { $this->setEngine($engine); } }
php
public function setErrorTemplate($errorTemplate, $engine = null) { if (!\is_string($errorTemplate)) { throw new \InvalidArgumentException('Please use string as template name (Example: "folder.file").'); } $this->errorTemplate = $errorTemplate; if ($engine) { $this->setEngine($engine); } }
[ "public", "function", "setErrorTemplate", "(", "$", "errorTemplate", ",", "$", "engine", "=", "null", ")", "{", "if", "(", "!", "\\", "is_string", "(", "$", "errorTemplate", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Please use string as template name (Example: \"folder.file\").'", ")", ";", "}", "$", "this", "->", "errorTemplate", "=", "$", "errorTemplate", ";", "if", "(", "$", "engine", ")", "{", "$", "this", "->", "setEngine", "(", "$", "engine", ")", ";", "}", "}" ]
Method to set property errorTemplate @param string $errorTemplate @param string $engine @return void @throws \InvalidArgumentException
[ "Method", "to", "set", "property", "errorTemplate" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Error/ErrorManager.php#L201-L212
29,736
ventoviro/windwalker-core
src/Core/Error/ErrorManager.php
ErrorManager.addHandler
public function addHandler(callable $handler, $name = null) { if ($name) { $this->handlers[$name] = $handler; } else { $this->handlers[] = $handler; } return $this; }
php
public function addHandler(callable $handler, $name = null) { if ($name) { $this->handlers[$name] = $handler; } else { $this->handlers[] = $handler; } return $this; }
[ "public", "function", "addHandler", "(", "callable", "$", "handler", ",", "$", "name", "=", "null", ")", "{", "if", "(", "$", "name", ")", "{", "$", "this", "->", "handlers", "[", "$", "name", "]", "=", "$", "handler", ";", "}", "else", "{", "$", "this", "->", "handlers", "[", "]", "=", "$", "handler", ";", "}", "return", "$", "this", ";", "}" ]
Method to set property handler @param callable $handler @param string $name @return static Return self to support chaining.
[ "Method", "to", "set", "property", "handler" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Error/ErrorManager.php#L288-L297
29,737
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/dissemination/parameter/AddParam.php
AddParam.transform
public function transform(string $value, string $paramName = '', string $paramValue = ''): string { $value = parse_url($value); if (!isset($value['query'])) { $value['query'] = ''; } $param = []; parse_str($value['query'], $param); if (!isset($param[$paramName])) { $param[$paramName] = $paramValue; } else { if (!is_array($param[$paramName])) { $param[$paramName] = [$param[$paramName]]; } $param[$paramName][] = $paramValue; $param[$paramName] = array_unique($param[$paramName]); } $value['query'] = http_build_query($param); $scheme = isset($value['scheme']) ? $value['scheme'] . '://' : ''; $host = isset($value['host']) ? $value['host'] : ''; $port = isset($value['port']) ? ':' . $value['port'] : ''; $user = isset($value['user']) ? $value['user'] : ''; $pass = isset($value['pass']) ? ':' . $value['pass'] : ''; $pass = ($user || $pass) ? "$pass@" : ''; $path = isset($value['path']) ? $value['path'] : ''; $query = isset($value['query']) ? '?' . $value['query'] : ''; $fragment = isset($value['fragment']) ? '#' . $value['fragment'] : ''; return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; }
php
public function transform(string $value, string $paramName = '', string $paramValue = ''): string { $value = parse_url($value); if (!isset($value['query'])) { $value['query'] = ''; } $param = []; parse_str($value['query'], $param); if (!isset($param[$paramName])) { $param[$paramName] = $paramValue; } else { if (!is_array($param[$paramName])) { $param[$paramName] = [$param[$paramName]]; } $param[$paramName][] = $paramValue; $param[$paramName] = array_unique($param[$paramName]); } $value['query'] = http_build_query($param); $scheme = isset($value['scheme']) ? $value['scheme'] . '://' : ''; $host = isset($value['host']) ? $value['host'] : ''; $port = isset($value['port']) ? ':' . $value['port'] : ''; $user = isset($value['user']) ? $value['user'] : ''; $pass = isset($value['pass']) ? ':' . $value['pass'] : ''; $pass = ($user || $pass) ? "$pass@" : ''; $path = isset($value['path']) ? $value['path'] : ''; $query = isset($value['query']) ? '?' . $value['query'] : ''; $fragment = isset($value['fragment']) ? '#' . $value['fragment'] : ''; return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; }
[ "public", "function", "transform", "(", "string", "$", "value", ",", "string", "$", "paramName", "=", "''", ",", "string", "$", "paramValue", "=", "''", ")", ":", "string", "{", "$", "value", "=", "parse_url", "(", "$", "value", ")", ";", "if", "(", "!", "isset", "(", "$", "value", "[", "'query'", "]", ")", ")", "{", "$", "value", "[", "'query'", "]", "=", "''", ";", "}", "$", "param", "=", "[", "]", ";", "parse_str", "(", "$", "value", "[", "'query'", "]", ",", "$", "param", ")", ";", "if", "(", "!", "isset", "(", "$", "param", "[", "$", "paramName", "]", ")", ")", "{", "$", "param", "[", "$", "paramName", "]", "=", "$", "paramValue", ";", "}", "else", "{", "if", "(", "!", "is_array", "(", "$", "param", "[", "$", "paramName", "]", ")", ")", "{", "$", "param", "[", "$", "paramName", "]", "=", "[", "$", "param", "[", "$", "paramName", "]", "]", ";", "}", "$", "param", "[", "$", "paramName", "]", "[", "]", "=", "$", "paramValue", ";", "$", "param", "[", "$", "paramName", "]", "=", "array_unique", "(", "$", "param", "[", "$", "paramName", "]", ")", ";", "}", "$", "value", "[", "'query'", "]", "=", "http_build_query", "(", "$", "param", ")", ";", "$", "scheme", "=", "isset", "(", "$", "value", "[", "'scheme'", "]", ")", "?", "$", "value", "[", "'scheme'", "]", ".", "'://'", ":", "''", ";", "$", "host", "=", "isset", "(", "$", "value", "[", "'host'", "]", ")", "?", "$", "value", "[", "'host'", "]", ":", "''", ";", "$", "port", "=", "isset", "(", "$", "value", "[", "'port'", "]", ")", "?", "':'", ".", "$", "value", "[", "'port'", "]", ":", "''", ";", "$", "user", "=", "isset", "(", "$", "value", "[", "'user'", "]", ")", "?", "$", "value", "[", "'user'", "]", ":", "''", ";", "$", "pass", "=", "isset", "(", "$", "value", "[", "'pass'", "]", ")", "?", "':'", ".", "$", "value", "[", "'pass'", "]", ":", "''", ";", "$", "pass", "=", "(", "$", "user", "||", "$", "pass", ")", "?", "\"$pass@\"", ":", "''", ";", "$", "path", "=", "isset", "(", "$", "value", "[", "'path'", "]", ")", "?", "$", "value", "[", "'path'", "]", ":", "''", ";", "$", "query", "=", "isset", "(", "$", "value", "[", "'query'", "]", ")", "?", "'?'", ".", "$", "value", "[", "'query'", "]", ":", "''", ";", "$", "fragment", "=", "isset", "(", "$", "value", "[", "'fragment'", "]", ")", "?", "'#'", ".", "$", "value", "[", "'fragment'", "]", ":", "''", ";", "return", "$", "scheme", ".", "$", "user", ".", "$", "pass", ".", "$", "host", ".", "$", "port", ".", "$", "path", ".", "$", "query", ".", "$", "fragment", ";", "}" ]
Adds a given query parameter value to the URL. If the parameter already exists in the query, it's turned into an array. @param string $value URL to be transformed @param string $paramName query parameter name @param string $paramValue query parameter value @return string
[ "Adds", "a", "given", "query", "parameter", "value", "to", "the", "URL", ".", "If", "the", "parameter", "already", "exists", "in", "the", "query", "it", "s", "turned", "into", "an", "array", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/parameter/AddParam.php#L57-L87
29,738
locomotivemtl/charcoal-ui
src/Charcoal/Ui/FormGroup/FormGroupTrait.php
FormGroupTrait.inputs
public function inputs(callable $inputCallback = null) { $groups = $this->groups; uasort($groups, [ $this, 'sortItemsByPriority' ]); $inputCallback = isset($inputCallback) ? $inputCallback : $this->inputCallback; foreach ($inputs as $input) { if (!$input->l10nMode()) { $input->setL10nMode($this->l10nMode()); } if ($inputCallback) { $inputCallback($input); } $GLOBALS['widget_template'] = $input->template(); yield $input->ident() => $input; $GLOBALS['widget_template'] = ''; } }
php
public function inputs(callable $inputCallback = null) { $groups = $this->groups; uasort($groups, [ $this, 'sortItemsByPriority' ]); $inputCallback = isset($inputCallback) ? $inputCallback : $this->inputCallback; foreach ($inputs as $input) { if (!$input->l10nMode()) { $input->setL10nMode($this->l10nMode()); } if ($inputCallback) { $inputCallback($input); } $GLOBALS['widget_template'] = $input->template(); yield $input->ident() => $input; $GLOBALS['widget_template'] = ''; } }
[ "public", "function", "inputs", "(", "callable", "$", "inputCallback", "=", "null", ")", "{", "$", "groups", "=", "$", "this", "->", "groups", ";", "uasort", "(", "$", "groups", ",", "[", "$", "this", ",", "'sortItemsByPriority'", "]", ")", ";", "$", "inputCallback", "=", "isset", "(", "$", "inputCallback", ")", "?", "$", "inputCallback", ":", "$", "this", "->", "inputCallback", ";", "foreach", "(", "$", "inputs", "as", "$", "input", ")", "{", "if", "(", "!", "$", "input", "->", "l10nMode", "(", ")", ")", "{", "$", "input", "->", "setL10nMode", "(", "$", "this", "->", "l10nMode", "(", ")", ")", ";", "}", "if", "(", "$", "inputCallback", ")", "{", "$", "inputCallback", "(", "$", "input", ")", ";", "}", "$", "GLOBALS", "[", "'widget_template'", "]", "=", "$", "input", "->", "template", "(", ")", ";", "yield", "$", "input", "->", "ident", "(", ")", "=>", "$", "input", ";", "$", "GLOBALS", "[", "'widget_template'", "]", "=", "''", ";", "}", "}" ]
Form Input generator. @param callable $inputCallback Optional. Input callback. @return FormGroupInterface[]|Generator
[ "Form", "Input", "generator", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/FormGroup/FormGroupTrait.php#L218-L235
29,739
acdh-oeaw/repo-php-util
src/acdhOeaw/util/MetadataCollection.php
MetadataCollection.import
public function import(string $namespace, int $singleOutNmsp): array { $dict = array(self::SKIP, self::CREATE); if (!in_array($singleOutNmsp, $dict)) { throw new InvalidArgumentException('singleOutNmsp parameters must be one of MetadataCollection::SKIP, MetadataCollection::CREATE'); } $this->autoCommitCounter = 0; $this->removeLiteralIds(); $this->promoteUrisToIds(); $toBeImported = $this->filterResources($namespace, $singleOutNmsp); $fedoraResources = $this->assureUuids($toBeImported); foreach ($toBeImported as $n => $res) { $uri = $res->getUri(); $fedoraRes = $fedoraResources[$uri]; echo self::$debug ? "Importing " . $uri . " (" . ($n + 1) . "/" . count($toBeImported) . ")\n" : ""; $this->sanitizeResource($res, $namespace); echo self::$debug ? "\tupdating " . $fedoraRes->getUri(true) . "\n" : ""; $meta = $fedoraRes->getMetadata(); $meta->merge($res, array(RC::idProp())); $fedoraRes->setMetadata($meta, false); $fedoraRes->updateMetadata(); $this->handleAutoCommit(); } return array_values($fedoraResources); }
php
public function import(string $namespace, int $singleOutNmsp): array { $dict = array(self::SKIP, self::CREATE); if (!in_array($singleOutNmsp, $dict)) { throw new InvalidArgumentException('singleOutNmsp parameters must be one of MetadataCollection::SKIP, MetadataCollection::CREATE'); } $this->autoCommitCounter = 0; $this->removeLiteralIds(); $this->promoteUrisToIds(); $toBeImported = $this->filterResources($namespace, $singleOutNmsp); $fedoraResources = $this->assureUuids($toBeImported); foreach ($toBeImported as $n => $res) { $uri = $res->getUri(); $fedoraRes = $fedoraResources[$uri]; echo self::$debug ? "Importing " . $uri . " (" . ($n + 1) . "/" . count($toBeImported) . ")\n" : ""; $this->sanitizeResource($res, $namespace); echo self::$debug ? "\tupdating " . $fedoraRes->getUri(true) . "\n" : ""; $meta = $fedoraRes->getMetadata(); $meta->merge($res, array(RC::idProp())); $fedoraRes->setMetadata($meta, false); $fedoraRes->updateMetadata(); $this->handleAutoCommit(); } return array_values($fedoraResources); }
[ "public", "function", "import", "(", "string", "$", "namespace", ",", "int", "$", "singleOutNmsp", ")", ":", "array", "{", "$", "dict", "=", "array", "(", "self", "::", "SKIP", ",", "self", "::", "CREATE", ")", ";", "if", "(", "!", "in_array", "(", "$", "singleOutNmsp", ",", "$", "dict", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'singleOutNmsp parameters must be one of MetadataCollection::SKIP, MetadataCollection::CREATE'", ")", ";", "}", "$", "this", "->", "autoCommitCounter", "=", "0", ";", "$", "this", "->", "removeLiteralIds", "(", ")", ";", "$", "this", "->", "promoteUrisToIds", "(", ")", ";", "$", "toBeImported", "=", "$", "this", "->", "filterResources", "(", "$", "namespace", ",", "$", "singleOutNmsp", ")", ";", "$", "fedoraResources", "=", "$", "this", "->", "assureUuids", "(", "$", "toBeImported", ")", ";", "foreach", "(", "$", "toBeImported", "as", "$", "n", "=>", "$", "res", ")", "{", "$", "uri", "=", "$", "res", "->", "getUri", "(", ")", ";", "$", "fedoraRes", "=", "$", "fedoraResources", "[", "$", "uri", "]", ";", "echo", "self", "::", "$", "debug", "?", "\"Importing \"", ".", "$", "uri", ".", "\" (\"", ".", "(", "$", "n", "+", "1", ")", ".", "\"/\"", ".", "count", "(", "$", "toBeImported", ")", ".", "\")\\n\"", ":", "\"\"", ";", "$", "this", "->", "sanitizeResource", "(", "$", "res", ",", "$", "namespace", ")", ";", "echo", "self", "::", "$", "debug", "?", "\"\\tupdating \"", ".", "$", "fedoraRes", "->", "getUri", "(", "true", ")", ".", "\"\\n\"", ":", "\"\"", ";", "$", "meta", "=", "$", "fedoraRes", "->", "getMetadata", "(", ")", ";", "$", "meta", "->", "merge", "(", "$", "res", ",", "array", "(", "RC", "::", "idProp", "(", ")", ")", ")", ";", "$", "fedoraRes", "->", "setMetadata", "(", "$", "meta", ",", "false", ")", ";", "$", "fedoraRes", "->", "updateMetadata", "(", ")", ";", "$", "this", "->", "handleAutoCommit", "(", ")", ";", "}", "return", "array_values", "(", "$", "fedoraResources", ")", ";", "}" ]
Imports the whole graph by looping over all resources. A repository resource is created for every node containing at least one cfg:fedoraIdProp property and: - containg at least one other property - or being within $namespace - or when $singleOutNmsp equals to MetadataCollection::CREATE Resources without cfg:fedoraIdProp property are skipped as we are unable to identify them on the next import (which would lead to duplication). Resource with a fully qualified URI is considered as having cfg:fedoraIdProp (its URI is taken as cfg:fedoraIdProp property value). Resources in the graph can denote relationships in any way but all object URIs already existing in the repository and all object URIs in the $namespace will be turned into ACDH ids. This means graph can not contain circular dependencies between resources which do not already exist in the repository, like: ``` _:a some:Prop _:b . _:b some:Prop _:a . ``` The $errorOnCycle parameter determines behaviour of the method when such a cycle exists in the graph. @param string $namespace repository resources will be created for all resources in this namespace @param int $singleOutNmsp should repository resources be created representing URIs outside $namespace (MetadataCollection::SKIP or MetadataCollection::CREATE) @return array @throws InvalidArgumentException
[ "Imports", "the", "whole", "graph", "by", "looping", "over", "all", "resources", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/MetadataCollection.php#L197-L224
29,740
acdh-oeaw/repo-php-util
src/acdhOeaw/util/MetadataCollection.php
MetadataCollection.filterResources
private function filterResources(string $namespace, int $singleOutNmsp): array { $result = array(); echo self::$debug ? "Filtering resources...\n" : ''; foreach ($this->resources() as $res) { echo self::$debug ? "\t" . $res->getUri() . "\n" : ''; $nonIdProps = array_diff($res->propertyUris(), array(RC::idProp())); $inNmsp = false; $ids = array(); foreach ($res->allResources(RC::idProp()) as $id) { $id = $id->getUri(); $ids[] = $id; $inNmsp = $inNmsp || strpos($id, $namespace) === 0; } if (count($ids) == 0) { echo self::$debug ? "\t\tskipping - no ids\n" : ''; } elseif ($this->fedora->isAcdhId($res->getUri())) { echo self::$debug ? "\t\tskipping - ACDH UUID\n" : ''; } elseif (count($nonIdProps) == 0 && $this->isIdElsewhere($res)) { echo self::$debug ? "\t\tskipping - single id assigned to another resource\n" : ''; } elseif (count($nonIdProps) == 0 && $singleOutNmsp !== MetadataCollection::CREATE && !$inNmsp) { echo self::$debug ? "\t\tskipping - onlyIds, outside namespace and mode == MetadataCollection::SKIP\n" : ''; } else { echo self::$debug ? "\t\tincluding\n" : ''; $result[] = $res; } } return $result; }
php
private function filterResources(string $namespace, int $singleOutNmsp): array { $result = array(); echo self::$debug ? "Filtering resources...\n" : ''; foreach ($this->resources() as $res) { echo self::$debug ? "\t" . $res->getUri() . "\n" : ''; $nonIdProps = array_diff($res->propertyUris(), array(RC::idProp())); $inNmsp = false; $ids = array(); foreach ($res->allResources(RC::idProp()) as $id) { $id = $id->getUri(); $ids[] = $id; $inNmsp = $inNmsp || strpos($id, $namespace) === 0; } if (count($ids) == 0) { echo self::$debug ? "\t\tskipping - no ids\n" : ''; } elseif ($this->fedora->isAcdhId($res->getUri())) { echo self::$debug ? "\t\tskipping - ACDH UUID\n" : ''; } elseif (count($nonIdProps) == 0 && $this->isIdElsewhere($res)) { echo self::$debug ? "\t\tskipping - single id assigned to another resource\n" : ''; } elseif (count($nonIdProps) == 0 && $singleOutNmsp !== MetadataCollection::CREATE && !$inNmsp) { echo self::$debug ? "\t\tskipping - onlyIds, outside namespace and mode == MetadataCollection::SKIP\n" : ''; } else { echo self::$debug ? "\t\tincluding\n" : ''; $result[] = $res; } } return $result; }
[ "private", "function", "filterResources", "(", "string", "$", "namespace", ",", "int", "$", "singleOutNmsp", ")", ":", "array", "{", "$", "result", "=", "array", "(", ")", ";", "echo", "self", "::", "$", "debug", "?", "\"Filtering resources...\\n\"", ":", "''", ";", "foreach", "(", "$", "this", "->", "resources", "(", ")", "as", "$", "res", ")", "{", "echo", "self", "::", "$", "debug", "?", "\"\\t\"", ".", "$", "res", "->", "getUri", "(", ")", ".", "\"\\n\"", ":", "''", ";", "$", "nonIdProps", "=", "array_diff", "(", "$", "res", "->", "propertyUris", "(", ")", ",", "array", "(", "RC", "::", "idProp", "(", ")", ")", ")", ";", "$", "inNmsp", "=", "false", ";", "$", "ids", "=", "array", "(", ")", ";", "foreach", "(", "$", "res", "->", "allResources", "(", "RC", "::", "idProp", "(", ")", ")", "as", "$", "id", ")", "{", "$", "id", "=", "$", "id", "->", "getUri", "(", ")", ";", "$", "ids", "[", "]", "=", "$", "id", ";", "$", "inNmsp", "=", "$", "inNmsp", "||", "strpos", "(", "$", "id", ",", "$", "namespace", ")", "===", "0", ";", "}", "if", "(", "count", "(", "$", "ids", ")", "==", "0", ")", "{", "echo", "self", "::", "$", "debug", "?", "\"\\t\\tskipping - no ids\\n\"", ":", "''", ";", "}", "elseif", "(", "$", "this", "->", "fedora", "->", "isAcdhId", "(", "$", "res", "->", "getUri", "(", ")", ")", ")", "{", "echo", "self", "::", "$", "debug", "?", "\"\\t\\tskipping - ACDH UUID\\n\"", ":", "''", ";", "}", "elseif", "(", "count", "(", "$", "nonIdProps", ")", "==", "0", "&&", "$", "this", "->", "isIdElsewhere", "(", "$", "res", ")", ")", "{", "echo", "self", "::", "$", "debug", "?", "\"\\t\\tskipping - single id assigned to another resource\\n\"", ":", "''", ";", "}", "elseif", "(", "count", "(", "$", "nonIdProps", ")", "==", "0", "&&", "$", "singleOutNmsp", "!==", "MetadataCollection", "::", "CREATE", "&&", "!", "$", "inNmsp", ")", "{", "echo", "self", "::", "$", "debug", "?", "\"\\t\\tskipping - onlyIds, outside namespace and mode == MetadataCollection::SKIP\\n\"", ":", "''", ";", "}", "else", "{", "echo", "self", "::", "$", "debug", "?", "\"\\t\\tincluding\\n\"", ":", "''", ";", "$", "result", "[", "]", "=", "$", "res", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns set of resources to be imported skipping all other. @param string $namespace repository resources will be created for all resources in this namespace @param int $singleOutNmsp should repository resources be created representing URIs outside $namespace (MetadataCollection::SKIP or MetadataCollection::CREATE) @return array
[ "Returns", "set", "of", "resources", "to", "be", "imported", "skipping", "all", "other", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/MetadataCollection.php#L235-L266
29,741
acdh-oeaw/repo-php-util
src/acdhOeaw/util/MetadataCollection.php
MetadataCollection.promoteUrisToIds
private function promoteUrisToIds() { echo self::$debug ? "Promoting URIs to ids...\n" : ''; foreach ($this->resources() as $i) { if (!$i->isBNode()) { echo self::$debug ? "\t" . $i->getUri() . "\n" : ''; $i->addResource(RC::idProp(), $i->getUri()); } } }
php
private function promoteUrisToIds() { echo self::$debug ? "Promoting URIs to ids...\n" : ''; foreach ($this->resources() as $i) { if (!$i->isBNode()) { echo self::$debug ? "\t" . $i->getUri() . "\n" : ''; $i->addResource(RC::idProp(), $i->getUri()); } } }
[ "private", "function", "promoteUrisToIds", "(", ")", "{", "echo", "self", "::", "$", "debug", "?", "\"Promoting URIs to ids...\\n\"", ":", "''", ";", "foreach", "(", "$", "this", "->", "resources", "(", ")", "as", "$", "i", ")", "{", "if", "(", "!", "$", "i", "->", "isBNode", "(", ")", ")", "{", "echo", "self", "::", "$", "debug", "?", "\"\\t\"", ".", "$", "i", "->", "getUri", "(", ")", ".", "\"\\n\"", ":", "''", ";", "$", "i", "->", "addResource", "(", "RC", "::", "idProp", "(", ")", ",", "$", "i", "->", "getUri", "(", ")", ")", ";", "}", "}", "}" ]
Promotes subjects being fully qualified URLs to ids.
[ "Promotes", "subjects", "being", "fully", "qualified", "URLs", "to", "ids", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/MetadataCollection.php#L383-L391
29,742
acdh-oeaw/repo-php-util
src/acdhOeaw/util/MetadataCollection.php
MetadataCollection.sanitizeResource
private function sanitizeResource(Resource $res, string $namespace): Resource { $nonIdProps = array_diff($res->propertyUris(), array(RC::idProp())); if (count($nonIdProps) == 0) { // don't do anything when it's purely-id resource return $res; } $this->fedora->fixMetadataReferences($res); if ($this->containsWrongRefs($res, $namespace)) { echo $res->copy()->getGraph()->serialise('ntriples') . "\n"; throw new InvalidArgumentException('resource contains references to blank nodes'); } if (count($res->allLiterals(RC::titleProp())) == 0) { $res->addLiteral(RC::titleProp(), $res->getResource(RC::idProp())); } if ($res->isA('http://xmlns.com/foaf/0.1/Person') || $res->isA('http://xmlns.com/foaf/0.1/Agent')) { $res = self::makeAgent($res); } if ($this->resource !== null) { $res->addResource(RC::relProp(), $this->resource->getId()); } return $res; }
php
private function sanitizeResource(Resource $res, string $namespace): Resource { $nonIdProps = array_diff($res->propertyUris(), array(RC::idProp())); if (count($nonIdProps) == 0) { // don't do anything when it's purely-id resource return $res; } $this->fedora->fixMetadataReferences($res); if ($this->containsWrongRefs($res, $namespace)) { echo $res->copy()->getGraph()->serialise('ntriples') . "\n"; throw new InvalidArgumentException('resource contains references to blank nodes'); } if (count($res->allLiterals(RC::titleProp())) == 0) { $res->addLiteral(RC::titleProp(), $res->getResource(RC::idProp())); } if ($res->isA('http://xmlns.com/foaf/0.1/Person') || $res->isA('http://xmlns.com/foaf/0.1/Agent')) { $res = self::makeAgent($res); } if ($this->resource !== null) { $res->addResource(RC::relProp(), $this->resource->getId()); } return $res; }
[ "private", "function", "sanitizeResource", "(", "Resource", "$", "res", ",", "string", "$", "namespace", ")", ":", "Resource", "{", "$", "nonIdProps", "=", "array_diff", "(", "$", "res", "->", "propertyUris", "(", ")", ",", "array", "(", "RC", "::", "idProp", "(", ")", ")", ")", ";", "if", "(", "count", "(", "$", "nonIdProps", ")", "==", "0", ")", "{", "// don't do anything when it's purely-id resource", "return", "$", "res", ";", "}", "$", "this", "->", "fedora", "->", "fixMetadataReferences", "(", "$", "res", ")", ";", "if", "(", "$", "this", "->", "containsWrongRefs", "(", "$", "res", ",", "$", "namespace", ")", ")", "{", "echo", "$", "res", "->", "copy", "(", ")", "->", "getGraph", "(", ")", "->", "serialise", "(", "'ntriples'", ")", ".", "\"\\n\"", ";", "throw", "new", "InvalidArgumentException", "(", "'resource contains references to blank nodes'", ")", ";", "}", "if", "(", "count", "(", "$", "res", "->", "allLiterals", "(", "RC", "::", "titleProp", "(", ")", ")", ")", "==", "0", ")", "{", "$", "res", "->", "addLiteral", "(", "RC", "::", "titleProp", "(", ")", ",", "$", "res", "->", "getResource", "(", "RC", "::", "idProp", "(", ")", ")", ")", ";", "}", "if", "(", "$", "res", "->", "isA", "(", "'http://xmlns.com/foaf/0.1/Person'", ")", "||", "$", "res", "->", "isA", "(", "'http://xmlns.com/foaf/0.1/Agent'", ")", ")", "{", "$", "res", "=", "self", "::", "makeAgent", "(", "$", "res", ")", ";", "}", "if", "(", "$", "this", "->", "resource", "!==", "null", ")", "{", "$", "res", "->", "addResource", "(", "RC", "::", "relProp", "(", ")", ",", "$", "this", "->", "resource", "->", "getId", "(", ")", ")", ";", "}", "return", "$", "res", ";", "}" ]
Cleans up resource metadata. @param Resource $res @param string $namespace @return Resource @throws InvalidArgumentException
[ "Cleans", "up", "resource", "metadata", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/MetadataCollection.php#L401-L428
29,743
acdh-oeaw/repo-php-util
src/acdhOeaw/util/MetadataCollection.php
MetadataCollection.removeLiteralIds
private function removeLiteralIds() { echo self::$debug ? "Removing literal ids...\n" : ""; foreach ($this->resources() as $i) { foreach ($i->allLiterals(RC::idProp()) as $j) { $i->delete(RC::idProp(), $j); if (self::$debug) { echo "\tremoved " . $j . " from " . $i->getUri() . "\n"; } } } }
php
private function removeLiteralIds() { echo self::$debug ? "Removing literal ids...\n" : ""; foreach ($this->resources() as $i) { foreach ($i->allLiterals(RC::idProp()) as $j) { $i->delete(RC::idProp(), $j); if (self::$debug) { echo "\tremoved " . $j . " from " . $i->getUri() . "\n"; } } } }
[ "private", "function", "removeLiteralIds", "(", ")", "{", "echo", "self", "::", "$", "debug", "?", "\"Removing literal ids...\\n\"", ":", "\"\"", ";", "foreach", "(", "$", "this", "->", "resources", "(", ")", "as", "$", "i", ")", "{", "foreach", "(", "$", "i", "->", "allLiterals", "(", "RC", "::", "idProp", "(", ")", ")", "as", "$", "j", ")", "{", "$", "i", "->", "delete", "(", "RC", "::", "idProp", "(", ")", ",", "$", "j", ")", ";", "if", "(", "self", "::", "$", "debug", ")", "{", "echo", "\"\\tremoved \"", ".", "$", "j", ".", "\" from \"", ".", "$", "i", "->", "getUri", "(", ")", ".", "\"\\n\"", ";", "}", "}", "}", "}" ]
Removes literal ids from the graph.
[ "Removes", "literal", "ids", "from", "the", "graph", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/MetadataCollection.php#L433-L444
29,744
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAcl.php
WebAcl.save
public function save() { foreach ($this->resRules as $i) { $i->save($this->res->getAclUrl()); } }
php
public function save() { foreach ($this->resRules as $i) { $i->save($this->res->getAclUrl()); } }
[ "public", "function", "save", "(", ")", "{", "foreach", "(", "$", "this", "->", "resRules", "as", "$", "i", ")", "{", "$", "i", "->", "save", "(", "$", "this", "->", "res", "->", "getAclUrl", "(", ")", ")", ";", "}", "}" ]
Manually triggers synchronization of all stored `WebAclRule` objects with the Fedora. @see setAutocommit()
[ "Manually", "triggers", "synchronization", "of", "all", "stored", "WebAclRule", "objects", "with", "the", "Fedora", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAcl.php#L203-L207
29,745
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAcl.php
WebAcl.revokeAll
public function revokeAll(int $mode = WebAclRule::READ): WebAcl { WebAclRule::checkMode($mode); if ($mode == WebAclRule::WRITE) { foreach ($this->resRules as $i) { $i->setMode(WebAclRule::READ); if (self::$autosave) { $i->save($this->res->getAclUrl()); } } } else { foreach ($this->resRules as $i) { $i->delete(true); } $this->resRules = array(); } return $this; }
php
public function revokeAll(int $mode = WebAclRule::READ): WebAcl { WebAclRule::checkMode($mode); if ($mode == WebAclRule::WRITE) { foreach ($this->resRules as $i) { $i->setMode(WebAclRule::READ); if (self::$autosave) { $i->save($this->res->getAclUrl()); } } } else { foreach ($this->resRules as $i) { $i->delete(true); } $this->resRules = array(); } return $this; }
[ "public", "function", "revokeAll", "(", "int", "$", "mode", "=", "WebAclRule", "::", "READ", ")", ":", "WebAcl", "{", "WebAclRule", "::", "checkMode", "(", "$", "mode", ")", ";", "if", "(", "$", "mode", "==", "WebAclRule", "::", "WRITE", ")", "{", "foreach", "(", "$", "this", "->", "resRules", "as", "$", "i", ")", "{", "$", "i", "->", "setMode", "(", "WebAclRule", "::", "READ", ")", ";", "if", "(", "self", "::", "$", "autosave", ")", "{", "$", "i", "->", "save", "(", "$", "this", "->", "res", "->", "getAclUrl", "(", ")", ")", ";", "}", "}", "}", "else", "{", "foreach", "(", "$", "this", "->", "resRules", "as", "$", "i", ")", "{", "$", "i", "->", "delete", "(", "true", ")", ";", "}", "$", "this", "->", "resRules", "=", "array", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Revokes privileges from all users, groups and classes for a given Fedora resource. Only rules directly targeting the given resource are removed. Rules inherited from Fedora parents sharing the same ACL are not affected. If `$mode` equals to `WebAclRule::WRITE` all privileges are limited to `WebAclRule::READ`. If `$mode` equals to `WebAclRule::READ` all privileges are revoked. @param int $mode WebAclRule::READ or WebAclRule::WRITE @return \acdhOeaw\fedora\acl\WebAcl
[ "Revokes", "privileges", "from", "all", "users", "groups", "and", "classes", "for", "a", "given", "Fedora", "resource", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAcl.php#L223-L241
29,746
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAcl.php
WebAcl.getRules
public function getRules(bool $inherited = true): array { $ret = array(); foreach ($this->resRules as $i) { $ret[] = $i->getData(); } if ($inherited) { foreach ($this->extRules as $i) { $ret[] = $i->getData(); } } return $ret; }
php
public function getRules(bool $inherited = true): array { $ret = array(); foreach ($this->resRules as $i) { $ret[] = $i->getData(); } if ($inherited) { foreach ($this->extRules as $i) { $ret[] = $i->getData(); } } return $ret; }
[ "public", "function", "getRules", "(", "bool", "$", "inherited", "=", "true", ")", ":", "array", "{", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "resRules", "as", "$", "i", ")", "{", "$", "ret", "[", "]", "=", "$", "i", "->", "getData", "(", ")", ";", "}", "if", "(", "$", "inherited", ")", "{", "foreach", "(", "$", "this", "->", "extRules", "as", "$", "i", ")", "{", "$", "ret", "[", "]", "=", "$", "i", "->", "getData", "(", ")", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Fetches an array of `WebAclRule` objects containing access rules for a corresponding Fedora resource. @param bool $inherited should rules inherited from parent (in Fedora terms) resources be taken into account? @return array
[ "Fetches", "an", "array", "of", "WebAclRule", "objects", "containing", "access", "rules", "for", "a", "corresponding", "Fedora", "resource", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAcl.php#L376-L387
29,747
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAcl.php
WebAcl.reload
public function reload(): WebAcl { $fedora = $this->res->getFedora(); $resUri = $this->res->getUri(true); $aclUri = $this->res->getAclUrl(); $this->resRules = []; $this->extRules = []; if ($aclUri) { $query = new SimpleQuery(self::QUERY, [$resUri, $aclUri]); $results = $fedora->runQuery($query); $rules = self::initRules($results, $fedora, $aclUri); foreach ($rules as $r) { if ($r->hasResource($resUri)) { $this->resRules[] = $r; } else { $this->extRules[] = $r; } } } return $this; }
php
public function reload(): WebAcl { $fedora = $this->res->getFedora(); $resUri = $this->res->getUri(true); $aclUri = $this->res->getAclUrl(); $this->resRules = []; $this->extRules = []; if ($aclUri) { $query = new SimpleQuery(self::QUERY, [$resUri, $aclUri]); $results = $fedora->runQuery($query); $rules = self::initRules($results, $fedora, $aclUri); foreach ($rules as $r) { if ($r->hasResource($resUri)) { $this->resRules[] = $r; } else { $this->extRules[] = $r; } } } return $this; }
[ "public", "function", "reload", "(", ")", ":", "WebAcl", "{", "$", "fedora", "=", "$", "this", "->", "res", "->", "getFedora", "(", ")", ";", "$", "resUri", "=", "$", "this", "->", "res", "->", "getUri", "(", "true", ")", ";", "$", "aclUri", "=", "$", "this", "->", "res", "->", "getAclUrl", "(", ")", ";", "$", "this", "->", "resRules", "=", "[", "]", ";", "$", "this", "->", "extRules", "=", "[", "]", ";", "if", "(", "$", "aclUri", ")", "{", "$", "query", "=", "new", "SimpleQuery", "(", "self", "::", "QUERY", ",", "[", "$", "resUri", ",", "$", "aclUri", "]", ")", ";", "$", "results", "=", "$", "fedora", "->", "runQuery", "(", "$", "query", ")", ";", "$", "rules", "=", "self", "::", "initRules", "(", "$", "results", ",", "$", "fedora", ",", "$", "aclUri", ")", ";", "foreach", "(", "$", "rules", "as", "$", "r", ")", "{", "if", "(", "$", "r", "->", "hasResource", "(", "$", "resUri", ")", ")", "{", "$", "this", "->", "resRules", "[", "]", "=", "$", "r", ";", "}", "else", "{", "$", "this", "->", "extRules", "[", "]", "=", "$", "r", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Reloads access rules by quering a triplestore. See class description for use cases.
[ "Reloads", "access", "rules", "by", "quering", "a", "triplestore", ".", "See", "class", "description", "for", "use", "cases", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAcl.php#L393-L413
29,748
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAcl.php
WebAcl.createAcl
public function createAcl(): WebAcl { $resMeta = $this->res->getMetadata(true); $acls = $resMeta->allResources(self::ACL_LINK_PROP); if (count($acls) > 1) { throw new RuntimeException('Resource has many ACLs'); } else if (count($acls) > 0) { return $this; } try { $location = RC::get('fedoraAclUri'); } catch (InvalidArgumentException $ex) { $location = '/'; } $aclMeta = (new Graph())->resource('.'); $aclMeta->addType(self::ACL_CLASS); $aclMeta->addLiteral(RC::titleProp(), 'ACL'); $id = preg_replace('|^[^:]+|', 'acl', $this->res->getUri(true)); $aclMeta->addResource(RC::idProp(), $id); // Link to ACL is applied after the transaction commit, so we need // a separate transaction not to affect the current one // As a side effect the resource for which an ACL is created has to // persistently exist in the repository already! $fedoraTmp = clone($this->res->getFedora()); $fedoraTmp->__clearCache(); $fedoraTmp->begin(); $aclRes = $fedoraTmp->createResource($aclMeta, '', $location, 'POST'); $resMeta->addResource(self::ACL_LINK_PROP, $aclRes->getUri(true)); try { $resTmp = $fedoraTmp->getResourceByUri($this->res->getUri()); $resTmp->setMetadata($resMeta); $resTmp->updateMetadata(); $fedoraTmp->commit(); } catch (NotFound $e) { $fedoraTmp->rollback(); } //sleep(1); //TODO $this->res->getMetadata(true); if ($this->res->getAclUrl() !== $aclRes->getUri(true)) { // second try for binary resources which are not handled properly by Fedora if ($this->res->getAclUrl(true) !== $aclRes->getUri(true)) { throw new RuntimeException('ACL creation failed'); } } foreach ($this->resRules as $h => $i) { $i->move($aclRes->getUri(true) . '/' . $h); } return $this; }
php
public function createAcl(): WebAcl { $resMeta = $this->res->getMetadata(true); $acls = $resMeta->allResources(self::ACL_LINK_PROP); if (count($acls) > 1) { throw new RuntimeException('Resource has many ACLs'); } else if (count($acls) > 0) { return $this; } try { $location = RC::get('fedoraAclUri'); } catch (InvalidArgumentException $ex) { $location = '/'; } $aclMeta = (new Graph())->resource('.'); $aclMeta->addType(self::ACL_CLASS); $aclMeta->addLiteral(RC::titleProp(), 'ACL'); $id = preg_replace('|^[^:]+|', 'acl', $this->res->getUri(true)); $aclMeta->addResource(RC::idProp(), $id); // Link to ACL is applied after the transaction commit, so we need // a separate transaction not to affect the current one // As a side effect the resource for which an ACL is created has to // persistently exist in the repository already! $fedoraTmp = clone($this->res->getFedora()); $fedoraTmp->__clearCache(); $fedoraTmp->begin(); $aclRes = $fedoraTmp->createResource($aclMeta, '', $location, 'POST'); $resMeta->addResource(self::ACL_LINK_PROP, $aclRes->getUri(true)); try { $resTmp = $fedoraTmp->getResourceByUri($this->res->getUri()); $resTmp->setMetadata($resMeta); $resTmp->updateMetadata(); $fedoraTmp->commit(); } catch (NotFound $e) { $fedoraTmp->rollback(); } //sleep(1); //TODO $this->res->getMetadata(true); if ($this->res->getAclUrl() !== $aclRes->getUri(true)) { // second try for binary resources which are not handled properly by Fedora if ($this->res->getAclUrl(true) !== $aclRes->getUri(true)) { throw new RuntimeException('ACL creation failed'); } } foreach ($this->resRules as $h => $i) { $i->move($aclRes->getUri(true) . '/' . $h); } return $this; }
[ "public", "function", "createAcl", "(", ")", ":", "WebAcl", "{", "$", "resMeta", "=", "$", "this", "->", "res", "->", "getMetadata", "(", "true", ")", ";", "$", "acls", "=", "$", "resMeta", "->", "allResources", "(", "self", "::", "ACL_LINK_PROP", ")", ";", "if", "(", "count", "(", "$", "acls", ")", ">", "1", ")", "{", "throw", "new", "RuntimeException", "(", "'Resource has many ACLs'", ")", ";", "}", "else", "if", "(", "count", "(", "$", "acls", ")", ">", "0", ")", "{", "return", "$", "this", ";", "}", "try", "{", "$", "location", "=", "RC", "::", "get", "(", "'fedoraAclUri'", ")", ";", "}", "catch", "(", "InvalidArgumentException", "$", "ex", ")", "{", "$", "location", "=", "'/'", ";", "}", "$", "aclMeta", "=", "(", "new", "Graph", "(", ")", ")", "->", "resource", "(", "'.'", ")", ";", "$", "aclMeta", "->", "addType", "(", "self", "::", "ACL_CLASS", ")", ";", "$", "aclMeta", "->", "addLiteral", "(", "RC", "::", "titleProp", "(", ")", ",", "'ACL'", ")", ";", "$", "id", "=", "preg_replace", "(", "'|^[^:]+|'", ",", "'acl'", ",", "$", "this", "->", "res", "->", "getUri", "(", "true", ")", ")", ";", "$", "aclMeta", "->", "addResource", "(", "RC", "::", "idProp", "(", ")", ",", "$", "id", ")", ";", "// Link to ACL is applied after the transaction commit, so we need ", "// a separate transaction not to affect the current one", "// As a side effect the resource for which an ACL is created has to ", "// persistently exist in the repository already!", "$", "fedoraTmp", "=", "clone", "(", "$", "this", "->", "res", "->", "getFedora", "(", ")", ")", ";", "$", "fedoraTmp", "->", "__clearCache", "(", ")", ";", "$", "fedoraTmp", "->", "begin", "(", ")", ";", "$", "aclRes", "=", "$", "fedoraTmp", "->", "createResource", "(", "$", "aclMeta", ",", "''", ",", "$", "location", ",", "'POST'", ")", ";", "$", "resMeta", "->", "addResource", "(", "self", "::", "ACL_LINK_PROP", ",", "$", "aclRes", "->", "getUri", "(", "true", ")", ")", ";", "try", "{", "$", "resTmp", "=", "$", "fedoraTmp", "->", "getResourceByUri", "(", "$", "this", "->", "res", "->", "getUri", "(", ")", ")", ";", "$", "resTmp", "->", "setMetadata", "(", "$", "resMeta", ")", ";", "$", "resTmp", "->", "updateMetadata", "(", ")", ";", "$", "fedoraTmp", "->", "commit", "(", ")", ";", "}", "catch", "(", "NotFound", "$", "e", ")", "{", "$", "fedoraTmp", "->", "rollback", "(", ")", ";", "}", "//sleep(1); //TODO", "$", "this", "->", "res", "->", "getMetadata", "(", "true", ")", ";", "if", "(", "$", "this", "->", "res", "->", "getAclUrl", "(", ")", "!==", "$", "aclRes", "->", "getUri", "(", "true", ")", ")", "{", "// second try for binary resources which are not handled properly by Fedora", "if", "(", "$", "this", "->", "res", "->", "getAclUrl", "(", "true", ")", "!==", "$", "aclRes", "->", "getUri", "(", "true", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'ACL creation failed'", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "resRules", "as", "$", "h", "=>", "$", "i", ")", "{", "$", "i", "->", "move", "(", "$", "aclRes", "->", "getUri", "(", "true", ")", ".", "'/'", ".", "$", "h", ")", ";", "}", "return", "$", "this", ";", "}" ]
Creates an ACL attached directly to a given resource. All rules describing resource from ACL currently in effect are automatically moved to the newly created ACL. Resource has to permanently exist in the repository for operation to succeed (you can not create a resource's ACL within the same transaction a resource was created). If it is not a case, a `NotFound` exception is rised. If an ACL attached directly to the resource already exists, nothing happens. @throws \RuntimeException
[ "Creates", "an", "ACL", "attached", "directly", "to", "a", "given", "resource", ".", "All", "rules", "describing", "resource", "from", "ACL", "currently", "in", "effect", "are", "automatically", "moved", "to", "the", "newly", "created", "ACL", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAcl.php#L429-L482
29,749
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAcl.php
WebAcl.deleteAcl
public function deleteAcl(): WebAcl { $fedora = $this->res->getFedora(); $resMeta = $this->res->getMetadata(); $acls = $resMeta->allResources(self::ACL_LINK_PROP); if (count($acls) == 0) { throw new NotFound(); } foreach ($acls as $i) { $aclRes = $fedora->getResourceByUri($i); $aclMeta = $aclRes->getMetadata(); foreach ($aclMeta->allResources(self::ACL_CHILDREN_PROP) as $j) { $fedora->getResourceByUri($j->getUri())->delete(); } $aclRes->getMetadata(true); // notify children were deleted $aclRes->delete(true, false); } $resMeta->deleteResource(self::ACL_LINK_PROP); $this->res->setMetadata($resMeta); $this->res->updateMetadata(); $this->res->getAclUrl(true); $this->resRules = $this->extRules = []; return $this; }
php
public function deleteAcl(): WebAcl { $fedora = $this->res->getFedora(); $resMeta = $this->res->getMetadata(); $acls = $resMeta->allResources(self::ACL_LINK_PROP); if (count($acls) == 0) { throw new NotFound(); } foreach ($acls as $i) { $aclRes = $fedora->getResourceByUri($i); $aclMeta = $aclRes->getMetadata(); foreach ($aclMeta->allResources(self::ACL_CHILDREN_PROP) as $j) { $fedora->getResourceByUri($j->getUri())->delete(); } $aclRes->getMetadata(true); // notify children were deleted $aclRes->delete(true, false); } $resMeta->deleteResource(self::ACL_LINK_PROP); $this->res->setMetadata($resMeta); $this->res->updateMetadata(); $this->res->getAclUrl(true); $this->resRules = $this->extRules = []; return $this; }
[ "public", "function", "deleteAcl", "(", ")", ":", "WebAcl", "{", "$", "fedora", "=", "$", "this", "->", "res", "->", "getFedora", "(", ")", ";", "$", "resMeta", "=", "$", "this", "->", "res", "->", "getMetadata", "(", ")", ";", "$", "acls", "=", "$", "resMeta", "->", "allResources", "(", "self", "::", "ACL_LINK_PROP", ")", ";", "if", "(", "count", "(", "$", "acls", ")", "==", "0", ")", "{", "throw", "new", "NotFound", "(", ")", ";", "}", "foreach", "(", "$", "acls", "as", "$", "i", ")", "{", "$", "aclRes", "=", "$", "fedora", "->", "getResourceByUri", "(", "$", "i", ")", ";", "$", "aclMeta", "=", "$", "aclRes", "->", "getMetadata", "(", ")", ";", "foreach", "(", "$", "aclMeta", "->", "allResources", "(", "self", "::", "ACL_CHILDREN_PROP", ")", "as", "$", "j", ")", "{", "$", "fedora", "->", "getResourceByUri", "(", "$", "j", "->", "getUri", "(", ")", ")", "->", "delete", "(", ")", ";", "}", "$", "aclRes", "->", "getMetadata", "(", "true", ")", ";", "// notify children were deleted", "$", "aclRes", "->", "delete", "(", "true", ",", "false", ")", ";", "}", "$", "resMeta", "->", "deleteResource", "(", "self", "::", "ACL_LINK_PROP", ")", ";", "$", "this", "->", "res", "->", "setMetadata", "(", "$", "resMeta", ")", ";", "$", "this", "->", "res", "->", "updateMetadata", "(", ")", ";", "$", "this", "->", "res", "->", "getAclUrl", "(", "true", ")", ";", "$", "this", "->", "resRules", "=", "$", "this", "->", "extRules", "=", "[", "]", ";", "return", "$", "this", ";", "}" ]
Removes ACL directly attached to this resource. If there is no such ACL, error is thrown. @return \acdhOeaw\fedora\acl\WebAcl @throws NotFound
[ "Removes", "ACL", "directly", "attached", "to", "this", "resource", ".", "If", "there", "is", "no", "such", "ACL", "error", "is", "thrown", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAcl.php#L490-L514
29,750
locomotivemtl/charcoal-ui
src/Charcoal/Ui/Dashboard/DashboardTrait.php
DashboardTrait.setWidgetBuilder
protected function setWidgetBuilder($builder) { if (is_object($builder)) { $this->widgetBuilder = $builder; } else { throw new InvalidArgumentException( sprintf( 'Argument must be a widget builder, %s given', (is_object($builder) ? get_class($builder) : gettype($builder)) ) ); } return $this; }
php
protected function setWidgetBuilder($builder) { if (is_object($builder)) { $this->widgetBuilder = $builder; } else { throw new InvalidArgumentException( sprintf( 'Argument must be a widget builder, %s given', (is_object($builder) ? get_class($builder) : gettype($builder)) ) ); } return $this; }
[ "protected", "function", "setWidgetBuilder", "(", "$", "builder", ")", "{", "if", "(", "is_object", "(", "$", "builder", ")", ")", "{", "$", "this", "->", "widgetBuilder", "=", "$", "builder", ";", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Argument must be a widget builder, %s given'", ",", "(", "is_object", "(", "$", "builder", ")", "?", "get_class", "(", "$", "builder", ")", ":", "gettype", "(", "$", "builder", ")", ")", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set a widget builder. @param object $builder The builder to create customized widget objects. @throws InvalidArgumentException If the argument is not a widget builder. @return DashboardInterface Chainable
[ "Set", "a", "widget", "builder", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/Dashboard/DashboardTrait.php#L59-L73
29,751
locomotivemtl/charcoal-ui
src/Charcoal/Ui/Dashboard/DashboardTrait.php
DashboardTrait.setWidgets
public function setWidgets(array $widgets) { $this->widgets = []; foreach ($widgets as $widgetIdent => $widget) { $this->addWidget($widgetIdent, $widget); } return $this; }
php
public function setWidgets(array $widgets) { $this->widgets = []; foreach ($widgets as $widgetIdent => $widget) { $this->addWidget($widgetIdent, $widget); } return $this; }
[ "public", "function", "setWidgets", "(", "array", "$", "widgets", ")", "{", "$", "this", "->", "widgets", "=", "[", "]", ";", "foreach", "(", "$", "widgets", "as", "$", "widgetIdent", "=>", "$", "widget", ")", "{", "$", "this", "->", "addWidget", "(", "$", "widgetIdent", ",", "$", "widget", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the dashboard's widgets. @param array $widgets A collection of widgets. @return DashboardInterface Chainable
[ "Set", "the", "dashboard", "s", "widgets", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/Dashboard/DashboardTrait.php#L111-L120
29,752
locomotivemtl/charcoal-ui
src/Charcoal/Ui/Dashboard/DashboardTrait.php
DashboardTrait.addWidget
public function addWidget($widgetIdent, $widget) { if (!is_string($widgetIdent)) { throw new InvalidArgumentException( 'Widget identifier needs to be a string' ); } if ($widget instanceof UiItemInterface) { $this->widgets[$widgetIdent] = $widget; } elseif (is_array($widget)) { if (!isset($widget['ident'])) { $widget['ident'] = $widgetIdent; } $w = $this->widgetBuilder->build($widget); $this->widgets[$widgetIdent] = $w; } else { throw new InvalidArgumentException( 'Can not add widget: Invalid Widget.' ); } return $this; }
php
public function addWidget($widgetIdent, $widget) { if (!is_string($widgetIdent)) { throw new InvalidArgumentException( 'Widget identifier needs to be a string' ); } if ($widget instanceof UiItemInterface) { $this->widgets[$widgetIdent] = $widget; } elseif (is_array($widget)) { if (!isset($widget['ident'])) { $widget['ident'] = $widgetIdent; } $w = $this->widgetBuilder->build($widget); $this->widgets[$widgetIdent] = $w; } else { throw new InvalidArgumentException( 'Can not add widget: Invalid Widget.' ); } return $this; }
[ "public", "function", "addWidget", "(", "$", "widgetIdent", ",", "$", "widget", ")", "{", "if", "(", "!", "is_string", "(", "$", "widgetIdent", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Widget identifier needs to be a string'", ")", ";", "}", "if", "(", "$", "widget", "instanceof", "UiItemInterface", ")", "{", "$", "this", "->", "widgets", "[", "$", "widgetIdent", "]", "=", "$", "widget", ";", "}", "elseif", "(", "is_array", "(", "$", "widget", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "widget", "[", "'ident'", "]", ")", ")", "{", "$", "widget", "[", "'ident'", "]", "=", "$", "widgetIdent", ";", "}", "$", "w", "=", "$", "this", "->", "widgetBuilder", "->", "build", "(", "$", "widget", ")", ";", "$", "this", "->", "widgets", "[", "$", "widgetIdent", "]", "=", "$", "w", ";", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'Can not add widget: Invalid Widget.'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add a widget to the dashboard. If a widget with the same $widgetIdent already exists, it will be overridden. @param string $widgetIdent The widget identifier. @param UiItemInterface|array $widget The widget object or structure. @throws InvalidArgumentException If the widget is invalid. @return DashboardInterface Chainable
[ "Add", "a", "widget", "to", "the", "dashboard", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/Dashboard/DashboardTrait.php#L132-L157
29,753
polyfony-inc/polyfony
Private/Polyfony/Keys.php
Keys.generate
public static function generate($mixed=null) { // create a sha1 signature of the array with a salt $hash = hash( Config::get('keys', 'algo'), json_encode(array($mixed, Config::get('keys', 'salt')), JSON_NUMERIC_CHECK) ); // get last 10 and first 10 chars together, convert to uppercase, return the key return(strtoupper(substr($hash, -10) . substr($hash, 0, 10))); }
php
public static function generate($mixed=null) { // create a sha1 signature of the array with a salt $hash = hash( Config::get('keys', 'algo'), json_encode(array($mixed, Config::get('keys', 'salt')), JSON_NUMERIC_CHECK) ); // get last 10 and first 10 chars together, convert to uppercase, return the key return(strtoupper(substr($hash, -10) . substr($hash, 0, 10))); }
[ "public", "static", "function", "generate", "(", "$", "mixed", "=", "null", ")", "{", "// create a sha1 signature of the array with a salt", "$", "hash", "=", "hash", "(", "Config", "::", "get", "(", "'keys'", ",", "'algo'", ")", ",", "json_encode", "(", "array", "(", "$", "mixed", ",", "Config", "::", "get", "(", "'keys'", ",", "'salt'", ")", ")", ",", "JSON_NUMERIC_CHECK", ")", ")", ";", "// get last 10 and first 10 chars together, convert to uppercase, return the key", "return", "(", "strtoupper", "(", "substr", "(", "$", "hash", ",", "-", "10", ")", ".", "substr", "(", "$", "hash", ",", "0", ",", "10", ")", ")", ")", ";", "}" ]
generate a key
[ "generate", "a", "key" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Keys.php#L8-L16
29,754
polyfony-inc/polyfony
Private/Polyfony/Keys.php
Keys.compare
public static function compare($key=null, $mixed=null) { // if no key is provided if(!$key || strlen($key) != 20) { // return false return(false); } // if keys do match return(self::generate($mixed) == $key ?: false); }
php
public static function compare($key=null, $mixed=null) { // if no key is provided if(!$key || strlen($key) != 20) { // return false return(false); } // if keys do match return(self::generate($mixed) == $key ?: false); }
[ "public", "static", "function", "compare", "(", "$", "key", "=", "null", ",", "$", "mixed", "=", "null", ")", "{", "// if no key is provided", "if", "(", "!", "$", "key", "||", "strlen", "(", "$", "key", ")", "!=", "20", ")", "{", "// return false", "return", "(", "false", ")", ";", "}", "// if keys do match", "return", "(", "self", "::", "generate", "(", "$", "mixed", ")", "==", "$", "key", "?", ":", "false", ")", ";", "}" ]
compare a key with a new dynamically generated one
[ "compare", "a", "key", "with", "a", "new", "dynamically", "generated", "one" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Keys.php#L19-L27
29,755
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Services/IdentRequestsService.php
IdentRequestsService.process
private function process(IdentRequest &$request) { if (isset($request->person)) { foreach ($request->person as $p) { $contact = $p->contact; if (!empty($contact) && !empty($contact->picture)) { $contact->pictureObject = $this->initMediaResource($contact->picture); } } } }
php
private function process(IdentRequest &$request) { if (isset($request->person)) { foreach ($request->person as $p) { $contact = $p->contact; if (!empty($contact) && !empty($contact->picture)) { $contact->pictureObject = $this->initMediaResource($contact->picture); } } } }
[ "private", "function", "process", "(", "IdentRequest", "&", "$", "request", ")", "{", "if", "(", "isset", "(", "$", "request", "->", "person", ")", ")", "{", "foreach", "(", "$", "request", "->", "person", "as", "$", "p", ")", "{", "$", "contact", "=", "$", "p", "->", "contact", ";", "if", "(", "!", "empty", "(", "$", "contact", ")", "&&", "!", "empty", "(", "$", "contact", "->", "picture", ")", ")", "{", "$", "contact", "->", "pictureObject", "=", "$", "this", "->", "initMediaResource", "(", "$", "contact", "->", "picture", ")", ";", "}", "}", "}", "}" ]
Handles proper contact picture initialization after retrieval of a ident request. @param IdentRequest $request
[ "Handles", "proper", "contact", "picture", "initialization", "after", "retrieval", "of", "a", "ident", "request", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Services/IdentRequestsService.php#L42-L52
29,756
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/dissemination/Service.php
Service.addParameter
public function addParameter(string $name, string $defaultValue = '', string $rdfProperty = '_') { $id = $this->getId() . '/param/' . $name; $this->params[] = new Parameter( $this->fedora, $id, $this, $name, $defaultValue, $rdfProperty ); }
php
public function addParameter(string $name, string $defaultValue = '', string $rdfProperty = '_') { $id = $this->getId() . '/param/' . $name; $this->params[] = new Parameter( $this->fedora, $id, $this, $name, $defaultValue, $rdfProperty ); }
[ "public", "function", "addParameter", "(", "string", "$", "name", ",", "string", "$", "defaultValue", "=", "''", ",", "string", "$", "rdfProperty", "=", "'_'", ")", "{", "$", "id", "=", "$", "this", "->", "getId", "(", ")", ".", "'/param/'", ".", "$", "name", ";", "$", "this", "->", "params", "[", "]", "=", "new", "Parameter", "(", "$", "this", "->", "fedora", ",", "$", "id", ",", "$", "this", ",", "$", "name", ",", "$", "defaultValue", ",", "$", "rdfProperty", ")", ";", "}" ]
Defines a dissemination service parameter. @param string $name parameter name @param string $defaultValue default parameter value @param string $rdfProperty RDF property holding parameter value in resources' metadata
[ "Defines", "a", "dissemination", "service", "parameter", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/dissemination/Service.php#L146-L152
29,757
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/dissemination/Service.php
Service.addMatch
public function addMatch(string $property, string $value, bool $required) { $id = $this->getid() . '/match/' . (count($this->matches) + 1); $this->matches[] = new Match($this->fedora, $id, $this, $property, $value, $required); }
php
public function addMatch(string $property, string $value, bool $required) { $id = $this->getid() . '/match/' . (count($this->matches) + 1); $this->matches[] = new Match($this->fedora, $id, $this, $property, $value, $required); }
[ "public", "function", "addMatch", "(", "string", "$", "property", ",", "string", "$", "value", ",", "bool", "$", "required", ")", "{", "$", "id", "=", "$", "this", "->", "getid", "(", ")", ".", "'/match/'", ".", "(", "count", "(", "$", "this", "->", "matches", ")", "+", "1", ")", ";", "$", "this", "->", "matches", "[", "]", "=", "new", "Match", "(", "$", "this", "->", "fedora", ",", "$", "id", ",", "$", "this", ",", "$", "property", ",", "$", "value", ",", "$", "required", ")", ";", "}" ]
Defines a matching rule for the dissemination service @param string $property RDF property to be checked in resource's metadata @param string $value expected RDF property value in resource's metadata @param bool $required is this match rule compulsory? @see \acdhOeaw\schema\dissemination\Match
[ "Defines", "a", "matching", "rule", "for", "the", "dissemination", "service" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/dissemination/Service.php#L161-L164
29,758
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/dissemination/Service.php
Service.getMetadata
public function getMetadata(): Resource { $meta = (new Graph())->resource('.'); $meta->addType(RC::get('fedoraServiceClass')); $meta->addResource(RC::idProp(), $this->getId()); $meta->addLiteral(RC::titleProp(), $this->getId()); $meta->addLiteral(RC::get('fedoraServiceLocProp'), $this->location); $retProp = RC::get('fedoraServiceRetFormatProp'); foreach ($this->format as $i) { $meta->addLiteral($retProp, $i); } $meta->addLiteral(RC::get('fedoraServiceRevProxyProp'), $this->revProxy); return $meta; }
php
public function getMetadata(): Resource { $meta = (new Graph())->resource('.'); $meta->addType(RC::get('fedoraServiceClass')); $meta->addResource(RC::idProp(), $this->getId()); $meta->addLiteral(RC::titleProp(), $this->getId()); $meta->addLiteral(RC::get('fedoraServiceLocProp'), $this->location); $retProp = RC::get('fedoraServiceRetFormatProp'); foreach ($this->format as $i) { $meta->addLiteral($retProp, $i); } $meta->addLiteral(RC::get('fedoraServiceRevProxyProp'), $this->revProxy); return $meta; }
[ "public", "function", "getMetadata", "(", ")", ":", "Resource", "{", "$", "meta", "=", "(", "new", "Graph", "(", ")", ")", "->", "resource", "(", "'.'", ")", ";", "$", "meta", "->", "addType", "(", "RC", "::", "get", "(", "'fedoraServiceClass'", ")", ")", ";", "$", "meta", "->", "addResource", "(", "RC", "::", "idProp", "(", ")", ",", "$", "this", "->", "getId", "(", ")", ")", ";", "$", "meta", "->", "addLiteral", "(", "RC", "::", "titleProp", "(", ")", ",", "$", "this", "->", "getId", "(", ")", ")", ";", "$", "meta", "->", "addLiteral", "(", "RC", "::", "get", "(", "'fedoraServiceLocProp'", ")", ",", "$", "this", "->", "location", ")", ";", "$", "retProp", "=", "RC", "::", "get", "(", "'fedoraServiceRetFormatProp'", ")", ";", "foreach", "(", "$", "this", "->", "format", "as", "$", "i", ")", "{", "$", "meta", "->", "addLiteral", "(", "$", "retProp", ",", "$", "i", ")", ";", "}", "$", "meta", "->", "addLiteral", "(", "RC", "::", "get", "(", "'fedoraServiceRevProxyProp'", ")", ",", "$", "this", "->", "revProxy", ")", ";", "return", "$", "meta", ";", "}" ]
Returns metadata describing the dissemination service. @return Resource
[ "Returns", "metadata", "describing", "the", "dissemination", "service", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/dissemination/Service.php#L170-L189
29,759
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/dissemination/Service.php
Service.updateRms
public function updateRms(bool $create = true, bool $uploadBinary = true, string $path = '/'): FedoraResource { parent::updateRms($create, $uploadBinary, $path); $res = $this->getResource(false, false); $chPath = $res->getUri(true) . '/'; $children = []; foreach ($res->getChildren() as $i) { $children[$i->getUri(true)] = $i; } $validChildren = []; foreach ($this->params as $i) { $tmp = $i->updateRms($create, $uploadBinary, $chPath); $validChildren[] = $tmp->getUri(true); } foreach ($this->matches as $i) { $tmp = $i->updateRms($create, $uploadBinary, $chPath); $validChildren[] = $tmp->getUri(true); } $invalidChildren = array_diff(array_keys($children), $validChildren); foreach ($invalidChildren as $i) { $children[$i]->delete(true, true, false); } return $res; }
php
public function updateRms(bool $create = true, bool $uploadBinary = true, string $path = '/'): FedoraResource { parent::updateRms($create, $uploadBinary, $path); $res = $this->getResource(false, false); $chPath = $res->getUri(true) . '/'; $children = []; foreach ($res->getChildren() as $i) { $children[$i->getUri(true)] = $i; } $validChildren = []; foreach ($this->params as $i) { $tmp = $i->updateRms($create, $uploadBinary, $chPath); $validChildren[] = $tmp->getUri(true); } foreach ($this->matches as $i) { $tmp = $i->updateRms($create, $uploadBinary, $chPath); $validChildren[] = $tmp->getUri(true); } $invalidChildren = array_diff(array_keys($children), $validChildren); foreach ($invalidChildren as $i) { $children[$i]->delete(true, true, false); } return $res; }
[ "public", "function", "updateRms", "(", "bool", "$", "create", "=", "true", ",", "bool", "$", "uploadBinary", "=", "true", ",", "string", "$", "path", "=", "'/'", ")", ":", "FedoraResource", "{", "parent", "::", "updateRms", "(", "$", "create", ",", "$", "uploadBinary", ",", "$", "path", ")", ";", "$", "res", "=", "$", "this", "->", "getResource", "(", "false", ",", "false", ")", ";", "$", "chPath", "=", "$", "res", "->", "getUri", "(", "true", ")", ".", "'/'", ";", "$", "children", "=", "[", "]", ";", "foreach", "(", "$", "res", "->", "getChildren", "(", ")", "as", "$", "i", ")", "{", "$", "children", "[", "$", "i", "->", "getUri", "(", "true", ")", "]", "=", "$", "i", ";", "}", "$", "validChildren", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "params", "as", "$", "i", ")", "{", "$", "tmp", "=", "$", "i", "->", "updateRms", "(", "$", "create", ",", "$", "uploadBinary", ",", "$", "chPath", ")", ";", "$", "validChildren", "[", "]", "=", "$", "tmp", "->", "getUri", "(", "true", ")", ";", "}", "foreach", "(", "$", "this", "->", "matches", "as", "$", "i", ")", "{", "$", "tmp", "=", "$", "i", "->", "updateRms", "(", "$", "create", ",", "$", "uploadBinary", ",", "$", "chPath", ")", ";", "$", "validChildren", "[", "]", "=", "$", "tmp", "->", "getUri", "(", "true", ")", ";", "}", "$", "invalidChildren", "=", "array_diff", "(", "array_keys", "(", "$", "children", ")", ",", "$", "validChildren", ")", ";", "foreach", "(", "$", "invalidChildren", "as", "$", "i", ")", "{", "$", "children", "[", "$", "i", "]", "->", "delete", "(", "true", ",", "true", ",", "false", ")", ";", "}", "return", "$", "res", ";", "}" ]
Updates the dissemination service definition in the repository. @param bool $create should repository resource be created if it does not exist? @param bool $uploadBinary should binary data of the real-world entity be uploaded uppon repository resource creation? @param string $path where to create a resource (if it does not exist). If it it ends with a "/", the resource will be created as a child of a given collection). All the parents in the Fedora resource tree have to exist (you can not create "/foo/bar" if "/foo" does not exist already). @return FedoraResource
[ "Updates", "the", "dissemination", "service", "definition", "in", "the", "repository", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/dissemination/Service.php#L203-L231
29,760
ventoviro/windwalker-core
src/Core/Logger/LoggerManager.php
LoggerManager.setLoggers
public function setLoggers(array $loggers) { foreach ($loggers as $channel => $logger) { $this->addLogger($channel, $logger); } return $this; }
php
public function setLoggers(array $loggers) { foreach ($loggers as $channel => $logger) { $this->addLogger($channel, $logger); } return $this; }
[ "public", "function", "setLoggers", "(", "array", "$", "loggers", ")", "{", "foreach", "(", "$", "loggers", "as", "$", "channel", "=>", "$", "logger", ")", "{", "$", "this", "->", "addLogger", "(", "$", "channel", ",", "$", "logger", ")", ";", "}", "return", "$", "this", ";", "}" ]
Method to set property loggers @param LoggerInterface[] $loggers @return static Return self to support chaining.
[ "Method", "to", "set", "property", "loggers" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Logger/LoggerManager.php#L519-L526
29,761
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/SparqlClient.php
SparqlClient.query
public function query(string $query, int $nTries = 1): Result { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); $body = 'query=' . rawurlencode($query); $request = new Request('POST', $this->url, $headers, $body); while ($nTries > 0) { $nTries--; try { $response = $this->client->send($request); $body = $response->getBody(); $result = new Result($body, 'application/sparql-results+json'); break; } catch (RequestException $ex) { if ($nTries <= 0) { throw $ex; } } } return $result; }
php
public function query(string $query, int $nTries = 1): Result { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); $body = 'query=' . rawurlencode($query); $request = new Request('POST', $this->url, $headers, $body); while ($nTries > 0) { $nTries--; try { $response = $this->client->send($request); $body = $response->getBody(); $result = new Result($body, 'application/sparql-results+json'); break; } catch (RequestException $ex) { if ($nTries <= 0) { throw $ex; } } } return $result; }
[ "public", "function", "query", "(", "string", "$", "query", ",", "int", "$", "nTries", "=", "1", ")", ":", "Result", "{", "$", "headers", "=", "array", "(", "'Content-Type'", "=>", "'application/x-www-form-urlencoded'", ")", ";", "$", "body", "=", "'query='", ".", "rawurlencode", "(", "$", "query", ")", ";", "$", "request", "=", "new", "Request", "(", "'POST'", ",", "$", "this", "->", "url", ",", "$", "headers", ",", "$", "body", ")", ";", "while", "(", "$", "nTries", ">", "0", ")", "{", "$", "nTries", "--", ";", "try", "{", "$", "response", "=", "$", "this", "->", "client", "->", "send", "(", "$", "request", ")", ";", "$", "body", "=", "$", "response", "->", "getBody", "(", ")", ";", "$", "result", "=", "new", "Result", "(", "$", "body", ",", "'application/sparql-results+json'", ")", ";", "break", ";", "}", "catch", "(", "RequestException", "$", "ex", ")", "{", "if", "(", "$", "nTries", "<=", "0", ")", "{", "throw", "$", "ex", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
Runs a given query. There is no support for UPDATE queries. @param string $query SPARQL query to be run @param int $nTries how many times request should be repeated in case of error before giving up @return \EasyRdf\Sparql\Result
[ "Runs", "a", "given", "query", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/SparqlClient.php#L91-L109
29,762
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Common/Model/BaseCollection.php
BaseCollection.get
public function get($id) { foreach ($this->items as $item) { if ($item->id === $id) { return $item; } } return null; }
php
public function get($id) { foreach ($this->items as $item) { if ($item->id === $id) { return $item; } } return null; }
[ "public", "function", "get", "(", "$", "id", ")", "{", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "if", "(", "$", "item", "->", "id", "===", "$", "id", ")", "{", "return", "$", "item", ";", "}", "}", "return", "null", ";", "}" ]
Get object in the collection by id @param string $id @return mixed|null
[ "Get", "object", "in", "the", "collection", "by", "id" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Common/Model/BaseCollection.php#L64-L72
29,763
locomotivemtl/charcoal-ui
src/Charcoal/Ui/ConditionalizableTrait.php
ConditionalizableTrait.parseConditionalLogic
final protected function parseConditionalLogic($condition) { if ($condition === null) { return null; } if (is_bool($condition)) { return $condition; } $not = false; if (is_string($condition)) { $not = ($condition[0] === '!'); if ($not) { $condition = ltrim($condition, '!'); } } $result = $this->resolveConditionalLogic($condition); return (($not === true) ? !$result : $result); }
php
final protected function parseConditionalLogic($condition) { if ($condition === null) { return null; } if (is_bool($condition)) { return $condition; } $not = false; if (is_string($condition)) { $not = ($condition[0] === '!'); if ($not) { $condition = ltrim($condition, '!'); } } $result = $this->resolveConditionalLogic($condition); return (($not === true) ? !$result : $result); }
[ "final", "protected", "function", "parseConditionalLogic", "(", "$", "condition", ")", "{", "if", "(", "$", "condition", "===", "null", ")", "{", "return", "null", ";", "}", "if", "(", "is_bool", "(", "$", "condition", ")", ")", "{", "return", "$", "condition", ";", "}", "$", "not", "=", "false", ";", "if", "(", "is_string", "(", "$", "condition", ")", ")", "{", "$", "not", "=", "(", "$", "condition", "[", "0", "]", "===", "'!'", ")", ";", "if", "(", "$", "not", ")", "{", "$", "condition", "=", "ltrim", "(", "$", "condition", ",", "'!'", ")", ";", "}", "}", "$", "result", "=", "$", "this", "->", "resolveConditionalLogic", "(", "$", "condition", ")", ";", "return", "(", "(", "$", "not", "===", "true", ")", "?", "!", "$", "result", ":", "$", "result", ")", ";", "}" ]
Resolve the conditional logic. @param mixed $condition The condition. @return boolean|null
[ "Resolve", "the", "conditional", "logic", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/ConditionalizableTrait.php#L78-L99
29,764
jmikola/JmikolaWildcardEventDispatcherBundle
EventDispatcher/ContainerAwareEventDispatcher.php
ContainerAwareEventDispatcher.addListenerServicePattern
private function addListenerServicePattern($eventPattern, $callback, $priority = 0) { if (!is_array($callback) || 2 !== count($callback)) { throw new \InvalidArgumentException('Expected an array("service", "method") argument'); } $container = $this->container; $listenerProvider = function() use ($container, $callback) { return array($container->get($callback[0]), $callback[1]); }; $this->addListenerPattern(new LazyListenerPattern($eventPattern, $listenerProvider, $priority)); }
php
private function addListenerServicePattern($eventPattern, $callback, $priority = 0) { if (!is_array($callback) || 2 !== count($callback)) { throw new \InvalidArgumentException('Expected an array("service", "method") argument'); } $container = $this->container; $listenerProvider = function() use ($container, $callback) { return array($container->get($callback[0]), $callback[1]); }; $this->addListenerPattern(new LazyListenerPattern($eventPattern, $listenerProvider, $priority)); }
[ "private", "function", "addListenerServicePattern", "(", "$", "eventPattern", ",", "$", "callback", ",", "$", "priority", "=", "0", ")", "{", "if", "(", "!", "is_array", "(", "$", "callback", ")", "||", "2", "!==", "count", "(", "$", "callback", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Expected an array(\"service\", \"method\") argument'", ")", ";", "}", "$", "container", "=", "$", "this", "->", "container", ";", "$", "listenerProvider", "=", "function", "(", ")", "use", "(", "$", "container", ",", "$", "callback", ")", "{", "return", "array", "(", "$", "container", "->", "get", "(", "$", "callback", "[", "0", "]", ")", ",", "$", "callback", "[", "1", "]", ")", ";", "}", ";", "$", "this", "->", "addListenerPattern", "(", "new", "LazyListenerPattern", "(", "$", "eventPattern", ",", "$", "listenerProvider", ",", "$", "priority", ")", ")", ";", "}" ]
Adds a service as an event listener for all events matching the specified pattern. @param string $eventPattern @param callback $callback @param integer $priority @throw InvalidArgumentException if the callback is not a service/method tuple
[ "Adds", "a", "service", "as", "an", "event", "listener", "for", "all", "events", "matching", "the", "specified", "pattern", "." ]
b3295ce0eb4212f9bb0d6d0d0913cfa13d2e3884
https://github.com/jmikola/JmikolaWildcardEventDispatcherBundle/blob/b3295ce0eb4212f9bb0d6d0d0913cfa13d2e3884/EventDispatcher/ContainerAwareEventDispatcher.php#L48-L60
29,765
jmikola/JmikolaWildcardEventDispatcherBundle
EventDispatcher/ContainerAwareEventDispatcher.php
ContainerAwareEventDispatcher.addSubscriberService
public function addSubscriberService($serviceId, $class) { foreach ($class::getSubscribedEvents() as $eventName => $params) { if (is_string($params)) { $this->addListenerService($eventName, array($serviceId, $params), 0); } elseif (is_string($params[0])) { $this->addListenerService($eventName, array($serviceId, $params[0]), isset($params[1]) ? $params[1] : 0); } else { foreach ($params as $listener) { $this->addListenerService($eventName, array($serviceId, $listener[0]), isset($listener[1]) ? $listener[1] : 0); } } } }
php
public function addSubscriberService($serviceId, $class) { foreach ($class::getSubscribedEvents() as $eventName => $params) { if (is_string($params)) { $this->addListenerService($eventName, array($serviceId, $params), 0); } elseif (is_string($params[0])) { $this->addListenerService($eventName, array($serviceId, $params[0]), isset($params[1]) ? $params[1] : 0); } else { foreach ($params as $listener) { $this->addListenerService($eventName, array($serviceId, $listener[0]), isset($listener[1]) ? $listener[1] : 0); } } } }
[ "public", "function", "addSubscriberService", "(", "$", "serviceId", ",", "$", "class", ")", "{", "foreach", "(", "$", "class", "::", "getSubscribedEvents", "(", ")", "as", "$", "eventName", "=>", "$", "params", ")", "{", "if", "(", "is_string", "(", "$", "params", ")", ")", "{", "$", "this", "->", "addListenerService", "(", "$", "eventName", ",", "array", "(", "$", "serviceId", ",", "$", "params", ")", ",", "0", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "params", "[", "0", "]", ")", ")", "{", "$", "this", "->", "addListenerService", "(", "$", "eventName", ",", "array", "(", "$", "serviceId", ",", "$", "params", "[", "0", "]", ")", ",", "isset", "(", "$", "params", "[", "1", "]", ")", "?", "$", "params", "[", "1", "]", ":", "0", ")", ";", "}", "else", "{", "foreach", "(", "$", "params", "as", "$", "listener", ")", "{", "$", "this", "->", "addListenerService", "(", "$", "eventName", ",", "array", "(", "$", "serviceId", ",", "$", "listener", "[", "0", "]", ")", ",", "isset", "(", "$", "listener", "[", "1", "]", ")", "?", "$", "listener", "[", "1", "]", ":", "0", ")", ";", "}", "}", "}", "}" ]
Adds a service as an event subscriber for all events matching the specified pattern @param string $serviceId The service ID of the subscriber service @param string $class The service's class name (which must implement EventSubscriberInterface)
[ "Adds", "a", "service", "as", "an", "event", "subscriber", "for", "all", "events", "matching", "the", "specified", "pattern" ]
b3295ce0eb4212f9bb0d6d0d0913cfa13d2e3884
https://github.com/jmikola/JmikolaWildcardEventDispatcherBundle/blob/b3295ce0eb4212f9bb0d6d0d0913cfa13d2e3884/EventDispatcher/ContainerAwareEventDispatcher.php#L69-L82
29,766
crcms/microservice-framework
src/Console/Kernel.php
Kernel.commands
protected function commands() { $commands = $this->app['config']->get('mount.commands', []); if ($commands) { Artisan::starting(function ($artisan) use ($commands) { $artisan->resolveCommands($commands); }); } }
php
protected function commands() { $commands = $this->app['config']->get('mount.commands', []); if ($commands) { Artisan::starting(function ($artisan) use ($commands) { $artisan->resolveCommands($commands); }); } }
[ "protected", "function", "commands", "(", ")", "{", "$", "commands", "=", "$", "this", "->", "app", "[", "'config'", "]", "->", "get", "(", "'mount.commands'", ",", "[", "]", ")", ";", "if", "(", "$", "commands", ")", "{", "Artisan", "::", "starting", "(", "function", "(", "$", "artisan", ")", "use", "(", "$", "commands", ")", "{", "$", "artisan", "->", "resolveCommands", "(", "$", "commands", ")", ";", "}", ")", ";", "}", "}" ]
Register the Closure based commands for the application. @return void
[ "Register", "the", "Closure", "based", "commands", "for", "the", "application", "." ]
7ad513562e333599642d5697ee45572d7d9e713d
https://github.com/crcms/microservice-framework/blob/7ad513562e333599642d5697ee45572d7d9e713d/src/Console/Kernel.php#L46-L54
29,767
polyfony-inc/polyfony
Private/Polyfony/Route.php
Route.setDestination
public function setDestination(string $merged_destination) :self { // explode the parameters list($this->bundle, $this->controller, $this->action) = explode('/', str_replace('@', '/',$merged_destination)); // if the action is an url parameter if(Route\Helper::isThisAParameterName($this->action)) { // we have an action triggered by an url parameter, remove special chars, and set the trigger $this->trigger = trim($this->action, '{}'); // action is not known yet $this->action = null; } // build route segments tp ease the job of the router later on $this->buildSegments(); // return the route return $this; }
php
public function setDestination(string $merged_destination) :self { // explode the parameters list($this->bundle, $this->controller, $this->action) = explode('/', str_replace('@', '/',$merged_destination)); // if the action is an url parameter if(Route\Helper::isThisAParameterName($this->action)) { // we have an action triggered by an url parameter, remove special chars, and set the trigger $this->trigger = trim($this->action, '{}'); // action is not known yet $this->action = null; } // build route segments tp ease the job of the router later on $this->buildSegments(); // return the route return $this; }
[ "public", "function", "setDestination", "(", "string", "$", "merged_destination", ")", ":", "self", "{", "// explode the parameters", "list", "(", "$", "this", "->", "bundle", ",", "$", "this", "->", "controller", ",", "$", "this", "->", "action", ")", "=", "explode", "(", "'/'", ",", "str_replace", "(", "'@'", ",", "'/'", ",", "$", "merged_destination", ")", ")", ";", "// if the action is an url parameter", "if", "(", "Route", "\\", "Helper", "::", "isThisAParameterName", "(", "$", "this", "->", "action", ")", ")", "{", "// we have an action triggered by an url parameter, remove special chars, and set the trigger", "$", "this", "->", "trigger", "=", "trim", "(", "$", "this", "->", "action", ",", "'{}'", ")", ";", "// action is not known yet", "$", "this", "->", "action", "=", "null", ";", "}", "// build route segments tp ease the job of the router later on", "$", "this", "->", "buildSegments", "(", ")", ";", "// return the route", "return", "$", "this", ";", "}" ]
shortcut for destination
[ "shortcut", "for", "destination" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Route.php#L74-L89
29,768
polyfony-inc/polyfony
Private/Polyfony/Response/CSV.php
CSV.buildAndGetDocument
public static function buildAndGetDocument($content) :array { // convert the array to a basic CSV string $content = is_array($content) ? self::convertArrayToString($content) : $content; // convert the content to the proper charset (if needs be) $content = mb_convert_encoding($content, self::destination_charset); // prefix it with the BOM characters $content = self::getBomCharacters() . $content; // return the formatted document return [ $content, self::destination_charset ]; }
php
public static function buildAndGetDocument($content) :array { // convert the array to a basic CSV string $content = is_array($content) ? self::convertArrayToString($content) : $content; // convert the content to the proper charset (if needs be) $content = mb_convert_encoding($content, self::destination_charset); // prefix it with the BOM characters $content = self::getBomCharacters() . $content; // return the formatted document return [ $content, self::destination_charset ]; }
[ "public", "static", "function", "buildAndGetDocument", "(", "$", "content", ")", ":", "array", "{", "// convert the array to a basic CSV string", "$", "content", "=", "is_array", "(", "$", "content", ")", "?", "self", "::", "convertArrayToString", "(", "$", "content", ")", ":", "$", "content", ";", "// convert the content to the proper charset (if needs be)", "$", "content", "=", "mb_convert_encoding", "(", "$", "content", ",", "self", "::", "destination_charset", ")", ";", "// prefix it with the BOM characters", "$", "content", "=", "self", "::", "getBomCharacters", "(", ")", ".", "$", "content", ";", "// return the formatted document", "return", "[", "$", "content", ",", "self", "::", "destination_charset", "]", ";", "}" ]
with preformatted csv will still work
[ "with", "preformatted", "csv", "will", "still", "work" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/CSV.php#L15-L27
29,769
ventoviro/windwalker-core
src/Core/Console/CoreConsole.php
CoreConsole.prepareExecute
protected function prepareExecute() { if (class_exists(ComposerInformation::class)) { $this->version = ComposerInformation::getInstalledVersion('windwalker/core'); } if ($this->getRootCommand()->getOption('n')) { IOFactory::getIO()->setInput(new NullInput()); } }
php
protected function prepareExecute() { if (class_exists(ComposerInformation::class)) { $this->version = ComposerInformation::getInstalledVersion('windwalker/core'); } if ($this->getRootCommand()->getOption('n')) { IOFactory::getIO()->setInput(new NullInput()); } }
[ "protected", "function", "prepareExecute", "(", ")", "{", "if", "(", "class_exists", "(", "ComposerInformation", "::", "class", ")", ")", "{", "$", "this", "->", "version", "=", "ComposerInformation", "::", "getInstalledVersion", "(", "'windwalker/core'", ")", ";", "}", "if", "(", "$", "this", "->", "getRootCommand", "(", ")", "->", "getOption", "(", "'n'", ")", ")", "{", "IOFactory", "::", "getIO", "(", ")", "->", "setInput", "(", "new", "NullInput", "(", ")", ")", ";", "}", "}" ]
Prepare execute hook. @return void
[ "Prepare", "execute", "hook", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Console/CoreConsole.php#L226-L235
29,770
secucard/secucard-connect-php-sdk
src/SecucardConnect/Auth/PasswordCredentials.php
PasswordCredentials.addParameters
public function addParameters(&$params) { $params['grant_type'] = $this->getType(); $params['username'] = $this->username; $params['password'] = $this->password; }
php
public function addParameters(&$params) { $params['grant_type'] = $this->getType(); $params['username'] = $this->username; $params['password'] = $this->password; }
[ "public", "function", "addParameters", "(", "&", "$", "params", ")", "{", "$", "params", "[", "'grant_type'", "]", "=", "$", "this", "->", "getType", "(", ")", ";", "$", "params", "[", "'username'", "]", "=", "$", "this", "->", "username", ";", "$", "params", "[", "'password'", "]", "=", "$", "this", "->", "password", ";", "}" ]
Function add parameters to params array @param array $params
[ "Function", "add", "parameters", "to", "params", "array" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Auth/PasswordCredentials.php#L36-L41
29,771
ventoviro/windwalker-core
src/Core/View/AbstractView.php
AbstractView.pipe
public function pipe($name, $handler = null) { if (is_callable($name)) { $handler = $name; $name = null; } return $handler($this->getRepository($name), $this); }
php
public function pipe($name, $handler = null) { if (is_callable($name)) { $handler = $name; $name = null; } return $handler($this->getRepository($name), $this); }
[ "public", "function", "pipe", "(", "$", "name", ",", "$", "handler", "=", "null", ")", "{", "if", "(", "is_callable", "(", "$", "name", ")", ")", "{", "$", "handler", "=", "$", "name", ";", "$", "name", "=", "null", ";", "}", "return", "$", "handler", "(", "$", "this", "->", "getRepository", "(", "$", "name", ")", ",", "$", "this", ")", ";", "}" ]
Pipe a callback to model and view then return value. @param string|callable $name The name alias of model, keep NULL as default model. Or just send a callable here as handler. @param callable $handler The callback handler. @return mixed
[ "Pipe", "a", "callback", "to", "model", "and", "view", "then", "return", "value", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/View/AbstractView.php#L663-L671
29,772
ventoviro/windwalker-core
src/Core/View/AbstractView.php
AbstractView.applyData
public function applyData($name, $handler = null) { if (is_callable($name)) { $handler = $name; $name = null; } $handler($this->getRepository($name), $this->getData()); return $this; }
php
public function applyData($name, $handler = null) { if (is_callable($name)) { $handler = $name; $name = null; } $handler($this->getRepository($name), $this->getData()); return $this; }
[ "public", "function", "applyData", "(", "$", "name", ",", "$", "handler", "=", "null", ")", "{", "if", "(", "is_callable", "(", "$", "name", ")", ")", "{", "$", "handler", "=", "$", "name", ";", "$", "name", "=", "null", ";", "}", "$", "handler", "(", "$", "this", "->", "getRepository", "(", "$", "name", ")", ",", "$", "this", "->", "getData", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Apply a callback to model and view data. @param string|callable $name The name alias of model, keep NULL as default model. Or just send a callable here as handler. @param callable $handler The callback handler. @return $this
[ "Apply", "a", "callback", "to", "model", "and", "view", "data", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/View/AbstractView.php#L682-L692
29,773
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/redmine/Issue.php
Issue.fetchAll
static public function fetchAll(Fedora $fedora, bool $progressBar, array $filters = array()): array { $param = ['key=' . urlencode(RC::get('redmineApiKey')), 'limit' => 1000000]; foreach ($filters as $k => $v) { $param[] = urlencode($k) . '=' . urlencode($v); } $param = implode('&', $param); return self::redmineFetchLoop($fedora, $progressBar, 'issues', $param); }
php
static public function fetchAll(Fedora $fedora, bool $progressBar, array $filters = array()): array { $param = ['key=' . urlencode(RC::get('redmineApiKey')), 'limit' => 1000000]; foreach ($filters as $k => $v) { $param[] = urlencode($k) . '=' . urlencode($v); } $param = implode('&', $param); return self::redmineFetchLoop($fedora, $progressBar, 'issues', $param); }
[ "static", "public", "function", "fetchAll", "(", "Fedora", "$", "fedora", ",", "bool", "$", "progressBar", ",", "array", "$", "filters", "=", "array", "(", ")", ")", ":", "array", "{", "$", "param", "=", "[", "'key='", ".", "urlencode", "(", "RC", "::", "get", "(", "'redmineApiKey'", ")", ")", ",", "'limit'", "=>", "1000000", "]", ";", "foreach", "(", "$", "filters", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "param", "[", "]", "=", "urlencode", "(", "$", "k", ")", ".", "'='", ".", "urlencode", "(", "$", "v", ")", ";", "}", "$", "param", "=", "implode", "(", "'&'", ",", "$", "param", ")", ";", "return", "self", "::", "redmineFetchLoop", "(", "$", "fedora", ",", "$", "progressBar", ",", "'issues'", ",", "$", "param", ")", ";", "}" ]
Returns array of all Issue objects which can be fetched from the Redmine. See the Redmine::fetchAll() description for details; @param \acdhOeaw\fedora\Fedora $fedora Fedora connection @param bool $progressBar should progress bar be displayed (makes sense only if the standard output is a console) @param array $filters filters to be passed to the Redmine's issue REST API in a form of an associative array, e.g. `array('tracker_id' => 5)` @return array @see Redmine::fetchAll()
[ "Returns", "array", "of", "all", "Issue", "objects", "which", "can", "be", "fetched", "from", "the", "Redmine", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/redmine/Issue.php#L57-L66
29,774
polyfony-inc/polyfony
Private/Polyfony/Record/Aware.php
Aware.save
public function save() :bool { // if an id already exists if($this->_['id']) { // we can update and return the number of affected rows (0 on error, 1 on success) return (bool) self::_update() ->set($this->__toArray(true, true)) ->where(['id'=>$this->_['id']]) ->execute(); } // this is a new record else { // try to insert it $inserted_object = self::create($this->__toArray(true, true)); // if insertion succeeded, return true if($inserted_object) { // clone ourselves with what the database returneds, a full fledged object $this->replicate($inserted_object); // return success return true; } // didnt insert else { // failure feedback return false; } } }
php
public function save() :bool { // if an id already exists if($this->_['id']) { // we can update and return the number of affected rows (0 on error, 1 on success) return (bool) self::_update() ->set($this->__toArray(true, true)) ->where(['id'=>$this->_['id']]) ->execute(); } // this is a new record else { // try to insert it $inserted_object = self::create($this->__toArray(true, true)); // if insertion succeeded, return true if($inserted_object) { // clone ourselves with what the database returneds, a full fledged object $this->replicate($inserted_object); // return success return true; } // didnt insert else { // failure feedback return false; } } }
[ "public", "function", "save", "(", ")", ":", "bool", "{", "// if an id already exists", "if", "(", "$", "this", "->", "_", "[", "'id'", "]", ")", "{", "// we can update and return the number of affected rows (0 on error, 1 on success)", "return", "(", "bool", ")", "self", "::", "_update", "(", ")", "->", "set", "(", "$", "this", "->", "__toArray", "(", "true", ",", "true", ")", ")", "->", "where", "(", "[", "'id'", "=>", "$", "this", "->", "_", "[", "'id'", "]", "]", ")", "->", "execute", "(", ")", ";", "}", "// this is a new record", "else", "{", "// try to insert it", "$", "inserted_object", "=", "self", "::", "create", "(", "$", "this", "->", "__toArray", "(", "true", ",", "true", ")", ")", ";", "// if insertion succeeded, return true", "if", "(", "$", "inserted_object", ")", "{", "// clone ourselves with what the database returneds, a full fledged object", "$", "this", "->", "replicate", "(", "$", "inserted_object", ")", ";", "// return success", "return", "true", ";", "}", "// didnt insert", "else", "{", "// failure feedback", "return", "false", ";", "}", "}", "}" ]
update or create
[ "update", "or", "create" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Record/Aware.php#L155-L183
29,775
polyfony-inc/polyfony
Private/Polyfony/Record/Aware.php
Aware.create
public static function create(array $columns_and_values=[]) { return Database::query() ->insert($columns_and_values) ->into(self::tableName()) ->execute(); }
php
public static function create(array $columns_and_values=[]) { return Database::query() ->insert($columns_and_values) ->into(self::tableName()) ->execute(); }
[ "public", "static", "function", "create", "(", "array", "$", "columns_and_values", "=", "[", "]", ")", "{", "return", "Database", "::", "query", "(", ")", "->", "insert", "(", "$", "columns_and_values", ")", "->", "into", "(", "self", "::", "tableName", "(", ")", ")", "->", "execute", "(", ")", ";", "}" ]
shortcut to insert an element
[ "shortcut", "to", "insert", "an", "element" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Record/Aware.php#L205-L212
29,776
polyfony-inc/polyfony
Private/Polyfony/Record/Aware.php
Aware._select
public static function _select(array $select=[]) :Query { // returns a Query object, to execute, or to complement with some more parameters return Database::query() ->select($select) ->from(self::tableName()); }
php
public static function _select(array $select=[]) :Query { // returns a Query object, to execute, or to complement with some more parameters return Database::query() ->select($select) ->from(self::tableName()); }
[ "public", "static", "function", "_select", "(", "array", "$", "select", "=", "[", "]", ")", ":", "Query", "{", "// returns a Query object, to execute, or to complement with some more parameters", "return", "Database", "::", "query", "(", ")", "->", "select", "(", "$", "select", ")", "->", "from", "(", "self", "::", "tableName", "(", ")", ")", ";", "}" ]
shortcut that bootstraps a select query
[ "shortcut", "that", "bootstraps", "a", "select", "query" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Record/Aware.php#L215-L222
29,777
polyfony-inc/polyfony
Private/Polyfony/Store/Memcache.php
Memcache.setup
public static function setup($server, $host, $port) { // Sanity check: Make sure we have received a valid switch ($server) { case 'Memcache' : self::$_memcache = new \Memcache(); break; case 'Memcached' : self::$_memcache = new \Memcached(); break; default : throw new \Exception("Unknown server {$server}."); } // Memcache instance created, add the server self::$_memcache->addServer($host, $port); }
php
public static function setup($server, $host, $port) { // Sanity check: Make sure we have received a valid switch ($server) { case 'Memcache' : self::$_memcache = new \Memcache(); break; case 'Memcached' : self::$_memcache = new \Memcached(); break; default : throw new \Exception("Unknown server {$server}."); } // Memcache instance created, add the server self::$_memcache->addServer($host, $port); }
[ "public", "static", "function", "setup", "(", "$", "server", ",", "$", "host", ",", "$", "port", ")", "{", "// Sanity check: Make sure we have received a valid", "switch", "(", "$", "server", ")", "{", "case", "'Memcache'", ":", "self", "::", "$", "_memcache", "=", "new", "\\", "Memcache", "(", ")", ";", "break", ";", "case", "'Memcached'", ":", "self", "::", "$", "_memcache", "=", "new", "\\", "Memcached", "(", ")", ";", "break", ";", "default", ":", "throw", "new", "\\", "Exception", "(", "\"Unknown server {$server}.\"", ")", ";", "}", "// Memcache instance created, add the server", "self", "::", "$", "_memcache", "->", "addServer", "(", "$", "host", ",", "$", "port", ")", ";", "}" ]
Setup Memcache for storing data. @access public @param string $server Whether we are using Memcache or Memcached. @param string $host The location of the Memcache server. @param string $port The port the Memcache server lives on. @throws \Exception If passed an incorrect server.
[ "Setup", "Memcache", "for", "storing", "data", "." ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Store/Memcache.php#L28-L38
29,778
stevegrunwell/phpunit-markup-assertions
src/MarkupAssertionsTrait.php
MarkupAssertionsTrait.assertContainsSelector
public function assertContainsSelector($selector, $output = '', $message = '') { $results = $this->executeDomQuery($output, $selector); $this->assertGreaterThan(0, count($results), $message); }
php
public function assertContainsSelector($selector, $output = '', $message = '') { $results = $this->executeDomQuery($output, $selector); $this->assertGreaterThan(0, count($results), $message); }
[ "public", "function", "assertContainsSelector", "(", "$", "selector", ",", "$", "output", "=", "''", ",", "$", "message", "=", "''", ")", "{", "$", "results", "=", "$", "this", "->", "executeDomQuery", "(", "$", "output", ",", "$", "selector", ")", ";", "$", "this", "->", "assertGreaterThan", "(", "0", ",", "count", "(", "$", "results", ")", ",", "$", "message", ")", ";", "}" ]
Assert that the given string contains an element matching the given selector. @since 1.0.0 @param string $selector A query selector for the element to find. @param string $output The output that should contain the $selector. @param string $message A message to display if the assertion fails.
[ "Assert", "that", "the", "given", "string", "contains", "an", "element", "matching", "the", "given", "selector", "." ]
545ce29918d4d986e26961bf4d380c655583ece9
https://github.com/stevegrunwell/phpunit-markup-assertions/blob/545ce29918d4d986e26961bf4d380c655583ece9/src/MarkupAssertionsTrait.php#L27-L32
29,779
stevegrunwell/phpunit-markup-assertions
src/MarkupAssertionsTrait.php
MarkupAssertionsTrait.assertNotContainsSelector
public function assertNotContainsSelector($selector, $output = '', $message = '') { $results = $this->executeDomQuery($output, $selector); $this->assertEquals(0, count($results), $message); }
php
public function assertNotContainsSelector($selector, $output = '', $message = '') { $results = $this->executeDomQuery($output, $selector); $this->assertEquals(0, count($results), $message); }
[ "public", "function", "assertNotContainsSelector", "(", "$", "selector", ",", "$", "output", "=", "''", ",", "$", "message", "=", "''", ")", "{", "$", "results", "=", "$", "this", "->", "executeDomQuery", "(", "$", "output", ",", "$", "selector", ")", ";", "$", "this", "->", "assertEquals", "(", "0", ",", "count", "(", "$", "results", ")", ",", "$", "message", ")", ";", "}" ]
Assert that the given string does not contain an element matching the given selector. @since 1.0.0 @param string $selector A query selector for the element to find. @param string $output The output that should not contain the $selector. @param string $message A message to display if the assertion fails.
[ "Assert", "that", "the", "given", "string", "does", "not", "contain", "an", "element", "matching", "the", "given", "selector", "." ]
545ce29918d4d986e26961bf4d380c655583ece9
https://github.com/stevegrunwell/phpunit-markup-assertions/blob/545ce29918d4d986e26961bf4d380c655583ece9/src/MarkupAssertionsTrait.php#L43-L48
29,780
stevegrunwell/phpunit-markup-assertions
src/MarkupAssertionsTrait.php
MarkupAssertionsTrait.assertSelectorCount
public function assertSelectorCount($count, $selector, $output = '', $message = '') { $results = $this->executeDomQuery($output, $selector); $this->assertCount($count, $results, $message); }
php
public function assertSelectorCount($count, $selector, $output = '', $message = '') { $results = $this->executeDomQuery($output, $selector); $this->assertCount($count, $results, $message); }
[ "public", "function", "assertSelectorCount", "(", "$", "count", ",", "$", "selector", ",", "$", "output", "=", "''", ",", "$", "message", "=", "''", ")", "{", "$", "results", "=", "$", "this", "->", "executeDomQuery", "(", "$", "output", ",", "$", "selector", ")", ";", "$", "this", "->", "assertCount", "(", "$", "count", ",", "$", "results", ",", "$", "message", ")", ";", "}" ]
Assert the number of times an element matching the given selector is found. @since 1.0.0 @param int $count The number of matching elements expected. @param string $selector A query selector for the element to find. @param string $output The markup to run the assertion against. @param string $message A message to display if the assertion fails.
[ "Assert", "the", "number", "of", "times", "an", "element", "matching", "the", "given", "selector", "is", "found", "." ]
545ce29918d4d986e26961bf4d380c655583ece9
https://github.com/stevegrunwell/phpunit-markup-assertions/blob/545ce29918d4d986e26961bf4d380c655583ece9/src/MarkupAssertionsTrait.php#L60-L65
29,781
stevegrunwell/phpunit-markup-assertions
src/MarkupAssertionsTrait.php
MarkupAssertionsTrait.assertHasElementWithAttributes
public function assertHasElementWithAttributes($attributes = [], $output = '', $message = '') { $this->assertContainsSelector( '*' . $this->flattenAttributeArray($attributes), $output, $message ); }
php
public function assertHasElementWithAttributes($attributes = [], $output = '', $message = '') { $this->assertContainsSelector( '*' . $this->flattenAttributeArray($attributes), $output, $message ); }
[ "public", "function", "assertHasElementWithAttributes", "(", "$", "attributes", "=", "[", "]", ",", "$", "output", "=", "''", ",", "$", "message", "=", "''", ")", "{", "$", "this", "->", "assertContainsSelector", "(", "'*'", ".", "$", "this", "->", "flattenAttributeArray", "(", "$", "attributes", ")", ",", "$", "output", ",", "$", "message", ")", ";", "}" ]
Assert that an element with the given attributes exists in the given markup. @since 1.0.0 @param array $attributes An array of HTML attributes that should be found on the element. @param string $output The output that should contain an element with the provided $attributes. @param string $message A message to display if the assertion fails.
[ "Assert", "that", "an", "element", "with", "the", "given", "attributes", "exists", "in", "the", "given", "markup", "." ]
545ce29918d4d986e26961bf4d380c655583ece9
https://github.com/stevegrunwell/phpunit-markup-assertions/blob/545ce29918d4d986e26961bf4d380c655583ece9/src/MarkupAssertionsTrait.php#L77-L84
29,782
stevegrunwell/phpunit-markup-assertions
src/MarkupAssertionsTrait.php
MarkupAssertionsTrait.assertNotHasElementWithAttributes
public function assertNotHasElementWithAttributes($attributes = [], $output = '', $message = '') { $this->assertNotContainsSelector( '*' . $this->flattenAttributeArray($attributes), $output, $message ); }
php
public function assertNotHasElementWithAttributes($attributes = [], $output = '', $message = '') { $this->assertNotContainsSelector( '*' . $this->flattenAttributeArray($attributes), $output, $message ); }
[ "public", "function", "assertNotHasElementWithAttributes", "(", "$", "attributes", "=", "[", "]", ",", "$", "output", "=", "''", ",", "$", "message", "=", "''", ")", "{", "$", "this", "->", "assertNotContainsSelector", "(", "'*'", ".", "$", "this", "->", "flattenAttributeArray", "(", "$", "attributes", ")", ",", "$", "output", ",", "$", "message", ")", ";", "}" ]
Assert that an element with the given attributes does not exist in the given markup. @since 1.0.0 @param array $attributes An array of HTML attributes that should be found on the element. @param string $output The output that should not contain an element with the provided $attributes. @param string $message A message to display if the assertion fails.
[ "Assert", "that", "an", "element", "with", "the", "given", "attributes", "does", "not", "exist", "in", "the", "given", "markup", "." ]
545ce29918d4d986e26961bf4d380c655583ece9
https://github.com/stevegrunwell/phpunit-markup-assertions/blob/545ce29918d4d986e26961bf4d380c655583ece9/src/MarkupAssertionsTrait.php#L96-L103
29,783
stevegrunwell/phpunit-markup-assertions
src/MarkupAssertionsTrait.php
MarkupAssertionsTrait.assertElementContains
public function assertElementContains($contents, $selector = '', $output = '', $message = '') { $this->assertContains( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector), $message ); }
php
public function assertElementContains($contents, $selector = '', $output = '', $message = '') { $this->assertContains( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector), $message ); }
[ "public", "function", "assertElementContains", "(", "$", "contents", ",", "$", "selector", "=", "''", ",", "$", "output", "=", "''", ",", "$", "message", "=", "''", ")", "{", "$", "this", "->", "assertContains", "(", "$", "contents", ",", "$", "this", "->", "getInnerHtmlOfMatchedElements", "(", "$", "output", ",", "$", "selector", ")", ",", "$", "message", ")", ";", "}" ]
Assert an element's contents contain the given string. @since 1.1.0 @param string $contents The string to look for within the DOM node's contents. @param string $selector A query selector for the element to find. @param string $output The output that should contain the $selector. @param string $message A message to display if the assertion fails.
[ "Assert", "an", "element", "s", "contents", "contain", "the", "given", "string", "." ]
545ce29918d4d986e26961bf4d380c655583ece9
https://github.com/stevegrunwell/phpunit-markup-assertions/blob/545ce29918d4d986e26961bf4d380c655583ece9/src/MarkupAssertionsTrait.php#L115-L122
29,784
stevegrunwell/phpunit-markup-assertions
src/MarkupAssertionsTrait.php
MarkupAssertionsTrait.assertElementNotContains
public function assertElementNotContains($contents, $selector = '', $output = '', $message = '') { $this->assertNotContains( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector), $message ); }
php
public function assertElementNotContains($contents, $selector = '', $output = '', $message = '') { $this->assertNotContains( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector), $message ); }
[ "public", "function", "assertElementNotContains", "(", "$", "contents", ",", "$", "selector", "=", "''", ",", "$", "output", "=", "''", ",", "$", "message", "=", "''", ")", "{", "$", "this", "->", "assertNotContains", "(", "$", "contents", ",", "$", "this", "->", "getInnerHtmlOfMatchedElements", "(", "$", "output", ",", "$", "selector", ")", ",", "$", "message", ")", ";", "}" ]
Assert an element's contents do not contain the given string. @since 1.1.0 @param string $contents The string to look for within the DOM node's contents. @param string $selector A query selector for the element to find. @param string $output The output that should not contain the $selector. @param string $message A message to display if the assertion fails.
[ "Assert", "an", "element", "s", "contents", "do", "not", "contain", "the", "given", "string", "." ]
545ce29918d4d986e26961bf4d380c655583ece9
https://github.com/stevegrunwell/phpunit-markup-assertions/blob/545ce29918d4d986e26961bf4d380c655583ece9/src/MarkupAssertionsTrait.php#L134-L141
29,785
stevegrunwell/phpunit-markup-assertions
src/MarkupAssertionsTrait.php
MarkupAssertionsTrait.assertElementRegExp
public function assertElementRegExp($regexp, $selector = '', $output = '', $message = '') { $this->assertRegExp( $regexp, $this->getInnerHtmlOfMatchedElements($output, $selector), $message ); }
php
public function assertElementRegExp($regexp, $selector = '', $output = '', $message = '') { $this->assertRegExp( $regexp, $this->getInnerHtmlOfMatchedElements($output, $selector), $message ); }
[ "public", "function", "assertElementRegExp", "(", "$", "regexp", ",", "$", "selector", "=", "''", ",", "$", "output", "=", "''", ",", "$", "message", "=", "''", ")", "{", "$", "this", "->", "assertRegExp", "(", "$", "regexp", ",", "$", "this", "->", "getInnerHtmlOfMatchedElements", "(", "$", "output", ",", "$", "selector", ")", ",", "$", "message", ")", ";", "}" ]
Assert an element's contents contain the given regular expression pattern. @since 1.1.0 @param string $regexp The regular expression pattern to look for within the DOM node. @param string $selector A query selector for the element to find. @param string $output The output that should contain the $selector. @param string $message A message to display if the assertion fails.
[ "Assert", "an", "element", "s", "contents", "contain", "the", "given", "regular", "expression", "pattern", "." ]
545ce29918d4d986e26961bf4d380c655583ece9
https://github.com/stevegrunwell/phpunit-markup-assertions/blob/545ce29918d4d986e26961bf4d380c655583ece9/src/MarkupAssertionsTrait.php#L153-L160
29,786
stevegrunwell/phpunit-markup-assertions
src/MarkupAssertionsTrait.php
MarkupAssertionsTrait.assertElementNotRegExp
public function assertElementNotRegExp($regexp, $selector = '', $output = '', $message = '') { $this->assertNotRegExp( $regexp, $this->getInnerHtmlOfMatchedElements($output, $selector), $message ); }
php
public function assertElementNotRegExp($regexp, $selector = '', $output = '', $message = '') { $this->assertNotRegExp( $regexp, $this->getInnerHtmlOfMatchedElements($output, $selector), $message ); }
[ "public", "function", "assertElementNotRegExp", "(", "$", "regexp", ",", "$", "selector", "=", "''", ",", "$", "output", "=", "''", ",", "$", "message", "=", "''", ")", "{", "$", "this", "->", "assertNotRegExp", "(", "$", "regexp", ",", "$", "this", "->", "getInnerHtmlOfMatchedElements", "(", "$", "output", ",", "$", "selector", ")", ",", "$", "message", ")", ";", "}" ]
Assert an element's contents do not contain the given regular expression pattern. @since 1.1.0 @param string $regexp The regular expression pattern to look for within the DOM node. @param string $selector A query selector for the element to find. @param string $output The output that should not contain the $selector. @param string $message A message to display if the assertion fails.
[ "Assert", "an", "element", "s", "contents", "do", "not", "contain", "the", "given", "regular", "expression", "pattern", "." ]
545ce29918d4d986e26961bf4d380c655583ece9
https://github.com/stevegrunwell/phpunit-markup-assertions/blob/545ce29918d4d986e26961bf4d380c655583ece9/src/MarkupAssertionsTrait.php#L172-L179
29,787
stevegrunwell/phpunit-markup-assertions
src/MarkupAssertionsTrait.php
MarkupAssertionsTrait.flattenAttributeArray
protected function flattenAttributeArray(array $attributes) { if (empty($attributes)) { throw new RiskyTestError('Attributes array is empty.'); } array_walk($attributes, function (&$value, $key) { // Boolean attributes. if (null === $value) { $value = sprintf('[%s]', $key); } else { $value = sprintf('[%s="%s"]', $key, htmlspecialchars($value)); } }); return implode('', $attributes); }
php
protected function flattenAttributeArray(array $attributes) { if (empty($attributes)) { throw new RiskyTestError('Attributes array is empty.'); } array_walk($attributes, function (&$value, $key) { // Boolean attributes. if (null === $value) { $value = sprintf('[%s]', $key); } else { $value = sprintf('[%s="%s"]', $key, htmlspecialchars($value)); } }); return implode('', $attributes); }
[ "protected", "function", "flattenAttributeArray", "(", "array", "$", "attributes", ")", "{", "if", "(", "empty", "(", "$", "attributes", ")", ")", "{", "throw", "new", "RiskyTestError", "(", "'Attributes array is empty.'", ")", ";", "}", "array_walk", "(", "$", "attributes", ",", "function", "(", "&", "$", "value", ",", "$", "key", ")", "{", "// Boolean attributes.", "if", "(", "null", "===", "$", "value", ")", "{", "$", "value", "=", "sprintf", "(", "'[%s]'", ",", "$", "key", ")", ";", "}", "else", "{", "$", "value", "=", "sprintf", "(", "'[%s=\"%s\"]'", ",", "$", "key", ",", "htmlspecialchars", "(", "$", "value", ")", ")", ";", "}", "}", ")", ";", "return", "implode", "(", "''", ",", "$", "attributes", ")", ";", "}" ]
Given an array of HTML attributes, flatten them into a XPath attribute selector. @since 1.0.0 @throws RiskyTestError When the $attributes array is empty. @param array $attributes HTML attributes and their values. @return string A XPath attribute query selector.
[ "Given", "an", "array", "of", "HTML", "attributes", "flatten", "them", "into", "a", "XPath", "attribute", "selector", "." ]
545ce29918d4d986e26961bf4d380c655583ece9
https://github.com/stevegrunwell/phpunit-markup-assertions/blob/545ce29918d4d986e26961bf4d380c655583ece9/src/MarkupAssertionsTrait.php#L209-L225
29,788
stevegrunwell/phpunit-markup-assertions
src/MarkupAssertionsTrait.php
MarkupAssertionsTrait.getInnerHtmlOfMatchedElements
protected function getInnerHtmlOfMatchedElements($markup, $query) { $results = $this->executeDomQuery($markup, $query); $contents = []; // Loop through results and collect their innerHTML values. foreach ($results as $result) { $document = new DOMDocument; $document->appendChild($document->importNode($result->firstChild, true)); $contents[] = trim($document->saveHTML()); } return implode(PHP_EOL, $contents); }
php
protected function getInnerHtmlOfMatchedElements($markup, $query) { $results = $this->executeDomQuery($markup, $query); $contents = []; // Loop through results and collect their innerHTML values. foreach ($results as $result) { $document = new DOMDocument; $document->appendChild($document->importNode($result->firstChild, true)); $contents[] = trim($document->saveHTML()); } return implode(PHP_EOL, $contents); }
[ "protected", "function", "getInnerHtmlOfMatchedElements", "(", "$", "markup", ",", "$", "query", ")", "{", "$", "results", "=", "$", "this", "->", "executeDomQuery", "(", "$", "markup", ",", "$", "query", ")", ";", "$", "contents", "=", "[", "]", ";", "// Loop through results and collect their innerHTML values.", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "document", "=", "new", "DOMDocument", ";", "$", "document", "->", "appendChild", "(", "$", "document", "->", "importNode", "(", "$", "result", "->", "firstChild", ",", "true", ")", ")", ";", "$", "contents", "[", "]", "=", "trim", "(", "$", "document", "->", "saveHTML", "(", ")", ")", ";", "}", "return", "implode", "(", "PHP_EOL", ",", "$", "contents", ")", ";", "}" ]
Given HTML markup and a DOM selector query, collect the innerHTML of the matched selectors. @since 1.1.0 @param string $markup The HTML for the DOMDocument. @param string $query The DOM selector query. @return string The concatenated innerHTML of any matched selectors.
[ "Given", "HTML", "markup", "and", "a", "DOM", "selector", "query", "collect", "the", "innerHTML", "of", "the", "matched", "selectors", "." ]
545ce29918d4d986e26961bf4d380c655583ece9
https://github.com/stevegrunwell/phpunit-markup-assertions/blob/545ce29918d4d986e26961bf4d380c655583ece9/src/MarkupAssertionsTrait.php#L237-L251
29,789
polyfony-inc/polyfony
Private/Polyfony/Thumbnail.php
Thumbnail.source
public function source($path, $override_chroot = false) { // if chroot is enabled, restrict the path to the chroot $this->Source = Filesystem::chroot($path, $override_chroot); // return self return($this); }
php
public function source($path, $override_chroot = false) { // if chroot is enabled, restrict the path to the chroot $this->Source = Filesystem::chroot($path, $override_chroot); // return self return($this); }
[ "public", "function", "source", "(", "$", "path", ",", "$", "override_chroot", "=", "false", ")", "{", "// if chroot is enabled, restrict the path to the chroot", "$", "this", "->", "Source", "=", "Filesystem", "::", "chroot", "(", "$", "path", ",", "$", "override_chroot", ")", ";", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
set the source image path
[ "set", "the", "source", "image", "path" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Thumbnail.php#L57-L62
29,790
polyfony-inc/polyfony
Private/Polyfony/Thumbnail.php
Thumbnail.type
public function type($mimetype) { // if the type is correct if(in_array($mimetype, $this->Allowed)) { // set the type $this->Output = $mimetype; } // return self return($this); }
php
public function type($mimetype) { // if the type is correct if(in_array($mimetype, $this->Allowed)) { // set the type $this->Output = $mimetype; } // return self return($this); }
[ "public", "function", "type", "(", "$", "mimetype", ")", "{", "// if the type is correct", "if", "(", "in_array", "(", "$", "mimetype", ",", "$", "this", "->", "Allowed", ")", ")", "{", "// set the type", "$", "this", "->", "Output", "=", "$", "mimetype", ";", "}", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
set the output type
[ "set", "the", "output", "type" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Thumbnail.php#L73-L81
29,791
polyfony-inc/polyfony
Private/Polyfony/Thumbnail.php
Thumbnail.size
public function size($pixels) { // if the value is acceptable if(is_numeric($pixels) && $pixels >= 16 && $pixels <= 4096) { // set the limit $this->Maximum = intval($pixels); } // return self return($this); }
php
public function size($pixels) { // if the value is acceptable if(is_numeric($pixels) && $pixels >= 16 && $pixels <= 4096) { // set the limit $this->Maximum = intval($pixels); } // return self return($this); }
[ "public", "function", "size", "(", "$", "pixels", ")", "{", "// if the value is acceptable", "if", "(", "is_numeric", "(", "$", "pixels", ")", "&&", "$", "pixels", ">=", "16", "&&", "$", "pixels", "<=", "4096", ")", "{", "// set the limit", "$", "this", "->", "Maximum", "=", "intval", "(", "$", "pixels", ")", ";", "}", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
set the size
[ "set", "the", "size" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Thumbnail.php#L84-L92
29,792
polyfony-inc/polyfony
Private/Polyfony/Thumbnail.php
Thumbnail.quality
public function quality($quality) { // if the value is acceptable if(is_numeric($quality) && $quality >= 10 && $quality <= 100) { // set the quality $this->Quality = intval($quality); } // return self return($this); }
php
public function quality($quality) { // if the value is acceptable if(is_numeric($quality) && $quality >= 10 && $quality <= 100) { // set the quality $this->Quality = intval($quality); } // return self return($this); }
[ "public", "function", "quality", "(", "$", "quality", ")", "{", "// if the value is acceptable", "if", "(", "is_numeric", "(", "$", "quality", ")", "&&", "$", "quality", ">=", "10", "&&", "$", "quality", "<=", "100", ")", "{", "// set the quality", "$", "this", "->", "Quality", "=", "intval", "(", "$", "quality", ")", ";", "}", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
set the quality
[ "set", "the", "quality" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Thumbnail.php#L95-L103
29,793
ventoviro/windwalker-core
src/Core/Asset/AssetManager.php
AssetManager.exists
public function exists($uri, $strict = false) { if (static::isAbsoluteUrl($uri)) { return $uri; } $assetUri = $this->path; if (static::isAbsoluteUrl($assetUri)) { return rtrim($assetUri, '/') . '/' . ltrim($uri, '/'); } $root = $this->addSysPath($assetUri); $this->normalizeUri($uri, $assetFile, $assetMinFile); if (is_file($root . '/' . $uri)) { return $this->addBase($uri, 'path'); } if (!$strict) { if (is_file($root . '/' . $assetFile)) { return $this->addBase($assetFile, 'path'); } if (is_file($root . '/' . $assetMinFile)) { return $this->addBase($assetMinFile, 'path'); } } return false; }
php
public function exists($uri, $strict = false) { if (static::isAbsoluteUrl($uri)) { return $uri; } $assetUri = $this->path; if (static::isAbsoluteUrl($assetUri)) { return rtrim($assetUri, '/') . '/' . ltrim($uri, '/'); } $root = $this->addSysPath($assetUri); $this->normalizeUri($uri, $assetFile, $assetMinFile); if (is_file($root . '/' . $uri)) { return $this->addBase($uri, 'path'); } if (!$strict) { if (is_file($root . '/' . $assetFile)) { return $this->addBase($assetFile, 'path'); } if (is_file($root . '/' . $assetMinFile)) { return $this->addBase($assetMinFile, 'path'); } } return false; }
[ "public", "function", "exists", "(", "$", "uri", ",", "$", "strict", "=", "false", ")", "{", "if", "(", "static", "::", "isAbsoluteUrl", "(", "$", "uri", ")", ")", "{", "return", "$", "uri", ";", "}", "$", "assetUri", "=", "$", "this", "->", "path", ";", "if", "(", "static", "::", "isAbsoluteUrl", "(", "$", "assetUri", ")", ")", "{", "return", "rtrim", "(", "$", "assetUri", ",", "'/'", ")", ".", "'/'", ".", "ltrim", "(", "$", "uri", ",", "'/'", ")", ";", "}", "$", "root", "=", "$", "this", "->", "addSysPath", "(", "$", "assetUri", ")", ";", "$", "this", "->", "normalizeUri", "(", "$", "uri", ",", "$", "assetFile", ",", "$", "assetMinFile", ")", ";", "if", "(", "is_file", "(", "$", "root", ".", "'/'", ".", "$", "uri", ")", ")", "{", "return", "$", "this", "->", "addBase", "(", "$", "uri", ",", "'path'", ")", ";", "}", "if", "(", "!", "$", "strict", ")", "{", "if", "(", "is_file", "(", "$", "root", ".", "'/'", ".", "$", "assetFile", ")", ")", "{", "return", "$", "this", "->", "addBase", "(", "$", "assetFile", ",", "'path'", ")", ";", "}", "if", "(", "is_file", "(", "$", "root", ".", "'/'", ".", "$", "assetMinFile", ")", ")", "{", "return", "$", "this", "->", "addBase", "(", "$", "assetMinFile", ",", "'path'", ")", ";", "}", "}", "return", "false", ";", "}" ]
Check asset uri exists in system and return actual path. @param string $uri The file uri to check. @param bool $strict Check .min file or un-min file exists again if input file not exists. @return bool|string @since 3.3
[ "Check", "asset", "uri", "exists", "in", "system", "and", "return", "actual", "path", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Asset/AssetManager.php#L269-L300
29,794
ventoviro/windwalker-core
src/Core/Asset/AssetManager.php
AssetManager.root
public function root($uri = null, $version = false) { if ($version === true) { $version = $this->getVersion(); } if ($version) { if (strpos($uri, '?') !== false) { $uri .= '&' . $version; } else { $uri .= '?' . $version; } } if ($uri !== null) { return $this->root . '/' . $uri; } return $this->root; }
php
public function root($uri = null, $version = false) { if ($version === true) { $version = $this->getVersion(); } if ($version) { if (strpos($uri, '?') !== false) { $uri .= '&' . $version; } else { $uri .= '?' . $version; } } if ($uri !== null) { return $this->root . '/' . $uri; } return $this->root; }
[ "public", "function", "root", "(", "$", "uri", "=", "null", ",", "$", "version", "=", "false", ")", "{", "if", "(", "$", "version", "===", "true", ")", "{", "$", "version", "=", "$", "this", "->", "getVersion", "(", ")", ";", "}", "if", "(", "$", "version", ")", "{", "if", "(", "strpos", "(", "$", "uri", ",", "'?'", ")", "!==", "false", ")", "{", "$", "uri", ".=", "'&'", ".", "$", "version", ";", "}", "else", "{", "$", "uri", ".=", "'?'", ".", "$", "version", ";", "}", "}", "if", "(", "$", "uri", "!==", "null", ")", "{", "return", "$", "this", "->", "root", ".", "'/'", ".", "$", "uri", ";", "}", "return", "$", "this", "->", "root", ";", "}" ]
Method to get property Root @param string $uri @param bool $version @return string
[ "Method", "to", "get", "property", "Root" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Asset/AssetManager.php#L1021-L1040
29,795
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/redmine/User.php
User.fetchAll
static public function fetchAll(Fedora $fedora, bool $progressBar): array { $param = 'limit=100000&key=' . urlencode(RC::get('redmineApiKey')); return self::redmineFetchLoop($fedora, $progressBar, 'users', $param); }
php
static public function fetchAll(Fedora $fedora, bool $progressBar): array { $param = 'limit=100000&key=' . urlencode(RC::get('redmineApiKey')); return self::redmineFetchLoop($fedora, $progressBar, 'users', $param); }
[ "static", "public", "function", "fetchAll", "(", "Fedora", "$", "fedora", ",", "bool", "$", "progressBar", ")", ":", "array", "{", "$", "param", "=", "'limit=100000&key='", ".", "urlencode", "(", "RC", "::", "get", "(", "'redmineApiKey'", ")", ")", ";", "return", "self", "::", "redmineFetchLoop", "(", "$", "fedora", ",", "$", "progressBar", ",", "'users'", ",", "$", "param", ")", ";", "}" ]
Returns array of all User objects which can be fetched from the Redmine. See the Redmine::fetchAll() description for details; @param \acdhOeaw\fedora\Fedora $fedora Fedora connection @param bool $progressBar should progress bar be displayed (makes sense only if the standard output is a console) @return array @see Redmine::fetchAll()
[ "Returns", "array", "of", "all", "User", "objects", "which", "can", "be", "fetched", "from", "the", "Redmine", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/redmine/User.php#L56-L59
29,796
ventoviro/windwalker-core
src/Core/Ioc.php
Ioc.share
public function share($key, $callback, $name = null) { return static::factory($name)->share($key, $callback); }
php
public function share($key, $callback, $name = null) { return static::factory($name)->share($key, $callback); }
[ "public", "function", "share", "(", "$", "key", ",", "$", "callback", ",", "$", "name", "=", "null", ")", "{", "return", "static", "::", "factory", "(", "$", "name", ")", "->", "share", "(", "$", "key", ",", "$", "callback", ")", ";", "}" ]
Convenience method for creating shared keys. @param string $key Name of dataStore key to set. @param callable $callback Callable function to run when requesting the specified $key. @param string $name Container name. @return Container This object for chaining. @since 2.0
[ "Convenience", "method", "for", "creating", "shared", "keys", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Ioc.php#L401-L404
29,797
crcms/microservice-framework
src/Foundation/Exceptions/ExceptionHandler.php
ExceptionHandler.convertExceptionToServiceException
protected function convertExceptionToServiceException(Exception $e): ServiceException { $exception = get_class($e); $conversion = $this->container['config']->get('exception.conversion', []); if (isset($conversion[$exception])) { return new $conversion[$exception]($e->getMessage(), $e->getCode(), $e); } /*else if (in_array($exception, $conversion, true)) { return new ServiceException($e->getMessage(), 400, $e); }*/ else { $statusCode = method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 400; return new ServiceException($e->getMessage(), $statusCode, $e); } }
php
protected function convertExceptionToServiceException(Exception $e): ServiceException { $exception = get_class($e); $conversion = $this->container['config']->get('exception.conversion', []); if (isset($conversion[$exception])) { return new $conversion[$exception]($e->getMessage(), $e->getCode(), $e); } /*else if (in_array($exception, $conversion, true)) { return new ServiceException($e->getMessage(), 400, $e); }*/ else { $statusCode = method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 400; return new ServiceException($e->getMessage(), $statusCode, $e); } }
[ "protected", "function", "convertExceptionToServiceException", "(", "Exception", "$", "e", ")", ":", "ServiceException", "{", "$", "exception", "=", "get_class", "(", "$", "e", ")", ";", "$", "conversion", "=", "$", "this", "->", "container", "[", "'config'", "]", "->", "get", "(", "'exception.conversion'", ",", "[", "]", ")", ";", "if", "(", "isset", "(", "$", "conversion", "[", "$", "exception", "]", ")", ")", "{", "return", "new", "$", "conversion", "[", "$", "exception", "]", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "/*else if (in_array($exception, $conversion, true)) {\n return new ServiceException($e->getMessage(), 400, $e);\n }*/", "else", "{", "$", "statusCode", "=", "method_exists", "(", "$", "e", ",", "'getStatusCode'", ")", "?", "$", "e", "->", "getStatusCode", "(", ")", ":", "400", ";", "return", "new", "ServiceException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "statusCode", ",", "$", "e", ")", ";", "}", "}" ]
Convert other exception to service exception. @param Exception $e @return ServiceException
[ "Convert", "other", "exception", "to", "service", "exception", "." ]
7ad513562e333599642d5697ee45572d7d9e713d
https://github.com/crcms/microservice-framework/blob/7ad513562e333599642d5697ee45572d7d9e713d/src/Foundation/Exceptions/ExceptionHandler.php#L159-L173
29,798
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getUri
public function getUri(bool $standardized = false): string { if ($standardized) { return $this->fedora->standardizeUri($this->uri); } else { return $this->fedora->sanitizeUri($this->uri); } }
php
public function getUri(bool $standardized = false): string { if ($standardized) { return $this->fedora->standardizeUri($this->uri); } else { return $this->fedora->sanitizeUri($this->uri); } }
[ "public", "function", "getUri", "(", "bool", "$", "standardized", "=", "false", ")", ":", "string", "{", "if", "(", "$", "standardized", ")", "{", "return", "$", "this", "->", "fedora", "->", "standardizeUri", "(", "$", "this", "->", "uri", ")", ";", "}", "else", "{", "return", "$", "this", "->", "fedora", "->", "sanitizeUri", "(", "$", "this", "->", "uri", ")", ";", "}", "}" ]
Returns resource's Fedora URI @param bool $standardized should the Uri be standardized (in the form used in a triplestore) or current Fedora connection specific @return string
[ "Returns", "resource", "s", "Fedora", "URI" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L158-L164
29,799
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getId
public function getId(): string { $ids = $this->getIds(); if (count($ids) === 0) { throw new NoAcdhId(); } $acdhId = null; foreach ($ids as $id) { $inIdNmsp = strpos($id, RC::idNmsp()) === 0; $inVocabsNmsp = strpos($id, RC::vocabsNmsp()) === 0; if ($inIdNmsp || $inVocabsNmsp) { if ($acdhId !== null) { throw new ManyAcdhIds(); } $acdhId = $id; } } if ($acdhId === null) { throw new NoAcdhId(); } return $acdhId; }
php
public function getId(): string { $ids = $this->getIds(); if (count($ids) === 0) { throw new NoAcdhId(); } $acdhId = null; foreach ($ids as $id) { $inIdNmsp = strpos($id, RC::idNmsp()) === 0; $inVocabsNmsp = strpos($id, RC::vocabsNmsp()) === 0; if ($inIdNmsp || $inVocabsNmsp) { if ($acdhId !== null) { throw new ManyAcdhIds(); } $acdhId = $id; } } if ($acdhId === null) { throw new NoAcdhId(); } return $acdhId; }
[ "public", "function", "getId", "(", ")", ":", "string", "{", "$", "ids", "=", "$", "this", "->", "getIds", "(", ")", ";", "if", "(", "count", "(", "$", "ids", ")", "===", "0", ")", "{", "throw", "new", "NoAcdhId", "(", ")", ";", "}", "$", "acdhId", "=", "null", ";", "foreach", "(", "$", "ids", "as", "$", "id", ")", "{", "$", "inIdNmsp", "=", "strpos", "(", "$", "id", ",", "RC", "::", "idNmsp", "(", ")", ")", "===", "0", ";", "$", "inVocabsNmsp", "=", "strpos", "(", "$", "id", ",", "RC", "::", "vocabsNmsp", "(", ")", ")", "===", "0", ";", "if", "(", "$", "inIdNmsp", "||", "$", "inVocabsNmsp", ")", "{", "if", "(", "$", "acdhId", "!==", "null", ")", "{", "throw", "new", "ManyAcdhIds", "(", ")", ";", "}", "$", "acdhId", "=", "$", "id", ";", "}", "}", "if", "(", "$", "acdhId", "===", "null", ")", "{", "throw", "new", "NoAcdhId", "(", ")", ";", "}", "return", "$", "acdhId", ";", "}" ]
Returns resource's ACDH UUID. If there is no or are many ACDH UUIDs, an error is thrown. @return string @throws RuntimeException @see getIds()
[ "Returns", "resource", "s", "ACDH", "UUID", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L175-L195