_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q260000 | ResourceProvider.createResources | test | private function createResources(array $resources, $type)
{
foreach ($resources as $resource) {
if ($type === "string") {
$this->vars->pathsLoadedCheck($resource);
if ($this->vars->cache->checkCache()) {
return;
}
if ($this->vars->resourceImported($resource)) {
continue;
}
$pos = $this->vars->addResource($resource);
$resource = new FileResource($this, $resource);
$this->vars->updateResource($resource, $pos);
} else {
$resource = new ResourceProvider($this->vars, $resource);
}
$this->addContent($resource->getContent());
}
} | php | {
"resource": ""
} |
q260001 | ResourceProvider.addContent | test | private function addContent($content)
{
if ($this->relative) {
$this->content = $this->mergeContents($this->content, $content);
} else {
$this->parent_content = $this->mergeContents($this->parent_content, $content);
}
} | php | {
"resource": ""
} |
q260002 | ResourceProvider.getSupportedFilesInDir | test | private function getSupportedFilesInDir($entity)
{
$dir_loader = new DirectoryLoader($entity, $this->recursive);
$dir_loader->setSupports($this->vars->loader->getExtensions());
$dir_loader->load();
return $dir_loader->getContent();
} | php | {
"resource": ""
} |
q260003 | ResourceProvider.mergeParentContent | test | public function mergeParentContent()
{
$this->content = $this->mergeContents($this->content, $this->parent_content);
return $this;
} | php | {
"resource": ""
} |
q260004 | AbstractResource.internalGet | test | private function internalGet(array $array, $key, $exists = false)
{
if (isset($array[$key])) {
return (!$exists) ? $array[$key] : true;
}
$parts = explode('.', $key);
foreach ($parts as $part) {
if (!is_array($array) || !isset($array[$part])) {
return (!$exists) ? null : false;
}
$array = $array[$part];
}
return (!$exists) ? $array : true;
} | php | {
"resource": ""
} |
q260005 | AbstractResource.arrayKeyExists | test | public function arrayKeyExists($key)
{
if (array_key_exists($key, $this->content)) {
return true;
}
$parts = explode('.', $key);
$arr = $this->content;
foreach ($parts as $part) {
if (!is_array($arr) || !array_key_exists($part, $arr)) {
return false;
}
$arr = $arr[$part];
}
return true;
} | php | {
"resource": ""
} |
q260006 | VariableProvider.parse | test | public function parse($value)
{
foreach (self::$variable_types as $variable_type) {
$value = $this->typeParse($value, $variable_type);
}
return $value;
} | php | {
"resource": ""
} |
q260007 | VariableProvider.typeParse | test | private function typeParse($value, $type)
{
$const_str = sprintf('REGEX_%s_SYNTAX', strtoupper($type));
$regex = constant('\M1\Vars\Variables\VariableProvider::'.$const_str);
$matches = $this->fetchVariableMatches($value, $regex);
if (is_array($matches)) {
if (count($matches[0]) === 1 && $value === $matches[0][0]) {
return $this->fetchVariable(trim($matches[1][0]), $type);
}
$value = $this->doReplacements($value, $matches, $type);
}
return $value;
} | php | {
"resource": ""
} |
q260008 | VariableProvider.fetchVariableMatches | test | private function fetchVariableMatches($value, $regex)
{
preg_match_all('/' . $regex . '/', $value, $matches);
if (!is_array($matches) || !isset($matches[0]) || empty($matches[0])) {
return false;
}
return $matches;
} | php | {
"resource": ""
} |
q260009 | VariableProvider.fetchVariable | test | private function fetchVariable($variable_name, $type)
{
$this->checkVariableExists($variable_name, $type);
if ($type === 'env') {
return getenv($variable_name);
} elseif ($type === 'replacement') {
return $this->rstore->get($variable_name);
}
return $this->vstore->get($variable_name);
} | php | {
"resource": ""
} |
q260010 | VariableProvider.checkVariableExists | test | private function checkVariableExists($variable, $type)
{
if (($type === 'env' && !getenv($variable)) ||
($type === 'replacement' && !$this->rstore->arrayKeyExists($variable)) ||
($type === 'variable' && !$this->vstore->arrayKeyExists($variable))
) {
throw new \InvalidArgumentException(
sprintf('Variable has not been defined as a `%s`: %s', $variable, $type)
);
}
return true;
} | php | {
"resource": ""
} |
q260011 | VariableProvider.doReplacements | test | public function doReplacements($value, $matches, $type)
{
$replacements = array();
for ($i = 0; $i <= (count($matches[0]) - 1); $i++) {
$replacement = $this->fetchVariable($matches[1][$i], $type);
$replacements[$matches[0][$i]] = $replacement;
}
if (!empty($replacements)) {
$value = strtr($value, $replacements);
}
return $value;
} | php | {
"resource": ""
} |
q260012 | svg_dom.export | test | protected static function export($dom = null) {
if (!is_a($dom, 'DOMDocument')) {
return false;
}
try {
$svgs = $dom->getElementsByTagName('svg');
if (!$svgs->length) {
return false;
}
$svg = $svgs->item(0)->ownerDocument->saveXML($svgs->item(0), LIBXML_NOBLANKS);
// Remove comments.
$svg = static::strip_comments($svg);
return $svg;
} catch (\Throwable $e) {
error_log($e->getMessage());
return false;
} catch (\Exception $e) {
return false;
}
return false;
} | php | {
"resource": ""
} |
q260013 | svg_dom.remove_nodes | test | protected static function remove_nodes($nodes) {
if (!is_a($nodes, 'DOMNodeList')) {
return false;
}
try {
while ($nodes->length) {
static::remove_node($nodes->item(0));
}
return true;
} catch (\Throwable $e) {
error_log($e->getMessage());
return false;
} catch (\Exception $e) {
return false;
}
return false;
} | php | {
"resource": ""
} |
q260014 | svg_dom.remove_node | test | protected static function remove_node($node) {
if (
!is_a($node, 'DOMElement') &&
!is_a($node, 'DOMNode')
) {
return false;
}
try {
// @codingStandardsIgnoreStart
$node->parentNode->removeChild($node);
// @codingStandardsIgnoreEnd
return true;
} catch (\Throwable $e) {
error_log($e->getMessage());
return false;
} catch (\Exception $e) {
return false;
}
return false;
} | php | {
"resource": ""
} |
q260015 | PathTrait.setPath | test | public function setPath($path, $check_writeable = false)
{
if (is_null($path)) {
return;
}
if (!is_dir($path) || ($check_writeable && !is_writable($path))) {
throw new \InvalidArgumentException(sprintf(
"'%s' base path does not exist or is not writable",
$path
));
}
$this->path = realpath($path);
return $this;
} | php | {
"resource": ""
} |
q260016 | FileResource.makePaths | test | private function makePaths($file)
{
$file = realpath($file);
$base_path = $this->provider->vars->getPath();
$filesystem = new Filesystem();
$abs_path = $filesystem->makePathRelative(
$file,
$base_path
);
$this->file = $file;
$this->filename = rtrim($abs_path, "/");
} | php | {
"resource": ""
} |
q260017 | FileResource.searchForResources | test | private function searchForResources($content = array(), $prefix = '')
{
$returned_content = array();
foreach ($content as $ck => $cv) {
$this->variables->vstore->setCurrentPrefix($prefix);
$returned_content = $this->parseContent($ck, $cv, $returned_content, $prefix);
}
return $returned_content;
} | php | {
"resource": ""
} |
q260018 | FileResource.parseContent | test | private function parseContent($key, $value, $returned_content, $prefix)
{
if ($key === 'imports' && !is_null($value) && !empty($value)) {
$imported_resource = $this->useImports($value);
if ($imported_resource) {
$returned_content = array_replace_recursive($returned_content, $imported_resource);
}
} elseif (is_array($value)) {
$returned_content[$key] = $this->searchForResources(
$value,
$this->variables->vstore->createPrefixName($prefix, $key)
);
} else {
$value = $this->parseText($value);
$this->variables->vstore->set($prefix.$key, $value);
$returned_content[$key] = $value;
}
return $returned_content;
} | php | {
"resource": ""
} |
q260019 | FileResource.useImports | test | private function useImports($imports)
{
$imported_resources = array();
if ((is_array($imports) && $this->isAssoc($imports)) || is_string($imports)) {
$imports = array($imports);
}
foreach ($imports as $import) {
$imported_resources = $this->processImport($this->parseText($import), $imported_resources);
}
return $imported_resources;
} | php | {
"resource": ""
} |
q260020 | FileResource.import2Resource | test | private function import2Resource($import, array $imported_resources)
{
$resource = $this->createResource($import);
if ($resource) {
$imported_resources = $this->importResource($resource, $imported_resources);
}
return $imported_resources;
} | php | {
"resource": ""
} |
q260021 | FileResource.createResource | test | private function createResource($import)
{
if (is_array($import) && array_key_exists('resource', $import)) {
$import_resource = $import;
$import_resource['relative'] = $this->checkBooleanValue('relative', $import_resource);
$import_resource['recursive'] = $this->checkBooleanValue('recursive', $import_resource);
} elseif (is_string($import)) {
$import_resource = array('resource' => $import, 'relative' => true, 'recursive' => true);
}
$import_resource = new ResourceProvider(
$this->provider->vars,
$this->createImportName($import_resource['resource']),
$import_resource['relative'],
$import_resource['recursive']
);
return $import_resource;
} | php | {
"resource": ""
} |
q260022 | FileResource.createImportName | test | private function createImportName($resource)
{
$resource = $this->explodeResourceIfElse($resource);
$resource_pieces = array();
foreach ($resource as $r) {
$parsed_r = $this->trimFlags($r);
$parsed_r = sprintf('%s/%s', dirname($this->file), $parsed_r);
$parsed_r = $this->replicateFlags($parsed_r, $r);
$resource_pieces[] = $parsed_r;
}
return $this->implodeResourceIfElse($resource_pieces);
} | php | {
"resource": ""
} |
q260023 | FileResource.importResource | test | private function importResource(ResourceProvider $provider, $imported_resources)
{
$content = $provider->getContent();
$parent_content = $provider->getParentContent();
if (!empty($content)) {
$imported_resources = array_replace_recursive($imported_resources, $content);
}
if (!empty($parent_content)) {
$this->provider->addParentContent($parent_content);
}
return $imported_resources;
} | php | {
"resource": ""
} |
q260024 | FileResource.checkBooleanValue | test | public function checkBooleanValue($value, $import)
{
$default = false;
if ($value === 'relative') {
$default = true;
}
$value = (isset($import[$value])) ? $import[$value] : $default;
return $this->getBooleanValue($value);
} | php | {
"resource": ""
} |
q260025 | FileResource.getBooleanValue | test | private function getBooleanValue($value)
{
$value = strtolower($value);
if (!$value || $value === "false" || $value === "no") {
return false;
}
return true;
} | php | {
"resource": ""
} |
q260026 | mime.get_aliases | test | public static function get_aliases($ext='') {
$ext = trim(strtolower($ext));
$ext = ltrim($ext, '.');
if (strlen($ext) && array_key_exists($ext, mime\aliases::$data)) {
$match = mime\aliases::$data[$ext];
} else {
$match = false;
}
// Filter.
return apply_filters('blobmimes_get_mime_aliases', $match, $ext);
} | php | {
"resource": ""
} |
q260027 | mime.update_filename_extension | test | public static function update_filename_extension($filename, $ext) {
$ext = strtolower($ext);
$ext = rtrim($ext, '.');
$ext = ltrim($ext, '.');
$filename_parts = explode('.', $filename);
// Remove the old extension.
if (count($filename_parts) > 1) {
array_pop($filename_parts);
}
// Add the new extension.
if (strlen($ext)) {
$filename_parts[] = $ext;
}
return implode('.', $filename_parts);
} | php | {
"resource": ""
} |
q260028 | mime.check_alias | test | public static function check_alias($ext='', $mime='') {
// Standardize inputs.
$mime = strtolower(sanitize_mime_type($mime));
$ext = trim(strtolower($ext));
$ext = ltrim($ext, '.');
// Can't continue if the extension is not in the database.
if (false === ($mimes = static::get_aliases($ext))) {
// Filter.
return apply_filters('blobmimes_check_mime_alias', false, $ext, $mime);
}
// Before looking for matches, convert any generic CDFV2
// types into an equally generic, but less variable type.
if (0 === strpos($mime, 'application/cdfv2')) {
$mime = 'application/vnd.ms-office';
}
// "Default" MIME might not need to trigger a failure.
if ('application/octet-stream' === $mime) {
// Filter.
if (false === apply_filters('blobmimes_check_application_octet_stream', false)) {
return apply_filters('blobmimes_check_mime_alias', true, $ext, $mime);
}
}
// An empty file doesn't really have a type.
elseif ('inode/x-empty' === $mime) {
return apply_filters('blobmimes_check_mime_alias', true, $ext, $mime);
}
// Test for the literal MIME, but also certain generic
// variations like x-subtype and vnd.subtype.
$test = array($mime);
$parts = explode('/', $mime);
$subtype = count($parts) - 1;
if ('x-' === substr($parts[$subtype], 0, 2)) {
$parts[$subtype] = substr($parts[$subtype], 2);
} else {
$parts[$subtype] = 'x-' . $parts[$subtype];
}
$test[] = implode('/', $parts);
$parts = explode('/', $mime);
$subtype = count($parts) - 1;
if ('vnd.' === substr($parts[$subtype], 0, 4)) {
$parts[$subtype] = substr($parts[$subtype], 4);
} else {
$parts[$subtype] = 'vnd.' . $parts[$subtype];
}
$test[] = implode('/', $parts);
// Overlap is success!
$found = array_intersect($test, $mimes);
$match = count($found) > 0;
// Filter.
return apply_filters('blobmimes_check_mime_alias', $match, $ext, $mime);
} | php | {
"resource": ""
} |
q260029 | mime.check_allowed_aliases | test | public static function check_allowed_aliases($alias, $mimes=null) {
// Default MIMEs.
if (empty($mimes)) {
$mimes = get_allowed_mime_types();
}
$alias = strtolower(sanitize_mime_type($alias));
$ext = $type = false;
// Early bail opportunity.
if (!$alias || !count($mimes)) {
return false;
}
// Direct hit!
if (false !== $extensions = array_search($alias, $mimes, true)) {
$extensions = explode('|', $extensions);
$ext = $extensions[0];
$type = $alias;
return compact('ext', 'type');
}
// Try all extensions.
foreach ($mimes as $extensions=>$mime) {
$extensions = explode('|', $extensions);
foreach ($extensions as $extension) {
if (static::check_alias($extension, $alias)) {
$ext = $extension;
$type = $mime;
return compact('ext', 'type');
}
}
}
return false;
} | php | {
"resource": ""
} |
q260030 | ReplacementStore.load | test | public function load($replacements)
{
if (is_array($replacements)) {
$variables = $replacements;
} elseif (is_file($replacements)) {
$variables = $this->loadContent($replacements);
} else {
throw new \RuntimeException('Config replacements must be a array or a file');
}
$this->content = $variables;
} | php | {
"resource": ""
} |
q260031 | DirectoryLoader.getSupportedFilesRecursively | test | private function getSupportedFilesRecursively()
{
$dir_it = new \RecursiveDirectoryIterator($this->entity, \RecursiveDirectoryIterator::SKIP_DOTS);
$files = new \RecursiveIteratorIterator(
$dir_it,
\RecursiveIteratorIterator::LEAVES_ONLY,
\RecursiveIteratorIterator::CATCH_GET_CHILD
);
return $this->createRegexIterator($files);
} | php | {
"resource": ""
} |
q260032 | DirectoryLoader.makeResources | test | private function makeResources($paths)
{
if ($paths && !empty($paths)) {
$resources = array();
foreach ($paths as $path) {
$resources[] = $path;
}
return $resources;
}
return false;
} | php | {
"resource": ""
} |
q260033 | CacheProvider.checkCache | test | public function checkCache()
{
if ($this->provide && $this->path && !$this->getAttempted()) {
$file = sprintf('%s/vars/%s.php', $this->path, $this->name);
$this->attempted = true;
if (is_file($file) &&
filemtime($file) >= (time() - $this->expire)) {
$this->hit = true;
return true;
}
}
return false;
} | php | {
"resource": ""
} |
q260034 | CacheProvider.makeCache | test | public function makeCache(Vars $vars)
{
if ($this->provide) {
$cache_folder = sprintf("%s/vars", $this->path);
if (!file_exists($cache_folder)) {
mkdir($cache_folder, 0777, true);
}
$cache_file = sprintf('%s/%s.php', $cache_folder, $this->name);
file_put_contents($cache_file, serialize($vars));
}
} | php | {
"resource": ""
} |
q260035 | AssetsVersionManager.setVersion | test | public function setVersion($value)
{
if (!is_string($value) && !is_numeric($value)) {
throw new \InvalidArgumentException(sprintf(
'Wrong value for assets version: %s - it must be string or numeric',
var_export($value, true)
));
}
if (!preg_match('/^' . static::$versionValueMask . '$/', $value)) {
throw new \InvalidArgumentException(sprintf(
'Wrong value for assets version: %s - it must be empty or consist only of letters, numbers and the following characters: .-_',
var_export($value, true)
));
}
$this->fileContents = substr_replace(
$this->fileContents,
$value,
$this->versionStartPos,
strlen($this->versionValue)
);
$this->versionValue = $value;
try {
file_put_contents($this->filePath, $this->fileContents);
} catch (\Exception $e) {
throw new FileException(sprintf(
'Could not write to write "%s"; make sure it exists and you have enough permissions',
$this->filePath
));
}
} | php | {
"resource": ""
} |
q260036 | AssetsVersionManager.readFile | test | protected function readFile()
{
$fileExtension = pathinfo($this->filePath, PATHINFO_EXTENSION);
if ($fileExtension != 'yml' && $fileExtension != 'yaml')
throw new InvalidConfigurationException(sprintf(
'Could not use "%s" - only yml files are supported by AssetsVersionManager',
var_export($this->versionValue, true)
));
try {
$this->fileContents = file_get_contents($this->filePath);
} catch (\Exception $e) {
throw new FileException(sprintf(
'Could not read file "%s"; make sure it exists and you have enough permissions',
$this->filePath
));
}
// Find a row with the parameter
preg_match(
'/(\s+' . $this->parameterName . '\:[^\S\n]*)(' . static::$versionValueMask . ')\s*(\n|#)/',
$this->fileContents . "\n",
$matches
);
if (array_key_exists(2, $matches)) {
$this->versionValue = $matches[2];
$this->versionStartPos = strpos($this->fileContents."\n", $matches[0]) + strlen($matches[1]);
return;
}
throw new \Exception(sprintf(
'Could not find definition of parameter "%s"; make sure it exists in "%s"',
$this->parameterName,
$this->filePath
));
} | php | {
"resource": ""
} |
q260037 | RESTClient.send | test | public function send($request)
{
$this->request = $request;
switch (strtoupper($request->getVerb())) {
case 'GET':
$this->response = $this->get($request);
break;
case 'PUT':
$this->response = $this->put($request);
break;
case 'DELETE':
$this->response = $this->delete($request);
break;
case 'POST':
$this->response = $this->post($request);
break;
case 'HEAD':
$this->response = $this->head($request);
break;
default:
throw new \Exception($verb . ' is an invalid or unsupported REST verb.');
}
return $this->response;
} | php | {
"resource": ""
} |
q260038 | RESTClient.setOptions | test | protected function setOptions(&$ch, $urlStr, $headers)
{
$url = $this->prefix . $urlStr; // Build full URL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, $this->auth);
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
curl_setopt($ch, CURLINFO_HEADER_OUT, true); // For debugging; TODO otherwise disable
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); // Expose ?
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Expose ?
$headerArr = array();
foreach ($headers as $key => $val) {
$headerArr[] = $key . ':' . $val;
}
// If headers exist, add them
if (count($headerArr) > 0) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
}
} | php | {
"resource": ""
} |
q260039 | RESTClient.get | test | public function get($request)
{
$ch = curl_init();
$this->setOptions($ch, $request->getUrlStr(), $request->getHeaders());
// Options specific to GET
curl_setopt($ch, CURLOPT_HTTPGET, true);
$this->logger->debug("GET");
return $this->execute($ch);
} | php | {
"resource": ""
} |
q260040 | RESTClient.put | test | public function put($request)
{
$this->logger->debug("PUT ");
$ch = curl_init();
// Handle body
$body = $request->getBody();
$requestLength = strlen($body);
$fh = fopen('php://temp', 'rw');
fwrite($fh, $body);
rewind($fh);
$this->setOptions($ch, $request->getUrlStr(), $request->getHeaders());
// Options specific to PUT
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, $requestLength);
curl_setopt($ch, CURLOPT_PUT, true);
$ret = $this->execute($ch);
fclose($fh);
return $ret;
} | php | {
"resource": ""
} |
q260041 | RESTClient.delete | test | public function delete($request)
{
$this->logger->debug("DELETE");
$ch = curl_init();
$this->setOptions($ch, $request->getUrlStr(), $request->getHeaders());
// Options specific to DELETE
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
return $this->execute($ch);
} | php | {
"resource": ""
} |
q260042 | RESTClient.post | test | public function post($request)
{
$ch = curl_init();
$this->setOptions($ch, $request->getUrlStr(), $request->getHeaders());
curl_setopt($ch, CURLOPT_POST, true);
if ($request->isWWWFormURLEncodedPost()) {
$this->logger->debug("POST www-form-urlencoded");
$requestBody = http_build_query($request->getParams());
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
} else {
$this->logger->debug("POST ");
$requestLength = strlen($request->getBody());
curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getBody());
}
return $this->execute($ch);
} | php | {
"resource": ""
} |
q260043 | RESTClient.head | test | public function head($request)
{
$ch = curl_init();
$this->setOptions($ch, $request->getUrlStr(), $request->getHeaders());
// Options specific to HEAD
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
$this->logger->debug("HEAD");
return $this->execute($ch);
} | php | {
"resource": ""
} |
q260044 | RESTClient.execute | test | protected function execute(&$ch)
{
$response = new RESTResponse();
$curl_exec = curl_exec($ch);
// print('******* START $curl_exec (body) *******' . PHP_EOL);
// print_r($curl_exec);
// print('******* END $curl_exec (body) *******' . PHP_EOL);
$response->setBody($curl_exec);
$curl_getinfo = curl_getinfo($ch);
// print('******* START $curl_getinfo *******' . PHP_EOL);
// print_r($curl_getinfo);
// print('******* END $curl_getinfo *******' . PHP_EOL);
$response->setInfo($curl_getinfo);
//print_r($response);
$this->logger->debug("Response code: " . $response->getHttpCode());
if ($response->getHttpCode() === 0) {
curl_close ($ch);
throw new \Exception(
'No connection: ' . $response->getUrl(),
$response->getHttpCode()
);
} else if ($response->getHttpCode() >= 400) {
curl_close ($ch);
$this->logger->debug("HTTP Error " . $response->getHttpCode());
throw new \Exception(
$response->getErrorMessage(),
$response->getHttpCode()
);
} else {
curl_close ($ch);
// print('***** RESPONSE *****' . PHP_EOL);
// print_r($response);
return $response;
}
} | php | {
"resource": ""
} |
q260045 | RESTClient.installExtension | test | public function installExtension($resource, $params, $filename)
{
if (!isset($params["provider"])) {
$params["provider"] = 'MLPHP';
}
$path = __DIR__ . DIRECTORY_SEPARATOR . "xquery" . DIRECTORY_SEPARATOR . $filename;
$body = file_get_contents($path);
$key = serialize(array($this->host, $this->port, $resource, $params, $body));
if (array_key_exists($key, self::$extension_cache)) {
return;
}
$this->logger->debug("installExtension");
$method = 'put';
$headers = array(
'Content-type' => 'application/xquery'
);
$request = new RESTRequest($method, $resource, $params, $body, $headers);
$this->put($request);
self::$extension_cache[$key] = 1;
} | php | {
"resource": ""
} |
q260046 | RangeConstraint.addBuckets | test | public function addBuckets($buckets) {
if (is_array($buckets)) {
$this->buckets = array_merge($this->buckets, $buckets);
} else {
$this->buckets[] = $buckets;
}
} | php | {
"resource": ""
} |
q260047 | XMLDocument.read | test | public function read($uri = null, $params = array())
{
$this->uri = (isset($uri)) ? (string)$uri : $this->uri;
$params = array_merge(array('format' => 'xml'), $params);
return parent::read($this->uri, $params);
} | php | {
"resource": ""
} |
q260048 | XMLDocument.write | test | public function write($uri = null, $params = array())
{
if ($this->isValidXML($this->getContent())) {
$this->uri = (isset($uri)) ? (string)$uri : $this->uri;
$params = array_merge(array('format' => 'xml'), $params);
return parent::write($this->uri, $params);
} else {
throw new \Exception('Attempting to write invalid XML content');
}
} | php | {
"resource": ""
} |
q260049 | XMLDocument.isValidXML | test | public function isValidXML($xml)
{
$doc = new \DOMDocument();
try {
return $doc->loadXML($xml) === true;
} catch(\Exception $e) {
$this->logger->warning('XMLDocument::isValidXML() - ' . $e->getMessage());
return false;
}
} | php | {
"resource": ""
} |
q260050 | Values.setUpRange | test | public function setUpRange($elem, $ns = '', $attr = '', $attrNs = '', $datatype = 'string')
{
$this->type = 'range';
$this->elem = (string)$elem;
$this->ns = (string)$ns;
$this->attr = (string)$attr;
$this->attrNs = (string)$attrNs;
$this->datatype = (string)$datatype;
} | php | {
"resource": ""
} |
q260051 | Values.getValuesAsElem | test | public function getValuesAsElem($dom)
{
$valsElem = $dom->createElement('values');
$valsElem->setAttribute('name', $this->name);
switch ($this->type) {
case 'range':
$rangeElem = $dom->createElement('range');
$rangeElem->setAttribute('type', $this->datatype);
$elemElem = $dom->createElement('element');
$elemElem->setAttribute('ns', $this->ns);
$elemElem->setAttribute('name', $this->elem);
$rangeElem->appendChild($elemElem);
if($this->attr) {
$attrElem = $dom->createElement('attribute');
$attrElem->setAttribute('ns', $this->attrNs);
$attrElem->setAttribute('name', $this->attr);
$rangeElem->appendChild($attrElem);
}
$valsElem->appendChild($rangeElem);
break;
/* <values name='example'>
<range type='xs:integer'>
<element ns='' name='game'/>
<attribute ns='' name='runs'/>
</range>
<aggregate apply='sum'/>
</values> */
case 'uri':
$uriElem = $dom->createElement('uri');
$valsElem->appendChild($uriElem);
break;
/* <values name='uri'>
<uri/>
<values-option>limit=10</values-option>
</values> */
case 'collection':
$collectionElem = $dom->createElement('collection');
$valsElem->appendChild($collectionElem);
break;
/* <values name="coll">
<collection/>
<values-option>limit=10</values-option>
</values> */
}
$this->addAggregate($dom, $valsElem);
$this->addValuesOptions($dom, $valsElem);
return $valsElem;
} | php | {
"resource": ""
} |
q260052 | Values.addValuesOptions | test | private function addValuesOptions($dom, $elem)
{
if (!empty($this->valuesOptions)) {
foreach($this->valuesOptions as $opt) {
$valuesElem = $dom->createElement('values-option');
$valuesElem->nodeValue = $opt;
$elem->appendChild($valuesElem);
}
}
return $elem;
} | php | {
"resource": ""
} |
q260053 | Values.addAggregate | test | private function addAggregate($dom, $elem)
{
if(!empty($this->aggregate)) {
$aggregateElem = $dom->createElement('aggregate');
$aggregateElem->setAttribute('apply', $this->aggregate);
$elem->appendChild($aggregateElem);
}
return $elem;
} | php | {
"resource": ""
} |
q260054 | Search.getParams | test | public function getParams()
{
$params = array(
'start' => $this->start, 'pageLength' => $this->pageLength,
'view' => $this->view, 'format' => $this->format
);
if(!empty($this->options)) {
$params['options'] = $this->options;
}
if(!empty($this->collection)) {
$params['collection'] = $this->collection;
}
if(!empty($this->directory)) {
$params['directory'] = $this->directory;
}
return $params;
} | php | {
"resource": ""
} |
q260055 | Search.retrieve | test | public function retrieve($query, $params = array(), $structured = false)
{
$this->query = (string)$query;
$params = array_merge(array(($structured ? 'structuredQuery' : 'q') =>
$this->query), $this->getParams(), $params);
$request = new RESTRequest('GET', 'search', $params);
try {
$response = $this->client->send($request);
//print_r($response);
$results = new SearchResults($response->getBody());
return $results;
} catch(Exception $e) {
echo $e->getMessage() . ' in ' . $e->getFile() .
' on line ' . $e->getLine() . PHP_EOL;
}
} | php | {
"resource": ""
} |
q260056 | Search.retrieveKeyValue | test | public function retrieveKeyValue($key, $value, $params = array())
{
// /v1/keyvalue is deprecated, use /v1/search with structured
$this->key = (string)$key;
$this->value = (string)$value;
$query = '<query xmlns="http://marklogic.com/appservices/search">
<container-query>
<json-property name="' . $this->key . '" ns="" />
<term-query>
<text>' . $this->value . '</text>
</term-query>
</container-query>
</query>';
try {
$params = array_merge(
array('structuredQuery' => $query),
$this->getParams(), $params
);
$request = new RESTRequest('GET', 'search', $params);
$response = $this->client->send($request);
$results = new SearchResults($response->getBody());
return $results;
} catch(Exception $e) {
echo $e->getMessage() . ' in ' . $e->getFile() .
' on line ' . $e->getLine() . PHP_EOL;
}
} | php | {
"resource": ""
} |
q260057 | Search.retrieveKeyValueElement | test | public function retrieveKeyValueElement(
$element, $attribute, $value, $params = array()
)
{
$this->element = (string)$element;
$this->attribute = (string)$attribute;
$this->value = (string)$value;
// /v1/keyvalue is deprecated, use /v1/search with structured
// $query = '<query xmlns="http://marklogic.com/appservices/search">
// <container-query>
// <element name="' . $this->element . '" ns="" />';
// $query .= $this->attribute ?
// '<attribute name=' . $this->attribute . ' ns="" />' :
// '';
// $query .= '<term-query>
// <text>' . $this->value . '</text>
// </term-query>
// </container-query>
// </query>';
try {
// Only include attribute in final array if it is set
$array_attr = (!empty($attribute)) ?
array('attribute' => $this->attribute) : array();
$params = array_merge(
array('element' => $this->element, 'value' => $this->value),
$array_attr, $this->getParams(), $params);
$request = new RESTRequest('GET', 'keyvalue', $params);
$params = array_merge(
array('element' => $this->element, 'value' => $this->value),
$array_attr, $this->getParams(), $params);
// $params = array_merge(
// array('structuredQuery' => $query),
// $this->getParams(), $params
// );
$request = new RESTRequest('GET', 'keyvalue', $params);
$response = $this->client->send($request);
$results = new SearchResults($response->getBody());
return $results;
} catch(Exception $e) {
echo $e->getMessage() . ' in ' . $e->getFile() .
' on line ' . $e->getLine() . PHP_EOL;
}
} | php | {
"resource": ""
} |
q260058 | Search.highlight | test | public function highlight(
$content, $contentType, $class, $query,
$params = array(), $structured = false
)
{
// Install the API extension
$resource = "resources/highlight";
$this->client->installExtension("config/" . $resource, array(
'method' => 'post',
'post:q?' => 'string',
'post:class' => 'string',
'post:structuredQuery?' => 'string',
'post:c' => 'string',
'post:ct' => 'string',
'post:provider?' => 'string'
), "highlight.xqy");
// Use it
$this->query = (string)$query;
$params = array_merge(array(
($structured ? 'structuredQuery' : 'q') => $this->query,
'c' => $content,
'ct' => $contentType,
'class' => $class
), $this->getParams(), $params);
$request = new RESTRequest('POST', $resource, $params, "", array(
'Content-type' => 'application/x-www-form-urlencoded'
));
try {
$response = $this->client->send($request);
//print_r($response);
$results = $response->getBody();
if ($contentType === "text/plain") {
return $results;
} else {
// Strip off XML decl
return substr( $results, strpos($results, "\n")+1 );
}
} catch(Exception $e) {
echo $e->getMessage() . ' in ' . $e->getFile() .
' on line ' . $e->getLine() . PHP_EOL;
}
} | php | {
"resource": ""
} |
q260059 | MLPHP.getClient | test | public function getClient()
{
return new RESTClient(
$this->config['host'],
$this->config['port'],
$this->config['path'],
$this->config['version'],
$this->config['username'],
$this->config['password'],
$this->config['auth'],
$this->config['logger']
);
} | php | {
"resource": ""
} |
q260060 | MLPHP.getManageClient | test | public function getManageClient()
{
return new RESTClient(
$this->config['host'],
$this->config['managePort'],
$this->config['managePath'],
$this->config['manageVersion'],
$this->config['username'],
$this->config['password'],
$this->config['auth'],
$this->config['logger']
);
} | php | {
"resource": ""
} |
q260061 | MLPHP.getAdminClient | test | public function getAdminClient()
{
return new RESTClient(
$this->config['host'],
$this->config['adminPort'],
$this->config['adminPath'],
$this->config['adminVersion'],
$this->config['username'],
$this->config['password'],
$this->config['auth'],
$this->config['logger']
);
} | php | {
"resource": ""
} |
q260062 | MLPHP.getAPI | test | public function getAPI()
{
return new RESTAPI(
$this->config['api'],
$this->config['host'],
$this->config['db'],
$this->config['port'],
$this->config['username'],
$this->config['password']
);
} | php | {
"resource": ""
} |
q260063 | MLPHP.getDatabase | test | public function getDatabase($name = null)
{
$name = $name ? $name : $this->config['db'];
return new Database(
$this->getManageClient(),
$name
);
} | php | {
"resource": ""
} |
q260064 | MLPHP.getOptions | test | public function getOptions($name = null)
{
$name = $name ? $name : $this->config['options'];
return new Options(
$this->getClient(),
$name
);
} | php | {
"resource": ""
} |
q260065 | MLPHP.autoload | test | public static function autoload($className)
{
$thisClass = str_replace(__NAMESPACE__ . '\\', '', __CLASS__);
$baseDir = __DIR__;
if (substr($baseDir, -strlen($thisClass)) === $thisClass) {
$baseDir = substr($baseDir, 0, -strlen($thisClass));
}
$className = ltrim($className, '\\');
// echo "class " . $className;
// echo '<br/>';
$fileName = (dirname($baseDir)) . DIRECTORY_SEPARATOR;
// echo "file " . $fileName;
// echo '<br/>';
if ($lastNsPos = strripos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
// echo "ns " . $namespace;
// echo '<br/>';
$className = substr($className, $lastNsPos + 1);
// echo "class " . $className;
// echo '<br/>';
$fileName .= str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
// echo "file " . $fileName;
// echo '<br/>';
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
// echo "FILE: " . $fileName;
if (file_exists($fileName)) {
require $fileName;
}
} | php | {
"resource": ""
} |
q260066 | Options.getAsXML | test | public function getAsXML()
{
// root
$this->dom = new \DOMDocument(); // reset so we don't continually to add to the options node
$root = $this->dom->createElement('options');
$root->setAttribute('xmlns', 'http://marklogic.com/appservices/search');
$this->dom->appendChild($root);
// constraints
foreach ($this->constraints as $constraint) {
$root->appendChild($constraint->getAsElem($this->dom));
}
// values
foreach ($this->values as $value) {
$root->appendChild($value->getValuesAsElem($this->dom));
}
// metadata extracts
if(isset($this->extracts)) {
$extractsElem = $this->extracts->getExtractsAsElem($this->dom);
$root->appendChild($extractsElem);
}
// transform results (snippetting)
if(isset($this->transformResults)) {
$transElem = $this->transformResults->getTransformResultsAsElem($this->dom);
$root->appendChild($transElem);
}
// term
if(isset($this->term)) {
$termElem = $this->term->getAsElem($this->dom);
$root->appendChild($termElem);
}
$this->addOptionXML($root, 'additional-query', $this->additionalQuery);
$this->addOption($root, 'concurrency-level', $this->concurrencyLevel);
$this->addOption($root, 'debug', $this->debug);
$this->addOption($root, 'forest', $this->forest);
$this->addOption($root, 'page-length', $this->pageLength);
$this->addOption($root, 'quality-weight', $this->qualityWeight);
$this->addOption($root, 'return-constraints', $this->returnConstraints);
$this->addOption($root, 'return-facets', $this->returnFacets);
$this->addOption($root, 'return-metrics', $this->returnMetrics);
$this->addOption($root, 'return-plan', $this->returnPlan);
$this->addOption($root, 'return-qtext', $this->returnQtext);
$this->addOption($root, 'return-query', $this->returnQuery);
$this->addOption($root, 'return-results', $this->returnResults);
$this->addOption($root, 'return-similar', $this->returnSimilar);
if (!empty($this->searchOptions)) {
foreach($this->searchOptions as $opt) {
$this->addOption($root, 'search-option', $this->returnSimilar);
}
}
return $this->dom->saveXML();
} | php | {
"resource": ""
} |
q260067 | Options.addOption | test | public function addOption($root, $name, $value)
{
if (isset($value)) {
$elem = $this->dom->createElement($name);
$elem->nodeValue = $value;
$root->appendChild($elem);
}
} | php | {
"resource": ""
} |
q260068 | Options.addOptionXML | test | public function addOptionXML($root, $name, $xmlString)
{
if (isset($xmlString)) {
$elem = $this->dom->createElement($name);
$xmlDoc = new \DOMDocument();
$xmlDoc->loadXML($xmlString);
// http://stackoverflow.com/questions/5783716/php-xml-dom-uncaught-exception-domexception-with-message-wrong-document-error
$elem->appendChild($this->dom->importNode($xmlDoc->documentElement, true));
$root->appendChild($elem);
}
} | php | {
"resource": ""
} |
q260069 | Options.read | test | public function read($name = null)
{
$name = $name ? $name : $this->name;
try {
$params = array('format' => 'xml');
$request = new RESTRequest('GET', 'config/query/' . $name, $params);
$response = $this->client->send($request);
return $response->getBody();
} catch(Exception $e) {
echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . PHP_EOL;
}
} | php | {
"resource": ""
} |
q260070 | Options.write | test | public function write($name = null)
{
$name = $name ? $name : $this->name;
try {
$params = array('format' => 'xml');
$headers = array('Content-type' => 'application/xml');
$request = new RESTRequest('PUT', 'config/query/' . $name, $params, $this->getAsXML(), $headers);
$this->response = $this->client->send($request);
return $this;
} catch(Exception $e) {
echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . PHP_EOL;
}
} | php | {
"resource": ""
} |
q260071 | Options.delete | test | public function delete($name)
{
$name = $name ? $name : $this->name;
try {
$request = new RESTRequest('DELETE', 'config/query/' . $name);
$this->response = $response = $this->client->send($request);
return $this;
} catch(Exception $e) {
echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . PHP_EOL;
}
} | php | {
"resource": ""
} |
q260072 | Options.setSearchOptions | test | public function setSearchOptions($searchOptions)
{
if (is_array($searchOptions)) {
$this->searchOptions = array_unique(array_merge($this->searchOptions, $searchOptions));
} else {
$this->searchOptions[] = $searchOptions;
$this->searchOptions = array_unique($this->searchOptions);
}
return $this;
} | php | {
"resource": ""
} |
q260073 | Document.read | test | public function read($uri = null, $params = array())
{
$this->uri = (isset($uri)) ? (string)$uri : $this->uri;
try {
$params = array_merge(array('uri' => $this->uri), $params);
$request = new RESTRequest('GET', 'documents', $params);
$this->response = $this->client->send($request);
$this->content = $this->response->getBody();
$this->contentType = $this->response->getContentType();
return $this->content;
} catch(\Exception $e) {
// TODO: error codes for not-found and other reasonable, unexceptional errors.
$this->logger->warning( $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() );
return false;
}
} | php | {
"resource": ""
} |
q260074 | Document.write | test | public function write($uri = null, $params = array())
{
$this->uri = (isset($uri)) ? (string)$uri : $this->uri;
try {
$params = array_merge(array('uri' => $this->uri), $params);
$headers = array();
if ($this->getContentType()) {
$headers = array('Content-type' => $this->getContentType());
}
$request = new RESTRequest('PUT', 'documents', $params, $this->content, $headers);
$this->response = $this->client->send($request);
} catch(\Exception $e) {
$this->logger->error( $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() );
throw $e;
}
return $this;
} | php | {
"resource": ""
} |
q260075 | Document.delete | test | public function delete($uri = null)
{
$this->uri = (isset($uri)) ? (string)$uri : $this->uri;
try {
$params = array('uri' => $this->uri);
$request = new RESTRequest('DELETE', 'documents', $params);
$this->response = $this->client->send($request);
} catch(\Exception $e) {
$this->logger->error( $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() );
}
return $this;
} | php | {
"resource": ""
} |
q260076 | Document.readMetadata | test | public function readMetadata()
{
try {
$params = array('uri' => $this->uri, 'category' => 'metadata');
$request = new RESTRequest('GET', 'documents', $params);
$this->response = $this->client->send($request);
$metadata = new Metadata();
$metadata->loadFromXML($this->response->getBody());
return $metadata;
} catch(\Exception $e) {
$this->logger->error( $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() );
return null;
}
} | php | {
"resource": ""
} |
q260077 | Document.writeMetadata | test | public function writeMetadata($metadata)
{
$metaxml = $metadata->getAsXML();
try {
$params = array('uri' => $this->uri, 'category' => 'metadata', 'format' => 'xml');
$headers = array('Content-type' => 'application/xml');
$request = new RESTRequest('PUT', 'documents', $params, $metaxml, $headers);
$this->response = $this->client->send($request);
} catch(\Exception $e) {
$this->logger->error( $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() );
}
return $this;
} | php | {
"resource": ""
} |
q260078 | Document.deleteMetadata | test | public function deleteMetadata()
{
try {
$params = array('uri' => $this->uri, 'category' => 'metadata');
$request = new RESTRequest('DELETE', 'documents', $params);
$this->response = $this->client->send($request);
} catch(\Exception $e) {
$this->logger->error( $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() );
}
return $this;
} | php | {
"resource": ""
} |
q260079 | Document.setContentFile | test | public function setContentFile($file)
{
try {
$content = file_get_contents((string)$file);
} catch(\Exception $e) {
$this->logger->error( $e->getMessage() );
}
$this->setContent($content);
return $this;
} | php | {
"resource": ""
} |
q260080 | Document.getFileMimeType | test | public function getFileMimeType($file)
{
if (function_exists('finfo_file')) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $file);
finfo_close($finfo);
} else if (function_exists('mime_content_type')) {
$type = mime_content_type($file);
} else {
$type = '';
}
return $type;
} | php | {
"resource": ""
} |
q260081 | Callmanager.log_soap_call | test | private function log_soap_call($CALL, $TIME, $QUERY, $REPLY)
{
array_push($this->SOAPCALLS,
[
'call' => $CALL,
'time' => $TIME,
'query' => $QUERY,
'reply' => $REPLY,
]
);
return count($this->SOAPCALLS);
} | php | {
"resource": ""
} |
q260082 | Callmanager.decode_soap_reply | test | public function decode_soap_reply($SOAPREPLY)
{
if (!is_object($SOAPREPLY)) {
throw new \Exception('SOAP reply is not an object');
}
if (!property_exists($SOAPREPLY, 'return')) {
throw new \Exception('SOAP reply does not have the property return');
}
$SOAPRETURN = $SOAPREPLY->return;
$SOAPOBJVARS = get_object_vars($SOAPRETURN);
$RETURN = reset($SOAPOBJVARS);
if (is_object($RETURN)) {
// Single objects mean we recieved exactly one element in the reply
$RETURN = [$this->object_to_assoc($RETURN)];
} else {
// Otherwise we recieved multiple elements in the reply.
$RETURN = $this->object_to_assoc($RETURN);
}
return $RETURN;
} | php | {
"resource": ""
} |
q260083 | Callmanager.assoc_key_values_to_array | test | public function assoc_key_values_to_array($ASSOC, $AKEY, $STOPONERROR = true)
{
$RETURN = [];
// Make sure its $ASSOC is an array or it errors out.
if (is_array($ASSOC)) {
// Loop through the array of key=>value pairs
foreach ($ASSOC as $KEY => $VALUE) {
if (isset($VALUE[$AKEY]) && $VALUE[$AKEY] !== '') {
if (isset($VALUE['uuid']) && $VALUE['uuid']) {
// If the query returns a UUID, use that as our array key!
$RETURN[$VALUE['uuid']] = $VALUE[$AKEY];
} else {
// If the query does NOT return a UUID, use sequencial keys
array_push($RETURN, $VALUE[$AKEY]);
}
} elseif ($STOPONERROR) {
throw new \Exception("Assoc array value does not have key {$KEY}");
}
}
}
return $RETURN;
} | php | {
"resource": ""
} |
q260084 | Callmanager.do_ldap_sync | test | public function do_ldap_sync($NAME, $BOOLEAN)
{
$SEARCH = ['name' => $NAME, 'sync' => $BOOLEAN];
// Search the CUCM for all phones
$BASETIME = $this->microtimeTicks();
$RETURN = $this->SOAPCLIENT->doLdapSync($SEARCH);
$DIFFTIME = $this->microtimeTicks() - $BASETIME;
// log our soap call
$this->log_soap_call('doLdapSync', $DIFFTIME, $SEARCH, $RETURN);
if (!is_object($RETURN)) {
throw new \Exception('SOAP reply is not an object');
} else {
return $RETURN;
}
} | php | {
"resource": ""
} |
q260085 | Callmanager.get_phone_names | test | public function get_phone_names()
{
$SEARCH = $this->axl_search_return_array(['devicePoolName' => '%'], ['name' => '']);
// Search the CUCM for all phones
$BASETIME = $this->microtimeTicks();
$RETURN = $this->SOAPCLIENT->listPhone($SEARCH);
$DIFFTIME = $this->microtimeTicks() - $BASETIME;
// log our soap call
$this->log_soap_call('listPhone', $DIFFTIME, $SEARCH, $RETURN);
// Decode the reply into an array of results
$RETURN = $this->decode_soap_reply($RETURN);
// Turn the associative arrays into a single simensional array list
$RETURN = $this->assoc_key_values_to_array($RETURN, 'name');
return $RETURN;
} | php | {
"resource": ""
} |
q260086 | Callmanager.list_all_phones_summary_by_site | test | public function list_all_phones_summary_by_site($SITE)
{
$SEARCH = $this->axl_search_return_array(['devicePoolName' => "%{$SITE}%"], [
'name' => '',
'description' => '',
'product' => '',
'callingSearchSpaceName' => '',
'devicePoolName' => '',
'locationName' => '',
'phoneTemplateName' => '',
'ownerUserName' => '',
]);
// Search the CUCM for phones from Site Device Pool
$BASETIME = $this->microtimeTicks();
$RETURN = $this->SOAPCLIENT->listPhone($SEARCH);
$DIFFTIME = $this->microtimeTicks() - $BASETIME;
// log our soap call
$this->log_soap_call('listPhone', $DIFFTIME, $SEARCH, $RETURN);
// Decode the reply into an array of results
$RETURN = $this->decode_soap_reply($RETURN);
// Turn the associative arrays into a single simensional array list
//$RETURN = $this->assoc_key_values_to_array($RETURN, 'name');
return $RETURN;
} | php | {
"resource": ""
} |
q260087 | Callmanager.phone_search_by_name | test | public function phone_search_by_name($NAME)
{
$SEARCH = $this->axl_search_return_array(['name' => "%{$NAME}%"], [
'name' => '',
'description' => '',
'product' => '',
'callingSearchSpaceName' => '',
'devicePoolName' => '',
'locationName' => '',
'phoneTemplateName' => '',
'ownerUserName' => '',
]);
// Search the CUCM for phones from Site Device Pool
$BASETIME = $this->microtimeTicks();
$RETURN = $this->SOAPCLIENT->listPhone($SEARCH);
$DIFFTIME = $this->microtimeTicks() - $BASETIME;
// log our soap call
$this->log_soap_call('listPhone', $DIFFTIME, $SEARCH, $RETURN);
// Decode the reply into an array of results
$RETURN = $this->decode_soap_reply($RETURN);
// Turn the associative arrays into a single simensional array list
//$RETURN = $this->assoc_key_values_to_array($RETURN, 'name');
return $RETURN;
} | php | {
"resource": ""
} |
q260088 | Callmanager.phone_search | test | public function phone_search($KEY, $SEARCH)
{
/*
$KEYS =
['name',
'description',
'protocol',
'callingSearchSpaceName',
'devicePoolName',
'securityProfileName']
*/
$SEARCH = $this->axl_search_return_array([$KEY => "%{$SEARCH}%"], [
'name' => '',
'description' => '',
'product' => '',
'callingSearchSpaceName' => '',
'devicePoolName' => '',
'locationName' => '',
'ownerUserName' => '',
]);
// Search the CUCM for phones from Site Device Pool
$BASETIME = $this->microtimeTicks();
$RETURN = $this->SOAPCLIENT->listPhone($SEARCH);
$DIFFTIME = $this->microtimeTicks() - $BASETIME;
// log our soap call
$this->log_soap_call('listPhone', $DIFFTIME, $SEARCH, $RETURN);
// Decode the reply into an array of results
$RETURN = $this->decode_soap_reply($RETURN);
// Turn the associative arrays into a single simensional array list
//$RETURN = $this->assoc_key_values_to_array($RETURN, 'name');
return $RETURN;
} | php | {
"resource": ""
} |
q260089 | Callmanager.get_phone_by_name | test | public function get_phone_by_name($NAME)
{
$SEARCH = ['name' => $NAME];
$BASETIME = $this->microtimeTicks();
$RETURN = $this->SOAPCLIENT->getPhone($SEARCH);
$DIFFTIME = $this->microtimeTicks() - $BASETIME;
// log our soap call
$this->log_soap_call('getPhone', $DIFFTIME, $SEARCH, $RETURN);
// Decode the reply into an array of results
$RETURN = $this->decode_soap_reply($RETURN);
// Count the number of replies we recieved...
$COUNT = count($RETURN);
// It should be EXACTLY one result
if ($COUNT !== 1) {
throw new \Exception("Search returned {$COUNT} results, not exactly 1 as expected");
}
// Strip off the outer array
$RETURN = reset($RETURN);
return $RETURN;
} | php | {
"resource": ""
} |
q260090 | Callmanager.get_directory_numbers_by_name | test | public function get_directory_numbers_by_name($NAME)
{
// Get our phone by name from the previous function
$PHONE = $this->get_phone_by_name($NAME);
if (!isset($PHONE['lines'])) {
throw new \Exception('Phone record does not contain the lines element');
}
if (!is_array($PHONE['lines'])) {
throw new \Exception('Phone record lines element is not an array');
}
// Suck out the array of phone numbers
$RETURN = reset($PHONE['lines']);
// Turn them into a flat array of DIRNs
$RETURN = $this->assoc_key_values_to_array($RETURN, 'dirn');
// Turn the DIRNs into patterns of phone numbers
$RETURN = $this->assoc_key_values_to_array($RETURN, 'pattern');
return $RETURN;
} | php | {
"resource": ""
} |
q260091 | Callmanager.get_device_pool_names | test | public function get_device_pool_names()
{
$SEARCH = $this->axl_search_return_array(['name' => '%'], ['name' => '']);
// Search the CUCM for all device pools
$BASETIME = $this->microtimeTicks();
$RETURN = $this->SOAPCLIENT->listDevicePool($SEARCH);
$DIFFTIME = $this->microtimeTicks() - $BASETIME;
// log our soap call
$this->log_soap_call('listDevicePool', $DIFFTIME, $SEARCH, $RETURN);
// Decode the reply into an array of results
$RETURN = $this->decode_soap_reply($RETURN);
// Turn the associative arrays into a single simensional array list
$RETURN = $this->assoc_key_values_to_array($RETURN, 'name');
return $RETURN;
} | php | {
"resource": ""
} |
q260092 | Callmanager.get_site_names | test | public function get_site_names()
{
// Get the list of device pools
$DEVICEPOOLS = $this->get_device_pool_names();
$SITES = [];
// Loop through all of the device pools
foreach ($DEVICEPOOLS as $DP) {
// Detect the DP_SITECODE format and put it into an array
$REGEX = "/^DP_(\w+)/";
if (preg_match($REGEX, $DP, $HITS)) {
array_push($SITES, $HITS[1]);
} else {
//print "{$DP} did not match {$REGEX}!<br>\n";
}
}
// Return our array of sites
return $SITES;
} | php | {
"resource": ""
} |
q260093 | Callmanager.get_lines_by_site | test | public function get_lines_by_site($SITE)
{
// Get all the phone object uuid=>names for a given site (based on device pool)
$PHONES = $this->get_object_type_by_site($SITE, 'Phone');
$LINES = [];
// Loop through our phones at a site and use the UUID to get its detailed object information
foreach ($PHONES as $UUID => $NAME) {
$PHONE = $this->get_object_type_by_uuid($UUID, 'Phone');
// if there are lines in the phone go get the uuid and name for each line dirn
if (isset($PHONE['lines']) && is_array($PHONE['lines']) && count($PHONE['lines'])) {
// loop through each line on the phone and suck out the uuid and dial pattern
foreach ($PHONE['lines'] as $PHONELINE) {
// If the phone has a dirn element with elements
if (isset($PHONELINE['dirn']) && is_array($PHONELINE['dirn']) && count($PHONELINE['dirn'])) {
// And the dirn has a uuid and pattern with value
if (isset($PHONELINE['dirn']['pattern']) && $PHONELINE['dirn']['pattern'] && isset($PHONELINE['dirn']['uuid']) && $PHONELINE['dirn']['uuid']) {
// Save this line to the list of site lines we return
$LINES[$PHONELINE['dirn']['uuid']] = $PHONELINE['dirn']['pattern'];
}
}
}
}
}
return $LINES;
} | php | {
"resource": ""
} |
q260094 | Callmanager.get_lines_details_by_phone_name | test | public function get_lines_details_by_phone_name($NAME)
{
// Get all the phone object uuid=>names for a given site (based on device pool)
$LINES = [];
// get phone Line detailed object information
$PHONE = $this->get_object_type_by_name($NAME, 'Phone');
// if there are lines in the phone go get the uuid and name for each line dirn
if (isset($PHONE['lines']) && is_array($PHONE['lines']) && count($PHONE['lines'])) {
// loop through each line on the phone and suck out the uuid and dial pattern
foreach ($PHONE['lines'] as $PHONELINE) {
if (isset($PHONELINE['dirn']['pattern']) && $PHONELINE['dirn']['pattern'] && isset($PHONELINE['dirn']['uuid']) && $PHONELINE['dirn']['uuid']) {
// Phone has single linee
$UUID = $PHONELINE['dirn']['uuid'];
$LINE = $this->get_object_type_by_uuid($UUID, 'Line');
$LINES[$PHONELINE['dirn']['uuid']] = $LINE;
} else {
// Phone has multiple lines
foreach ($PHONELINE as $SUBLINE) {
if (isset($SUBLINE['dirn']['pattern']) && $SUBLINE['dirn']['pattern'] && isset($SUBLINE['dirn']['uuid']) && $SUBLINE['dirn']['uuid']) {
// Save this line to the list of site lines we return
//$LINES[$SUBLINE['dirn']['uuid']] = $SUBLINE['dirn']['pattern'];
$UUID = $SUBLINE['dirn']['uuid'];
$LINE = $this->get_object_type_by_uuid($UUID, 'Line');
$LINES[$SUBLINE['dirn']['uuid']] = $LINE;
}
}
}
}
}
return $LINES;
} | php | {
"resource": ""
} |
q260095 | Callmanager.get_all_object_types_by_site | test | public function get_all_object_types_by_site($SITE)
{
// Get our valid object types
$TYPES = $this->object_types();
// Do not get these objects by site. - They need to be requested directly.
$DISCARD_TYPES = [
'Phone',
'Line',
//'CtiRoutePoint',
];
$RETURN = [];
foreach ($TYPES as $TYPE) {
if (in_array($TYPE, $DISCARD_TYPES)) {
continue;
}
if (php_sapi_name() === 'cli') {
//print "Getting {$SITE}s {$TYPE}...".PHP_EOL;
}
/*
if ($TYPE == 'Line') {
continue;
}*/
try {
$RETURN[$TYPE] = $this->get_object_type_by_site($SITE, $TYPE);
} catch (\Exception $E) {
$RETURN[$TYPE] = [];
}
}
return $RETURN;
} | php | {
"resource": ""
} |
q260096 | Callmanager.get_object_type_by_name | test | public function get_object_type_by_name($NAME, $TYPE)
{
// Get our valid object types
$TYPES = $this->object_types();
// TransPattern is not valid for get-item-by-NAME, must use UUID or a combination of name and routepartitionname
$TYPES = array_diff($TYPES, ['TransPattern']);
// Lines is not valid for get-item-by-name, must be UUID
$TYPES = array_diff($TYPES, ['Line']);
// Check to see if the one we were passed is valid for this function
if (!in_array($TYPE, $TYPES)) {
throw new \Exception("Object type provided {$TYPE} is not supported");
}
$QUERY = ['name' => $NAME];
$FUNCTION = 'get'.$TYPE;
$BASETIME = $this->microtimeTicks();
$RETURN = $this->SOAPCLIENT->$FUNCTION($QUERY);
$DIFFTIME = $this->microtimeTicks() - $BASETIME;
$this->log_soap_call($FUNCTION, $DIFFTIME, $QUERY, $RETURN);
$RETURN = $this->decode_soap_reply($RETURN);
$RETURN = reset($RETURN);
return $RETURN;
} | php | {
"resource": ""
} |
q260097 | Callmanager.delete_object_type_by_uuid | test | public function delete_object_type_by_uuid($UUID, $TYPE)
{
// Get our valid object types
$TYPES = $this->object_types();
// Check to see if the one we were passed is valid for this function
if (!in_array($TYPE, $TYPES)) {
throw new \Exception("Object type provided {$TYPE} is not supported");
}
$QUERY = ['uuid' => $UUID];
$FUNCTION = 'remove'.$TYPE;
$BASETIME = $this->microtimeTicks();
$RETURN = $this->SOAPCLIENT->$FUNCTION($QUERY);
$DIFFTIME = $this->microtimeTicks() - $BASETIME;
$this->log_soap_call($FUNCTION, $DIFFTIME, $QUERY, $RETURN);
return $RETURN;
} | php | {
"resource": ""
} |
q260098 | Permission.addCapabilities | test | public function addCapabilities($capabilities)
{
if (is_array($capabilities)) {
$this->capabilities = array_merge((array)$this->capabilities, (array)$capabilities);
} else {
$this->capabilities[] = (string)$capabilities;
}
} | php | {
"resource": ""
} |
q260099 | IPhoneImageDocument.getLatitude | test | public function getLatitude()
{
if (isset($this->exif)) {
return (float)$this->getGps($this->exif['GPSLatitude'], $this->exif['GPSLatitudeRef']);
} else {
return null;
}
} | php | {
"resource": ""
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.