id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
29,800
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getIds
public function getIds(): array { $this->loadMetadata(); $ids = array(); foreach ($this->metadata->allResources(RC::idProp()) as $i) { $ids[] = $i->getUri(); } return $ids; }
php
public function getIds(): array { $this->loadMetadata(); $ids = array(); foreach ($this->metadata->allResources(RC::idProp()) as $i) { $ids[] = $i->getUri(); } return $ids; }
[ "public", "function", "getIds", "(", ")", ":", "array", "{", "$", "this", "->", "loadMetadata", "(", ")", ";", "$", "ids", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "metadata", "->", "allResources", "(", "RC", "::", "idProp", "(", ")", ")", "as", "$", "i", ")", "{", "$", "ids", "[", "]", "=", "$", "i", "->", "getUri", "(", ")", ";", "}", "return", "$", "ids", ";", "}" ]
Returns an array of resource's IDs. If you want to get an ACDH ID, use the getId() method. @return array @see getId()
[ "Returns", "an", "array", "of", "resource", "s", "IDs", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L205-L212
29,801
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.delete
public function delete(bool $deep = false, bool $children = false, bool $references = false) { $this->uri = $this->fedora->sanitizeUri($this->getUri()); $fedoraChildren = $this->getMetadata()->allResources(self::CONTAINS_PROP); if (count($fedoraChildren) > 0) { throw new RuntimeException("A resource has Fedora children"); } $request = new Request('DELETE', $this->uri); $this->fedora->sendRequest($request); $this->fedora->getCache()->delete($this); if ($deep) { $request = new Request('DELETE', $this->uri . '/fcr:tombstone'); $this->fedora->sendRequest($request); } try { $this->getAcl()->deleteAcl(); } catch (NotFound $e) { } catch (Deleted $e) { } if ($children) { foreach ($this->getChildren() as $i) { $i->delete($deep, $children, $references); } } if ($references) { $id = $this->getId(); $query = new SimpleQuery('SELECT * WHERE {?res ?prop ?@}'); $query->setValues(array($id)); $results = $this->fedora->runQuery($query); foreach ($results as $i) { try { $res = $this->fedora->getResourceByUri($i->res); $meta = $res->getMetadata(); foreach ($meta->propertyUris() as $prop) { $meta->deleteResource($prop, $id); } $res->setMetadata($meta); $res->updateMetadata(self::OVERWRITE); } catch (Deleted $e) { } catch (NotFound $e) { } } } }
php
public function delete(bool $deep = false, bool $children = false, bool $references = false) { $this->uri = $this->fedora->sanitizeUri($this->getUri()); $fedoraChildren = $this->getMetadata()->allResources(self::CONTAINS_PROP); if (count($fedoraChildren) > 0) { throw new RuntimeException("A resource has Fedora children"); } $request = new Request('DELETE', $this->uri); $this->fedora->sendRequest($request); $this->fedora->getCache()->delete($this); if ($deep) { $request = new Request('DELETE', $this->uri . '/fcr:tombstone'); $this->fedora->sendRequest($request); } try { $this->getAcl()->deleteAcl(); } catch (NotFound $e) { } catch (Deleted $e) { } if ($children) { foreach ($this->getChildren() as $i) { $i->delete($deep, $children, $references); } } if ($references) { $id = $this->getId(); $query = new SimpleQuery('SELECT * WHERE {?res ?prop ?@}'); $query->setValues(array($id)); $results = $this->fedora->runQuery($query); foreach ($results as $i) { try { $res = $this->fedora->getResourceByUri($i->res); $meta = $res->getMetadata(); foreach ($meta->propertyUris() as $prop) { $meta->deleteResource($prop, $id); } $res->setMetadata($meta); $res->updateMetadata(self::OVERWRITE); } catch (Deleted $e) { } catch (NotFound $e) { } } } }
[ "public", "function", "delete", "(", "bool", "$", "deep", "=", "false", ",", "bool", "$", "children", "=", "false", ",", "bool", "$", "references", "=", "false", ")", "{", "$", "this", "->", "uri", "=", "$", "this", "->", "fedora", "->", "sanitizeUri", "(", "$", "this", "->", "getUri", "(", ")", ")", ";", "$", "fedoraChildren", "=", "$", "this", "->", "getMetadata", "(", ")", "->", "allResources", "(", "self", "::", "CONTAINS_PROP", ")", ";", "if", "(", "count", "(", "$", "fedoraChildren", ")", ">", "0", ")", "{", "throw", "new", "RuntimeException", "(", "\"A resource has Fedora children\"", ")", ";", "}", "$", "request", "=", "new", "Request", "(", "'DELETE'", ",", "$", "this", "->", "uri", ")", ";", "$", "this", "->", "fedora", "->", "sendRequest", "(", "$", "request", ")", ";", "$", "this", "->", "fedora", "->", "getCache", "(", ")", "->", "delete", "(", "$", "this", ")", ";", "if", "(", "$", "deep", ")", "{", "$", "request", "=", "new", "Request", "(", "'DELETE'", ",", "$", "this", "->", "uri", ".", "'/fcr:tombstone'", ")", ";", "$", "this", "->", "fedora", "->", "sendRequest", "(", "$", "request", ")", ";", "}", "try", "{", "$", "this", "->", "getAcl", "(", ")", "->", "deleteAcl", "(", ")", ";", "}", "catch", "(", "NotFound", "$", "e", ")", "{", "}", "catch", "(", "Deleted", "$", "e", ")", "{", "}", "if", "(", "$", "children", ")", "{", "foreach", "(", "$", "this", "->", "getChildren", "(", ")", "as", "$", "i", ")", "{", "$", "i", "->", "delete", "(", "$", "deep", ",", "$", "children", ",", "$", "references", ")", ";", "}", "}", "if", "(", "$", "references", ")", "{", "$", "id", "=", "$", "this", "->", "getId", "(", ")", ";", "$", "query", "=", "new", "SimpleQuery", "(", "'SELECT * WHERE {?res ?prop ?@}'", ")", ";", "$", "query", "->", "setValues", "(", "array", "(", "$", "id", ")", ")", ";", "$", "results", "=", "$", "this", "->", "fedora", "->", "runQuery", "(", "$", "query", ")", ";", "foreach", "(", "$", "results", "as", "$", "i", ")", "{", "try", "{", "$", "res", "=", "$", "this", "->", "fedora", "->", "getResourceByUri", "(", "$", "i", "->", "res", ")", ";", "$", "meta", "=", "$", "res", "->", "getMetadata", "(", ")", ";", "foreach", "(", "$", "meta", "->", "propertyUris", "(", ")", "as", "$", "prop", ")", "{", "$", "meta", "->", "deleteResource", "(", "$", "prop", ",", "$", "id", ")", ";", "}", "$", "res", "->", "setMetadata", "(", "$", "meta", ")", ";", "$", "res", "->", "updateMetadata", "(", "self", "::", "OVERWRITE", ")", ";", "}", "catch", "(", "Deleted", "$", "e", ")", "{", "}", "catch", "(", "NotFound", "$", "e", ")", "{", "}", "}", "}", "}" ]
Removes the resource from the Fedora. Please remember searching for children and references is done using a SPARQL query so any changes made since the beginning of the transaction won't be taken into account. @param bool $deep should tombstone resource will be deleted? @param bool $children should children be removed? @param bool $references should references to the resource be removed? (applies also for children when `$children == true`)
[ "Removes", "the", "resource", "from", "the", "Fedora", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L234-L284
29,802
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.move
public function move(string $destination): Response { $uri = $this->fedora->sanitizeUri($this->uri); $destination = $this->fedora->sanitizeUri($destination); $request = new Request('MOVE', $uri, ['Destination' => $destination]); $response = $this->fedora->sendRequest($request); $cache = $this->fedora->getCache(); $cache->deleteById($this->getId()); $cache->add($this); return $response; }
php
public function move(string $destination): Response { $uri = $this->fedora->sanitizeUri($this->uri); $destination = $this->fedora->sanitizeUri($destination); $request = new Request('MOVE', $uri, ['Destination' => $destination]); $response = $this->fedora->sendRequest($request); $cache = $this->fedora->getCache(); $cache->deleteById($this->getId()); $cache->add($this); return $response; }
[ "public", "function", "move", "(", "string", "$", "destination", ")", ":", "Response", "{", "$", "uri", "=", "$", "this", "->", "fedora", "->", "sanitizeUri", "(", "$", "this", "->", "uri", ")", ";", "$", "destination", "=", "$", "this", "->", "fedora", "->", "sanitizeUri", "(", "$", "destination", ")", ";", "$", "request", "=", "new", "Request", "(", "'MOVE'", ",", "$", "uri", ",", "[", "'Destination'", "=>", "$", "destination", "]", ")", ";", "$", "response", "=", "$", "this", "->", "fedora", "->", "sendRequest", "(", "$", "request", ")", ";", "$", "cache", "=", "$", "this", "->", "fedora", "->", "getCache", "(", ")", ";", "$", "cache", "->", "deleteById", "(", "$", "this", "->", "getId", "(", ")", ")", ";", "$", "cache", "->", "add", "(", "$", "this", ")", ";", "return", "$", "response", ";", "}" ]
Moves resource to another location. @param string $destination new location
[ "Moves", "resource", "to", "another", "location", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L291-L300
29,803
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getFixity
public function getFixity(): string { $uri = $this->fedora->sanitizeUri($this->uri); $request = new Request('GET', $uri . '/fcr:fixity'); $resp = $this->fedora->sendRequest($request); $graph = new Graph(); $graph->parse($resp->getBody()); $res = $graph->resource($uri); $fixityRes = $graph->resource($res->getResource('http://www.loc.gov/premis/rdf/v1#hasFixity')); $fixity = $fixityRes->getResource('http://www.loc.gov/premis/rdf/v1#hasMessageDigest'); return $fixity->getUri(); }
php
public function getFixity(): string { $uri = $this->fedora->sanitizeUri($this->uri); $request = new Request('GET', $uri . '/fcr:fixity'); $resp = $this->fedora->sendRequest($request); $graph = new Graph(); $graph->parse($resp->getBody()); $res = $graph->resource($uri); $fixityRes = $graph->resource($res->getResource('http://www.loc.gov/premis/rdf/v1#hasFixity')); $fixity = $fixityRes->getResource('http://www.loc.gov/premis/rdf/v1#hasMessageDigest'); return $fixity->getUri(); }
[ "public", "function", "getFixity", "(", ")", ":", "string", "{", "$", "uri", "=", "$", "this", "->", "fedora", "->", "sanitizeUri", "(", "$", "this", "->", "uri", ")", ";", "$", "request", "=", "new", "Request", "(", "'GET'", ",", "$", "uri", ".", "'/fcr:fixity'", ")", ";", "$", "resp", "=", "$", "this", "->", "fedora", "->", "sendRequest", "(", "$", "request", ")", ";", "$", "graph", "=", "new", "Graph", "(", ")", ";", "$", "graph", "->", "parse", "(", "$", "resp", "->", "getBody", "(", ")", ")", ";", "$", "res", "=", "$", "graph", "->", "resource", "(", "$", "uri", ")", ";", "$", "fixityRes", "=", "$", "graph", "->", "resource", "(", "$", "res", "->", "getResource", "(", "'http://www.loc.gov/premis/rdf/v1#hasFixity'", ")", ")", ";", "$", "fixity", "=", "$", "fixityRes", "->", "getResource", "(", "'http://www.loc.gov/premis/rdf/v1#hasMessageDigest'", ")", ";", "return", "$", "fixity", "->", "getUri", "(", ")", ";", "}" ]
Returns resource fixity. @throws Deleted @throws NotFound @throws RequestException
[ "Returns", "resource", "fixity", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L308-L319
29,804
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.setMetadata
public function setMetadata(Resource $metadata, bool $fixReferences = false) { $this->metadata = $metadata; $this->updated = false; $this->extractAclFromMetadata(); $this->fedora->getCache()->reload($this); if ($fixReferences) { $this->fedora->fixMetadataReferences($this->metadata); } }
php
public function setMetadata(Resource $metadata, bool $fixReferences = false) { $this->metadata = $metadata; $this->updated = false; $this->extractAclFromMetadata(); $this->fedora->getCache()->reload($this); if ($fixReferences) { $this->fedora->fixMetadataReferences($this->metadata); } }
[ "public", "function", "setMetadata", "(", "Resource", "$", "metadata", ",", "bool", "$", "fixReferences", "=", "false", ")", "{", "$", "this", "->", "metadata", "=", "$", "metadata", ";", "$", "this", "->", "updated", "=", "false", ";", "$", "this", "->", "extractAclFromMetadata", "(", ")", ";", "$", "this", "->", "fedora", "->", "getCache", "(", ")", "->", "reload", "(", "$", "this", ")", ";", "if", "(", "$", "fixReferences", ")", "{", "$", "this", "->", "fedora", "->", "fixMetadataReferences", "(", "$", "this", "->", "metadata", ")", ";", "}", "}" ]
Replaces resource metadata with a given RDF graph. New metadata are not automatically written back to the Fedora. Use the updateMetadata() method to write them back. @param EasyRdf\Resource $metadata @param bool $fixReferences Should reference to other repository resources be switched into corresponding UUIDs? @see updateMetadata()
[ "Replaces", "resource", "metadata", "with", "a", "given", "RDF", "graph", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L332-L343
29,805
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getMetadata
public function getMetadata(bool $force = false): Resource { $this->loadMetadata($force); return $this->metadata->copy(); }
php
public function getMetadata(bool $force = false): Resource { $this->loadMetadata($force); return $this->metadata->copy(); }
[ "public", "function", "getMetadata", "(", "bool", "$", "force", "=", "false", ")", ":", "Resource", "{", "$", "this", "->", "loadMetadata", "(", "$", "force", ")", ";", "return", "$", "this", "->", "metadata", "->", "copy", "(", ")", ";", "}" ]
Returns resource metadata. Fetches them from the Fedora if they were not fetched already. A deep copy of metadata is returned meaning adjusting the returned object does not automatically affect the resource metadata. Use the setMetadata() method to write back the changes you made. @param bool $force enforce fetch from Fedora (when you want to make sure metadata are in line with ones in the Fedora or e.g. reset them back to their current state in Fedora) @return \EasyRdf\Resource @see updateMetadata() @see setMetadata()
[ "Returns", "resource", "metadata", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L435-L438
29,806
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.loadMetadata
protected function loadMetadata(bool $force = false) { if (!$this->metadata || $force) { $meta = $this->getMetadataFromFedora(); if (count($meta->propertyUris()) === 0) { throw new RuntimeException('No resource metadata. Please check a value of the fedoraApiUrl configuration property.'); } $this->setMetadata($meta); } }
php
protected function loadMetadata(bool $force = false) { if (!$this->metadata || $force) { $meta = $this->getMetadataFromFedora(); if (count($meta->propertyUris()) === 0) { throw new RuntimeException('No resource metadata. Please check a value of the fedoraApiUrl configuration property.'); } $this->setMetadata($meta); } }
[ "protected", "function", "loadMetadata", "(", "bool", "$", "force", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "metadata", "||", "$", "force", ")", "{", "$", "meta", "=", "$", "this", "->", "getMetadataFromFedora", "(", ")", ";", "if", "(", "count", "(", "$", "meta", "->", "propertyUris", "(", ")", ")", "===", "0", ")", "{", "throw", "new", "RuntimeException", "(", "'No resource metadata. Please check a value of the fedoraApiUrl configuration property.'", ")", ";", "}", "$", "this", "->", "setMetadata", "(", "$", "meta", ")", ";", "}", "}" ]
Loads current metadata from the Fedora. @param bool $force enforce fetch from Fedora (when you want to make sure metadata are in line with ones in the Fedora or e.g. reset them back to their current state in Fedora)
[ "Loads", "current", "metadata", "from", "the", "Fedora", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L447-L457
29,807
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getMetadataFromFedora
private function getMetadataFromFedora(): Resource { $uri = $this->fedora->sanitizeUri($this->uri); $request = new Request('GET', $uri . '/fcr:metadata', ['Accept' => 'application/n-triples']); $resp = $this->fedora->sendRequest($request); $format = ''; $headers = $resp->getHeaders(); if (isset($headers['Content-Type'])) { $format = explode(';', $headers['Content-Type'][0])[0]; } $this->extractAcl($resp); $graph = new Graph(); $graph->parse($resp->getBody(), $format); $meta = $graph->resource($uri); return $meta; }
php
private function getMetadataFromFedora(): Resource { $uri = $this->fedora->sanitizeUri($this->uri); $request = new Request('GET', $uri . '/fcr:metadata', ['Accept' => 'application/n-triples']); $resp = $this->fedora->sendRequest($request); $format = ''; $headers = $resp->getHeaders(); if (isset($headers['Content-Type'])) { $format = explode(';', $headers['Content-Type'][0])[0]; } $this->extractAcl($resp); $graph = new Graph(); $graph->parse($resp->getBody(), $format); $meta = $graph->resource($uri); return $meta; }
[ "private", "function", "getMetadataFromFedora", "(", ")", ":", "Resource", "{", "$", "uri", "=", "$", "this", "->", "fedora", "->", "sanitizeUri", "(", "$", "this", "->", "uri", ")", ";", "$", "request", "=", "new", "Request", "(", "'GET'", ",", "$", "uri", ".", "'/fcr:metadata'", ",", "[", "'Accept'", "=>", "'application/n-triples'", "]", ")", ";", "$", "resp", "=", "$", "this", "->", "fedora", "->", "sendRequest", "(", "$", "request", ")", ";", "$", "format", "=", "''", ";", "$", "headers", "=", "$", "resp", "->", "getHeaders", "(", ")", ";", "if", "(", "isset", "(", "$", "headers", "[", "'Content-Type'", "]", ")", ")", "{", "$", "format", "=", "explode", "(", "';'", ",", "$", "headers", "[", "'Content-Type'", "]", "[", "0", "]", ")", "[", "0", "]", ";", "}", "$", "this", "->", "extractAcl", "(", "$", "resp", ")", ";", "$", "graph", "=", "new", "Graph", "(", ")", ";", "$", "graph", "->", "parse", "(", "$", "resp", "->", "getBody", "(", ")", ",", "$", "format", ")", ";", "$", "meta", "=", "$", "graph", "->", "resource", "(", "$", "uri", ")", ";", "return", "$", "meta", ";", "}" ]
Fetches metadata from Fedora. @return Resource @throws RequestException @throws Deleted
[ "Fetches", "metadata", "from", "Fedora", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L465-L482
29,808
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getContent
public function getContent(): Response { $uri = $this->fedora->sanitizeUri($this->uri); $request = new Request('GET', $uri); return $this->fedora->sendRequest($request); }
php
public function getContent(): Response { $uri = $this->fedora->sanitizeUri($this->uri); $request = new Request('GET', $uri); return $this->fedora->sendRequest($request); }
[ "public", "function", "getContent", "(", ")", ":", "Response", "{", "$", "uri", "=", "$", "this", "->", "fedora", "->", "sanitizeUri", "(", "$", "this", "->", "uri", ")", ";", "$", "request", "=", "new", "Request", "(", "'GET'", ",", "$", "uri", ")", ";", "return", "$", "this", "->", "fedora", "->", "sendRequest", "(", "$", "request", ")", ";", "}" ]
Returns resource's binary content. @return Response PSR-7 response containing resource's binary content
[ "Returns", "resource", "s", "binary", "content", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L488-L492
29,809
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.updateContent
public function updateContent($data, bool $convert = false) { if (empty($data)) { return; } $this->loadMetadata(); if ($this->isA('http://www.w3.org/ns/ldp#NonRDFSource')) { $request = new Request('PUT', $this->getUri()); $request = Fedora::attachData($request, $data); $this->fedora->sendRequest($request); } else if ($convert) { $aclRules = $this->getAcl()->getRules(false); $this->uri = $this->fedora->sanitizeUri($this->uri); $this->delete(true); $newRes = $this->fedora->createResource($this->metadata, $data, $this->uri, 'PUT'); $this->uri = $newRes->getUri(); // restore acl rules foreach ($aclRules as $rule) { $rule->save(); } } else { throw new RuntimeException('Resource is not a binary one. Turn on the $convert parameter if you are sure what you are doing.'); } $this->loadMetadata(true); }
php
public function updateContent($data, bool $convert = false) { if (empty($data)) { return; } $this->loadMetadata(); if ($this->isA('http://www.w3.org/ns/ldp#NonRDFSource')) { $request = new Request('PUT', $this->getUri()); $request = Fedora::attachData($request, $data); $this->fedora->sendRequest($request); } else if ($convert) { $aclRules = $this->getAcl()->getRules(false); $this->uri = $this->fedora->sanitizeUri($this->uri); $this->delete(true); $newRes = $this->fedora->createResource($this->metadata, $data, $this->uri, 'PUT'); $this->uri = $newRes->getUri(); // restore acl rules foreach ($aclRules as $rule) { $rule->save(); } } else { throw new RuntimeException('Resource is not a binary one. Turn on the $convert parameter if you are sure what you are doing.'); } $this->loadMetadata(true); }
[ "public", "function", "updateContent", "(", "$", "data", ",", "bool", "$", "convert", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "return", ";", "}", "$", "this", "->", "loadMetadata", "(", ")", ";", "if", "(", "$", "this", "->", "isA", "(", "'http://www.w3.org/ns/ldp#NonRDFSource'", ")", ")", "{", "$", "request", "=", "new", "Request", "(", "'PUT'", ",", "$", "this", "->", "getUri", "(", ")", ")", ";", "$", "request", "=", "Fedora", "::", "attachData", "(", "$", "request", ",", "$", "data", ")", ";", "$", "this", "->", "fedora", "->", "sendRequest", "(", "$", "request", ")", ";", "}", "else", "if", "(", "$", "convert", ")", "{", "$", "aclRules", "=", "$", "this", "->", "getAcl", "(", ")", "->", "getRules", "(", "false", ")", ";", "$", "this", "->", "uri", "=", "$", "this", "->", "fedora", "->", "sanitizeUri", "(", "$", "this", "->", "uri", ")", ";", "$", "this", "->", "delete", "(", "true", ")", ";", "$", "newRes", "=", "$", "this", "->", "fedora", "->", "createResource", "(", "$", "this", "->", "metadata", ",", "$", "data", ",", "$", "this", "->", "uri", ",", "'PUT'", ")", ";", "$", "this", "->", "uri", "=", "$", "newRes", "->", "getUri", "(", ")", ";", "// restore acl rules", "foreach", "(", "$", "aclRules", "as", "$", "rule", ")", "{", "$", "rule", "->", "save", "(", ")", ";", "}", "}", "else", "{", "throw", "new", "RuntimeException", "(", "'Resource is not a binary one. Turn on the $convert parameter if you are sure what you are doing.'", ")", ";", "}", "$", "this", "->", "loadMetadata", "(", "true", ")", ";", "}" ]
Updates resource binary content in the Fedora. If the resource is not a binary resource (in Fedora terms), it can be converted. This means the existing Fedora resource will be deleted and the new one will be created. This means the resource will change its Fedora URI but the id property indicated by the "fedoraIdProp" config option (see init()) will be preserved. This means until you are using the id property values (and not Fedora URIs) to denote resources in your metadata, your metadata consistency will be preserved. @param mixed $data resource data as a string, file name or an array: ['contentType' => 'foo', 'data' => 'bar', 'filename' => 'baz.txt'] @param bool $convert if metadata-only resource be automatically converted to a binary one @throws \DomainException @see init()
[ "Updates", "resource", "binary", "content", "in", "the", "Fedora", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L514-L537
29,810
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getFedoraChildren
public function getFedoraChildren(): array { $children = []; foreach ($this->getMetadata()->allResources(self::CONTAINS_PROP) as $i) { $children[] = $this->fedora->getResourceByUri($i->getUri()); } return $children; }
php
public function getFedoraChildren(): array { $children = []; foreach ($this->getMetadata()->allResources(self::CONTAINS_PROP) as $i) { $children[] = $this->fedora->getResourceByUri($i->getUri()); } return $children; }
[ "public", "function", "getFedoraChildren", "(", ")", ":", "array", "{", "$", "children", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getMetadata", "(", ")", "->", "allResources", "(", "self", "::", "CONTAINS_PROP", ")", "as", "$", "i", ")", "{", "$", "children", "[", "]", "=", "$", "this", "->", "fedora", "->", "getResourceByUri", "(", "$", "i", "->", "getUri", "(", ")", ")", ";", "}", "return", "$", "children", ";", "}" ]
Returns all resource's Fedora children. A Fedora child is a resource pointed by the ldp:contains triple. All Fedora children URIs are nested in the parent's URI path but the deepness of such nesting can vary (e.g. both http://a/b and http://a/b/c/d can be Fedora children of the http://a depenging on how they were created). Fedora's parent-child relation is automatically maintained by the Fedora and depends on the way Fedora resources are created. @return array
[ "Returns", "all", "resource", "s", "Fedora", "children", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L612-L618
29,811
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getChildrenByProperty
public function getChildrenByProperty(string $property, string $value = ''): array { $query = $this->getChildrenQuery(); if ($value != '') { $param = new HasValue($property, $value); } else { $param = new HasProperty($property); } $query->addParameter($param); return $this->fedora->getResourcesByQuery($query); }
php
public function getChildrenByProperty(string $property, string $value = ''): array { $query = $this->getChildrenQuery(); if ($value != '') { $param = new HasValue($property, $value); } else { $param = new HasProperty($property); } $query->addParameter($param); return $this->fedora->getResourcesByQuery($query); }
[ "public", "function", "getChildrenByProperty", "(", "string", "$", "property", ",", "string", "$", "value", "=", "''", ")", ":", "array", "{", "$", "query", "=", "$", "this", "->", "getChildrenQuery", "(", ")", ";", "if", "(", "$", "value", "!=", "''", ")", "{", "$", "param", "=", "new", "HasValue", "(", "$", "property", ",", "$", "value", ")", ";", "}", "else", "{", "$", "param", "=", "new", "HasProperty", "(", "$", "property", ")", ";", "}", "$", "query", "->", "addParameter", "(", "$", "param", ")", ";", "return", "$", "this", "->", "fedora", "->", "getResourcesByQuery", "(", "$", "query", ")", ";", "}" ]
Returns all resource's children having a given property or a given value of a given property. It is assumed that child-parent relations are denoted by: `child -> config::relProp -> id <- config::idProp <- parent` metadata properties scheme. @param string $property fully qualified URI of the property @param string $value property value (optional) @return array
[ "Returns", "all", "resource", "s", "children", "having", "a", "given", "property", "or", "a", "given", "value", "of", "a", "given", "property", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L645-L654
29,812
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getChildrenByPropertyRegEx
public function getChildrenByPropertyRegEx(string $property, string $regEx, string $flags = 'i'): array { $query = $this->getChildrenQuery(); $query->addParameter(new MatchesRegEx($property, $regEx, $flags)); return $this->fedora->getResourcesByQuery($query); }
php
public function getChildrenByPropertyRegEx(string $property, string $regEx, string $flags = 'i'): array { $query = $this->getChildrenQuery(); $query->addParameter(new MatchesRegEx($property, $regEx, $flags)); return $this->fedora->getResourcesByQuery($query); }
[ "public", "function", "getChildrenByPropertyRegEx", "(", "string", "$", "property", ",", "string", "$", "regEx", ",", "string", "$", "flags", "=", "'i'", ")", ":", "array", "{", "$", "query", "=", "$", "this", "->", "getChildrenQuery", "(", ")", ";", "$", "query", "->", "addParameter", "(", "new", "MatchesRegEx", "(", "$", "property", ",", "$", "regEx", ",", "$", "flags", ")", ")", ";", "return", "$", "this", "->", "fedora", "->", "getResourcesByQuery", "(", "$", "query", ")", ";", "}" ]
Returns all resource's children with a given property matching a given regular expression It is assumed that child-parent relations are denoted by: `child -> config::relProp -> id <- config::idProp <- parent` metadata properties scheme. @param string $property fully qualified URI of the property @param string $regEx regular expression to match @param string $flags regular expression flags @return array
[ "Returns", "all", "resource", "s", "children", "with", "a", "given", "property", "matching", "a", "given", "regular", "expression" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L669-L674
29,813
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getAclUrl
public function getAclUrl(bool $refresh = false): string { if ($refresh || $this->aclUrl === null) { $request = new Request('HEAD', $this->fedora->sanitizeUri($this->uri)); $response = $this->fedora->sendRequest($request); $this->extractAcl($response); // Fedora 4.7.5 doesn't provide ACL link header for binary resources // if the ACL id directly attached to the resource (sic!). // As a fallback we can try to extract it from the metadata (which // is done automatically in the setMetadata() method being called // by the getMetadata(true) method). if ($this->aclUrl == '') { $this->getMetadata(true); } } return $this->aclUrl; }
php
public function getAclUrl(bool $refresh = false): string { if ($refresh || $this->aclUrl === null) { $request = new Request('HEAD', $this->fedora->sanitizeUri($this->uri)); $response = $this->fedora->sendRequest($request); $this->extractAcl($response); // Fedora 4.7.5 doesn't provide ACL link header for binary resources // if the ACL id directly attached to the resource (sic!). // As a fallback we can try to extract it from the metadata (which // is done automatically in the setMetadata() method being called // by the getMetadata(true) method). if ($this->aclUrl == '') { $this->getMetadata(true); } } return $this->aclUrl; }
[ "public", "function", "getAclUrl", "(", "bool", "$", "refresh", "=", "false", ")", ":", "string", "{", "if", "(", "$", "refresh", "||", "$", "this", "->", "aclUrl", "===", "null", ")", "{", "$", "request", "=", "new", "Request", "(", "'HEAD'", ",", "$", "this", "->", "fedora", "->", "sanitizeUri", "(", "$", "this", "->", "uri", ")", ")", ";", "$", "response", "=", "$", "this", "->", "fedora", "->", "sendRequest", "(", "$", "request", ")", ";", "$", "this", "->", "extractAcl", "(", "$", "response", ")", ";", "// Fedora 4.7.5 doesn't provide ACL link header for binary resources", "// if the ACL id directly attached to the resource (sic!).", "// As a fallback we can try to extract it from the metadata (which", "// is done automatically in the setMetadata() method being called", "// by the getMetadata(true) method).", "if", "(", "$", "this", "->", "aclUrl", "==", "''", ")", "{", "$", "this", "->", "getMetadata", "(", "true", ")", ";", "}", "}", "return", "$", "this", "->", "aclUrl", ";", "}" ]
Returns URL of the resources' ACL collection @param bool $refresh should ACL URL be reread @return string
[ "Returns", "URL", "of", "the", "resources", "ACL", "collection" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L681-L697
29,814
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getAcl
public function getAcl(bool $refresh = true): WebAcl { if ($refresh || $this->acl === null) { $this->getAclUrl($refresh); $this->acl = new WebAcl($this); } return $this->acl; }
php
public function getAcl(bool $refresh = true): WebAcl { if ($refresh || $this->acl === null) { $this->getAclUrl($refresh); $this->acl = new WebAcl($this); } return $this->acl; }
[ "public", "function", "getAcl", "(", "bool", "$", "refresh", "=", "true", ")", ":", "WebAcl", "{", "if", "(", "$", "refresh", "||", "$", "this", "->", "acl", "===", "null", ")", "{", "$", "this", "->", "getAclUrl", "(", "$", "refresh", ")", ";", "$", "this", "->", "acl", "=", "new", "WebAcl", "(", "$", "this", ")", ";", "}", "return", "$", "this", "->", "acl", ";", "}" ]
Returns a WebAcl object for access rules manipulation. @param bool $refresh should the ACL collection and rules be refreshed or read from cache (there are many scenarios when reading requiring ACL data to be outdated so the default behaviour is to refresh) @return WebAcl
[ "Returns", "a", "WebAcl", "object", "for", "access", "rules", "manipulation", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L706-L712
29,815
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraResource.php
FedoraResource.getSparqlTriples
private function getSparqlTriples(Resource $metadata): string { $uri = $this->fedora->sanitizeUri($this->uri); $res = $metadata->copy(self::$skipProp, self::$skipPropRegExp, $uri); // make sure the ACL property is in current transaction $aclProp = $res->getResource(WebAcl::ACL_LINK_PROP); if ($aclProp) { $res->deleteResource(WebAcl::ACL_LINK_PROP); if ($aclProp->getUri() !== 'http://fedora.info/definitions/v4/repository#inaccessibleResource') { $res->addResource(WebAcl::ACL_LINK_PROP, $this->fedora->sanitizeUri($aclProp->getUri())); } } $rdf = $res->getGraph()->serialise('ntriples'); return $rdf; }
php
private function getSparqlTriples(Resource $metadata): string { $uri = $this->fedora->sanitizeUri($this->uri); $res = $metadata->copy(self::$skipProp, self::$skipPropRegExp, $uri); // make sure the ACL property is in current transaction $aclProp = $res->getResource(WebAcl::ACL_LINK_PROP); if ($aclProp) { $res->deleteResource(WebAcl::ACL_LINK_PROP); if ($aclProp->getUri() !== 'http://fedora.info/definitions/v4/repository#inaccessibleResource') { $res->addResource(WebAcl::ACL_LINK_PROP, $this->fedora->sanitizeUri($aclProp->getUri())); } } $rdf = $res->getGraph()->serialise('ntriples'); return $rdf; }
[ "private", "function", "getSparqlTriples", "(", "Resource", "$", "metadata", ")", ":", "string", "{", "$", "uri", "=", "$", "this", "->", "fedora", "->", "sanitizeUri", "(", "$", "this", "->", "uri", ")", ";", "$", "res", "=", "$", "metadata", "->", "copy", "(", "self", "::", "$", "skipProp", ",", "self", "::", "$", "skipPropRegExp", ",", "$", "uri", ")", ";", "// make sure the ACL property is in current transaction", "$", "aclProp", "=", "$", "res", "->", "getResource", "(", "WebAcl", "::", "ACL_LINK_PROP", ")", ";", "if", "(", "$", "aclProp", ")", "{", "$", "res", "->", "deleteResource", "(", "WebAcl", "::", "ACL_LINK_PROP", ")", ";", "if", "(", "$", "aclProp", "->", "getUri", "(", ")", "!==", "'http://fedora.info/definitions/v4/repository#inaccessibleResource'", ")", "{", "$", "res", "->", "addResource", "(", "WebAcl", "::", "ACL_LINK_PROP", ",", "$", "this", "->", "fedora", "->", "sanitizeUri", "(", "$", "aclProp", "->", "getUri", "(", ")", ")", ")", ";", "}", "}", "$", "rdf", "=", "$", "res", "->", "getGraph", "(", ")", "->", "serialise", "(", "'ntriples'", ")", ";", "return", "$", "rdf", ";", "}" ]
Serializes metadata to a form suitable for Fedora's SPARQL-update query. This means the "ntriples" format with subject URIs compliant with current Fedora connection and excluding properties Fedora reserves for itself (and rises errors when they are provided from the outside). @param \EasyRdf\Resource $metadata metadata to serialize @return string @see $skipProp @see $skipPropRegExp
[ "Serializes", "metadata", "to", "a", "form", "suitable", "for", "Fedora", "s", "SPARQL", "-", "update", "query", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraResource.php#L824-L839
29,816
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Loyalty/CardGroupsService.php
CardGroupsService.checkPasscodeEnabled
public function checkPasscodeEnabled($cardGroupId, $transactionType, $cardNumber) { return $this->execute($cardGroupId, "checkPasscodeEnabled", null, ["action" => $transactionType, "cardnumber" => $cardNumber]); }
php
public function checkPasscodeEnabled($cardGroupId, $transactionType, $cardNumber) { return $this->execute($cardGroupId, "checkPasscodeEnabled", null, ["action" => $transactionType, "cardnumber" => $cardNumber]); }
[ "public", "function", "checkPasscodeEnabled", "(", "$", "cardGroupId", ",", "$", "transactionType", ",", "$", "cardNumber", ")", "{", "return", "$", "this", "->", "execute", "(", "$", "cardGroupId", ",", "\"checkPasscodeEnabled\"", ",", "null", ",", "[", "\"action\"", "=>", "$", "transactionType", ",", "\"cardnumber\"", "=>", "$", "cardNumber", "]", ")", ";", "}" ]
Check if a passcode is enabled for this card @param string $cardGroupId CRG_XYZ @param string $transactionType FORM_TRANSACTION_XYZ @param string $cardNumber Number of the card @return bool|null @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Check", "if", "a", "passcode", "is", "enabled", "for", "this", "card" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Loyalty/CardGroupsService.php#L29-L32
29,817
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/SchemaObject.php
SchemaObject.getResource
public function getResource(bool $create = true, bool $uploadBinary = true): FedoraResource { if ($this->res === null) { try { $this->findResource(false, false); } catch (NotFound $e) { $this->updateRms($create, $uploadBinary); } } return $this->res; }
php
public function getResource(bool $create = true, bool $uploadBinary = true): FedoraResource { if ($this->res === null) { try { $this->findResource(false, false); } catch (NotFound $e) { $this->updateRms($create, $uploadBinary); } } return $this->res; }
[ "public", "function", "getResource", "(", "bool", "$", "create", "=", "true", ",", "bool", "$", "uploadBinary", "=", "true", ")", ":", "FedoraResource", "{", "if", "(", "$", "this", "->", "res", "===", "null", ")", "{", "try", "{", "$", "this", "->", "findResource", "(", "false", ",", "false", ")", ";", "}", "catch", "(", "NotFound", "$", "e", ")", "{", "$", "this", "->", "updateRms", "(", "$", "create", ",", "$", "uploadBinary", ")", ";", "}", "}", "return", "$", "this", "->", "res", ";", "}" ]
Returns repository resource representing given real-world entity. If it does not exist, it can be created. @param bool $create should repository resource be created if it does not exist? @param bool $uploadBinary should binary data of the real-world entity be uploaded uppon repository resource creation? @return FedoraResource
[ "Returns", "repository", "resource", "representing", "given", "real", "-", "world", "entity", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/SchemaObject.php#L129-L138
29,818
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/SchemaObject.php
SchemaObject.getIds
public function getIds(): array { $ids = array($this->id); $meta = $this->getMetadata(); foreach ($meta->allResources(RC::idProp()) as $id) { $ids[] = $id->getUri(); } $ids = array_unique($ids); return $ids; }
php
public function getIds(): array { $ids = array($this->id); $meta = $this->getMetadata(); foreach ($meta->allResources(RC::idProp()) as $id) { $ids[] = $id->getUri(); } $ids = array_unique($ids); return $ids; }
[ "public", "function", "getIds", "(", ")", ":", "array", "{", "$", "ids", "=", "array", "(", "$", "this", "->", "id", ")", ";", "$", "meta", "=", "$", "this", "->", "getMetadata", "(", ")", ";", "foreach", "(", "$", "meta", "->", "allResources", "(", "RC", "::", "idProp", "(", ")", ")", "as", "$", "id", ")", "{", "$", "ids", "[", "]", "=", "$", "id", "->", "getUri", "(", ")", ";", "}", "$", "ids", "=", "array_unique", "(", "$", "ids", ")", ";", "return", "$", "ids", ";", "}" ]
Returns all known ids @return array list of all ids
[ "Returns", "all", "known", "ids" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/SchemaObject.php#L157-L165
29,819
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/SchemaObject.php
SchemaObject.updateRms
public function updateRms(bool $create = true, bool $uploadBinary = true, string $path = '/'): FedoraResource { $this->created = $this->findResource($create, $uploadBinary, $path); // if it has just been created it would be a waste of time to update it if (!$this->created) { $meta = $this->getMetadata(); if ($this->metadata) { $meta->merge($this->metadata, $this->metadataPreserve); } $this->fedora->fixMetadataReferences($meta); $meta = $this->mergeMetadata($this->res->getMetadata(), $meta); $this->res->setMetadata($meta); $this->res->updateMetadata(); $binaryContent = $this->getBinaryData(); if ($uploadBinary && $binaryContent !== '') { $this->res->updateContent($binaryContent, true); } } return $this->res; }
php
public function updateRms(bool $create = true, bool $uploadBinary = true, string $path = '/'): FedoraResource { $this->created = $this->findResource($create, $uploadBinary, $path); // if it has just been created it would be a waste of time to update it if (!$this->created) { $meta = $this->getMetadata(); if ($this->metadata) { $meta->merge($this->metadata, $this->metadataPreserve); } $this->fedora->fixMetadataReferences($meta); $meta = $this->mergeMetadata($this->res->getMetadata(), $meta); $this->res->setMetadata($meta); $this->res->updateMetadata(); $binaryContent = $this->getBinaryData(); if ($uploadBinary && $binaryContent !== '') { $this->res->updateContent($binaryContent, true); } } return $this->res; }
[ "public", "function", "updateRms", "(", "bool", "$", "create", "=", "true", ",", "bool", "$", "uploadBinary", "=", "true", ",", "string", "$", "path", "=", "'/'", ")", ":", "FedoraResource", "{", "$", "this", "->", "created", "=", "$", "this", "->", "findResource", "(", "$", "create", ",", "$", "uploadBinary", ",", "$", "path", ")", ";", "// if it has just been created it would be a waste of time to update it", "if", "(", "!", "$", "this", "->", "created", ")", "{", "$", "meta", "=", "$", "this", "->", "getMetadata", "(", ")", ";", "if", "(", "$", "this", "->", "metadata", ")", "{", "$", "meta", "->", "merge", "(", "$", "this", "->", "metadata", ",", "$", "this", "->", "metadataPreserve", ")", ";", "}", "$", "this", "->", "fedora", "->", "fixMetadataReferences", "(", "$", "meta", ")", ";", "$", "meta", "=", "$", "this", "->", "mergeMetadata", "(", "$", "this", "->", "res", "->", "getMetadata", "(", ")", ",", "$", "meta", ")", ";", "$", "this", "->", "res", "->", "setMetadata", "(", "$", "meta", ")", ";", "$", "this", "->", "res", "->", "updateMetadata", "(", ")", ";", "$", "binaryContent", "=", "$", "this", "->", "getBinaryData", "(", ")", ";", "if", "(", "$", "uploadBinary", "&&", "$", "binaryContent", "!==", "''", ")", "{", "$", "this", "->", "res", "->", "updateContent", "(", "$", "binaryContent", ",", "true", ")", ";", "}", "}", "return", "$", "this", "->", "res", ";", "}" ]
Updates repository resource representing a real-world entity stored in this object. @param bool $create should repository resource be created if it does not exist? @param bool $uploadBinary should binary data of the real-world entity be uploaded uppon repository resource creation? @param string $path where to create a resource (if it does not exist). If it it ends with a "/", the resource will be created as a child of a given collection). All the parents in the Fedora resource tree have to exist (you can not create "/foo/bar" if "/foo" does not exist already). @return FedoraResource
[ "Updates", "repository", "resource", "representing", "a", "real", "-", "world", "entity", "stored", "in", "this", "object", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/SchemaObject.php#L181-L203
29,820
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/SchemaObject.php
SchemaObject.setMetadata
public function setMetadata(Resource $meta, array $preserve = array()) { $this->metadata = $meta; $this->metadataPreserve = $preserve; }
php
public function setMetadata(Resource $meta, array $preserve = array()) { $this->metadata = $meta; $this->metadataPreserve = $preserve; }
[ "public", "function", "setMetadata", "(", "Resource", "$", "meta", ",", "array", "$", "preserve", "=", "array", "(", ")", ")", "{", "$", "this", "->", "metadata", "=", "$", "meta", ";", "$", "this", "->", "metadataPreserve", "=", "$", "preserve", ";", "}" ]
Sets an external metadata to be appended to automatically generated ones. If a given metatada property exists both in automatically generated and provided metadata, then the final result depends on the $preserve parameter: - if the property is listed in the $preserve array, both automatically generated and provided values will be kept - if not, only values from provided metadata will be kept and automatically generated ones will be skipped @param Resource $meta external metadata @param array $preserve list of metadata properties to be kept - see above
[ "Sets", "an", "external", "metadata", "to", "be", "appended", "to", "automatically", "generated", "ones", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/SchemaObject.php#L231-L234
29,821
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/SchemaObject.php
SchemaObject.findResource
protected function findResource(bool $create = true, bool $uploadBinary = true, string $path = ''): bool { $ids = $this->getIds(); echo self::$debug ? "searching for " . implode(', ', $ids) . "\n" : ""; $result = ''; try { $this->res = $this->fedora->getResourceByIds($ids); $result = 'found in cache'; } catch (NotFound $e) { if (!$create) { throw $e; } $meta = $this->getMetadata(); $this->fedora->fixMetadataReferences($meta); $binary = $uploadBinary ? $this->getBinaryData() : ''; $method = substr($path, -1) == '/' || $path === '' ? 'POST' : 'PUT'; $this->res = $this->fedora->createResource($meta, $binary, $path, $method); $result = 'not found - created'; } echo self::$debug ? "\t" . $result . " - " . $this->res->getUri(true) . "\n" : ""; return $result == 'not found - created'; }
php
protected function findResource(bool $create = true, bool $uploadBinary = true, string $path = ''): bool { $ids = $this->getIds(); echo self::$debug ? "searching for " . implode(', ', $ids) . "\n" : ""; $result = ''; try { $this->res = $this->fedora->getResourceByIds($ids); $result = 'found in cache'; } catch (NotFound $e) { if (!$create) { throw $e; } $meta = $this->getMetadata(); $this->fedora->fixMetadataReferences($meta); $binary = $uploadBinary ? $this->getBinaryData() : ''; $method = substr($path, -1) == '/' || $path === '' ? 'POST' : 'PUT'; $this->res = $this->fedora->createResource($meta, $binary, $path, $method); $result = 'not found - created'; } echo self::$debug ? "\t" . $result . " - " . $this->res->getUri(true) . "\n" : ""; return $result == 'not found - created'; }
[ "protected", "function", "findResource", "(", "bool", "$", "create", "=", "true", ",", "bool", "$", "uploadBinary", "=", "true", ",", "string", "$", "path", "=", "''", ")", ":", "bool", "{", "$", "ids", "=", "$", "this", "->", "getIds", "(", ")", ";", "echo", "self", "::", "$", "debug", "?", "\"searching for \"", ".", "implode", "(", "', '", ",", "$", "ids", ")", ".", "\"\\n\"", ":", "\"\"", ";", "$", "result", "=", "''", ";", "try", "{", "$", "this", "->", "res", "=", "$", "this", "->", "fedora", "->", "getResourceByIds", "(", "$", "ids", ")", ";", "$", "result", "=", "'found in cache'", ";", "}", "catch", "(", "NotFound", "$", "e", ")", "{", "if", "(", "!", "$", "create", ")", "{", "throw", "$", "e", ";", "}", "$", "meta", "=", "$", "this", "->", "getMetadata", "(", ")", ";", "$", "this", "->", "fedora", "->", "fixMetadataReferences", "(", "$", "meta", ")", ";", "$", "binary", "=", "$", "uploadBinary", "?", "$", "this", "->", "getBinaryData", "(", ")", ":", "''", ";", "$", "method", "=", "substr", "(", "$", "path", ",", "-", "1", ")", "==", "'/'", "||", "$", "path", "===", "''", "?", "'POST'", ":", "'PUT'", ";", "$", "this", "->", "res", "=", "$", "this", "->", "fedora", "->", "createResource", "(", "$", "meta", ",", "$", "binary", ",", "$", "path", ",", "$", "method", ")", ";", "$", "result", "=", "'not found - created'", ";", "}", "echo", "self", "::", "$", "debug", "?", "\"\\t\"", ".", "$", "result", ".", "\" - \"", ".", "$", "this", "->", "res", "->", "getUri", "(", "true", ")", ".", "\"\\n\"", ":", "\"\"", ";", "return", "$", "result", "==", "'not found - created'", ";", "}" ]
Tries to find a repository resource representing a given object. @param bool $create should repository resource be created if it was not found? @param bool $uploadBinary should binary data of the real-world entity be uploaded uppon repository resource creation? @param string $path where to create a resource (if it does not exist). If it it ends with a "/", the resource will be created as a child of a given collection). All the parents in the Fedora resource tree have to exist (you can not create "/foo/bar" if "/foo" does not exist already). @return boolean if a repository resource was found
[ "Tries", "to", "find", "a", "repository", "resource", "representing", "a", "given", "object", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/SchemaObject.php#L249-L273
29,822
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/dissemination/Match.php
Match.getMetadata
public function getMetadata(): Resource { $meta = (new Graph())->resource('.'); $meta->addResource(RC::relProp(), $this->service->getResource()->getId()); $meta->addResource(RC::idProp(), $this->getId()); $meta->addLiteral(RC::titleProp(), 'A dissemination service matching rule'); $meta->addResource(RC::get('fedoraServiceMatchProp'), $this->property); $meta->addLiteral(RC::get('fedoraServiceMatchValue'), $this->value); $meta->addLiteral(RC::get('fedoraServiceMatchRequired'), $this->required); return $meta; }
php
public function getMetadata(): Resource { $meta = (new Graph())->resource('.'); $meta->addResource(RC::relProp(), $this->service->getResource()->getId()); $meta->addResource(RC::idProp(), $this->getId()); $meta->addLiteral(RC::titleProp(), 'A dissemination service matching rule'); $meta->addResource(RC::get('fedoraServiceMatchProp'), $this->property); $meta->addLiteral(RC::get('fedoraServiceMatchValue'), $this->value); $meta->addLiteral(RC::get('fedoraServiceMatchRequired'), $this->required); return $meta; }
[ "public", "function", "getMetadata", "(", ")", ":", "Resource", "{", "$", "meta", "=", "(", "new", "Graph", "(", ")", ")", "->", "resource", "(", "'.'", ")", ";", "$", "meta", "->", "addResource", "(", "RC", "::", "relProp", "(", ")", ",", "$", "this", "->", "service", "->", "getResource", "(", ")", "->", "getId", "(", ")", ")", ";", "$", "meta", "->", "addResource", "(", "RC", "::", "idProp", "(", ")", ",", "$", "this", "->", "getId", "(", ")", ")", ";", "$", "meta", "->", "addLiteral", "(", "RC", "::", "titleProp", "(", ")", ",", "'A dissemination service matching rule'", ")", ";", "$", "meta", "->", "addResource", "(", "RC", "::", "get", "(", "'fedoraServiceMatchProp'", ")", ",", "$", "this", "->", "property", ")", ";", "$", "meta", "->", "addLiteral", "(", "RC", "::", "get", "(", "'fedoraServiceMatchValue'", ")", ",", "$", "this", "->", "value", ")", ";", "$", "meta", "->", "addLiteral", "(", "RC", "::", "get", "(", "'fedoraServiceMatchRequired'", ")", ",", "$", "this", "->", "required", ")", ";", "return", "$", "meta", ";", "}" ]
Returns metadata describing the match @return Resource
[ "Returns", "metadata", "describing", "the", "match" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/dissemination/Match.php#L119-L131
29,823
polyfony-inc/polyfony
Private/Polyfony/Record.php
Record.tget
public function tget(string $column, int $length=32) { // we get the raw value, truncate it, and escape it afterwards return strlen($this->get($column, true)) > $length ? Format::htmlSafe( Format::truncate( $this->get($column, true), $length ) ) : $this->get($column); }
php
public function tget(string $column, int $length=32) { // we get the raw value, truncate it, and escape it afterwards return strlen($this->get($column, true)) > $length ? Format::htmlSafe( Format::truncate( $this->get($column, true), $length ) ) : $this->get($column); }
[ "public", "function", "tget", "(", "string", "$", "column", ",", "int", "$", "length", "=", "32", ")", "{", "// we get the raw value, truncate it, and escape it afterwards", "return", "strlen", "(", "$", "this", "->", "get", "(", "$", "column", ",", "true", ")", ")", ">", "$", "length", "?", "Format", "::", "htmlSafe", "(", "Format", "::", "truncate", "(", "$", "this", "->", "get", "(", "$", "column", ",", "true", ")", ",", "$", "length", ")", ")", ":", "$", "this", "->", "get", "(", "$", "column", ")", ";", "}" ]
get a truncated field, that is safe to place in a HTML document
[ "get", "a", "truncated", "field", "that", "is", "safe", "to", "place", "in", "a", "HTML", "document" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Record.php#L8-L18
29,824
acdh-oeaw/repo-php-util
src/acdhOeaw/util/metadataValidator/MetadataValidator.php
MetadataValidator.validateGraph
static public function validateGraph(Graph $graph, Fedora $fedora): array { $results = array(); foreach ($graph->resources() as $i) { $results = array_merge($results, self::validateResource($i, $fedora)); } return $results; }
php
static public function validateGraph(Graph $graph, Fedora $fedora): array { $results = array(); foreach ($graph->resources() as $i) { $results = array_merge($results, self::validateResource($i, $fedora)); } return $results; }
[ "static", "public", "function", "validateGraph", "(", "Graph", "$", "graph", ",", "Fedora", "$", "fedora", ")", ":", "array", "{", "$", "results", "=", "array", "(", ")", ";", "foreach", "(", "$", "graph", "->", "resources", "(", ")", "as", "$", "i", ")", "{", "$", "results", "=", "array_merge", "(", "$", "results", ",", "self", "::", "validateResource", "(", "$", "i", ",", "$", "fedora", ")", ")", ";", "}", "return", "$", "results", ";", "}" ]
Checks a given RDF graph against ontology in a given Fedora repository. @param Graph $graph RDF graph to be checked @param Fedora $fedora repository connection object @return array list of errors
[ "Checks", "a", "given", "RDF", "graph", "against", "ontology", "in", "a", "given", "Fedora", "repository", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/metadataValidator/MetadataValidator.php#L71-L77
29,825
acdh-oeaw/repo-php-util
src/acdhOeaw/util/metadataValidator/MetadataValidator.php
MetadataValidator.validateResource
static public function validateResource(Resource $res, Fedora $fedora): array { $results = array(); foreach ($res->propertyUris() as $prop) { if ($prop === self::RDFS_TYPE) { $tmp = self::checkClass($res, $fedora); } else { $tmp = self::checkProperty($prop, $res, $fedora); } $results = array_merge($results, $tmp); } return $results; }
php
static public function validateResource(Resource $res, Fedora $fedora): array { $results = array(); foreach ($res->propertyUris() as $prop) { if ($prop === self::RDFS_TYPE) { $tmp = self::checkClass($res, $fedora); } else { $tmp = self::checkProperty($prop, $res, $fedora); } $results = array_merge($results, $tmp); } return $results; }
[ "static", "public", "function", "validateResource", "(", "Resource", "$", "res", ",", "Fedora", "$", "fedora", ")", ":", "array", "{", "$", "results", "=", "array", "(", ")", ";", "foreach", "(", "$", "res", "->", "propertyUris", "(", ")", "as", "$", "prop", ")", "{", "if", "(", "$", "prop", "===", "self", "::", "RDFS_TYPE", ")", "{", "$", "tmp", "=", "self", "::", "checkClass", "(", "$", "res", ",", "$", "fedora", ")", ";", "}", "else", "{", "$", "tmp", "=", "self", "::", "checkProperty", "(", "$", "prop", ",", "$", "res", ",", "$", "fedora", ")", ";", "}", "$", "results", "=", "array_merge", "(", "$", "results", ",", "$", "tmp", ")", ";", "}", "return", "$", "results", ";", "}" ]
Checks a given EasyRdf\Resource against ontology in a given repository. @param Resource $res @param Fedora $fedora repository connection object @return array list of errors
[ "Checks", "a", "given", "EasyRdf", "\\", "Resource", "against", "ontology", "in", "a", "given", "repository", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/metadataValidator/MetadataValidator.php#L85-L96
29,826
acdh-oeaw/repo-php-util
src/acdhOeaw/util/metadataValidator/MetadataValidator.php
MetadataValidator.printResults
static public function printResults(array $results, string $format = 'text') { if ($format == 'tsv') { echo "subject\tmessage\tproperty\tvalue\n"; foreach ($results as $i) { echo $i . "\n"; } } else { $len = array(9, 9, 10, 7); foreach ($results as $i) { $len[0] = max($len[0], mb_strlen($i->resUri) + 2); $len[1] = max($len[1], mb_strlen($i->message) + 2); $len[2] = max($len[2], mb_strlen($i->property) + 2); $len[3] = max($len[3], mb_strlen($i->value) + 2); } $format = sprintf("%% %ds%% %ds%% %ds%% %ds\n", $len[0], $len[1], $len[2], $len[3]); printf($format, 'subject', 'message', 'property', 'value'); foreach ($results as $i) { printf($format, $i->resUri, $i->message, $i->property, $i->value); } } }
php
static public function printResults(array $results, string $format = 'text') { if ($format == 'tsv') { echo "subject\tmessage\tproperty\tvalue\n"; foreach ($results as $i) { echo $i . "\n"; } } else { $len = array(9, 9, 10, 7); foreach ($results as $i) { $len[0] = max($len[0], mb_strlen($i->resUri) + 2); $len[1] = max($len[1], mb_strlen($i->message) + 2); $len[2] = max($len[2], mb_strlen($i->property) + 2); $len[3] = max($len[3], mb_strlen($i->value) + 2); } $format = sprintf("%% %ds%% %ds%% %ds%% %ds\n", $len[0], $len[1], $len[2], $len[3]); printf($format, 'subject', 'message', 'property', 'value'); foreach ($results as $i) { printf($format, $i->resUri, $i->message, $i->property, $i->value); } } }
[ "static", "public", "function", "printResults", "(", "array", "$", "results", ",", "string", "$", "format", "=", "'text'", ")", "{", "if", "(", "$", "format", "==", "'tsv'", ")", "{", "echo", "\"subject\\tmessage\\tproperty\\tvalue\\n\"", ";", "foreach", "(", "$", "results", "as", "$", "i", ")", "{", "echo", "$", "i", ".", "\"\\n\"", ";", "}", "}", "else", "{", "$", "len", "=", "array", "(", "9", ",", "9", ",", "10", ",", "7", ")", ";", "foreach", "(", "$", "results", "as", "$", "i", ")", "{", "$", "len", "[", "0", "]", "=", "max", "(", "$", "len", "[", "0", "]", ",", "mb_strlen", "(", "$", "i", "->", "resUri", ")", "+", "2", ")", ";", "$", "len", "[", "1", "]", "=", "max", "(", "$", "len", "[", "1", "]", ",", "mb_strlen", "(", "$", "i", "->", "message", ")", "+", "2", ")", ";", "$", "len", "[", "2", "]", "=", "max", "(", "$", "len", "[", "2", "]", ",", "mb_strlen", "(", "$", "i", "->", "property", ")", "+", "2", ")", ";", "$", "len", "[", "3", "]", "=", "max", "(", "$", "len", "[", "3", "]", ",", "mb_strlen", "(", "$", "i", "->", "value", ")", "+", "2", ")", ";", "}", "$", "format", "=", "sprintf", "(", "\"%% %ds%% %ds%% %ds%% %ds\\n\"", ",", "$", "len", "[", "0", "]", ",", "$", "len", "[", "1", "]", ",", "$", "len", "[", "2", "]", ",", "$", "len", "[", "3", "]", ")", ";", "printf", "(", "$", "format", ",", "'subject'", ",", "'message'", ",", "'property'", ",", "'value'", ")", ";", "foreach", "(", "$", "results", "as", "$", "i", ")", "{", "printf", "(", "$", "format", ",", "$", "i", "->", "resUri", ",", "$", "i", "->", "message", ",", "$", "i", "->", "property", ",", "$", "i", "->", "value", ")", ";", "}", "}", "}" ]
Pretty prints a list of errors. @param array $results list of errors @param string $format print format: tsv or text
[ "Pretty", "prints", "a", "list", "of", "errors", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/metadataValidator/MetadataValidator.php#L113-L133
29,827
acdh-oeaw/repo-php-util
src/acdhOeaw/util/metadataValidator/MetadataValidator.php
MetadataValidator.checkClass
static private function checkClass(Resource $res, Fedora $fedora): array { if (self::$classes === null) { self::loadClasses($fedora); } $ret = array(); foreach ($res->allResources(self::RDFS_TYPE) as $i) { $i = $i->getUri(); if (!isset(self::$classes[$i])) { $ret[] = new Error($res->getUri(), 'unknown class', $i); } } return $ret; }
php
static private function checkClass(Resource $res, Fedora $fedora): array { if (self::$classes === null) { self::loadClasses($fedora); } $ret = array(); foreach ($res->allResources(self::RDFS_TYPE) as $i) { $i = $i->getUri(); if (!isset(self::$classes[$i])) { $ret[] = new Error($res->getUri(), 'unknown class', $i); } } return $ret; }
[ "static", "private", "function", "checkClass", "(", "Resource", "$", "res", ",", "Fedora", "$", "fedora", ")", ":", "array", "{", "if", "(", "self", "::", "$", "classes", "===", "null", ")", "{", "self", "::", "loadClasses", "(", "$", "fedora", ")", ";", "}", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "res", "->", "allResources", "(", "self", "::", "RDFS_TYPE", ")", "as", "$", "i", ")", "{", "$", "i", "=", "$", "i", "->", "getUri", "(", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "classes", "[", "$", "i", "]", ")", ")", "{", "$", "ret", "[", "]", "=", "new", "Error", "(", "$", "res", "->", "getUri", "(", ")", ",", "'unknown class'", ",", "$", "i", ")", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Checks if a resource is of known class @param Resource $res resource to be checked @param Fedora $fedora repository connection object @return array list of errors
[ "Checks", "if", "a", "resource", "is", "of", "known", "class" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/metadataValidator/MetadataValidator.php#L141-L153
29,828
acdh-oeaw/repo-php-util
src/acdhOeaw/util/metadataValidator/MetadataValidator.php
MetadataValidator.checkProperty
static private function checkProperty(string $property, Resource $res, Fedora $fedora): array { $uri = $res->getUri(); $ret = array(); try { $propDef = self::getPropertyDef($property, $fedora); if (!self::checkRangeDomain($res, $propDef->getDomain())) { $ret[] = new Error($uri, 'wrong domain', '', $property); } list($matchType, $wrongType) = $propDef->fetchValues($res); foreach ($wrongType as $i) { $ret[] = new Error($uri, 'wrong value type (literal/uri)', (string) $i, $property); } foreach ($matchType as $i) { if (!self::checkRangeDomain($i, $propDef->getRange())) { $ret[] = new Error($uri, 'wrong range', $i->getUri(), $property); } } } catch (RuntimeException $e) { switch ($e->getCode()) { case 10: $ret[] = new Error($uri, 'unknown property', '', $property); break; case 11: $ret[] = new Error($uri, 'wrongly defined property', '', $property); break; case 12: $ret[] = new Error($uri, 'wrongly defined property', '', $property); break; default: throw $e; } } return $ret; }
php
static private function checkProperty(string $property, Resource $res, Fedora $fedora): array { $uri = $res->getUri(); $ret = array(); try { $propDef = self::getPropertyDef($property, $fedora); if (!self::checkRangeDomain($res, $propDef->getDomain())) { $ret[] = new Error($uri, 'wrong domain', '', $property); } list($matchType, $wrongType) = $propDef->fetchValues($res); foreach ($wrongType as $i) { $ret[] = new Error($uri, 'wrong value type (literal/uri)', (string) $i, $property); } foreach ($matchType as $i) { if (!self::checkRangeDomain($i, $propDef->getRange())) { $ret[] = new Error($uri, 'wrong range', $i->getUri(), $property); } } } catch (RuntimeException $e) { switch ($e->getCode()) { case 10: $ret[] = new Error($uri, 'unknown property', '', $property); break; case 11: $ret[] = new Error($uri, 'wrongly defined property', '', $property); break; case 12: $ret[] = new Error($uri, 'wrongly defined property', '', $property); break; default: throw $e; } } return $ret; }
[ "static", "private", "function", "checkProperty", "(", "string", "$", "property", ",", "Resource", "$", "res", ",", "Fedora", "$", "fedora", ")", ":", "array", "{", "$", "uri", "=", "$", "res", "->", "getUri", "(", ")", ";", "$", "ret", "=", "array", "(", ")", ";", "try", "{", "$", "propDef", "=", "self", "::", "getPropertyDef", "(", "$", "property", ",", "$", "fedora", ")", ";", "if", "(", "!", "self", "::", "checkRangeDomain", "(", "$", "res", ",", "$", "propDef", "->", "getDomain", "(", ")", ")", ")", "{", "$", "ret", "[", "]", "=", "new", "Error", "(", "$", "uri", ",", "'wrong domain'", ",", "''", ",", "$", "property", ")", ";", "}", "list", "(", "$", "matchType", ",", "$", "wrongType", ")", "=", "$", "propDef", "->", "fetchValues", "(", "$", "res", ")", ";", "foreach", "(", "$", "wrongType", "as", "$", "i", ")", "{", "$", "ret", "[", "]", "=", "new", "Error", "(", "$", "uri", ",", "'wrong value type (literal/uri)'", ",", "(", "string", ")", "$", "i", ",", "$", "property", ")", ";", "}", "foreach", "(", "$", "matchType", "as", "$", "i", ")", "{", "if", "(", "!", "self", "::", "checkRangeDomain", "(", "$", "i", ",", "$", "propDef", "->", "getRange", "(", ")", ")", ")", "{", "$", "ret", "[", "]", "=", "new", "Error", "(", "$", "uri", ",", "'wrong range'", ",", "$", "i", "->", "getUri", "(", ")", ",", "$", "property", ")", ";", "}", "}", "}", "catch", "(", "RuntimeException", "$", "e", ")", "{", "switch", "(", "$", "e", "->", "getCode", "(", ")", ")", "{", "case", "10", ":", "$", "ret", "[", "]", "=", "new", "Error", "(", "$", "uri", ",", "'unknown property'", ",", "''", ",", "$", "property", ")", ";", "break", ";", "case", "11", ":", "$", "ret", "[", "]", "=", "new", "Error", "(", "$", "uri", ",", "'wrongly defined property'", ",", "''", ",", "$", "property", ")", ";", "break", ";", "case", "12", ":", "$", "ret", "[", "]", "=", "new", "Error", "(", "$", "uri", ",", "'wrongly defined property'", ",", "''", ",", "$", "property", ")", ";", "break", ";", "default", ":", "throw", "$", "e", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Checks if a given property is defined in the ontology and if all its values for a given resource match property definition provided by the ontology. @param string $property RDF property to be checked @param Resource $res resource containing given property values @param Fedora $fedora repository connection object @return array list of errors @throws RuntimeException
[ "Checks", "if", "a", "given", "property", "is", "defined", "in", "the", "ontology", "and", "if", "all", "its", "values", "for", "a", "given", "resource", "match", "property", "definition", "provided", "by", "the", "ontology", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/metadataValidator/MetadataValidator.php#L165-L201
29,829
acdh-oeaw/repo-php-util
src/acdhOeaw/util/metadataValidator/MetadataValidator.php
MetadataValidator.getPropertyDef
static private function getPropertyDef(string $property, Fedora $fedora): OntologyProperty { if (!isset(self::$cache[$property])) { self::$cache[$property] = new OntologyProperty($property, $fedora); } return self::$cache[$property]; }
php
static private function getPropertyDef(string $property, Fedora $fedora): OntologyProperty { if (!isset(self::$cache[$property])) { self::$cache[$property] = new OntologyProperty($property, $fedora); } return self::$cache[$property]; }
[ "static", "private", "function", "getPropertyDef", "(", "string", "$", "property", ",", "Fedora", "$", "fedora", ")", ":", "OntologyProperty", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "cache", "[", "$", "property", "]", ")", ")", "{", "self", "::", "$", "cache", "[", "$", "property", "]", "=", "new", "OntologyProperty", "(", "$", "property", ",", "$", "fedora", ")", ";", "}", "return", "self", "::", "$", "cache", "[", "$", "property", "]", ";", "}" ]
Fetches property definition from cache. Creates a deifinition if it does not exist. @param string $property RDF property URI @param Fedora $fedora repository connection object @return \acdhOeaw\util\metadataValidator\OntologyProperty
[ "Fetches", "property", "definition", "from", "cache", ".", "Creates", "a", "deifinition", "if", "it", "does", "not", "exist", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/metadataValidator/MetadataValidator.php#L210-L215
29,830
acdh-oeaw/repo-php-util
src/acdhOeaw/util/metadataValidator/MetadataValidator.php
MetadataValidator.loadClasses
static private function loadClasses(Fedora $fedora) { $ontologyLoc = RC::get('fedoraApiUrl') . '/' . RC::get('doorkeeperOntologyLocation') . '/'; $query = new SimpleQuery(" select ?fRes ?id ?parent where { ?fRes a <http://www.w3.org/2002/07/owl#Class> . ?fRes ?@ ?id . optional { ?fRes <http://www.w3.org/2000/01/rdf-schema#subClassOf> / (^?@ / <http://www.w3.org/2000/01/rdf-schema#subClassOf>)* ?parent . } filter regex(str(?fRes), ?#) } "); $query->setValues(array(RC::idProp(), RC::idProp(), $ontologyLoc)); $res = $fedora->runQuery($query); self::$classes = array(); foreach ($res as $i) { $id = $i->id->getUri(); if (!isset(self::$classes[$id])) { self::$classes[$id] = array($id); } if (isset($i->parent) && $i->parent) { self::$classes[$id][] = $i->parent->getUri(); } } }
php
static private function loadClasses(Fedora $fedora) { $ontologyLoc = RC::get('fedoraApiUrl') . '/' . RC::get('doorkeeperOntologyLocation') . '/'; $query = new SimpleQuery(" select ?fRes ?id ?parent where { ?fRes a <http://www.w3.org/2002/07/owl#Class> . ?fRes ?@ ?id . optional { ?fRes <http://www.w3.org/2000/01/rdf-schema#subClassOf> / (^?@ / <http://www.w3.org/2000/01/rdf-schema#subClassOf>)* ?parent . } filter regex(str(?fRes), ?#) } "); $query->setValues(array(RC::idProp(), RC::idProp(), $ontologyLoc)); $res = $fedora->runQuery($query); self::$classes = array(); foreach ($res as $i) { $id = $i->id->getUri(); if (!isset(self::$classes[$id])) { self::$classes[$id] = array($id); } if (isset($i->parent) && $i->parent) { self::$classes[$id][] = $i->parent->getUri(); } } }
[ "static", "private", "function", "loadClasses", "(", "Fedora", "$", "fedora", ")", "{", "$", "ontologyLoc", "=", "RC", "::", "get", "(", "'fedoraApiUrl'", ")", ".", "'/'", ".", "RC", "::", "get", "(", "'doorkeeperOntologyLocation'", ")", ".", "'/'", ";", "$", "query", "=", "new", "SimpleQuery", "(", "\"\n select ?fRes ?id ?parent\n where {\n ?fRes a <http://www.w3.org/2002/07/owl#Class> .\n ?fRes ?@ ?id .\n optional { ?fRes <http://www.w3.org/2000/01/rdf-schema#subClassOf> / (^?@ / <http://www.w3.org/2000/01/rdf-schema#subClassOf>)* ?parent . }\n filter regex(str(?fRes), ?#)\n }\n \"", ")", ";", "$", "query", "->", "setValues", "(", "array", "(", "RC", "::", "idProp", "(", ")", ",", "RC", "::", "idProp", "(", ")", ",", "$", "ontologyLoc", ")", ")", ";", "$", "res", "=", "$", "fedora", "->", "runQuery", "(", "$", "query", ")", ";", "self", "::", "$", "classes", "=", "array", "(", ")", ";", "foreach", "(", "$", "res", "as", "$", "i", ")", "{", "$", "id", "=", "$", "i", "->", "id", "->", "getUri", "(", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "classes", "[", "$", "id", "]", ")", ")", "{", "self", "::", "$", "classes", "[", "$", "id", "]", "=", "array", "(", "$", "id", ")", ";", "}", "if", "(", "isset", "(", "$", "i", "->", "parent", ")", "&&", "$", "i", "->", "parent", ")", "{", "self", "::", "$", "classes", "[", "$", "id", "]", "[", "]", "=", "$", "i", "->", "parent", "->", "getUri", "(", ")", ";", "}", "}", "}" ]
Loads classes defined in the ontology. @param Fedora $fedora repository connection object
[ "Loads", "classes", "defined", "in", "the", "ontology", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/metadataValidator/MetadataValidator.php#L251-L276
29,831
polyfony-inc/polyfony
Private/Polyfony/Database.php
Database.describe
public static function describe(string $table) :array { // set the cachefile name $cache_name = ucfirst($table).'Nulls'; // check if it has been cached already if(Cache::has($cache_name)) { // get it from the cache return Cache::get($cache_name); } // else it is not available from the cache else { // the list of allowed null columns $allowed_nulls = []; // query the database foreach(self::query() ->query(str_replace('*table*', $table, self::$_config['nulls']['query'])) ->execute() as $column) { // populate the list $allowed_nulls[$column->get(self::$_config['nulls']['column_for_name'])] = self::$_config['nulls']['true'] == $column->get(self::$_config['nulls']['column_for_value']) ? true : false; } // save the results in the cache Cache::put($cache_name, $allowed_nulls); // and finaly return the results return $allowed_nulls; } }
php
public static function describe(string $table) :array { // set the cachefile name $cache_name = ucfirst($table).'Nulls'; // check if it has been cached already if(Cache::has($cache_name)) { // get it from the cache return Cache::get($cache_name); } // else it is not available from the cache else { // the list of allowed null columns $allowed_nulls = []; // query the database foreach(self::query() ->query(str_replace('*table*', $table, self::$_config['nulls']['query'])) ->execute() as $column) { // populate the list $allowed_nulls[$column->get(self::$_config['nulls']['column_for_name'])] = self::$_config['nulls']['true'] == $column->get(self::$_config['nulls']['column_for_value']) ? true : false; } // save the results in the cache Cache::put($cache_name, $allowed_nulls); // and finaly return the results return $allowed_nulls; } }
[ "public", "static", "function", "describe", "(", "string", "$", "table", ")", ":", "array", "{", "// set the cachefile name", "$", "cache_name", "=", "ucfirst", "(", "$", "table", ")", ".", "'Nulls'", ";", "// check if it has been cached already", "if", "(", "Cache", "::", "has", "(", "$", "cache_name", ")", ")", "{", "// get it from the cache", "return", "Cache", "::", "get", "(", "$", "cache_name", ")", ";", "}", "// else it is not available from the cache", "else", "{", "// the list of allowed null columns", "$", "allowed_nulls", "=", "[", "]", ";", "// query the database", "foreach", "(", "self", "::", "query", "(", ")", "->", "query", "(", "str_replace", "(", "'*table*'", ",", "$", "table", ",", "self", "::", "$", "_config", "[", "'nulls'", "]", "[", "'query'", "]", ")", ")", "->", "execute", "(", ")", "as", "$", "column", ")", "{", "// populate the list", "$", "allowed_nulls", "[", "$", "column", "->", "get", "(", "self", "::", "$", "_config", "[", "'nulls'", "]", "[", "'column_for_name'", "]", ")", "]", "=", "self", "::", "$", "_config", "[", "'nulls'", "]", "[", "'true'", "]", "==", "$", "column", "->", "get", "(", "self", "::", "$", "_config", "[", "'nulls'", "]", "[", "'column_for_value'", "]", ")", "?", "true", ":", "false", ";", "}", "// save the results in the cache", "Cache", "::", "put", "(", "$", "cache_name", ",", "$", "allowed_nulls", ")", ";", "// and finaly return the results", "return", "$", "allowed_nulls", ";", "}", "}" ]
get the description of a table
[ "get", "the", "description", "of", "a", "table" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Database.php#L181-L218
29,832
polyfony-inc/polyfony
Private/Polyfony/Controller.php
Controller.forward
final public function forward(string $controller, $action = null) :void { // get the current route as a base $route = Router::getCurrentRoute(); // and alter it $route->controller = $controller; $route->action = $action; // forward to the new route Router::forward($route); }
php
final public function forward(string $controller, $action = null) :void { // get the current route as a base $route = Router::getCurrentRoute(); // and alter it $route->controller = $controller; $route->action = $action; // forward to the new route Router::forward($route); }
[ "final", "public", "function", "forward", "(", "string", "$", "controller", ",", "$", "action", "=", "null", ")", ":", "void", "{", "// get the current route as a base", "$", "route", "=", "Router", "::", "getCurrentRoute", "(", ")", ";", "// and alter it", "$", "route", "->", "controller", "=", "$", "controller", ";", "$", "route", "->", "action", "=", "$", "action", ";", "// forward to the new route", "Router", "::", "forward", "(", "$", "route", ")", ";", "}" ]
forward to another controller in the same bundle
[ "forward", "to", "another", "controller", "in", "the", "same", "bundle" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Controller.php#L56-L68
29,833
ventoviro/windwalker-core
src/Core/Utilities/Classes/ArrayAccessTrait.php
ArrayAccessTrait.offsetGet
public function offsetGet($offset) { $field = $this->dataField; if (empty($this->{$field}[$offset])) { return null; } return $this->{$field}[$offset]; }
php
public function offsetGet($offset) { $field = $this->dataField; if (empty($this->{$field}[$offset])) { return null; } return $this->{$field}[$offset]; }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "$", "field", "=", "$", "this", "->", "dataField", ";", "if", "(", "empty", "(", "$", "this", "->", "{", "$", "field", "}", "[", "$", "offset", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "{", "$", "field", "}", "[", "$", "offset", "]", ";", "}" ]
Get a value of property. @param mixed $offset Property key. @return mixed The value of this property.
[ "Get", "a", "value", "of", "property", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Utilities/Classes/ArrayAccessTrait.php#L46-L55
29,834
ventoviro/windwalker-core
src/Core/Utilities/Classes/ArrayAccessTrait.php
ArrayAccessTrait.offsetSet
public function offsetSet($offset, $value) { $field = $this->dataField; if ($offset !== null) { $this->{$field}[$offset] = $value; } else { array_push($this->{$field}, $value); } }
php
public function offsetSet($offset, $value) { $field = $this->dataField; if ($offset !== null) { $this->{$field}[$offset] = $value; } else { array_push($this->{$field}, $value); } }
[ "public", "function", "offsetSet", "(", "$", "offset", ",", "$", "value", ")", "{", "$", "field", "=", "$", "this", "->", "dataField", ";", "if", "(", "$", "offset", "!==", "null", ")", "{", "$", "this", "->", "{", "$", "field", "}", "[", "$", "offset", "]", "=", "$", "value", ";", "}", "else", "{", "array_push", "(", "$", "this", "->", "{", "$", "field", "}", ",", "$", "value", ")", ";", "}", "}" ]
Set value to property @param mixed $offset Property key. @param mixed $value Property value to set. @return void
[ "Set", "value", "to", "property" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Utilities/Classes/ArrayAccessTrait.php#L65-L74
29,835
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/metadataQuery/QueryParameter.php
QueryParameter.escapeUri
static public function escapeUri(string $uri): string { self::initSerializer(); return self::$serializer->serialiseValue(new Resource($uri)); }
php
static public function escapeUri(string $uri): string { self::initSerializer(); return self::$serializer->serialiseValue(new Resource($uri)); }
[ "static", "public", "function", "escapeUri", "(", "string", "$", "uri", ")", ":", "string", "{", "self", "::", "initSerializer", "(", ")", ";", "return", "self", "::", "$", "serializer", "->", "serialiseValue", "(", "new", "Resource", "(", "$", "uri", ")", ")", ";", "}" ]
Escapes a given string as an URI @param string $uri @return string
[ "Escapes", "a", "given", "string", "as", "an", "URI" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/metadataQuery/QueryParameter.php#L68-L71
29,836
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/metadataQuery/QueryParameter.php
QueryParameter.escapeLiteral
static public function escapeLiteral(string $literal): string { self::initSerializer(); $value = self::$serializer->serialiseValue(new Literal($literal)); return $value; }
php
static public function escapeLiteral(string $literal): string { self::initSerializer(); $value = self::$serializer->serialiseValue(new Literal($literal)); return $value; }
[ "static", "public", "function", "escapeLiteral", "(", "string", "$", "literal", ")", ":", "string", "{", "self", "::", "initSerializer", "(", ")", ";", "$", "value", "=", "self", "::", "$", "serializer", "->", "serialiseValue", "(", "new", "Literal", "(", "$", "literal", ")", ")", ";", "return", "$", "value", ";", "}" ]
Escapes a given string as a literal @param string $literal @return string
[ "Escapes", "a", "given", "string", "as", "a", "literal" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/metadataQuery/QueryParameter.php#L79-L83
29,837
hnhdigital-os/laravel-model-schema
src/Exceptions/ValidationException.php
ValidationException.getResponse
public function getResponse($route, $parameters, $config = []) { // Copy standard response. $response = self::$response; // Fill the response. array_set($response, 'is_error', true); array_set($response, 'message', $this->getMessage()); array_set($response, 'fields', array_keys($this->validator->errors()->messages())); array_set($response, 'feedback', $this->validator->errors()->all()); array_set($response, 'errors', $this->validator->errors()); if (array_has($config, 'feedback.html')) { array_set( $response, 'feedback', '<ul><li>'.implode('</li><li>', array_get($response, 'feedback')).'</li></ul>' ); } // JSON response required. if (request()->ajax() || request()->wantsJson()) { return response() ->json($response, 422); } // Redirect response, flash to session. session()->flash('is_error', true); session()->flash('message', array_get($response, 'message', '')); session()->flash('feedback', array_get($response, 'feedback', '')); session()->flash('fields', array_get($response, 'fields', [])); // Redirect to provided route. return redirect() ->route($route, $parameters) ->withErrors($this->getValidator()) ->withInput(); }
php
public function getResponse($route, $parameters, $config = []) { // Copy standard response. $response = self::$response; // Fill the response. array_set($response, 'is_error', true); array_set($response, 'message', $this->getMessage()); array_set($response, 'fields', array_keys($this->validator->errors()->messages())); array_set($response, 'feedback', $this->validator->errors()->all()); array_set($response, 'errors', $this->validator->errors()); if (array_has($config, 'feedback.html')) { array_set( $response, 'feedback', '<ul><li>'.implode('</li><li>', array_get($response, 'feedback')).'</li></ul>' ); } // JSON response required. if (request()->ajax() || request()->wantsJson()) { return response() ->json($response, 422); } // Redirect response, flash to session. session()->flash('is_error', true); session()->flash('message', array_get($response, 'message', '')); session()->flash('feedback', array_get($response, 'feedback', '')); session()->flash('fields', array_get($response, 'fields', [])); // Redirect to provided route. return redirect() ->route($route, $parameters) ->withErrors($this->getValidator()) ->withInput(); }
[ "public", "function", "getResponse", "(", "$", "route", ",", "$", "parameters", ",", "$", "config", "=", "[", "]", ")", "{", "// Copy standard response.", "$", "response", "=", "self", "::", "$", "response", ";", "// Fill the response.", "array_set", "(", "$", "response", ",", "'is_error'", ",", "true", ")", ";", "array_set", "(", "$", "response", ",", "'message'", ",", "$", "this", "->", "getMessage", "(", ")", ")", ";", "array_set", "(", "$", "response", ",", "'fields'", ",", "array_keys", "(", "$", "this", "->", "validator", "->", "errors", "(", ")", "->", "messages", "(", ")", ")", ")", ";", "array_set", "(", "$", "response", ",", "'feedback'", ",", "$", "this", "->", "validator", "->", "errors", "(", ")", "->", "all", "(", ")", ")", ";", "array_set", "(", "$", "response", ",", "'errors'", ",", "$", "this", "->", "validator", "->", "errors", "(", ")", ")", ";", "if", "(", "array_has", "(", "$", "config", ",", "'feedback.html'", ")", ")", "{", "array_set", "(", "$", "response", ",", "'feedback'", ",", "'<ul><li>'", ".", "implode", "(", "'</li><li>'", ",", "array_get", "(", "$", "response", ",", "'feedback'", ")", ")", ".", "'</li></ul>'", ")", ";", "}", "// JSON response required.", "if", "(", "request", "(", ")", "->", "ajax", "(", ")", "||", "request", "(", ")", "->", "wantsJson", "(", ")", ")", "{", "return", "response", "(", ")", "->", "json", "(", "$", "response", ",", "422", ")", ";", "}", "// Redirect response, flash to session.", "session", "(", ")", "->", "flash", "(", "'is_error'", ",", "true", ")", ";", "session", "(", ")", "->", "flash", "(", "'message'", ",", "array_get", "(", "$", "response", ",", "'message'", ",", "''", ")", ")", ";", "session", "(", ")", "->", "flash", "(", "'feedback'", ",", "array_get", "(", "$", "response", ",", "'feedback'", ",", "''", ")", ")", ";", "session", "(", ")", "->", "flash", "(", "'fields'", ",", "array_get", "(", "$", "response", ",", "'fields'", ",", "[", "]", ")", ")", ";", "// Redirect to provided route.", "return", "redirect", "(", ")", "->", "route", "(", "$", "route", ",", "$", "parameters", ")", "->", "withErrors", "(", "$", "this", "->", "getValidator", "(", ")", ")", "->", "withInput", "(", ")", ";", "}" ]
Get a response to return. @return string|array
[ "Get", "a", "response", "to", "return", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Exceptions/ValidationException.php#L56-L93
29,838
ventoviro/windwalker-core
src/Core/Application/WebApplication.php
WebApplication.dispatch
public function dispatch(Request $request, Response $response, $finalHandler = null) { /** @var AbstractPackage $package */ $package = $this->getPackage(); if (!$package) { throw new RouteNotFoundException('Can not find package to execute.', 404); } return $package->execute($request->getAttribute('_controller'), $request, $response); }
php
public function dispatch(Request $request, Response $response, $finalHandler = null) { /** @var AbstractPackage $package */ $package = $this->getPackage(); if (!$package) { throw new RouteNotFoundException('Can not find package to execute.', 404); } return $package->execute($request->getAttribute('_controller'), $request, $response); }
[ "public", "function", "dispatch", "(", "Request", "$", "request", ",", "Response", "$", "response", ",", "$", "finalHandler", "=", "null", ")", "{", "/** @var AbstractPackage $package */", "$", "package", "=", "$", "this", "->", "getPackage", "(", ")", ";", "if", "(", "!", "$", "package", ")", "{", "throw", "new", "RouteNotFoundException", "(", "'Can not find package to execute.'", ",", "404", ")", ";", "}", "return", "$", "package", "->", "execute", "(", "$", "request", "->", "getAttribute", "(", "'_controller'", ")", ",", "$", "request", ",", "$", "response", ")", ";", "}" ]
Method as the Psr7 WebHttpServer handler. @param Request $request The Psr7 ServerRequest to get request params. @param Response $response The Psr7 Response interface to prepare respond data. @param callable $finalHandler The next handler to support middleware pattern. @return Response The returned response object. @throws \ReflectionException @throws \Windwalker\DI\Exception\DependencyResolutionException @since 3.0
[ "Method", "as", "the", "Psr7", "WebHttpServer", "handler", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Application/WebApplication.php#L230-L240
29,839
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/dissemination/Parameter.php
Parameter.registerTransformation
static public function registerTransformation(iTransformation $transformation) { self::$transformations[$transformation->getName()] = get_class($transformation); print_r(self::$transformations); }
php
static public function registerTransformation(iTransformation $transformation) { self::$transformations[$transformation->getName()] = get_class($transformation); print_r(self::$transformations); }
[ "static", "public", "function", "registerTransformation", "(", "iTransformation", "$", "transformation", ")", "{", "self", "::", "$", "transformations", "[", "$", "transformation", "->", "getName", "(", ")", "]", "=", "get_class", "(", "$", "transformation", ")", ";", "print_r", "(", "self", "::", "$", "transformations", ")", ";", "}" ]
Registers a new transformation @param iTransformation $transformation transformation to be registered
[ "Registers", "a", "new", "transformation" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/Parameter.php#L68-L72
29,840
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/dissemination/Parameter.php
Parameter.value
static public function value(FedoraResource $res, string $valueProp, string $default, array $transformations): string { $value = $default; if ($valueProp !== '') { $matches = $res->getMetadata()->all($valueProp); if (count($matches) > 0) { $value = (string) $matches[0]; } } foreach ($transformations as $i) { $matches = []; preg_match('|^([^(]+)([(].*[)])?$|', $i, $matches); $name = $matches[1]; if (!isset(self::$transformations[$name])) { throw new RuntimeException('unknown transformation'); } $param = [$value]; if (isset($matches[2])) { $tmp = explode(',', substr($matches[2], 1, -1)); foreach ($tmp as $j) { $param[] = trim($j); } } $transformation = new self::$transformations[$name](); $value = $transformation->transform(...$param); } return $value; }
php
static public function value(FedoraResource $res, string $valueProp, string $default, array $transformations): string { $value = $default; if ($valueProp !== '') { $matches = $res->getMetadata()->all($valueProp); if (count($matches) > 0) { $value = (string) $matches[0]; } } foreach ($transformations as $i) { $matches = []; preg_match('|^([^(]+)([(].*[)])?$|', $i, $matches); $name = $matches[1]; if (!isset(self::$transformations[$name])) { throw new RuntimeException('unknown transformation'); } $param = [$value]; if (isset($matches[2])) { $tmp = explode(',', substr($matches[2], 1, -1)); foreach ($tmp as $j) { $param[] = trim($j); } } $transformation = new self::$transformations[$name](); $value = $transformation->transform(...$param); } return $value; }
[ "static", "public", "function", "value", "(", "FedoraResource", "$", "res", ",", "string", "$", "valueProp", ",", "string", "$", "default", ",", "array", "$", "transformations", ")", ":", "string", "{", "$", "value", "=", "$", "default", ";", "if", "(", "$", "valueProp", "!==", "''", ")", "{", "$", "matches", "=", "$", "res", "->", "getMetadata", "(", ")", "->", "all", "(", "$", "valueProp", ")", ";", "if", "(", "count", "(", "$", "matches", ")", ">", "0", ")", "{", "$", "value", "=", "(", "string", ")", "$", "matches", "[", "0", "]", ";", "}", "}", "foreach", "(", "$", "transformations", "as", "$", "i", ")", "{", "$", "matches", "=", "[", "]", ";", "preg_match", "(", "'|^([^(]+)([(].*[)])?$|'", ",", "$", "i", ",", "$", "matches", ")", ";", "$", "name", "=", "$", "matches", "[", "1", "]", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "transformations", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'unknown transformation'", ")", ";", "}", "$", "param", "=", "[", "$", "value", "]", ";", "if", "(", "isset", "(", "$", "matches", "[", "2", "]", ")", ")", "{", "$", "tmp", "=", "explode", "(", "','", ",", "substr", "(", "$", "matches", "[", "2", "]", ",", "1", ",", "-", "1", ")", ")", ";", "foreach", "(", "$", "tmp", "as", "$", "j", ")", "{", "$", "param", "[", "]", "=", "trim", "(", "$", "j", ")", ";", "}", "}", "$", "transformation", "=", "new", "self", "::", "$", "transformations", "[", "$", "name", "]", "(", ")", ";", "$", "value", "=", "$", "transformation", "->", "transform", "(", "...", "$", "param", ")", ";", "}", "return", "$", "value", ";", "}" ]
Returns parameter value for a given resource. @param FedoraResource $res repository resource to return the value for @param string $valueProp RDF property holding the parameter value. If empty, the $default value is used. @param string $default parameter default value @param string $transformations transformations to be applied to the parameter value @return string
[ "Returns", "parameter", "value", "for", "a", "given", "resource", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/Parameter.php#L83-L115
29,841
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/dissemination/Parameter.php
Parameter.getName
public function getName(): string { $meta = $this->getMetadata(); return (string) $meta->getLiteral(RC::titleProp()); }
php
public function getName(): string { $meta = $this->getMetadata(); return (string) $meta->getLiteral(RC::titleProp()); }
[ "public", "function", "getName", "(", ")", ":", "string", "{", "$", "meta", "=", "$", "this", "->", "getMetadata", "(", ")", ";", "return", "(", "string", ")", "$", "meta", "->", "getLiteral", "(", "RC", "::", "titleProp", "(", ")", ")", ";", "}" ]
Returns parameter name @return string
[ "Returns", "parameter", "name" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/Parameter.php#L136-L139
29,842
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/dissemination/Parameter.php
Parameter.getValue
public function getValue(FedoraResource $res, array $transformations = []): string { $overwrite = filter_input(INPUT_GET, $this->getName()); if ($overwrite !== null) { $valueProp = ''; $default = $overwrite; } else { $meta = $this->getMetadata(); $default = $meta->all(RC::get('fedoraServiceParamDefaultValueProp')); $default = count($default) > 0 ? (string) $default[0] : ''; $valueProp = $meta->all(RC::get('fedoraServiceParamRdfPropertyProp')); if (count($valueProp) > 0) { $valueProp = (string) $valueProp[0]; } else { $valueProp = ''; } } return self::value($res, $valueProp, $default, $transformations); }
php
public function getValue(FedoraResource $res, array $transformations = []): string { $overwrite = filter_input(INPUT_GET, $this->getName()); if ($overwrite !== null) { $valueProp = ''; $default = $overwrite; } else { $meta = $this->getMetadata(); $default = $meta->all(RC::get('fedoraServiceParamDefaultValueProp')); $default = count($default) > 0 ? (string) $default[0] : ''; $valueProp = $meta->all(RC::get('fedoraServiceParamRdfPropertyProp')); if (count($valueProp) > 0) { $valueProp = (string) $valueProp[0]; } else { $valueProp = ''; } } return self::value($res, $valueProp, $default, $transformations); }
[ "public", "function", "getValue", "(", "FedoraResource", "$", "res", ",", "array", "$", "transformations", "=", "[", "]", ")", ":", "string", "{", "$", "overwrite", "=", "filter_input", "(", "INPUT_GET", ",", "$", "this", "->", "getName", "(", ")", ")", ";", "if", "(", "$", "overwrite", "!==", "null", ")", "{", "$", "valueProp", "=", "''", ";", "$", "default", "=", "$", "overwrite", ";", "}", "else", "{", "$", "meta", "=", "$", "this", "->", "getMetadata", "(", ")", ";", "$", "default", "=", "$", "meta", "->", "all", "(", "RC", "::", "get", "(", "'fedoraServiceParamDefaultValueProp'", ")", ")", ";", "$", "default", "=", "count", "(", "$", "default", ")", ">", "0", "?", "(", "string", ")", "$", "default", "[", "0", "]", ":", "''", ";", "$", "valueProp", "=", "$", "meta", "->", "all", "(", "RC", "::", "get", "(", "'fedoraServiceParamRdfPropertyProp'", ")", ")", ";", "if", "(", "count", "(", "$", "valueProp", ")", ">", "0", ")", "{", "$", "valueProp", "=", "(", "string", ")", "$", "valueProp", "[", "0", "]", ";", "}", "else", "{", "$", "valueProp", "=", "''", ";", "}", "}", "return", "self", "::", "value", "(", "$", "res", ",", "$", "valueProp", ",", "$", "default", ",", "$", "transformations", ")", ";", "}" ]
Return parameter value for a given repository resource @param FedoraResource $res repository resource to get the value for @param string $transformations transformations to be applied to the value @return string @see transform()
[ "Return", "parameter", "value", "for", "a", "given", "repository", "resource" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/Parameter.php#L148-L165
29,843
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/redmine/Redmine.php
Redmine.redmineFetchLoop
static protected function redmineFetchLoop(Fedora $fedora, bool $progressBar, string $endpoint, string $param): array { if ($progressBar) { $pb = new ProgressBar(null, 10); } $class = get_called_class(); $objects = []; $offset = 0; do { $flag = false; $url = RC::get('redmineApiUrl') . '/' . $endpoint . '.json?offset=' . $offset . '&' . $param; $data = file_get_contents($url); if ($data) { $data = json_decode($data); foreach ($data->$endpoint as $i) { $objects[] = new $class($fedora, $class::redmineId2repoId($i->id), (array) $i); if ($progressBar) { $pb->next(); } } $flag = $data->offset + $data->limit < $data->total_count; $offset += $data->limit; } } while ($flag); if ($progressBar) { $pb->finish(); } return $objects; }
php
static protected function redmineFetchLoop(Fedora $fedora, bool $progressBar, string $endpoint, string $param): array { if ($progressBar) { $pb = new ProgressBar(null, 10); } $class = get_called_class(); $objects = []; $offset = 0; do { $flag = false; $url = RC::get('redmineApiUrl') . '/' . $endpoint . '.json?offset=' . $offset . '&' . $param; $data = file_get_contents($url); if ($data) { $data = json_decode($data); foreach ($data->$endpoint as $i) { $objects[] = new $class($fedora, $class::redmineId2repoId($i->id), (array) $i); if ($progressBar) { $pb->next(); } } $flag = $data->offset + $data->limit < $data->total_count; $offset += $data->limit; } } while ($flag); if ($progressBar) { $pb->finish(); } return $objects; }
[ "static", "protected", "function", "redmineFetchLoop", "(", "Fedora", "$", "fedora", ",", "bool", "$", "progressBar", ",", "string", "$", "endpoint", ",", "string", "$", "param", ")", ":", "array", "{", "if", "(", "$", "progressBar", ")", "{", "$", "pb", "=", "new", "ProgressBar", "(", "null", ",", "10", ")", ";", "}", "$", "class", "=", "get_called_class", "(", ")", ";", "$", "objects", "=", "[", "]", ";", "$", "offset", "=", "0", ";", "do", "{", "$", "flag", "=", "false", ";", "$", "url", "=", "RC", "::", "get", "(", "'redmineApiUrl'", ")", ".", "'/'", ".", "$", "endpoint", ".", "'.json?offset='", ".", "$", "offset", ".", "'&'", ".", "$", "param", ";", "$", "data", "=", "file_get_contents", "(", "$", "url", ")", ";", "if", "(", "$", "data", ")", "{", "$", "data", "=", "json_decode", "(", "$", "data", ")", ";", "foreach", "(", "$", "data", "->", "$", "endpoint", "as", "$", "i", ")", "{", "$", "objects", "[", "]", "=", "new", "$", "class", "(", "$", "fedora", ",", "$", "class", "::", "redmineId2repoId", "(", "$", "i", "->", "id", ")", ",", "(", "array", ")", "$", "i", ")", ";", "if", "(", "$", "progressBar", ")", "{", "$", "pb", "->", "next", "(", ")", ";", "}", "}", "$", "flag", "=", "$", "data", "->", "offset", "+", "$", "data", "->", "limit", "<", "$", "data", "->", "total_count", ";", "$", "offset", "+=", "$", "data", "->", "limit", ";", "}", "}", "while", "(", "$", "flag", ")", ";", "if", "(", "$", "progressBar", ")", "{", "$", "pb", "->", "finish", "(", ")", ";", "}", "return", "$", "objects", ";", "}" ]
Fetches all objects from a given Redmine API endpoint. Redmine limits number of results returned by one API call to 100 therefore it may be needed to call the API many times. @param Fedora $fedora @param bool $progressBar @param string $endpoint @param string $param @return array
[ "Fetches", "all", "objects", "from", "a", "given", "Redmine", "API", "endpoint", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/redmine/Redmine.php#L113-L142
29,844
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/redmine/Redmine.php
Redmine.fetchData
static protected function fetchData(string $url): array { $url .= '.json?key=' . urlencode(RC::get('redmineApiKey')); $data = file_get_contents($url); if ($data) { $data = (array) json_decode($data); $data = array_pop($data); return (array) $data; } throw new RuntimeException('Fetching data failed'); }
php
static protected function fetchData(string $url): array { $url .= '.json?key=' . urlencode(RC::get('redmineApiKey')); $data = file_get_contents($url); if ($data) { $data = (array) json_decode($data); $data = array_pop($data); return (array) $data; } throw new RuntimeException('Fetching data failed'); }
[ "static", "protected", "function", "fetchData", "(", "string", "$", "url", ")", ":", "array", "{", "$", "url", ".=", "'.json?key='", ".", "urlencode", "(", "RC", "::", "get", "(", "'redmineApiKey'", ")", ")", ";", "$", "data", "=", "file_get_contents", "(", "$", "url", ")", ";", "if", "(", "$", "data", ")", "{", "$", "data", "=", "(", "array", ")", "json_decode", "(", "$", "data", ")", ";", "$", "data", "=", "array_pop", "(", "$", "data", ")", ";", "return", "(", "array", ")", "$", "data", ";", "}", "throw", "new", "RuntimeException", "(", "'Fetching data failed'", ")", ";", "}" ]
Fetches given Redmine entity description from the Redmine API URI. @param string $url @return array @throws RuntimeException
[ "Fetches", "given", "Redmine", "entity", "description", "from", "the", "Redmine", "API", "URI", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/redmine/Redmine.php#L150-L159
29,845
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/redmine/Redmine.php
Redmine.getMetadata
public function getMetadata(): Resource { $graph = new Graph(); $res = $graph->resource('.'); $res->addResource(RC::idProp(), $this->getId()); $res->addResource(self::$seeAlsoProp, $this->getId()); $classes = RC::get('redmineClasses'); $res->addResource('rdf:type', $classes[get_called_class()]); foreach (self::$propMap as $redmineProp => $rdfProp) { $value = null; if (isset($this->data[$redmineProp])) { $value = $this->data[$redmineProp]; } elseif (isset($this->data['custom_fields'])) { foreach ($this->data['custom_fields'] as $cf) { if ($cf->name === $redmineProp && isset($cf->value)) { $value = $cf->value; } } } if (is_object($value)) { $value = $value->id; } if ($value !== null) { if (!is_array($value)) { $value = [$value]; } foreach ($value as $v) { try { $this->addValue($res, $rdfProp, $v); } catch (RuntimeException $e) { echo "\n" . 'Adding value for the ' . $redmineProp . ' of the ' . $this->data['id'] . ' failed: ' . $e->getMessage() . "\n"; throw $e; } } } } return $res; }
php
public function getMetadata(): Resource { $graph = new Graph(); $res = $graph->resource('.'); $res->addResource(RC::idProp(), $this->getId()); $res->addResource(self::$seeAlsoProp, $this->getId()); $classes = RC::get('redmineClasses'); $res->addResource('rdf:type', $classes[get_called_class()]); foreach (self::$propMap as $redmineProp => $rdfProp) { $value = null; if (isset($this->data[$redmineProp])) { $value = $this->data[$redmineProp]; } elseif (isset($this->data['custom_fields'])) { foreach ($this->data['custom_fields'] as $cf) { if ($cf->name === $redmineProp && isset($cf->value)) { $value = $cf->value; } } } if (is_object($value)) { $value = $value->id; } if ($value !== null) { if (!is_array($value)) { $value = [$value]; } foreach ($value as $v) { try { $this->addValue($res, $rdfProp, $v); } catch (RuntimeException $e) { echo "\n" . 'Adding value for the ' . $redmineProp . ' of the ' . $this->data['id'] . ' failed: ' . $e->getMessage() . "\n"; throw $e; } } } } return $res; }
[ "public", "function", "getMetadata", "(", ")", ":", "Resource", "{", "$", "graph", "=", "new", "Graph", "(", ")", ";", "$", "res", "=", "$", "graph", "->", "resource", "(", "'.'", ")", ";", "$", "res", "->", "addResource", "(", "RC", "::", "idProp", "(", ")", ",", "$", "this", "->", "getId", "(", ")", ")", ";", "$", "res", "->", "addResource", "(", "self", "::", "$", "seeAlsoProp", ",", "$", "this", "->", "getId", "(", ")", ")", ";", "$", "classes", "=", "RC", "::", "get", "(", "'redmineClasses'", ")", ";", "$", "res", "->", "addResource", "(", "'rdf:type'", ",", "$", "classes", "[", "get_called_class", "(", ")", "]", ")", ";", "foreach", "(", "self", "::", "$", "propMap", "as", "$", "redmineProp", "=>", "$", "rdfProp", ")", "{", "$", "value", "=", "null", ";", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "$", "redmineProp", "]", ")", ")", "{", "$", "value", "=", "$", "this", "->", "data", "[", "$", "redmineProp", "]", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "data", "[", "'custom_fields'", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "data", "[", "'custom_fields'", "]", "as", "$", "cf", ")", "{", "if", "(", "$", "cf", "->", "name", "===", "$", "redmineProp", "&&", "isset", "(", "$", "cf", "->", "value", ")", ")", "{", "$", "value", "=", "$", "cf", "->", "value", ";", "}", "}", "}", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "$", "value", "=", "$", "value", "->", "id", ";", "}", "if", "(", "$", "value", "!==", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "[", "$", "value", "]", ";", "}", "foreach", "(", "$", "value", "as", "$", "v", ")", "{", "try", "{", "$", "this", "->", "addValue", "(", "$", "res", ",", "$", "rdfProp", ",", "$", "v", ")", ";", "}", "catch", "(", "RuntimeException", "$", "e", ")", "{", "echo", "\"\\n\"", ".", "'Adding value for the '", ".", "$", "redmineProp", ".", "' of the '", ".", "$", "this", "->", "data", "[", "'id'", "]", ".", "' failed: '", ".", "$", "e", "->", "getMessage", "(", ")", ".", "\"\\n\"", ";", "throw", "$", "e", ";", "}", "}", "}", "}", "return", "$", "res", ";", "}" ]
Maps Redmine's object properties to and RDF graph. If resource already exists mapping must preserve already existing properties (especialy fedoraId) and also take care about deleting ones being "updated". That is because in RDF there is nothing like updating a triple. Triples can be only deleted or added. "Updating a triple" means deleting its old value and inserting the new one. @return \EasyRdf\Resource
[ "Maps", "Redmine", "s", "object", "properties", "to", "and", "RDF", "graph", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/redmine/Redmine.php#L207-L246
29,846
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/redmine/Redmine.php
Redmine.addValue
private function addValue(Resource $res, stdClass $prop, string $value) { if (!$value) { return; } $value = str_replace('\\', '/', $value); // ugly workaround for windows-like paths; should be applied only to location_path property if ($prop->template !== '') { $value = str_replace(['%REDMINE_URL%', '%VALUE%'], [RC::get('redmineApiUrl'), $value], $prop->template); } if ($prop->redmineClass) { $class = $prop->redmineClass === 'self' ? get_class($this) : $prop->redmineClass; $obj = new $class($this->fedora, $class::redmineId2repoId($value)); $value = $obj->getResource(true)->getId(); } if ($prop->class === 'dataProperty') { $res->addLiteral($prop->uri, $value); } else { if (preg_match('|^[a-zA-Z][a-zA-Z0-9]*:|', $value)) { $res->addResource($prop->uri, $value); } else { throw new RuntimeException('dataProperty must be an URI (' . $value . ')'); } } }
php
private function addValue(Resource $res, stdClass $prop, string $value) { if (!$value) { return; } $value = str_replace('\\', '/', $value); // ugly workaround for windows-like paths; should be applied only to location_path property if ($prop->template !== '') { $value = str_replace(['%REDMINE_URL%', '%VALUE%'], [RC::get('redmineApiUrl'), $value], $prop->template); } if ($prop->redmineClass) { $class = $prop->redmineClass === 'self' ? get_class($this) : $prop->redmineClass; $obj = new $class($this->fedora, $class::redmineId2repoId($value)); $value = $obj->getResource(true)->getId(); } if ($prop->class === 'dataProperty') { $res->addLiteral($prop->uri, $value); } else { if (preg_match('|^[a-zA-Z][a-zA-Z0-9]*:|', $value)) { $res->addResource($prop->uri, $value); } else { throw new RuntimeException('dataProperty must be an URI (' . $value . ')'); } } }
[ "private", "function", "addValue", "(", "Resource", "$", "res", ",", "stdClass", "$", "prop", ",", "string", "$", "value", ")", "{", "if", "(", "!", "$", "value", ")", "{", "return", ";", "}", "$", "value", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "value", ")", ";", "// ugly workaround for windows-like paths; should be applied only to location_path property", "if", "(", "$", "prop", "->", "template", "!==", "''", ")", "{", "$", "value", "=", "str_replace", "(", "[", "'%REDMINE_URL%'", ",", "'%VALUE%'", "]", ",", "[", "RC", "::", "get", "(", "'redmineApiUrl'", ")", ",", "$", "value", "]", ",", "$", "prop", "->", "template", ")", ";", "}", "if", "(", "$", "prop", "->", "redmineClass", ")", "{", "$", "class", "=", "$", "prop", "->", "redmineClass", "===", "'self'", "?", "get_class", "(", "$", "this", ")", ":", "$", "prop", "->", "redmineClass", ";", "$", "obj", "=", "new", "$", "class", "(", "$", "this", "->", "fedora", ",", "$", "class", "::", "redmineId2repoId", "(", "$", "value", ")", ")", ";", "$", "value", "=", "$", "obj", "->", "getResource", "(", "true", ")", "->", "getId", "(", ")", ";", "}", "if", "(", "$", "prop", "->", "class", "===", "'dataProperty'", ")", "{", "$", "res", "->", "addLiteral", "(", "$", "prop", "->", "uri", ",", "$", "value", ")", ";", "}", "else", "{", "if", "(", "preg_match", "(", "'|^[a-zA-Z][a-zA-Z0-9]*:|'", ",", "$", "value", ")", ")", "{", "$", "res", "->", "addResource", "(", "$", "prop", "->", "uri", ",", "$", "value", ")", ";", "}", "else", "{", "throw", "new", "RuntimeException", "(", "'dataProperty must be an URI ('", ".", "$", "value", ".", "')'", ")", ";", "}", "}", "}" ]
Adds RDF property to the metadata according to mapping rules. @param EasyRdf\Resource $res metadata @param stdClass $prop property mapping object @param string $value Redmine property value @throws RuntimeException
[ "Adds", "RDF", "property", "to", "the", "metadata", "according", "to", "mapping", "rules", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/redmine/Redmine.php#L256-L281
29,847
polyfony-inc/polyfony
Private/Storage/Defaults/Models/Accounts.php
Accounts.withErrors
public static function withErrors() :array { return self::_select() ->whereNotEmpty('last_failure_date') ->whereHigherThan('last_failure_date', time() - self::RECENT_FAILURE ) ->limitTo(0, 10) ->orderBy(['last_failure_date'=>'DESC']) ->execute(); }
php
public static function withErrors() :array { return self::_select() ->whereNotEmpty('last_failure_date') ->whereHigherThan('last_failure_date', time() - self::RECENT_FAILURE ) ->limitTo(0, 10) ->orderBy(['last_failure_date'=>'DESC']) ->execute(); }
[ "public", "static", "function", "withErrors", "(", ")", ":", "array", "{", "return", "self", "::", "_select", "(", ")", "->", "whereNotEmpty", "(", "'last_failure_date'", ")", "->", "whereHigherThan", "(", "'last_failure_date'", ",", "time", "(", ")", "-", "self", "::", "RECENT_FAILURE", ")", "->", "limitTo", "(", "0", ",", "10", ")", "->", "orderBy", "(", "[", "'last_failure_date'", "=>", "'DESC'", "]", ")", "->", "execute", "(", ")", ";", "}" ]
accounts that have had issues login in recently
[ "accounts", "that", "have", "had", "issues", "login", "in", "recently" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Storage/Defaults/Models/Accounts.php#L83-L92
29,848
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/file/File.php
File.detectPathEncoding
static private function detectPathEncoding() { if (self::$pathEncoding) { return; } foreach (explode(';', setlocale(LC_ALL, 0)) as $i) { $i = explode('=', $i); if ($i[0] === 'LC_CTYPE') { $tmp = preg_replace('|^.*[.]|', '', $i[1]); if (is_numeric($tmp)) { self::$pathEncoding = 'windows-' . $tmp; break; } else if (preg_match('|utf-?8|i', $tmp)) { self::$pathEncoding = 'utf-8'; break; } else { throw new RuntimeException('Operation system encoding can not be determined'); } } } }
php
static private function detectPathEncoding() { if (self::$pathEncoding) { return; } foreach (explode(';', setlocale(LC_ALL, 0)) as $i) { $i = explode('=', $i); if ($i[0] === 'LC_CTYPE') { $tmp = preg_replace('|^.*[.]|', '', $i[1]); if (is_numeric($tmp)) { self::$pathEncoding = 'windows-' . $tmp; break; } else if (preg_match('|utf-?8|i', $tmp)) { self::$pathEncoding = 'utf-8'; break; } else { throw new RuntimeException('Operation system encoding can not be determined'); } } } }
[ "static", "private", "function", "detectPathEncoding", "(", ")", "{", "if", "(", "self", "::", "$", "pathEncoding", ")", "{", "return", ";", "}", "foreach", "(", "explode", "(", "';'", ",", "setlocale", "(", "LC_ALL", ",", "0", ")", ")", "as", "$", "i", ")", "{", "$", "i", "=", "explode", "(", "'='", ",", "$", "i", ")", ";", "if", "(", "$", "i", "[", "0", "]", "===", "'LC_CTYPE'", ")", "{", "$", "tmp", "=", "preg_replace", "(", "'|^.*[.]|'", ",", "''", ",", "$", "i", "[", "1", "]", ")", ";", "if", "(", "is_numeric", "(", "$", "tmp", ")", ")", "{", "self", "::", "$", "pathEncoding", "=", "'windows-'", ".", "$", "tmp", ";", "break", ";", "}", "else", "if", "(", "preg_match", "(", "'|utf-?8|i'", ",", "$", "tmp", ")", ")", "{", "self", "::", "$", "pathEncoding", "=", "'utf-8'", ";", "break", ";", "}", "else", "{", "throw", "new", "RuntimeException", "(", "'Operation system encoding can not be determined'", ")", ";", "}", "}", "}", "}" ]
Tries to detect path encoding used in the operating system by looking into locale settings. @throws RuntimeException
[ "Tries", "to", "detect", "path", "encoding", "used", "in", "the", "operating", "system", "by", "looking", "into", "locale", "settings", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/file/File.php#L60-L79
29,849
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/file/File.php
File.getMetadata
public function getMetadata(): Resource { $graph = new Graph(); $meta = $graph->resource('.'); $meta->addResource(RC::idProp(), $this->getId()); if ($this->class != '') { $meta->addResource('http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $this->class); } if ($this->parent) { $meta->addResource(RC::relProp(), $this->parent); } $meta->addLiteral(RC::locProp(), self::getRelPath(self::sanitizePath($this->path))); $meta->addLiteral(RC::titleProp(), basename($this->path)); $meta->addLiteral('http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#filename', basename($this->path)); if (is_file($this->path)) { $mime = $this->getMime(); if ($mime) { $meta->addLiteral('http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasMimeType', $mime); } $meta->addLiteral(RC::get('fedoraSizeProp'), filesize($this->path)); } if ($this->metaLookup) { $addMeta = $this->metaLookup->getMetadata($this->path, $meta, $this->metaLookupRequire); $meta->merge($addMeta, array(RC::idProp())); } return $meta; }
php
public function getMetadata(): Resource { $graph = new Graph(); $meta = $graph->resource('.'); $meta->addResource(RC::idProp(), $this->getId()); if ($this->class != '') { $meta->addResource('http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $this->class); } if ($this->parent) { $meta->addResource(RC::relProp(), $this->parent); } $meta->addLiteral(RC::locProp(), self::getRelPath(self::sanitizePath($this->path))); $meta->addLiteral(RC::titleProp(), basename($this->path)); $meta->addLiteral('http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#filename', basename($this->path)); if (is_file($this->path)) { $mime = $this->getMime(); if ($mime) { $meta->addLiteral('http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasMimeType', $mime); } $meta->addLiteral(RC::get('fedoraSizeProp'), filesize($this->path)); } if ($this->metaLookup) { $addMeta = $this->metaLookup->getMetadata($this->path, $meta, $this->metaLookupRequire); $meta->merge($addMeta, array(RC::idProp())); } return $meta; }
[ "public", "function", "getMetadata", "(", ")", ":", "Resource", "{", "$", "graph", "=", "new", "Graph", "(", ")", ";", "$", "meta", "=", "$", "graph", "->", "resource", "(", "'.'", ")", ";", "$", "meta", "->", "addResource", "(", "RC", "::", "idProp", "(", ")", ",", "$", "this", "->", "getId", "(", ")", ")", ";", "if", "(", "$", "this", "->", "class", "!=", "''", ")", "{", "$", "meta", "->", "addResource", "(", "'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'", ",", "$", "this", "->", "class", ")", ";", "}", "if", "(", "$", "this", "->", "parent", ")", "{", "$", "meta", "->", "addResource", "(", "RC", "::", "relProp", "(", ")", ",", "$", "this", "->", "parent", ")", ";", "}", "$", "meta", "->", "addLiteral", "(", "RC", "::", "locProp", "(", ")", ",", "self", "::", "getRelPath", "(", "self", "::", "sanitizePath", "(", "$", "this", "->", "path", ")", ")", ")", ";", "$", "meta", "->", "addLiteral", "(", "RC", "::", "titleProp", "(", ")", ",", "basename", "(", "$", "this", "->", "path", ")", ")", ";", "$", "meta", "->", "addLiteral", "(", "'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#filename'", ",", "basename", "(", "$", "this", "->", "path", ")", ")", ";", "if", "(", "is_file", "(", "$", "this", "->", "path", ")", ")", "{", "$", "mime", "=", "$", "this", "->", "getMime", "(", ")", ";", "if", "(", "$", "mime", ")", "{", "$", "meta", "->", "addLiteral", "(", "'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasMimeType'", ",", "$", "mime", ")", ";", "}", "$", "meta", "->", "addLiteral", "(", "RC", "::", "get", "(", "'fedoraSizeProp'", ")", ",", "filesize", "(", "$", "this", "->", "path", ")", ")", ";", "}", "if", "(", "$", "this", "->", "metaLookup", ")", "{", "$", "addMeta", "=", "$", "this", "->", "metaLookup", "->", "getMetadata", "(", "$", "this", "->", "path", ",", "$", "meta", ",", "$", "this", "->", "metaLookupRequire", ")", ";", "$", "meta", "->", "merge", "(", "$", "addMeta", ",", "array", "(", "RC", "::", "idProp", "(", ")", ")", ")", ";", "}", "return", "$", "meta", ";", "}" ]
Creates RDF metadata for a file. Can use metadata lookup mechanism - see the setMetaLookup() method. @return Resource @see setMetaLookup()
[ "Creates", "RDF", "metadata", "for", "a", "file", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/file/File.php#L171-L203
29,850
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/file/File.php
File.getMime
public function getMime() { switch(strtolower(pathinfo($this->path, PATHINFO_EXTENSION))) { case 'json': $mime = 'application/json'; break; case 'geojson': $mime = 'application/vnd.geo+json'; break; default: $mime = @mime_content_type($this->path); } return $mime; }
php
public function getMime() { switch(strtolower(pathinfo($this->path, PATHINFO_EXTENSION))) { case 'json': $mime = 'application/json'; break; case 'geojson': $mime = 'application/vnd.geo+json'; break; default: $mime = @mime_content_type($this->path); } return $mime; }
[ "public", "function", "getMime", "(", ")", "{", "switch", "(", "strtolower", "(", "pathinfo", "(", "$", "this", "->", "path", ",", "PATHINFO_EXTENSION", ")", ")", ")", "{", "case", "'json'", ":", "$", "mime", "=", "'application/json'", ";", "break", ";", "case", "'geojson'", ":", "$", "mime", "=", "'application/vnd.geo+json'", ";", "break", ";", "default", ":", "$", "mime", "=", "@", "mime_content_type", "(", "$", "this", "->", "path", ")", ";", "}", "return", "$", "mime", ";", "}" ]
Returns file's mime type @return string
[ "Returns", "file", "s", "mime", "type" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/file/File.php#L225-L237
29,851
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/file/File.php
File.mergeMetadata
protected function mergeMetadata(Resource $current, Resource $new): Resource { // title handling logic: // if title is not provided by an external metadata (also when there is // no external metadata) and current $oldTitle = $current->getLiteral(RC::titleProp()); $extTitle = null; $meta = $current->merge($new, array(RC::idProp())); if ($this->metaLookup) { $extMeta = $this->metaLookup->getMetadata($this->path, $new, $this->metaLookupRequire); $extTitle = $extMeta->getLiteral(RC::titleProp()); } if ($oldTitle !== null && $extTitle === null) { $meta->delete(RC::titleProp()); $meta->addLiteral(RC::titleProp(), $oldTitle, $oldTitle->getLang()); } return $meta; }
php
protected function mergeMetadata(Resource $current, Resource $new): Resource { // title handling logic: // if title is not provided by an external metadata (also when there is // no external metadata) and current $oldTitle = $current->getLiteral(RC::titleProp()); $extTitle = null; $meta = $current->merge($new, array(RC::idProp())); if ($this->metaLookup) { $extMeta = $this->metaLookup->getMetadata($this->path, $new, $this->metaLookupRequire); $extTitle = $extMeta->getLiteral(RC::titleProp()); } if ($oldTitle !== null && $extTitle === null) { $meta->delete(RC::titleProp()); $meta->addLiteral(RC::titleProp(), $oldTitle, $oldTitle->getLang()); } return $meta; }
[ "protected", "function", "mergeMetadata", "(", "Resource", "$", "current", ",", "Resource", "$", "new", ")", ":", "Resource", "{", "// title handling logic:", "// if title is not provided by an external metadata (also when there is", "// no external metadata) and current", "$", "oldTitle", "=", "$", "current", "->", "getLiteral", "(", "RC", "::", "titleProp", "(", ")", ")", ";", "$", "extTitle", "=", "null", ";", "$", "meta", "=", "$", "current", "->", "merge", "(", "$", "new", ",", "array", "(", "RC", "::", "idProp", "(", ")", ")", ")", ";", "if", "(", "$", "this", "->", "metaLookup", ")", "{", "$", "extMeta", "=", "$", "this", "->", "metaLookup", "->", "getMetadata", "(", "$", "this", "->", "path", ",", "$", "new", ",", "$", "this", "->", "metaLookupRequire", ")", ";", "$", "extTitle", "=", "$", "extMeta", "->", "getLiteral", "(", "RC", "::", "titleProp", "(", ")", ")", ";", "}", "if", "(", "$", "oldTitle", "!==", "null", "&&", "$", "extTitle", "===", "null", ")", "{", "$", "meta", "->", "delete", "(", "RC", "::", "titleProp", "(", ")", ")", ";", "$", "meta", "->", "addLiteral", "(", "RC", "::", "titleProp", "(", ")", ",", "$", "oldTitle", ",", "$", "oldTitle", "->", "getLang", "(", ")", ")", ";", "}", "return", "$", "meta", ";", "}" ]
Merges metadata coming from the Fedora and generated by the class. Preserves the resource title if it already exists. @param Resource $current current Fedora resource metadata @param Resource $new metadata generated by the class @return Resource final metadata
[ "Merges", "metadata", "coming", "from", "the", "Fedora", "and", "generated", "by", "the", "class", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/file/File.php#L263-L282
29,852
polyfony-inc/polyfony
Private/Storage/Defaults/Bundles/Shared/Controllers/Exception.php
ExceptionController.exceptionAction
public function exceptionAction() { // get the exception $this->Exception = Store\Request::get('exception'); // if the exception is not a 404 or a 403 (the most common and non important) if( $this->Exception->getCode() < 401 || $this->Exception->getCode() > 404 ) { // log the exception Logger::critical( $this->Exception->getCode() . ' '. $this->Exception->getMessage(), $this->Exception->getTrace() ); } // error occured while requesting something else than html if(!in_array( Response::getType(), ['html','html-page'] )) { // change the type to plaintext Response::setType('text'); // set the stack a string Response::setContent( $this->Exception->getCode() . "\n". $this->Exception->getMessage() . "\n". $this->Exception ); // render as is Response::render(); } // error occured normally else { // disable space removal for the trace stack Config::set('response','minify', 0); // reset already output data (very important, because of content-length) Response::setType('html-page'); // proper title and assets Response\HTML::set([ 'metas' =>[ 'title'=> $this->Exception->getCode() . ', ' . Locales::get($this->Exception->getMessage()) ], 'scripts' =>[ '//code.jquery.com/jquery-3.3.1.slim.min.js', '//stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js' ], 'links' =>[ '//stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css', '//use.fontawesome.com/releases/v5.3.1/css/all.css' ] ]); // error is of type forbidden/bad request if( $this->Exception->getCode() >= 400 && $this->Exception->getCode() <= 403 ) { $this->icon = 'fa fa-ban'; } // error is of type internal error elseif( $this->Exception->getCode() >= 500 && $this->Exception->getCode() <= 599 ) { $this->icon = 'fa fa-bug'; } // error is not found elseif( $this->Exception->getCode() == 404 ) { $this->icon = 'fa fa-exclamation-circle'; } // any other type of errors else { $this->icon = 'fa fa-exclamation-triangle'; } // pass to the exception view $this->view('Exception'); } }
php
public function exceptionAction() { // get the exception $this->Exception = Store\Request::get('exception'); // if the exception is not a 404 or a 403 (the most common and non important) if( $this->Exception->getCode() < 401 || $this->Exception->getCode() > 404 ) { // log the exception Logger::critical( $this->Exception->getCode() . ' '. $this->Exception->getMessage(), $this->Exception->getTrace() ); } // error occured while requesting something else than html if(!in_array( Response::getType(), ['html','html-page'] )) { // change the type to plaintext Response::setType('text'); // set the stack a string Response::setContent( $this->Exception->getCode() . "\n". $this->Exception->getMessage() . "\n". $this->Exception ); // render as is Response::render(); } // error occured normally else { // disable space removal for the trace stack Config::set('response','minify', 0); // reset already output data (very important, because of content-length) Response::setType('html-page'); // proper title and assets Response\HTML::set([ 'metas' =>[ 'title'=> $this->Exception->getCode() . ', ' . Locales::get($this->Exception->getMessage()) ], 'scripts' =>[ '//code.jquery.com/jquery-3.3.1.slim.min.js', '//stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js' ], 'links' =>[ '//stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css', '//use.fontawesome.com/releases/v5.3.1/css/all.css' ] ]); // error is of type forbidden/bad request if( $this->Exception->getCode() >= 400 && $this->Exception->getCode() <= 403 ) { $this->icon = 'fa fa-ban'; } // error is of type internal error elseif( $this->Exception->getCode() >= 500 && $this->Exception->getCode() <= 599 ) { $this->icon = 'fa fa-bug'; } // error is not found elseif( $this->Exception->getCode() == 404 ) { $this->icon = 'fa fa-exclamation-circle'; } // any other type of errors else { $this->icon = 'fa fa-exclamation-triangle'; } // pass to the exception view $this->view('Exception'); } }
[ "public", "function", "exceptionAction", "(", ")", "{", "// get the exception", "$", "this", "->", "Exception", "=", "Store", "\\", "Request", "::", "get", "(", "'exception'", ")", ";", "// if the exception is not a 404 or a 403 (the most common and non important)", "if", "(", "$", "this", "->", "Exception", "->", "getCode", "(", ")", "<", "401", "||", "$", "this", "->", "Exception", "->", "getCode", "(", ")", ">", "404", ")", "{", "// log the exception", "Logger", "::", "critical", "(", "$", "this", "->", "Exception", "->", "getCode", "(", ")", ".", "' '", ".", "$", "this", "->", "Exception", "->", "getMessage", "(", ")", ",", "$", "this", "->", "Exception", "->", "getTrace", "(", ")", ")", ";", "}", "// error occured while requesting something else than html", "if", "(", "!", "in_array", "(", "Response", "::", "getType", "(", ")", ",", "[", "'html'", ",", "'html-page'", "]", ")", ")", "{", "// change the type to plaintext", "Response", "::", "setType", "(", "'text'", ")", ";", "// set the stack a string", "Response", "::", "setContent", "(", "$", "this", "->", "Exception", "->", "getCode", "(", ")", ".", "\"\\n\"", ".", "$", "this", "->", "Exception", "->", "getMessage", "(", ")", ".", "\"\\n\"", ".", "$", "this", "->", "Exception", ")", ";", "// render as is", "Response", "::", "render", "(", ")", ";", "}", "// error occured normally", "else", "{", "// disable space removal for the trace stack", "Config", "::", "set", "(", "'response'", ",", "'minify'", ",", "0", ")", ";", "// reset already output data (very important, because of content-length)", "Response", "::", "setType", "(", "'html-page'", ")", ";", "// proper title and assets", "Response", "\\", "HTML", "::", "set", "(", "[", "'metas'", "=>", "[", "'title'", "=>", "$", "this", "->", "Exception", "->", "getCode", "(", ")", ".", "', '", ".", "Locales", "::", "get", "(", "$", "this", "->", "Exception", "->", "getMessage", "(", ")", ")", "]", ",", "'scripts'", "=>", "[", "'//code.jquery.com/jquery-3.3.1.slim.min.js'", ",", "'//stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js'", "]", ",", "'links'", "=>", "[", "'//stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css'", ",", "'//use.fontawesome.com/releases/v5.3.1/css/all.css'", "]", "]", ")", ";", "// error is of type forbidden/bad request", "if", "(", "$", "this", "->", "Exception", "->", "getCode", "(", ")", ">=", "400", "&&", "$", "this", "->", "Exception", "->", "getCode", "(", ")", "<=", "403", ")", "{", "$", "this", "->", "icon", "=", "'fa fa-ban'", ";", "}", "// error is of type internal error", "elseif", "(", "$", "this", "->", "Exception", "->", "getCode", "(", ")", ">=", "500", "&&", "$", "this", "->", "Exception", "->", "getCode", "(", ")", "<=", "599", ")", "{", "$", "this", "->", "icon", "=", "'fa fa-bug'", ";", "}", "// error is not found", "elseif", "(", "$", "this", "->", "Exception", "->", "getCode", "(", ")", "==", "404", ")", "{", "$", "this", "->", "icon", "=", "'fa fa-exclamation-circle'", ";", "}", "// any other type of errors", "else", "{", "$", "this", "->", "icon", "=", "'fa fa-exclamation-triangle'", ";", "}", "// pass to the exception view", "$", "this", "->", "view", "(", "'Exception'", ")", ";", "}", "}" ]
this exception action is quite generic and can be kept for production
[ "this", "exception", "action", "is", "quite", "generic", "and", "can", "be", "kept", "for", "production" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Storage/Defaults/Bundles/Shared/Controllers/Exception.php#L13-L96
29,853
ventoviro/windwalker-core
src/Core/Logger/Monolog/MessageHandler.php
MessageHandler.handle
public function handle(array $record) { if (!$this->isHandling($record)) { return false; } $type = $this->types[strtolower($record['level_name'])]; $this->app->addMessage($record['message'], $type); return false === $this->bubble; }
php
public function handle(array $record) { if (!$this->isHandling($record)) { return false; } $type = $this->types[strtolower($record['level_name'])]; $this->app->addMessage($record['message'], $type); return false === $this->bubble; }
[ "public", "function", "handle", "(", "array", "$", "record", ")", "{", "if", "(", "!", "$", "this", "->", "isHandling", "(", "$", "record", ")", ")", "{", "return", "false", ";", "}", "$", "type", "=", "$", "this", "->", "types", "[", "strtolower", "(", "$", "record", "[", "'level_name'", "]", ")", "]", ";", "$", "this", "->", "app", "->", "addMessage", "(", "$", "record", "[", "'message'", "]", ",", "$", "type", ")", ";", "return", "false", "===", "$", "this", "->", "bubble", ";", "}" ]
Handles a record. All records may be passed to this method, and the handler should discard those that it does not want to handle. The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record. @param array $record The record to handle @return Boolean true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
[ "Handles", "a", "record", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Logger/Monolog/MessageHandler.php#L77-L88
29,854
polyfony-inc/polyfony
Private/Polyfony/Request.php
Request.setUrlParameter
public static function setUrlParameter(string $key, $value=null) :void { // set the value self::$_get[$key] = $value; }
php
public static function setUrlParameter(string $key, $value=null) :void { // set the value self::$_get[$key] = $value; }
[ "public", "static", "function", "setUrlParameter", "(", "string", "$", "key", ",", "$", "value", "=", "null", ")", ":", "void", "{", "// set the value", "self", "::", "$", "_get", "[", "$", "key", "]", "=", "$", "value", ";", "}" ]
rarely used but can allow to artificially set a get parameter
[ "rarely", "used", "but", "can", "allow", "to", "artificially", "set", "a", "get", "parameter" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Request.php#L122-L127
29,855
polyfony-inc/polyfony
Private/Polyfony/Request.php
Request.header
public static function header(string $variable, $default=null) { return isset(self::$_headers[$variable]) ? self::$_headers[$variable] : $default; }
php
public static function header(string $variable, $default=null) { return isset(self::$_headers[$variable]) ? self::$_headers[$variable] : $default; }
[ "public", "static", "function", "header", "(", "string", "$", "variable", ",", "$", "default", "=", "null", ")", "{", "return", "isset", "(", "self", "::", "$", "_headers", "[", "$", "variable", "]", ")", "?", "self", "::", "$", "_headers", "[", "$", "variable", "]", ":", "$", "default", ";", "}" ]
Get a single Header variable. @access public @param string $variable The variable we wish to return. @param mixed $default If the variable is not found, this is returned. @return mixed @static
[ "Get", "a", "single", "Header", "variable", "." ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Request.php#L146-L150
29,856
polyfony-inc/polyfony
Private/Polyfony/Request.php
Request.get
public static function get(string $variable, $default = null) { return isset(self::$_get[$variable]) ? urldecode(self::$_get[$variable]) : $default; }
php
public static function get(string $variable, $default = null) { return isset(self::$_get[$variable]) ? urldecode(self::$_get[$variable]) : $default; }
[ "public", "static", "function", "get", "(", "string", "$", "variable", ",", "$", "default", "=", "null", ")", "{", "return", "isset", "(", "self", "::", "$", "_get", "[", "$", "variable", "]", ")", "?", "urldecode", "(", "self", "::", "$", "_get", "[", "$", "variable", "]", ")", ":", "$", "default", ";", "}" ]
Get a single GET variable. @access public @param string $variable The variable we wish to return. @param mixed $default If the variable is not found, this is returned. @return mixed @static
[ "Get", "a", "single", "GET", "variable", "." ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Request.php#L162-L166
29,857
polyfony-inc/polyfony
Private/Polyfony/Request.php
Request.post
public static function post(string $variable, $default = null) { return isset(self::$_post[$variable]) ? self::$_post[$variable] : $default; }
php
public static function post(string $variable, $default = null) { return isset(self::$_post[$variable]) ? self::$_post[$variable] : $default; }
[ "public", "static", "function", "post", "(", "string", "$", "variable", ",", "$", "default", "=", "null", ")", "{", "return", "isset", "(", "self", "::", "$", "_post", "[", "$", "variable", "]", ")", "?", "self", "::", "$", "_post", "[", "$", "variable", "]", ":", "$", "default", ";", "}" ]
Get a single POST variable. @access public @param string $variable The variable we wish to return. @param mixed $default If the variable is not found, this is returned. @return mixed @static
[ "Get", "a", "single", "POST", "variable", "." ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Request.php#L177-L181
29,858
polyfony-inc/polyfony
Private/Polyfony/Request.php
Request.files
public static function files(string $variable, $default = null) { return isset(self::$_files[$variable]) ? self::$_files[$variable] : $default; }
php
public static function files(string $variable, $default = null) { return isset(self::$_files[$variable]) ? self::$_files[$variable] : $default; }
[ "public", "static", "function", "files", "(", "string", "$", "variable", ",", "$", "default", "=", "null", ")", "{", "return", "isset", "(", "self", "::", "$", "_files", "[", "$", "variable", "]", ")", "?", "self", "::", "$", "_files", "[", "$", "variable", "]", ":", "$", "default", ";", "}" ]
Get a single FILES variable. @access public @param string $variable The variable we wish to return. @param mixed $default If the variable is not found, this is returned. @return mixed @static
[ "Get", "a", "single", "FILES", "variable", "." ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Request.php#L192-L196
29,859
polyfony-inc/polyfony
Private/Polyfony/Request.php
Request.server
public static function server(string $variable, $default = null) { return isset(self::$_server[$variable]) ? self::$_server[$variable] : $default; }
php
public static function server(string $variable, $default = null) { return isset(self::$_server[$variable]) ? self::$_server[$variable] : $default; }
[ "public", "static", "function", "server", "(", "string", "$", "variable", ",", "$", "default", "=", "null", ")", "{", "return", "isset", "(", "self", "::", "$", "_server", "[", "$", "variable", "]", ")", "?", "self", "::", "$", "_server", "[", "$", "variable", "]", ":", "$", "default", ";", "}" ]
Get a single SERVER variable. @access public @param string $variable The variable we wish to return. @param mixed $default If the variable is not found, this is returned. @return mixed @static
[ "Get", "a", "single", "SERVER", "variable", "." ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Request.php#L207-L211
29,860
polyfony-inc/polyfony
Private/Polyfony/Request.php
Request.argv
public static function argv(string $variable, $default = null) { return isset(self::$_argv[$variable]) ? self::$_argv[$variable] : $default; }
php
public static function argv(string $variable, $default = null) { return isset(self::$_argv[$variable]) ? self::$_argv[$variable] : $default; }
[ "public", "static", "function", "argv", "(", "string", "$", "variable", ",", "$", "default", "=", "null", ")", "{", "return", "isset", "(", "self", "::", "$", "_argv", "[", "$", "variable", "]", ")", "?", "self", "::", "$", "_argv", "[", "$", "variable", "]", ":", "$", "default", ";", "}" ]
Get a single argv variable. @access public @param string $variable The variable we wish to return. @param mixed $default If the variable is not found, this is returned. @return mixed @static
[ "Get", "a", "single", "argv", "variable", "." ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Request.php#L223-L227
29,861
acdh-oeaw/repo-php-util
src/acdhOeaw/util/ResourceFactory.php
ResourceFactory.removeAcl
static public function removeAcl(Fedora $fedora, bool $verbose = true) { echo $verbose ? "removing ACL rules\n" : ''; $fedora->rollback(); $fedora->begin(); $resp = $fedora->getResourcesByProperty('http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://www.w3.org/ns/auth/acl#Authorization'); foreach ($resp as $k => $rule) { echo $verbose ? " removing rule " . ($k + 1) . "/" . count($resp) . "\n" : ''; $rule->delete(true); } $fedora->commit(); $fedora->begin(); $resp = $fedora->getResourcesByProperty('http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://fedora.info/definitions/v4/webac#Acl'); foreach ($resp as $k => $rule) { if ($rule->getUri(true) === 'https://fedora.localhost/rest/acl') { continue; } echo $verbose ? " removing ACL " . ($k + 1) . "/" . count($resp) . "\n" : ''; $rule->delete(true, true); } $fedora->commit(); $fedora->begin(); $resp = $fedora->getResourcesByProperty('http://www.w3.org/ns/auth/acl#accessControl'); foreach ($resp as $k => $res) { if ($res->getUri(true) === 'https://fedora.localhost/rest/') { continue; } echo $verbose ? " removing ACL link " . ($k + 1) . "/" . count($resp) . "\n" : ''; $meta = $res->getMetadata(); $meta->delete('http://www.w3.org/ns/auth/acl#accessControl'); $res->setMetadata($meta); $res->updateMetadata(FedoraResource::OVERWRITE); } $fedora->commit(); echo $verbose ? " ended\n" : ''; $fedora->__refreshCache(); // make all cached FedoraResource object aware of the changes made }
php
static public function removeAcl(Fedora $fedora, bool $verbose = true) { echo $verbose ? "removing ACL rules\n" : ''; $fedora->rollback(); $fedora->begin(); $resp = $fedora->getResourcesByProperty('http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://www.w3.org/ns/auth/acl#Authorization'); foreach ($resp as $k => $rule) { echo $verbose ? " removing rule " . ($k + 1) . "/" . count($resp) . "\n" : ''; $rule->delete(true); } $fedora->commit(); $fedora->begin(); $resp = $fedora->getResourcesByProperty('http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://fedora.info/definitions/v4/webac#Acl'); foreach ($resp as $k => $rule) { if ($rule->getUri(true) === 'https://fedora.localhost/rest/acl') { continue; } echo $verbose ? " removing ACL " . ($k + 1) . "/" . count($resp) . "\n" : ''; $rule->delete(true, true); } $fedora->commit(); $fedora->begin(); $resp = $fedora->getResourcesByProperty('http://www.w3.org/ns/auth/acl#accessControl'); foreach ($resp as $k => $res) { if ($res->getUri(true) === 'https://fedora.localhost/rest/') { continue; } echo $verbose ? " removing ACL link " . ($k + 1) . "/" . count($resp) . "\n" : ''; $meta = $res->getMetadata(); $meta->delete('http://www.w3.org/ns/auth/acl#accessControl'); $res->setMetadata($meta); $res->updateMetadata(FedoraResource::OVERWRITE); } $fedora->commit(); echo $verbose ? " ended\n" : ''; $fedora->__refreshCache(); // make all cached FedoraResource object aware of the changes made }
[ "static", "public", "function", "removeAcl", "(", "Fedora", "$", "fedora", ",", "bool", "$", "verbose", "=", "true", ")", "{", "echo", "$", "verbose", "?", "\"removing ACL rules\\n\"", ":", "''", ";", "$", "fedora", "->", "rollback", "(", ")", ";", "$", "fedora", "->", "begin", "(", ")", ";", "$", "resp", "=", "$", "fedora", "->", "getResourcesByProperty", "(", "'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'", ",", "'http://www.w3.org/ns/auth/acl#Authorization'", ")", ";", "foreach", "(", "$", "resp", "as", "$", "k", "=>", "$", "rule", ")", "{", "echo", "$", "verbose", "?", "\" removing rule \"", ".", "(", "$", "k", "+", "1", ")", ".", "\"/\"", ".", "count", "(", "$", "resp", ")", ".", "\"\\n\"", ":", "''", ";", "$", "rule", "->", "delete", "(", "true", ")", ";", "}", "$", "fedora", "->", "commit", "(", ")", ";", "$", "fedora", "->", "begin", "(", ")", ";", "$", "resp", "=", "$", "fedora", "->", "getResourcesByProperty", "(", "'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'", ",", "'http://fedora.info/definitions/v4/webac#Acl'", ")", ";", "foreach", "(", "$", "resp", "as", "$", "k", "=>", "$", "rule", ")", "{", "if", "(", "$", "rule", "->", "getUri", "(", "true", ")", "===", "'https://fedora.localhost/rest/acl'", ")", "{", "continue", ";", "}", "echo", "$", "verbose", "?", "\" removing ACL \"", ".", "(", "$", "k", "+", "1", ")", ".", "\"/\"", ".", "count", "(", "$", "resp", ")", ".", "\"\\n\"", ":", "''", ";", "$", "rule", "->", "delete", "(", "true", ",", "true", ")", ";", "}", "$", "fedora", "->", "commit", "(", ")", ";", "$", "fedora", "->", "begin", "(", ")", ";", "$", "resp", "=", "$", "fedora", "->", "getResourcesByProperty", "(", "'http://www.w3.org/ns/auth/acl#accessControl'", ")", ";", "foreach", "(", "$", "resp", "as", "$", "k", "=>", "$", "res", ")", "{", "if", "(", "$", "res", "->", "getUri", "(", "true", ")", "===", "'https://fedora.localhost/rest/'", ")", "{", "continue", ";", "}", "echo", "$", "verbose", "?", "\" removing ACL link \"", ".", "(", "$", "k", "+", "1", ")", ".", "\"/\"", ".", "count", "(", "$", "resp", ")", ".", "\"\\n\"", ":", "''", ";", "$", "meta", "=", "$", "res", "->", "getMetadata", "(", ")", ";", "$", "meta", "->", "delete", "(", "'http://www.w3.org/ns/auth/acl#accessControl'", ")", ";", "$", "res", "->", "setMetadata", "(", "$", "meta", ")", ";", "$", "res", "->", "updateMetadata", "(", "FedoraResource", "::", "OVERWRITE", ")", ";", "}", "$", "fedora", "->", "commit", "(", ")", ";", "echo", "$", "verbose", "?", "\" ended\\n\"", ":", "''", ";", "$", "fedora", "->", "__refreshCache", "(", ")", ";", "// make all cached FedoraResource object aware of the changes made", "}" ]
Removes all access control rules from the repository @param Fedora $fedora Fedora connection object @param bool $verbose should progess messages be displayed
[ "Removes", "all", "access", "control", "rules", "from", "the", "repository" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/ResourceFactory.php#L152-L192
29,862
acdh-oeaw/repo-php-util
src/acdhOeaw/schema/dissemination/Parameter.php
Parameter.getMetadata
public function getMetadata(): Resource { $meta = (new Graph())->resource('.'); $meta->addResource(RC::relProp(), $this->service->getResource()->getId()); $meta->addResource(RC::idProp(), $this->getId()); $meta->addType(RC::get('fedoraServiceParamClass')); $titleProp = RC::get('fedoraTitleProp'); $meta->addLiteral($titleProp, $this->name); $defaultValueProp = RC::get('fedoraServiceParamDefaultValueProp'); $meta->addLiteral($defaultValueProp, $this->defaultValue); $redPropertyProp = RC::get('fedoraServiceParamRdfPropertyProp'); $meta->addLiteral($redPropertyProp, $this->rdfProperty); return $meta; }
php
public function getMetadata(): Resource { $meta = (new Graph())->resource('.'); $meta->addResource(RC::relProp(), $this->service->getResource()->getId()); $meta->addResource(RC::idProp(), $this->getId()); $meta->addType(RC::get('fedoraServiceParamClass')); $titleProp = RC::get('fedoraTitleProp'); $meta->addLiteral($titleProp, $this->name); $defaultValueProp = RC::get('fedoraServiceParamDefaultValueProp'); $meta->addLiteral($defaultValueProp, $this->defaultValue); $redPropertyProp = RC::get('fedoraServiceParamRdfPropertyProp'); $meta->addLiteral($redPropertyProp, $this->rdfProperty); return $meta; }
[ "public", "function", "getMetadata", "(", ")", ":", "Resource", "{", "$", "meta", "=", "(", "new", "Graph", "(", ")", ")", "->", "resource", "(", "'.'", ")", ";", "$", "meta", "->", "addResource", "(", "RC", "::", "relProp", "(", ")", ",", "$", "this", "->", "service", "->", "getResource", "(", ")", "->", "getId", "(", ")", ")", ";", "$", "meta", "->", "addResource", "(", "RC", "::", "idProp", "(", ")", ",", "$", "this", "->", "getId", "(", ")", ")", ";", "$", "meta", "->", "addType", "(", "RC", "::", "get", "(", "'fedoraServiceParamClass'", ")", ")", ";", "$", "titleProp", "=", "RC", "::", "get", "(", "'fedoraTitleProp'", ")", ";", "$", "meta", "->", "addLiteral", "(", "$", "titleProp", ",", "$", "this", "->", "name", ")", ";", "$", "defaultValueProp", "=", "RC", "::", "get", "(", "'fedoraServiceParamDefaultValueProp'", ")", ";", "$", "meta", "->", "addLiteral", "(", "$", "defaultValueProp", ",", "$", "this", "->", "defaultValue", ")", ";", "$", "redPropertyProp", "=", "RC", "::", "get", "(", "'fedoraServiceParamRdfPropertyProp'", ")", ";", "$", "meta", "->", "addLiteral", "(", "$", "redPropertyProp", ",", "$", "this", "->", "rdfProperty", ")", ";", "return", "$", "meta", ";", "}" ]
Returns metadata describing the dissemination service parameter @return Resource
[ "Returns", "metadata", "describing", "the", "dissemination", "service", "parameter" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/schema/dissemination/Parameter.php#L106-L123
29,863
polyfony-inc/polyfony
Private/Polyfony/Element.php
Element.setText
public function setText(string $text=null, bool $append=true) :self { // append by default or replace text $this->content = $append ? $this->content . Format::htmlSafe($text) : Format::htmlSafe($text); // return self return($this); }
php
public function setText(string $text=null, bool $append=true) :self { // append by default or replace text $this->content = $append ? $this->content . Format::htmlSafe($text) : Format::htmlSafe($text); // return self return($this); }
[ "public", "function", "setText", "(", "string", "$", "text", "=", "null", ",", "bool", "$", "append", "=", "true", ")", ":", "self", "{", "// append by default or replace text", "$", "this", "->", "content", "=", "$", "append", "?", "$", "this", "->", "content", ".", "Format", "::", "htmlSafe", "(", "$", "text", ")", ":", "Format", "::", "htmlSafe", "(", "$", "text", ")", ";", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
set the text in the tag
[ "set", "the", "text", "in", "the", "tag" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Element.php#L26-L31
29,864
polyfony-inc/polyfony
Private/Polyfony/Element.php
Element.setHtml
public function setHtml(string $html=null, bool $append=true) :self { // append by default or replace html $this->content = $append ? $this->content . $html : $html; // return self return($this); }
php
public function setHtml(string $html=null, bool $append=true) :self { // append by default or replace html $this->content = $append ? $this->content . $html : $html; // return self return($this); }
[ "public", "function", "setHtml", "(", "string", "$", "html", "=", "null", ",", "bool", "$", "append", "=", "true", ")", ":", "self", "{", "// append by default or replace html", "$", "this", "->", "content", "=", "$", "append", "?", "$", "this", "->", "content", ".", "$", "html", ":", "$", "html", ";", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
set the html in the tag
[ "set", "the", "html", "in", "the", "tag" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Element.php#L34-L39
29,865
polyfony-inc/polyfony
Private/Polyfony/Element.php
Element.setStyle
public function setStyle(array $css_properties=[]) :self { // init the style attribute is it didn't exist already isset($this->attributes['style']) ?: $this->attributes['style'] = ''; // for each of the css properties foreach($css_properties as $css_property => $css_value) { // add them to the already existing ones $this->attributes['style'] .= $css_property.':'.$css_value.';'; } // return self return($this); }
php
public function setStyle(array $css_properties=[]) :self { // init the style attribute is it didn't exist already isset($this->attributes['style']) ?: $this->attributes['style'] = ''; // for each of the css properties foreach($css_properties as $css_property => $css_value) { // add them to the already existing ones $this->attributes['style'] .= $css_property.':'.$css_value.';'; } // return self return($this); }
[ "public", "function", "setStyle", "(", "array", "$", "css_properties", "=", "[", "]", ")", ":", "self", "{", "// init the style attribute is it didn't exist already", "isset", "(", "$", "this", "->", "attributes", "[", "'style'", "]", ")", "?", ":", "$", "this", "->", "attributes", "[", "'style'", "]", "=", "''", ";", "// for each of the css properties", "foreach", "(", "$", "css_properties", "as", "$", "css_property", "=>", "$", "css_value", ")", "{", "// add them to the already existing ones", "$", "this", "->", "attributes", "[", "'style'", "]", ".=", "$", "css_property", ".", "':'", ".", "$", "css_value", ".", "';'", ";", "}", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
set the style for the tag
[ "set", "the", "style", "for", "the", "tag" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Element.php#L42-L52
29,866
polyfony-inc/polyfony
Private/Polyfony/Element.php
Element.setValue
public function setValue($value=null) :self { // append by default or replace html $this->attributes['value'] = Format::htmlSafe($value); // return self return($this); }
php
public function setValue($value=null) :self { // append by default or replace html $this->attributes['value'] = Format::htmlSafe($value); // return self return($this); }
[ "public", "function", "setValue", "(", "$", "value", "=", "null", ")", ":", "self", "{", "// append by default or replace html", "$", "this", "->", "attributes", "[", "'value'", "]", "=", "Format", "::", "htmlSafe", "(", "$", "value", ")", ";", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
set the value of a tag
[ "set", "the", "value", "of", "a", "tag" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Element.php#L55-L60
29,867
polyfony-inc/polyfony
Private/Polyfony/Element.php
Element.set
public function set($attribute, $value=null) :self { // array is passed if(is_array($attribute)) { // for each associative value in the array foreach($attribute as $single_attribute => $single_value) { // recurse with a single pair or attribute/value $this->set($single_attribute, $single_value); } // return self return($this); } // specific case of text if($attribute == 'text') { // use the setter $this->setText($value); } // specific case of html elseif($attribute == 'html') { // use the setter $this->setHtml($value); } // specific case of style elseif($attribute == 'style' && is_array($value)) { // use the setter $this->setStyle($value); } // specific case of value elseif($attribute == 'value') { // use the setter $this->setValue($value); } // any normal attribute else { // if the value is an array we assemble its content or we set directly $this->attributes[$attribute] = is_array($value) ? implode(' ', $value) : $value; } // return self return($this); }
php
public function set($attribute, $value=null) :self { // array is passed if(is_array($attribute)) { // for each associative value in the array foreach($attribute as $single_attribute => $single_value) { // recurse with a single pair or attribute/value $this->set($single_attribute, $single_value); } // return self return($this); } // specific case of text if($attribute == 'text') { // use the setter $this->setText($value); } // specific case of html elseif($attribute == 'html') { // use the setter $this->setHtml($value); } // specific case of style elseif($attribute == 'style' && is_array($value)) { // use the setter $this->setStyle($value); } // specific case of value elseif($attribute == 'value') { // use the setter $this->setValue($value); } // any normal attribute else { // if the value is an array we assemble its content or we set directly $this->attributes[$attribute] = is_array($value) ? implode(' ', $value) : $value; } // return self return($this); }
[ "public", "function", "set", "(", "$", "attribute", ",", "$", "value", "=", "null", ")", ":", "self", "{", "// array is passed", "if", "(", "is_array", "(", "$", "attribute", ")", ")", "{", "// for each associative value in the array", "foreach", "(", "$", "attribute", "as", "$", "single_attribute", "=>", "$", "single_value", ")", "{", "// recurse with a single pair or attribute/value", "$", "this", "->", "set", "(", "$", "single_attribute", ",", "$", "single_value", ")", ";", "}", "// return self", "return", "(", "$", "this", ")", ";", "}", "// specific case of text", "if", "(", "$", "attribute", "==", "'text'", ")", "{", "// use the setter", "$", "this", "->", "setText", "(", "$", "value", ")", ";", "}", "// specific case of html", "elseif", "(", "$", "attribute", "==", "'html'", ")", "{", "// use the setter", "$", "this", "->", "setHtml", "(", "$", "value", ")", ";", "}", "// specific case of style", "elseif", "(", "$", "attribute", "==", "'style'", "&&", "is_array", "(", "$", "value", ")", ")", "{", "// use the setter", "$", "this", "->", "setStyle", "(", "$", "value", ")", ";", "}", "// specific case of value", "elseif", "(", "$", "attribute", "==", "'value'", ")", "{", "// use the setter", "$", "this", "->", "setValue", "(", "$", "value", ")", ";", "}", "// any normal attribute", "else", "{", "// if the value is an array we assemble its content or we set directly", "$", "this", "->", "attributes", "[", "$", "attribute", "]", "=", "is_array", "(", "$", "value", ")", "?", "implode", "(", "' '", ",", "$", "value", ")", ":", "$", "value", ";", "}", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
set everything, mostly attribute but also content
[ "set", "everything", "mostly", "attribute", "but", "also", "content" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Element.php#L63-L101
29,868
polyfony-inc/polyfony
Private/Polyfony/Element.php
Element.adopt
public function adopt($child, $before=false) { // adopt, or adopt before $this->content = $before ? $child . $this->content : $this->content . $child; // return self return($this); }
php
public function adopt($child, $before=false) { // adopt, or adopt before $this->content = $before ? $child . $this->content : $this->content . $child; // return self return($this); }
[ "public", "function", "adopt", "(", "$", "child", ",", "$", "before", "=", "false", ")", "{", "// adopt, or adopt before", "$", "this", "->", "content", "=", "$", "before", "?", "$", "child", ".", "$", "this", "->", "content", ":", "$", "this", "->", "content", ".", "$", "child", ";", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
adopt an element of the same kind
[ "adopt", "an", "element", "of", "the", "same", "kind" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Element.php#L104-L109
29,869
ventoviro/windwalker-core
src/Core/Controller/AbstractController.php
AbstractController.hmvc
public function hmvc($task, $input = null, $package = null) { // If task is controller object, just execute it. if ($task instanceof AbstractController) { if (is_array($input)) { $input = new Input($input); } // Let's push some important data into it. /** @var AbstractController $controller */ $controller = $task->setContainer($this->container) ->isHmvc(true) ->setRequest($this->request) ->setResponse($this->response) ->setPackage($this->package) ->setApplication($this->package->app) ->setInput($input); // Do action and return executed result. $result = $controller->execute(); // Take back the redirect information. $this->passRedirect($controller); return $result; } // If task is string, find controller by package $package = $package ? $this->app->getPackage($package) : $this->package; $response = $package->execute( $package->getController($task, $input), $this->getRequest(), new Response(), true ); // Take back the redirect information. $this->passRedirect($package->getCurrentController()); return $response->getBody()->__toString(); }
php
public function hmvc($task, $input = null, $package = null) { // If task is controller object, just execute it. if ($task instanceof AbstractController) { if (is_array($input)) { $input = new Input($input); } // Let's push some important data into it. /** @var AbstractController $controller */ $controller = $task->setContainer($this->container) ->isHmvc(true) ->setRequest($this->request) ->setResponse($this->response) ->setPackage($this->package) ->setApplication($this->package->app) ->setInput($input); // Do action and return executed result. $result = $controller->execute(); // Take back the redirect information. $this->passRedirect($controller); return $result; } // If task is string, find controller by package $package = $package ? $this->app->getPackage($package) : $this->package; $response = $package->execute( $package->getController($task, $input), $this->getRequest(), new Response(), true ); // Take back the redirect information. $this->passRedirect($package->getCurrentController()); return $response->getBody()->__toString(); }
[ "public", "function", "hmvc", "(", "$", "task", ",", "$", "input", "=", "null", ",", "$", "package", "=", "null", ")", "{", "// If task is controller object, just execute it.", "if", "(", "$", "task", "instanceof", "AbstractController", ")", "{", "if", "(", "is_array", "(", "$", "input", ")", ")", "{", "$", "input", "=", "new", "Input", "(", "$", "input", ")", ";", "}", "// Let's push some important data into it.", "/** @var AbstractController $controller */", "$", "controller", "=", "$", "task", "->", "setContainer", "(", "$", "this", "->", "container", ")", "->", "isHmvc", "(", "true", ")", "->", "setRequest", "(", "$", "this", "->", "request", ")", "->", "setResponse", "(", "$", "this", "->", "response", ")", "->", "setPackage", "(", "$", "this", "->", "package", ")", "->", "setApplication", "(", "$", "this", "->", "package", "->", "app", ")", "->", "setInput", "(", "$", "input", ")", ";", "// Do action and return executed result.", "$", "result", "=", "$", "controller", "->", "execute", "(", ")", ";", "// Take back the redirect information.", "$", "this", "->", "passRedirect", "(", "$", "controller", ")", ";", "return", "$", "result", ";", "}", "// If task is string, find controller by package", "$", "package", "=", "$", "package", "?", "$", "this", "->", "app", "->", "getPackage", "(", "$", "package", ")", ":", "$", "this", "->", "package", ";", "$", "response", "=", "$", "package", "->", "execute", "(", "$", "package", "->", "getController", "(", "$", "task", ",", "$", "input", ")", ",", "$", "this", "->", "getRequest", "(", ")", ",", "new", "Response", "(", ")", ",", "true", ")", ";", "// Take back the redirect information.", "$", "this", "->", "passRedirect", "(", "$", "package", "->", "getCurrentController", "(", ")", ")", ";", "return", "$", "response", "->", "getBody", "(", ")", "->", "__toString", "(", ")", ";", "}" ]
Run HMVC to fetch content from other controller. @param string|AbstractController $task The task to exeiocute, must be controller object or string. The string format is `Name\ActionController` example: `Page\GetController` @param Input|array $input The input for this task, can be array or Input object. @param string $package The package for this controller, can be string or AbstractPackage. @return mixed @throws \Throwable
[ "Run", "HMVC", "to", "fetch", "content", "from", "other", "controller", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Controller/AbstractController.php#L176-L217
29,870
ventoviro/windwalker-core
src/Core/Controller/AbstractController.php
AbstractController.execute
public function execute() { try { // @ prepare hook $this->prepareExecute(); // @ before event $this->triggerEvent('onControllerBeforeExecute', [ 'controller' => $this ]); // Prepare the last middleware, the last middleware is the real logic of this controller self. $chain = $this->getMiddlewareChain()->setEndMiddleware(function () { return $this->container->call([$this, 'doExecute'], [], $this); }); // Do execute, run middlewares. $result = $chain->execute(new ControllerData(get_object_vars($this))); // @ post hook $result = $this->postExecute($result); // @ post event $this->triggerEvent('onControllerAfterExecute', [ 'controller' => $this, 'result' => &$result, ]); } catch (ValidateFailException $e) { return $this->processFailure($e); } catch (\Exception $e) { // You can do some error handling in processFailure(), for example: rollback the transaction. $result = $this->processFailure($e); if (!$this->app->get('system.debug')) { return $result; } throw $e; } catch (\Throwable $t) { // You can do some error handling in processFailure(), for example: rollback the transaction. $this->processFailure(new \ErrorException( $t->getMessage(), $t->getCode(), E_ERROR, $t->getFile(), $t->getLine(), $t )); throw $t; } if ($result === false) { // You can do some error handling in processFailure(), for example: rollback the transaction. return $this->processFailure(new \Exception('Unknown Error')); } // Now we return result to package that it will handle response. return $this->processSuccess($result); }
php
public function execute() { try { // @ prepare hook $this->prepareExecute(); // @ before event $this->triggerEvent('onControllerBeforeExecute', [ 'controller' => $this ]); // Prepare the last middleware, the last middleware is the real logic of this controller self. $chain = $this->getMiddlewareChain()->setEndMiddleware(function () { return $this->container->call([$this, 'doExecute'], [], $this); }); // Do execute, run middlewares. $result = $chain->execute(new ControllerData(get_object_vars($this))); // @ post hook $result = $this->postExecute($result); // @ post event $this->triggerEvent('onControllerAfterExecute', [ 'controller' => $this, 'result' => &$result, ]); } catch (ValidateFailException $e) { return $this->processFailure($e); } catch (\Exception $e) { // You can do some error handling in processFailure(), for example: rollback the transaction. $result = $this->processFailure($e); if (!$this->app->get('system.debug')) { return $result; } throw $e; } catch (\Throwable $t) { // You can do some error handling in processFailure(), for example: rollback the transaction. $this->processFailure(new \ErrorException( $t->getMessage(), $t->getCode(), E_ERROR, $t->getFile(), $t->getLine(), $t )); throw $t; } if ($result === false) { // You can do some error handling in processFailure(), for example: rollback the transaction. return $this->processFailure(new \Exception('Unknown Error')); } // Now we return result to package that it will handle response. return $this->processSuccess($result); }
[ "public", "function", "execute", "(", ")", "{", "try", "{", "// @ prepare hook", "$", "this", "->", "prepareExecute", "(", ")", ";", "// @ before event", "$", "this", "->", "triggerEvent", "(", "'onControllerBeforeExecute'", ",", "[", "'controller'", "=>", "$", "this", "]", ")", ";", "// Prepare the last middleware, the last middleware is the real logic of this controller self.", "$", "chain", "=", "$", "this", "->", "getMiddlewareChain", "(", ")", "->", "setEndMiddleware", "(", "function", "(", ")", "{", "return", "$", "this", "->", "container", "->", "call", "(", "[", "$", "this", ",", "'doExecute'", "]", ",", "[", "]", ",", "$", "this", ")", ";", "}", ")", ";", "// Do execute, run middlewares.", "$", "result", "=", "$", "chain", "->", "execute", "(", "new", "ControllerData", "(", "get_object_vars", "(", "$", "this", ")", ")", ")", ";", "// @ post hook", "$", "result", "=", "$", "this", "->", "postExecute", "(", "$", "result", ")", ";", "// @ post event", "$", "this", "->", "triggerEvent", "(", "'onControllerAfterExecute'", ",", "[", "'controller'", "=>", "$", "this", ",", "'result'", "=>", "&", "$", "result", ",", "]", ")", ";", "}", "catch", "(", "ValidateFailException", "$", "e", ")", "{", "return", "$", "this", "->", "processFailure", "(", "$", "e", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// You can do some error handling in processFailure(), for example: rollback the transaction.", "$", "result", "=", "$", "this", "->", "processFailure", "(", "$", "e", ")", ";", "if", "(", "!", "$", "this", "->", "app", "->", "get", "(", "'system.debug'", ")", ")", "{", "return", "$", "result", ";", "}", "throw", "$", "e", ";", "}", "catch", "(", "\\", "Throwable", "$", "t", ")", "{", "// You can do some error handling in processFailure(), for example: rollback the transaction.", "$", "this", "->", "processFailure", "(", "new", "\\", "ErrorException", "(", "$", "t", "->", "getMessage", "(", ")", ",", "$", "t", "->", "getCode", "(", ")", ",", "E_ERROR", ",", "$", "t", "->", "getFile", "(", ")", ",", "$", "t", "->", "getLine", "(", ")", ",", "$", "t", ")", ")", ";", "throw", "$", "t", ";", "}", "if", "(", "$", "result", "===", "false", ")", "{", "// You can do some error handling in processFailure(), for example: rollback the transaction.", "return", "$", "this", "->", "processFailure", "(", "new", "\\", "Exception", "(", "'Unknown Error'", ")", ")", ";", "}", "// Now we return result to package that it will handle response.", "return", "$", "this", "->", "processSuccess", "(", "$", "result", ")", ";", "}" ]
Execute the controller. @return mixed Return executed result. @throws \Exception @throws \Throwable
[ "Execute", "the", "controller", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Controller/AbstractController.php#L255-L314
29,871
ventoviro/windwalker-core
src/Core/Controller/AbstractController.php
AbstractController.delegate
protected function delegate($task, ...$args) { if (method_exists($this, $task)) { return $this->container->call([$this, $task], $args, $this); } if (is_callable($task)) { return $this->container->call($task, $args, $this); } throw new \LogicException('Task: ' . $task . ' not found.'); }
php
protected function delegate($task, ...$args) { if (method_exists($this, $task)) { return $this->container->call([$this, $task], $args, $this); } if (is_callable($task)) { return $this->container->call($task, $args, $this); } throw new \LogicException('Task: ' . $task . ' not found.'); }
[ "protected", "function", "delegate", "(", "$", "task", ",", "...", "$", "args", ")", "{", "if", "(", "method_exists", "(", "$", "this", ",", "$", "task", ")", ")", "{", "return", "$", "this", "->", "container", "->", "call", "(", "[", "$", "this", ",", "$", "task", "]", ",", "$", "args", ",", "$", "this", ")", ";", "}", "if", "(", "is_callable", "(", "$", "task", ")", ")", "{", "return", "$", "this", "->", "container", "->", "call", "(", "$", "task", ",", "$", "args", ",", "$", "this", ")", ";", "}", "throw", "new", "\\", "LogicException", "(", "'Task: '", ".", "$", "task", ".", "' not found.'", ")", ";", "}" ]
Method to easily distribute task to other methods that we can process different tasks. Example in doExecute(): ``` return $this->delegate($this->input->get('task'), `arg1`, `arg2`); // OR return $this->delegate([$object, 'method'], `arg1`, `arg2`); ``` @param string $task The task name. @param array $args The arguments we provides. @return mixed @throws \ReflectionException @throws \Windwalker\DI\Exception\DependencyResolutionException
[ "Method", "to", "easily", "distribute", "task", "to", "other", "methods", "that", "we", "can", "process", "different", "tasks", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Controller/AbstractController.php#L335-L346
29,872
ventoviro/windwalker-core
src/Core/Controller/AbstractController.php
AbstractController.renderView
public function renderView($view, $layout = 'default', $engine = 'php', array $data = []) { $viewObject = $view; if (\is_string($view)) { $viewObject = class_exists($view) ? $this->container->createSharedObject($view) : $this->getView($view, 'html', $engine); } $this->setConfig($this->config); // Set data into View foreach ($data as $key => $value) { $viewObject[$key] = $value; } if ($layout !== null && $viewObject instanceof LayoutRenderableInterface) { $viewObject->setLayout($layout); } return $viewObject->render(); }
php
public function renderView($view, $layout = 'default', $engine = 'php', array $data = []) { $viewObject = $view; if (\is_string($view)) { $viewObject = class_exists($view) ? $this->container->createSharedObject($view) : $this->getView($view, 'html', $engine); } $this->setConfig($this->config); // Set data into View foreach ($data as $key => $value) { $viewObject[$key] = $value; } if ($layout !== null && $viewObject instanceof LayoutRenderableInterface) { $viewObject->setLayout($layout); } return $viewObject->render(); }
[ "public", "function", "renderView", "(", "$", "view", ",", "$", "layout", "=", "'default'", ",", "$", "engine", "=", "'php'", ",", "array", "$", "data", "=", "[", "]", ")", "{", "$", "viewObject", "=", "$", "view", ";", "if", "(", "\\", "is_string", "(", "$", "view", ")", ")", "{", "$", "viewObject", "=", "class_exists", "(", "$", "view", ")", "?", "$", "this", "->", "container", "->", "createSharedObject", "(", "$", "view", ")", ":", "$", "this", "->", "getView", "(", "$", "view", ",", "'html'", ",", "$", "engine", ")", ";", "}", "$", "this", "->", "setConfig", "(", "$", "this", "->", "config", ")", ";", "// Set data into View", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "viewObject", "[", "$", "key", "]", "=", "$", "value", ";", "}", "if", "(", "$", "layout", "!==", "null", "&&", "$", "viewObject", "instanceof", "LayoutRenderableInterface", ")", "{", "$", "viewObject", "->", "setLayout", "(", "$", "layout", ")", ";", "}", "return", "$", "viewObject", "->", "render", "(", ")", ";", "}" ]
Method to easily render view. @param LayoutRenderableInterface|string $view The view name or object. @param string $layout The layout to render. @param string $engine The engine of template. @param array $data The data to set in view. @return string @throws \LogicException @throws \Exception
[ "Method", "to", "easily", "render", "view", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Controller/AbstractController.php#L360-L382
29,873
ventoviro/windwalker-core
src/Core/Controller/AbstractController.php
AbstractController.getView
public function getView($name = null, $format = 'html', $engine = null, $forceNew = false) { $name = $name ?: $this->getName(); $format = $format ?: 'html'; $key = ViewResolver::getDIKey($name . '.' . strtolower($format)); // Let's prepare controller getter. if (!$this->container->exists($key)) { $this->container->share($key, function (Container $container) use ($name, $format, $engine) { // Find if package exists $viewName = sprintf('%s\%s%sView', ucfirst($name), ucfirst($name), ucfirst($format)); $config = clone $this->config; /* * If the name of this view not same as this controller, we don't pass name into it, * so that the view will keep it's own name. * Otherwise we override the name in view config with ours. */ if ($name && strcasecmp($name, $this->getName()) !== 0) { $config['name'] = null; } try { // Use MvcResolver to find view class. $class = $this->getPackage()->getMvcResolver()->getViewResolver()->resolve($viewName); // Create object by container, container will auto inject all necessary dependencies return $container->createSharedObject($class, ['renderer' => $engine, 'config' => $config]); } catch (\Exception $e) { if (!$e instanceof \DomainException && !$e instanceof \UnexpectedValueException) { throw $e; } // Guess the view position $class = MvcHelper::getPackageNamespace($this) . '\View\\' . ucfirst($viewName); if (class_exists($class)) { return $container->createSharedObject($class, ['renderer' => $engine, 'config' => $config]); } // If format is html or NULL, we return HtmlView as default. if (strtolower($format) === 'html') { $config['name'] = $name; return new HtmlView([], $config, $engine); } // Otherwise we throw exception to notice developers that they did something wrong. throw $e; } }); } // Get view from controller. return $this->container->get($key, $forceNew); }
php
public function getView($name = null, $format = 'html', $engine = null, $forceNew = false) { $name = $name ?: $this->getName(); $format = $format ?: 'html'; $key = ViewResolver::getDIKey($name . '.' . strtolower($format)); // Let's prepare controller getter. if (!$this->container->exists($key)) { $this->container->share($key, function (Container $container) use ($name, $format, $engine) { // Find if package exists $viewName = sprintf('%s\%s%sView', ucfirst($name), ucfirst($name), ucfirst($format)); $config = clone $this->config; /* * If the name of this view not same as this controller, we don't pass name into it, * so that the view will keep it's own name. * Otherwise we override the name in view config with ours. */ if ($name && strcasecmp($name, $this->getName()) !== 0) { $config['name'] = null; } try { // Use MvcResolver to find view class. $class = $this->getPackage()->getMvcResolver()->getViewResolver()->resolve($viewName); // Create object by container, container will auto inject all necessary dependencies return $container->createSharedObject($class, ['renderer' => $engine, 'config' => $config]); } catch (\Exception $e) { if (!$e instanceof \DomainException && !$e instanceof \UnexpectedValueException) { throw $e; } // Guess the view position $class = MvcHelper::getPackageNamespace($this) . '\View\\' . ucfirst($viewName); if (class_exists($class)) { return $container->createSharedObject($class, ['renderer' => $engine, 'config' => $config]); } // If format is html or NULL, we return HtmlView as default. if (strtolower($format) === 'html') { $config['name'] = $name; return new HtmlView([], $config, $engine); } // Otherwise we throw exception to notice developers that they did something wrong. throw $e; } }); } // Get view from controller. return $this->container->get($key, $forceNew); }
[ "public", "function", "getView", "(", "$", "name", "=", "null", ",", "$", "format", "=", "'html'", ",", "$", "engine", "=", "null", ",", "$", "forceNew", "=", "false", ")", "{", "$", "name", "=", "$", "name", "?", ":", "$", "this", "->", "getName", "(", ")", ";", "$", "format", "=", "$", "format", "?", ":", "'html'", ";", "$", "key", "=", "ViewResolver", "::", "getDIKey", "(", "$", "name", ".", "'.'", ".", "strtolower", "(", "$", "format", ")", ")", ";", "// Let's prepare controller getter.", "if", "(", "!", "$", "this", "->", "container", "->", "exists", "(", "$", "key", ")", ")", "{", "$", "this", "->", "container", "->", "share", "(", "$", "key", ",", "function", "(", "Container", "$", "container", ")", "use", "(", "$", "name", ",", "$", "format", ",", "$", "engine", ")", "{", "// Find if package exists", "$", "viewName", "=", "sprintf", "(", "'%s\\%s%sView'", ",", "ucfirst", "(", "$", "name", ")", ",", "ucfirst", "(", "$", "name", ")", ",", "ucfirst", "(", "$", "format", ")", ")", ";", "$", "config", "=", "clone", "$", "this", "->", "config", ";", "/*\n * If the name of this view not same as this controller, we don't pass name into it,\n * so that the view will keep it's own name.\n * Otherwise we override the name in view config with ours.\n */", "if", "(", "$", "name", "&&", "strcasecmp", "(", "$", "name", ",", "$", "this", "->", "getName", "(", ")", ")", "!==", "0", ")", "{", "$", "config", "[", "'name'", "]", "=", "null", ";", "}", "try", "{", "// Use MvcResolver to find view class.", "$", "class", "=", "$", "this", "->", "getPackage", "(", ")", "->", "getMvcResolver", "(", ")", "->", "getViewResolver", "(", ")", "->", "resolve", "(", "$", "viewName", ")", ";", "// Create object by container, container will auto inject all necessary dependencies", "return", "$", "container", "->", "createSharedObject", "(", "$", "class", ",", "[", "'renderer'", "=>", "$", "engine", ",", "'config'", "=>", "$", "config", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "!", "$", "e", "instanceof", "\\", "DomainException", "&&", "!", "$", "e", "instanceof", "\\", "UnexpectedValueException", ")", "{", "throw", "$", "e", ";", "}", "// Guess the view position", "$", "class", "=", "MvcHelper", "::", "getPackageNamespace", "(", "$", "this", ")", ".", "'\\View\\\\'", ".", "ucfirst", "(", "$", "viewName", ")", ";", "if", "(", "class_exists", "(", "$", "class", ")", ")", "{", "return", "$", "container", "->", "createSharedObject", "(", "$", "class", ",", "[", "'renderer'", "=>", "$", "engine", ",", "'config'", "=>", "$", "config", "]", ")", ";", "}", "// If format is html or NULL, we return HtmlView as default.", "if", "(", "strtolower", "(", "$", "format", ")", "===", "'html'", ")", "{", "$", "config", "[", "'name'", "]", "=", "$", "name", ";", "return", "new", "HtmlView", "(", "[", "]", ",", "$", "config", ",", "$", "engine", ")", ";", "}", "// Otherwise we throw exception to notice developers that they did something wrong.", "throw", "$", "e", ";", "}", "}", ")", ";", "}", "// Get view from controller.", "return", "$", "this", "->", "container", "->", "get", "(", "$", "key", ",", "$", "forceNew", ")", ";", "}" ]
Get view object. @param string $name The view name. @param string $format The view foramt. @param string $engine The renderer template engine. @param bool $forceNew The Force create new instance. @return AbstractView|HtmlView @throws \Exception
[ "Get", "view", "object", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Controller/AbstractController.php#L422-L480
29,874
ventoviro/windwalker-core
src/Core/Controller/AbstractController.php
AbstractController.isHmvc
public function isHmvc($boolean = null) { if ($boolean === null) { return $this->hmvc; } $this->hmvc = (bool) $boolean; return $this; }
php
public function isHmvc($boolean = null) { if ($boolean === null) { return $this->hmvc; } $this->hmvc = (bool) $boolean; return $this; }
[ "public", "function", "isHmvc", "(", "$", "boolean", "=", "null", ")", "{", "if", "(", "$", "boolean", "===", "null", ")", "{", "return", "$", "this", "->", "hmvc", ";", "}", "$", "this", "->", "hmvc", "=", "(", "bool", ")", "$", "boolean", ";", "return", "$", "this", ";", "}" ]
Check this controller is in HMVC that we can close some behaviors. @param boolean $boolean @return static|boolean
[ "Check", "this", "controller", "is", "in", "HMVC", "that", "we", "can", "close", "some", "behaviors", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Controller/AbstractController.php#L1023-L1032
29,875
ventoviro/windwalker-core
src/Core/Migration/Command/MigrationCommand.php
MigrationCommand.init
public function init() { $this->addCommand(Migration\CreateCommand::class); $this->addCommand(Migration\StatusCommand::class); $this->addCommand(Migration\MigrateCommand::class); $this->addCommand(Migration\ResetCommand::class); $this->addCommand(Migration\DropAllCommand::class); $this->addGlobalOption('d') ->alias('dir') ->description('Set migration file directory.'); $this->addGlobalOption('p') ->alias('package') ->description('Package to run migration.'); }
php
public function init() { $this->addCommand(Migration\CreateCommand::class); $this->addCommand(Migration\StatusCommand::class); $this->addCommand(Migration\MigrateCommand::class); $this->addCommand(Migration\ResetCommand::class); $this->addCommand(Migration\DropAllCommand::class); $this->addGlobalOption('d') ->alias('dir') ->description('Set migration file directory.'); $this->addGlobalOption('p') ->alias('package') ->description('Package to run migration.'); }
[ "public", "function", "init", "(", ")", "{", "$", "this", "->", "addCommand", "(", "Migration", "\\", "CreateCommand", "::", "class", ")", ";", "$", "this", "->", "addCommand", "(", "Migration", "\\", "StatusCommand", "::", "class", ")", ";", "$", "this", "->", "addCommand", "(", "Migration", "\\", "MigrateCommand", "::", "class", ")", ";", "$", "this", "->", "addCommand", "(", "Migration", "\\", "ResetCommand", "::", "class", ")", ";", "$", "this", "->", "addCommand", "(", "Migration", "\\", "DropAllCommand", "::", "class", ")", ";", "$", "this", "->", "addGlobalOption", "(", "'d'", ")", "->", "alias", "(", "'dir'", ")", "->", "description", "(", "'Set migration file directory.'", ")", ";", "$", "this", "->", "addGlobalOption", "(", "'p'", ")", "->", "alias", "(", "'package'", ")", "->", "description", "(", "'Package to run migration.'", ")", ";", "}" ]
Configure command information. @return void
[ "Configure", "command", "information", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Migration/Command/MigrationCommand.php#L59-L74
29,876
acdh-oeaw/repo-php-util
src/acdhOeaw/util/Indexer.php
Indexer.setParent
public function setParent(FedoraResource $resource): Indexer { $this->parent = $resource; $this->fedora = $this->parent->getFedora(); $metadata = $this->parent->getMetadata(); $locations = $metadata->allLiterals(RC::locProp()); foreach ($locations as $i) { $loc = preg_replace('|/$|', '', self::containerDir() . $i->getValue()); if (is_dir($loc)) { $this->paths[] = $i->getValue(); } } return $this; }
php
public function setParent(FedoraResource $resource): Indexer { $this->parent = $resource; $this->fedora = $this->parent->getFedora(); $metadata = $this->parent->getMetadata(); $locations = $metadata->allLiterals(RC::locProp()); foreach ($locations as $i) { $loc = preg_replace('|/$|', '', self::containerDir() . $i->getValue()); if (is_dir($loc)) { $this->paths[] = $i->getValue(); } } return $this; }
[ "public", "function", "setParent", "(", "FedoraResource", "$", "resource", ")", ":", "Indexer", "{", "$", "this", "->", "parent", "=", "$", "resource", ";", "$", "this", "->", "fedora", "=", "$", "this", "->", "parent", "->", "getFedora", "(", ")", ";", "$", "metadata", "=", "$", "this", "->", "parent", "->", "getMetadata", "(", ")", ";", "$", "locations", "=", "$", "metadata", "->", "allLiterals", "(", "RC", "::", "locProp", "(", ")", ")", ";", "foreach", "(", "$", "locations", "as", "$", "i", ")", "{", "$", "loc", "=", "preg_replace", "(", "'|/$|'", ",", "''", ",", "self", "::", "containerDir", "(", ")", ".", "$", "i", "->", "getValue", "(", ")", ")", ";", "if", "(", "is_dir", "(", "$", "loc", ")", ")", "{", "$", "this", "->", "paths", "[", "]", "=", "$", "i", "->", "getValue", "(", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Sets the parent resource for the indexed files @param FedoraResource $resource
[ "Sets", "the", "parent", "resource", "for", "the", "indexed", "files" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/Indexer.php#L233-L245
29,877
acdh-oeaw/repo-php-util
src/acdhOeaw/util/Indexer.php
Indexer.setSkip
public function setSkip(int $skipMode): Indexer { if (!in_array($skipMode, [self::SKIP_NONE, self::SKIP_NOT_EXIST, self::SKIP_EXIST, self::SKIP_BINARY_EXIST])) { throw new BadMethodCallException('Wrong skip mode'); } $this->skipMode = $skipMode; return $this; }
php
public function setSkip(int $skipMode): Indexer { if (!in_array($skipMode, [self::SKIP_NONE, self::SKIP_NOT_EXIST, self::SKIP_EXIST, self::SKIP_BINARY_EXIST])) { throw new BadMethodCallException('Wrong skip mode'); } $this->skipMode = $skipMode; return $this; }
[ "public", "function", "setSkip", "(", "int", "$", "skipMode", ")", ":", "Indexer", "{", "if", "(", "!", "in_array", "(", "$", "skipMode", ",", "[", "self", "::", "SKIP_NONE", ",", "self", "::", "SKIP_NOT_EXIST", ",", "self", "::", "SKIP_EXIST", ",", "self", "::", "SKIP_BINARY_EXIST", "]", ")", ")", "{", "throw", "new", "BadMethodCallException", "(", "'Wrong skip mode'", ")", ";", "}", "$", "this", "->", "skipMode", "=", "$", "skipMode", ";", "return", "$", "this", ";", "}" ]
Allows to turn on skipping of already existing resource or resources which don't exist in the Fedora already. @param int $skipMode mode either Indexer::SKIP_NONE (default), Indexer::SKIP_NOT_EXIST, Indexer::SKIP_EXIST or Indexer::SKIP_BINARY_EXIST @return \acdhOeaw\util\Indexer
[ "Allows", "to", "turn", "on", "skipping", "of", "already", "existing", "resource", "or", "resources", "which", "don", "t", "exist", "in", "the", "Fedora", "already", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/Indexer.php#L283-L289
29,878
acdh-oeaw/repo-php-util
src/acdhOeaw/util/Indexer.php
Indexer.setFilter
public function setFilter(string $filter, int $type = self::MATCH): Indexer { switch ($type) { case self::MATCH: $this->filter = $filter; break; case self::SKIP: $this->filterNot = $filter; break; default: throw new BadMethodCallException('wrong $type parameter'); } return $this; }
php
public function setFilter(string $filter, int $type = self::MATCH): Indexer { switch ($type) { case self::MATCH: $this->filter = $filter; break; case self::SKIP: $this->filterNot = $filter; break; default: throw new BadMethodCallException('wrong $type parameter'); } return $this; }
[ "public", "function", "setFilter", "(", "string", "$", "filter", ",", "int", "$", "type", "=", "self", "::", "MATCH", ")", ":", "Indexer", "{", "switch", "(", "$", "type", ")", "{", "case", "self", "::", "MATCH", ":", "$", "this", "->", "filter", "=", "$", "filter", ";", "break", ";", "case", "self", "::", "SKIP", ":", "$", "this", "->", "filterNot", "=", "$", "filter", ";", "break", ";", "default", ":", "throw", "new", "BadMethodCallException", "(", "'wrong $type parameter'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets file name filter for child resources. You can choose if file names must match or must not match (skip) the filter using the $type parameter. You can set both match and skip filters by calling setFilter() two times (once with `$type = Indexer::MATCH` and second time with `$type = Indexer::SKIP`). Filter is applied only to file names but NOT to directory names. @param string $filter regular expression conformant with preg_replace() @param int $type decides if $filter is a match or skip filter (can be one of Indexer::MATCH and Indexer::SKIP) @return \acdhOeaw\util\Indexer
[ "Sets", "file", "name", "filter", "for", "child", "resources", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/Indexer.php#L332-L344
29,879
acdh-oeaw/repo-php-util
src/acdhOeaw/util/Indexer.php
Indexer.setMetaLookup
public function setMetaLookup(MetaLookupInterface $metaLookup, bool $require = false): Indexer { $this->metaLookup = $metaLookup; $this->metaLookupRequire = $require; return $this; }
php
public function setMetaLookup(MetaLookupInterface $metaLookup, bool $require = false): Indexer { $this->metaLookup = $metaLookup; $this->metaLookupRequire = $require; return $this; }
[ "public", "function", "setMetaLookup", "(", "MetaLookupInterface", "$", "metaLookup", ",", "bool", "$", "require", "=", "false", ")", ":", "Indexer", "{", "$", "this", "->", "metaLookup", "=", "$", "metaLookup", ";", "$", "this", "->", "metaLookupRequire", "=", "$", "require", ";", "return", "$", "this", ";", "}" ]
Sets a class providing metadata for indexed files. @param MetaLookupInterface $metaLookup @param bool $require should files lacking external metadata be skipped @return \acdhOeaw\util\Indexer
[ "Sets", "a", "class", "providing", "metadata", "for", "indexed", "files", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/Indexer.php#L425-L430
29,880
acdh-oeaw/repo-php-util
src/acdhOeaw/util/Indexer.php
Indexer.isSkippedExisting
private function isSkippedExisting(File $file): bool { if (!in_array($this->skipMode, [self::SKIP_EXIST, self::SKIP_BINARY_EXIST])) { return false; } try { $res = $file->getResource(false, false); return $res->isBinary() || $this->skipMode === self::SKIP_EXIST; } catch (MetaLookupException $e) { if ($this->metaLookupRequire) { return true; } else { throw $e; } } catch (NotFound $e) { return false; } }
php
private function isSkippedExisting(File $file): bool { if (!in_array($this->skipMode, [self::SKIP_EXIST, self::SKIP_BINARY_EXIST])) { return false; } try { $res = $file->getResource(false, false); return $res->isBinary() || $this->skipMode === self::SKIP_EXIST; } catch (MetaLookupException $e) { if ($this->metaLookupRequire) { return true; } else { throw $e; } } catch (NotFound $e) { return false; } }
[ "private", "function", "isSkippedExisting", "(", "File", "$", "file", ")", ":", "bool", "{", "if", "(", "!", "in_array", "(", "$", "this", "->", "skipMode", ",", "[", "self", "::", "SKIP_EXIST", ",", "self", "::", "SKIP_BINARY_EXIST", "]", ")", ")", "{", "return", "false", ";", "}", "try", "{", "$", "res", "=", "$", "file", "->", "getResource", "(", "false", ",", "false", ")", ";", "return", "$", "res", "->", "isBinary", "(", ")", "||", "$", "this", "->", "skipMode", "===", "self", "::", "SKIP_EXIST", ";", "}", "catch", "(", "MetaLookupException", "$", "e", ")", "{", "if", "(", "$", "this", "->", "metaLookupRequire", ")", "{", "return", "true", ";", "}", "else", "{", "throw", "$", "e", ";", "}", "}", "catch", "(", "NotFound", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
Checks if a given file should be skipped because it already exists in the repository while the Indexer skip mode is set to SKIP_EXIST or SKIP_BINARY_EXIST. @param File $file file to be checked @return bool @throws MetaLookupException
[ "Checks", "if", "a", "given", "file", "should", "be", "skipped", "because", "it", "already", "exists", "in", "the", "repository", "while", "the", "Indexer", "skip", "mode", "is", "set", "to", "SKIP_EXIST", "or", "SKIP_BINARY_EXIST", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/Indexer.php#L555-L571
29,881
acdh-oeaw/repo-php-util
src/acdhOeaw/util/Indexer.php
Indexer.isSkipped
private function isSkipped(DirectoryIterator $i): bool { $isEmptyDir = true; if ($i->isDir()) { foreach (new DirectoryIterator($i->getPathname()) as $j) { if (!$j->isDot()) { $isEmptyDir = false; break; } } } $skipDir = (!$this->includeEmpty && ($this->depth == 0 || $isEmptyDir) || $this->flatStructure); $filenameInclude = preg_match($this->filter, $i->getFilename()); $filenameExclude = strlen($this->filterNot) > 0 && preg_match($this->filterNot, $i->getFilename()); $skipFile = !$filenameInclude || $filenameExclude; return $i->isDir() && $skipDir || !$i->isDir() && $skipFile; }
php
private function isSkipped(DirectoryIterator $i): bool { $isEmptyDir = true; if ($i->isDir()) { foreach (new DirectoryIterator($i->getPathname()) as $j) { if (!$j->isDot()) { $isEmptyDir = false; break; } } } $skipDir = (!$this->includeEmpty && ($this->depth == 0 || $isEmptyDir) || $this->flatStructure); $filenameInclude = preg_match($this->filter, $i->getFilename()); $filenameExclude = strlen($this->filterNot) > 0 && preg_match($this->filterNot, $i->getFilename()); $skipFile = !$filenameInclude || $filenameExclude; return $i->isDir() && $skipDir || !$i->isDir() && $skipFile; }
[ "private", "function", "isSkipped", "(", "DirectoryIterator", "$", "i", ")", ":", "bool", "{", "$", "isEmptyDir", "=", "true", ";", "if", "(", "$", "i", "->", "isDir", "(", ")", ")", "{", "foreach", "(", "new", "DirectoryIterator", "(", "$", "i", "->", "getPathname", "(", ")", ")", "as", "$", "j", ")", "{", "if", "(", "!", "$", "j", "->", "isDot", "(", ")", ")", "{", "$", "isEmptyDir", "=", "false", ";", "break", ";", "}", "}", "}", "$", "skipDir", "=", "(", "!", "$", "this", "->", "includeEmpty", "&&", "(", "$", "this", "->", "depth", "==", "0", "||", "$", "isEmptyDir", ")", "||", "$", "this", "->", "flatStructure", ")", ";", "$", "filenameInclude", "=", "preg_match", "(", "$", "this", "->", "filter", ",", "$", "i", "->", "getFilename", "(", ")", ")", ";", "$", "filenameExclude", "=", "strlen", "(", "$", "this", "->", "filterNot", ")", ">", "0", "&&", "preg_match", "(", "$", "this", "->", "filterNot", ",", "$", "i", "->", "getFilename", "(", ")", ")", ";", "$", "skipFile", "=", "!", "$", "filenameInclude", "||", "$", "filenameExclude", ";", "return", "$", "i", "->", "isDir", "(", ")", "&&", "$", "skipDir", "||", "!", "$", "i", "->", "isDir", "(", ")", "&&", "$", "skipFile", ";", "}" ]
Checks if a given file system node should be skipped during import. @param DirectoryIterator $i file system node @return bool
[ "Checks", "if", "a", "given", "file", "system", "node", "should", "be", "skipped", "during", "import", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/Indexer.php#L579-L594
29,882
acdh-oeaw/repo-php-util
src/acdhOeaw/util/Indexer.php
Indexer.handleAutoCommit
private function handleAutoCommit(): bool { $diff = count($this->indexedRes) - count($this->commitedRes); if ($diff >= $this->autoCommit && $this->autoCommit > 0) { echo self::$debug ? " + autocommit" : ''; $this->fedora->commit(); $this->commitedRes = $this->indexedRes; $this->fedora->begin(); return true; } return false; }
php
private function handleAutoCommit(): bool { $diff = count($this->indexedRes) - count($this->commitedRes); if ($diff >= $this->autoCommit && $this->autoCommit > 0) { echo self::$debug ? " + autocommit" : ''; $this->fedora->commit(); $this->commitedRes = $this->indexedRes; $this->fedora->begin(); return true; } return false; }
[ "private", "function", "handleAutoCommit", "(", ")", ":", "bool", "{", "$", "diff", "=", "count", "(", "$", "this", "->", "indexedRes", ")", "-", "count", "(", "$", "this", "->", "commitedRes", ")", ";", "if", "(", "$", "diff", ">=", "$", "this", "->", "autoCommit", "&&", "$", "this", "->", "autoCommit", ">", "0", ")", "{", "echo", "self", "::", "$", "debug", "?", "\" + autocommit\"", ":", "''", ";", "$", "this", "->", "fedora", "->", "commit", "(", ")", ";", "$", "this", "->", "commitedRes", "=", "$", "this", "->", "indexedRes", ";", "$", "this", "->", "fedora", "->", "begin", "(", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Performs autocommit if needed @return bool if autocommit was performed
[ "Performs", "autocommit", "if", "needed" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/Indexer.php#L600-L610
29,883
ventoviro/windwalker-core
src/Core/Package/AbstractPackage.php
AbstractPackage.registerCommands
public function registerCommands(Console $console) { $commands = (array) $this->get('console.commands'); foreach ($commands as $class) { if (class_exists($class) && is_subclass_of($class, Command::class)) { $console->addCommand($this->container->createObject($class)); } } }
php
public function registerCommands(Console $console) { $commands = (array) $this->get('console.commands'); foreach ($commands as $class) { if (class_exists($class) && is_subclass_of($class, Command::class)) { $console->addCommand($this->container->createObject($class)); } } }
[ "public", "function", "registerCommands", "(", "Console", "$", "console", ")", "{", "$", "commands", "=", "(", "array", ")", "$", "this", "->", "get", "(", "'console.commands'", ")", ";", "foreach", "(", "$", "commands", "as", "$", "class", ")", "{", "if", "(", "class_exists", "(", "$", "class", ")", "&&", "is_subclass_of", "(", "$", "class", ",", "Command", "::", "class", ")", ")", "{", "$", "console", "->", "addCommand", "(", "$", "this", "->", "container", "->", "createObject", "(", "$", "class", ")", ")", ";", "}", "}", "}" ]
Register commands to console. @param Console $console Windwalker console object. @return void
[ "Register", "commands", "to", "console", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Package/AbstractPackage.php#L429-L438
29,884
ventoviro/windwalker-core
src/Core/Package/AbstractPackage.php
AbstractPackage.getConfig
public function getConfig() { if (!$this->config) { $this->config = new Structure(); $this->loadConfig($this->config); } return $this->config; }
php
public function getConfig() { if (!$this->config) { $this->config = new Structure(); $this->loadConfig($this->config); } return $this->config; }
[ "public", "function", "getConfig", "(", ")", "{", "if", "(", "!", "$", "this", "->", "config", ")", "{", "$", "this", "->", "config", "=", "new", "Structure", "(", ")", ";", "$", "this", "->", "loadConfig", "(", "$", "this", "->", "config", ")", ";", "}", "return", "$", "this", "->", "config", ";", "}" ]
Method to get property Config @return Structure @since 2.1 @throws \ReflectionException
[ "Method", "to", "get", "property", "Config" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Package/AbstractPackage.php#L897-L906
29,885
secucard/secucard-connect-php-sdk
src/SecucardConnect/Util/GuzzleLogger.php
GuzzleLogger.onSuccess
protected function onSuccess(RequestInterface $request) { return function ($response) use ($request) { $this->log($request, $response); return $response; }; }
php
protected function onSuccess(RequestInterface $request) { return function ($response) use ($request) { $this->log($request, $response); return $response; }; }
[ "protected", "function", "onSuccess", "(", "RequestInterface", "$", "request", ")", "{", "return", "function", "(", "$", "response", ")", "use", "(", "$", "request", ")", "{", "$", "this", "->", "log", "(", "$", "request", ",", "$", "response", ")", ";", "return", "$", "response", ";", "}", ";", "}" ]
Returns a function which is handled when a request was successful. @param RequestInterface $request @return Closure
[ "Returns", "a", "function", "which", "is", "handled", "when", "a", "request", "was", "successful", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Util/GuzzleLogger.php#L90-L96
29,886
secucard/secucard-connect-php-sdk
src/SecucardConnect/Util/GuzzleLogger.php
GuzzleLogger.onFailure
protected function onFailure(RequestInterface $request) { return function ($reason) use ($request) { // Only log a rejected requests if it hasn't already been logged $this->log($request, null, $reason); return Promise\rejection_for($reason); }; }
php
protected function onFailure(RequestInterface $request) { return function ($reason) use ($request) { // Only log a rejected requests if it hasn't already been logged $this->log($request, null, $reason); return Promise\rejection_for($reason); }; }
[ "protected", "function", "onFailure", "(", "RequestInterface", "$", "request", ")", "{", "return", "function", "(", "$", "reason", ")", "use", "(", "$", "request", ")", "{", "// Only log a rejected requests if it hasn't already been logged", "$", "this", "->", "log", "(", "$", "request", ",", "null", ",", "$", "reason", ")", ";", "return", "Promise", "\\", "rejection_for", "(", "$", "reason", ")", ";", "}", ";", "}" ]
Returns a function which is handled when a request was rejected. @param RequestInterface $request @return Closure
[ "Returns", "a", "function", "which", "is", "handled", "when", "a", "request", "was", "rejected", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Util/GuzzleLogger.php#L105-L114
29,887
polyfony-inc/polyfony
Private/Polyfony/Query.php
Query.query
public function query( string $query, $values=null, $table=null ) { // set the main action $this->action('QUERY'); // set the table $this->Table = $table; // set the query $this->Query = $query; // set the array of values $this->Values = $values; // detetect the action $action = substr($query, 0, 6); // if action can alter a table (INSERT, UPDATE, DELETE) if(in_array($action, array('INSERT', 'UPDATE', 'DELETE', 'SELECT'))) { // in case of INSERT if($action == 'INSERT') { // explode after INTO list(,$table) = explode('INTO ', $this->Query); // isolate the table name list($this->Table) = explode(' ', $table); } // in case of UPDATE elseif($action == 'UPDATE') { // explode after UPDATE list(,$table) = explode('UPDATE ', $this->Query); // isolate the table name list($this->Table) = explode(' ', $table); } // in case of DELETE or SELECT elseif($action == 'DELETE' || $action == 'SELECT') { // explode after FROM list(,$table) = explode('FROM ', $this->Query); // isolate the table name list($this->Table) = explode(' ', $table); } // clean the table name from any quotes $this->Table = trim($this->Table, '\'/"`'); } // return self to the next method return $this; }
php
public function query( string $query, $values=null, $table=null ) { // set the main action $this->action('QUERY'); // set the table $this->Table = $table; // set the query $this->Query = $query; // set the array of values $this->Values = $values; // detetect the action $action = substr($query, 0, 6); // if action can alter a table (INSERT, UPDATE, DELETE) if(in_array($action, array('INSERT', 'UPDATE', 'DELETE', 'SELECT'))) { // in case of INSERT if($action == 'INSERT') { // explode after INTO list(,$table) = explode('INTO ', $this->Query); // isolate the table name list($this->Table) = explode(' ', $table); } // in case of UPDATE elseif($action == 'UPDATE') { // explode after UPDATE list(,$table) = explode('UPDATE ', $this->Query); // isolate the table name list($this->Table) = explode(' ', $table); } // in case of DELETE or SELECT elseif($action == 'DELETE' || $action == 'SELECT') { // explode after FROM list(,$table) = explode('FROM ', $this->Query); // isolate the table name list($this->Table) = explode(' ', $table); } // clean the table name from any quotes $this->Table = trim($this->Table, '\'/"`'); } // return self to the next method return $this; }
[ "public", "function", "query", "(", "string", "$", "query", ",", "$", "values", "=", "null", ",", "$", "table", "=", "null", ")", "{", "// set the main action", "$", "this", "->", "action", "(", "'QUERY'", ")", ";", "// set the table", "$", "this", "->", "Table", "=", "$", "table", ";", "// set the query", "$", "this", "->", "Query", "=", "$", "query", ";", "// set the array of values", "$", "this", "->", "Values", "=", "$", "values", ";", "// detetect the action", "$", "action", "=", "substr", "(", "$", "query", ",", "0", ",", "6", ")", ";", "// if action can alter a table (INSERT, UPDATE, DELETE)", "if", "(", "in_array", "(", "$", "action", ",", "array", "(", "'INSERT'", ",", "'UPDATE'", ",", "'DELETE'", ",", "'SELECT'", ")", ")", ")", "{", "// in case of INSERT", "if", "(", "$", "action", "==", "'INSERT'", ")", "{", "// explode after INTO", "list", "(", ",", "$", "table", ")", "=", "explode", "(", "'INTO '", ",", "$", "this", "->", "Query", ")", ";", "// isolate the table name", "list", "(", "$", "this", "->", "Table", ")", "=", "explode", "(", "' '", ",", "$", "table", ")", ";", "}", "// in case of UPDATE", "elseif", "(", "$", "action", "==", "'UPDATE'", ")", "{", "// explode after UPDATE", "list", "(", ",", "$", "table", ")", "=", "explode", "(", "'UPDATE '", ",", "$", "this", "->", "Query", ")", ";", "// isolate the table name", "list", "(", "$", "this", "->", "Table", ")", "=", "explode", "(", "' '", ",", "$", "table", ")", ";", "}", "// in case of DELETE or SELECT", "elseif", "(", "$", "action", "==", "'DELETE'", "||", "$", "action", "==", "'SELECT'", ")", "{", "// explode after FROM ", "list", "(", ",", "$", "table", ")", "=", "explode", "(", "'FROM '", ",", "$", "this", "->", "Query", ")", ";", "// isolate the table name", "list", "(", "$", "this", "->", "Table", ")", "=", "explode", "(", "' '", ",", "$", "table", ")", ";", "}", "// clean the table name from any quotes", "$", "this", "->", "Table", "=", "trim", "(", "$", "this", "->", "Table", ",", "'\\'/\"`'", ")", ";", "}", "// return self to the next method", "return", "$", "this", ";", "}" ]
passrthu a query with values if needed
[ "passrthu", "a", "query", "with", "values", "if", "needed" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Query.php#L18-L61
29,888
polyfony-inc/polyfony
Private/Polyfony/Query.php
Query.select
public function select(array $array=[]) { // set the main action $this->action('SELECT'); // for each column foreach($array as $function_or_index_or_column => $column) { // secure the column name list($column, $placeholder) = Query\Convert::columnToPlaceholder($this->Quote ,$column, true); // if the key is function_or_index_or_column if(is_numeric($function_or_index_or_column)) { // just select the column $this->Selects[] = $column; } // the key contains a dot, we are trying to create a alias elseif(stripos($function_or_index_or_column, '.') !== false) { // secure the column list($column) = Query\Convert::columnToPlaceholder($this->Quote ,$function_or_index_or_column); // select the column and create an alias $this->Selects[] = "{$column} AS {$placeholder}"; } // the key is a SQL function else { // secure the function list($function) = Query\Convert::columnToPlaceholder($this->Quote ,$function_or_index_or_column); // select the column using a function $this->Selects[] = "{$function}({$column}) AS {$function}_{$placeholder}"; } } // return self to the next method return $this; }
php
public function select(array $array=[]) { // set the main action $this->action('SELECT'); // for each column foreach($array as $function_or_index_or_column => $column) { // secure the column name list($column, $placeholder) = Query\Convert::columnToPlaceholder($this->Quote ,$column, true); // if the key is function_or_index_or_column if(is_numeric($function_or_index_or_column)) { // just select the column $this->Selects[] = $column; } // the key contains a dot, we are trying to create a alias elseif(stripos($function_or_index_or_column, '.') !== false) { // secure the column list($column) = Query\Convert::columnToPlaceholder($this->Quote ,$function_or_index_or_column); // select the column and create an alias $this->Selects[] = "{$column} AS {$placeholder}"; } // the key is a SQL function else { // secure the function list($function) = Query\Convert::columnToPlaceholder($this->Quote ,$function_or_index_or_column); // select the column using a function $this->Selects[] = "{$function}({$column}) AS {$function}_{$placeholder}"; } } // return self to the next method return $this; }
[ "public", "function", "select", "(", "array", "$", "array", "=", "[", "]", ")", "{", "// set the main action", "$", "this", "->", "action", "(", "'SELECT'", ")", ";", "// for each column", "foreach", "(", "$", "array", "as", "$", "function_or_index_or_column", "=>", "$", "column", ")", "{", "// secure the column name", "list", "(", "$", "column", ",", "$", "placeholder", ")", "=", "Query", "\\", "Convert", "::", "columnToPlaceholder", "(", "$", "this", "->", "Quote", ",", "$", "column", ",", "true", ")", ";", "// if the key is function_or_index_or_column", "if", "(", "is_numeric", "(", "$", "function_or_index_or_column", ")", ")", "{", "// just select the column", "$", "this", "->", "Selects", "[", "]", "=", "$", "column", ";", "}", "// the key contains a dot, we are trying to create a alias", "elseif", "(", "stripos", "(", "$", "function_or_index_or_column", ",", "'.'", ")", "!==", "false", ")", "{", "// secure the column", "list", "(", "$", "column", ")", "=", "Query", "\\", "Convert", "::", "columnToPlaceholder", "(", "$", "this", "->", "Quote", ",", "$", "function_or_index_or_column", ")", ";", "// select the column and create an alias", "$", "this", "->", "Selects", "[", "]", "=", "\"{$column} AS {$placeholder}\"", ";", "}", "// the key is a SQL function", "else", "{", "// secure the function", "list", "(", "$", "function", ")", "=", "Query", "\\", "Convert", "::", "columnToPlaceholder", "(", "$", "this", "->", "Quote", ",", "$", "function_or_index_or_column", ")", ";", "// select the column using a function", "$", "this", "->", "Selects", "[", "]", "=", "\"{$function}({$column}) AS {$function}_{$placeholder}\"", ";", "}", "}", "// return self to the next method", "return", "$", "this", ";", "}" ]
first main method
[ "first", "main", "method" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Query.php#L64-L93
29,889
polyfony-inc/polyfony
Private/Polyfony/Query.php
Query.set
public function set(array $columns_and_values) { // for each provided strict condition foreach($columns_and_values as $column => $value) { // secure the column name list($column, $placeholder) = Query\Convert::columnToPlaceholder($this->Quote ,$column); // save the condition $this->Updates[] = "{$column} = :{$placeholder}"; // save the value (converted if necessary) $this->Values[":{$placeholder}"] = Query\Convert::valueForDatabase($column,$value); } // return self to the next method return $this; }
php
public function set(array $columns_and_values) { // for each provided strict condition foreach($columns_and_values as $column => $value) { // secure the column name list($column, $placeholder) = Query\Convert::columnToPlaceholder($this->Quote ,$column); // save the condition $this->Updates[] = "{$column} = :{$placeholder}"; // save the value (converted if necessary) $this->Values[":{$placeholder}"] = Query\Convert::valueForDatabase($column,$value); } // return self to the next method return $this; }
[ "public", "function", "set", "(", "array", "$", "columns_and_values", ")", "{", "// for each provided strict condition", "foreach", "(", "$", "columns_and_values", "as", "$", "column", "=>", "$", "value", ")", "{", "// secure the column name", "list", "(", "$", "column", ",", "$", "placeholder", ")", "=", "Query", "\\", "Convert", "::", "columnToPlaceholder", "(", "$", "this", "->", "Quote", ",", "$", "column", ")", ";", "// save the condition", "$", "this", "->", "Updates", "[", "]", "=", "\"{$column} = :{$placeholder}\"", ";", "// save the value (converted if necessary)", "$", "this", "->", "Values", "[", "\":{$placeholder}\"", "]", "=", "Query", "\\", "Convert", "::", "valueForDatabase", "(", "$", "column", ",", "$", "value", ")", ";", "}", "// return self to the next method", "return", "$", "this", ";", "}" ]
alias of update
[ "alias", "of", "update" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Query.php#L96-L108
29,890
polyfony-inc/polyfony
Private/Polyfony/Query.php
Query.update
public function update(string $table) { // set the main action $this->action('UPDATE'); // set the destination table list($this->Table) = Query\Convert::columnToPlaceholder($this->Quote ,$table); // return self to the next method return $this; }
php
public function update(string $table) { // set the main action $this->action('UPDATE'); // set the destination table list($this->Table) = Query\Convert::columnToPlaceholder($this->Quote ,$table); // return self to the next method return $this; }
[ "public", "function", "update", "(", "string", "$", "table", ")", "{", "// set the main action", "$", "this", "->", "action", "(", "'UPDATE'", ")", ";", "// set the destination table", "list", "(", "$", "this", "->", "Table", ")", "=", "Query", "\\", "Convert", "::", "columnToPlaceholder", "(", "$", "this", "->", "Quote", ",", "$", "table", ")", ";", "// return self to the next method", "return", "$", "this", ";", "}" ]
second main method
[ "second", "main", "method" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Query.php#L111-L118
29,891
polyfony-inc/polyfony
Private/Polyfony/Query.php
Query.from
public function from(string $table) { // set the table list($this->Table) = Query\Convert::columnToPlaceholder($this->Quote ,$table); // return self to the next method return $this; }
php
public function from(string $table) { // set the table list($this->Table) = Query\Convert::columnToPlaceholder($this->Quote ,$table); // return self to the next method return $this; }
[ "public", "function", "from", "(", "string", "$", "table", ")", "{", "// set the table", "list", "(", "$", "this", "->", "Table", ")", "=", "Query", "\\", "Convert", "::", "columnToPlaceholder", "(", "$", "this", "->", "Quote", ",", "$", "table", ")", ";", "// return self to the next method", "return", "$", "this", ";", "}" ]
select the table
[ "select", "the", "table" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Query.php#L146-L151
29,892
polyfony-inc/polyfony
Private/Polyfony/Query.php
Query.orderBy
public function orderBy(array $columns_and_direction) { // for each given parameter foreach($columns_and_direction as $column => $direction) { // if the direction is not valid force ASC $direction == 'ASC' || $direction == 'DESC' ?: $direction = 'ASC'; // secure the column name list($column) = Query\Convert::columnToPlaceholder($this->Quote ,$column); // push it $this->Order[] = "{$column} $direction"; } // return self to the next method return $this; }
php
public function orderBy(array $columns_and_direction) { // for each given parameter foreach($columns_and_direction as $column => $direction) { // if the direction is not valid force ASC $direction == 'ASC' || $direction == 'DESC' ?: $direction = 'ASC'; // secure the column name list($column) = Query\Convert::columnToPlaceholder($this->Quote ,$column); // push it $this->Order[] = "{$column} $direction"; } // return self to the next method return $this; }
[ "public", "function", "orderBy", "(", "array", "$", "columns_and_direction", ")", "{", "// for each given parameter", "foreach", "(", "$", "columns_and_direction", "as", "$", "column", "=>", "$", "direction", ")", "{", "// if the direction is not valid force ASC", "$", "direction", "==", "'ASC'", "||", "$", "direction", "==", "'DESC'", "?", ":", "$", "direction", "=", "'ASC'", ";", "// secure the column name", "list", "(", "$", "column", ")", "=", "Query", "\\", "Convert", "::", "columnToPlaceholder", "(", "$", "this", "->", "Quote", ",", "$", "column", ")", ";", "// push it", "$", "this", "->", "Order", "[", "]", "=", "\"{$column} $direction\"", ";", "}", "// return self to the next method", "return", "$", "this", ";", "}" ]
add an order clause
[ "add", "an", "order", "clause" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Query.php#L232-L244
29,893
polyfony-inc/polyfony
Private/Polyfony/Query.php
Query.groupBy
public function groupBy(array $columns) { // for each given parameter foreach($columns as $column) { // secure the column name list($column) = Query\Convert::columnToPlaceholder($this->Quote ,$column); // push it $this->Groups[] = $column; } // return self to the next method return $this; }
php
public function groupBy(array $columns) { // for each given parameter foreach($columns as $column) { // secure the column name list($column) = Query\Convert::columnToPlaceholder($this->Quote ,$column); // push it $this->Groups[] = $column; } // return self to the next method return $this; }
[ "public", "function", "groupBy", "(", "array", "$", "columns", ")", "{", "// for each given parameter", "foreach", "(", "$", "columns", "as", "$", "column", ")", "{", "// secure the column name", "list", "(", "$", "column", ")", "=", "Query", "\\", "Convert", "::", "columnToPlaceholder", "(", "$", "this", "->", "Quote", ",", "$", "column", ")", ";", "// push it", "$", "this", "->", "Groups", "[", "]", "=", "$", "column", ";", "}", "// return self to the next method", "return", "$", "this", ";", "}" ]
add a group clause
[ "add", "a", "group", "clause" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Query.php#L247-L257
29,894
polyfony-inc/polyfony
Private/Polyfony/Query.php
Query.limitTo
public function limitTo(int $from, int $until) { // build the limit to $this->Limit = array($from, $until); // return self to the next method return $this; }
php
public function limitTo(int $from, int $until) { // build the limit to $this->Limit = array($from, $until); // return self to the next method return $this; }
[ "public", "function", "limitTo", "(", "int", "$", "from", ",", "int", "$", "until", ")", "{", "// build the limit to ", "$", "this", "->", "Limit", "=", "array", "(", "$", "from", ",", "$", "until", ")", ";", "// return self to the next method", "return", "$", "this", ";", "}" ]
add a limit clause
[ "add", "a", "limit", "clause" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Query.php#L260-L265
29,895
ventoviro/windwalker-core
src/Debugger/Controller/Mail/GetController.php
GetController.doExecute
protected function doExecute() { $class = $this->input->getString('class'); $view = $this->getView(); if ($class && is_subclass_of($class, MailMessage::class)) { Mailer::getContainer() ->prepareSharedObject(DebugMailerAdapter::class) ->bindShared(MailerAdapterInterface::class, DebugMailerAdapter::class); /** @var MailMessage $message */ $message = Mailer::send($class::create()); $view['message'] = $message; // Set default sender if (!$message->getFrom()) { $config = $this->app->config; if ($config->exists('mail.from.email')) { $message->from($config->get('mail.from.email'), $config->get('mail.from.name')); } } } $view['class'] = $class; return $view->render(); }
php
protected function doExecute() { $class = $this->input->getString('class'); $view = $this->getView(); if ($class && is_subclass_of($class, MailMessage::class)) { Mailer::getContainer() ->prepareSharedObject(DebugMailerAdapter::class) ->bindShared(MailerAdapterInterface::class, DebugMailerAdapter::class); /** @var MailMessage $message */ $message = Mailer::send($class::create()); $view['message'] = $message; // Set default sender if (!$message->getFrom()) { $config = $this->app->config; if ($config->exists('mail.from.email')) { $message->from($config->get('mail.from.email'), $config->get('mail.from.name')); } } } $view['class'] = $class; return $view->render(); }
[ "protected", "function", "doExecute", "(", ")", "{", "$", "class", "=", "$", "this", "->", "input", "->", "getString", "(", "'class'", ")", ";", "$", "view", "=", "$", "this", "->", "getView", "(", ")", ";", "if", "(", "$", "class", "&&", "is_subclass_of", "(", "$", "class", ",", "MailMessage", "::", "class", ")", ")", "{", "Mailer", "::", "getContainer", "(", ")", "->", "prepareSharedObject", "(", "DebugMailerAdapter", "::", "class", ")", "->", "bindShared", "(", "MailerAdapterInterface", "::", "class", ",", "DebugMailerAdapter", "::", "class", ")", ";", "/** @var MailMessage $message */", "$", "message", "=", "Mailer", "::", "send", "(", "$", "class", "::", "create", "(", ")", ")", ";", "$", "view", "[", "'message'", "]", "=", "$", "message", ";", "// Set default sender", "if", "(", "!", "$", "message", "->", "getFrom", "(", ")", ")", "{", "$", "config", "=", "$", "this", "->", "app", "->", "config", ";", "if", "(", "$", "config", "->", "exists", "(", "'mail.from.email'", ")", ")", "{", "$", "message", "->", "from", "(", "$", "config", "->", "get", "(", "'mail.from.email'", ")", ",", "$", "config", "->", "get", "(", "'mail.from.name'", ")", ")", ";", "}", "}", "}", "$", "view", "[", "'class'", "]", "=", "$", "class", ";", "return", "$", "view", "->", "render", "(", ")", ";", "}" ]
Do execute action. @return mixed @throws \Exception
[ "Do", "execute", "action", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Debugger/Controller/Mail/GetController.php#L31-L60
29,896
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/Fedora.php
Fedora.attachData
static public function attachData(Request $request, $body): Request { $headers = $request->getHeaders(); if (is_string($body) && file_exists($body)) { $filename = rawurldecode(basename($body)); // lucky guess - unfortunately it is not clear how to escape header values $headers['Content-Disposition'] = 'attachment; filename="' . $filename . '"'; $mime = @mime_content_type($body); if ($mime) { $headers['Content-Type'] = $mime; } $body = fopen($body, 'rb'); } elseif (is_array($body) && isset($body['contentType']) && isset($body['data']) && isset($body['filename'])) { $headers['Content-Type'] = $body['contentType']; $headers['Content-Disposition'] = 'attachment; filename="' . rawurldecode($body['filename']) . '"'; $body = file_exists($body['data']) ? fopen($body['data'], 'rb') : $body['data']; } elseif (is_string($body) && preg_match('|^[a-z0-9]+://|i', $body)) { $headers['Content-Type'] = 'message/external-body; access-type=URL; URL="' . $body . '"'; $body = null; } return new Request($request->getMethod(), $request->getUri(), $headers, $body); }
php
static public function attachData(Request $request, $body): Request { $headers = $request->getHeaders(); if (is_string($body) && file_exists($body)) { $filename = rawurldecode(basename($body)); // lucky guess - unfortunately it is not clear how to escape header values $headers['Content-Disposition'] = 'attachment; filename="' . $filename . '"'; $mime = @mime_content_type($body); if ($mime) { $headers['Content-Type'] = $mime; } $body = fopen($body, 'rb'); } elseif (is_array($body) && isset($body['contentType']) && isset($body['data']) && isset($body['filename'])) { $headers['Content-Type'] = $body['contentType']; $headers['Content-Disposition'] = 'attachment; filename="' . rawurldecode($body['filename']) . '"'; $body = file_exists($body['data']) ? fopen($body['data'], 'rb') : $body['data']; } elseif (is_string($body) && preg_match('|^[a-z0-9]+://|i', $body)) { $headers['Content-Type'] = 'message/external-body; access-type=URL; URL="' . $body . '"'; $body = null; } return new Request($request->getMethod(), $request->getUri(), $headers, $body); }
[ "static", "public", "function", "attachData", "(", "Request", "$", "request", ",", "$", "body", ")", ":", "Request", "{", "$", "headers", "=", "$", "request", "->", "getHeaders", "(", ")", ";", "if", "(", "is_string", "(", "$", "body", ")", "&&", "file_exists", "(", "$", "body", ")", ")", "{", "$", "filename", "=", "rawurldecode", "(", "basename", "(", "$", "body", ")", ")", ";", "// lucky guess - unfortunately it is not clear how to escape header values", "$", "headers", "[", "'Content-Disposition'", "]", "=", "'attachment; filename=\"'", ".", "$", "filename", ".", "'\"'", ";", "$", "mime", "=", "@", "mime_content_type", "(", "$", "body", ")", ";", "if", "(", "$", "mime", ")", "{", "$", "headers", "[", "'Content-Type'", "]", "=", "$", "mime", ";", "}", "$", "body", "=", "fopen", "(", "$", "body", ",", "'rb'", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "body", ")", "&&", "isset", "(", "$", "body", "[", "'contentType'", "]", ")", "&&", "isset", "(", "$", "body", "[", "'data'", "]", ")", "&&", "isset", "(", "$", "body", "[", "'filename'", "]", ")", ")", "{", "$", "headers", "[", "'Content-Type'", "]", "=", "$", "body", "[", "'contentType'", "]", ";", "$", "headers", "[", "'Content-Disposition'", "]", "=", "'attachment; filename=\"'", ".", "rawurldecode", "(", "$", "body", "[", "'filename'", "]", ")", ".", "'\"'", ";", "$", "body", "=", "file_exists", "(", "$", "body", "[", "'data'", "]", ")", "?", "fopen", "(", "$", "body", "[", "'data'", "]", ",", "'rb'", ")", ":", "$", "body", "[", "'data'", "]", ";", "}", "elseif", "(", "is_string", "(", "$", "body", ")", "&&", "preg_match", "(", "'|^[a-z0-9]+://|i'", ",", "$", "body", ")", ")", "{", "$", "headers", "[", "'Content-Type'", "]", "=", "'message/external-body; access-type=URL; URL=\"'", ".", "$", "body", ".", "'\"'", ";", "$", "body", "=", "null", ";", "}", "return", "new", "Request", "(", "$", "request", "->", "getMethod", "(", ")", ",", "$", "request", "->", "getUri", "(", ")", ",", "$", "headers", ",", "$", "body", ")", ";", "}" ]
Attaches binary content to a given Guzzle HTTP request @param \GuzzleHttp\Psr7\Request $request HTTP request @param $body binary content to be attached It can be a file name, an URL, an array or a normal string. If it is an URL, a "redirecting Fedora resource" will be created. If it is an array, it should contain fields: contentType, filename, data @return \GuzzleHttp\Psr7\Request
[ "Attaches", "binary", "content", "to", "a", "given", "Guzzle", "HTTP", "request" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L88-L108
29,897
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/Fedora.php
Fedora.createResource
public function createResource(Resource $metadata, $data = '', string $path = '', string $method = 'POST'): FedoraResource { if (!in_array($method, array('POST', 'PUT'))) { throw new BadMethodCallException('method must be PUT or POST'); } $baseUrl = $this->txUrl ? $this->txUrl : $this->apiUrl; $path = $path ? $this->sanitizeUri($path) : $baseUrl . $this->defaultCollection; $request = new Request($method, $path); $request = self::attachData($request, $data); try { $resp = $this->sendRequest($request); } catch (ClientException $e) { if (strpos($e->getMessage(), 'tombstone resource') === false) { throw $e; } throw new Deleted(); } $uri = $resp->getHeader('Location')[0]; $res = $this->getResourceByUri($uri); // merge the metadata created by Fedora (and Doorkeeper) upon resource creation // with the ones provided by user $curMetadata = $res->getMetadata()->merge($metadata, array(RC::idProp())); $res->setMetadata($curMetadata); $res->updateMetadata(); return $res; }
php
public function createResource(Resource $metadata, $data = '', string $path = '', string $method = 'POST'): FedoraResource { if (!in_array($method, array('POST', 'PUT'))) { throw new BadMethodCallException('method must be PUT or POST'); } $baseUrl = $this->txUrl ? $this->txUrl : $this->apiUrl; $path = $path ? $this->sanitizeUri($path) : $baseUrl . $this->defaultCollection; $request = new Request($method, $path); $request = self::attachData($request, $data); try { $resp = $this->sendRequest($request); } catch (ClientException $e) { if (strpos($e->getMessage(), 'tombstone resource') === false) { throw $e; } throw new Deleted(); } $uri = $resp->getHeader('Location')[0]; $res = $this->getResourceByUri($uri); // merge the metadata created by Fedora (and Doorkeeper) upon resource creation // with the ones provided by user $curMetadata = $res->getMetadata()->merge($metadata, array(RC::idProp())); $res->setMetadata($curMetadata); $res->updateMetadata(); return $res; }
[ "public", "function", "createResource", "(", "Resource", "$", "metadata", ",", "$", "data", "=", "''", ",", "string", "$", "path", "=", "''", ",", "string", "$", "method", "=", "'POST'", ")", ":", "FedoraResource", "{", "if", "(", "!", "in_array", "(", "$", "method", ",", "array", "(", "'POST'", ",", "'PUT'", ")", ")", ")", "{", "throw", "new", "BadMethodCallException", "(", "'method must be PUT or POST'", ")", ";", "}", "$", "baseUrl", "=", "$", "this", "->", "txUrl", "?", "$", "this", "->", "txUrl", ":", "$", "this", "->", "apiUrl", ";", "$", "path", "=", "$", "path", "?", "$", "this", "->", "sanitizeUri", "(", "$", "path", ")", ":", "$", "baseUrl", ".", "$", "this", "->", "defaultCollection", ";", "$", "request", "=", "new", "Request", "(", "$", "method", ",", "$", "path", ")", ";", "$", "request", "=", "self", "::", "attachData", "(", "$", "request", ",", "$", "data", ")", ";", "try", "{", "$", "resp", "=", "$", "this", "->", "sendRequest", "(", "$", "request", ")", ";", "}", "catch", "(", "ClientException", "$", "e", ")", "{", "if", "(", "strpos", "(", "$", "e", "->", "getMessage", "(", ")", ",", "'tombstone resource'", ")", "===", "false", ")", "{", "throw", "$", "e", ";", "}", "throw", "new", "Deleted", "(", ")", ";", "}", "$", "uri", "=", "$", "resp", "->", "getHeader", "(", "'Location'", ")", "[", "0", "]", ";", "$", "res", "=", "$", "this", "->", "getResourceByUri", "(", "$", "uri", ")", ";", "// merge the metadata created by Fedora (and Doorkeeper) upon resource creation", "// with the ones provided by user", "$", "curMetadata", "=", "$", "res", "->", "getMetadata", "(", ")", "->", "merge", "(", "$", "metadata", ",", "array", "(", "RC", "::", "idProp", "(", ")", ")", ")", ";", "$", "res", "->", "setMetadata", "(", "$", "curMetadata", ")", ";", "$", "res", "->", "updateMetadata", "(", ")", ";", "return", "$", "res", ";", "}" ]
Creates a resource in the Fedora and returns corresponding Resource object @param EasyRdf\Resource $metadata resource metadata @param mixed $data optional resource data as a string, file name or an array: ['content-type' => 'foo', 'data' => 'bar'] @param string $path optional Fedora resource path (see also the `$method` parameter) @param string $method creation method to use - POST or PUT, by default POST @return \acdhOeaw\rms\FedoraResource @throws \BadMethodCallException
[ "Creates", "a", "resource", "in", "the", "Fedora", "and", "returns", "corresponding", "Resource", "object" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L274-L301
29,898
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/Fedora.php
Fedora.sendRequest
public function sendRequest(Request $request): Response { if ($this->txUrl && time() - $this->txTimestamp > $this->txKeepAlive) { $this->prolong(); } try { $response = $this->client->send($request); // Fedora triplestore plugin doesn't index resources which were // deleted and recreated within the same transaction so we need // to remember deleted resources and try to reindex them at the end // of a transaction. if ($request->getMethod() === 'DELETE') { $this->resToReindex[] = preg_replace('|/fcr:[-a-zA-Z0-9]+$|', '', $request->getUri()); } } catch (RequestException $e) { switch ($e->getCode()) { case 410: throw new Deleted(); case 404: throw new NotFound(); default: throw $e; } } return $response; }
php
public function sendRequest(Request $request): Response { if ($this->txUrl && time() - $this->txTimestamp > $this->txKeepAlive) { $this->prolong(); } try { $response = $this->client->send($request); // Fedora triplestore plugin doesn't index resources which were // deleted and recreated within the same transaction so we need // to remember deleted resources and try to reindex them at the end // of a transaction. if ($request->getMethod() === 'DELETE') { $this->resToReindex[] = preg_replace('|/fcr:[-a-zA-Z0-9]+$|', '', $request->getUri()); } } catch (RequestException $e) { switch ($e->getCode()) { case 410: throw new Deleted(); case 404: throw new NotFound(); default: throw $e; } } return $response; }
[ "public", "function", "sendRequest", "(", "Request", "$", "request", ")", ":", "Response", "{", "if", "(", "$", "this", "->", "txUrl", "&&", "time", "(", ")", "-", "$", "this", "->", "txTimestamp", ">", "$", "this", "->", "txKeepAlive", ")", "{", "$", "this", "->", "prolong", "(", ")", ";", "}", "try", "{", "$", "response", "=", "$", "this", "->", "client", "->", "send", "(", "$", "request", ")", ";", "// Fedora triplestore plugin doesn't index resources which were", "// deleted and recreated within the same transaction so we need", "// to remember deleted resources and try to reindex them at the end", "// of a transaction.", "if", "(", "$", "request", "->", "getMethod", "(", ")", "===", "'DELETE'", ")", "{", "$", "this", "->", "resToReindex", "[", "]", "=", "preg_replace", "(", "'|/fcr:[-a-zA-Z0-9]+$|'", ",", "''", ",", "$", "request", "->", "getUri", "(", ")", ")", ";", "}", "}", "catch", "(", "RequestException", "$", "e", ")", "{", "switch", "(", "$", "e", "->", "getCode", "(", ")", ")", "{", "case", "410", ":", "throw", "new", "Deleted", "(", ")", ";", "case", "404", ":", "throw", "new", "NotFound", "(", ")", ";", "default", ":", "throw", "$", "e", ";", "}", "}", "return", "$", "response", ";", "}" ]
Sends a given HTTP request to the Fedora. Switches most important errors into specific error classes. @param Request $request request to be send @return Response @throws Deleted @throws NotFound @throws RequestException
[ "Sends", "a", "given", "HTTP", "request", "to", "the", "Fedora", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L313-L338
29,899
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/Fedora.php
Fedora.getResourceByUri
public function getResourceByUri(string $uri): FedoraResource { $uri = $this->standardizeUri($uri); try { return $this->cache->getByUri($uri); } catch (NotInCache $e) { return new FedoraResource($this, $uri); } }
php
public function getResourceByUri(string $uri): FedoraResource { $uri = $this->standardizeUri($uri); try { return $this->cache->getByUri($uri); } catch (NotInCache $e) { return new FedoraResource($this, $uri); } }
[ "public", "function", "getResourceByUri", "(", "string", "$", "uri", ")", ":", "FedoraResource", "{", "$", "uri", "=", "$", "this", "->", "standardizeUri", "(", "$", "uri", ")", ";", "try", "{", "return", "$", "this", "->", "cache", "->", "getByUri", "(", "$", "uri", ")", ";", "}", "catch", "(", "NotInCache", "$", "e", ")", "{", "return", "new", "FedoraResource", "(", "$", "this", ",", "$", "uri", ")", ";", "}", "}" ]
Returns a FedoraResource based on a given URI. Request URI is imported into the current connection meaning base Fedora API URL will and the current transaction URI (if there is an active transaction) will replace ones in passed URI. It is not checked if a resource with a given URI exists. @param string $uri @return \acdhOeaw\fedora\FedoraResource
[ "Returns", "a", "FedoraResource", "based", "on", "a", "given", "URI", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L352-L359