repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
ArkEcosystem/php-crypto
src/Identities/PrivateKey.php
PrivateKey.fromWif
public static function fromWif(string $wif, AbstractNetwork $network = null): EcPrivateKey { return (new PrivateKeyFactory())->fromWif($wif, $network); }
php
public static function fromWif(string $wif, AbstractNetwork $network = null): EcPrivateKey { return (new PrivateKeyFactory())->fromWif($wif, $network); }
[ "public", "static", "function", "fromWif", "(", "string", "$", "wif", ",", "AbstractNetwork", "$", "network", "=", "null", ")", ":", "EcPrivateKey", "{", "return", "(", "new", "PrivateKeyFactory", "(", ")", ")", "->", "fromWif", "(", "$", "wif", ",", "$", "network", ")", ";", "}" ]
Derive the private key for the given WIF. @param string $wif @param \ArkEcosystem\Crypto\Networks\AbstractNetwork|null $network @return \BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Key\PrivateKey
[ "Derive", "the", "private", "key", "for", "the", "given", "WIF", "." ]
6b0a597ec056991d355b214e5afd209c7cccaa66
https://github.com/ArkEcosystem/php-crypto/blob/6b0a597ec056991d355b214e5afd209c7cccaa66/src/Identities/PrivateKey.php#L63-L66
train
ArkEcosystem/php-crypto
src/Utils/Message.php
Message.sign
public static function sign(string $message, string $passphrase): self { $keys = PrivateKey::fromPassphrase($passphrase); return static::new([ 'publickey' => $keys->getPublicKey()->getHex(), 'signature' => $keys->sign(Hash::sha256(new Buffer($message)))->getBuffer()->getHex(), 'message' => $message, ]); }
php
public static function sign(string $message, string $passphrase): self { $keys = PrivateKey::fromPassphrase($passphrase); return static::new([ 'publickey' => $keys->getPublicKey()->getHex(), 'signature' => $keys->sign(Hash::sha256(new Buffer($message)))->getBuffer()->getHex(), 'message' => $message, ]); }
[ "public", "static", "function", "sign", "(", "string", "$", "message", ",", "string", "$", "passphrase", ")", ":", "self", "{", "$", "keys", "=", "PrivateKey", "::", "fromPassphrase", "(", "$", "passphrase", ")", ";", "return", "static", "::", "new", "(", "[", "'publickey'", "=>", "$", "keys", "->", "getPublicKey", "(", ")", "->", "getHex", "(", ")", ",", "'signature'", "=>", "$", "keys", "->", "sign", "(", "Hash", "::", "sha256", "(", "new", "Buffer", "(", "$", "message", ")", ")", ")", "->", "getBuffer", "(", ")", "->", "getHex", "(", ")", ",", "'message'", "=>", "$", "message", ",", "]", ")", ";", "}" ]
Sign a message using the given passphrase. @param string $message @param string $passphrase @return \ArkEcosystem\Crypto\Message
[ "Sign", "a", "message", "using", "the", "given", "passphrase", "." ]
6b0a597ec056991d355b214e5afd209c7cccaa66
https://github.com/ArkEcosystem/php-crypto/blob/6b0a597ec056991d355b214e5afd209c7cccaa66/src/Utils/Message.php#L112-L121
train
ArkEcosystem/php-crypto
src/Utils/Message.php
Message.verify
public function verify(): bool { $factory = new PublicKeyFactory; return $factory->fromHex($this->publicKey)->verify( new Buffer(hash('sha256', $this->message, true)), SignatureFactory::fromHex($this->signature) ); }
php
public function verify(): bool { $factory = new PublicKeyFactory; return $factory->fromHex($this->publicKey)->verify( new Buffer(hash('sha256', $this->message, true)), SignatureFactory::fromHex($this->signature) ); }
[ "public", "function", "verify", "(", ")", ":", "bool", "{", "$", "factory", "=", "new", "PublicKeyFactory", ";", "return", "$", "factory", "->", "fromHex", "(", "$", "this", "->", "publicKey", ")", "->", "verify", "(", "new", "Buffer", "(", "hash", "(", "'sha256'", ",", "$", "this", "->", "message", ",", "true", ")", ")", ",", "SignatureFactory", "::", "fromHex", "(", "$", "this", "->", "signature", ")", ")", ";", "}" ]
Verify the message contents. @return bool
[ "Verify", "the", "message", "contents", "." ]
6b0a597ec056991d355b214e5afd209c7cccaa66
https://github.com/ArkEcosystem/php-crypto/blob/6b0a597ec056991d355b214e5afd209c7cccaa66/src/Utils/Message.php#L128-L136
train
silverstripe/cwp-search
src/CwpSearchEngine.php
CwpSearchEngine.getSearchQuery
protected function getSearchQuery($keywords, $classes) { $query = new SearchQuery(); $query->classes = $classes; $query->addSearchTerm($keywords); $query->addExclude(SiteTree::class . '_ShowInSearch', 0); // Artificially lower the amount of results to prevent too high resource usage. // on subsequent canView check loop. $query->setLimit(100); // Allow user code to modify the search query before returning it $this->extend('updateSearchQuery', $query); return $query; }
php
protected function getSearchQuery($keywords, $classes) { $query = new SearchQuery(); $query->classes = $classes; $query->addSearchTerm($keywords); $query->addExclude(SiteTree::class . '_ShowInSearch', 0); // Artificially lower the amount of results to prevent too high resource usage. // on subsequent canView check loop. $query->setLimit(100); // Allow user code to modify the search query before returning it $this->extend('updateSearchQuery', $query); return $query; }
[ "protected", "function", "getSearchQuery", "(", "$", "keywords", ",", "$", "classes", ")", "{", "$", "query", "=", "new", "SearchQuery", "(", ")", ";", "$", "query", "->", "classes", "=", "$", "classes", ";", "$", "query", "->", "addSearchTerm", "(", "$", "keywords", ")", ";", "$", "query", "->", "addExclude", "(", "SiteTree", "::", "class", ".", "'_ShowInSearch'", ",", "0", ")", ";", "// Artificially lower the amount of results to prevent too high resource usage.", "// on subsequent canView check loop.", "$", "query", "->", "setLimit", "(", "100", ")", ";", "// Allow user code to modify the search query before returning it", "$", "this", "->", "extend", "(", "'updateSearchQuery'", ",", "$", "query", ")", ";", "return", "$", "query", ";", "}" ]
Build a SearchQuery for a new search @param string $keywords @param array $classes @return SearchQuery
[ "Build", "a", "SearchQuery", "for", "a", "new", "search" ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/CwpSearchEngine.php#L56-L71
train
silverstripe/cwp-search
src/CwpSearchEngine.php
CwpSearchEngine.getSearchOptions
protected function getSearchOptions($spellcheck) { $options = $this->config()->get('search_options'); if ($spellcheck) { $options = array_merge($options, $this->config()->get('spellcheck_options')); } return $options; }
php
protected function getSearchOptions($spellcheck) { $options = $this->config()->get('search_options'); if ($spellcheck) { $options = array_merge($options, $this->config()->get('spellcheck_options')); } return $options; }
[ "protected", "function", "getSearchOptions", "(", "$", "spellcheck", ")", "{", "$", "options", "=", "$", "this", "->", "config", "(", ")", "->", "get", "(", "'search_options'", ")", ";", "if", "(", "$", "spellcheck", ")", "{", "$", "options", "=", "array_merge", "(", "$", "options", ",", "$", "this", "->", "config", "(", ")", "->", "get", "(", "'spellcheck_options'", ")", ")", ";", "}", "return", "$", "options", ";", "}" ]
Get solr search options for this query @param bool $spellcheck True if we should include spellcheck support @return array
[ "Get", "solr", "search", "options", "for", "this", "query" ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/CwpSearchEngine.php#L79-L86
train
silverstripe/cwp-search
src/CwpSearchEngine.php
CwpSearchEngine.getResult
protected function getResult($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $spellcheck = false) { // Prepare options $query = $this->getSearchQuery($keywords, $classes); $options = $this->getSearchOptions($spellcheck); // Get results $solrResult = $searchIndex->search( $query, $start, $limit, $options ); return CwpSearchResult::create($keywords, $solrResult); }
php
protected function getResult($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $spellcheck = false) { // Prepare options $query = $this->getSearchQuery($keywords, $classes); $options = $this->getSearchOptions($spellcheck); // Get results $solrResult = $searchIndex->search( $query, $start, $limit, $options ); return CwpSearchResult::create($keywords, $solrResult); }
[ "protected", "function", "getResult", "(", "$", "keywords", ",", "$", "classes", ",", "$", "searchIndex", ",", "$", "limit", "=", "-", "1", ",", "$", "start", "=", "0", ",", "$", "spellcheck", "=", "false", ")", "{", "// Prepare options", "$", "query", "=", "$", "this", "->", "getSearchQuery", "(", "$", "keywords", ",", "$", "classes", ")", ";", "$", "options", "=", "$", "this", "->", "getSearchOptions", "(", "$", "spellcheck", ")", ";", "// Get results", "$", "solrResult", "=", "$", "searchIndex", "->", "search", "(", "$", "query", ",", "$", "start", ",", "$", "limit", ",", "$", "options", ")", ";", "return", "CwpSearchResult", "::", "create", "(", "$", "keywords", ",", "$", "solrResult", ")", ";", "}" ]
Get results for a search term @param string $keywords @param array $classes @param SolrIndex $searchIndex @param int $limit Max number of results for this page @param int $start Skip this number of records @param bool $spellcheck True to enable spellcheck @return CwpSearchResult
[ "Get", "results", "for", "a", "search", "term" ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/CwpSearchEngine.php#L99-L114
train
silverstripe/cwp-search
src/CwpSearchEngine.php
CwpSearchEngine.search
public function search($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $followSuggestions = false) { if (empty($keywords)) { return null; } try { // Begin search $result = $this->getResult($keywords, $classes, $searchIndex, $limit, $start, true); // Return results if we don't need to refine this any further if (!$followSuggestions || $result->hasResults() || !$result->getSuggestion()) { return $result; } // Perform new search with the suggested terms $suggested = $result->getSuggestion(); $newResult = $this->getResult($suggested, $classes, $searchIndex, $limit, $start, false); $newResult->setOriginal($keywords); // Compare new results to the original query if ($newResult->hasResults()) { return $newResult; } return $result; } catch (Exception $e) { Injector::inst()->get(LoggerInterface::class)->warning($e); } }
php
public function search($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $followSuggestions = false) { if (empty($keywords)) { return null; } try { // Begin search $result = $this->getResult($keywords, $classes, $searchIndex, $limit, $start, true); // Return results if we don't need to refine this any further if (!$followSuggestions || $result->hasResults() || !$result->getSuggestion()) { return $result; } // Perform new search with the suggested terms $suggested = $result->getSuggestion(); $newResult = $this->getResult($suggested, $classes, $searchIndex, $limit, $start, false); $newResult->setOriginal($keywords); // Compare new results to the original query if ($newResult->hasResults()) { return $newResult; } return $result; } catch (Exception $e) { Injector::inst()->get(LoggerInterface::class)->warning($e); } }
[ "public", "function", "search", "(", "$", "keywords", ",", "$", "classes", ",", "$", "searchIndex", ",", "$", "limit", "=", "-", "1", ",", "$", "start", "=", "0", ",", "$", "followSuggestions", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "keywords", ")", ")", "{", "return", "null", ";", "}", "try", "{", "// Begin search", "$", "result", "=", "$", "this", "->", "getResult", "(", "$", "keywords", ",", "$", "classes", ",", "$", "searchIndex", ",", "$", "limit", ",", "$", "start", ",", "true", ")", ";", "// Return results if we don't need to refine this any further", "if", "(", "!", "$", "followSuggestions", "||", "$", "result", "->", "hasResults", "(", ")", "||", "!", "$", "result", "->", "getSuggestion", "(", ")", ")", "{", "return", "$", "result", ";", "}", "// Perform new search with the suggested terms", "$", "suggested", "=", "$", "result", "->", "getSuggestion", "(", ")", ";", "$", "newResult", "=", "$", "this", "->", "getResult", "(", "$", "suggested", ",", "$", "classes", ",", "$", "searchIndex", ",", "$", "limit", ",", "$", "start", ",", "false", ")", ";", "$", "newResult", "->", "setOriginal", "(", "$", "keywords", ")", ";", "// Compare new results to the original query", "if", "(", "$", "newResult", "->", "hasResults", "(", ")", ")", "{", "return", "$", "newResult", ";", "}", "return", "$", "result", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "Injector", "::", "inst", "(", ")", "->", "get", "(", "LoggerInterface", "::", "class", ")", "->", "warning", "(", "$", "e", ")", ";", "}", "}" ]
Get a CwpSearchResult for a given criterea @param string $keywords @param array $classes @param SolrIndex $searchIndex @param int $limit Max number of results for this page @param int $start Skip this number of records @param bool $followSuggestions True to enable suggested searches to be returned immediately @return CwpSearchResult|null
[ "Get", "a", "CwpSearchResult", "for", "a", "given", "criterea" ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/CwpSearchEngine.php#L127-L156
train
basecrm/basecrm-php
lib/HttpClient.php
HttpClient.unwrapEnvelope
protected function unwrapEnvelope(array $body) { if (isset($body['data'])) { return $body['data']; } else if (isset($body['items'])) { $items = array(); foreach ($body['items'] as $item) { $items[] = $item; } return $items; } return $body; }
php
protected function unwrapEnvelope(array $body) { if (isset($body['data'])) { return $body['data']; } else if (isset($body['items'])) { $items = array(); foreach ($body['items'] as $item) { $items[] = $item; } return $items; } return $body; }
[ "protected", "function", "unwrapEnvelope", "(", "array", "$", "body", ")", "{", "if", "(", "isset", "(", "$", "body", "[", "'data'", "]", ")", ")", "{", "return", "$", "body", "[", "'data'", "]", ";", "}", "else", "if", "(", "isset", "(", "$", "body", "[", "'items'", "]", ")", ")", "{", "$", "items", "=", "array", "(", ")", ";", "foreach", "(", "$", "body", "[", "'items'", "]", "as", "$", "item", ")", "{", "$", "items", "[", "]", "=", "$", "item", ";", "}", "return", "$", "items", ";", "}", "return", "$", "body", ";", "}" ]
Perform envelope unwrapping @param array $body Associative array after json decoding. @return mixed Either single resource or array of associative resources. @ignore
[ "Perform", "envelope", "unwrapping" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/HttpClient.php#L189-L206
train
basecrm/basecrm-php
lib/HttpClient.php
HttpClient.encodePayload
protected function encodePayload(array $params) { $encoded = []; foreach ($params as $key => $value) { if (is_array($value)) $encoded[$key] = $this->encodePayload($value); else if ($value instanceof \DateTime) $encoded[$key] = $value->format(\DateTime::ISO8601); else $encoded[$key] = $value; } return $encoded; }
php
protected function encodePayload(array $params) { $encoded = []; foreach ($params as $key => $value) { if (is_array($value)) $encoded[$key] = $this->encodePayload($value); else if ($value instanceof \DateTime) $encoded[$key] = $value->format(\DateTime::ISO8601); else $encoded[$key] = $value; } return $encoded; }
[ "protected", "function", "encodePayload", "(", "array", "$", "params", ")", "{", "$", "encoded", "=", "[", "]", ";", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "$", "encoded", "[", "$", "key", "]", "=", "$", "this", "->", "encodePayload", "(", "$", "value", ")", ";", "else", "if", "(", "$", "value", "instanceof", "\\", "DateTime", ")", "$", "encoded", "[", "$", "key", "]", "=", "$", "value", "->", "format", "(", "\\", "DateTime", "::", "ISO8601", ")", ";", "else", "$", "encoded", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "encoded", ";", "}" ]
Ensure consistency in encoding between native PHP types and Base API expected types. @param array $params Associative array of either wrapped or unwrapped payload to be send. @return array Associative array with properly handled data types @ignore
[ "Ensure", "consistency", "in", "encoding", "between", "native", "PHP", "types", "and", "Base", "API", "expected", "types", "." ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/HttpClient.php#L216-L227
train
basecrm/basecrm-php
lib/HttpClient.php
HttpClient.encodeQueryParams
protected function encodeQueryParams(array $params) { $encoded = []; foreach ($params as $key => $value) { if (is_array($value)) $encoded[$key] = $this->encodeQueryParams($value); else if (is_bool($value)) $encoded[$key] = $value ? 'true' : 'false'; else if ($value instanceof \DateTime) $encoded[$key] = $value->format(\DateTime::ISO8601); else $encoded[$key] = $value; } return $encoded; }
php
protected function encodeQueryParams(array $params) { $encoded = []; foreach ($params as $key => $value) { if (is_array($value)) $encoded[$key] = $this->encodeQueryParams($value); else if (is_bool($value)) $encoded[$key] = $value ? 'true' : 'false'; else if ($value instanceof \DateTime) $encoded[$key] = $value->format(\DateTime::ISO8601); else $encoded[$key] = $value; } return $encoded; }
[ "protected", "function", "encodeQueryParams", "(", "array", "$", "params", ")", "{", "$", "encoded", "=", "[", "]", ";", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "$", "encoded", "[", "$", "key", "]", "=", "$", "this", "->", "encodeQueryParams", "(", "$", "value", ")", ";", "else", "if", "(", "is_bool", "(", "$", "value", ")", ")", "$", "encoded", "[", "$", "key", "]", "=", "$", "value", "?", "'true'", ":", "'false'", ";", "else", "if", "(", "$", "value", "instanceof", "\\", "DateTime", ")", "$", "encoded", "[", "$", "key", "]", "=", "$", "value", "->", "format", "(", "\\", "DateTime", "::", "ISO8601", ")", ";", "else", "$", "encoded", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "encoded", ";", "}" ]
Ensure consistency in encoding between native PHP types and Base API expected query type format. @param array $params Associative array of query parameters to be send. @return array Associative array with properly handled data types @ignore
[ "Ensure", "consistency", "in", "encoding", "between", "native", "PHP", "types", "and", "Base", "API", "expected", "query", "type", "format", "." ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/HttpClient.php#L237-L249
train
basecrm/basecrm-php
lib/TasksService.php
TasksService.all
public function all($params = [], array $options = array()) { list($code, $tasks) = $this->httpClient->get("/tasks", $params, $options); return $tasks; }
php
public function all($params = [], array $options = array()) { list($code, $tasks) = $this->httpClient->get("/tasks", $params, $options); return $tasks; }
[ "public", "function", "all", "(", "$", "params", "=", "[", "]", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "list", "(", "$", "code", ",", "$", "tasks", ")", "=", "$", "this", "->", "httpClient", "->", "get", "(", "\"/tasks\"", ",", "$", "params", ",", "$", "options", ")", ";", "return", "$", "tasks", ";", "}" ]
Retrieve all tasks get '/tasks' Returns all tasks available to the user, according to the parameters provided If you ask for tasks without any parameter provided Base API will return you both **floating** and **related** tasks Although you can narrow the search set to either of them via query parameters @param array $params Search options @param array $options Additional request's options. @return array The list of Tasks for the first page, unless otherwise specified.
[ "Retrieve", "all", "tasks" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/TasksService.php#L43-L47
train
basecrm/basecrm-php
lib/TasksService.php
TasksService.create
public function create(array $task, array $options = array()) { $attributes = array_intersect_key($task, array_flip(self::$keysToPersist)); list($code, $createdTask) = $this->httpClient->post("/tasks", $attributes, $options); return $createdTask; }
php
public function create(array $task, array $options = array()) { $attributes = array_intersect_key($task, array_flip(self::$keysToPersist)); list($code, $createdTask) = $this->httpClient->post("/tasks", $attributes, $options); return $createdTask; }
[ "public", "function", "create", "(", "array", "$", "task", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "task", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "createdTask", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "\"/tasks\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "createdTask", ";", "}" ]
Create a task post '/tasks' Creates a new task You can create either a **floating** task or create a **related** task and associate it with one of the resource types below: * [Leads](/docs/rest/reference/leads) * [Contacts](/docs/rest/reference/contacts) * [Deals](/docs/rest/reference/deals) @param array $task This array's attributes describe the object to be created. @param array $options Additional request's options. @return array The resulting object representing created resource.
[ "Create", "a", "task" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/TasksService.php#L65-L71
train
silverstripe/cwp-search
src/CwpSearchResult.php
CwpSearchResult.getLink
protected function getLink($terms, $format = null) { if (!$terms) { return null; } $link = 'search/SearchForm?Search='.rawurlencode($terms); if ($format) { $link .= '&format='.rawurlencode($format); } return $link; }
php
protected function getLink($terms, $format = null) { if (!$terms) { return null; } $link = 'search/SearchForm?Search='.rawurlencode($terms); if ($format) { $link .= '&format='.rawurlencode($format); } return $link; }
[ "protected", "function", "getLink", "(", "$", "terms", ",", "$", "format", "=", "null", ")", "{", "if", "(", "!", "$", "terms", ")", "{", "return", "null", ";", "}", "$", "link", "=", "'search/SearchForm?Search='", ".", "rawurlencode", "(", "$", "terms", ")", ";", "if", "(", "$", "format", ")", "{", "$", "link", ".=", "'&format='", ".", "rawurlencode", "(", "$", "format", ")", ";", "}", "return", "$", "link", ";", "}" ]
Get a search link for given terms @param string $terms @return string|null
[ "Get", "a", "search", "link", "for", "given", "terms" ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/CwpSearchResult.php#L197-L207
train
rockettheme/toolbox
File/src/YamlFile.php
YamlFile.setting
public function setting($setting, $default = null) { $value = parent::setting($setting); if (null === $value) { $value = isset(static::$globalSettings[$setting]) ? static::$globalSettings[$setting] : $default; } return $value; }
php
public function setting($setting, $default = null) { $value = parent::setting($setting); if (null === $value) { $value = isset(static::$globalSettings[$setting]) ? static::$globalSettings[$setting] : $default; } return $value; }
[ "public", "function", "setting", "(", "$", "setting", ",", "$", "default", "=", "null", ")", "{", "$", "value", "=", "parent", "::", "setting", "(", "$", "setting", ")", ";", "if", "(", "null", "===", "$", "value", ")", "{", "$", "value", "=", "isset", "(", "static", "::", "$", "globalSettings", "[", "$", "setting", "]", ")", "?", "static", "::", "$", "globalSettings", "[", "$", "setting", "]", ":", "$", "default", ";", "}", "return", "$", "value", ";", "}" ]
Get setting. @param string $setting @param mixed $default @return mixed
[ "Get", "setting", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/File/src/YamlFile.php#L75-L83
train
silverstripe/cwp-search
src/Extensions/SearchControllerExtension.php
SearchControllerExtension.getResultsTemplate
protected function getResultsTemplate($request) { $templates = [ Page::class . '_results', Page::class ]; if ($request->getVar('format') == 'rss') { array_unshift($templates, Page::class . '_results_rss'); } if ($request->getVar('format') == 'atom') { array_unshift($templates, Page::class . '_results_atom'); } return $templates; }
php
protected function getResultsTemplate($request) { $templates = [ Page::class . '_results', Page::class ]; if ($request->getVar('format') == 'rss') { array_unshift($templates, Page::class . '_results_rss'); } if ($request->getVar('format') == 'atom') { array_unshift($templates, Page::class . '_results_atom'); } return $templates; }
[ "protected", "function", "getResultsTemplate", "(", "$", "request", ")", "{", "$", "templates", "=", "[", "Page", "::", "class", ".", "'_results'", ",", "Page", "::", "class", "]", ";", "if", "(", "$", "request", "->", "getVar", "(", "'format'", ")", "==", "'rss'", ")", "{", "array_unshift", "(", "$", "templates", ",", "Page", "::", "class", ".", "'_results_rss'", ")", ";", "}", "if", "(", "$", "request", "->", "getVar", "(", "'format'", ")", "==", "'atom'", ")", "{", "array_unshift", "(", "$", "templates", ",", "Page", "::", "class", ".", "'_results_atom'", ")", ";", "}", "return", "$", "templates", ";", "}" ]
Select the template to render search results with @param HTTPRequest $request @return array
[ "Select", "the", "template", "to", "render", "search", "results", "with" ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/Extensions/SearchControllerExtension.php#L147-L163
train
rockettheme/toolbox
File/src/IniFile.php
IniFile.decode
protected function decode($var) { $decoded = file_exists($this->filename) ? @parse_ini_file($this->filename) : []; if ($decoded === false) { throw new \RuntimeException("Decoding file '{$this->filename}' failed'"); } return $decoded; }
php
protected function decode($var) { $decoded = file_exists($this->filename) ? @parse_ini_file($this->filename) : []; if ($decoded === false) { throw new \RuntimeException("Decoding file '{$this->filename}' failed'"); } return $decoded; }
[ "protected", "function", "decode", "(", "$", "var", ")", "{", "$", "decoded", "=", "file_exists", "(", "$", "this", "->", "filename", ")", "?", "@", "parse_ini_file", "(", "$", "this", "->", "filename", ")", ":", "[", "]", ";", "if", "(", "$", "decoded", "===", "false", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"Decoding file '{$this->filename}' failed'\"", ")", ";", "}", "return", "$", "decoded", ";", "}" ]
Decode INI file into contents. @param string $var @return array @throws \RuntimeException
[ "Decode", "INI", "file", "into", "contents", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/File/src/IniFile.php#L66-L75
train
basecrm/basecrm-php
lib/SyncService.php
SyncService.start
public function start($deviceUUID, array $options = array()) { // @throws InvalidArgumentException $this->checkArgument($deviceUUID, 'deviceUUID'); list($code, $session) = $this->httpClient->post('/sync/start', null, array_merge($options, ['headers' => $this->buildHeaders($deviceUUID)])); if ($code == 204) return null; return $session; }
php
public function start($deviceUUID, array $options = array()) { // @throws InvalidArgumentException $this->checkArgument($deviceUUID, 'deviceUUID'); list($code, $session) = $this->httpClient->post('/sync/start', null, array_merge($options, ['headers' => $this->buildHeaders($deviceUUID)])); if ($code == 204) return null; return $session; }
[ "public", "function", "start", "(", "$", "deviceUUID", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "// @throws InvalidArgumentException", "$", "this", "->", "checkArgument", "(", "$", "deviceUUID", ",", "'deviceUUID'", ")", ";", "list", "(", "$", "code", ",", "$", "session", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "'/sync/start'", ",", "null", ",", "array_merge", "(", "$", "options", ",", "[", "'headers'", "=>", "$", "this", "->", "buildHeaders", "(", "$", "deviceUUID", ")", "]", ")", ")", ";", "if", "(", "$", "code", "==", "204", ")", "return", "null", ";", "return", "$", "session", ";", "}" ]
Start synchronization flow post '/sync/start' Starts a new synchronization session. This is the first endpoint to call, in order to start a new synchronization session. @param string $deviceUUID Device's UUID for which to perform synchronization. @param array $options Additional request's options. @return array The resulting object representing synchronization session or null if there is nothing to synchronize.
[ "Start", "synchronization", "flow" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/SyncService.php#L39-L48
train
basecrm/basecrm-php
lib/SyncService.php
SyncService.fetch
public function fetch($deviceUUID, $sessionId, $queue = 'main', array $options = array()) { // @throws InvalidArgumentException $this->checkArgument($deviceUUID, 'deviceUUID'); $this->checkArgument($sessionId, 'sessionId'); $this->checkArgument($queue, 'queue'); $options = array_merge($options, [ 'headers' => $this->buildHeaders($deviceUUID), 'raw' => true ]); list($code, $root) = $this->httpClient->get("/sync/{$sessionId}/queues/{$queue}", null, $options); if ($code == 204) return []; return $root['items']; }
php
public function fetch($deviceUUID, $sessionId, $queue = 'main', array $options = array()) { // @throws InvalidArgumentException $this->checkArgument($deviceUUID, 'deviceUUID'); $this->checkArgument($sessionId, 'sessionId'); $this->checkArgument($queue, 'queue'); $options = array_merge($options, [ 'headers' => $this->buildHeaders($deviceUUID), 'raw' => true ]); list($code, $root) = $this->httpClient->get("/sync/{$sessionId}/queues/{$queue}", null, $options); if ($code == 204) return []; return $root['items']; }
[ "public", "function", "fetch", "(", "$", "deviceUUID", ",", "$", "sessionId", ",", "$", "queue", "=", "'main'", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "// @throws InvalidArgumentException", "$", "this", "->", "checkArgument", "(", "$", "deviceUUID", ",", "'deviceUUID'", ")", ";", "$", "this", "->", "checkArgument", "(", "$", "sessionId", ",", "'sessionId'", ")", ";", "$", "this", "->", "checkArgument", "(", "$", "queue", ",", "'queue'", ")", ";", "$", "options", "=", "array_merge", "(", "$", "options", ",", "[", "'headers'", "=>", "$", "this", "->", "buildHeaders", "(", "$", "deviceUUID", ")", ",", "'raw'", "=>", "true", "]", ")", ";", "list", "(", "$", "code", ",", "$", "root", ")", "=", "$", "this", "->", "httpClient", "->", "get", "(", "\"/sync/{$sessionId}/queues/{$queue}\"", ",", "null", ",", "$", "options", ")", ";", "if", "(", "$", "code", "==", "204", ")", "return", "[", "]", ";", "return", "$", "root", "[", "'items'", "]", ";", "}" ]
Get data from queue get '/sync/{sessionId}/queues/main' Fetch fresh data from the named queue. Using session identifier you call continously the `#fetch` method to drain the named queue. @param string $deviceUUID Device's UUID for which to perform synchronization. @param string $sessionId Unique identifier of a synchronization session. @param string $queue Queue name. @param array $options Additional request's options. @return array The list of resources and associated meta data or an empty array if there is no more data to synchronize.
[ "Get", "data", "from", "queue" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/SyncService.php#L65-L80
train
basecrm/basecrm-php
lib/SyncService.php
SyncService.ack
public function ack($deviceUUID, array $ackKeys, array $options = array()) { // @throws InvalidArgumentException $this->checkArgument($deviceUUID, 'deviceUUID'); // fast path - nothing to acknowledge if (!$ackKeys) return true; $attributes = ['ack_keys' => $ackKeys]; list($code,) = $this->httpClient->post('/sync/ack', $attributes, array_merge($options, ['headers' => $this->buildHeaders($deviceUUID)])); return $code == 202; }
php
public function ack($deviceUUID, array $ackKeys, array $options = array()) { // @throws InvalidArgumentException $this->checkArgument($deviceUUID, 'deviceUUID'); // fast path - nothing to acknowledge if (!$ackKeys) return true; $attributes = ['ack_keys' => $ackKeys]; list($code,) = $this->httpClient->post('/sync/ack', $attributes, array_merge($options, ['headers' => $this->buildHeaders($deviceUUID)])); return $code == 202; }
[ "public", "function", "ack", "(", "$", "deviceUUID", ",", "array", "$", "ackKeys", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "// @throws InvalidArgumentException", "$", "this", "->", "checkArgument", "(", "$", "deviceUUID", ",", "'deviceUUID'", ")", ";", "// fast path - nothing to acknowledge", "if", "(", "!", "$", "ackKeys", ")", "return", "true", ";", "$", "attributes", "=", "[", "'ack_keys'", "=>", "$", "ackKeys", "]", ";", "list", "(", "$", "code", ",", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "'/sync/ack'", ",", "$", "attributes", ",", "array_merge", "(", "$", "options", ",", "[", "'headers'", "=>", "$", "this", "->", "buildHeaders", "(", "$", "deviceUUID", ")", "]", ")", ")", ";", "return", "$", "code", "==", "202", ";", "}" ]
Acknowledge received data post '/sync/ack' Send acknowledgement keys to let know the Sync service which data you have. As you fetch new data, you need to send acknowledgement keys. @param string $deviceUUID Device's UUID for which to perform synchronization. @param array $ackKeys The list of acknowledgement keys. @param array $options Additional request's options. @return boolean Status of the operation.
[ "Acknowledge", "received", "data" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/SyncService.php#L96-L107
train
basecrm/basecrm-php
lib/SourcesService.php
SourcesService.create
public function create(array $source, array $options = array()) { $attributes = array_intersect_key($source, array_flip(self::$keysToPersist)); list($code, $createdSource) = $this->httpClient->post("/sources", $attributes, $options); return $createdSource; }
php
public function create(array $source, array $options = array()) { $attributes = array_intersect_key($source, array_flip(self::$keysToPersist)); list($code, $createdSource) = $this->httpClient->post("/sources", $attributes, $options); return $createdSource; }
[ "public", "function", "create", "(", "array", "$", "source", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "source", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "createdSource", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "\"/sources\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "createdSource", ";", "}" ]
Create a source post '/sources' Creates a new source <figure class="notice"> Source's name **must** be unique </figure> @param array $source This array's attributes describe the object to be created. @param array $options Additional request's options. @return array The resulting object representing created resource.
[ "Create", "a", "source" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/SourcesService.php#L62-L68
train
basecrm/basecrm-php
lib/OrdersService.php
OrdersService.update
public function update($id, array $order, array $options = array()) { $attributes = array_intersect_key($order, array_flip(self::$keysToPersist)); list($code, $updatedOrder) = $this->httpClient->put("/orders/{$id}", $attributes, $options); return $updatedOrder; }
php
public function update($id, array $order, array $options = array()) { $attributes = array_intersect_key($order, array_flip(self::$keysToPersist)); list($code, $updatedOrder) = $this->httpClient->put("/orders/{$id}", $attributes, $options); return $updatedOrder; }
[ "public", "function", "update", "(", "$", "id", ",", "array", "$", "order", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "order", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "updatedOrder", ")", "=", "$", "this", "->", "httpClient", "->", "put", "(", "\"/orders/{$id}\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "updatedOrder", ";", "}" ]
Update an order put '/orders/{id}' Updates order information If the specified order does not exist, the request will return an error @param integer $id Unique identifier of a Order @param array $order This array's attributes describe the object to be updated. @param array $options Additional request's options. @return array The resulting object representing updated resource.
[ "Update", "an", "order" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/OrdersService.php#L102-L108
train
basecrm/basecrm-php
lib/LeadsService.php
LeadsService.create
public function create(array $lead, array $options = array()) { $attributes = array_intersect_key($lead, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); list($code, $createdLead) = $this->httpClient->post("/leads", $attributes, $options); return $createdLead; }
php
public function create(array $lead, array $options = array()) { $attributes = array_intersect_key($lead, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); list($code, $createdLead) = $this->httpClient->post("/leads", $attributes, $options); return $createdLead; }
[ "public", "function", "create", "(", "array", "$", "lead", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "lead", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", "&&", "empty", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ")", "unset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ";", "list", "(", "$", "code", ",", "$", "createdLead", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "\"/leads\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "createdLead", ";", "}" ]
Create a lead post '/leads' Creates a new lead A lead may represent a single individual or an organization @param array $lead This array's attributes describe the object to be created. @param array $options Additional request's options. @return array The resulting object representing created resource.
[ "Create", "a", "lead" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/LeadsService.php#L60-L67
train
basecrm/basecrm-php
lib/LeadsService.php
LeadsService.update
public function update($id, array $lead, array $options = array()) { $attributes = array_intersect_key($lead, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); list($code, $updatedLead) = $this->httpClient->put("/leads/{$id}", $attributes, $options); return $updatedLead; }
php
public function update($id, array $lead, array $options = array()) { $attributes = array_intersect_key($lead, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); list($code, $updatedLead) = $this->httpClient->put("/leads/{$id}", $attributes, $options); return $updatedLead; }
[ "public", "function", "update", "(", "$", "id", ",", "array", "$", "lead", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "lead", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", "&&", "empty", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ")", "unset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ";", "list", "(", "$", "code", ",", "$", "updatedLead", ")", "=", "$", "this", "->", "httpClient", "->", "put", "(", "\"/leads/{$id}\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "updatedLead", ";", "}" ]
Update a lead put '/leads/{id}' Updates lead information If the specified lead does not exist, this query returns an error <figure class="notice"> In order to modify tags, you need to supply the entire set of tags `tags` are replaced every time they are used in a request </figure> @param integer $id Unique identifier of a Lead @param array $lead This array's attributes describe the object to be updated. @param array $options Additional request's options. @return array The resulting object representing updated resource.
[ "Update", "a", "lead" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/LeadsService.php#L106-L113
train
rockettheme/toolbox
Session/src/Session.php
Session.start
public function start() { // Protection against invalid session cookie names throwing exception: http://php.net/manual/en/function.session-id.php#116836 if (isset($_COOKIE[session_name()]) && !preg_match('/^[-,a-zA-Z0-9]{1,128}$/', $_COOKIE[session_name()])) { unset($_COOKIE[session_name()]); } if (!session_start()) { throw new \RuntimeException('Failed to start session.', 500); } $this->started = true; return $this; }
php
public function start() { // Protection against invalid session cookie names throwing exception: http://php.net/manual/en/function.session-id.php#116836 if (isset($_COOKIE[session_name()]) && !preg_match('/^[-,a-zA-Z0-9]{1,128}$/', $_COOKIE[session_name()])) { unset($_COOKIE[session_name()]); } if (!session_start()) { throw new \RuntimeException('Failed to start session.', 500); } $this->started = true; return $this; }
[ "public", "function", "start", "(", ")", "{", "// Protection against invalid session cookie names throwing exception: http://php.net/manual/en/function.session-id.php#116836", "if", "(", "isset", "(", "$", "_COOKIE", "[", "session_name", "(", ")", "]", ")", "&&", "!", "preg_match", "(", "'/^[-,a-zA-Z0-9]{1,128}$/'", ",", "$", "_COOKIE", "[", "session_name", "(", ")", "]", ")", ")", "{", "unset", "(", "$", "_COOKIE", "[", "session_name", "(", ")", "]", ")", ";", "}", "if", "(", "!", "session_start", "(", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Failed to start session.'", ",", "500", ")", ";", "}", "$", "this", "->", "started", "=", "true", ";", "return", "$", "this", ";", "}" ]
Starts the session storage @return $this @throws \RuntimeException
[ "Starts", "the", "session", "storage" ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Session/src/Session.php#L78-L92
train
rockettheme/toolbox
Session/src/Session.php
Session.invalidate
public function invalidate() { $params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly'] ); session_unset(); session_destroy(); $this->started = false; return $this; }
php
public function invalidate() { $params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly'] ); session_unset(); session_destroy(); $this->started = false; return $this; }
[ "public", "function", "invalidate", "(", ")", "{", "$", "params", "=", "session_get_cookie_params", "(", ")", ";", "setcookie", "(", "session_name", "(", ")", ",", "''", ",", "time", "(", ")", "-", "42000", ",", "$", "params", "[", "'path'", "]", ",", "$", "params", "[", "'domain'", "]", ",", "$", "params", "[", "'secure'", "]", ",", "$", "params", "[", "'httponly'", "]", ")", ";", "session_unset", "(", ")", ";", "session_destroy", "(", ")", ";", "$", "this", "->", "started", "=", "false", ";", "return", "$", "this", ";", "}" ]
Invalidates the current session. @return $this
[ "Invalidates", "the", "current", "session", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Session/src/Session.php#L148-L162
train
silverstripe/cwp-search
src/Extensions/CwpSearchBoostExtension.php
CwpSearchBoostExtension.updateCMSFields
public function updateCMSFields(FieldList $fields) { $pageInfoTitle = _t(__CLASS__ . '.PAGEINFO', 'Page info and SEO'); $boostTitle = _t(__CLASS__ . '.SearchBoost', 'Boost Keywords'); $boostNote = _t( __CLASS__ . '.SearchBoostNote', '(Only applies to the search results on this site e.g. not on Google search)' ); $boostDescription = _t( __CLASS__ . '.SearchBoostDescription', 'Enter keywords separated by comma ( , ) for which to boost the ranking of this page ' . 'within the search results on this site.' ); $boostField = TextareaField::create('SearchBoost', $boostTitle) ->setRightTitle($boostNote) ->setDescription($boostDescription); if ($meta = $fields->fieldByName('Root.Main.Metadata')) { // Rename metafield if it exists $meta->setTitle($pageInfoTitle); $fields->insertBefore('MetaDescription', $boostField); } else { // Else create new field to store SEO $fields->addFieldToTab( 'Root.Main', ToggleCompositeField::create( 'Metadata', $pageInfoTitle, [ $boostField, ] ) ); } }
php
public function updateCMSFields(FieldList $fields) { $pageInfoTitle = _t(__CLASS__ . '.PAGEINFO', 'Page info and SEO'); $boostTitle = _t(__CLASS__ . '.SearchBoost', 'Boost Keywords'); $boostNote = _t( __CLASS__ . '.SearchBoostNote', '(Only applies to the search results on this site e.g. not on Google search)' ); $boostDescription = _t( __CLASS__ . '.SearchBoostDescription', 'Enter keywords separated by comma ( , ) for which to boost the ranking of this page ' . 'within the search results on this site.' ); $boostField = TextareaField::create('SearchBoost', $boostTitle) ->setRightTitle($boostNote) ->setDescription($boostDescription); if ($meta = $fields->fieldByName('Root.Main.Metadata')) { // Rename metafield if it exists $meta->setTitle($pageInfoTitle); $fields->insertBefore('MetaDescription', $boostField); } else { // Else create new field to store SEO $fields->addFieldToTab( 'Root.Main', ToggleCompositeField::create( 'Metadata', $pageInfoTitle, [ $boostField, ] ) ); } }
[ "public", "function", "updateCMSFields", "(", "FieldList", "$", "fields", ")", "{", "$", "pageInfoTitle", "=", "_t", "(", "__CLASS__", ".", "'.PAGEINFO'", ",", "'Page info and SEO'", ")", ";", "$", "boostTitle", "=", "_t", "(", "__CLASS__", ".", "'.SearchBoost'", ",", "'Boost Keywords'", ")", ";", "$", "boostNote", "=", "_t", "(", "__CLASS__", ".", "'.SearchBoostNote'", ",", "'(Only applies to the search results on this site e.g. not on Google search)'", ")", ";", "$", "boostDescription", "=", "_t", "(", "__CLASS__", ".", "'.SearchBoostDescription'", ",", "'Enter keywords separated by comma ( , ) for which to boost the ranking of this page '", ".", "'within the search results on this site.'", ")", ";", "$", "boostField", "=", "TextareaField", "::", "create", "(", "'SearchBoost'", ",", "$", "boostTitle", ")", "->", "setRightTitle", "(", "$", "boostNote", ")", "->", "setDescription", "(", "$", "boostDescription", ")", ";", "if", "(", "$", "meta", "=", "$", "fields", "->", "fieldByName", "(", "'Root.Main.Metadata'", ")", ")", "{", "// Rename metafield if it exists", "$", "meta", "->", "setTitle", "(", "$", "pageInfoTitle", ")", ";", "$", "fields", "->", "insertBefore", "(", "'MetaDescription'", ",", "$", "boostField", ")", ";", "}", "else", "{", "// Else create new field to store SEO", "$", "fields", "->", "addFieldToTab", "(", "'Root.Main'", ",", "ToggleCompositeField", "::", "create", "(", "'Metadata'", ",", "$", "pageInfoTitle", ",", "[", "$", "boostField", ",", "]", ")", ")", ";", "}", "}" ]
Adds boost fields to this page @param FieldList $fields
[ "Adds", "boost", "fields", "to", "this", "page" ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/Extensions/CwpSearchBoostExtension.php#L33-L67
train
basecrm/basecrm-php
lib/LossReasonsService.php
LossReasonsService.create
public function create(array $lossReason, array $options = array()) { $attributes = array_intersect_key($lossReason, array_flip(self::$keysToPersist)); list($code, $createdLossReason) = $this->httpClient->post("/loss_reasons", $attributes, $options); return $createdLossReason; }
php
public function create(array $lossReason, array $options = array()) { $attributes = array_intersect_key($lossReason, array_flip(self::$keysToPersist)); list($code, $createdLossReason) = $this->httpClient->post("/loss_reasons", $attributes, $options); return $createdLossReason; }
[ "public", "function", "create", "(", "array", "$", "lossReason", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "lossReason", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "createdLossReason", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "\"/loss_reasons\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "createdLossReason", ";", "}" ]
Create a loss reason post '/loss_reasons' Create a new loss reason <figure class="notice"> Loss reason's name **must** be unique </figure> @param array $lossReason This array's attributes describe the object to be created. @param array $options Additional request's options. @return array The resulting object representing created resource.
[ "Create", "a", "loss", "reason" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/LossReasonsService.php#L62-L68
train
basecrm/basecrm-php
lib/LossReasonsService.php
LossReasonsService.get
public function get($id, array $options = array()) { list($code, $loss_reason) = $this->httpClient->get("/loss_reasons/{$id}", null, $options); return $loss_reason; }
php
public function get($id, array $options = array()) { list($code, $loss_reason) = $this->httpClient->get("/loss_reasons/{$id}", null, $options); return $loss_reason; }
[ "public", "function", "get", "(", "$", "id", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "list", "(", "$", "code", ",", "$", "loss_reason", ")", "=", "$", "this", "->", "httpClient", "->", "get", "(", "\"/loss_reasons/{$id}\"", ",", "null", ",", "$", "options", ")", ";", "return", "$", "loss_reason", ";", "}" ]
Retrieve a single reason get '/loss_reasons/{id}' Returns a single loss reason available to the user by the provided id If a loss reason with the supplied unique identifier does not exist, it returns an error @param integer $id Unique identifier of a LossReason @param array $options Additional request's options. @return array Searched LossReason.
[ "Retrieve", "a", "single", "reason" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/LossReasonsService.php#L83-L87
train
basecrm/basecrm-php
lib/LossReasonsService.php
LossReasonsService.update
public function update($id, array $lossReason, array $options = array()) { $attributes = array_intersect_key($lossReason, array_flip(self::$keysToPersist)); list($code, $updatedLossReason) = $this->httpClient->put("/loss_reasons/{$id}", $attributes, $options); return $updatedLossReason; }
php
public function update($id, array $lossReason, array $options = array()) { $attributes = array_intersect_key($lossReason, array_flip(self::$keysToPersist)); list($code, $updatedLossReason) = $this->httpClient->put("/loss_reasons/{$id}", $attributes, $options); return $updatedLossReason; }
[ "public", "function", "update", "(", "$", "id", ",", "array", "$", "lossReason", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "lossReason", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "updatedLossReason", ")", "=", "$", "this", "->", "httpClient", "->", "put", "(", "\"/loss_reasons/{$id}\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "updatedLossReason", ";", "}" ]
Update a loss reason put '/loss_reasons/{id}' Updates a loss reason information If the specified loss reason does not exist, the request will return an error <figure class="notice"> If you want to update loss reason you **must** make sure name of the reason is unique </figure> @param integer $id Unique identifier of a LossReason @param array $lossReason This array's attributes describe the object to be updated. @param array $options Additional request's options. @return array The resulting object representing updated resource.
[ "Update", "a", "loss", "reason" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/LossReasonsService.php#L106-L112
train
basecrm/basecrm-php
lib/AssociatedContactsService.php
AssociatedContactsService.all
public function all($deal_id, $params = [], array $options = array()) { list($code, $associated_contacts) = $this->httpClient->get("/deals/{$deal_id}/associated_contacts", $params, $options); return $associated_contacts; }
php
public function all($deal_id, $params = [], array $options = array()) { list($code, $associated_contacts) = $this->httpClient->get("/deals/{$deal_id}/associated_contacts", $params, $options); return $associated_contacts; }
[ "public", "function", "all", "(", "$", "deal_id", ",", "$", "params", "=", "[", "]", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "list", "(", "$", "code", ",", "$", "associated_contacts", ")", "=", "$", "this", "->", "httpClient", "->", "get", "(", "\"/deals/{$deal_id}/associated_contacts\"", ",", "$", "params", ",", "$", "options", ")", ";", "return", "$", "associated_contacts", ";", "}" ]
Retrieve deal's associated contacts get '/deals/{deal_id}/associated_contacts' Returns all deal associated contacts @param integer $deal_id Unique identifier of a Deal @param array $params Search options @param array $options Additional request's options. @return array The list of AssociatedContacts for the first page, unless otherwise specified.
[ "Retrieve", "deal", "s", "associated", "contacts" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/AssociatedContactsService.php#L42-L46
train
basecrm/basecrm-php
lib/AssociatedContactsService.php
AssociatedContactsService.create
public function create($deal_id, array $associatedContact, array $options = array()) { $attributes = array_intersect_key($associatedContact, array_flip(self::$keysToPersist)); list($code, $createdAssociatedContact) = $this->httpClient->post("/deals/{$deal_id}/associated_contacts", $attributes, $options); return $createdAssociatedContact; }
php
public function create($deal_id, array $associatedContact, array $options = array()) { $attributes = array_intersect_key($associatedContact, array_flip(self::$keysToPersist)); list($code, $createdAssociatedContact) = $this->httpClient->post("/deals/{$deal_id}/associated_contacts", $attributes, $options); return $createdAssociatedContact; }
[ "public", "function", "create", "(", "$", "deal_id", ",", "array", "$", "associatedContact", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "associatedContact", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "createdAssociatedContact", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "\"/deals/{$deal_id}/associated_contacts\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "createdAssociatedContact", ";", "}" ]
Create an associated contact post '/deals/{deal_id}/associated_contacts' Creates a deal's associated contact and its role If the specified deal or contact does not exist, the request will return an error @param integer $deal_id Unique identifier of a Deal @param array $associatedContact This array's attributes describe the object to be created. @param array $options Additional request's options. @return array The resulting object representing created resource.
[ "Create", "an", "associated", "contact" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/AssociatedContactsService.php#L62-L68
train
basecrm/basecrm-php
lib/AssociatedContactsService.php
AssociatedContactsService.destroy
public function destroy($deal_id, $contact_id, array $options = array()) { list($code, $payload) = $this->httpClient->delete("/deals/{$deal_id}/associated_contacts/{$contact_id}", null, $options); return $code == 204; }
php
public function destroy($deal_id, $contact_id, array $options = array()) { list($code, $payload) = $this->httpClient->delete("/deals/{$deal_id}/associated_contacts/{$contact_id}", null, $options); return $code == 204; }
[ "public", "function", "destroy", "(", "$", "deal_id", ",", "$", "contact_id", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "list", "(", "$", "code", ",", "$", "payload", ")", "=", "$", "this", "->", "httpClient", "->", "delete", "(", "\"/deals/{$deal_id}/associated_contacts/{$contact_id}\"", ",", "null", ",", "$", "options", ")", ";", "return", "$", "code", "==", "204", ";", "}" ]
Remove an associated contact delete '/deals/{deal_id}/associated_contacts/{contact_id}' Remove a deal's associated contact If a deal with the supplied unique identifier does not exist, it returns an error This operation cannot be undone @param integer $deal_id Unique identifier of a Deal @param integer $contact_id Unique identifier of a Contact @param array $options Additional request's options. @return boolean Status of the operation.
[ "Remove", "an", "associated", "contact" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/AssociatedContactsService.php#L85-L89
train
basecrm/basecrm-php
lib/TagsService.php
TagsService.update
public function update($id, array $tag, array $options = array()) { $attributes = array_intersect_key($tag, array_flip(self::$keysToPersist)); list($code, $updatedTag) = $this->httpClient->put("/tags/{$id}", $attributes, $options); return $updatedTag; }
php
public function update($id, array $tag, array $options = array()) { $attributes = array_intersect_key($tag, array_flip(self::$keysToPersist)); list($code, $updatedTag) = $this->httpClient->put("/tags/{$id}", $attributes, $options); return $updatedTag; }
[ "public", "function", "update", "(", "$", "id", ",", "array", "$", "tag", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "tag", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "updatedTag", ")", "=", "$", "this", "->", "httpClient", "->", "put", "(", "\"/tags/{$id}\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "updatedTag", ";", "}" ]
Update a tag put '/tags/{id}' Updates a tag's information If the specified tag does not exist, this query will return an error **Notice** if you want to update a tag, you **must** make sure the tag's name is unique within the scope of the specified resource @param integer $id Unique identifier of a Tag @param array $tag This array's attributes describe the object to be updated. @param array $options Additional request's options. @return array The resulting object representing updated resource.
[ "Update", "a", "tag" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/TagsService.php#L102-L108
train
basecrm/basecrm-php
lib/DealUnqualifiedReasonsService.php
DealUnqualifiedReasonsService.create
public function create(array $dealUnqualifiedReason, array $options = array()) { $attributes = array_intersect_key($dealUnqualifiedReason, array_flip(self::$keysToPersist)); list($code, $createdDealUnqualifiedReason) = $this->httpClient->post("/deal_unqualified_reasons", $attributes, $options); return $createdDealUnqualifiedReason; }
php
public function create(array $dealUnqualifiedReason, array $options = array()) { $attributes = array_intersect_key($dealUnqualifiedReason, array_flip(self::$keysToPersist)); list($code, $createdDealUnqualifiedReason) = $this->httpClient->post("/deal_unqualified_reasons", $attributes, $options); return $createdDealUnqualifiedReason; }
[ "public", "function", "create", "(", "array", "$", "dealUnqualifiedReason", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "dealUnqualifiedReason", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "createdDealUnqualifiedReason", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "\"/deal_unqualified_reasons\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "createdDealUnqualifiedReason", ";", "}" ]
Create a deal unqualified reason post '/deal_unqualified_reasons' Create a new deal unqualified reason <figure class="notice"> Deal unqualified reason's name **must** be unique </figure> @param array $dealUnqualifiedReason This array's attributes describe the object to be created. @param array $options Additional request's options. @return array The resulting object representing created resource.
[ "Create", "a", "deal", "unqualified", "reason" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/DealUnqualifiedReasonsService.php#L62-L68
train
basecrm/basecrm-php
lib/DealUnqualifiedReasonsService.php
DealUnqualifiedReasonsService.update
public function update($id, array $dealUnqualifiedReason, array $options = array()) { $attributes = array_intersect_key($dealUnqualifiedReason, array_flip(self::$keysToPersist)); list($code, $updatedDealUnqualifiedReason) = $this->httpClient->put("/deal_unqualified_reasons/{$id}", $attributes, $options); return $updatedDealUnqualifiedReason; }
php
public function update($id, array $dealUnqualifiedReason, array $options = array()) { $attributes = array_intersect_key($dealUnqualifiedReason, array_flip(self::$keysToPersist)); list($code, $updatedDealUnqualifiedReason) = $this->httpClient->put("/deal_unqualified_reasons/{$id}", $attributes, $options); return $updatedDealUnqualifiedReason; }
[ "public", "function", "update", "(", "$", "id", ",", "array", "$", "dealUnqualifiedReason", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "dealUnqualifiedReason", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "updatedDealUnqualifiedReason", ")", "=", "$", "this", "->", "httpClient", "->", "put", "(", "\"/deal_unqualified_reasons/{$id}\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "updatedDealUnqualifiedReason", ";", "}" ]
Update a deal unqualified reason put '/deal_unqualified_reasons/{id}' Updates a deal unqualified reason information If the specified deal unqualified reason does not exist, the request will return an error <figure class="notice"> If you want to update deal unqualified reason you **must** make sure name of the reason is unique </figure> @param integer $id Unique identifier of a DealUnqualifiedReason @param array $dealUnqualifiedReason This array's attributes describe the object to be updated. @param array $options Additional request's options. @return array The resulting object representing updated resource.
[ "Update", "a", "deal", "unqualified", "reason" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/DealUnqualifiedReasonsService.php#L106-L112
train
rockettheme/toolbox
Compat/src/Yaml/Parser.php
Parser.cleanup
private function cleanup($value) { $value = str_replace(array("\r\n", "\r"), "\n", $value); // strip YAML header $count = 0; $value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#u', '', $value, -1, $count); $this->offset += $count; // remove leading comments $trimmedValue = preg_replace('#^(\#.*?\n)+#s', '', $value, -1, $count); if (1 == $count) { // items have been removed, update the offset $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n"); $value = $trimmedValue; } // remove start of the document marker (---) $trimmedValue = preg_replace('#^\-\-\-.*?\n#s', '', $value, -1, $count); if (1 == $count) { // items have been removed, update the offset $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n"); $value = $trimmedValue; // remove end of the document marker (...) $value = preg_replace('#\.\.\.\s*$#', '', $value); } return $value; }
php
private function cleanup($value) { $value = str_replace(array("\r\n", "\r"), "\n", $value); // strip YAML header $count = 0; $value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#u', '', $value, -1, $count); $this->offset += $count; // remove leading comments $trimmedValue = preg_replace('#^(\#.*?\n)+#s', '', $value, -1, $count); if (1 == $count) { // items have been removed, update the offset $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n"); $value = $trimmedValue; } // remove start of the document marker (---) $trimmedValue = preg_replace('#^\-\-\-.*?\n#s', '', $value, -1, $count); if (1 == $count) { // items have been removed, update the offset $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n"); $value = $trimmedValue; // remove end of the document marker (...) $value = preg_replace('#\.\.\.\s*$#', '', $value); } return $value; }
[ "private", "function", "cleanup", "(", "$", "value", ")", "{", "$", "value", "=", "str_replace", "(", "array", "(", "\"\\r\\n\"", ",", "\"\\r\"", ")", ",", "\"\\n\"", ",", "$", "value", ")", ";", "// strip YAML header", "$", "count", "=", "0", ";", "$", "value", "=", "preg_replace", "(", "'#^\\%YAML[: ][\\d\\.]+.*\\n#u'", ",", "''", ",", "$", "value", ",", "-", "1", ",", "$", "count", ")", ";", "$", "this", "->", "offset", "+=", "$", "count", ";", "// remove leading comments", "$", "trimmedValue", "=", "preg_replace", "(", "'#^(\\#.*?\\n)+#s'", ",", "''", ",", "$", "value", ",", "-", "1", ",", "$", "count", ")", ";", "if", "(", "1", "==", "$", "count", ")", "{", "// items have been removed, update the offset", "$", "this", "->", "offset", "+=", "substr_count", "(", "$", "value", ",", "\"\\n\"", ")", "-", "substr_count", "(", "$", "trimmedValue", ",", "\"\\n\"", ")", ";", "$", "value", "=", "$", "trimmedValue", ";", "}", "// remove start of the document marker (---)", "$", "trimmedValue", "=", "preg_replace", "(", "'#^\\-\\-\\-.*?\\n#s'", ",", "''", ",", "$", "value", ",", "-", "1", ",", "$", "count", ")", ";", "if", "(", "1", "==", "$", "count", ")", "{", "// items have been removed, update the offset", "$", "this", "->", "offset", "+=", "substr_count", "(", "$", "value", ",", "\"\\n\"", ")", "-", "substr_count", "(", "$", "trimmedValue", ",", "\"\\n\"", ")", ";", "$", "value", "=", "$", "trimmedValue", ";", "// remove end of the document marker (...)", "$", "value", "=", "preg_replace", "(", "'#\\.\\.\\.\\s*$#'", ",", "''", ",", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Cleanups a YAML string to be parsed. @param string $value The input YAML string @return string A cleaned up YAML string
[ "Cleanups", "a", "YAML", "string", "to", "be", "parsed", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Compat/src/Yaml/Parser.php#L735-L764
train
rockettheme/toolbox
File/src/PhpFile.php
PhpFile.save
public function save($data = null) { parent::save($data); // Invalidate configuration file from the opcache. if (\function_exists('opcache_invalidate')) { // PHP 5.5.5+ @opcache_invalidate($this->filename, true); } elseif (\function_exists('apc_invalidate')) { // APC @apc_invalidate($this->filename); } }
php
public function save($data = null) { parent::save($data); // Invalidate configuration file from the opcache. if (\function_exists('opcache_invalidate')) { // PHP 5.5.5+ @opcache_invalidate($this->filename, true); } elseif (\function_exists('apc_invalidate')) { // APC @apc_invalidate($this->filename); } }
[ "public", "function", "save", "(", "$", "data", "=", "null", ")", "{", "parent", "::", "save", "(", "$", "data", ")", ";", "// Invalidate configuration file from the opcache.", "if", "(", "\\", "function_exists", "(", "'opcache_invalidate'", ")", ")", "{", "// PHP 5.5.5+", "@", "opcache_invalidate", "(", "$", "this", "->", "filename", ",", "true", ")", ";", "}", "elseif", "(", "\\", "function_exists", "(", "'apc_invalidate'", ")", ")", "{", "// APC", "@", "apc_invalidate", "(", "$", "this", "->", "filename", ")", ";", "}", "}" ]
Saves PHP file and invalidates opcache. @param mixed $data Optional data to be saved, usually array. @throws \RuntimeException
[ "Saves", "PHP", "file", "and", "invalidates", "opcache", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/File/src/PhpFile.php#L29-L41
train
rockettheme/toolbox
File/src/File.php
File.instance
public static function instance($filename) { if (!\is_string($filename) && $filename) { throw new \InvalidArgumentException('Filename should be non-empty string'); } if (!isset(static::$instances[$filename])) { static::$instances[$filename] = new static; static::$instances[$filename]->init($filename); } return static::$instances[$filename]; }
php
public static function instance($filename) { if (!\is_string($filename) && $filename) { throw new \InvalidArgumentException('Filename should be non-empty string'); } if (!isset(static::$instances[$filename])) { static::$instances[$filename] = new static; static::$instances[$filename]->init($filename); } return static::$instances[$filename]; }
[ "public", "static", "function", "instance", "(", "$", "filename", ")", "{", "if", "(", "!", "\\", "is_string", "(", "$", "filename", ")", "&&", "$", "filename", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Filename should be non-empty string'", ")", ";", "}", "if", "(", "!", "isset", "(", "static", "::", "$", "instances", "[", "$", "filename", "]", ")", ")", "{", "static", "::", "$", "instances", "[", "$", "filename", "]", "=", "new", "static", ";", "static", "::", "$", "instances", "[", "$", "filename", "]", "->", "init", "(", "$", "filename", ")", ";", "}", "return", "static", "::", "$", "instances", "[", "$", "filename", "]", ";", "}" ]
Get file instance. @param string $filename @return static
[ "Get", "file", "instance", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/File/src/File.php#L59-L69
train
rockettheme/toolbox
File/src/File.php
File.free
public function free() { if ($this->locked) { $this->unlock(); } $this->content = null; $this->raw = null; unset(static::$instances[$this->filename]); }
php
public function free() { if ($this->locked) { $this->unlock(); } $this->content = null; $this->raw = null; unset(static::$instances[$this->filename]); }
[ "public", "function", "free", "(", ")", "{", "if", "(", "$", "this", "->", "locked", ")", "{", "$", "this", "->", "unlock", "(", ")", ";", "}", "$", "this", "->", "content", "=", "null", ";", "$", "this", "->", "raw", "=", "null", ";", "unset", "(", "static", "::", "$", "instances", "[", "$", "this", "->", "filename", "]", ")", ";", "}" ]
Free the file instance.
[ "Free", "the", "file", "instance", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/File/src/File.php#L126-L135
train
rockettheme/toolbox
File/src/File.php
File.writable
public function writable() { return file_exists($this->filename) ? is_writable($this->filename) && is_file($this->filename) : $this->writableDir(\dirname($this->filename)); }
php
public function writable() { return file_exists($this->filename) ? is_writable($this->filename) && is_file($this->filename) : $this->writableDir(\dirname($this->filename)); }
[ "public", "function", "writable", "(", ")", "{", "return", "file_exists", "(", "$", "this", "->", "filename", ")", "?", "is_writable", "(", "$", "this", "->", "filename", ")", "&&", "is_file", "(", "$", "this", "->", "filename", ")", ":", "$", "this", "->", "writableDir", "(", "\\", "dirname", "(", "$", "this", "->", "filename", ")", ")", ";", "}" ]
Check if file can be written. @return bool
[ "Check", "if", "file", "can", "be", "written", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/File/src/File.php#L244-L247
train
rockettheme/toolbox
File/src/File.php
File.rename
public function rename($filename) { if ($this->exists() && !@rename($this->filename, $filename)) { return false; } unset(static::$instances[$this->filename]); static::$instances[$filename] = $this; $this->filename = $filename; return true; }
php
public function rename($filename) { if ($this->exists() && !@rename($this->filename, $filename)) { return false; } unset(static::$instances[$this->filename]); static::$instances[$filename] = $this; $this->filename = $filename; return true; }
[ "public", "function", "rename", "(", "$", "filename", ")", "{", "if", "(", "$", "this", "->", "exists", "(", ")", "&&", "!", "@", "rename", "(", "$", "this", "->", "filename", ",", "$", "filename", ")", ")", "{", "return", "false", ";", "}", "unset", "(", "static", "::", "$", "instances", "[", "$", "this", "->", "filename", "]", ")", ";", "static", "::", "$", "instances", "[", "$", "filename", "]", "=", "$", "this", ";", "$", "this", "->", "filename", "=", "$", "filename", ";", "return", "true", ";", "}" ]
Rename file in the filesystem if it exists. @param $filename @return bool
[ "Rename", "file", "in", "the", "filesystem", "if", "it", "exists", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/File/src/File.php#L364-L376
train
basecrm/basecrm-php
lib/UsersService.php
UsersService.self
public function self(array $options = array()) { list($code, $resource) = $this->httpClient->get("/users/self", null, $options); return $resource; }
php
public function self(array $options = array()) { list($code, $resource) = $this->httpClient->get("/users/self", null, $options); return $resource; }
[ "public", "function", "self", "(", "array", "$", "options", "=", "array", "(", ")", ")", "{", "list", "(", "$", "code", ",", "$", "resource", ")", "=", "$", "this", "->", "httpClient", "->", "get", "(", "\"/users/self\"", ",", "null", ",", "$", "options", ")", ";", "return", "$", "resource", ";", "}" ]
Retrieve an authenticating user get '/users/self' Returns a single authenticating user, according to the authentication credentials provided @param array $options Additional request's options. @return array Resource object.
[ "Retrieve", "an", "authenticating", "user" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/UsersService.php#L74-L78
train
rockettheme/toolbox
Session/src/Message.php
Message.add
public function add($message, $scope = 'default') { $key = md5($scope.'~'.$message); $item = ['message' => $message, 'scope' => $scope]; // don't add duplicates if (!array_key_exists($key, $this->messages)) { $this->messages[$key] = $item; } return $this; }
php
public function add($message, $scope = 'default') { $key = md5($scope.'~'.$message); $item = ['message' => $message, 'scope' => $scope]; // don't add duplicates if (!array_key_exists($key, $this->messages)) { $this->messages[$key] = $item; } return $this; }
[ "public", "function", "add", "(", "$", "message", ",", "$", "scope", "=", "'default'", ")", "{", "$", "key", "=", "md5", "(", "$", "scope", ".", "'~'", ".", "$", "message", ")", ";", "$", "item", "=", "[", "'message'", "=>", "$", "message", ",", "'scope'", "=>", "$", "scope", "]", ";", "// don't add duplicates", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "messages", ")", ")", "{", "$", "this", "->", "messages", "[", "$", "key", "]", "=", "$", "item", ";", "}", "return", "$", "this", ";", "}" ]
Add message to the queue. @param string $message @param string $scope @return $this
[ "Add", "message", "to", "the", "queue", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Session/src/Message.php#L25-L36
train
rockettheme/toolbox
Session/src/Message.php
Message.clear
public function clear($scope = null) { if ($scope === null) { $this->messages = array(); } else { foreach ($this->messages as $key => $message) { if ($message['scope'] === $scope) { unset($this->messages[$key]); } } } return $this; }
php
public function clear($scope = null) { if ($scope === null) { $this->messages = array(); } else { foreach ($this->messages as $key => $message) { if ($message['scope'] === $scope) { unset($this->messages[$key]); } } } return $this; }
[ "public", "function", "clear", "(", "$", "scope", "=", "null", ")", "{", "if", "(", "$", "scope", "===", "null", ")", "{", "$", "this", "->", "messages", "=", "array", "(", ")", ";", "}", "else", "{", "foreach", "(", "$", "this", "->", "messages", "as", "$", "key", "=>", "$", "message", ")", "{", "if", "(", "$", "message", "[", "'scope'", "]", "===", "$", "scope", ")", "{", "unset", "(", "$", "this", "->", "messages", "[", "$", "key", "]", ")", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Clear message queue. @param string $scope @return $this
[ "Clear", "message", "queue", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Session/src/Message.php#L44-L56
train
rockettheme/toolbox
Session/src/Message.php
Message.all
public function all($scope = null) { if ($scope === null) { return array_values($this->messages); } $messages = array(); foreach ($this->messages as $message) { if ($message['scope'] === $scope) { $messages[] = $message; } } return $messages; }
php
public function all($scope = null) { if ($scope === null) { return array_values($this->messages); } $messages = array(); foreach ($this->messages as $message) { if ($message['scope'] === $scope) { $messages[] = $message; } } return $messages; }
[ "public", "function", "all", "(", "$", "scope", "=", "null", ")", "{", "if", "(", "$", "scope", "===", "null", ")", "{", "return", "array_values", "(", "$", "this", "->", "messages", ")", ";", "}", "$", "messages", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "messages", "as", "$", "message", ")", "{", "if", "(", "$", "message", "[", "'scope'", "]", "===", "$", "scope", ")", "{", "$", "messages", "[", "]", "=", "$", "message", ";", "}", "}", "return", "$", "messages", ";", "}" ]
Fetch all messages. @param string $scope @return array
[ "Fetch", "all", "messages", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Session/src/Message.php#L64-L78
train
rockettheme/toolbox
Session/src/Message.php
Message.fetch
public function fetch($scope = null) { $messages = $this->all($scope); $this->clear($scope); return $messages; }
php
public function fetch($scope = null) { $messages = $this->all($scope); $this->clear($scope); return $messages; }
[ "public", "function", "fetch", "(", "$", "scope", "=", "null", ")", "{", "$", "messages", "=", "$", "this", "->", "all", "(", "$", "scope", ")", ";", "$", "this", "->", "clear", "(", "$", "scope", ")", ";", "return", "$", "messages", ";", "}" ]
Fetch and clear message queue. @param string $scope @return array
[ "Fetch", "and", "clear", "message", "queue", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Session/src/Message.php#L86-L92
train
basecrm/basecrm-php
lib/DealsService.php
DealsService.all
public function all($params = [], array $options = array()) { list($code, $deals) = $this->httpClient->get("/deals", $params, $options); if (isset($options['raw']) && $options['raw']) { return $deals; } $dealsData = array_map(array($this, 'coerceNestedDealData'), $deals); return $dealsData; }
php
public function all($params = [], array $options = array()) { list($code, $deals) = $this->httpClient->get("/deals", $params, $options); if (isset($options['raw']) && $options['raw']) { return $deals; } $dealsData = array_map(array($this, 'coerceNestedDealData'), $deals); return $dealsData; }
[ "public", "function", "all", "(", "$", "params", "=", "[", "]", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "list", "(", "$", "code", ",", "$", "deals", ")", "=", "$", "this", "->", "httpClient", "->", "get", "(", "\"/deals\"", ",", "$", "params", ",", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'raw'", "]", ")", "&&", "$", "options", "[", "'raw'", "]", ")", "{", "return", "$", "deals", ";", "}", "$", "dealsData", "=", "array_map", "(", "array", "(", "$", "this", ",", "'coerceNestedDealData'", ")", ",", "$", "deals", ")", ";", "return", "$", "dealsData", ";", "}" ]
Retrieve all deals get '/deals' Returns all deals available to the user according to the parameters provided @param array $params Search options @param array $options Additional request's options. @return array The list of Deals for the first page, unless otherwise specified.
[ "Retrieve", "all", "deals" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/DealsService.php#L41-L49
train
basecrm/basecrm-php
lib/DealsService.php
DealsService.create
public function create(array $deal, array $options = array()) { $attributes = array_intersect_key($deal, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); if (isset($attributes['value'])) $attributes["value"] = Coercion::toStringValue($attributes['value']); list($code, $createdDeal) = $this->httpClient->post("/deals", $attributes, $options); if (isset($options['raw']) && $options['raw']) { return $createdDeal; } $createdDeal = $this->coerceDealData($createdDeal); return $createdDeal; }
php
public function create(array $deal, array $options = array()) { $attributes = array_intersect_key($deal, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); if (isset($attributes['value'])) $attributes["value"] = Coercion::toStringValue($attributes['value']); list($code, $createdDeal) = $this->httpClient->post("/deals", $attributes, $options); if (isset($options['raw']) && $options['raw']) { return $createdDeal; } $createdDeal = $this->coerceDealData($createdDeal); return $createdDeal; }
[ "public", "function", "create", "(", "array", "$", "deal", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "deal", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", "&&", "empty", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ")", "unset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "'value'", "]", ")", ")", "$", "attributes", "[", "\"value\"", "]", "=", "Coercion", "::", "toStringValue", "(", "$", "attributes", "[", "'value'", "]", ")", ";", "list", "(", "$", "code", ",", "$", "createdDeal", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "\"/deals\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'raw'", "]", ")", "&&", "$", "options", "[", "'raw'", "]", ")", "{", "return", "$", "createdDeal", ";", "}", "$", "createdDeal", "=", "$", "this", "->", "coerceDealData", "(", "$", "createdDeal", ")", ";", "return", "$", "createdDeal", ";", "}" ]
Create a deal post '/deals' Create a new deal @param array $deal This array's attributes describe the object to be created. @param array $options Additional request's options. @return array The resulting object representing created resource.
[ "Create", "a", "deal" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/DealsService.php#L63-L74
train
basecrm/basecrm-php
lib/DealsService.php
DealsService.get
public function get($id, array $options = array()) { list($code, $deal) = $this->httpClient->get("/deals/{$id}", null, $options); if (isset($options['raw']) && $options['raw']) { return $deal; } $deal = $this->coerceDealData($deal); return $deal; }
php
public function get($id, array $options = array()) { list($code, $deal) = $this->httpClient->get("/deals/{$id}", null, $options); if (isset($options['raw']) && $options['raw']) { return $deal; } $deal = $this->coerceDealData($deal); return $deal; }
[ "public", "function", "get", "(", "$", "id", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "list", "(", "$", "code", ",", "$", "deal", ")", "=", "$", "this", "->", "httpClient", "->", "get", "(", "\"/deals/{$id}\"", ",", "null", ",", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'raw'", "]", ")", "&&", "$", "options", "[", "'raw'", "]", ")", "{", "return", "$", "deal", ";", "}", "$", "deal", "=", "$", "this", "->", "coerceDealData", "(", "$", "deal", ")", ";", "return", "$", "deal", ";", "}" ]
Retrieve a single deal get '/deals/{id}' Returns a single deal available to the user, according to the unique deal ID provided If the specified deal does not exist, the request will return an error @param integer $id Unique identifier of a Deal @param array $options Additional request's options. @return array Searched Deal.
[ "Retrieve", "a", "single", "deal" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/DealsService.php#L89-L97
train
basecrm/basecrm-php
lib/DealsService.php
DealsService.update
public function update($id, array $deal, array $options = array()) { $attributes = array_intersect_key($deal, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); if (isset($attributes["value"])) $attributes["value"] = Coercion::toStringValue($attributes['value']); list($code, $updatedDeal) = $this->httpClient->put("/deals/{$id}", $attributes, $options); if (isset($options['raw']) && $options['raw']) { return $updatedDeal; } $updatedDeal = $this->coerceDealData($updatedDeal); return $updatedDeal; }
php
public function update($id, array $deal, array $options = array()) { $attributes = array_intersect_key($deal, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); if (isset($attributes["value"])) $attributes["value"] = Coercion::toStringValue($attributes['value']); list($code, $updatedDeal) = $this->httpClient->put("/deals/{$id}", $attributes, $options); if (isset($options['raw']) && $options['raw']) { return $updatedDeal; } $updatedDeal = $this->coerceDealData($updatedDeal); return $updatedDeal; }
[ "public", "function", "update", "(", "$", "id", ",", "array", "$", "deal", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "deal", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", "&&", "empty", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ")", "unset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "\"value\"", "]", ")", ")", "$", "attributes", "[", "\"value\"", "]", "=", "Coercion", "::", "toStringValue", "(", "$", "attributes", "[", "'value'", "]", ")", ";", "list", "(", "$", "code", ",", "$", "updatedDeal", ")", "=", "$", "this", "->", "httpClient", "->", "put", "(", "\"/deals/{$id}\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'raw'", "]", ")", "&&", "$", "options", "[", "'raw'", "]", ")", "{", "return", "$", "updatedDeal", ";", "}", "$", "updatedDeal", "=", "$", "this", "->", "coerceDealData", "(", "$", "updatedDeal", ")", ";", "return", "$", "updatedDeal", ";", "}" ]
Update a deal put '/deals/{id}' Updates deal information If the specified deal does not exist, the request will return an error <figure class="notice"> In order to modify tags used on a record, you need to supply the entire set `tags` are replaced every time they are used in a request </figure> @param integer $id Unique identifier of a Deal @param array $deal This array's attributes describe the object to be updated. @param array $options Additional request's options. @return array The resulting object representing updated resource.
[ "Update", "a", "deal" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/DealsService.php#L117-L129
train
basecrm/basecrm-php
lib/ProductsService.php
ProductsService.update
public function update($id, array $product, array $options = array()) { $attributes = array_intersect_key($product, array_flip(self::$keysToPersist)); list($code, $updatedProduct) = $this->httpClient->put("/products/{$id}", $attributes, $options); return $updatedProduct; }
php
public function update($id, array $product, array $options = array()) { $attributes = array_intersect_key($product, array_flip(self::$keysToPersist)); list($code, $updatedProduct) = $this->httpClient->put("/products/{$id}", $attributes, $options); return $updatedProduct; }
[ "public", "function", "update", "(", "$", "id", ",", "array", "$", "product", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "product", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "updatedProduct", ")", "=", "$", "this", "->", "httpClient", "->", "put", "(", "\"/products/{$id}\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "updatedProduct", ";", "}" ]
Update a product put '/products/{id}' Updates product information If the specified product does not exist, the request will return an error <figure class="notice"><p>In order to modify prices used on a record, you need to supply the entire set <code>prices</code> are replaced every time they are used in a request </p></figure> @param integer $id Unique identifier of a Product @param array $product This array's attributes describe the object to be updated. @param array $options Additional request's options. @return array The resulting object representing updated resource.
[ "Update", "a", "product" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/ProductsService.php#L103-L109
train
basecrm/basecrm-php
lib/ProductsService.php
ProductsService.destroy
public function destroy($id, array $options = array()) { list($code, $payload) = $this->httpClient->delete("/products/{$id}", null, $options); return $code == 204; }
php
public function destroy($id, array $options = array()) { list($code, $payload) = $this->httpClient->delete("/products/{$id}", null, $options); return $code == 204; }
[ "public", "function", "destroy", "(", "$", "id", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "list", "(", "$", "code", ",", "$", "payload", ")", "=", "$", "this", "->", "httpClient", "->", "delete", "(", "\"/products/{$id}\"", ",", "null", ",", "$", "options", ")", ";", "return", "$", "code", "==", "204", ";", "}" ]
Delete a product delete '/products/{id}' Delete an existing product from the catalog Existing orders and line items are not affected If the specified product does not exist, the request will return an error This operation cannot be undone Products can be removed only by an account administrator @param integer $id Unique identifier of a Product @param array $options Additional request's options. @return boolean Status of the operation.
[ "Delete", "a", "product" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/ProductsService.php#L127-L131
train
rockettheme/toolbox
Blueprints/src/BlueprintForm.php
BlueprintForm.load
public function load($extends = null) { // Only load and extend blueprint if it has not yet been loaded. if (empty($this->items) && $this->filename) { // Get list of files. $files = $this->getFiles($this->filename); // Load and extend blueprints. $data = $this->doLoad($files, $extends); $this->items = (array) array_shift($data); foreach ($data as $content) { $this->extend($content, true); } } // Import blueprints. $this->deepInit($this->items); return $this; }
php
public function load($extends = null) { // Only load and extend blueprint if it has not yet been loaded. if (empty($this->items) && $this->filename) { // Get list of files. $files = $this->getFiles($this->filename); // Load and extend blueprints. $data = $this->doLoad($files, $extends); $this->items = (array) array_shift($data); foreach ($data as $content) { $this->extend($content, true); } } // Import blueprints. $this->deepInit($this->items); return $this; }
[ "public", "function", "load", "(", "$", "extends", "=", "null", ")", "{", "// Only load and extend blueprint if it has not yet been loaded.", "if", "(", "empty", "(", "$", "this", "->", "items", ")", "&&", "$", "this", "->", "filename", ")", "{", "// Get list of files.", "$", "files", "=", "$", "this", "->", "getFiles", "(", "$", "this", "->", "filename", ")", ";", "// Load and extend blueprints.", "$", "data", "=", "$", "this", "->", "doLoad", "(", "$", "files", ",", "$", "extends", ")", ";", "$", "this", "->", "items", "=", "(", "array", ")", "array_shift", "(", "$", "data", ")", ";", "foreach", "(", "$", "data", "as", "$", "content", ")", "{", "$", "this", "->", "extend", "(", "$", "content", ",", "true", ")", ";", "}", "}", "// Import blueprints.", "$", "this", "->", "deepInit", "(", "$", "this", "->", "items", ")", ";", "return", "$", "this", ";", "}" ]
Load blueprint. @return $this
[ "Load", "blueprint", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintForm.php#L118-L139
train
rockettheme/toolbox
Blueprints/src/BlueprintForm.php
BlueprintForm.fields
public function fields() { $fields = $this->get('form/fields'); if ($fields === null) { $field = $this->get('form/field'); $fields = $field !== null ? ['' => (array) $field] : $fields; } return (array) $fields; }
php
public function fields() { $fields = $this->get('form/fields'); if ($fields === null) { $field = $this->get('form/field'); $fields = $field !== null ? ['' => (array) $field] : $fields; } return (array) $fields; }
[ "public", "function", "fields", "(", ")", "{", "$", "fields", "=", "$", "this", "->", "get", "(", "'form/fields'", ")", ";", "if", "(", "$", "fields", "===", "null", ")", "{", "$", "field", "=", "$", "this", "->", "get", "(", "'form/field'", ")", ";", "$", "fields", "=", "$", "field", "!==", "null", "?", "[", "''", "=>", "(", "array", ")", "$", "field", "]", ":", "$", "fields", ";", "}", "return", "(", "array", ")", "$", "fields", ";", "}" ]
Get form fields. @return array
[ "Get", "form", "fields", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintForm.php#L202-L212
train
rockettheme/toolbox
Blueprints/src/BlueprintForm.php
BlueprintForm.extend
public function extend($extends, $append = false) { if ($extends instanceof self) { $extends = $extends->toArray(); } if ($append) { $a = $this->items; $b = $extends; } else { $a = $extends; $b = $this->items; } $this->items = $this->deepMerge($a, $b); return $this; }
php
public function extend($extends, $append = false) { if ($extends instanceof self) { $extends = $extends->toArray(); } if ($append) { $a = $this->items; $b = $extends; } else { $a = $extends; $b = $this->items; } $this->items = $this->deepMerge($a, $b); return $this; }
[ "public", "function", "extend", "(", "$", "extends", ",", "$", "append", "=", "false", ")", "{", "if", "(", "$", "extends", "instanceof", "self", ")", "{", "$", "extends", "=", "$", "extends", "->", "toArray", "(", ")", ";", "}", "if", "(", "$", "append", ")", "{", "$", "a", "=", "$", "this", "->", "items", ";", "$", "b", "=", "$", "extends", ";", "}", "else", "{", "$", "a", "=", "$", "extends", ";", "$", "b", "=", "$", "this", "->", "items", ";", "}", "$", "this", "->", "items", "=", "$", "this", "->", "deepMerge", "(", "$", "a", ",", "$", "b", ")", ";", "return", "$", "this", ";", "}" ]
Extend blueprint with another blueprint. @param BlueprintForm|array $extends @param bool $append @return $this
[ "Extend", "blueprint", "with", "another", "blueprint", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintForm.php#L221-L238
train
rockettheme/toolbox
Blueprints/src/BlueprintForm.php
BlueprintForm.deepMerge
protected function deepMerge(array $a, array $b) { $bref_stack = [&$a]; $head_stack = [$b]; do { end($bref_stack); $bref = &$bref_stack[key($bref_stack)]; $head = array_pop($head_stack); unset($bref_stack[key($bref_stack)]); foreach ($head as $key => $value) { if (strpos($key, '@') !== false) { // Remove @ from the start and the end. Key syntax `import@2` is supported to allow multiple operations of the same type. $list = explode('-', preg_replace('/^(@*)?([^@]+)(@\d*)?$/', '\2', $key), 2); $action = array_shift($list); $property = array_shift($list); switch ($action) { case 'unset': case 'replace': if (!$property) { $bref = ['unset@' => true]; } else { unset($bref[$property]); } continue 2; } } if (isset($key, $bref[$key]) && \is_array($bref[$key]) && \is_array($head[$key])) { $bref_stack[] = &$bref[$key]; $head_stack[] = $head[$key]; } else { $bref = array_merge($bref, [$key => $head[$key]]); } } } while (\count($head_stack)); return $a; }
php
protected function deepMerge(array $a, array $b) { $bref_stack = [&$a]; $head_stack = [$b]; do { end($bref_stack); $bref = &$bref_stack[key($bref_stack)]; $head = array_pop($head_stack); unset($bref_stack[key($bref_stack)]); foreach ($head as $key => $value) { if (strpos($key, '@') !== false) { // Remove @ from the start and the end. Key syntax `import@2` is supported to allow multiple operations of the same type. $list = explode('-', preg_replace('/^(@*)?([^@]+)(@\d*)?$/', '\2', $key), 2); $action = array_shift($list); $property = array_shift($list); switch ($action) { case 'unset': case 'replace': if (!$property) { $bref = ['unset@' => true]; } else { unset($bref[$property]); } continue 2; } } if (isset($key, $bref[$key]) && \is_array($bref[$key]) && \is_array($head[$key])) { $bref_stack[] = &$bref[$key]; $head_stack[] = $head[$key]; } else { $bref = array_merge($bref, [$key => $head[$key]]); } } } while (\count($head_stack)); return $a; }
[ "protected", "function", "deepMerge", "(", "array", "$", "a", ",", "array", "$", "b", ")", "{", "$", "bref_stack", "=", "[", "&", "$", "a", "]", ";", "$", "head_stack", "=", "[", "$", "b", "]", ";", "do", "{", "end", "(", "$", "bref_stack", ")", ";", "$", "bref", "=", "&", "$", "bref_stack", "[", "key", "(", "$", "bref_stack", ")", "]", ";", "$", "head", "=", "array_pop", "(", "$", "head_stack", ")", ";", "unset", "(", "$", "bref_stack", "[", "key", "(", "$", "bref_stack", ")", "]", ")", ";", "foreach", "(", "$", "head", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "key", ",", "'@'", ")", "!==", "false", ")", "{", "// Remove @ from the start and the end. Key syntax `import@2` is supported to allow multiple operations of the same type.", "$", "list", "=", "explode", "(", "'-'", ",", "preg_replace", "(", "'/^(@*)?([^@]+)(@\\d*)?$/'", ",", "'\\2'", ",", "$", "key", ")", ",", "2", ")", ";", "$", "action", "=", "array_shift", "(", "$", "list", ")", ";", "$", "property", "=", "array_shift", "(", "$", "list", ")", ";", "switch", "(", "$", "action", ")", "{", "case", "'unset'", ":", "case", "'replace'", ":", "if", "(", "!", "$", "property", ")", "{", "$", "bref", "=", "[", "'unset@'", "=>", "true", "]", ";", "}", "else", "{", "unset", "(", "$", "bref", "[", "$", "property", "]", ")", ";", "}", "continue", "2", ";", "}", "}", "if", "(", "isset", "(", "$", "key", ",", "$", "bref", "[", "$", "key", "]", ")", "&&", "\\", "is_array", "(", "$", "bref", "[", "$", "key", "]", ")", "&&", "\\", "is_array", "(", "$", "head", "[", "$", "key", "]", ")", ")", "{", "$", "bref_stack", "[", "]", "=", "&", "$", "bref", "[", "$", "key", "]", ";", "$", "head_stack", "[", "]", "=", "$", "head", "[", "$", "key", "]", ";", "}", "else", "{", "$", "bref", "=", "array_merge", "(", "$", "bref", ",", "[", "$", "key", "=>", "$", "head", "[", "$", "key", "]", "]", ")", ";", "}", "}", "}", "while", "(", "\\", "count", "(", "$", "head_stack", ")", ")", ";", "return", "$", "a", ";", "}" ]
Deep merge two arrays together. @param array $a @param array $b @return array
[ "Deep", "merge", "two", "arrays", "together", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintForm.php#L321-L361
train
rockettheme/toolbox
Blueprints/src/BlueprintForm.php
BlueprintForm.doLoad
protected function doLoad(array $files, $extends = null) { $filename = array_shift($files); $content = $this->loadFile($filename); $key = ''; if (isset($content['extends@'])) { $key = 'extends@'; } elseif (isset($content['@extends'])) { $key = '@extends'; } elseif (isset($content['@extends@'])) { $key = '@extends@'; } $override = (bool)$extends; $extends = (array)($key && !$extends ? $content[$key] : $extends); unset($content['extends@'], $content['@extends'], $content['@extends@']); $data = $extends ? $this->doExtend($filename, $files, $extends, $override) : []; $data[] = $content; return $data; }
php
protected function doLoad(array $files, $extends = null) { $filename = array_shift($files); $content = $this->loadFile($filename); $key = ''; if (isset($content['extends@'])) { $key = 'extends@'; } elseif (isset($content['@extends'])) { $key = '@extends'; } elseif (isset($content['@extends@'])) { $key = '@extends@'; } $override = (bool)$extends; $extends = (array)($key && !$extends ? $content[$key] : $extends); unset($content['extends@'], $content['@extends'], $content['@extends@']); $data = $extends ? $this->doExtend($filename, $files, $extends, $override) : []; $data[] = $content; return $data; }
[ "protected", "function", "doLoad", "(", "array", "$", "files", ",", "$", "extends", "=", "null", ")", "{", "$", "filename", "=", "array_shift", "(", "$", "files", ")", ";", "$", "content", "=", "$", "this", "->", "loadFile", "(", "$", "filename", ")", ";", "$", "key", "=", "''", ";", "if", "(", "isset", "(", "$", "content", "[", "'extends@'", "]", ")", ")", "{", "$", "key", "=", "'extends@'", ";", "}", "elseif", "(", "isset", "(", "$", "content", "[", "'@extends'", "]", ")", ")", "{", "$", "key", "=", "'@extends'", ";", "}", "elseif", "(", "isset", "(", "$", "content", "[", "'@extends@'", "]", ")", ")", "{", "$", "key", "=", "'@extends@'", ";", "}", "$", "override", "=", "(", "bool", ")", "$", "extends", ";", "$", "extends", "=", "(", "array", ")", "(", "$", "key", "&&", "!", "$", "extends", "?", "$", "content", "[", "$", "key", "]", ":", "$", "extends", ")", ";", "unset", "(", "$", "content", "[", "'extends@'", "]", ",", "$", "content", "[", "'@extends'", "]", ",", "$", "content", "[", "'@extends@'", "]", ")", ";", "$", "data", "=", "$", "extends", "?", "$", "this", "->", "doExtend", "(", "$", "filename", ",", "$", "files", ",", "$", "extends", ",", "$", "override", ")", ":", "[", "]", ";", "$", "data", "[", "]", "=", "$", "content", ";", "return", "$", "data", ";", "}" ]
Internal function that handles loading extended blueprints. @param array $files @param string|array|null $extends @return array
[ "Internal", "function", "that", "handles", "loading", "extended", "blueprints", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintForm.php#L486-L509
train
rockettheme/toolbox
Blueprints/src/BlueprintForm.php
BlueprintForm.doExtend
protected function doExtend($filename, array $parents, array $extends, $override = false) { if (\is_string(key($extends))) { $extends = [$extends]; } $data = [[]]; foreach ($extends as $value) { // Accept array of type and context or a string. $type = !\is_string($value) ? (!isset($value['type']) ? null : $value['type']) : $value; if (!$type) { continue; } if ($type === '@parent' || $type === 'parent@') { if (!$parents) { throw new RuntimeException("Parent blueprint missing for '{$filename}'"); } $files = $parents; } else { $files = $this->getFiles($type, isset($value['context']) ? $value['context'] : null); if ($override && !$files) { throw new RuntimeException("Blueprint '{$type}' missing for '{$filename}'"); } // Detect extend loops. if ($files && array_intersect($files, $parents)) { // Let's check if user really meant extends@: parent@. $index = \array_search($filename, $files, true); if ($index !== false) { // We want to grab only the parents of the file which is currently being loaded. $files = \array_slice($files, $index + 1); } if ($files !== $parents) { throw new RuntimeException("Loop detected while extending blueprint file '{$filename}'"); } if (!$parents) { throw new RuntimeException("Parent blueprint missing for '{$filename}'"); } } } if ($files) { $data[] = $this->doLoad($files); } } // TODO: In PHP 5.6+ use array_merge(...$data); return call_user_func_array('array_merge', $data); }
php
protected function doExtend($filename, array $parents, array $extends, $override = false) { if (\is_string(key($extends))) { $extends = [$extends]; } $data = [[]]; foreach ($extends as $value) { // Accept array of type and context or a string. $type = !\is_string($value) ? (!isset($value['type']) ? null : $value['type']) : $value; if (!$type) { continue; } if ($type === '@parent' || $type === 'parent@') { if (!$parents) { throw new RuntimeException("Parent blueprint missing for '{$filename}'"); } $files = $parents; } else { $files = $this->getFiles($type, isset($value['context']) ? $value['context'] : null); if ($override && !$files) { throw new RuntimeException("Blueprint '{$type}' missing for '{$filename}'"); } // Detect extend loops. if ($files && array_intersect($files, $parents)) { // Let's check if user really meant extends@: parent@. $index = \array_search($filename, $files, true); if ($index !== false) { // We want to grab only the parents of the file which is currently being loaded. $files = \array_slice($files, $index + 1); } if ($files !== $parents) { throw new RuntimeException("Loop detected while extending blueprint file '{$filename}'"); } if (!$parents) { throw new RuntimeException("Parent blueprint missing for '{$filename}'"); } } } if ($files) { $data[] = $this->doLoad($files); } } // TODO: In PHP 5.6+ use array_merge(...$data); return call_user_func_array('array_merge', $data); }
[ "protected", "function", "doExtend", "(", "$", "filename", ",", "array", "$", "parents", ",", "array", "$", "extends", ",", "$", "override", "=", "false", ")", "{", "if", "(", "\\", "is_string", "(", "key", "(", "$", "extends", ")", ")", ")", "{", "$", "extends", "=", "[", "$", "extends", "]", ";", "}", "$", "data", "=", "[", "[", "]", "]", ";", "foreach", "(", "$", "extends", "as", "$", "value", ")", "{", "// Accept array of type and context or a string.", "$", "type", "=", "!", "\\", "is_string", "(", "$", "value", ")", "?", "(", "!", "isset", "(", "$", "value", "[", "'type'", "]", ")", "?", "null", ":", "$", "value", "[", "'type'", "]", ")", ":", "$", "value", ";", "if", "(", "!", "$", "type", ")", "{", "continue", ";", "}", "if", "(", "$", "type", "===", "'@parent'", "||", "$", "type", "===", "'parent@'", ")", "{", "if", "(", "!", "$", "parents", ")", "{", "throw", "new", "RuntimeException", "(", "\"Parent blueprint missing for '{$filename}'\"", ")", ";", "}", "$", "files", "=", "$", "parents", ";", "}", "else", "{", "$", "files", "=", "$", "this", "->", "getFiles", "(", "$", "type", ",", "isset", "(", "$", "value", "[", "'context'", "]", ")", "?", "$", "value", "[", "'context'", "]", ":", "null", ")", ";", "if", "(", "$", "override", "&&", "!", "$", "files", ")", "{", "throw", "new", "RuntimeException", "(", "\"Blueprint '{$type}' missing for '{$filename}'\"", ")", ";", "}", "// Detect extend loops.", "if", "(", "$", "files", "&&", "array_intersect", "(", "$", "files", ",", "$", "parents", ")", ")", "{", "// Let's check if user really meant extends@: parent@.", "$", "index", "=", "\\", "array_search", "(", "$", "filename", ",", "$", "files", ",", "true", ")", ";", "if", "(", "$", "index", "!==", "false", ")", "{", "// We want to grab only the parents of the file which is currently being loaded.", "$", "files", "=", "\\", "array_slice", "(", "$", "files", ",", "$", "index", "+", "1", ")", ";", "}", "if", "(", "$", "files", "!==", "$", "parents", ")", "{", "throw", "new", "RuntimeException", "(", "\"Loop detected while extending blueprint file '{$filename}'\"", ")", ";", "}", "if", "(", "!", "$", "parents", ")", "{", "throw", "new", "RuntimeException", "(", "\"Parent blueprint missing for '{$filename}'\"", ")", ";", "}", "}", "}", "if", "(", "$", "files", ")", "{", "$", "data", "[", "]", "=", "$", "this", "->", "doLoad", "(", "$", "files", ")", ";", "}", "}", "// TODO: In PHP 5.6+ use array_merge(...$data);", "return", "call_user_func_array", "(", "'array_merge'", ",", "$", "data", ")", ";", "}" ]
Internal function to recursively load extended blueprints. @param string $filename @param array $parents @param array $extends @return array
[ "Internal", "function", "to", "recursively", "load", "extended", "blueprints", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintForm.php#L519-L571
train
rockettheme/toolbox
Blueprints/src/BlueprintForm.php
BlueprintForm.doReorder
protected function doReorder(array $items, array $keys) { $reordered = array_keys($items); foreach ($keys as $item => $ordering) { if ((string)(int) $ordering === (string) $ordering) { $location = array_search($item, $reordered, true); $rel = array_splice($reordered, $location, 1); array_splice($reordered, $ordering, 0, $rel); } elseif (isset($items[$ordering])) { $location = array_search($item, $reordered, true); $rel = array_splice($reordered, $location, 1); $location = array_search($ordering, $reordered, true); array_splice($reordered, $location + 1, 0, $rel); } } return array_merge(array_flip($reordered), $items); }
php
protected function doReorder(array $items, array $keys) { $reordered = array_keys($items); foreach ($keys as $item => $ordering) { if ((string)(int) $ordering === (string) $ordering) { $location = array_search($item, $reordered, true); $rel = array_splice($reordered, $location, 1); array_splice($reordered, $ordering, 0, $rel); } elseif (isset($items[$ordering])) { $location = array_search($item, $reordered, true); $rel = array_splice($reordered, $location, 1); $location = array_search($ordering, $reordered, true); array_splice($reordered, $location + 1, 0, $rel); } } return array_merge(array_flip($reordered), $items); }
[ "protected", "function", "doReorder", "(", "array", "$", "items", ",", "array", "$", "keys", ")", "{", "$", "reordered", "=", "array_keys", "(", "$", "items", ")", ";", "foreach", "(", "$", "keys", "as", "$", "item", "=>", "$", "ordering", ")", "{", "if", "(", "(", "string", ")", "(", "int", ")", "$", "ordering", "===", "(", "string", ")", "$", "ordering", ")", "{", "$", "location", "=", "array_search", "(", "$", "item", ",", "$", "reordered", ",", "true", ")", ";", "$", "rel", "=", "array_splice", "(", "$", "reordered", ",", "$", "location", ",", "1", ")", ";", "array_splice", "(", "$", "reordered", ",", "$", "ordering", ",", "0", ",", "$", "rel", ")", ";", "}", "elseif", "(", "isset", "(", "$", "items", "[", "$", "ordering", "]", ")", ")", "{", "$", "location", "=", "array_search", "(", "$", "item", ",", "$", "reordered", ",", "true", ")", ";", "$", "rel", "=", "array_splice", "(", "$", "reordered", ",", "$", "location", ",", "1", ")", ";", "$", "location", "=", "array_search", "(", "$", "ordering", ",", "$", "reordered", ",", "true", ")", ";", "array_splice", "(", "$", "reordered", ",", "$", "location", "+", "1", ",", "0", ",", "$", "rel", ")", ";", "}", "}", "return", "array_merge", "(", "array_flip", "(", "$", "reordered", ")", ",", "$", "items", ")", ";", "}" ]
Internal function to reorder items. @param array $items @param array $keys @return array
[ "Internal", "function", "to", "reorder", "items", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintForm.php#L580-L599
train
silverstripe/cwp-search
src/CwpSearchPageController.php
CwpSearchPageController.generateSearchRecord
protected function generateSearchRecord() { $searchPage = CwpSearchPage::create(); $searchPage->URLSegment = 'search'; $searchPage->Title = _t('SilverStripe\\CMS\\Search\\SearchForm.SearchResults', 'Search Results'); $searchPage->ID = -1; return $searchPage; }
php
protected function generateSearchRecord() { $searchPage = CwpSearchPage::create(); $searchPage->URLSegment = 'search'; $searchPage->Title = _t('SilverStripe\\CMS\\Search\\SearchForm.SearchResults', 'Search Results'); $searchPage->ID = -1; return $searchPage; }
[ "protected", "function", "generateSearchRecord", "(", ")", "{", "$", "searchPage", "=", "CwpSearchPage", "::", "create", "(", ")", ";", "$", "searchPage", "->", "URLSegment", "=", "'search'", ";", "$", "searchPage", "->", "Title", "=", "_t", "(", "'SilverStripe\\\\CMS\\\\Search\\\\SearchForm.SearchResults'", ",", "'Search Results'", ")", ";", "$", "searchPage", "->", "ID", "=", "-", "1", ";", "return", "$", "searchPage", ";", "}" ]
Create the dummy search record for this page @return CwpSearchPage
[ "Create", "the", "dummy", "search", "record", "for", "this", "page" ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/CwpSearchPageController.php#L19-L26
train
silverstripe/silverstripe-graphql-devtools
src/GraphiQLController.php
GraphiQLController.init
public function init() { parent::init(); $routes = $this->findAvailableRoutes(); $route = $this->getRequest()->getVar('endpoint') ?: $this->config()->default_route; // Legacy. Find the first route mapped to the controller. if (!$route && !empty($routes)) { $route = $routes[0]; } if (!$route) { throw new \RuntimeException("There are no routes set up for a GraphQL server. You will need to add one to the SilverStripe\Control\Director.rules config setting."); } $route = trim($route, '/'); $jsonRoutes = json_encode($routes); $securityID = Controller::config()->enable_csrf_protection ? "'" . SecurityToken::inst()->getValue() . "'" : 'null'; Requirements::customScript( <<<JS var GRAPHQL_ROUTE = '{$route}'; var GRAPHQL_ROUTES = $jsonRoutes; var SECURITY_ID = $securityID; JS ); Requirements::javascript('silverstripe/graphql-devtools: client/dist/graphiql.js'); }
php
public function init() { parent::init(); $routes = $this->findAvailableRoutes(); $route = $this->getRequest()->getVar('endpoint') ?: $this->config()->default_route; // Legacy. Find the first route mapped to the controller. if (!$route && !empty($routes)) { $route = $routes[0]; } if (!$route) { throw new \RuntimeException("There are no routes set up for a GraphQL server. You will need to add one to the SilverStripe\Control\Director.rules config setting."); } $route = trim($route, '/'); $jsonRoutes = json_encode($routes); $securityID = Controller::config()->enable_csrf_protection ? "'" . SecurityToken::inst()->getValue() . "'" : 'null'; Requirements::customScript( <<<JS var GRAPHQL_ROUTE = '{$route}'; var GRAPHQL_ROUTES = $jsonRoutes; var SECURITY_ID = $securityID; JS ); Requirements::javascript('silverstripe/graphql-devtools: client/dist/graphiql.js'); }
[ "public", "function", "init", "(", ")", "{", "parent", "::", "init", "(", ")", ";", "$", "routes", "=", "$", "this", "->", "findAvailableRoutes", "(", ")", ";", "$", "route", "=", "$", "this", "->", "getRequest", "(", ")", "->", "getVar", "(", "'endpoint'", ")", "?", ":", "$", "this", "->", "config", "(", ")", "->", "default_route", ";", "// Legacy. Find the first route mapped to the controller.", "if", "(", "!", "$", "route", "&&", "!", "empty", "(", "$", "routes", ")", ")", "{", "$", "route", "=", "$", "routes", "[", "0", "]", ";", "}", "if", "(", "!", "$", "route", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"There are no routes set up for a GraphQL server. You will need to add one to the SilverStripe\\Control\\Director.rules config setting.\"", ")", ";", "}", "$", "route", "=", "trim", "(", "$", "route", ",", "'/'", ")", ";", "$", "jsonRoutes", "=", "json_encode", "(", "$", "routes", ")", ";", "$", "securityID", "=", "Controller", "::", "config", "(", ")", "->", "enable_csrf_protection", "?", "\"'\"", ".", "SecurityToken", "::", "inst", "(", ")", "->", "getValue", "(", ")", ".", "\"'\"", ":", "'null'", ";", "Requirements", "::", "customScript", "(", "\n <<<JS\nvar GRAPHQL_ROUTE = '{$route}';\nvar GRAPHQL_ROUTES = $jsonRoutes;\nvar SECURITY_ID = $securityID;\nJS", ")", ";", "Requirements", "::", "javascript", "(", "'silverstripe/graphql-devtools: client/dist/graphiql.js'", ")", ";", "}" ]
Initialise the controller, sanity check, load javascript. Note that permission checks are handled by DevelopmentAdmin.
[ "Initialise", "the", "controller", "sanity", "check", "load", "javascript", ".", "Note", "that", "permission", "checks", "are", "handled", "by", "DevelopmentAdmin", "." ]
d73f56c845e3a1c029eec0e0d676e4dd40579513
https://github.com/silverstripe/silverstripe-graphql-devtools/blob/d73f56c845e3a1c029eec0e0d676e4dd40579513/src/GraphiQLController.php#L24-L54
train
silverstripe/silverstripe-graphql-devtools
src/GraphiQLController.php
GraphiQLController.findAvailableRoutes
protected function findAvailableRoutes() { $routes = []; $rules = Director::config()->get('rules'); foreach ($rules as $pattern => $controllerInfo) { $routeClass = (is_string($controllerInfo)) ? $controllerInfo : $controllerInfo['Controller']; try { $routeController = Injector::inst()->get($routeClass); if ($routeController instanceof Controller) { $routes[] = $pattern; } } catch (InjectorNotFoundException $ex) { } } return $routes; }
php
protected function findAvailableRoutes() { $routes = []; $rules = Director::config()->get('rules'); foreach ($rules as $pattern => $controllerInfo) { $routeClass = (is_string($controllerInfo)) ? $controllerInfo : $controllerInfo['Controller']; try { $routeController = Injector::inst()->get($routeClass); if ($routeController instanceof Controller) { $routes[] = $pattern; } } catch (InjectorNotFoundException $ex) { } } return $routes; }
[ "protected", "function", "findAvailableRoutes", "(", ")", "{", "$", "routes", "=", "[", "]", ";", "$", "rules", "=", "Director", "::", "config", "(", ")", "->", "get", "(", "'rules'", ")", ";", "foreach", "(", "$", "rules", "as", "$", "pattern", "=>", "$", "controllerInfo", ")", "{", "$", "routeClass", "=", "(", "is_string", "(", "$", "controllerInfo", ")", ")", "?", "$", "controllerInfo", ":", "$", "controllerInfo", "[", "'Controller'", "]", ";", "try", "{", "$", "routeController", "=", "Injector", "::", "inst", "(", ")", "->", "get", "(", "$", "routeClass", ")", ";", "if", "(", "$", "routeController", "instanceof", "Controller", ")", "{", "$", "routes", "[", "]", "=", "$", "pattern", ";", "}", "}", "catch", "(", "InjectorNotFoundException", "$", "ex", ")", "{", "}", "}", "return", "$", "routes", ";", "}" ]
Find all available graphql routes @return string[]
[ "Find", "all", "available", "graphql", "routes" ]
d73f56c845e3a1c029eec0e0d676e4dd40579513
https://github.com/silverstripe/silverstripe-graphql-devtools/blob/d73f56c845e3a1c029eec0e0d676e4dd40579513/src/GraphiQLController.php#L60-L78
train
basecrm/basecrm-php
lib/LineItemsService.php
LineItemsService.all
public function all($order_id, $params = [], array $options = array()) { list($code, $line_items) = $this->httpClient->get("/orders/{$order_id}/line_items", $params, $options); return $line_items; }
php
public function all($order_id, $params = [], array $options = array()) { list($code, $line_items) = $this->httpClient->get("/orders/{$order_id}/line_items", $params, $options); return $line_items; }
[ "public", "function", "all", "(", "$", "order_id", ",", "$", "params", "=", "[", "]", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "list", "(", "$", "code", ",", "$", "line_items", ")", "=", "$", "this", "->", "httpClient", "->", "get", "(", "\"/orders/{$order_id}/line_items\"", ",", "$", "params", ",", "$", "options", ")", ";", "return", "$", "line_items", ";", "}" ]
Retrieve order's line items get '/orders/{order_id}/line_items' Returns all line items associated to order @param integer $order_id Unique identifier of a Order @param array $params Search options @param array $options Additional request's options. @return array The list of LineItems for the first page, unless otherwise specified.
[ "Retrieve", "order", "s", "line", "items" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/LineItemsService.php#L42-L46
train
basecrm/basecrm-php
lib/LineItemsService.php
LineItemsService.create
public function create($order_id, array $lineItem, array $options = array()) { $attributes = array_intersect_key($lineItem, array_flip(self::$keysToPersist)); list($code, $createdLineItem) = $this->httpClient->post("/orders/{$order_id}/line_items", $attributes, $options); return $createdLineItem; }
php
public function create($order_id, array $lineItem, array $options = array()) { $attributes = array_intersect_key($lineItem, array_flip(self::$keysToPersist)); list($code, $createdLineItem) = $this->httpClient->post("/orders/{$order_id}/line_items", $attributes, $options); return $createdLineItem; }
[ "public", "function", "create", "(", "$", "order_id", ",", "array", "$", "lineItem", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "lineItem", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "createdLineItem", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "\"/orders/{$order_id}/line_items\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "createdLineItem", ";", "}" ]
Create a line item post '/orders/{order_id}/line_items' Adds a new line item to an existing order Line items correspond to products in the catalog, so first you must create products Because products allow defining different prices in different currencies, when creating a line item, the parameter currency is required @param integer $order_id Unique identifier of a Order @param array $lineItem This array's attributes describe the object to be created. @param array $options Additional request's options. @return array The resulting object representing created resource.
[ "Create", "a", "line", "item" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/LineItemsService.php#L63-L69
train
basecrm/basecrm-php
lib/LineItemsService.php
LineItemsService.get
public function get($order_id, $id, array $options = array()) { list($code, $line_item) = $this->httpClient->get("/orders/{$order_id}/line_items/{$id}", null, $options); return $line_item; }
php
public function get($order_id, $id, array $options = array()) { list($code, $line_item) = $this->httpClient->get("/orders/{$order_id}/line_items/{$id}", null, $options); return $line_item; }
[ "public", "function", "get", "(", "$", "order_id", ",", "$", "id", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "list", "(", "$", "code", ",", "$", "line_item", ")", "=", "$", "this", "->", "httpClient", "->", "get", "(", "\"/orders/{$order_id}/line_items/{$id}\"", ",", "null", ",", "$", "options", ")", ";", "return", "$", "line_item", ";", "}" ]
Retrieve a single line item get '/orders/{order_id}/line_items/{id}' Returns a single line item of an order, according to the unique line item ID provided @param integer $order_id Unique identifier of a Order @param integer $id Unique identifier of a LineItem @param array $options Additional request's options. @return array Searched LineItem.
[ "Retrieve", "a", "single", "line", "item" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/LineItemsService.php#L84-L88
train
basecrm/basecrm-php
lib/ContactsService.php
ContactsService.create
public function create(array $contact, array $options = array()) { $attributes = array_intersect_key($contact, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); list($code, $createdContact) = $this->httpClient->post("/contacts", $attributes, $options); return $createdContact; }
php
public function create(array $contact, array $options = array()) { $attributes = array_intersect_key($contact, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); list($code, $createdContact) = $this->httpClient->post("/contacts", $attributes, $options); return $createdContact; }
[ "public", "function", "create", "(", "array", "$", "contact", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "contact", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", "&&", "empty", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ")", "unset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ";", "list", "(", "$", "code", ",", "$", "createdContact", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "\"/contacts\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "createdContact", ";", "}" ]
Create a contact post '/contacts' Create a new contact A contact may represent a single individual or an organization @param array $contact This array's attributes describe the object to be created. @param array $options Additional request's options. @return array The resulting object representing created resource.
[ "Create", "a", "contact" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/ContactsService.php#L60-L67
train
basecrm/basecrm-php
lib/ContactsService.php
ContactsService.update
public function update($id, array $contact, array $options = array()) { $attributes = array_intersect_key($contact, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); list($code, $updatedContact) = $this->httpClient->put("/contacts/{$id}", $attributes, $options); return $updatedContact; }
php
public function update($id, array $contact, array $options = array()) { $attributes = array_intersect_key($contact, array_flip(self::$keysToPersist)); if (isset($attributes['custom_fields']) && empty($attributes['custom_fields'])) unset($attributes['custom_fields']); list($code, $updatedContact) = $this->httpClient->put("/contacts/{$id}", $attributes, $options); return $updatedContact; }
[ "public", "function", "update", "(", "$", "id", ",", "array", "$", "contact", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "contact", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", "&&", "empty", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ")", "unset", "(", "$", "attributes", "[", "'custom_fields'", "]", ")", ";", "list", "(", "$", "code", ",", "$", "updatedContact", ")", "=", "$", "this", "->", "httpClient", "->", "put", "(", "\"/contacts/{$id}\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "updatedContact", ";", "}" ]
Update a contact put '/contacts/{id}' Updates contact information If the specified contact does not exist, the request will return an error **Notice** When updating contact tags, you need to provide all tags Any missing tag will be removed from a contact's tags @param integer $id Unique identifier of a Contact @param array $contact This array's attributes describe the object to be updated. @param array $options Additional request's options. @return array The resulting object representing updated resource.
[ "Update", "a", "contact" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/ContactsService.php#L104-L111
train
rockettheme/toolbox
Blueprints/src/BlueprintSchema.php
BlueprintSchema.getState
public function getState() { return [ 'items' => $this->items, 'rules' => $this->rules, 'nested' => $this->nested, 'dynamic' => $this->dynamic, 'filter' => $this->filter ]; }
php
public function getState() { return [ 'items' => $this->items, 'rules' => $this->rules, 'nested' => $this->nested, 'dynamic' => $this->dynamic, 'filter' => $this->filter ]; }
[ "public", "function", "getState", "(", ")", "{", "return", "[", "'items'", "=>", "$", "this", "->", "items", ",", "'rules'", "=>", "$", "this", "->", "rules", ",", "'nested'", "=>", "$", "this", "->", "nested", ",", "'dynamic'", "=>", "$", "this", "->", "dynamic", ",", "'filter'", "=>", "$", "this", "->", "filter", "]", ";", "}" ]
Convert object into an array. @return array
[ "Convert", "object", "into", "an", "array", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintSchema.php#L167-L176
train
rockettheme/toolbox
Blueprints/src/BlueprintSchema.php
BlueprintSchema.embed
public function embed($name, array $value, $separator = '.', $merge = false) { if (isset($value['rules'])) { $this->rules = array_merge($this->rules, $value['rules']); } $name = $separator !== '.' ? str_replace($separator, '.', $name) : $name; if (isset($value['form'])) { $form = array_diff_key($value['form'], ['fields' => 1, 'field' => 1]); } else { $form = []; } $items = isset($this->items[$name]) ? $this->items[$name] : ['type' => '_root', 'form_field' => false]; $this->items[$name] = $items; $this->addProperty($name); $prefix = $name ? $name . '.' : ''; $params = array_intersect_key($form, $this->filter); $location = [$name]; if (isset($value['form']['field'])) { $this->parseFormField($name, $value['form']['field'], $params, $prefix, '', $merge, $location); } elseif (isset($value['form']['fields'])) { $this->parseFormFields($value['form']['fields'], $params, $prefix, '', $merge, $location); } $this->items[$name] += ['form' => $form]; return $this; }
php
public function embed($name, array $value, $separator = '.', $merge = false) { if (isset($value['rules'])) { $this->rules = array_merge($this->rules, $value['rules']); } $name = $separator !== '.' ? str_replace($separator, '.', $name) : $name; if (isset($value['form'])) { $form = array_diff_key($value['form'], ['fields' => 1, 'field' => 1]); } else { $form = []; } $items = isset($this->items[$name]) ? $this->items[$name] : ['type' => '_root', 'form_field' => false]; $this->items[$name] = $items; $this->addProperty($name); $prefix = $name ? $name . '.' : ''; $params = array_intersect_key($form, $this->filter); $location = [$name]; if (isset($value['form']['field'])) { $this->parseFormField($name, $value['form']['field'], $params, $prefix, '', $merge, $location); } elseif (isset($value['form']['fields'])) { $this->parseFormFields($value['form']['fields'], $params, $prefix, '', $merge, $location); } $this->items[$name] += ['form' => $form]; return $this; }
[ "public", "function", "embed", "(", "$", "name", ",", "array", "$", "value", ",", "$", "separator", "=", "'.'", ",", "$", "merge", "=", "false", ")", "{", "if", "(", "isset", "(", "$", "value", "[", "'rules'", "]", ")", ")", "{", "$", "this", "->", "rules", "=", "array_merge", "(", "$", "this", "->", "rules", ",", "$", "value", "[", "'rules'", "]", ")", ";", "}", "$", "name", "=", "$", "separator", "!==", "'.'", "?", "str_replace", "(", "$", "separator", ",", "'.'", ",", "$", "name", ")", ":", "$", "name", ";", "if", "(", "isset", "(", "$", "value", "[", "'form'", "]", ")", ")", "{", "$", "form", "=", "array_diff_key", "(", "$", "value", "[", "'form'", "]", ",", "[", "'fields'", "=>", "1", ",", "'field'", "=>", "1", "]", ")", ";", "}", "else", "{", "$", "form", "=", "[", "]", ";", "}", "$", "items", "=", "isset", "(", "$", "this", "->", "items", "[", "$", "name", "]", ")", "?", "$", "this", "->", "items", "[", "$", "name", "]", ":", "[", "'type'", "=>", "'_root'", ",", "'form_field'", "=>", "false", "]", ";", "$", "this", "->", "items", "[", "$", "name", "]", "=", "$", "items", ";", "$", "this", "->", "addProperty", "(", "$", "name", ")", ";", "$", "prefix", "=", "$", "name", "?", "$", "name", ".", "'.'", ":", "''", ";", "$", "params", "=", "array_intersect_key", "(", "$", "form", ",", "$", "this", "->", "filter", ")", ";", "$", "location", "=", "[", "$", "name", "]", ";", "if", "(", "isset", "(", "$", "value", "[", "'form'", "]", "[", "'field'", "]", ")", ")", "{", "$", "this", "->", "parseFormField", "(", "$", "name", ",", "$", "value", "[", "'form'", "]", "[", "'field'", "]", ",", "$", "params", ",", "$", "prefix", ",", "''", ",", "$", "merge", ",", "$", "location", ")", ";", "}", "elseif", "(", "isset", "(", "$", "value", "[", "'form'", "]", "[", "'fields'", "]", ")", ")", "{", "$", "this", "->", "parseFormFields", "(", "$", "value", "[", "'form'", "]", "[", "'fields'", "]", ",", "$", "params", ",", "$", "prefix", ",", "''", ",", "$", "merge", ",", "$", "location", ")", ";", "}", "$", "this", "->", "items", "[", "$", "name", "]", "+=", "[", "'form'", "=>", "$", "form", "]", ";", "return", "$", "this", ";", "}" ]
Embed an array to the blueprint. @param $name @param array $value @param string $separator @param bool $merge Merge fields instead replacing them. @return $this
[ "Embed", "an", "array", "to", "the", "blueprint", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintSchema.php#L199-L231
train
rockettheme/toolbox
Blueprints/src/BlueprintSchema.php
BlueprintSchema.getPropertyName
public function getPropertyName($path = null, $separator = '.') { $parts = explode($separator, $path); $nested = $this->nested; $result = []; while (($part = array_shift($parts)) !== null) { if (!isset($nested[$part])) { if (isset($nested['*'])) { $part = '*'; } else { return implode($separator, array_merge($result, [$part], $parts)); } } $result[] = $part; $nested = $nested[$part]; } return implode('.', $result); }
php
public function getPropertyName($path = null, $separator = '.') { $parts = explode($separator, $path); $nested = $this->nested; $result = []; while (($part = array_shift($parts)) !== null) { if (!isset($nested[$part])) { if (isset($nested['*'])) { $part = '*'; } else { return implode($separator, array_merge($result, [$part], $parts)); } } $result[] = $part; $nested = $nested[$part]; } return implode('.', $result); }
[ "public", "function", "getPropertyName", "(", "$", "path", "=", "null", ",", "$", "separator", "=", "'.'", ")", "{", "$", "parts", "=", "explode", "(", "$", "separator", ",", "$", "path", ")", ";", "$", "nested", "=", "$", "this", "->", "nested", ";", "$", "result", "=", "[", "]", ";", "while", "(", "(", "$", "part", "=", "array_shift", "(", "$", "parts", ")", ")", "!==", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "nested", "[", "$", "part", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "nested", "[", "'*'", "]", ")", ")", "{", "$", "part", "=", "'*'", ";", "}", "else", "{", "return", "implode", "(", "$", "separator", ",", "array_merge", "(", "$", "result", ",", "[", "$", "part", "]", ",", "$", "parts", ")", ")", ";", "}", "}", "$", "result", "[", "]", "=", "$", "part", ";", "$", "nested", "=", "$", "nested", "[", "$", "part", "]", ";", "}", "return", "implode", "(", "'.'", ",", "$", "result", ")", ";", "}" ]
Returns name of the property with given path. @param string $path @param string $separator @return string
[ "Returns", "name", "of", "the", "property", "with", "given", "path", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintSchema.php#L276-L295
train
rockettheme/toolbox
Blueprints/src/BlueprintSchema.php
BlueprintSchema.getNested
protected function getNested($path = null, $separator = '.') { if (!$path) { return $this->nested; } $parts = explode($separator, $path); $item = array_pop($parts); $nested = $this->nested; foreach ($parts as $part) { if (!isset($nested[$part])) { $part = '*'; if (!isset($nested[$part])) { return []; } } $nested = $nested[$part]; } return isset($nested[$item]) ? $nested[$item] : (isset($nested['*']) ? $nested['*'] : null); }
php
protected function getNested($path = null, $separator = '.') { if (!$path) { return $this->nested; } $parts = explode($separator, $path); $item = array_pop($parts); $nested = $this->nested; foreach ($parts as $part) { if (!isset($nested[$part])) { $part = '*'; if (!isset($nested[$part])) { return []; } } $nested = $nested[$part]; } return isset($nested[$item]) ? $nested[$item] : (isset($nested['*']) ? $nested['*'] : null); }
[ "protected", "function", "getNested", "(", "$", "path", "=", "null", ",", "$", "separator", "=", "'.'", ")", "{", "if", "(", "!", "$", "path", ")", "{", "return", "$", "this", "->", "nested", ";", "}", "$", "parts", "=", "explode", "(", "$", "separator", ",", "$", "path", ")", ";", "$", "item", "=", "array_pop", "(", "$", "parts", ")", ";", "$", "nested", "=", "$", "this", "->", "nested", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "if", "(", "!", "isset", "(", "$", "nested", "[", "$", "part", "]", ")", ")", "{", "$", "part", "=", "'*'", ";", "if", "(", "!", "isset", "(", "$", "nested", "[", "$", "part", "]", ")", ")", "{", "return", "[", "]", ";", "}", "}", "$", "nested", "=", "$", "nested", "[", "$", "part", "]", ";", "}", "return", "isset", "(", "$", "nested", "[", "$", "item", "]", ")", "?", "$", "nested", "[", "$", "item", "]", ":", "(", "isset", "(", "$", "nested", "[", "'*'", "]", ")", "?", "$", "nested", "[", "'*'", "]", ":", "null", ")", ";", "}" ]
Get property from the definition. @param string $path Comma separated path to the property. @param string $separator @return array|string|null @internal
[ "Get", "property", "from", "the", "definition", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintSchema.php#L367-L387
train
rockettheme/toolbox
Blueprints/src/BlueprintSchema.php
BlueprintSchema.parseFormFields
protected function parseFormFields(array $fields, array $params, $prefix = '', $parent = '', $merge = false, array $formPath = []) { if (isset($fields['type']) && !\is_array($fields['type'])) { return; } // Go though all the fields in current level. foreach ($fields as $key => $field) { $this->parseFormField($key, $field, $params, $prefix, $parent, $merge, $formPath); } }
php
protected function parseFormFields(array $fields, array $params, $prefix = '', $parent = '', $merge = false, array $formPath = []) { if (isset($fields['type']) && !\is_array($fields['type'])) { return; } // Go though all the fields in current level. foreach ($fields as $key => $field) { $this->parseFormField($key, $field, $params, $prefix, $parent, $merge, $formPath); } }
[ "protected", "function", "parseFormFields", "(", "array", "$", "fields", ",", "array", "$", "params", ",", "$", "prefix", "=", "''", ",", "$", "parent", "=", "''", ",", "$", "merge", "=", "false", ",", "array", "$", "formPath", "=", "[", "]", ")", "{", "if", "(", "isset", "(", "$", "fields", "[", "'type'", "]", ")", "&&", "!", "\\", "is_array", "(", "$", "fields", "[", "'type'", "]", ")", ")", "{", "return", ";", "}", "// Go though all the fields in current level.", "foreach", "(", "$", "fields", "as", "$", "key", "=>", "$", "field", ")", "{", "$", "this", "->", "parseFormField", "(", "$", "key", ",", "$", "field", ",", "$", "params", ",", "$", "prefix", ",", "$", "parent", ",", "$", "merge", ",", "$", "formPath", ")", ";", "}", "}" ]
Gets all field definitions from the blueprints. @param array $fields Fields to parse. @param array $params Property parameters. @param string $prefix Property prefix. @param string $parent Parent property. @param bool $merge Merge fields instead replacing them. @param array $formPath
[ "Gets", "all", "field", "definitions", "from", "the", "blueprints", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintSchema.php#L461-L471
train
rockettheme/toolbox
Blueprints/src/BlueprintSchema.php
BlueprintSchema.addProperty
protected function addProperty($path) { $parts = explode('.', $path); $item = array_pop($parts); $nested = &$this->nested; foreach ($parts as $part) { if (!isset($nested[$part]) || !\is_array($nested[$part])) { $nested[$part] = []; } $nested = &$nested[$part]; } if (!isset($nested[$item])) { $nested[$item] = $path; } }
php
protected function addProperty($path) { $parts = explode('.', $path); $item = array_pop($parts); $nested = &$this->nested; foreach ($parts as $part) { if (!isset($nested[$part]) || !\is_array($nested[$part])) { $nested[$part] = []; } $nested = &$nested[$part]; } if (!isset($nested[$item])) { $nested[$item] = $path; } }
[ "protected", "function", "addProperty", "(", "$", "path", ")", "{", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "path", ")", ";", "$", "item", "=", "array_pop", "(", "$", "parts", ")", ";", "$", "nested", "=", "&", "$", "this", "->", "nested", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "if", "(", "!", "isset", "(", "$", "nested", "[", "$", "part", "]", ")", "||", "!", "\\", "is_array", "(", "$", "nested", "[", "$", "part", "]", ")", ")", "{", "$", "nested", "[", "$", "part", "]", "=", "[", "]", ";", "}", "$", "nested", "=", "&", "$", "nested", "[", "$", "part", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "nested", "[", "$", "item", "]", ")", ")", "{", "$", "nested", "[", "$", "item", "]", "=", "$", "path", ";", "}", "}" ]
Add property to the definition. @param string $path Comma separated path to the property. @internal
[ "Add", "property", "to", "the", "definition", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Blueprints/src/BlueprintSchema.php#L590-L607
train
silverstripe/cwp-search
src/Extensions/SynonymValidator.php
SynonymValidator.validateField
protected function validateField($fieldName, $value) { if (!$this->validateValue($value)) { $this->validationError( $fieldName, _t( __CLASS__ . '.InvalidValue', 'Synonyms cannot contain words separated by spaces' ) ); } }
php
protected function validateField($fieldName, $value) { if (!$this->validateValue($value)) { $this->validationError( $fieldName, _t( __CLASS__ . '.InvalidValue', 'Synonyms cannot contain words separated by spaces' ) ); } }
[ "protected", "function", "validateField", "(", "$", "fieldName", ",", "$", "value", ")", "{", "if", "(", "!", "$", "this", "->", "validateValue", "(", "$", "value", ")", ")", "{", "$", "this", "->", "validationError", "(", "$", "fieldName", ",", "_t", "(", "__CLASS__", ".", "'.InvalidValue'", ",", "'Synonyms cannot contain words separated by spaces'", ")", ")", ";", "}", "}" ]
Validate field values, raising errors if the values are invalid. @param string $fieldName @param mixed $value
[ "Validate", "field", "values", "raising", "errors", "if", "the", "values", "are", "invalid", "." ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/Extensions/SynonymValidator.php#L50-L61
train
silverstripe/cwp-search
src/Extensions/SynonymValidator.php
SynonymValidator.validateValue
protected function validateValue($value) { // strip empty lines $lines = array_filter( explode("\n", $value) ); // strip comments (lines beginning with "#") $lines = array_filter($lines, function ($line) { $line = trim($line); return !empty($line) && $line[0] !== '#'; }); // validate each line foreach ($lines as $line) { if (!$this->validateLine($line)) { return false; } } return true; }
php
protected function validateValue($value) { // strip empty lines $lines = array_filter( explode("\n", $value) ); // strip comments (lines beginning with "#") $lines = array_filter($lines, function ($line) { $line = trim($line); return !empty($line) && $line[0] !== '#'; }); // validate each line foreach ($lines as $line) { if (!$this->validateLine($line)) { return false; } } return true; }
[ "protected", "function", "validateValue", "(", "$", "value", ")", "{", "// strip empty lines", "$", "lines", "=", "array_filter", "(", "explode", "(", "\"\\n\"", ",", "$", "value", ")", ")", ";", "// strip comments (lines beginning with \"#\")", "$", "lines", "=", "array_filter", "(", "$", "lines", ",", "function", "(", "$", "line", ")", "{", "$", "line", "=", "trim", "(", "$", "line", ")", ";", "return", "!", "empty", "(", "$", "line", ")", "&&", "$", "line", "[", "0", "]", "!==", "'#'", ";", "}", ")", ";", "// validate each line", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "if", "(", "!", "$", "this", "->", "validateLine", "(", "$", "line", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check field values to see that they doesn't contain spaces between words. @param mixed $value @return bool
[ "Check", "field", "values", "to", "see", "that", "they", "doesn", "t", "contain", "spaces", "between", "words", "." ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/Extensions/SynonymValidator.php#L70-L92
train
silverstripe/cwp-search
src/Extensions/SynonymValidator.php
SynonymValidator.validateLine
protected function validateLine($line) { $line = trim($line); $parts = explode(',', $line); $parts = array_filter($parts); foreach ($parts as $part) { if (!$this->validatePart($part)) { return false; } } return true; }
php
protected function validateLine($line) { $line = trim($line); $parts = explode(',', $line); $parts = array_filter($parts); foreach ($parts as $part) { if (!$this->validatePart($part)) { return false; } } return true; }
[ "protected", "function", "validateLine", "(", "$", "line", ")", "{", "$", "line", "=", "trim", "(", "$", "line", ")", ";", "$", "parts", "=", "explode", "(", "','", ",", "$", "line", ")", ";", "$", "parts", "=", "array_filter", "(", "$", "parts", ")", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "if", "(", "!", "$", "this", "->", "validatePart", "(", "$", "part", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check each line to see that it doesn't contain spaces between words. @param string $line @return bool
[ "Check", "each", "line", "to", "see", "that", "it", "doesn", "t", "contain", "spaces", "between", "words", "." ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/Extensions/SynonymValidator.php#L101-L115
train
silverstripe/cwp-search
src/Extensions/SynonymValidator.php
SynonymValidator.validatePart
protected function validatePart($part) { if (strpos($part, '=>') !== false) { $subs = explode('=>', $part); $subs = array_filter($subs); foreach ($subs as $sub) { if (!$this->validateNoSpaces($sub)) { return false; } } return true; } return $this->validateNoSpaces($part); }
php
protected function validatePart($part) { if (strpos($part, '=>') !== false) { $subs = explode('=>', $part); $subs = array_filter($subs); foreach ($subs as $sub) { if (!$this->validateNoSpaces($sub)) { return false; } } return true; } return $this->validateNoSpaces($part); }
[ "protected", "function", "validatePart", "(", "$", "part", ")", "{", "if", "(", "strpos", "(", "$", "part", ",", "'=>'", ")", "!==", "false", ")", "{", "$", "subs", "=", "explode", "(", "'=>'", ",", "$", "part", ")", ";", "$", "subs", "=", "array_filter", "(", "$", "subs", ")", ";", "foreach", "(", "$", "subs", "as", "$", "sub", ")", "{", "if", "(", "!", "$", "this", "->", "validateNoSpaces", "(", "$", "sub", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", "return", "$", "this", "->", "validateNoSpaces", "(", "$", "part", ")", ";", "}" ]
Check each part of the line doesn't contain spaces between words. @param string $part @return bool
[ "Check", "each", "part", "of", "the", "line", "doesn", "t", "contain", "spaces", "between", "words", "." ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/Extensions/SynonymValidator.php#L124-L140
train
rockettheme/toolbox
Compat/src/Yaml/Inline.php
Inline.parseQuotedScalar
private static function parseQuotedScalar($scalar, &$i) { if (!Parser::preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) { throw new ParseException(sprintf('Malformed inline YAML string: %s.', substr($scalar, $i))); } $output = substr($match[0], 1, strlen($match[0]) - 2); $unescaper = new Unescaper(); if ('"' == $scalar[$i]) { $output = $unescaper->unescapeDoubleQuotedString($output); } else { $output = $unescaper->unescapeSingleQuotedString($output); } $i += strlen($match[0]); return $output; }
php
private static function parseQuotedScalar($scalar, &$i) { if (!Parser::preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) { throw new ParseException(sprintf('Malformed inline YAML string: %s.', substr($scalar, $i))); } $output = substr($match[0], 1, strlen($match[0]) - 2); $unescaper = new Unescaper(); if ('"' == $scalar[$i]) { $output = $unescaper->unescapeDoubleQuotedString($output); } else { $output = $unescaper->unescapeSingleQuotedString($output); } $i += strlen($match[0]); return $output; }
[ "private", "static", "function", "parseQuotedScalar", "(", "$", "scalar", ",", "&", "$", "i", ")", "{", "if", "(", "!", "Parser", "::", "preg_match", "(", "'/'", ".", "self", "::", "REGEX_QUOTED_STRING", ".", "'/Au'", ",", "substr", "(", "$", "scalar", ",", "$", "i", ")", ",", "$", "match", ")", ")", "{", "throw", "new", "ParseException", "(", "sprintf", "(", "'Malformed inline YAML string: %s.'", ",", "substr", "(", "$", "scalar", ",", "$", "i", ")", ")", ")", ";", "}", "$", "output", "=", "substr", "(", "$", "match", "[", "0", "]", ",", "1", ",", "strlen", "(", "$", "match", "[", "0", "]", ")", "-", "2", ")", ";", "$", "unescaper", "=", "new", "Unescaper", "(", ")", ";", "if", "(", "'\"'", "==", "$", "scalar", "[", "$", "i", "]", ")", "{", "$", "output", "=", "$", "unescaper", "->", "unescapeDoubleQuotedString", "(", "$", "output", ")", ";", "}", "else", "{", "$", "output", "=", "$", "unescaper", "->", "unescapeSingleQuotedString", "(", "$", "output", ")", ";", "}", "$", "i", "+=", "strlen", "(", "$", "match", "[", "0", "]", ")", ";", "return", "$", "output", ";", "}" ]
Parses a YAML quoted scalar. @param string $scalar @param int &$i @return string @throws ParseException When malformed inline YAML string is parsed
[ "Parses", "a", "YAML", "quoted", "scalar", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/Compat/src/Yaml/Inline.php#L178-L196
train
basecrm/basecrm-php
lib/NotesService.php
NotesService.create
public function create(array $note, array $options = array()) { $attributes = array_intersect_key($note, array_flip(self::$keysToPersist)); list($code, $createdNote) = $this->httpClient->post("/notes", $attributes, $options); return $createdNote; }
php
public function create(array $note, array $options = array()) { $attributes = array_intersect_key($note, array_flip(self::$keysToPersist)); list($code, $createdNote) = $this->httpClient->post("/notes", $attributes, $options); return $createdNote; }
[ "public", "function", "create", "(", "array", "$", "note", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "note", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "createdNote", ")", "=", "$", "this", "->", "httpClient", "->", "post", "(", "\"/notes\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "createdNote", ";", "}" ]
Create a note post '/notes' Create a new note and associate it with one of the resources listed below: * [Leads](/docs/rest/reference/leads) * [Contacts](/docs/rest/reference/contacts) * [Deals](/docs/rest/reference/deals) @param array $note This array's attributes describe the object to be created. @param array $options Additional request's options. @return array The resulting object representing created resource.
[ "Create", "a", "note" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/NotesService.php#L62-L68
train
basecrm/basecrm-php
lib/NotesService.php
NotesService.update
public function update($id, array $note, array $options = array()) { $attributes = array_intersect_key($note, array_flip(self::$keysToPersist)); list($code, $updatedNote) = $this->httpClient->put("/notes/{$id}", $attributes, $options); return $updatedNote; }
php
public function update($id, array $note, array $options = array()) { $attributes = array_intersect_key($note, array_flip(self::$keysToPersist)); list($code, $updatedNote) = $this->httpClient->put("/notes/{$id}", $attributes, $options); return $updatedNote; }
[ "public", "function", "update", "(", "$", "id", ",", "array", "$", "note", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_intersect_key", "(", "$", "note", ",", "array_flip", "(", "self", "::", "$", "keysToPersist", ")", ")", ";", "list", "(", "$", "code", ",", "$", "updatedNote", ")", "=", "$", "this", "->", "httpClient", "->", "put", "(", "\"/notes/{$id}\"", ",", "$", "attributes", ",", "$", "options", ")", ";", "return", "$", "updatedNote", ";", "}" ]
Update a note put '/notes/{id}' Updates note information If the note ID does not exist, this request will return an error @param integer $id Unique identifier of a Note @param array $note This array's attributes describe the object to be updated. @param array $options Additional request's options. @return array The resulting object representing updated resource.
[ "Update", "a", "note" ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/NotesService.php#L103-L109
train
basecrm/basecrm-php
lib/Configuration.php
Configuration.isValid
public function isValid() { if (!is_string($this->accessToken)) { $msg = 'Provided access token is invalid as it is not a string'; throw new Errors\ConfigurationError($msg); } if (preg_match('/\s/', $this->accessToken)) { $msg = 'Provided access token is invalid ' . 'as it contains disallowed characters. ' . 'Please double-check your access token.'; throw new Errors\ConfigurationError($msg); } if (strlen($this->accessToken) != 64) { $msg = 'Provided access token is invalid ' . 'as it contains disallowed characters. ' . 'Please double-check your access token.'; throw new Errors\ConfigurationError($msg); } if (!is_string($this->baseUrl) || !preg_match(Configuration::URL_REGEXP, $this->baseUrl)) { $msg = 'Provided base url is invalid ' . 'as it is not a valid URI. ' . 'Please make sure it includes the schema part, both http and https are accepted, ' . 'and the hierarchical part.'; throw new Errors\ConfigurationError($msg); } return true; }
php
public function isValid() { if (!is_string($this->accessToken)) { $msg = 'Provided access token is invalid as it is not a string'; throw new Errors\ConfigurationError($msg); } if (preg_match('/\s/', $this->accessToken)) { $msg = 'Provided access token is invalid ' . 'as it contains disallowed characters. ' . 'Please double-check your access token.'; throw new Errors\ConfigurationError($msg); } if (strlen($this->accessToken) != 64) { $msg = 'Provided access token is invalid ' . 'as it contains disallowed characters. ' . 'Please double-check your access token.'; throw new Errors\ConfigurationError($msg); } if (!is_string($this->baseUrl) || !preg_match(Configuration::URL_REGEXP, $this->baseUrl)) { $msg = 'Provided base url is invalid ' . 'as it is not a valid URI. ' . 'Please make sure it includes the schema part, both http and https are accepted, ' . 'and the hierarchical part.'; throw new Errors\ConfigurationError($msg); } return true; }
[ "public", "function", "isValid", "(", ")", "{", "if", "(", "!", "is_string", "(", "$", "this", "->", "accessToken", ")", ")", "{", "$", "msg", "=", "'Provided access token is invalid as it is not a string'", ";", "throw", "new", "Errors", "\\", "ConfigurationError", "(", "$", "msg", ")", ";", "}", "if", "(", "preg_match", "(", "'/\\s/'", ",", "$", "this", "->", "accessToken", ")", ")", "{", "$", "msg", "=", "'Provided access token is invalid '", ".", "'as it contains disallowed characters. '", ".", "'Please double-check your access token.'", ";", "throw", "new", "Errors", "\\", "ConfigurationError", "(", "$", "msg", ")", ";", "}", "if", "(", "strlen", "(", "$", "this", "->", "accessToken", ")", "!=", "64", ")", "{", "$", "msg", "=", "'Provided access token is invalid '", ".", "'as it contains disallowed characters. '", ".", "'Please double-check your access token.'", ";", "throw", "new", "Errors", "\\", "ConfigurationError", "(", "$", "msg", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "this", "->", "baseUrl", ")", "||", "!", "preg_match", "(", "Configuration", "::", "URL_REGEXP", ",", "$", "this", "->", "baseUrl", ")", ")", "{", "$", "msg", "=", "'Provided base url is invalid '", ".", "'as it is not a valid URI. '", ".", "'Please make sure it includes the schema part, both http and https are accepted, '", ".", "'and the hierarchical part.'", ";", "throw", "new", "Errors", "\\", "ConfigurationError", "(", "$", "msg", ")", ";", "}", "return", "true", ";", "}" ]
Checks if provided configuration is valid. @throws \BaseCRM\Errors\ConfigurationError if provided access token is invalid - contains disallowed characters @throws \BaseCRM\Errors\ConfigurationError if provided access token is invalid - has invalid length @throws \BaseCRM\Errors\ConfigurationError if provided base url is invalid @return boolean
[ "Checks", "if", "provided", "configuration", "is", "valid", "." ]
4dce65d027b67dd0800ea89463320cc163731500
https://github.com/basecrm/basecrm-php/blob/4dce65d027b67dd0800ea89463320cc163731500/lib/Configuration.php#L64-L98
train
silverstripe/cwp-search
src/Solr/CwpSolr.php
CwpSolr.configure
public static function configure() { if (!class_exists(Solr::class)) { return; } // get options from configuration $options = static::config()->get('options'); // get version specific options switch ($options['version']) { case 'cwp-4': $solrOptions = self::options_for_cwp($options); break; case 'local-4': $solrOptions = self::options_for_local($options); break; default: throw new InvalidArgumentException(sprintf( 'Solr version "%s" is not supported on CWP. Please use "local-4" on local ' . 'and "cwp-4" on production. For preferred configuration see ' . 'https://www.cwp.govt.nz/developer-docs/.', $options['version'] )); break; } // Allow users to override extras path. // CAUTION: CWP does not permit usage of customised solrconfig.xml. if (isset($options['extraspath']) && file_exists($options['extraspath'])) { $solrOptions['extraspath'] = $options['extraspath']; } elseif (file_exists(BASE_PATH . '/app/conf/extras')) { $solrOptions['extraspath'] = BASE_PATH . '/app/conf/extras'; } Solr::configure_server($solrOptions); }
php
public static function configure() { if (!class_exists(Solr::class)) { return; } // get options from configuration $options = static::config()->get('options'); // get version specific options switch ($options['version']) { case 'cwp-4': $solrOptions = self::options_for_cwp($options); break; case 'local-4': $solrOptions = self::options_for_local($options); break; default: throw new InvalidArgumentException(sprintf( 'Solr version "%s" is not supported on CWP. Please use "local-4" on local ' . 'and "cwp-4" on production. For preferred configuration see ' . 'https://www.cwp.govt.nz/developer-docs/.', $options['version'] )); break; } // Allow users to override extras path. // CAUTION: CWP does not permit usage of customised solrconfig.xml. if (isset($options['extraspath']) && file_exists($options['extraspath'])) { $solrOptions['extraspath'] = $options['extraspath']; } elseif (file_exists(BASE_PATH . '/app/conf/extras')) { $solrOptions['extraspath'] = BASE_PATH . '/app/conf/extras'; } Solr::configure_server($solrOptions); }
[ "public", "static", "function", "configure", "(", ")", "{", "if", "(", "!", "class_exists", "(", "Solr", "::", "class", ")", ")", "{", "return", ";", "}", "// get options from configuration", "$", "options", "=", "static", "::", "config", "(", ")", "->", "get", "(", "'options'", ")", ";", "// get version specific options", "switch", "(", "$", "options", "[", "'version'", "]", ")", "{", "case", "'cwp-4'", ":", "$", "solrOptions", "=", "self", "::", "options_for_cwp", "(", "$", "options", ")", ";", "break", ";", "case", "'local-4'", ":", "$", "solrOptions", "=", "self", "::", "options_for_local", "(", "$", "options", ")", ";", "break", ";", "default", ":", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Solr version \"%s\" is not supported on CWP. Please use \"local-4\" on local '", ".", "'and \"cwp-4\" on production. For preferred configuration see '", ".", "'https://www.cwp.govt.nz/developer-docs/.'", ",", "$", "options", "[", "'version'", "]", ")", ")", ";", "break", ";", "}", "// Allow users to override extras path.", "// CAUTION: CWP does not permit usage of customised solrconfig.xml.", "if", "(", "isset", "(", "$", "options", "[", "'extraspath'", "]", ")", "&&", "file_exists", "(", "$", "options", "[", "'extraspath'", "]", ")", ")", "{", "$", "solrOptions", "[", "'extraspath'", "]", "=", "$", "options", "[", "'extraspath'", "]", ";", "}", "elseif", "(", "file_exists", "(", "BASE_PATH", ".", "'/app/conf/extras'", ")", ")", "{", "$", "solrOptions", "[", "'extraspath'", "]", "=", "BASE_PATH", ".", "'/app/conf/extras'", ";", "}", "Solr", "::", "configure_server", "(", "$", "solrOptions", ")", ";", "}" ]
Configure Solr. $options - An array consisting of: 'extraspath' - (String) Where to find Solr core configuartion files. Defaults to '<BASE_PATH>/app/conf/extras'. 'version' - select the Solr configuration to use when in CWP. One of: * 'cwp-4': preferred version, uses secured 4.x service available on CWP * 'local-4': this can be use for development using silverstripe-localsolr package, 4.x branch
[ "Configure", "Solr", "." ]
ca1558f19080f48392ee767de71f4efb08acd848
https://github.com/silverstripe/cwp-search/blob/ca1558f19080f48392ee767de71f4efb08acd848/src/Solr/CwpSolr.php#L34-L70
train
rockettheme/toolbox
ResourceLocator/src/UniformResourceLocator.php
UniformResourceLocator.addPath
public function addPath($scheme, $prefix, $paths, $override = false, $force = false) { $list = []; foreach((array) $paths as $path) { if (\is_array($path)) { // Support stream lookup in ['theme', 'path/to'] format. if (\count($path) !== 2 || !\is_string($path[0]) || !\is_string($path[1])) { throw new \BadMethodCallException('Invalid stream path given.'); } $list[] = $path; } elseif (false !== strpos($path, '://')) { // Support stream lookup in 'theme://path/to' format. $stream = explode('://', $path, 2); $stream[1] = trim($stream[1], '/'); $list[] = $stream; } else { // Normalize path. $path = rtrim(str_replace('\\', '/', $path), '/'); if ($force || @file_exists("{$this->base}/{$path}") || @file_exists($path)) { // Support for absolute and relative paths. $list[] = $path; } } } if (isset($this->schemes[$scheme][$prefix])) { $paths = $this->schemes[$scheme][$prefix]; if (!$override || $override == 1) { $list = $override ? array_merge($paths, $list) : array_merge($list, $paths); } else { $location = array_search($override, $paths, true) ?: \count($paths); array_splice($paths, $location, 0, $list); $list = $paths; } } $this->schemes[$scheme][$prefix] = $list; // Sort in reverse order to get longer prefixes to be matched first. krsort($this->schemes[$scheme]); $this->cache = []; }
php
public function addPath($scheme, $prefix, $paths, $override = false, $force = false) { $list = []; foreach((array) $paths as $path) { if (\is_array($path)) { // Support stream lookup in ['theme', 'path/to'] format. if (\count($path) !== 2 || !\is_string($path[0]) || !\is_string($path[1])) { throw new \BadMethodCallException('Invalid stream path given.'); } $list[] = $path; } elseif (false !== strpos($path, '://')) { // Support stream lookup in 'theme://path/to' format. $stream = explode('://', $path, 2); $stream[1] = trim($stream[1], '/'); $list[] = $stream; } else { // Normalize path. $path = rtrim(str_replace('\\', '/', $path), '/'); if ($force || @file_exists("{$this->base}/{$path}") || @file_exists($path)) { // Support for absolute and relative paths. $list[] = $path; } } } if (isset($this->schemes[$scheme][$prefix])) { $paths = $this->schemes[$scheme][$prefix]; if (!$override || $override == 1) { $list = $override ? array_merge($paths, $list) : array_merge($list, $paths); } else { $location = array_search($override, $paths, true) ?: \count($paths); array_splice($paths, $location, 0, $list); $list = $paths; } } $this->schemes[$scheme][$prefix] = $list; // Sort in reverse order to get longer prefixes to be matched first. krsort($this->schemes[$scheme]); $this->cache = []; }
[ "public", "function", "addPath", "(", "$", "scheme", ",", "$", "prefix", ",", "$", "paths", ",", "$", "override", "=", "false", ",", "$", "force", "=", "false", ")", "{", "$", "list", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "paths", "as", "$", "path", ")", "{", "if", "(", "\\", "is_array", "(", "$", "path", ")", ")", "{", "// Support stream lookup in ['theme', 'path/to'] format.", "if", "(", "\\", "count", "(", "$", "path", ")", "!==", "2", "||", "!", "\\", "is_string", "(", "$", "path", "[", "0", "]", ")", "||", "!", "\\", "is_string", "(", "$", "path", "[", "1", "]", ")", ")", "{", "throw", "new", "\\", "BadMethodCallException", "(", "'Invalid stream path given.'", ")", ";", "}", "$", "list", "[", "]", "=", "$", "path", ";", "}", "elseif", "(", "false", "!==", "strpos", "(", "$", "path", ",", "'://'", ")", ")", "{", "// Support stream lookup in 'theme://path/to' format.", "$", "stream", "=", "explode", "(", "'://'", ",", "$", "path", ",", "2", ")", ";", "$", "stream", "[", "1", "]", "=", "trim", "(", "$", "stream", "[", "1", "]", ",", "'/'", ")", ";", "$", "list", "[", "]", "=", "$", "stream", ";", "}", "else", "{", "// Normalize path.", "$", "path", "=", "rtrim", "(", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "path", ")", ",", "'/'", ")", ";", "if", "(", "$", "force", "||", "@", "file_exists", "(", "\"{$this->base}/{$path}\"", ")", "||", "@", "file_exists", "(", "$", "path", ")", ")", "{", "// Support for absolute and relative paths.", "$", "list", "[", "]", "=", "$", "path", ";", "}", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "schemes", "[", "$", "scheme", "]", "[", "$", "prefix", "]", ")", ")", "{", "$", "paths", "=", "$", "this", "->", "schemes", "[", "$", "scheme", "]", "[", "$", "prefix", "]", ";", "if", "(", "!", "$", "override", "||", "$", "override", "==", "1", ")", "{", "$", "list", "=", "$", "override", "?", "array_merge", "(", "$", "paths", ",", "$", "list", ")", ":", "array_merge", "(", "$", "list", ",", "$", "paths", ")", ";", "}", "else", "{", "$", "location", "=", "array_search", "(", "$", "override", ",", "$", "paths", ",", "true", ")", "?", ":", "\\", "count", "(", "$", "paths", ")", ";", "array_splice", "(", "$", "paths", ",", "$", "location", ",", "0", ",", "$", "list", ")", ";", "$", "list", "=", "$", "paths", ";", "}", "}", "$", "this", "->", "schemes", "[", "$", "scheme", "]", "[", "$", "prefix", "]", "=", "$", "list", ";", "// Sort in reverse order to get longer prefixes to be matched first.", "krsort", "(", "$", "this", "->", "schemes", "[", "$", "scheme", "]", ")", ";", "$", "this", "->", "cache", "=", "[", "]", ";", "}" ]
Add new paths to the scheme. @param string $scheme @param string $prefix @param string|array $paths @param bool|string $override True to add path as override, string @param bool $force True to add paths even if them do not exist. @throws \BadMethodCallException
[ "Add", "new", "paths", "to", "the", "scheme", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/ResourceLocator/src/UniformResourceLocator.php#L99-L142
train
rockettheme/toolbox
ResourceLocator/src/UniformResourceLocator.php
UniformResourceLocator.getPaths
public function getPaths($scheme = null) { return !$scheme ? $this->schemes : (isset($this->schemes[$scheme]) ? $this->schemes[$scheme] : []); }
php
public function getPaths($scheme = null) { return !$scheme ? $this->schemes : (isset($this->schemes[$scheme]) ? $this->schemes[$scheme] : []); }
[ "public", "function", "getPaths", "(", "$", "scheme", "=", "null", ")", "{", "return", "!", "$", "scheme", "?", "$", "this", "->", "schemes", ":", "(", "isset", "(", "$", "this", "->", "schemes", "[", "$", "scheme", "]", ")", "?", "$", "this", "->", "schemes", "[", "$", "scheme", "]", ":", "[", "]", ")", ";", "}" ]
Return all scheme lookup paths. @param string $scheme @return array
[ "Return", "all", "scheme", "lookup", "paths", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/ResourceLocator/src/UniformResourceLocator.php#L182-L185
train
rockettheme/toolbox
ResourceLocator/src/UniformResourceLocator.php
UniformResourceLocator.isStream
public function isStream($uri) { try { list ($scheme,) = $this->normalize($uri, true, true); } catch (\Exception $e) { return false; } return $this->schemeExists($scheme); }
php
public function isStream($uri) { try { list ($scheme,) = $this->normalize($uri, true, true); } catch (\Exception $e) { return false; } return $this->schemeExists($scheme); }
[ "public", "function", "isStream", "(", "$", "uri", ")", "{", "try", "{", "list", "(", "$", "scheme", ",", ")", "=", "$", "this", "->", "normalize", "(", "$", "uri", ",", "true", ",", "true", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "schemeExists", "(", "$", "scheme", ")", ";", "}" ]
Returns true if uri is resolvable by using locator. @param string $uri @return bool
[ "Returns", "true", "if", "uri", "is", "resolvable", "by", "using", "locator", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/ResourceLocator/src/UniformResourceLocator.php#L206-L215
train
rockettheme/toolbox
ResourceLocator/src/UniformResourceLocator.php
UniformResourceLocator.findResource
public function findResource($uri, $absolute = true, $first = false) { if (!\is_string($uri)) { throw new \BadMethodCallException('Invalid parameter $uri.'); } return $this->findCached($uri, false, $absolute, $first); }
php
public function findResource($uri, $absolute = true, $first = false) { if (!\is_string($uri)) { throw new \BadMethodCallException('Invalid parameter $uri.'); } return $this->findCached($uri, false, $absolute, $first); }
[ "public", "function", "findResource", "(", "$", "uri", ",", "$", "absolute", "=", "true", ",", "$", "first", "=", "false", ")", "{", "if", "(", "!", "\\", "is_string", "(", "$", "uri", ")", ")", "{", "throw", "new", "\\", "BadMethodCallException", "(", "'Invalid parameter $uri.'", ")", ";", "}", "return", "$", "this", "->", "findCached", "(", "$", "uri", ",", "false", ",", "$", "absolute", ",", "$", "first", ")", ";", "}" ]
Find highest priority instance from a resource. @param string $uri Input URI to be searched. @param bool $absolute Whether to return absolute path. @param bool $first Whether to return first path even if it doesn't exist. @throws \BadMethodCallException @return string|bool
[ "Find", "highest", "priority", "instance", "from", "a", "resource", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/ResourceLocator/src/UniformResourceLocator.php#L285-L291
train
rockettheme/toolbox
ResourceLocator/src/UniformResourceLocator.php
UniformResourceLocator.findResources
public function findResources($uri, $absolute = true, $all = false) { if (!\is_string($uri)) { throw new \BadMethodCallException('Invalid parameter $uri.'); } return $this->findCached($uri, true, $absolute, $all); }
php
public function findResources($uri, $absolute = true, $all = false) { if (!\is_string($uri)) { throw new \BadMethodCallException('Invalid parameter $uri.'); } return $this->findCached($uri, true, $absolute, $all); }
[ "public", "function", "findResources", "(", "$", "uri", ",", "$", "absolute", "=", "true", ",", "$", "all", "=", "false", ")", "{", "if", "(", "!", "\\", "is_string", "(", "$", "uri", ")", ")", "{", "throw", "new", "\\", "BadMethodCallException", "(", "'Invalid parameter $uri.'", ")", ";", "}", "return", "$", "this", "->", "findCached", "(", "$", "uri", ",", "true", ",", "$", "absolute", ",", "$", "all", ")", ";", "}" ]
Find all instances from a resource. @param string $uri Input URI to be searched. @param bool $absolute Whether to return absolute path. @param bool $all Whether to return all paths even if they don't exist. @throws \BadMethodCallException @return array
[ "Find", "all", "instances", "from", "a", "resource", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/ResourceLocator/src/UniformResourceLocator.php#L302-L309
train
rockettheme/toolbox
ResourceLocator/src/UniformResourceLocator.php
UniformResourceLocator.mergeResources
public function mergeResources(array $uris, $absolute = true, $all = false) { $uris = array_unique($uris); $lists = [[]]; foreach ($uris as $uri) { $lists[] = $this->findResources($uri, $absolute, $all); } // TODO: In PHP 5.6+ use array_merge(...$list); return call_user_func_array('array_merge', $lists); }
php
public function mergeResources(array $uris, $absolute = true, $all = false) { $uris = array_unique($uris); $lists = [[]]; foreach ($uris as $uri) { $lists[] = $this->findResources($uri, $absolute, $all); } // TODO: In PHP 5.6+ use array_merge(...$list); return call_user_func_array('array_merge', $lists); }
[ "public", "function", "mergeResources", "(", "array", "$", "uris", ",", "$", "absolute", "=", "true", ",", "$", "all", "=", "false", ")", "{", "$", "uris", "=", "array_unique", "(", "$", "uris", ")", ";", "$", "lists", "=", "[", "[", "]", "]", ";", "foreach", "(", "$", "uris", "as", "$", "uri", ")", "{", "$", "lists", "[", "]", "=", "$", "this", "->", "findResources", "(", "$", "uri", ",", "$", "absolute", ",", "$", "all", ")", ";", "}", "// TODO: In PHP 5.6+ use array_merge(...$list);", "return", "call_user_func_array", "(", "'array_merge'", ",", "$", "lists", ")", ";", "}" ]
Find all instances from a list of resources. @param array $uris Input URIs to be searched. @param bool $absolute Whether to return absolute path. @param bool $all Whether to return all paths even if they don't exist. @throws \BadMethodCallException @return array
[ "Find", "all", "instances", "from", "a", "list", "of", "resources", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/ResourceLocator/src/UniformResourceLocator.php#L320-L331
train
rockettheme/toolbox
ResourceLocator/src/UniformResourceLocator.php
UniformResourceLocator.fillCache
public function fillCache($uri) { $cacheKey = $uri . '@cache'; if (!isset($this->cache[$cacheKey])) { $this->cache[$cacheKey] = true; $iterator = new \RecursiveIteratorIterator($this->getRecursiveIterator($uri), \RecursiveIteratorIterator::SELF_FIRST); /** @var UniformResourceIterator $uri */ foreach ($iterator as $item) { $key = $item->getUrl() . '@010'; $this->cache[$key] = $item->getPathname(); } } return $this; }
php
public function fillCache($uri) { $cacheKey = $uri . '@cache'; if (!isset($this->cache[$cacheKey])) { $this->cache[$cacheKey] = true; $iterator = new \RecursiveIteratorIterator($this->getRecursiveIterator($uri), \RecursiveIteratorIterator::SELF_FIRST); /** @var UniformResourceIterator $uri */ foreach ($iterator as $item) { $key = $item->getUrl() . '@010'; $this->cache[$key] = $item->getPathname(); } } return $this; }
[ "public", "function", "fillCache", "(", "$", "uri", ")", "{", "$", "cacheKey", "=", "$", "uri", ".", "'@cache'", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "cache", "[", "$", "cacheKey", "]", ")", ")", "{", "$", "this", "->", "cache", "[", "$", "cacheKey", "]", "=", "true", ";", "$", "iterator", "=", "new", "\\", "RecursiveIteratorIterator", "(", "$", "this", "->", "getRecursiveIterator", "(", "$", "uri", ")", ",", "\\", "RecursiveIteratorIterator", "::", "SELF_FIRST", ")", ";", "/** @var UniformResourceIterator $uri */", "foreach", "(", "$", "iterator", "as", "$", "item", ")", "{", "$", "key", "=", "$", "item", "->", "getUrl", "(", ")", ".", "'@010'", ";", "$", "this", "->", "cache", "[", "$", "key", "]", "=", "$", "item", "->", "getPathname", "(", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Pre-fill cache by a stream. @param string $uri @return $this
[ "Pre", "-", "fill", "cache", "by", "a", "stream", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/ResourceLocator/src/UniformResourceLocator.php#L339-L356
train
rockettheme/toolbox
ResourceLocator/src/UniformResourceLocator.php
UniformResourceLocator.clearCache
public function clearCache($uri = null) { if ($uri) { $this->clearCached($uri, true, true, true); $this->clearCached($uri, true, true, false); $this->clearCached($uri, true, false, true); $this->clearCached($uri, true, false, false); $this->clearCached($uri, false, true, true); $this->clearCached($uri, false, true, false); $this->clearCached($uri, false, false, true); $this->clearCached($uri, false, false, false); } else { $this->cache = []; } return $this; }
php
public function clearCache($uri = null) { if ($uri) { $this->clearCached($uri, true, true, true); $this->clearCached($uri, true, true, false); $this->clearCached($uri, true, false, true); $this->clearCached($uri, true, false, false); $this->clearCached($uri, false, true, true); $this->clearCached($uri, false, true, false); $this->clearCached($uri, false, false, true); $this->clearCached($uri, false, false, false); } else { $this->cache = []; } return $this; }
[ "public", "function", "clearCache", "(", "$", "uri", "=", "null", ")", "{", "if", "(", "$", "uri", ")", "{", "$", "this", "->", "clearCached", "(", "$", "uri", ",", "true", ",", "true", ",", "true", ")", ";", "$", "this", "->", "clearCached", "(", "$", "uri", ",", "true", ",", "true", ",", "false", ")", ";", "$", "this", "->", "clearCached", "(", "$", "uri", ",", "true", ",", "false", ",", "true", ")", ";", "$", "this", "->", "clearCached", "(", "$", "uri", ",", "true", ",", "false", ",", "false", ")", ";", "$", "this", "->", "clearCached", "(", "$", "uri", ",", "false", ",", "true", ",", "true", ")", ";", "$", "this", "->", "clearCached", "(", "$", "uri", ",", "false", ",", "true", ",", "false", ")", ";", "$", "this", "->", "clearCached", "(", "$", "uri", ",", "false", ",", "false", ",", "true", ")", ";", "$", "this", "->", "clearCached", "(", "$", "uri", ",", "false", ",", "false", ",", "false", ")", ";", "}", "else", "{", "$", "this", "->", "cache", "=", "[", "]", ";", "}", "return", "$", "this", ";", "}" ]
Reset locator cache. @param string $uri @return $this
[ "Reset", "locator", "cache", "." ]
7cacabf0322804ce0977988f71f7dca171f19a5c
https://github.com/rockettheme/toolbox/blob/7cacabf0322804ce0977988f71f7dca171f19a5c/ResourceLocator/src/UniformResourceLocator.php#L364-L380
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Controller/CRUDController.php
CRUDController.moveUpAction
public function moveUpAction($id) { $repo = $this->getDoctrine()->getManager()->getRepository($this->admin->getClass()); $result = $repo->find($id); $repo->moveUp($result); if ($referer = $this->getRequest()->headers->get('referer')) { return $this->redirect($referer); } else { return new Response('<script>history.go(-1);</script>'); } }
php
public function moveUpAction($id) { $repo = $this->getDoctrine()->getManager()->getRepository($this->admin->getClass()); $result = $repo->find($id); $repo->moveUp($result); if ($referer = $this->getRequest()->headers->get('referer')) { return $this->redirect($referer); } else { return new Response('<script>history.go(-1);</script>'); } }
[ "public", "function", "moveUpAction", "(", "$", "id", ")", "{", "$", "repo", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", "->", "getRepository", "(", "$", "this", "->", "admin", "->", "getClass", "(", ")", ")", ";", "$", "result", "=", "$", "repo", "->", "find", "(", "$", "id", ")", ";", "$", "repo", "->", "moveUp", "(", "$", "result", ")", ";", "if", "(", "$", "referer", "=", "$", "this", "->", "getRequest", "(", ")", "->", "headers", "->", "get", "(", "'referer'", ")", ")", "{", "return", "$", "this", "->", "redirect", "(", "$", "referer", ")", ";", "}", "else", "{", "return", "new", "Response", "(", "'<script>history.go(-1);</script>'", ")", ";", "}", "}" ]
Move the item up. Used for Tree admins @param mixed $id @return \Symfony\Component\HttpFoundation\Response
[ "Move", "the", "item", "up", ".", "Used", "for", "Tree", "admins" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Controller/CRUDController.php#L130-L141
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Controller/CRUDController.php
CRUDController.bindAndRender
protected function bindAndRender($action) { // the key used to lookup the template $templateKey = 'edit'; if ($action == 'edit') { $id = $this->getRequest()->get($this->admin->getIdParameter()); $object = $this->admin->getObject($id); if (!$object) { throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id)); } if (false === $this->admin->isGranted('EDIT', $object)) { throw new AccessDeniedException(); } } else { $object = $this->admin->getNewInstance(); $this->admin->setSubject($object); /** @var $form \Symfony\Component\Form\Form */ $form = $this->admin->getForm(); $form->setData($object); } $this->admin->setSubject($object); /** @var $form \Symfony\Component\Form\Form */ $form = $this->admin->getForm(); $form->setData($object); if ($this->getRequest()->getMethod() == 'POST') { $form->handleRequest($this->getRequest()); } $view = $form->createView(); // set the theme for the current Admin Form $this->get('twig')->getRuntime(FormRenderer::class)->setTheme($view, $this->admin->getFormTheme()); return $this->render( $this->admin->getTemplate($templateKey), array( 'action' => $action, 'form' => $view, 'object' => $object, ) ); }
php
protected function bindAndRender($action) { // the key used to lookup the template $templateKey = 'edit'; if ($action == 'edit') { $id = $this->getRequest()->get($this->admin->getIdParameter()); $object = $this->admin->getObject($id); if (!$object) { throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id)); } if (false === $this->admin->isGranted('EDIT', $object)) { throw new AccessDeniedException(); } } else { $object = $this->admin->getNewInstance(); $this->admin->setSubject($object); /** @var $form \Symfony\Component\Form\Form */ $form = $this->admin->getForm(); $form->setData($object); } $this->admin->setSubject($object); /** @var $form \Symfony\Component\Form\Form */ $form = $this->admin->getForm(); $form->setData($object); if ($this->getRequest()->getMethod() == 'POST') { $form->handleRequest($this->getRequest()); } $view = $form->createView(); // set the theme for the current Admin Form $this->get('twig')->getRuntime(FormRenderer::class)->setTheme($view, $this->admin->getFormTheme()); return $this->render( $this->admin->getTemplate($templateKey), array( 'action' => $action, 'form' => $view, 'object' => $object, ) ); }
[ "protected", "function", "bindAndRender", "(", "$", "action", ")", "{", "// the key used to lookup the template", "$", "templateKey", "=", "'edit'", ";", "if", "(", "$", "action", "==", "'edit'", ")", "{", "$", "id", "=", "$", "this", "->", "getRequest", "(", ")", "->", "get", "(", "$", "this", "->", "admin", "->", "getIdParameter", "(", ")", ")", ";", "$", "object", "=", "$", "this", "->", "admin", "->", "getObject", "(", "$", "id", ")", ";", "if", "(", "!", "$", "object", ")", "{", "throw", "new", "NotFoundHttpException", "(", "sprintf", "(", "'unable to find the object with id : %s'", ",", "$", "id", ")", ")", ";", "}", "if", "(", "false", "===", "$", "this", "->", "admin", "->", "isGranted", "(", "'EDIT'", ",", "$", "object", ")", ")", "{", "throw", "new", "AccessDeniedException", "(", ")", ";", "}", "}", "else", "{", "$", "object", "=", "$", "this", "->", "admin", "->", "getNewInstance", "(", ")", ";", "$", "this", "->", "admin", "->", "setSubject", "(", "$", "object", ")", ";", "/** @var $form \\Symfony\\Component\\Form\\Form */", "$", "form", "=", "$", "this", "->", "admin", "->", "getForm", "(", ")", ";", "$", "form", "->", "setData", "(", "$", "object", ")", ";", "}", "$", "this", "->", "admin", "->", "setSubject", "(", "$", "object", ")", ";", "/** @var $form \\Symfony\\Component\\Form\\Form */", "$", "form", "=", "$", "this", "->", "admin", "->", "getForm", "(", ")", ";", "$", "form", "->", "setData", "(", "$", "object", ")", ";", "if", "(", "$", "this", "->", "getRequest", "(", ")", "->", "getMethod", "(", ")", "==", "'POST'", ")", "{", "$", "form", "->", "handleRequest", "(", "$", "this", "->", "getRequest", "(", ")", ")", ";", "}", "$", "view", "=", "$", "form", "->", "createView", "(", ")", ";", "// set the theme for the current Admin Form", "$", "this", "->", "get", "(", "'twig'", ")", "->", "getRuntime", "(", "FormRenderer", "::", "class", ")", "->", "setTheme", "(", "$", "view", ",", "$", "this", "->", "admin", "->", "getFormTheme", "(", ")", ")", ";", "return", "$", "this", "->", "render", "(", "$", "this", "->", "admin", "->", "getTemplate", "(", "$", "templateKey", ")", ",", "array", "(", "'action'", "=>", "$", "action", ",", "'form'", "=>", "$", "view", ",", "'object'", "=>", "$", "object", ",", ")", ")", ";", "}" ]
Binds the request to the form and only renders the resulting form. @param string $action @return \Symfony\Component\HttpFoundation\Response @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
[ "Binds", "the", "request", "to", "the", "form", "and", "only", "renders", "the", "resulting", "form", "." ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Controller/CRUDController.php#L173-L223
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Admin/TreeAdmin.php
TreeAdmin.createQuery
public function createQuery($context = 'list') { if ($context === 'list') { /** @var $em \Doctrine\ORM\EntityManager */ $em = $this->getModelManager()->getEntityManager($this->getClass()); /** @var $cmd \Doctrine\Common\Persistence\Mapping\ClassMetadata */ $cmd = $em->getMetadataFactory()->getMetadataFor($this->getClass()); $queryBuilder = $em->createQueryBuilder(); $queryBuilder ->select('n') ->from($this->getClass(), 'n'); if ($cmd->hasField('root')) { $queryBuilder->orderBy('n.root, n.lft'); } else { $queryBuilder->orderBy('n.lft'); } return new ProxyQuery($queryBuilder); } return parent::createQuery($context); }
php
public function createQuery($context = 'list') { if ($context === 'list') { /** @var $em \Doctrine\ORM\EntityManager */ $em = $this->getModelManager()->getEntityManager($this->getClass()); /** @var $cmd \Doctrine\Common\Persistence\Mapping\ClassMetadata */ $cmd = $em->getMetadataFactory()->getMetadataFor($this->getClass()); $queryBuilder = $em->createQueryBuilder(); $queryBuilder ->select('n') ->from($this->getClass(), 'n'); if ($cmd->hasField('root')) { $queryBuilder->orderBy('n.root, n.lft'); } else { $queryBuilder->orderBy('n.lft'); } return new ProxyQuery($queryBuilder); } return parent::createQuery($context); }
[ "public", "function", "createQuery", "(", "$", "context", "=", "'list'", ")", "{", "if", "(", "$", "context", "===", "'list'", ")", "{", "/** @var $em \\Doctrine\\ORM\\EntityManager */", "$", "em", "=", "$", "this", "->", "getModelManager", "(", ")", "->", "getEntityManager", "(", "$", "this", "->", "getClass", "(", ")", ")", ";", "/** @var $cmd \\Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata */", "$", "cmd", "=", "$", "em", "->", "getMetadataFactory", "(", ")", "->", "getMetadataFor", "(", "$", "this", "->", "getClass", "(", ")", ")", ";", "$", "queryBuilder", "=", "$", "em", "->", "createQueryBuilder", "(", ")", ";", "$", "queryBuilder", "->", "select", "(", "'n'", ")", "->", "from", "(", "$", "this", "->", "getClass", "(", ")", ",", "'n'", ")", ";", "if", "(", "$", "cmd", "->", "hasField", "(", "'root'", ")", ")", "{", "$", "queryBuilder", "->", "orderBy", "(", "'n.root, n.lft'", ")", ";", "}", "else", "{", "$", "queryBuilder", "->", "orderBy", "(", "'n.lft'", ")", ";", "}", "return", "new", "ProxyQuery", "(", "$", "queryBuilder", ")", ";", "}", "return", "parent", "::", "createQuery", "(", "$", "context", ")", ";", "}" ]
Override the default query builder to utilize correct sorting @param string $context @return ProxyQueryInterface
[ "Override", "the", "default", "query", "builder", "to", "utilize", "correct", "sorting" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Admin/TreeAdmin.php#L28-L51
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Admin/TreeAdmin.php
TreeAdmin.filterWithChildren
public function filterWithChildren($qb, $alias, $field, $value) { // Check whether it is a numeric value because we could get a string number. if (!($value['value'] && is_numeric($value['value']))) { return null; } // Get the parent item $parentQb = clone $qb; $parentQb->where($parentQb->expr()->eq(sprintf('%s.id', $alias), ':id')); $parentQb->setParameter('id', (int)$value['value']); $currentItem = $parentQb->getQuery()->getOneOrNullResult(); if ($currentItem === null) { return null; } $qb->where( $qb->expr()->andX( $qb->expr()->eq(sprintf('%s.root', $alias), ':root'), $qb->expr()->orX( $qb->expr()->andX( $qb->expr()->lt(sprintf('%s.lft', $alias), ':left'), $qb->expr()->gt(sprintf('%s.rgt', $alias), ':right') ), $qb->expr()->between(sprintf('%s.lft', $alias), ':left', ':right') ) ) ); $qb->setParameter('root', $currentItem->getRoot()); $qb->setParameter('left', $currentItem->getLft()); $qb->setParameter('right', $currentItem->getRgt()); return true; }
php
public function filterWithChildren($qb, $alias, $field, $value) { // Check whether it is a numeric value because we could get a string number. if (!($value['value'] && is_numeric($value['value']))) { return null; } // Get the parent item $parentQb = clone $qb; $parentQb->where($parentQb->expr()->eq(sprintf('%s.id', $alias), ':id')); $parentQb->setParameter('id', (int)$value['value']); $currentItem = $parentQb->getQuery()->getOneOrNullResult(); if ($currentItem === null) { return null; } $qb->where( $qb->expr()->andX( $qb->expr()->eq(sprintf('%s.root', $alias), ':root'), $qb->expr()->orX( $qb->expr()->andX( $qb->expr()->lt(sprintf('%s.lft', $alias), ':left'), $qb->expr()->gt(sprintf('%s.rgt', $alias), ':right') ), $qb->expr()->between(sprintf('%s.lft', $alias), ':left', ':right') ) ) ); $qb->setParameter('root', $currentItem->getRoot()); $qb->setParameter('left', $currentItem->getLft()); $qb->setParameter('right', $currentItem->getRgt()); return true; }
[ "public", "function", "filterWithChildren", "(", "$", "qb", ",", "$", "alias", ",", "$", "field", ",", "$", "value", ")", "{", "// Check whether it is a numeric value because we could get a string number.", "if", "(", "!", "(", "$", "value", "[", "'value'", "]", "&&", "is_numeric", "(", "$", "value", "[", "'value'", "]", ")", ")", ")", "{", "return", "null", ";", "}", "// Get the parent item", "$", "parentQb", "=", "clone", "$", "qb", ";", "$", "parentQb", "->", "where", "(", "$", "parentQb", "->", "expr", "(", ")", "->", "eq", "(", "sprintf", "(", "'%s.id'", ",", "$", "alias", ")", ",", "':id'", ")", ")", ";", "$", "parentQb", "->", "setParameter", "(", "'id'", ",", "(", "int", ")", "$", "value", "[", "'value'", "]", ")", ";", "$", "currentItem", "=", "$", "parentQb", "->", "getQuery", "(", ")", "->", "getOneOrNullResult", "(", ")", ";", "if", "(", "$", "currentItem", "===", "null", ")", "{", "return", "null", ";", "}", "$", "qb", "->", "where", "(", "$", "qb", "->", "expr", "(", ")", "->", "andX", "(", "$", "qb", "->", "expr", "(", ")", "->", "eq", "(", "sprintf", "(", "'%s.root'", ",", "$", "alias", ")", ",", "':root'", ")", ",", "$", "qb", "->", "expr", "(", ")", "->", "orX", "(", "$", "qb", "->", "expr", "(", ")", "->", "andX", "(", "$", "qb", "->", "expr", "(", ")", "->", "lt", "(", "sprintf", "(", "'%s.lft'", ",", "$", "alias", ")", ",", "':left'", ")", ",", "$", "qb", "->", "expr", "(", ")", "->", "gt", "(", "sprintf", "(", "'%s.rgt'", ",", "$", "alias", ")", ",", "':right'", ")", ")", ",", "$", "qb", "->", "expr", "(", ")", "->", "between", "(", "sprintf", "(", "'%s.lft'", ",", "$", "alias", ")", ",", "':left'", ",", "':right'", ")", ")", ")", ")", ";", "$", "qb", "->", "setParameter", "(", "'root'", ",", "$", "currentItem", "->", "getRoot", "(", ")", ")", ";", "$", "qb", "->", "setParameter", "(", "'left'", ",", "$", "currentItem", "->", "getLft", "(", ")", ")", ";", "$", "qb", "->", "setParameter", "(", "'right'", ",", "$", "currentItem", "->", "getRgt", "(", ")", ")", ";", "return", "true", ";", "}" ]
Get item plus children @param \Doctrine\ORM\QueryBuilder $qb @param string $alias @param string $field @param array $value @return bool|null
[ "Get", "item", "plus", "children" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Admin/TreeAdmin.php#L157-L192
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Security/Voter/AdminVoter.php
AdminVoter.mapAttributesToRoles
protected function mapAttributesToRoles($class, $attributes) { $mappedAttributes = array(); foreach ($this->pool->getAdminClasses() as $adminClass => $adminCodes) { if ($class === $adminClass || $class instanceof $adminClass) { foreach ($adminCodes as $adminCode) { $admin = $this->pool->getAdminByAdminCode($adminCode); $baseRole = $this->securityHandler->getBaseRole($admin); foreach ($attributes as $attr) { if ($this->supportsAttribute($attr)) { $mappedAttributes[] = sprintf($baseRole, $attr); } } } } } return $mappedAttributes; }
php
protected function mapAttributesToRoles($class, $attributes) { $mappedAttributes = array(); foreach ($this->pool->getAdminClasses() as $adminClass => $adminCodes) { if ($class === $adminClass || $class instanceof $adminClass) { foreach ($adminCodes as $adminCode) { $admin = $this->pool->getAdminByAdminCode($adminCode); $baseRole = $this->securityHandler->getBaseRole($admin); foreach ($attributes as $attr) { if ($this->supportsAttribute($attr)) { $mappedAttributes[] = sprintf($baseRole, $attr); } } } } } return $mappedAttributes; }
[ "protected", "function", "mapAttributesToRoles", "(", "$", "class", ",", "$", "attributes", ")", "{", "$", "mappedAttributes", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "pool", "->", "getAdminClasses", "(", ")", "as", "$", "adminClass", "=>", "$", "adminCodes", ")", "{", "if", "(", "$", "class", "===", "$", "adminClass", "||", "$", "class", "instanceof", "$", "adminClass", ")", "{", "foreach", "(", "$", "adminCodes", "as", "$", "adminCode", ")", "{", "$", "admin", "=", "$", "this", "->", "pool", "->", "getAdminByAdminCode", "(", "$", "adminCode", ")", ";", "$", "baseRole", "=", "$", "this", "->", "securityHandler", "->", "getBaseRole", "(", "$", "admin", ")", ";", "foreach", "(", "$", "attributes", "as", "$", "attr", ")", "{", "if", "(", "$", "this", "->", "supportsAttribute", "(", "$", "attr", ")", ")", "{", "$", "mappedAttributes", "[", "]", "=", "sprintf", "(", "$", "baseRole", ",", "$", "attr", ")", ";", "}", "}", "}", "}", "}", "return", "$", "mappedAttributes", ";", "}" ]
Maps regular attributes such as VIEW, EDIT, etc, to their respective SONATA role name, such as ROLE_FOO_BAR_BAZ_EDIT @param string $class @param string[] $attributes @return array
[ "Maps", "regular", "attributes", "such", "as", "VIEW", "EDIT", "etc", "to", "their", "respective", "SONATA", "role", "name", "such", "as", "ROLE_FOO_BAR_BAZ_EDIT" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Security/Voter/AdminVoter.php#L109-L128
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Twig/Extension.php
Extension.adminUrl
public function adminUrl($subject, $action, $parameters = array()) { if (is_object($subject)) { $className = get_class($subject); } elseif (is_string($subject)) { $className = $subject; if (strpos($className, ':') !== false) { list($namespace, $entity) = explode(':', $className); $className = $this->doctrine->getAliasNamespace($namespace) . '\\' . $entity; } } else { throw new InvalidArgumentException("Unsupported subject, need either an object or a string"); } /** @var $admin \Sonata\AdminBundle\Admin\Admin */ $admin = $this->sonata->getAdminByClass($className); if (!$admin) { // assume the string is an admincode. $admin = $this->sonata->getAdminByAdminCode($className); } if (!$admin) { throw new InvalidArgumentException("No admin found for {$className}"); } if (is_object($subject)) { return $admin->generateObjectUrl($action, $subject, $parameters); } else { return $admin->generateUrl($action, $parameters); } }
php
public function adminUrl($subject, $action, $parameters = array()) { if (is_object($subject)) { $className = get_class($subject); } elseif (is_string($subject)) { $className = $subject; if (strpos($className, ':') !== false) { list($namespace, $entity) = explode(':', $className); $className = $this->doctrine->getAliasNamespace($namespace) . '\\' . $entity; } } else { throw new InvalidArgumentException("Unsupported subject, need either an object or a string"); } /** @var $admin \Sonata\AdminBundle\Admin\Admin */ $admin = $this->sonata->getAdminByClass($className); if (!$admin) { // assume the string is an admincode. $admin = $this->sonata->getAdminByAdminCode($className); } if (!$admin) { throw new InvalidArgumentException("No admin found for {$className}"); } if (is_object($subject)) { return $admin->generateObjectUrl($action, $subject, $parameters); } else { return $admin->generateUrl($action, $parameters); } }
[ "public", "function", "adminUrl", "(", "$", "subject", ",", "$", "action", ",", "$", "parameters", "=", "array", "(", ")", ")", "{", "if", "(", "is_object", "(", "$", "subject", ")", ")", "{", "$", "className", "=", "get_class", "(", "$", "subject", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "subject", ")", ")", "{", "$", "className", "=", "$", "subject", ";", "if", "(", "strpos", "(", "$", "className", ",", "':'", ")", "!==", "false", ")", "{", "list", "(", "$", "namespace", ",", "$", "entity", ")", "=", "explode", "(", "':'", ",", "$", "className", ")", ";", "$", "className", "=", "$", "this", "->", "doctrine", "->", "getAliasNamespace", "(", "$", "namespace", ")", ".", "'\\\\'", ".", "$", "entity", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "\"Unsupported subject, need either an object or a string\"", ")", ";", "}", "/** @var $admin \\Sonata\\AdminBundle\\Admin\\Admin */", "$", "admin", "=", "$", "this", "->", "sonata", "->", "getAdminByClass", "(", "$", "className", ")", ";", "if", "(", "!", "$", "admin", ")", "{", "// assume the string is an admincode.", "$", "admin", "=", "$", "this", "->", "sonata", "->", "getAdminByAdminCode", "(", "$", "className", ")", ";", "}", "if", "(", "!", "$", "admin", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"No admin found for {$className}\"", ")", ";", "}", "if", "(", "is_object", "(", "$", "subject", ")", ")", "{", "return", "$", "admin", "->", "generateObjectUrl", "(", "$", "action", ",", "$", "subject", ",", "$", "parameters", ")", ";", "}", "else", "{", "return", "$", "admin", "->", "generateUrl", "(", "$", "action", ",", "$", "parameters", ")", ";", "}", "}" ]
Render an url to a sonata admin @param mixed $subject @param string $action @param array $parameters @return string @throws InvalidArgumentException
[ "Render", "an", "url", "to", "a", "sonata", "admin" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Twig/Extension.php#L63-L92
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Doctrine/TransactionalRequestListener.php
TransactionalRequestListener.onKernelResponse
public function onKernelResponse(KernelEvent $event) { if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST && $this->wasTxStarted && $this->doctrine->getConnection()->getTransactionIsolation() > 0) { if ($this->doctrine->getConnection()->isRollbackOnly()) { $this->doctrine->getConnection()->rollback(); } else { $this->doctrine->getConnection()->commit(); } $this->wasTxStarted = false; } }
php
public function onKernelResponse(KernelEvent $event) { if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST && $this->wasTxStarted && $this->doctrine->getConnection()->getTransactionIsolation() > 0) { if ($this->doctrine->getConnection()->isRollbackOnly()) { $this->doctrine->getConnection()->rollback(); } else { $this->doctrine->getConnection()->commit(); } $this->wasTxStarted = false; } }
[ "public", "function", "onKernelResponse", "(", "KernelEvent", "$", "event", ")", "{", "if", "(", "$", "event", "->", "getRequestType", "(", ")", "===", "HttpKernelInterface", "::", "MASTER_REQUEST", "&&", "$", "this", "->", "wasTxStarted", "&&", "$", "this", "->", "doctrine", "->", "getConnection", "(", ")", "->", "getTransactionIsolation", "(", ")", ">", "0", ")", "{", "if", "(", "$", "this", "->", "doctrine", "->", "getConnection", "(", ")", "->", "isRollbackOnly", "(", ")", ")", "{", "$", "this", "->", "doctrine", "->", "getConnection", "(", ")", "->", "rollback", "(", ")", ";", "}", "else", "{", "$", "this", "->", "doctrine", "->", "getConnection", "(", ")", "->", "commit", "(", ")", ";", "}", "$", "this", "->", "wasTxStarted", "=", "false", ";", "}", "}" ]
Commits the transaction, if started @param \Symfony\Component\HttpKernel\Event\KernelEvent $event @return void
[ "Commits", "the", "transaction", "if", "started" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Doctrine/TransactionalRequestListener.php#L83-L96
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Controller/QuicklistController.php
QuicklistController.quicklistAction
public function quicklistAction(Request $request) { $quicklist = $this->get('zicht_admin.quicklist'); if ($request->get('repo') && $request->get('pattern')) { if ($request->get('language')) { $language = $request->get('language'); } else { $language = null; } return new JsonResponse($quicklist->getResults($request->get('repo'), $request->get('pattern'), $language)); } return array( 'repos' => $quicklist->getRepositoryConfigs() ); }
php
public function quicklistAction(Request $request) { $quicklist = $this->get('zicht_admin.quicklist'); if ($request->get('repo') && $request->get('pattern')) { if ($request->get('language')) { $language = $request->get('language'); } else { $language = null; } return new JsonResponse($quicklist->getResults($request->get('repo'), $request->get('pattern'), $language)); } return array( 'repos' => $quicklist->getRepositoryConfigs() ); }
[ "public", "function", "quicklistAction", "(", "Request", "$", "request", ")", "{", "$", "quicklist", "=", "$", "this", "->", "get", "(", "'zicht_admin.quicklist'", ")", ";", "if", "(", "$", "request", "->", "get", "(", "'repo'", ")", "&&", "$", "request", "->", "get", "(", "'pattern'", ")", ")", "{", "if", "(", "$", "request", "->", "get", "(", "'language'", ")", ")", "{", "$", "language", "=", "$", "request", "->", "get", "(", "'language'", ")", ";", "}", "else", "{", "$", "language", "=", "null", ";", "}", "return", "new", "JsonResponse", "(", "$", "quicklist", "->", "getResults", "(", "$", "request", "->", "get", "(", "'repo'", ")", ",", "$", "request", "->", "get", "(", "'pattern'", ")", ",", "$", "language", ")", ")", ";", "}", "return", "array", "(", "'repos'", "=>", "$", "quicklist", "->", "getRepositoryConfigs", "(", ")", ")", ";", "}" ]
Displays a quick list control for jumping to entries registered in the quick list service @param Request $request @return array|JsonResponse @Template("@ZichtAdmin/Quicklist/quicklist.html.twig") @Route("quick-list")
[ "Displays", "a", "quick", "list", "control", "for", "jumping", "to", "entries", "registered", "in", "the", "quick", "list", "service" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Controller/QuicklistController.php#L27-L42
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Event/Propagator.php
Propagator.onEvent
public function onEvent(Event $anyEvent, $eventName, EventDispatcherInterface $dispatcher) { if (isset($this->propagations[$eventName])) { foreach ($this->propagations[$eventName] as $builder) { $builder->buildAndForwardEvent($anyEvent); } } }
php
public function onEvent(Event $anyEvent, $eventName, EventDispatcherInterface $dispatcher) { if (isset($this->propagations[$eventName])) { foreach ($this->propagations[$eventName] as $builder) { $builder->buildAndForwardEvent($anyEvent); } } }
[ "public", "function", "onEvent", "(", "Event", "$", "anyEvent", ",", "$", "eventName", ",", "EventDispatcherInterface", "$", "dispatcher", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "propagations", "[", "$", "eventName", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "propagations", "[", "$", "eventName", "]", "as", "$", "builder", ")", "{", "$", "builder", "->", "buildAndForwardEvent", "(", "$", "anyEvent", ")", ";", "}", "}", "}" ]
Builds and forwards the event for all progragations registered for the specified event type. @param \Symfony\Component\EventDispatcher\Event $anyEvent @param string $eventName @param EventDispatcherInterface $dispatcher @return void
[ "Builds", "and", "forwards", "the", "event", "for", "all", "progragations", "registered", "for", "the", "specified", "event", "type", "." ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Event/Propagator.php#L48-L55
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Service/Quicklist.php
Quicklist.getRepositoryConfigs
public function getRepositoryConfigs($exposedOnly = true) { if ($exposedOnly) { return array_filter( $this->repos, function ($item) { return isset($item['exposed']) && $item['exposed'] === true; } ); } return $this->repos; }
php
public function getRepositoryConfigs($exposedOnly = true) { if ($exposedOnly) { return array_filter( $this->repos, function ($item) { return isset($item['exposed']) && $item['exposed'] === true; } ); } return $this->repos; }
[ "public", "function", "getRepositoryConfigs", "(", "$", "exposedOnly", "=", "true", ")", "{", "if", "(", "$", "exposedOnly", ")", "{", "return", "array_filter", "(", "$", "this", "->", "repos", ",", "function", "(", "$", "item", ")", "{", "return", "isset", "(", "$", "item", "[", "'exposed'", "]", ")", "&&", "$", "item", "[", "'exposed'", "]", "===", "true", ";", "}", ")", ";", "}", "return", "$", "this", "->", "repos", ";", "}" ]
Returns all configurations @param bool $exposedOnly @return array
[ "Returns", "all", "configurations" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Service/Quicklist.php#L62-L73
train