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
26,500
libgraviton/graviton
src/Graviton/ProxyBundle/Service/TransformationHandler.php
TransformationHandler.transformRequest
public function transformRequest($api, $endpoint, Request $requestIn, Request $requestOut) { $transformations = $this->getRequestTransformations($api, $endpoint); if (!empty($transformations)) { foreach ($transformations as $transformation) { $transformedRequest = $transformation->transformRequest($requestIn, $requestOut); $requestOut = $transformedRequest instanceof Request ? $transformedRequest : $requestOut; } return $requestOut; } // TODO [taafeba2]: add logging return $requestOut; }
php
public function transformRequest($api, $endpoint, Request $requestIn, Request $requestOut) { $transformations = $this->getRequestTransformations($api, $endpoint); if (!empty($transformations)) { foreach ($transformations as $transformation) { $transformedRequest = $transformation->transformRequest($requestIn, $requestOut); $requestOut = $transformedRequest instanceof Request ? $transformedRequest : $requestOut; } return $requestOut; } // TODO [taafeba2]: add logging return $requestOut; }
[ "public", "function", "transformRequest", "(", "$", "api", ",", "$", "endpoint", ",", "Request", "$", "requestIn", ",", "Request", "$", "requestOut", ")", "{", "$", "transformations", "=", "$", "this", "->", "getRequestTransformations", "(", "$", "api", ",", "$", "endpoint", ")", ";", "if", "(", "!", "empty", "(", "$", "transformations", ")", ")", "{", "foreach", "(", "$", "transformations", "as", "$", "transformation", ")", "{", "$", "transformedRequest", "=", "$", "transformation", "->", "transformRequest", "(", "$", "requestIn", ",", "$", "requestOut", ")", ";", "$", "requestOut", "=", "$", "transformedRequest", "instanceof", "Request", "?", "$", "transformedRequest", ":", "$", "requestOut", ";", "}", "return", "$", "requestOut", ";", "}", "// TODO [taafeba2]: add logging", "return", "$", "requestOut", ";", "}" ]
Applies all transformations defined for the given API and endpoint on a request. @param string $api The API name @param string $endpoint The endpoint @param Request $requestIn The original request object. @param Request $requestOut The request object to use for transformations @return Request The transformed request @throws TransformationException
[ "Applies", "all", "transformations", "defined", "for", "the", "given", "API", "and", "endpoint", "on", "a", "request", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Service/TransformationHandler.php#L48-L63
26,501
libgraviton/graviton
src/Graviton/ProxyBundle/Service/TransformationHandler.php
TransformationHandler.transformResponse
public function transformResponse($api, $endpoint, Response $responseIn, Response $responseOut) { $transformations = $this->getResponseTransformations($api, $endpoint); foreach ($transformations as $transformation) { $transformedRequest = $transformation->transformResponse($responseIn, $responseOut); $responseOut = $transformedRequest instanceof Response ? $transformedRequest : $responseOut; } return $responseOut; }
php
public function transformResponse($api, $endpoint, Response $responseIn, Response $responseOut) { $transformations = $this->getResponseTransformations($api, $endpoint); foreach ($transformations as $transformation) { $transformedRequest = $transformation->transformResponse($responseIn, $responseOut); $responseOut = $transformedRequest instanceof Response ? $transformedRequest : $responseOut; } return $responseOut; }
[ "public", "function", "transformResponse", "(", "$", "api", ",", "$", "endpoint", ",", "Response", "$", "responseIn", ",", "Response", "$", "responseOut", ")", "{", "$", "transformations", "=", "$", "this", "->", "getResponseTransformations", "(", "$", "api", ",", "$", "endpoint", ")", ";", "foreach", "(", "$", "transformations", "as", "$", "transformation", ")", "{", "$", "transformedRequest", "=", "$", "transformation", "->", "transformResponse", "(", "$", "responseIn", ",", "$", "responseOut", ")", ";", "$", "responseOut", "=", "$", "transformedRequest", "instanceof", "Response", "?", "$", "transformedRequest", ":", "$", "responseOut", ";", "}", "return", "$", "responseOut", ";", "}" ]
Applies all transformations defined for the given API and endpoint on a response. @param string $api The API name @param string $endpoint The endpoint @param Response $responseIn The original response object @param Response $responseOut The response object to use for transformations @return Response The transformed response
[ "Applies", "all", "transformations", "defined", "for", "the", "given", "API", "and", "endpoint", "on", "a", "response", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Service/TransformationHandler.php#L74-L82
26,502
libgraviton/graviton
src/Graviton/ProxyBundle/Service/TransformationHandler.php
TransformationHandler.transformSchema
public function transformSchema($api, $endpoint, \stdClass $schemaIn, \stdClass $schemaOut) { $transformations = $this->getSchemaTransformations($api, $endpoint); foreach ($transformations as $transformation) { $transformedSchema = $transformation->transformSchema($schemaIn, $schemaOut); $schemaOut = $transformedSchema instanceof \stdClass ? $transformedSchema : $schemaOut; } return $schemaOut; }
php
public function transformSchema($api, $endpoint, \stdClass $schemaIn, \stdClass $schemaOut) { $transformations = $this->getSchemaTransformations($api, $endpoint); foreach ($transformations as $transformation) { $transformedSchema = $transformation->transformSchema($schemaIn, $schemaOut); $schemaOut = $transformedSchema instanceof \stdClass ? $transformedSchema : $schemaOut; } return $schemaOut; }
[ "public", "function", "transformSchema", "(", "$", "api", ",", "$", "endpoint", ",", "\\", "stdClass", "$", "schemaIn", ",", "\\", "stdClass", "$", "schemaOut", ")", "{", "$", "transformations", "=", "$", "this", "->", "getSchemaTransformations", "(", "$", "api", ",", "$", "endpoint", ")", ";", "foreach", "(", "$", "transformations", "as", "$", "transformation", ")", "{", "$", "transformedSchema", "=", "$", "transformation", "->", "transformSchema", "(", "$", "schemaIn", ",", "$", "schemaOut", ")", ";", "$", "schemaOut", "=", "$", "transformedSchema", "instanceof", "\\", "stdClass", "?", "$", "transformedSchema", ":", "$", "schemaOut", ";", "}", "return", "$", "schemaOut", ";", "}" ]
Applies all transformations defined for the given API and endpoint on a schema. @param string $api The API name @param string $endpoint The endpoint @param \stdClass $schemaIn The original schema object @param \stdClass $schemaOut The schema object to use for transformations @return \stdClass The transformed schema
[ "Applies", "all", "transformations", "defined", "for", "the", "given", "API", "and", "endpoint", "on", "a", "schema", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Service/TransformationHandler.php#L93-L101
26,503
libgraviton/graviton
src/Graviton/ProxyBundle/Service/TransformationHandler.php
TransformationHandler.getRequestTransformations
public function getRequestTransformations($api, $endpoint) { if (isset($this->requestTransformations[$api])) { $patterns = array_keys($this->requestTransformations[$api]); foreach ($patterns as $pattern) { preg_match($pattern, $endpoint, $matches); if (!empty($matches[1])) { return $this->requestTransformations[$api][$pattern]; } } } return []; }
php
public function getRequestTransformations($api, $endpoint) { if (isset($this->requestTransformations[$api])) { $patterns = array_keys($this->requestTransformations[$api]); foreach ($patterns as $pattern) { preg_match($pattern, $endpoint, $matches); if (!empty($matches[1])) { return $this->requestTransformations[$api][$pattern]; } } } return []; }
[ "public", "function", "getRequestTransformations", "(", "$", "api", ",", "$", "endpoint", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "requestTransformations", "[", "$", "api", "]", ")", ")", "{", "$", "patterns", "=", "array_keys", "(", "$", "this", "->", "requestTransformations", "[", "$", "api", "]", ")", ";", "foreach", "(", "$", "patterns", "as", "$", "pattern", ")", "{", "preg_match", "(", "$", "pattern", ",", "$", "endpoint", ",", "$", "matches", ")", ";", "if", "(", "!", "empty", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "return", "$", "this", "->", "requestTransformations", "[", "$", "api", "]", "[", "$", "pattern", "]", ";", "}", "}", "}", "return", "[", "]", ";", "}" ]
Returns the request transformations registered for a given API and endpoint. @param string $api The API name @param string $endpoint The endpoint @return array The transformations
[ "Returns", "the", "request", "transformations", "registered", "for", "a", "given", "API", "and", "endpoint", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Service/TransformationHandler.php#L110-L125
26,504
libgraviton/graviton
src/Graviton/ProxyBundle/Service/TransformationHandler.php
TransformationHandler.addRequestTransformation
public function addRequestTransformation($api, $endpoint, RequestTransformationInterface $transformation) { $this->requestTransformations[$api][$endpoint][] = $transformation; return count($this->requestTransformations[$api][$endpoint]) - 1; }
php
public function addRequestTransformation($api, $endpoint, RequestTransformationInterface $transformation) { $this->requestTransformations[$api][$endpoint][] = $transformation; return count($this->requestTransformations[$api][$endpoint]) - 1; }
[ "public", "function", "addRequestTransformation", "(", "$", "api", ",", "$", "endpoint", ",", "RequestTransformationInterface", "$", "transformation", ")", "{", "$", "this", "->", "requestTransformations", "[", "$", "api", "]", "[", "$", "endpoint", "]", "[", "]", "=", "$", "transformation", ";", "return", "count", "(", "$", "this", "->", "requestTransformations", "[", "$", "api", "]", "[", "$", "endpoint", "]", ")", "-", "1", ";", "}" ]
Adds a transformation to a given API and endpoint. @param string $api The API name @param string $endpoint The API endpoint @param RequestTransformationInterface $transformation The transformation @return int The position of the added transformation within the transformation array.
[ "Adds", "a", "transformation", "to", "a", "given", "API", "and", "endpoint", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Service/TransformationHandler.php#L161-L165
26,505
libgraviton/graviton
src/Graviton/ProxyBundle/Service/TransformationHandler.php
TransformationHandler.addResponseTransformation
public function addResponseTransformation($api, $endpoint, ResponseTransformationInterface $transformation) { $this->responseTransformations[$api][$endpoint][] = $transformation; return count($this->responseTransformations[$api][$endpoint]) - 1; }
php
public function addResponseTransformation($api, $endpoint, ResponseTransformationInterface $transformation) { $this->responseTransformations[$api][$endpoint][] = $transformation; return count($this->responseTransformations[$api][$endpoint]) - 1; }
[ "public", "function", "addResponseTransformation", "(", "$", "api", ",", "$", "endpoint", ",", "ResponseTransformationInterface", "$", "transformation", ")", "{", "$", "this", "->", "responseTransformations", "[", "$", "api", "]", "[", "$", "endpoint", "]", "[", "]", "=", "$", "transformation", ";", "return", "count", "(", "$", "this", "->", "responseTransformations", "[", "$", "api", "]", "[", "$", "endpoint", "]", ")", "-", "1", ";", "}" ]
Adds a response transformation to a given API and endpoint. @param string $api The API name @param string $endpoint The API endpoint @param ResponseTransformationInterface $transformation The transformation @return int The position of the added transformation within the transformation array.
[ "Adds", "a", "response", "transformation", "to", "a", "given", "API", "and", "endpoint", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Service/TransformationHandler.php#L175-L179
26,506
libgraviton/graviton
src/Graviton/ProxyBundle/Service/TransformationHandler.php
TransformationHandler.addSchemaTransformation
public function addSchemaTransformation($api, $endpoint, SchemaTransformationInterface $transformation) { $this->schemaTransformations[$api][$endpoint][] = $transformation; return count($this->schemaTransformations[$api][$endpoint]) - 1; }
php
public function addSchemaTransformation($api, $endpoint, SchemaTransformationInterface $transformation) { $this->schemaTransformations[$api][$endpoint][] = $transformation; return count($this->schemaTransformations[$api][$endpoint]) - 1; }
[ "public", "function", "addSchemaTransformation", "(", "$", "api", ",", "$", "endpoint", ",", "SchemaTransformationInterface", "$", "transformation", ")", "{", "$", "this", "->", "schemaTransformations", "[", "$", "api", "]", "[", "$", "endpoint", "]", "[", "]", "=", "$", "transformation", ";", "return", "count", "(", "$", "this", "->", "schemaTransformations", "[", "$", "api", "]", "[", "$", "endpoint", "]", ")", "-", "1", ";", "}" ]
Adds a schema transformation to a given API and endpoint. @param string $api The API name @param string $endpoint The API endpoint @param SchemaTransformationInterface $transformation The transformation @return int The position of the added transformation within the transformation array.
[ "Adds", "a", "schema", "transformation", "to", "a", "given", "API", "and", "endpoint", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Service/TransformationHandler.php#L189-L193
26,507
libgraviton/graviton
src/Graviton/AnalyticsBundle/Helper/JsonMapper.php
JsonMapper.map
public function map($json, $object) { foreach ($json as $key => $jvalue) { $key = $this->getSafeName($key); $setter = 'set' . $this->getCamelCaseName($key); if (method_exists($object, $setter)) { $object->{$setter}($jvalue); } } return $object; }
php
public function map($json, $object) { foreach ($json as $key => $jvalue) { $key = $this->getSafeName($key); $setter = 'set' . $this->getCamelCaseName($key); if (method_exists($object, $setter)) { $object->{$setter}($jvalue); } } return $object; }
[ "public", "function", "map", "(", "$", "json", ",", "$", "object", ")", "{", "foreach", "(", "$", "json", "as", "$", "key", "=>", "$", "jvalue", ")", "{", "$", "key", "=", "$", "this", "->", "getSafeName", "(", "$", "key", ")", ";", "$", "setter", "=", "'set'", ".", "$", "this", "->", "getCamelCaseName", "(", "$", "key", ")", ";", "if", "(", "method_exists", "(", "$", "object", ",", "$", "setter", ")", ")", "{", "$", "object", "->", "{", "$", "setter", "}", "(", "$", "jvalue", ")", ";", "}", "}", "return", "$", "object", ";", "}" ]
Maps data into object class @param object $json to be casted @param object $object Class to receive data @throws InvalidArgumentException @return object
[ "Maps", "data", "into", "object", "class" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/AnalyticsBundle/Helper/JsonMapper.php#L26-L38
26,508
libgraviton/graviton
src/Graviton/SchemaBundle/Model/SchemaModel.php
SchemaModel.manyPropertyModelForTarget
public function manyPropertyModelForTarget($mapping) { // @todo refactor to get rid of container dependency (maybe remove from here) list($app, $bundle, , $document) = explode('\\', $mapping); $app = strtolower($app); $bundle = strtolower(substr($bundle, 0, -6)); $document = strtolower($document); $propertyService = implode('.', array($app, $bundle, 'model', $document)); $propertyModel = $this->container->get($propertyService); return $propertyModel; }
php
public function manyPropertyModelForTarget($mapping) { // @todo refactor to get rid of container dependency (maybe remove from here) list($app, $bundle, , $document) = explode('\\', $mapping); $app = strtolower($app); $bundle = strtolower(substr($bundle, 0, -6)); $document = strtolower($document); $propertyService = implode('.', array($app, $bundle, 'model', $document)); $propertyModel = $this->container->get($propertyService); return $propertyModel; }
[ "public", "function", "manyPropertyModelForTarget", "(", "$", "mapping", ")", "{", "// @todo refactor to get rid of container dependency (maybe remove from here)", "list", "(", "$", "app", ",", "$", "bundle", ",", ",", "$", "document", ")", "=", "explode", "(", "'\\\\'", ",", "$", "mapping", ")", ";", "$", "app", "=", "strtolower", "(", "$", "app", ")", ";", "$", "bundle", "=", "strtolower", "(", "substr", "(", "$", "bundle", ",", "0", ",", "-", "6", ")", ")", ";", "$", "document", "=", "strtolower", "(", "$", "document", ")", ";", "$", "propertyService", "=", "implode", "(", "'.'", ",", "array", "(", "$", "app", ",", "$", "bundle", ",", "'model'", ",", "$", "document", ")", ")", ";", "$", "propertyModel", "=", "$", "this", "->", "container", "->", "get", "(", "$", "propertyService", ")", ";", "return", "$", "propertyModel", ";", "}" ]
get property model for embedded field @param string $mapping name of mapping class @return $this
[ "get", "property", "model", "for", "embedded", "field" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/Model/SchemaModel.php#L176-L187
26,509
libgraviton/graviton
src/Graviton/SchemaBundle/Model/SchemaModel.php
SchemaModel.getRequiredFields
public function getRequiredFields($variationName = null) { if (is_null($variationName)) { return $this->schema->required; } /* compose required fields based on variation */ $requiredFields = $this->getRequiredFields(); foreach ($this->schema->properties as $fieldName => $fieldAttributes) { $onVariation = $this->getOnVariaton($fieldName); if (is_object($onVariation) && isset($onVariation->{$variationName}->required)) { $thisRequired = $onVariation->{$variationName}->required; if ($thisRequired === true) { $requiredFields[] = $fieldName; } if ($thisRequired === false) { // see if its set $fieldIndex = array_search($fieldName, $requiredFields); if ($fieldName !== false) { unset($requiredFields[$fieldIndex]); } } } } return array_values( array_unique( $requiredFields ) ); }
php
public function getRequiredFields($variationName = null) { if (is_null($variationName)) { return $this->schema->required; } /* compose required fields based on variation */ $requiredFields = $this->getRequiredFields(); foreach ($this->schema->properties as $fieldName => $fieldAttributes) { $onVariation = $this->getOnVariaton($fieldName); if (is_object($onVariation) && isset($onVariation->{$variationName}->required)) { $thisRequired = $onVariation->{$variationName}->required; if ($thisRequired === true) { $requiredFields[] = $fieldName; } if ($thisRequired === false) { // see if its set $fieldIndex = array_search($fieldName, $requiredFields); if ($fieldName !== false) { unset($requiredFields[$fieldIndex]); } } } } return array_values( array_unique( $requiredFields ) ); }
[ "public", "function", "getRequiredFields", "(", "$", "variationName", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "variationName", ")", ")", "{", "return", "$", "this", "->", "schema", "->", "required", ";", "}", "/* compose required fields based on variation */", "$", "requiredFields", "=", "$", "this", "->", "getRequiredFields", "(", ")", ";", "foreach", "(", "$", "this", "->", "schema", "->", "properties", "as", "$", "fieldName", "=>", "$", "fieldAttributes", ")", "{", "$", "onVariation", "=", "$", "this", "->", "getOnVariaton", "(", "$", "fieldName", ")", ";", "if", "(", "is_object", "(", "$", "onVariation", ")", "&&", "isset", "(", "$", "onVariation", "->", "{", "$", "variationName", "}", "->", "required", ")", ")", "{", "$", "thisRequired", "=", "$", "onVariation", "->", "{", "$", "variationName", "}", "->", "required", ";", "if", "(", "$", "thisRequired", "===", "true", ")", "{", "$", "requiredFields", "[", "]", "=", "$", "fieldName", ";", "}", "if", "(", "$", "thisRequired", "===", "false", ")", "{", "// see if its set", "$", "fieldIndex", "=", "array_search", "(", "$", "fieldName", ",", "$", "requiredFields", ")", ";", "if", "(", "$", "fieldName", "!==", "false", ")", "{", "unset", "(", "$", "requiredFields", "[", "$", "fieldIndex", "]", ")", ";", "}", "}", "}", "}", "return", "array_values", "(", "array_unique", "(", "$", "requiredFields", ")", ")", ";", "}" ]
get required fields for this object @param string $variationName a variation that can alter which fields are required @return string[]
[ "get", "required", "fields", "for", "this", "object" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/Model/SchemaModel.php#L196-L229
26,510
libgraviton/graviton
src/Graviton/SchemaBundle/Model/SchemaModel.php
SchemaModel.getDocumentClass
public function getDocumentClass() { $documentClass = false; if (isset($this->schema->{'x-documentClass'})) { $documentClass = $this->schema->{'x-documentClass'}; } return $documentClass; }
php
public function getDocumentClass() { $documentClass = false; if (isset($this->schema->{'x-documentClass'})) { $documentClass = $this->schema->{'x-documentClass'}; } return $documentClass; }
[ "public", "function", "getDocumentClass", "(", ")", "{", "$", "documentClass", "=", "false", ";", "if", "(", "isset", "(", "$", "this", "->", "schema", "->", "{", "'x-documentClass'", "}", ")", ")", "{", "$", "documentClass", "=", "$", "this", "->", "schema", "->", "{", "'x-documentClass'", "}", ";", "}", "return", "$", "documentClass", ";", "}" ]
Gets the defined document class in shortform from schema @return string|false either the document class or false it not given
[ "Gets", "the", "defined", "document", "class", "in", "shortform", "from", "schema" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/Model/SchemaModel.php#L308-L315
26,511
libgraviton/graviton
src/Graviton/SchemaBundle/Model/SchemaModel.php
SchemaModel.getSchemaField
private function getSchemaField($field, $property, $fallbackValue = '') { if (isset($this->schema->properties->$field->$property)) { $fallbackValue = $this->schema->properties->$field->$property; } return $fallbackValue; }
php
private function getSchemaField($field, $property, $fallbackValue = '') { if (isset($this->schema->properties->$field->$property)) { $fallbackValue = $this->schema->properties->$field->$property; } return $fallbackValue; }
[ "private", "function", "getSchemaField", "(", "$", "field", ",", "$", "property", ",", "$", "fallbackValue", "=", "''", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "schema", "->", "properties", "->", "$", "field", "->", "$", "property", ")", ")", "{", "$", "fallbackValue", "=", "$", "this", "->", "schema", "->", "properties", "->", "$", "field", "->", "$", "property", ";", "}", "return", "$", "fallbackValue", ";", "}" ]
get schema field value @param string $field field name @param string $property property name @param mixed $fallbackValue fallback value if property isn't set @return mixed
[ "get", "schema", "field", "value" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/Model/SchemaModel.php#L378-L385
26,512
duncan3dc/domparser
src/ParserTrait.php
ParserTrait.getData
protected function getData($data) { $method = "load" . strtoupper($this->mode); libxml_use_internal_errors(true); $this->dom->$method($data); $this->errors = libxml_get_errors(); libxml_clear_errors(); return $data; }
php
protected function getData($data) { $method = "load" . strtoupper($this->mode); libxml_use_internal_errors(true); $this->dom->$method($data); $this->errors = libxml_get_errors(); libxml_clear_errors(); return $data; }
[ "protected", "function", "getData", "(", "$", "data", ")", "{", "$", "method", "=", "\"load\"", ".", "strtoupper", "(", "$", "this", "->", "mode", ")", ";", "libxml_use_internal_errors", "(", "true", ")", ";", "$", "this", "->", "dom", "->", "$", "method", "(", "$", "data", ")", ";", "$", "this", "->", "errors", "=", "libxml_get_errors", "(", ")", ";", "libxml_clear_errors", "(", ")", ";", "return", "$", "data", ";", "}" ]
Get the content for parsing. Creates an internal dom instance. @param string $data The xml/html @return string The xml/html
[ "Get", "the", "content", "for", "parsing", "." ]
d5523b58337cab3b9ad90e8d135f87793795f93f
https://github.com/duncan3dc/domparser/blob/d5523b58337cab3b9ad90e8d135f87793795f93f/src/ParserTrait.php#L24-L34
26,513
duncan3dc/domparser
src/ParserTrait.php
ParserTrait.xpath
public function xpath($path) { $xpath = new \DOMXPath($this->dom); $list = $xpath->query($path); $return = []; foreach ($list as $node) { $return[] = $this->newElement($node); } return $return; }
php
public function xpath($path) { $xpath = new \DOMXPath($this->dom); $list = $xpath->query($path); $return = []; foreach ($list as $node) { $return[] = $this->newElement($node); } return $return; }
[ "public", "function", "xpath", "(", "$", "path", ")", "{", "$", "xpath", "=", "new", "\\", "DOMXPath", "(", "$", "this", "->", "dom", ")", ";", "$", "list", "=", "$", "xpath", "->", "query", "(", "$", "path", ")", ";", "$", "return", "=", "[", "]", ";", "foreach", "(", "$", "list", "as", "$", "node", ")", "{", "$", "return", "[", "]", "=", "$", "this", "->", "newElement", "(", "$", "node", ")", ";", "}", "return", "$", "return", ";", "}" ]
Get elements using an xpath selector. @param string $path The xpath selector @return Element[]
[ "Get", "elements", "using", "an", "xpath", "selector", "." ]
d5523b58337cab3b9ad90e8d135f87793795f93f
https://github.com/duncan3dc/domparser/blob/d5523b58337cab3b9ad90e8d135f87793795f93f/src/ParserTrait.php#L44-L56
26,514
libgraviton/graviton
src/Graviton/MigrationBundle/Command/MongodbMigrateCommand.php
MongodbMigrateCommand.execute
public function execute(InputInterface $input, OutputInterface $output) { // graviton root $baseDir = __DIR__.'/../../../'; // vendorized? - go back some more.. if (strpos($baseDir, '/vendor/') !== false) { $baseDir .= '../../../'; } $this->finder ->in($baseDir) ->path('Resources/config') ->name('/migrations.(xml|yml)/') ->files(); foreach ($this->finder as $file) { if (!$file->isFile()) { continue; } $output->writeln('Found '.$file->getRelativePathname()); $command = $this->getApplication()->find('mongodb:migrations:migrate'); $helperSet = $command->getHelperSet(); $helperSet->set($this->documentManager, 'dm'); $command->setHelperSet($helperSet); $configuration = $this->getConfiguration($file->getPathname(), $output); self::injectContainerToMigrations($this->container, $configuration->getMigrations()); $command->setMigrationConfiguration($configuration); $arguments = $input->getArguments(); $arguments['command'] = 'mongodb:migrations:migrate'; $arguments['--configuration'] = $file->getPathname(); $migrateInput = new ArrayInput($arguments); $migrateInput->setInteractive($input->isInteractive()); $returnCode = $command->run($migrateInput, $output); if ($returnCode !== 0) { $this->errors[] = sprintf( 'Calling mongodb:migrations:migrate failed for %s', $file->getRelativePathname() ); } } if (!empty($this->errors)) { $output->writeln( sprintf('<error>%s</error>', implode(PHP_EOL, $this->errors)) ); return -1; } return 0; }
php
public function execute(InputInterface $input, OutputInterface $output) { // graviton root $baseDir = __DIR__.'/../../../'; // vendorized? - go back some more.. if (strpos($baseDir, '/vendor/') !== false) { $baseDir .= '../../../'; } $this->finder ->in($baseDir) ->path('Resources/config') ->name('/migrations.(xml|yml)/') ->files(); foreach ($this->finder as $file) { if (!$file->isFile()) { continue; } $output->writeln('Found '.$file->getRelativePathname()); $command = $this->getApplication()->find('mongodb:migrations:migrate'); $helperSet = $command->getHelperSet(); $helperSet->set($this->documentManager, 'dm'); $command->setHelperSet($helperSet); $configuration = $this->getConfiguration($file->getPathname(), $output); self::injectContainerToMigrations($this->container, $configuration->getMigrations()); $command->setMigrationConfiguration($configuration); $arguments = $input->getArguments(); $arguments['command'] = 'mongodb:migrations:migrate'; $arguments['--configuration'] = $file->getPathname(); $migrateInput = new ArrayInput($arguments); $migrateInput->setInteractive($input->isInteractive()); $returnCode = $command->run($migrateInput, $output); if ($returnCode !== 0) { $this->errors[] = sprintf( 'Calling mongodb:migrations:migrate failed for %s', $file->getRelativePathname() ); } } if (!empty($this->errors)) { $output->writeln( sprintf('<error>%s</error>', implode(PHP_EOL, $this->errors)) ); return -1; } return 0; }
[ "public", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "// graviton root", "$", "baseDir", "=", "__DIR__", ".", "'/../../../'", ";", "// vendorized? - go back some more..", "if", "(", "strpos", "(", "$", "baseDir", ",", "'/vendor/'", ")", "!==", "false", ")", "{", "$", "baseDir", ".=", "'../../../'", ";", "}", "$", "this", "->", "finder", "->", "in", "(", "$", "baseDir", ")", "->", "path", "(", "'Resources/config'", ")", "->", "name", "(", "'/migrations.(xml|yml)/'", ")", "->", "files", "(", ")", ";", "foreach", "(", "$", "this", "->", "finder", "as", "$", "file", ")", "{", "if", "(", "!", "$", "file", "->", "isFile", "(", ")", ")", "{", "continue", ";", "}", "$", "output", "->", "writeln", "(", "'Found '", ".", "$", "file", "->", "getRelativePathname", "(", ")", ")", ";", "$", "command", "=", "$", "this", "->", "getApplication", "(", ")", "->", "find", "(", "'mongodb:migrations:migrate'", ")", ";", "$", "helperSet", "=", "$", "command", "->", "getHelperSet", "(", ")", ";", "$", "helperSet", "->", "set", "(", "$", "this", "->", "documentManager", ",", "'dm'", ")", ";", "$", "command", "->", "setHelperSet", "(", "$", "helperSet", ")", ";", "$", "configuration", "=", "$", "this", "->", "getConfiguration", "(", "$", "file", "->", "getPathname", "(", ")", ",", "$", "output", ")", ";", "self", "::", "injectContainerToMigrations", "(", "$", "this", "->", "container", ",", "$", "configuration", "->", "getMigrations", "(", ")", ")", ";", "$", "command", "->", "setMigrationConfiguration", "(", "$", "configuration", ")", ";", "$", "arguments", "=", "$", "input", "->", "getArguments", "(", ")", ";", "$", "arguments", "[", "'command'", "]", "=", "'mongodb:migrations:migrate'", ";", "$", "arguments", "[", "'--configuration'", "]", "=", "$", "file", "->", "getPathname", "(", ")", ";", "$", "migrateInput", "=", "new", "ArrayInput", "(", "$", "arguments", ")", ";", "$", "migrateInput", "->", "setInteractive", "(", "$", "input", "->", "isInteractive", "(", ")", ")", ";", "$", "returnCode", "=", "$", "command", "->", "run", "(", "$", "migrateInput", ",", "$", "output", ")", ";", "if", "(", "$", "returnCode", "!==", "0", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "sprintf", "(", "'Calling mongodb:migrations:migrate failed for %s'", ",", "$", "file", "->", "getRelativePathname", "(", ")", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "errors", ")", ")", "{", "$", "output", "->", "writeln", "(", "sprintf", "(", "'<error>%s</error>'", ",", "implode", "(", "PHP_EOL", ",", "$", "this", "->", "errors", ")", ")", ")", ";", "return", "-", "1", ";", "}", "return", "0", ";", "}" ]
call execute on found commands @param InputInterface $input user input @param OutputInterface $output command output @return void
[ "call", "execute", "on", "found", "commands" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/MigrationBundle/Command/MongodbMigrateCommand.php#L90-L147
26,515
libgraviton/graviton
src/Graviton/MigrationBundle/Command/MongodbMigrateCommand.php
MongodbMigrateCommand.getConfiguration
private function getConfiguration($filepath, $output) { $outputWriter = new OutputWriter( function ($message) use ($output) { return $output->writeln($message); } ); $info = pathinfo($filepath); $namespace = 'AntiMattr\MongoDB\Migrations\Configuration'; $class = $info['extension'] === 'xml' ? 'XmlConfiguration' : 'YamlConfiguration'; $class = sprintf('%s\%s', $namespace, $class); $configuration = new $class($this->documentManager->getDocumentManager()->getConnection(), $outputWriter); // register databsae name before loading to ensure that loading does not fail $configuration->setMigrationsDatabaseName($this->databaseName); // load additional config from migrations.(yml|xml) $configuration->load($filepath); return $configuration; }
php
private function getConfiguration($filepath, $output) { $outputWriter = new OutputWriter( function ($message) use ($output) { return $output->writeln($message); } ); $info = pathinfo($filepath); $namespace = 'AntiMattr\MongoDB\Migrations\Configuration'; $class = $info['extension'] === 'xml' ? 'XmlConfiguration' : 'YamlConfiguration'; $class = sprintf('%s\%s', $namespace, $class); $configuration = new $class($this->documentManager->getDocumentManager()->getConnection(), $outputWriter); // register databsae name before loading to ensure that loading does not fail $configuration->setMigrationsDatabaseName($this->databaseName); // load additional config from migrations.(yml|xml) $configuration->load($filepath); return $configuration; }
[ "private", "function", "getConfiguration", "(", "$", "filepath", ",", "$", "output", ")", "{", "$", "outputWriter", "=", "new", "OutputWriter", "(", "function", "(", "$", "message", ")", "use", "(", "$", "output", ")", "{", "return", "$", "output", "->", "writeln", "(", "$", "message", ")", ";", "}", ")", ";", "$", "info", "=", "pathinfo", "(", "$", "filepath", ")", ";", "$", "namespace", "=", "'AntiMattr\\MongoDB\\Migrations\\Configuration'", ";", "$", "class", "=", "$", "info", "[", "'extension'", "]", "===", "'xml'", "?", "'XmlConfiguration'", ":", "'YamlConfiguration'", ";", "$", "class", "=", "sprintf", "(", "'%s\\%s'", ",", "$", "namespace", ",", "$", "class", ")", ";", "$", "configuration", "=", "new", "$", "class", "(", "$", "this", "->", "documentManager", "->", "getDocumentManager", "(", ")", "->", "getConnection", "(", ")", ",", "$", "outputWriter", ")", ";", "// register databsae name before loading to ensure that loading does not fail", "$", "configuration", "->", "setMigrationsDatabaseName", "(", "$", "this", "->", "databaseName", ")", ";", "// load additional config from migrations.(yml|xml)", "$", "configuration", "->", "load", "(", "$", "filepath", ")", ";", "return", "$", "configuration", ";", "}" ]
get configration object for migration script This is based on antromattr/mongodb-migartion code but extends it so we can inject non local stuff centrally. @param string $filepath path to configuration file @param Output $output ouput interface need by config parser to do stuff @return AntiMattr\MongoDB\Migrations\Configuration\Configuration
[ "get", "configration", "object", "for", "migration", "script" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/MigrationBundle/Command/MongodbMigrateCommand.php#L160-L181
26,516
libgraviton/graviton
src/Graviton/FileBundle/Manager/RequestManager.php
RequestManager.updateFileRequest
public function updateFileRequest(Request $request) { $original = $this->requestStack->getMasterRequest(); $input = $original ? $original->getContent() : false; if (!$input) { return $request; } $part = new Part((string) $request); if ($part->isMultiPart()) { // do we have metadata? for a multipart form $metadata = $part->getPartsByName('metadata'); if (is_array($metadata) && !empty($metadata)) { $request->request->set('metadata', $metadata[0]->getBody()); } // the file itself $upload = $part->getPartsByName('upload'); if (is_array($upload) && !empty($upload)) { $uploadPart = $upload[0]; $file = $this->extractFileFromString( $uploadPart->getBody(), $uploadPart->getFileName() ); $request->files->add([$file]); } } elseif ((strpos($request->headers->get('Content-Type'), 'application/json') !== false) && $json = json_decode($part->getBody(), true) ) { // Type json and can be parsed $request->request->set('metadata', json_encode($json)); } else { // Anything else should be saved as file $file = $this->extractFileFromString($part->getBody()); if ($file) { $request->files->add([$file]); } } return $request; }
php
public function updateFileRequest(Request $request) { $original = $this->requestStack->getMasterRequest(); $input = $original ? $original->getContent() : false; if (!$input) { return $request; } $part = new Part((string) $request); if ($part->isMultiPart()) { // do we have metadata? for a multipart form $metadata = $part->getPartsByName('metadata'); if (is_array($metadata) && !empty($metadata)) { $request->request->set('metadata', $metadata[0]->getBody()); } // the file itself $upload = $part->getPartsByName('upload'); if (is_array($upload) && !empty($upload)) { $uploadPart = $upload[0]; $file = $this->extractFileFromString( $uploadPart->getBody(), $uploadPart->getFileName() ); $request->files->add([$file]); } } elseif ((strpos($request->headers->get('Content-Type'), 'application/json') !== false) && $json = json_decode($part->getBody(), true) ) { // Type json and can be parsed $request->request->set('metadata', json_encode($json)); } else { // Anything else should be saved as file $file = $this->extractFileFromString($part->getBody()); if ($file) { $request->files->add([$file]); } } return $request; }
[ "public", "function", "updateFileRequest", "(", "Request", "$", "request", ")", "{", "$", "original", "=", "$", "this", "->", "requestStack", "->", "getMasterRequest", "(", ")", ";", "$", "input", "=", "$", "original", "?", "$", "original", "->", "getContent", "(", ")", ":", "false", ";", "if", "(", "!", "$", "input", ")", "{", "return", "$", "request", ";", "}", "$", "part", "=", "new", "Part", "(", "(", "string", ")", "$", "request", ")", ";", "if", "(", "$", "part", "->", "isMultiPart", "(", ")", ")", "{", "// do we have metadata? for a multipart form", "$", "metadata", "=", "$", "part", "->", "getPartsByName", "(", "'metadata'", ")", ";", "if", "(", "is_array", "(", "$", "metadata", ")", "&&", "!", "empty", "(", "$", "metadata", ")", ")", "{", "$", "request", "->", "request", "->", "set", "(", "'metadata'", ",", "$", "metadata", "[", "0", "]", "->", "getBody", "(", ")", ")", ";", "}", "// the file itself", "$", "upload", "=", "$", "part", "->", "getPartsByName", "(", "'upload'", ")", ";", "if", "(", "is_array", "(", "$", "upload", ")", "&&", "!", "empty", "(", "$", "upload", ")", ")", "{", "$", "uploadPart", "=", "$", "upload", "[", "0", "]", ";", "$", "file", "=", "$", "this", "->", "extractFileFromString", "(", "$", "uploadPart", "->", "getBody", "(", ")", ",", "$", "uploadPart", "->", "getFileName", "(", ")", ")", ";", "$", "request", "->", "files", "->", "add", "(", "[", "$", "file", "]", ")", ";", "}", "}", "elseif", "(", "(", "strpos", "(", "$", "request", "->", "headers", "->", "get", "(", "'Content-Type'", ")", ",", "'application/json'", ")", "!==", "false", ")", "&&", "$", "json", "=", "json_decode", "(", "$", "part", "->", "getBody", "(", ")", ",", "true", ")", ")", "{", "// Type json and can be parsed", "$", "request", "->", "request", "->", "set", "(", "'metadata'", ",", "json_encode", "(", "$", "json", ")", ")", ";", "}", "else", "{", "// Anything else should be saved as file", "$", "file", "=", "$", "this", "->", "extractFileFromString", "(", "$", "part", "->", "getBody", "(", ")", ")", ";", "if", "(", "$", "file", ")", "{", "$", "request", "->", "files", "->", "add", "(", "[", "$", "file", "]", ")", ";", "}", "}", "return", "$", "request", ";", "}" ]
Simple RAW http request parser. Ideal for PUT requests where PUT is streamed but you still need the data. @param Request $request Sf data request @return Request
[ "Simple", "RAW", "http", "request", "parser", ".", "Ideal", "for", "PUT", "requests", "where", "PUT", "is", "streamed", "but", "you", "still", "need", "the", "data", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/FileBundle/Manager/RequestManager.php#L44-L88
26,517
libgraviton/graviton
src/Graviton/FileBundle/Manager/RequestManager.php
RequestManager.extractFileFromString
private function extractFileFromString($fileContent, $originalFileName = null) { $tmpName = $fileName = uniqid(true); if (!is_null($originalFileName)) { $fileName = $originalFileName; } $dir = ini_get('upload_tmp_dir'); $dir = (empty($dir)) ? sys_get_temp_dir() : $dir; $tmpFile = $dir . DIRECTORY_SEPARATOR . $tmpName; // create temporary file; (new Filesystem())->dumpFile($tmpFile, $fileContent); $file = new File($tmpFile); return new UploadedFile( $file->getRealPath(), $fileName, $file->getMimeType(), $file->getSize() ); }
php
private function extractFileFromString($fileContent, $originalFileName = null) { $tmpName = $fileName = uniqid(true); if (!is_null($originalFileName)) { $fileName = $originalFileName; } $dir = ini_get('upload_tmp_dir'); $dir = (empty($dir)) ? sys_get_temp_dir() : $dir; $tmpFile = $dir . DIRECTORY_SEPARATOR . $tmpName; // create temporary file; (new Filesystem())->dumpFile($tmpFile, $fileContent); $file = new File($tmpFile); return new UploadedFile( $file->getRealPath(), $fileName, $file->getMimeType(), $file->getSize() ); }
[ "private", "function", "extractFileFromString", "(", "$", "fileContent", ",", "$", "originalFileName", "=", "null", ")", "{", "$", "tmpName", "=", "$", "fileName", "=", "uniqid", "(", "true", ")", ";", "if", "(", "!", "is_null", "(", "$", "originalFileName", ")", ")", "{", "$", "fileName", "=", "$", "originalFileName", ";", "}", "$", "dir", "=", "ini_get", "(", "'upload_tmp_dir'", ")", ";", "$", "dir", "=", "(", "empty", "(", "$", "dir", ")", ")", "?", "sys_get_temp_dir", "(", ")", ":", "$", "dir", ";", "$", "tmpFile", "=", "$", "dir", ".", "DIRECTORY_SEPARATOR", ".", "$", "tmpName", ";", "// create temporary file;", "(", "new", "Filesystem", "(", ")", ")", "->", "dumpFile", "(", "$", "tmpFile", ",", "$", "fileContent", ")", ";", "$", "file", "=", "new", "File", "(", "$", "tmpFile", ")", ";", "return", "new", "UploadedFile", "(", "$", "file", "->", "getRealPath", "(", ")", ",", "$", "fileName", ",", "$", "file", "->", "getMimeType", "(", ")", ",", "$", "file", "->", "getSize", "(", ")", ")", ";", "}" ]
Extracts file data from request content @param string $fileContent the file content @param string $originalFileName an overriding original file name @return false|UploadedFile
[ "Extracts", "file", "data", "from", "request", "content" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/FileBundle/Manager/RequestManager.php#L98-L120
26,518
libgraviton/graviton
src/Graviton/DocumentBundle/GravitonDocumentBundle.php
GravitonDocumentBundle.boot
public function boot() { $extRefConverter = $this->container->get('graviton.document.service.extrefconverter'); $customType = Type::getType('hash'); $customType->setExtRefConverter($extRefConverter); }
php
public function boot() { $extRefConverter = $this->container->get('graviton.document.service.extrefconverter'); $customType = Type::getType('hash'); $customType->setExtRefConverter($extRefConverter); }
[ "public", "function", "boot", "(", ")", "{", "$", "extRefConverter", "=", "$", "this", "->", "container", "->", "get", "(", "'graviton.document.service.extrefconverter'", ")", ";", "$", "customType", "=", "Type", "::", "getType", "(", "'hash'", ")", ";", "$", "customType", "->", "setExtRefConverter", "(", "$", "extRefConverter", ")", ";", "}" ]
boot bundle function @return void
[ "boot", "bundle", "function" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/GravitonDocumentBundle.php#L126-L131
26,519
libgraviton/graviton
src/Graviton/CoreBundle/Compiler/VersionCompilerPass.php
VersionCompilerPass.process
public function process(ContainerBuilder $container) { $rootDir = $container->getParameter('kernel.root_dir'); if (strpos($rootDir, 'vendor') !== false) { $configurationFile = $rootDir.'/../../../../app'; } else { $configurationFile = $rootDir; } $configurationFile .= '/config/version_service.yml'; if (!file_exists($configurationFile)) { throw new \LogicException( 'Could not read version configuration file "'.$configurationFile.'"' ); } $config = Yaml::parseFile($configurationFile); $versionInformation = [ 'self' => 'unknown' ]; if (isset($config['selfName'])) { $versionInformation['self'] = $this->getPackageVersion($config['selfName']); } if (isset($config['desiredVersions']) && is_array($config['desiredVersions'])) { foreach ($config['desiredVersions'] as $name) { $versionInformation[$name] = $this->getPackageVersion($name); } } // for version header $versionHeader = ''; foreach ($versionInformation as $name => $version) { $versionHeader .= $name . ': ' . $version . '; '; } $container->setParameter( 'graviton.core.version.data', $versionInformation ); $container->setParameter( 'graviton.core.version.header', trim($versionHeader) ); }
php
public function process(ContainerBuilder $container) { $rootDir = $container->getParameter('kernel.root_dir'); if (strpos($rootDir, 'vendor') !== false) { $configurationFile = $rootDir.'/../../../../app'; } else { $configurationFile = $rootDir; } $configurationFile .= '/config/version_service.yml'; if (!file_exists($configurationFile)) { throw new \LogicException( 'Could not read version configuration file "'.$configurationFile.'"' ); } $config = Yaml::parseFile($configurationFile); $versionInformation = [ 'self' => 'unknown' ]; if (isset($config['selfName'])) { $versionInformation['self'] = $this->getPackageVersion($config['selfName']); } if (isset($config['desiredVersions']) && is_array($config['desiredVersions'])) { foreach ($config['desiredVersions'] as $name) { $versionInformation[$name] = $this->getPackageVersion($name); } } // for version header $versionHeader = ''; foreach ($versionInformation as $name => $version) { $versionHeader .= $name . ': ' . $version . '; '; } $container->setParameter( 'graviton.core.version.data', $versionInformation ); $container->setParameter( 'graviton.core.version.header', trim($versionHeader) ); }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "rootDir", "=", "$", "container", "->", "getParameter", "(", "'kernel.root_dir'", ")", ";", "if", "(", "strpos", "(", "$", "rootDir", ",", "'vendor'", ")", "!==", "false", ")", "{", "$", "configurationFile", "=", "$", "rootDir", ".", "'/../../../../app'", ";", "}", "else", "{", "$", "configurationFile", "=", "$", "rootDir", ";", "}", "$", "configurationFile", ".=", "'/config/version_service.yml'", ";", "if", "(", "!", "file_exists", "(", "$", "configurationFile", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "'Could not read version configuration file \"'", ".", "$", "configurationFile", ".", "'\"'", ")", ";", "}", "$", "config", "=", "Yaml", "::", "parseFile", "(", "$", "configurationFile", ")", ";", "$", "versionInformation", "=", "[", "'self'", "=>", "'unknown'", "]", ";", "if", "(", "isset", "(", "$", "config", "[", "'selfName'", "]", ")", ")", "{", "$", "versionInformation", "[", "'self'", "]", "=", "$", "this", "->", "getPackageVersion", "(", "$", "config", "[", "'selfName'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'desiredVersions'", "]", ")", "&&", "is_array", "(", "$", "config", "[", "'desiredVersions'", "]", ")", ")", "{", "foreach", "(", "$", "config", "[", "'desiredVersions'", "]", "as", "$", "name", ")", "{", "$", "versionInformation", "[", "$", "name", "]", "=", "$", "this", "->", "getPackageVersion", "(", "$", "name", ")", ";", "}", "}", "// for version header", "$", "versionHeader", "=", "''", ";", "foreach", "(", "$", "versionInformation", "as", "$", "name", "=>", "$", "version", ")", "{", "$", "versionHeader", ".=", "$", "name", ".", "': '", ".", "$", "version", ".", "'; '", ";", "}", "$", "container", "->", "setParameter", "(", "'graviton.core.version.data'", ",", "$", "versionInformation", ")", ";", "$", "container", "->", "setParameter", "(", "'graviton.core.version.header'", ",", "trim", "(", "$", "versionHeader", ")", ")", ";", "}" ]
add version information of packages to the container @param ContainerBuilder $container Container @return void
[ "add", "version", "information", "of", "packages", "to", "the", "container" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/CoreBundle/Compiler/VersionCompilerPass.php#L41-L88
26,520
libgraviton/graviton
src/Graviton/DocumentBundle/Listener/DocumentVersionListener.php
DocumentVersionListener.updateCounter
private function updateCounter(ModelEvent $event, $action) { if (!$this->constraint->isVersioningService()) { return; } $qb = $this->documentManager->createQueryBuilder($event->getCollectionClass()); if ('update' == $action) { $qb->findAndUpdate() ->field('id')->equals($event->getCollectionId()) ->field(VersionServiceConstraint::FIELD_NAME)->inc(1) ->getQuery()->execute(); } else { $qb->findAndUpdate() ->field('id')->equals($event->getCollectionId()) ->field(VersionServiceConstraint::FIELD_NAME)->set(1) ->getQuery()->execute(); } }
php
private function updateCounter(ModelEvent $event, $action) { if (!$this->constraint->isVersioningService()) { return; } $qb = $this->documentManager->createQueryBuilder($event->getCollectionClass()); if ('update' == $action) { $qb->findAndUpdate() ->field('id')->equals($event->getCollectionId()) ->field(VersionServiceConstraint::FIELD_NAME)->inc(1) ->getQuery()->execute(); } else { $qb->findAndUpdate() ->field('id')->equals($event->getCollectionId()) ->field(VersionServiceConstraint::FIELD_NAME)->set(1) ->getQuery()->execute(); } }
[ "private", "function", "updateCounter", "(", "ModelEvent", "$", "event", ",", "$", "action", ")", "{", "if", "(", "!", "$", "this", "->", "constraint", "->", "isVersioningService", "(", ")", ")", "{", "return", ";", "}", "$", "qb", "=", "$", "this", "->", "documentManager", "->", "createQueryBuilder", "(", "$", "event", "->", "getCollectionClass", "(", ")", ")", ";", "if", "(", "'update'", "==", "$", "action", ")", "{", "$", "qb", "->", "findAndUpdate", "(", ")", "->", "field", "(", "'id'", ")", "->", "equals", "(", "$", "event", "->", "getCollectionId", "(", ")", ")", "->", "field", "(", "VersionServiceConstraint", "::", "FIELD_NAME", ")", "->", "inc", "(", "1", ")", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "}", "else", "{", "$", "qb", "->", "findAndUpdate", "(", ")", "->", "field", "(", "'id'", ")", "->", "equals", "(", "$", "event", "->", "getCollectionId", "(", ")", ")", "->", "field", "(", "VersionServiceConstraint", "::", "FIELD_NAME", ")", "->", "set", "(", "1", ")", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "}", "}" ]
Update Counter for all new saved items @param ModelEvent $event Object event @param string $action What is to be done @return void
[ "Update", "Counter", "for", "all", "new", "saved", "items" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Listener/DocumentVersionListener.php#L68-L86
26,521
libgraviton/graviton
src/Graviton/DocumentBundle/Service/SolrQuery.php
SolrQuery.isConfigured
public function isConfigured() { if (!empty($this->urlParts) && isset($this->solrMap[$this->className])) { return true; } return false; }
php
public function isConfigured() { if (!empty($this->urlParts) && isset($this->solrMap[$this->className])) { return true; } return false; }
[ "public", "function", "isConfigured", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "urlParts", ")", "&&", "isset", "(", "$", "this", "->", "solrMap", "[", "$", "this", "->", "className", "]", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
returns true if solr is configured currently, false otherwise @return bool if solr is configured
[ "returns", "true", "if", "solr", "is", "configured", "currently", "false", "otherwise" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Service/SolrQuery.php#L148-L154
26,522
libgraviton/graviton
src/Graviton/DocumentBundle/Service/SolrQuery.php
SolrQuery.query
public function query(SearchNode $node, LimitNode $limitNode = null) { $client = $this->getClient(); $query = $client->createQuery($client::QUERY_SELECT); // set the weights $query->getEDisMax()->setQueryFields($this->solrMap[$this->className]); $query->setQuery($this->getSearchTerm($node)); if ($limitNode instanceof LimitNode) { $query->setStart($limitNode->getOffset())->setRows($limitNode->getLimit()); } else { $query->setStart(0)->setRows($this->paginationDefaultLimit); } $query->setFields(['id']); $result = $client->select($query); if ($this->requestStack->getCurrentRequest() instanceof Request) { $this->requestStack->getCurrentRequest()->attributes->set('totalCount', $result->getNumFound()); $this->requestStack->getCurrentRequest()->attributes->set('X-Search-Source', 'solr'); } $idList = []; foreach ($result as $document) { if (isset($document->id)) { $idList[] = (string) $document->id; } elseif (isset($document->_id)) { $idList[] = (string) $document->_id; } } return $idList; }
php
public function query(SearchNode $node, LimitNode $limitNode = null) { $client = $this->getClient(); $query = $client->createQuery($client::QUERY_SELECT); // set the weights $query->getEDisMax()->setQueryFields($this->solrMap[$this->className]); $query->setQuery($this->getSearchTerm($node)); if ($limitNode instanceof LimitNode) { $query->setStart($limitNode->getOffset())->setRows($limitNode->getLimit()); } else { $query->setStart(0)->setRows($this->paginationDefaultLimit); } $query->setFields(['id']); $result = $client->select($query); if ($this->requestStack->getCurrentRequest() instanceof Request) { $this->requestStack->getCurrentRequest()->attributes->set('totalCount', $result->getNumFound()); $this->requestStack->getCurrentRequest()->attributes->set('X-Search-Source', 'solr'); } $idList = []; foreach ($result as $document) { if (isset($document->id)) { $idList[] = (string) $document->id; } elseif (isset($document->_id)) { $idList[] = (string) $document->_id; } } return $idList; }
[ "public", "function", "query", "(", "SearchNode", "$", "node", ",", "LimitNode", "$", "limitNode", "=", "null", ")", "{", "$", "client", "=", "$", "this", "->", "getClient", "(", ")", ";", "$", "query", "=", "$", "client", "->", "createQuery", "(", "$", "client", "::", "QUERY_SELECT", ")", ";", "// set the weights", "$", "query", "->", "getEDisMax", "(", ")", "->", "setQueryFields", "(", "$", "this", "->", "solrMap", "[", "$", "this", "->", "className", "]", ")", ";", "$", "query", "->", "setQuery", "(", "$", "this", "->", "getSearchTerm", "(", "$", "node", ")", ")", ";", "if", "(", "$", "limitNode", "instanceof", "LimitNode", ")", "{", "$", "query", "->", "setStart", "(", "$", "limitNode", "->", "getOffset", "(", ")", ")", "->", "setRows", "(", "$", "limitNode", "->", "getLimit", "(", ")", ")", ";", "}", "else", "{", "$", "query", "->", "setStart", "(", "0", ")", "->", "setRows", "(", "$", "this", "->", "paginationDefaultLimit", ")", ";", "}", "$", "query", "->", "setFields", "(", "[", "'id'", "]", ")", ";", "$", "result", "=", "$", "client", "->", "select", "(", "$", "query", ")", ";", "if", "(", "$", "this", "->", "requestStack", "->", "getCurrentRequest", "(", ")", "instanceof", "Request", ")", "{", "$", "this", "->", "requestStack", "->", "getCurrentRequest", "(", ")", "->", "attributes", "->", "set", "(", "'totalCount'", ",", "$", "result", "->", "getNumFound", "(", ")", ")", ";", "$", "this", "->", "requestStack", "->", "getCurrentRequest", "(", ")", "->", "attributes", "->", "set", "(", "'X-Search-Source'", ",", "'solr'", ")", ";", "}", "$", "idList", "=", "[", "]", ";", "foreach", "(", "$", "result", "as", "$", "document", ")", "{", "if", "(", "isset", "(", "$", "document", "->", "id", ")", ")", "{", "$", "idList", "[", "]", "=", "(", "string", ")", "$", "document", "->", "id", ";", "}", "elseif", "(", "isset", "(", "$", "document", "->", "_id", ")", ")", "{", "$", "idList", "[", "]", "=", "(", "string", ")", "$", "document", "->", "_id", ";", "}", "}", "return", "$", "idList", ";", "}" ]
executes the search on solr using the rql parsing nodes. @param SearchNode $node search node @param LimitNode|null $limitNode limit node @return array an array of just record ids (the ids of the matching documents in solr)
[ "executes", "the", "search", "on", "solr", "using", "the", "rql", "parsing", "nodes", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Service/SolrQuery.php#L164-L200
26,523
libgraviton/graviton
src/Graviton/DocumentBundle/Service/SolrQuery.php
SolrQuery.getSearchTerm
private function getSearchTerm(SearchNode $node) { $fullTerm = $node->getSearchQuery(); foreach ($this->fullTermPatterns as $pattern) { if (preg_match($pattern, $fullTerm, $matches) === 1) { return '"'.$fullTerm.'"'; } } if ($this->andifyTerms) { $glue = 'AND'; } else { $glue = ''; } $i = 0; $hasPreviousOperator = false; $fullSearchElements = []; foreach (explode(' ', $node->getSearchQuery()) as $term) { $i++; // is this an operator? if (array_search($term, $this->queryOperators) !== false) { $fullSearchElements[] = $term; $hasPreviousOperator = true; continue; } $singleTerm = $this->getSingleTerm($term); if ($i > 1 && $hasPreviousOperator == false && !empty($glue)) { $fullSearchElements[] = $glue; } else { $hasPreviousOperator = false; } $fullSearchElements[] = $singleTerm; } return implode(' ', $fullSearchElements); }
php
private function getSearchTerm(SearchNode $node) { $fullTerm = $node->getSearchQuery(); foreach ($this->fullTermPatterns as $pattern) { if (preg_match($pattern, $fullTerm, $matches) === 1) { return '"'.$fullTerm.'"'; } } if ($this->andifyTerms) { $glue = 'AND'; } else { $glue = ''; } $i = 0; $hasPreviousOperator = false; $fullSearchElements = []; foreach (explode(' ', $node->getSearchQuery()) as $term) { $i++; // is this an operator? if (array_search($term, $this->queryOperators) !== false) { $fullSearchElements[] = $term; $hasPreviousOperator = true; continue; } $singleTerm = $this->getSingleTerm($term); if ($i > 1 && $hasPreviousOperator == false && !empty($glue)) { $fullSearchElements[] = $glue; } else { $hasPreviousOperator = false; } $fullSearchElements[] = $singleTerm; } return implode(' ', $fullSearchElements); }
[ "private", "function", "getSearchTerm", "(", "SearchNode", "$", "node", ")", "{", "$", "fullTerm", "=", "$", "node", "->", "getSearchQuery", "(", ")", ";", "foreach", "(", "$", "this", "->", "fullTermPatterns", "as", "$", "pattern", ")", "{", "if", "(", "preg_match", "(", "$", "pattern", ",", "$", "fullTerm", ",", "$", "matches", ")", "===", "1", ")", "{", "return", "'\"'", ".", "$", "fullTerm", ".", "'\"'", ";", "}", "}", "if", "(", "$", "this", "->", "andifyTerms", ")", "{", "$", "glue", "=", "'AND'", ";", "}", "else", "{", "$", "glue", "=", "''", ";", "}", "$", "i", "=", "0", ";", "$", "hasPreviousOperator", "=", "false", ";", "$", "fullSearchElements", "=", "[", "]", ";", "foreach", "(", "explode", "(", "' '", ",", "$", "node", "->", "getSearchQuery", "(", ")", ")", "as", "$", "term", ")", "{", "$", "i", "++", ";", "// is this an operator?", "if", "(", "array_search", "(", "$", "term", ",", "$", "this", "->", "queryOperators", ")", "!==", "false", ")", "{", "$", "fullSearchElements", "[", "]", "=", "$", "term", ";", "$", "hasPreviousOperator", "=", "true", ";", "continue", ";", "}", "$", "singleTerm", "=", "$", "this", "->", "getSingleTerm", "(", "$", "term", ")", ";", "if", "(", "$", "i", ">", "1", "&&", "$", "hasPreviousOperator", "==", "false", "&&", "!", "empty", "(", "$", "glue", ")", ")", "{", "$", "fullSearchElements", "[", "]", "=", "$", "glue", ";", "}", "else", "{", "$", "hasPreviousOperator", "=", "false", ";", "}", "$", "fullSearchElements", "[", "]", "=", "$", "singleTerm", ";", "}", "return", "implode", "(", "' '", ",", "$", "fullSearchElements", ")", ";", "}" ]
returns the string search term to be used in the solr query @param SearchNode $node the search node @return string the composed search query
[ "returns", "the", "string", "search", "term", "to", "be", "used", "in", "the", "solr", "query" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Service/SolrQuery.php#L209-L252
26,524
libgraviton/graviton
src/Graviton/DocumentBundle/Service/SolrQuery.php
SolrQuery.getSingleTerm
private function getSingleTerm($term) { // we don't modify numbers if (ctype_digit($term)) { return '"'.$term.'"'; } // formatted number? $formatted = str_replace( [ '-', '.' ], '', $term ); if (ctype_digit($formatted)) { return '"'.$term.'"'; } // everything that is only numbers *and* characters and at least 3 long, we don't fuzzy/wildcard // thanks to https://stackoverflow.com/a/7684859/3762521 $pattern = '/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/'; if (strlen($term) > 3 && preg_match($pattern, $term, $matches) === 1) { return '"'.$term.'"'; } // is it a solr field query (like id:333)? if (preg_match($this->fieldQueryPattern, $term) === 1) { return $this->parseSolrFieldQuery($term); } // strings shorter then 5 chars (like hans) we wildcard, all others we make fuzzy if (strlen($term) >= $this->solrFuzzyBridge) { return $this->doAndNotPrefixSingleTerm($term, '~'); } if (strlen($term) >= $this->solrWildcardBridge) { return $this->doAndNotPrefixSingleTerm($term, '*'); } return $term; }
php
private function getSingleTerm($term) { // we don't modify numbers if (ctype_digit($term)) { return '"'.$term.'"'; } // formatted number? $formatted = str_replace( [ '-', '.' ], '', $term ); if (ctype_digit($formatted)) { return '"'.$term.'"'; } // everything that is only numbers *and* characters and at least 3 long, we don't fuzzy/wildcard // thanks to https://stackoverflow.com/a/7684859/3762521 $pattern = '/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/'; if (strlen($term) > 3 && preg_match($pattern, $term, $matches) === 1) { return '"'.$term.'"'; } // is it a solr field query (like id:333)? if (preg_match($this->fieldQueryPattern, $term) === 1) { return $this->parseSolrFieldQuery($term); } // strings shorter then 5 chars (like hans) we wildcard, all others we make fuzzy if (strlen($term) >= $this->solrFuzzyBridge) { return $this->doAndNotPrefixSingleTerm($term, '~'); } if (strlen($term) >= $this->solrWildcardBridge) { return $this->doAndNotPrefixSingleTerm($term, '*'); } return $term; }
[ "private", "function", "getSingleTerm", "(", "$", "term", ")", "{", "// we don't modify numbers", "if", "(", "ctype_digit", "(", "$", "term", ")", ")", "{", "return", "'\"'", ".", "$", "term", ".", "'\"'", ";", "}", "// formatted number?", "$", "formatted", "=", "str_replace", "(", "[", "'-'", ",", "'.'", "]", ",", "''", ",", "$", "term", ")", ";", "if", "(", "ctype_digit", "(", "$", "formatted", ")", ")", "{", "return", "'\"'", ".", "$", "term", ".", "'\"'", ";", "}", "// everything that is only numbers *and* characters and at least 3 long, we don't fuzzy/wildcard", "// thanks to https://stackoverflow.com/a/7684859/3762521", "$", "pattern", "=", "'/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/'", ";", "if", "(", "strlen", "(", "$", "term", ")", ">", "3", "&&", "preg_match", "(", "$", "pattern", ",", "$", "term", ",", "$", "matches", ")", "===", "1", ")", "{", "return", "'\"'", ".", "$", "term", ".", "'\"'", ";", "}", "// is it a solr field query (like id:333)?", "if", "(", "preg_match", "(", "$", "this", "->", "fieldQueryPattern", ",", "$", "term", ")", "===", "1", ")", "{", "return", "$", "this", "->", "parseSolrFieldQuery", "(", "$", "term", ")", ";", "}", "// strings shorter then 5 chars (like hans) we wildcard, all others we make fuzzy", "if", "(", "strlen", "(", "$", "term", ")", ">=", "$", "this", "->", "solrFuzzyBridge", ")", "{", "return", "$", "this", "->", "doAndNotPrefixSingleTerm", "(", "$", "term", ",", "'~'", ")", ";", "}", "if", "(", "strlen", "(", "$", "term", ")", ">=", "$", "this", "->", "solrWildcardBridge", ")", "{", "return", "$", "this", "->", "doAndNotPrefixSingleTerm", "(", "$", "term", ",", "'*'", ")", ";", "}", "return", "$", "term", ";", "}" ]
returns a single term how to search. here we can apply custom logic to the user input string @param string $term single search term @return string modified search term
[ "returns", "a", "single", "term", "how", "to", "search", ".", "here", "we", "can", "apply", "custom", "logic", "to", "the", "user", "input", "string" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Service/SolrQuery.php#L261-L303
26,525
libgraviton/graviton
src/Graviton/DocumentBundle/Service/SolrQuery.php
SolrQuery.doAndNotPrefixSingleTerm
private function doAndNotPrefixSingleTerm($term, $modifier) { // already modifier there? $last = substr($term, -1); if ($last == '~' || $last == '*') { // clean from term, override modifier from client $modifier = $last; $term = substr($term, 0, -1); } return sprintf( '(%s OR %s%s)', $term, $term, $modifier ); }
php
private function doAndNotPrefixSingleTerm($term, $modifier) { // already modifier there? $last = substr($term, -1); if ($last == '~' || $last == '*') { // clean from term, override modifier from client $modifier = $last; $term = substr($term, 0, -1); } return sprintf( '(%s OR %s%s)', $term, $term, $modifier ); }
[ "private", "function", "doAndNotPrefixSingleTerm", "(", "$", "term", ",", "$", "modifier", ")", "{", "// already modifier there?", "$", "last", "=", "substr", "(", "$", "term", ",", "-", "1", ")", ";", "if", "(", "$", "last", "==", "'~'", "||", "$", "last", "==", "'*'", ")", "{", "// clean from term, override modifier from client", "$", "modifier", "=", "$", "last", ";", "$", "term", "=", "substr", "(", "$", "term", ",", "0", ",", "-", "1", ")", ";", "}", "return", "sprintf", "(", "'(%s OR %s%s)'", ",", "$", "term", ",", "$", "term", ",", "$", "modifier", ")", ";", "}" ]
ORify a single term @param string $term search term @param string $modifier modified @return string ORified query
[ "ORify", "a", "single", "term" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Service/SolrQuery.php#L339-L355
26,526
libgraviton/graviton
src/Graviton/DocumentBundle/Service/SolrQuery.php
SolrQuery.getClient
private function getClient() { $endpointConfig = $this->urlParts; if (!isset($endpointConfig['path'])) { $endpointConfig['path'] = '/'; } if (substr($endpointConfig['path'], -1) != '/') { $endpointConfig['path'] .= '/'; } // find core name $classnameParts = explode('\\', $this->className); $endpointConfig['core'] = array_pop($classnameParts); $endpointConfig['timeout'] = 10000; $endpointConfig['key'] = 'local'; $this->solrClient->addEndpoint($endpointConfig); $this->solrClient->setDefaultEndpoint($endpointConfig['key']); return $this->solrClient; }
php
private function getClient() { $endpointConfig = $this->urlParts; if (!isset($endpointConfig['path'])) { $endpointConfig['path'] = '/'; } if (substr($endpointConfig['path'], -1) != '/') { $endpointConfig['path'] .= '/'; } // find core name $classnameParts = explode('\\', $this->className); $endpointConfig['core'] = array_pop($classnameParts); $endpointConfig['timeout'] = 10000; $endpointConfig['key'] = 'local'; $this->solrClient->addEndpoint($endpointConfig); $this->solrClient->setDefaultEndpoint($endpointConfig['key']); return $this->solrClient; }
[ "private", "function", "getClient", "(", ")", "{", "$", "endpointConfig", "=", "$", "this", "->", "urlParts", ";", "if", "(", "!", "isset", "(", "$", "endpointConfig", "[", "'path'", "]", ")", ")", "{", "$", "endpointConfig", "[", "'path'", "]", "=", "'/'", ";", "}", "if", "(", "substr", "(", "$", "endpointConfig", "[", "'path'", "]", ",", "-", "1", ")", "!=", "'/'", ")", "{", "$", "endpointConfig", "[", "'path'", "]", ".=", "'/'", ";", "}", "// find core name", "$", "classnameParts", "=", "explode", "(", "'\\\\'", ",", "$", "this", "->", "className", ")", ";", "$", "endpointConfig", "[", "'core'", "]", "=", "array_pop", "(", "$", "classnameParts", ")", ";", "$", "endpointConfig", "[", "'timeout'", "]", "=", "10000", ";", "$", "endpointConfig", "[", "'key'", "]", "=", "'local'", ";", "$", "this", "->", "solrClient", "->", "addEndpoint", "(", "$", "endpointConfig", ")", ";", "$", "this", "->", "solrClient", "->", "setDefaultEndpoint", "(", "$", "endpointConfig", "[", "'key'", "]", ")", ";", "return", "$", "this", "->", "solrClient", ";", "}" ]
returns the client to use for the current query @return Client client
[ "returns", "the", "client", "to", "use", "for", "the", "current", "query" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Service/SolrQuery.php#L362-L384
26,527
libgraviton/graviton
src/Graviton/ProxyBundle/Transformation/BodyMapping.php
BodyMapping.transformResponse
public function transformResponse(Response $responseIn, Response $responseOut) { $responseOut->setContent( json_encode($this->transformer->transform($responseIn->getContent(), $this->mapping)) ); }
php
public function transformResponse(Response $responseIn, Response $responseOut) { $responseOut->setContent( json_encode($this->transformer->transform($responseIn->getContent(), $this->mapping)) ); }
[ "public", "function", "transformResponse", "(", "Response", "$", "responseIn", ",", "Response", "$", "responseOut", ")", "{", "$", "responseOut", "->", "setContent", "(", "json_encode", "(", "$", "this", "->", "transformer", "->", "transform", "(", "$", "responseIn", "->", "getContent", "(", ")", ",", "$", "this", "->", "mapping", ")", ")", ")", ";", "}" ]
Transforms a response @param Response $responseIn The original response object @param Response $responseOut The response object to transform @return void
[ "Transforms", "a", "response" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Transformation/BodyMapping.php#L50-L55
26,528
libgraviton/graviton
src/Graviton/ProxyBundle/Transformation/BodyMapping.php
BodyMapping.transformRequest
public function transformRequest(Request $requestIn, Request $requestOut) { $requestOut = Request::create( $requestOut->getUri(), $requestOut->getMethod(), [], [], [], [], json_encode( $this->transformer->transform(json_decode($requestIn->getContent()), $this->mapping) ) ); return $requestOut; }
php
public function transformRequest(Request $requestIn, Request $requestOut) { $requestOut = Request::create( $requestOut->getUri(), $requestOut->getMethod(), [], [], [], [], json_encode( $this->transformer->transform(json_decode($requestIn->getContent()), $this->mapping) ) ); return $requestOut; }
[ "public", "function", "transformRequest", "(", "Request", "$", "requestIn", ",", "Request", "$", "requestOut", ")", "{", "$", "requestOut", "=", "Request", "::", "create", "(", "$", "requestOut", "->", "getUri", "(", ")", ",", "$", "requestOut", "->", "getMethod", "(", ")", ",", "[", "]", ",", "[", "]", ",", "[", "]", ",", "[", "]", ",", "json_encode", "(", "$", "this", "->", "transformer", "->", "transform", "(", "json_decode", "(", "$", "requestIn", "->", "getContent", "(", ")", ")", ",", "$", "this", "->", "mapping", ")", ")", ")", ";", "return", "$", "requestOut", ";", "}" ]
Transforms a request @param Request $requestIn The original request object @param Request $requestOut The request object to transform @return Request The transformed request
[ "Transforms", "a", "request" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Transformation/BodyMapping.php#L64-L78
26,529
libgraviton/graviton
src/Graviton/RestBundle/Routing/Loader/ActionUtils.php
ActionUtils.getBaseFromService
private static function getBaseFromService($service, $serviceConfig) { if (isset($serviceConfig[0]['router-base']) && strlen($serviceConfig[0]['router-base']) > 0) { $base = $serviceConfig[0]['router-base'] . '/'; } else { $parts = explode('.', $service); $entity = array_pop($parts); $module = $parts[1]; $base = '/' . $module . '/' . $entity . '/'; } return $base; }
php
private static function getBaseFromService($service, $serviceConfig) { if (isset($serviceConfig[0]['router-base']) && strlen($serviceConfig[0]['router-base']) > 0) { $base = $serviceConfig[0]['router-base'] . '/'; } else { $parts = explode('.', $service); $entity = array_pop($parts); $module = $parts[1]; $base = '/' . $module . '/' . $entity . '/'; } return $base; }
[ "private", "static", "function", "getBaseFromService", "(", "$", "service", ",", "$", "serviceConfig", ")", "{", "if", "(", "isset", "(", "$", "serviceConfig", "[", "0", "]", "[", "'router-base'", "]", ")", "&&", "strlen", "(", "$", "serviceConfig", "[", "0", "]", "[", "'router-base'", "]", ")", ">", "0", ")", "{", "$", "base", "=", "$", "serviceConfig", "[", "0", "]", "[", "'router-base'", "]", ".", "'/'", ";", "}", "else", "{", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "service", ")", ";", "$", "entity", "=", "array_pop", "(", "$", "parts", ")", ";", "$", "module", "=", "$", "parts", "[", "1", "]", ";", "$", "base", "=", "'/'", ".", "$", "module", ".", "'/'", ".", "$", "entity", ".", "'/'", ";", "}", "return", "$", "base", ";", "}" ]
Get entity name from service strings. By convention the last part of the service string so far makes up the entities name. @param string $service (partial) service id @param array $serviceConfig service configuration @return string
[ "Get", "entity", "name", "from", "service", "strings", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Routing/Loader/ActionUtils.php#L77-L91
26,530
libgraviton/graviton
src/Graviton/RestBundle/Routing/Loader/ActionUtils.php
ActionUtils.getRouteOptions
public static function getRouteOptions($service, $serviceConfig, array $parameters = [], $useIdPattern = false) { if ($useIdPattern) { $parameters['id'] = self::ID_PATTERN; } return self::getRoute($service, 'OPTIONS', 'optionsAction', $serviceConfig, $parameters); }
php
public static function getRouteOptions($service, $serviceConfig, array $parameters = [], $useIdPattern = false) { if ($useIdPattern) { $parameters['id'] = self::ID_PATTERN; } return self::getRoute($service, 'OPTIONS', 'optionsAction', $serviceConfig, $parameters); }
[ "public", "static", "function", "getRouteOptions", "(", "$", "service", ",", "$", "serviceConfig", ",", "array", "$", "parameters", "=", "[", "]", ",", "$", "useIdPattern", "=", "false", ")", "{", "if", "(", "$", "useIdPattern", ")", "{", "$", "parameters", "[", "'id'", "]", "=", "self", "::", "ID_PATTERN", ";", "}", "return", "self", "::", "getRoute", "(", "$", "service", ",", "'OPTIONS'", ",", "'optionsAction'", ",", "$", "serviceConfig", ",", "$", "parameters", ")", ";", "}" ]
Get route for OPTIONS requests @param string $service service id @param array $serviceConfig service configuration @param array $parameters service params @param boolean $useIdPattern generate route with id param @return Route
[ "Get", "route", "for", "OPTIONS", "requests" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Routing/Loader/ActionUtils.php#L168-L174
26,531
libgraviton/graviton
src/Graviton/RestBundle/Routing/Loader/ActionUtils.php
ActionUtils.getCanonicalSchemaRoute
public static function getCanonicalSchemaRoute($service, $serviceConfig, $type = 'item', $option = false) { $pattern = self::getBaseFromService($service, $serviceConfig); $pattern = '/schema' . $pattern . $type; $action = 'schemaAction'; $method = 'GET'; if ($option !== false) { $action = 'optionsAction'; $method = 'OPTIONS'; } $defaults = array( '_controller' => $service . ':' . $action, '_format' => '~', ); $route = new Route($pattern, $defaults, []); $route->setMethods($method); return $route; }
php
public static function getCanonicalSchemaRoute($service, $serviceConfig, $type = 'item', $option = false) { $pattern = self::getBaseFromService($service, $serviceConfig); $pattern = '/schema' . $pattern . $type; $action = 'schemaAction'; $method = 'GET'; if ($option !== false) { $action = 'optionsAction'; $method = 'OPTIONS'; } $defaults = array( '_controller' => $service . ':' . $action, '_format' => '~', ); $route = new Route($pattern, $defaults, []); $route->setMethods($method); return $route; }
[ "public", "static", "function", "getCanonicalSchemaRoute", "(", "$", "service", ",", "$", "serviceConfig", ",", "$", "type", "=", "'item'", ",", "$", "option", "=", "false", ")", "{", "$", "pattern", "=", "self", "::", "getBaseFromService", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "pattern", "=", "'/schema'", ".", "$", "pattern", ".", "$", "type", ";", "$", "action", "=", "'schemaAction'", ";", "$", "method", "=", "'GET'", ";", "if", "(", "$", "option", "!==", "false", ")", "{", "$", "action", "=", "'optionsAction'", ";", "$", "method", "=", "'OPTIONS'", ";", "}", "$", "defaults", "=", "array", "(", "'_controller'", "=>", "$", "service", ".", "':'", ".", "$", "action", ",", "'_format'", "=>", "'~'", ",", ")", ";", "$", "route", "=", "new", "Route", "(", "$", "pattern", ",", "$", "defaults", ",", "[", "]", ")", ";", "$", "route", "->", "setMethods", "(", "$", "method", ")", ";", "return", "$", "route", ";", "}" ]
Get canonical route for schema requests @param string $service service id @param array $serviceConfig service configuration @param string $type service type (item or collection) @param boolean $option render a options route @return Route
[ "Get", "canonical", "route", "for", "schema", "requests" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Routing/Loader/ActionUtils.php#L204-L225
26,532
libgraviton/graviton
src/Graviton/I18nBundle/Service/I18nUtils.php
I18nUtils.findMatchingTranslatables
public function findMatchingTranslatables($value, $sourceLocale, $useWildCard = false) { // i need to use a queryBuilder as the repository doesn't let me do regex queries (i guess so..) $builder = $this->manager->createQueryBuilder(Translation::class); $builder ->field('language')->equals($sourceLocale); if ($useWildCard === true) { $value = new \MongoRegex($value); } /* * we have 2 cases to match * - 'translated' is set and matches * - 'translated' is not present, so 'original' can match (as this is inserted 'virtually') */ $builder->addAnd( $builder->expr() ->addOr( $builder->expr()->field('localized')->equals($value) ) ->addOr( $builder->expr() ->field('localized')->equals(null) ->field('original')->equals($value) ) ); $query = $builder->getQuery(); return $query->execute()->toArray(); }
php
public function findMatchingTranslatables($value, $sourceLocale, $useWildCard = false) { // i need to use a queryBuilder as the repository doesn't let me do regex queries (i guess so..) $builder = $this->manager->createQueryBuilder(Translation::class); $builder ->field('language')->equals($sourceLocale); if ($useWildCard === true) { $value = new \MongoRegex($value); } /* * we have 2 cases to match * - 'translated' is set and matches * - 'translated' is not present, so 'original' can match (as this is inserted 'virtually') */ $builder->addAnd( $builder->expr() ->addOr( $builder->expr()->field('localized')->equals($value) ) ->addOr( $builder->expr() ->field('localized')->equals(null) ->field('original')->equals($value) ) ); $query = $builder->getQuery(); return $query->execute()->toArray(); }
[ "public", "function", "findMatchingTranslatables", "(", "$", "value", ",", "$", "sourceLocale", ",", "$", "useWildCard", "=", "false", ")", "{", "// i need to use a queryBuilder as the repository doesn't let me do regex queries (i guess so..)", "$", "builder", "=", "$", "this", "->", "manager", "->", "createQueryBuilder", "(", "Translation", "::", "class", ")", ";", "$", "builder", "->", "field", "(", "'language'", ")", "->", "equals", "(", "$", "sourceLocale", ")", ";", "if", "(", "$", "useWildCard", "===", "true", ")", "{", "$", "value", "=", "new", "\\", "MongoRegex", "(", "$", "value", ")", ";", "}", "/*\n * we have 2 cases to match\n * - 'translated' is set and matches\n * - 'translated' is not present, so 'original' can match (as this is inserted 'virtually')\n */", "$", "builder", "->", "addAnd", "(", "$", "builder", "->", "expr", "(", ")", "->", "addOr", "(", "$", "builder", "->", "expr", "(", ")", "->", "field", "(", "'localized'", ")", "->", "equals", "(", "$", "value", ")", ")", "->", "addOr", "(", "$", "builder", "->", "expr", "(", ")", "->", "field", "(", "'localized'", ")", "->", "equals", "(", "null", ")", "->", "field", "(", "'original'", ")", "->", "equals", "(", "$", "value", ")", ")", ")", ";", "$", "query", "=", "$", "builder", "->", "getQuery", "(", ")", ";", "return", "$", "query", "->", "execute", "(", ")", "->", "toArray", "(", ")", ";", "}" ]
This function allows to search for existing translations from a source language, probably using a wildcard @param string $value the translated string @param string $sourceLocale a source locale @param boolean $useWildCard if we should search wildcard or not @return array matching Translatables
[ "This", "function", "allows", "to", "search", "for", "existing", "translations", "from", "a", "source", "language", "probably", "using", "a", "wildcard" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/I18nBundle/Service/I18nUtils.php#L102-L133
26,533
libgraviton/graviton
src/Graviton/SecurityBundle/Authentication/SecurityAuthenticator.php
SecurityAuthenticator.authenticateToken
public function authenticateToken( TokenInterface $token, UserProviderInterface $userProvider, $providerKey ) { $username = $token->getCredentials(); $roles = array_map(array($this, 'objectRolesToArray'), $token->getRoles()); $user = false; // If no username in Strategy, check if required. if ($this->securityRequired && !$username) { $this->logger->warning('Authentication key is required.'); throw new AuthenticationException('Authentication key is required.'); } if ($username) { if (in_array(SecurityUser::ROLE_SUBNET, $roles)) { $this->logger->info('Authentication, subnet user IP address: ' . $token->getAttribute('ipAddress')); $user = new SubnetUser($username); } elseif ($user = $this->userProvider->loadUserByUsername($username)) { $roles[] = SecurityUser::ROLE_CONSULTANT; } } // If no user, try to fetch the test user, else check if anonymous is enabled if (!$user) { if ($this->testUsername && $user = $this->userProvider->loadUserByUsername($this->testUsername)) { $this->logger->info('Authentication, test user: ' . $this->testUsername); $roles[] = SecurityUser::ROLE_TEST; } elseif ($this->allowAnonymous) { $this->logger->info('Authentication, loading anonymous user.'); $user = new AnonymousUser(); $roles[] = SecurityUser::ROLE_ANONYMOUS; } } /** @var SecurityUser $securityUser */ if ($user) { $securityUser = new SecurityUser($user, $roles); } else { $this->logger->warning(sprintf('Authentication key "%s" could not be resolved.', $username)); throw new AuthenticationException( sprintf('Authentication key "%s" could not be resolved.', $username) ); } return new PreAuthenticatedToken( $securityUser, $username, $providerKey, $securityUser->getRoles() ); }
php
public function authenticateToken( TokenInterface $token, UserProviderInterface $userProvider, $providerKey ) { $username = $token->getCredentials(); $roles = array_map(array($this, 'objectRolesToArray'), $token->getRoles()); $user = false; // If no username in Strategy, check if required. if ($this->securityRequired && !$username) { $this->logger->warning('Authentication key is required.'); throw new AuthenticationException('Authentication key is required.'); } if ($username) { if (in_array(SecurityUser::ROLE_SUBNET, $roles)) { $this->logger->info('Authentication, subnet user IP address: ' . $token->getAttribute('ipAddress')); $user = new SubnetUser($username); } elseif ($user = $this->userProvider->loadUserByUsername($username)) { $roles[] = SecurityUser::ROLE_CONSULTANT; } } // If no user, try to fetch the test user, else check if anonymous is enabled if (!$user) { if ($this->testUsername && $user = $this->userProvider->loadUserByUsername($this->testUsername)) { $this->logger->info('Authentication, test user: ' . $this->testUsername); $roles[] = SecurityUser::ROLE_TEST; } elseif ($this->allowAnonymous) { $this->logger->info('Authentication, loading anonymous user.'); $user = new AnonymousUser(); $roles[] = SecurityUser::ROLE_ANONYMOUS; } } /** @var SecurityUser $securityUser */ if ($user) { $securityUser = new SecurityUser($user, $roles); } else { $this->logger->warning(sprintf('Authentication key "%s" could not be resolved.', $username)); throw new AuthenticationException( sprintf('Authentication key "%s" could not be resolved.', $username) ); } return new PreAuthenticatedToken( $securityUser, $username, $providerKey, $securityUser->getRoles() ); }
[ "public", "function", "authenticateToken", "(", "TokenInterface", "$", "token", ",", "UserProviderInterface", "$", "userProvider", ",", "$", "providerKey", ")", "{", "$", "username", "=", "$", "token", "->", "getCredentials", "(", ")", ";", "$", "roles", "=", "array_map", "(", "array", "(", "$", "this", ",", "'objectRolesToArray'", ")", ",", "$", "token", "->", "getRoles", "(", ")", ")", ";", "$", "user", "=", "false", ";", "// If no username in Strategy, check if required.", "if", "(", "$", "this", "->", "securityRequired", "&&", "!", "$", "username", ")", "{", "$", "this", "->", "logger", "->", "warning", "(", "'Authentication key is required.'", ")", ";", "throw", "new", "AuthenticationException", "(", "'Authentication key is required.'", ")", ";", "}", "if", "(", "$", "username", ")", "{", "if", "(", "in_array", "(", "SecurityUser", "::", "ROLE_SUBNET", ",", "$", "roles", ")", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "'Authentication, subnet user IP address: '", ".", "$", "token", "->", "getAttribute", "(", "'ipAddress'", ")", ")", ";", "$", "user", "=", "new", "SubnetUser", "(", "$", "username", ")", ";", "}", "elseif", "(", "$", "user", "=", "$", "this", "->", "userProvider", "->", "loadUserByUsername", "(", "$", "username", ")", ")", "{", "$", "roles", "[", "]", "=", "SecurityUser", "::", "ROLE_CONSULTANT", ";", "}", "}", "// If no user, try to fetch the test user, else check if anonymous is enabled", "if", "(", "!", "$", "user", ")", "{", "if", "(", "$", "this", "->", "testUsername", "&&", "$", "user", "=", "$", "this", "->", "userProvider", "->", "loadUserByUsername", "(", "$", "this", "->", "testUsername", ")", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "'Authentication, test user: '", ".", "$", "this", "->", "testUsername", ")", ";", "$", "roles", "[", "]", "=", "SecurityUser", "::", "ROLE_TEST", ";", "}", "elseif", "(", "$", "this", "->", "allowAnonymous", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "'Authentication, loading anonymous user.'", ")", ";", "$", "user", "=", "new", "AnonymousUser", "(", ")", ";", "$", "roles", "[", "]", "=", "SecurityUser", "::", "ROLE_ANONYMOUS", ";", "}", "}", "/** @var SecurityUser $securityUser */", "if", "(", "$", "user", ")", "{", "$", "securityUser", "=", "new", "SecurityUser", "(", "$", "user", ",", "$", "roles", ")", ";", "}", "else", "{", "$", "this", "->", "logger", "->", "warning", "(", "sprintf", "(", "'Authentication key \"%s\" could not be resolved.'", ",", "$", "username", ")", ")", ";", "throw", "new", "AuthenticationException", "(", "sprintf", "(", "'Authentication key \"%s\" could not be resolved.'", ",", "$", "username", ")", ")", ";", "}", "return", "new", "PreAuthenticatedToken", "(", "$", "securityUser", ",", "$", "username", ",", "$", "providerKey", ",", "$", "securityUser", "->", "getRoles", "(", ")", ")", ";", "}" ]
Tries to authenticate the provided token @param TokenInterface $token token to authenticate @param UserProviderInterface $userProvider provider to auth against @param string $providerKey key to auth with @return PreAuthenticatedToken
[ "Tries", "to", "authenticate", "the", "provided", "token" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SecurityBundle/Authentication/SecurityAuthenticator.php#L126-L178
26,534
libgraviton/graviton
src/Graviton/GeneratorBundle/Generator/ResourceGenerator/XDynamicKey.php
XDynamicKey.prepareFunctionNames
private static function prepareFunctionNames($refMethods) { $fieldNames = explode('.', $refMethods); $getters = []; foreach ($fieldNames as $field) { array_push($getters, 'get'.ucfirst($field)); } return $getters; }
php
private static function prepareFunctionNames($refMethods) { $fieldNames = explode('.', $refMethods); $getters = []; foreach ($fieldNames as $field) { array_push($getters, 'get'.ucfirst($field)); } return $getters; }
[ "private", "static", "function", "prepareFunctionNames", "(", "$", "refMethods", ")", "{", "$", "fieldNames", "=", "explode", "(", "'.'", ",", "$", "refMethods", ")", ";", "$", "getters", "=", "[", "]", ";", "foreach", "(", "$", "fieldNames", "as", "$", "field", ")", "{", "array_push", "(", "$", "getters", ",", "'get'", ".", "ucfirst", "(", "$", "field", ")", ")", ";", "}", "return", "$", "getters", ";", "}" ]
prepares getter methods for every given field name @param string $refMethods string containing "path" to the ref field @return array
[ "prepares", "getter", "methods", "for", "every", "given", "field", "name" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/ResourceGenerator/XDynamicKey.php#L55-L65
26,535
libgraviton/graviton
src/Graviton/RestBundle/Routing/Loader/BasicLoader.php
BasicLoader.loadService
private function loadService($service, $serviceConfig) { list($app, $bundle, , $entity) = explode('.', $service); $resource = implode('.', array($app, $bundle, 'rest', $entity)); $this->loadReadOnlyRoutes($service, $resource, $serviceConfig); if (!($serviceConfig[0] && array_key_exists('read-only', $serviceConfig[0]))) { $this->loadWriteRoutes($service, $resource, $serviceConfig); } }
php
private function loadService($service, $serviceConfig) { list($app, $bundle, , $entity) = explode('.', $service); $resource = implode('.', array($app, $bundle, 'rest', $entity)); $this->loadReadOnlyRoutes($service, $resource, $serviceConfig); if (!($serviceConfig[0] && array_key_exists('read-only', $serviceConfig[0]))) { $this->loadWriteRoutes($service, $resource, $serviceConfig); } }
[ "private", "function", "loadService", "(", "$", "service", ",", "$", "serviceConfig", ")", "{", "list", "(", "$", "app", ",", "$", "bundle", ",", ",", "$", "entity", ")", "=", "explode", "(", "'.'", ",", "$", "service", ")", ";", "$", "resource", "=", "implode", "(", "'.'", ",", "array", "(", "$", "app", ",", "$", "bundle", ",", "'rest'", ",", "$", "entity", ")", ")", ";", "$", "this", "->", "loadReadOnlyRoutes", "(", "$", "service", ",", "$", "resource", ",", "$", "serviceConfig", ")", ";", "if", "(", "!", "(", "$", "serviceConfig", "[", "0", "]", "&&", "array_key_exists", "(", "'read-only'", ",", "$", "serviceConfig", "[", "0", "]", ")", ")", ")", "{", "$", "this", "->", "loadWriteRoutes", "(", "$", "service", ",", "$", "resource", ",", "$", "serviceConfig", ")", ";", "}", "}" ]
load routes for a single service @param string $service service name @param array $serviceConfig service configuration @return void
[ "load", "routes", "for", "a", "single", "service" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Routing/Loader/BasicLoader.php#L88-L97
26,536
libgraviton/graviton
src/Graviton/RestBundle/Routing/Loader/BasicLoader.php
BasicLoader.loadReadOnlyRoutes
public function loadReadOnlyRoutes($service, $resource, $serviceConfig) { $actionOptions = ActionUtils::getRouteOptions($service, $serviceConfig); $this->routes->add($resource . '.options', $actionOptions); $actionOptionsNoSlash = ActionUtils::getRouteOptions($service, $serviceConfig); $actionOptionsNoSlash->setPath(substr($actionOptionsNoSlash->getPath(), 0, -1)); $this->routes->add($resource . '.optionsNoSlash', $actionOptionsNoSlash); $actionHead = ActionUtils::getRouteHead($service, $serviceConfig); $this->routes->add($resource . '.head', $actionHead); $actionHead = ActionUtils::getRouteHead($service, $serviceConfig, [], true); $this->routes->add($resource . '.idHead', $actionHead); $actionGet = ActionUtils::getRouteGet($service, $serviceConfig); $this->routes->add($resource . '.get', $actionGet); $actionAll = ActionUtils::getRouteAll($service, $serviceConfig); $this->routes->add($resource . '.all', $actionAll); $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig, 'collection'); $this->routes->add($resource . '.canonicalSchema', $actionOptions); $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig, 'collection', true); $this->routes->add($resource . '.canonicalSchemaOptions', $actionOptions); $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig); $this->routes->add($resource . '.canonicalIdSchema', $actionOptions); $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig, 'item', true); $this->routes->add($resource . '.canonicalIdSchemaOptions', $actionOptions); $actionOptions = ActionUtils::getRouteOptions($service, $serviceConfig, [], true); $this->routes->add($resource . '.idOptions', $actionOptions); }
php
public function loadReadOnlyRoutes($service, $resource, $serviceConfig) { $actionOptions = ActionUtils::getRouteOptions($service, $serviceConfig); $this->routes->add($resource . '.options', $actionOptions); $actionOptionsNoSlash = ActionUtils::getRouteOptions($service, $serviceConfig); $actionOptionsNoSlash->setPath(substr($actionOptionsNoSlash->getPath(), 0, -1)); $this->routes->add($resource . '.optionsNoSlash', $actionOptionsNoSlash); $actionHead = ActionUtils::getRouteHead($service, $serviceConfig); $this->routes->add($resource . '.head', $actionHead); $actionHead = ActionUtils::getRouteHead($service, $serviceConfig, [], true); $this->routes->add($resource . '.idHead', $actionHead); $actionGet = ActionUtils::getRouteGet($service, $serviceConfig); $this->routes->add($resource . '.get', $actionGet); $actionAll = ActionUtils::getRouteAll($service, $serviceConfig); $this->routes->add($resource . '.all', $actionAll); $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig, 'collection'); $this->routes->add($resource . '.canonicalSchema', $actionOptions); $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig, 'collection', true); $this->routes->add($resource . '.canonicalSchemaOptions', $actionOptions); $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig); $this->routes->add($resource . '.canonicalIdSchema', $actionOptions); $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig, 'item', true); $this->routes->add($resource . '.canonicalIdSchemaOptions', $actionOptions); $actionOptions = ActionUtils::getRouteOptions($service, $serviceConfig, [], true); $this->routes->add($resource . '.idOptions', $actionOptions); }
[ "public", "function", "loadReadOnlyRoutes", "(", "$", "service", ",", "$", "resource", ",", "$", "serviceConfig", ")", "{", "$", "actionOptions", "=", "ActionUtils", "::", "getRouteOptions", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.options'", ",", "$", "actionOptions", ")", ";", "$", "actionOptionsNoSlash", "=", "ActionUtils", "::", "getRouteOptions", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "actionOptionsNoSlash", "->", "setPath", "(", "substr", "(", "$", "actionOptionsNoSlash", "->", "getPath", "(", ")", ",", "0", ",", "-", "1", ")", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.optionsNoSlash'", ",", "$", "actionOptionsNoSlash", ")", ";", "$", "actionHead", "=", "ActionUtils", "::", "getRouteHead", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.head'", ",", "$", "actionHead", ")", ";", "$", "actionHead", "=", "ActionUtils", "::", "getRouteHead", "(", "$", "service", ",", "$", "serviceConfig", ",", "[", "]", ",", "true", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.idHead'", ",", "$", "actionHead", ")", ";", "$", "actionGet", "=", "ActionUtils", "::", "getRouteGet", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.get'", ",", "$", "actionGet", ")", ";", "$", "actionAll", "=", "ActionUtils", "::", "getRouteAll", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.all'", ",", "$", "actionAll", ")", ";", "$", "actionOptions", "=", "ActionUtils", "::", "getCanonicalSchemaRoute", "(", "$", "service", ",", "$", "serviceConfig", ",", "'collection'", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.canonicalSchema'", ",", "$", "actionOptions", ")", ";", "$", "actionOptions", "=", "ActionUtils", "::", "getCanonicalSchemaRoute", "(", "$", "service", ",", "$", "serviceConfig", ",", "'collection'", ",", "true", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.canonicalSchemaOptions'", ",", "$", "actionOptions", ")", ";", "$", "actionOptions", "=", "ActionUtils", "::", "getCanonicalSchemaRoute", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.canonicalIdSchema'", ",", "$", "actionOptions", ")", ";", "$", "actionOptions", "=", "ActionUtils", "::", "getCanonicalSchemaRoute", "(", "$", "service", ",", "$", "serviceConfig", ",", "'item'", ",", "true", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.canonicalIdSchemaOptions'", ",", "$", "actionOptions", ")", ";", "$", "actionOptions", "=", "ActionUtils", "::", "getRouteOptions", "(", "$", "service", ",", "$", "serviceConfig", ",", "[", "]", ",", "true", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.idOptions'", ",", "$", "actionOptions", ")", ";", "}" ]
generate ro routes @param string $service service name @param string $resource resource name @param array $serviceConfig service configuration @return void
[ "generate", "ro", "routes" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Routing/Loader/BasicLoader.php#L108-L144
26,537
libgraviton/graviton
src/Graviton/RestBundle/Routing/Loader/BasicLoader.php
BasicLoader.loadWriteRoutes
public function loadWriteRoutes($service, $resource, $serviceConfig) { $actionPost = ActionUtils::getRoutePost($service, $serviceConfig); $this->routes->add($resource . '.post', $actionPost); $actionPut = ActionUtils::getRoutePut($service, $serviceConfig); $this->routes->add($resource . '.put', $actionPut); $actionPostNoSlash = ActionUtils::getRoutePost($service, $serviceConfig); $actionPostNoSlash->setPath(substr($actionPostNoSlash->getPath(), 0, -1)); $this->routes->add($resource . '.postNoSlash', $actionPostNoSlash); $actionPatch = ActionUtils::getRoutePatch($service, $serviceConfig); $this->routes->add($resource . '.patch', $actionPatch); $actionDelete = ActionUtils::getRouteDelete($service, $serviceConfig); $this->routes->add($resource . '.delete', $actionDelete); }
php
public function loadWriteRoutes($service, $resource, $serviceConfig) { $actionPost = ActionUtils::getRoutePost($service, $serviceConfig); $this->routes->add($resource . '.post', $actionPost); $actionPut = ActionUtils::getRoutePut($service, $serviceConfig); $this->routes->add($resource . '.put', $actionPut); $actionPostNoSlash = ActionUtils::getRoutePost($service, $serviceConfig); $actionPostNoSlash->setPath(substr($actionPostNoSlash->getPath(), 0, -1)); $this->routes->add($resource . '.postNoSlash', $actionPostNoSlash); $actionPatch = ActionUtils::getRoutePatch($service, $serviceConfig); $this->routes->add($resource . '.patch', $actionPatch); $actionDelete = ActionUtils::getRouteDelete($service, $serviceConfig); $this->routes->add($resource . '.delete', $actionDelete); }
[ "public", "function", "loadWriteRoutes", "(", "$", "service", ",", "$", "resource", ",", "$", "serviceConfig", ")", "{", "$", "actionPost", "=", "ActionUtils", "::", "getRoutePost", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.post'", ",", "$", "actionPost", ")", ";", "$", "actionPut", "=", "ActionUtils", "::", "getRoutePut", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.put'", ",", "$", "actionPut", ")", ";", "$", "actionPostNoSlash", "=", "ActionUtils", "::", "getRoutePost", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "actionPostNoSlash", "->", "setPath", "(", "substr", "(", "$", "actionPostNoSlash", "->", "getPath", "(", ")", ",", "0", ",", "-", "1", ")", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.postNoSlash'", ",", "$", "actionPostNoSlash", ")", ";", "$", "actionPatch", "=", "ActionUtils", "::", "getRoutePatch", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.patch'", ",", "$", "actionPatch", ")", ";", "$", "actionDelete", "=", "ActionUtils", "::", "getRouteDelete", "(", "$", "service", ",", "$", "serviceConfig", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "resource", ".", "'.delete'", ",", "$", "actionDelete", ")", ";", "}" ]
generate write routes @param string $service service name @param string $resource resource name @param array $serviceConfig service configuration @return void
[ "generate", "write", "routes" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Routing/Loader/BasicLoader.php#L155-L172
26,538
libgraviton/graviton
src/Graviton/GeneratorBundle/Definition/JsonDefinitionField.php
JsonDefinitionField.getTypeDoctrine
public function getTypeDoctrine() { if (isset(self::$doctrineTypeMap[$this->getType()])) { return self::$doctrineTypeMap[$this->getType()]; } // our fallback default return self::$doctrineTypeMap[self::TYPE_STRING]; }
php
public function getTypeDoctrine() { if (isset(self::$doctrineTypeMap[$this->getType()])) { return self::$doctrineTypeMap[$this->getType()]; } // our fallback default return self::$doctrineTypeMap[self::TYPE_STRING]; }
[ "public", "function", "getTypeDoctrine", "(", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "doctrineTypeMap", "[", "$", "this", "->", "getType", "(", ")", "]", ")", ")", "{", "return", "self", "::", "$", "doctrineTypeMap", "[", "$", "this", "->", "getType", "(", ")", "]", ";", "}", "// our fallback default", "return", "self", "::", "$", "doctrineTypeMap", "[", "self", "::", "TYPE_STRING", "]", ";", "}" ]
Returns the field type in a doctrine-understandable way.. @return string Type
[ "Returns", "the", "field", "type", "in", "a", "doctrine", "-", "understandable", "way", ".." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinitionField.php#L138-L146
26,539
libgraviton/graviton
src/Graviton/GeneratorBundle/Definition/JsonDefinitionField.php
JsonDefinitionField.getType
public function getType() { if ($this->definition->getTranslatable()) { return self::TYPE_TRANSLATABLE; } return strtolower($this->definition->getType()); }
php
public function getType() { if ($this->definition->getTranslatable()) { return self::TYPE_TRANSLATABLE; } return strtolower($this->definition->getType()); }
[ "public", "function", "getType", "(", ")", "{", "if", "(", "$", "this", "->", "definition", "->", "getTranslatable", "(", ")", ")", "{", "return", "self", "::", "TYPE_TRANSLATABLE", ";", "}", "return", "strtolower", "(", "$", "this", "->", "definition", "->", "getType", "(", ")", ")", ";", "}" ]
Returns the field type @return string Type
[ "Returns", "the", "field", "type" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinitionField.php#L153-L159
26,540
libgraviton/graviton
src/Graviton/DocumentBundle/Listener/RqlSearchNodeListener.php
RqlSearchNodeListener.onVisitNode
public function onVisitNode(VisitNodeEvent $event) { // any search? if (!$event->getNode() instanceof SearchNode || $event->getNode()->isVisited()) { return $event; } $this->node = $event->getNode(); $this->builder = $event->getBuilder(); $this->expr = $event->isExpr(); $this->className = $event->getClassName(); // which mode? if ($this->getSearchMode() === self::SEARCHMODE_SOLR) { $this->handleSearchSolr(); } else { $this->handleSearchMongo(); } $event->setBuilder($this->builder); $event->setNode($this->node); $event->setExprNode($this->exprNode); return $event; }
php
public function onVisitNode(VisitNodeEvent $event) { // any search? if (!$event->getNode() instanceof SearchNode || $event->getNode()->isVisited()) { return $event; } $this->node = $event->getNode(); $this->builder = $event->getBuilder(); $this->expr = $event->isExpr(); $this->className = $event->getClassName(); // which mode? if ($this->getSearchMode() === self::SEARCHMODE_SOLR) { $this->handleSearchSolr(); } else { $this->handleSearchMongo(); } $event->setBuilder($this->builder); $event->setNode($this->node); $event->setExprNode($this->exprNode); return $event; }
[ "public", "function", "onVisitNode", "(", "VisitNodeEvent", "$", "event", ")", "{", "// any search?", "if", "(", "!", "$", "event", "->", "getNode", "(", ")", "instanceof", "SearchNode", "||", "$", "event", "->", "getNode", "(", ")", "->", "isVisited", "(", ")", ")", "{", "return", "$", "event", ";", "}", "$", "this", "->", "node", "=", "$", "event", "->", "getNode", "(", ")", ";", "$", "this", "->", "builder", "=", "$", "event", "->", "getBuilder", "(", ")", ";", "$", "this", "->", "expr", "=", "$", "event", "->", "isExpr", "(", ")", ";", "$", "this", "->", "className", "=", "$", "event", "->", "getClassName", "(", ")", ";", "// which mode?", "if", "(", "$", "this", "->", "getSearchMode", "(", ")", "===", "self", "::", "SEARCHMODE_SOLR", ")", "{", "$", "this", "->", "handleSearchSolr", "(", ")", ";", "}", "else", "{", "$", "this", "->", "handleSearchMongo", "(", ")", ";", "}", "$", "event", "->", "setBuilder", "(", "$", "this", "->", "builder", ")", ";", "$", "event", "->", "setNode", "(", "$", "this", "->", "node", ")", ";", "$", "event", "->", "setExprNode", "(", "$", "this", "->", "exprNode", ")", ";", "return", "$", "event", ";", "}" ]
gets called during the visit of a normal search node @param VisitNodeEvent $event node event to visit @return VisitNodeEvent event object
[ "gets", "called", "during", "the", "visit", "of", "a", "normal", "search", "node" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Listener/RqlSearchNodeListener.php#L89-L113
26,541
libgraviton/graviton
src/Graviton/DocumentBundle/Listener/RqlSearchNodeListener.php
RqlSearchNodeListener.getSearchMode
private function getSearchMode() { $this->solrQuery->setClassName($this->className); if ($this->solrQuery->isConfigured()) { return self::SEARCHMODE_SOLR; } return self::SEARCHMODE_MONGO; }
php
private function getSearchMode() { $this->solrQuery->setClassName($this->className); if ($this->solrQuery->isConfigured()) { return self::SEARCHMODE_SOLR; } return self::SEARCHMODE_MONGO; }
[ "private", "function", "getSearchMode", "(", ")", "{", "$", "this", "->", "solrQuery", "->", "setClassName", "(", "$", "this", "->", "className", ")", ";", "if", "(", "$", "this", "->", "solrQuery", "->", "isConfigured", "(", ")", ")", "{", "return", "self", "::", "SEARCHMODE_SOLR", ";", "}", "return", "self", "::", "SEARCHMODE_MONGO", ";", "}" ]
returns which search backend to use @return string search mode constant
[ "returns", "which", "search", "backend", "to", "use" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Listener/RqlSearchNodeListener.php#L211-L219
26,542
libgraviton/graviton
src/Graviton/GeneratorBundle/Generator/BundleGenerator.php
BundleGenerator.generate
public function generate($namespace, $bundle, $dir, $format) { $dir .= '/' . strtr($namespace, '\\', '/'); // make sure we have no trailing \ in namespace if (substr($namespace, -1) == '\\') { $namespace = substr($namespace, 0, -1); } $basename = $this->getBundleBaseName($bundle); $parameters = array( 'namespace' => $namespace, 'bundle' => $bundle, 'format' => $format, 'bundle_basename' => $basename, 'extension_alias' => Container::underscore($basename), ); $this->renderFile('bundle/Bundle.php.twig', $dir . '/' . $bundle . '.php', $parameters); $this->renderFile( 'bundle/Extension.php.twig', $dir . '/DependencyInjection/' . $basename . 'Extension.php', $parameters ); $this->renderFile('bundle/config.xml.twig', $dir . '/Resources/config/config.xml', $parameters); if ('xml' === $format || 'annotation' === $format) { $this->renderFile('bundle/services.xml.twig', $dir . '/Resources/config/services.xml', $parameters); } else { $this->renderFile( 'bundle/services.' . $format . '.twig', $dir . '/Resources/config/services.' . $format, $parameters ); } if ('annotation' != $format) { $this->renderFile( 'bundle/routing.' . $format . '.twig', $dir . '/Resources/config/routing.' . $format, $parameters ); } }
php
public function generate($namespace, $bundle, $dir, $format) { $dir .= '/' . strtr($namespace, '\\', '/'); // make sure we have no trailing \ in namespace if (substr($namespace, -1) == '\\') { $namespace = substr($namespace, 0, -1); } $basename = $this->getBundleBaseName($bundle); $parameters = array( 'namespace' => $namespace, 'bundle' => $bundle, 'format' => $format, 'bundle_basename' => $basename, 'extension_alias' => Container::underscore($basename), ); $this->renderFile('bundle/Bundle.php.twig', $dir . '/' . $bundle . '.php', $parameters); $this->renderFile( 'bundle/Extension.php.twig', $dir . '/DependencyInjection/' . $basename . 'Extension.php', $parameters ); $this->renderFile('bundle/config.xml.twig', $dir . '/Resources/config/config.xml', $parameters); if ('xml' === $format || 'annotation' === $format) { $this->renderFile('bundle/services.xml.twig', $dir . '/Resources/config/services.xml', $parameters); } else { $this->renderFile( 'bundle/services.' . $format . '.twig', $dir . '/Resources/config/services.' . $format, $parameters ); } if ('annotation' != $format) { $this->renderFile( 'bundle/routing.' . $format . '.twig', $dir . '/Resources/config/routing.' . $format, $parameters ); } }
[ "public", "function", "generate", "(", "$", "namespace", ",", "$", "bundle", ",", "$", "dir", ",", "$", "format", ")", "{", "$", "dir", ".=", "'/'", ".", "strtr", "(", "$", "namespace", ",", "'\\\\'", ",", "'/'", ")", ";", "// make sure we have no trailing \\ in namespace", "if", "(", "substr", "(", "$", "namespace", ",", "-", "1", ")", "==", "'\\\\'", ")", "{", "$", "namespace", "=", "substr", "(", "$", "namespace", ",", "0", ",", "-", "1", ")", ";", "}", "$", "basename", "=", "$", "this", "->", "getBundleBaseName", "(", "$", "bundle", ")", ";", "$", "parameters", "=", "array", "(", "'namespace'", "=>", "$", "namespace", ",", "'bundle'", "=>", "$", "bundle", ",", "'format'", "=>", "$", "format", ",", "'bundle_basename'", "=>", "$", "basename", ",", "'extension_alias'", "=>", "Container", "::", "underscore", "(", "$", "basename", ")", ",", ")", ";", "$", "this", "->", "renderFile", "(", "'bundle/Bundle.php.twig'", ",", "$", "dir", ".", "'/'", ".", "$", "bundle", ".", "'.php'", ",", "$", "parameters", ")", ";", "$", "this", "->", "renderFile", "(", "'bundle/Extension.php.twig'", ",", "$", "dir", ".", "'/DependencyInjection/'", ".", "$", "basename", ".", "'Extension.php'", ",", "$", "parameters", ")", ";", "$", "this", "->", "renderFile", "(", "'bundle/config.xml.twig'", ",", "$", "dir", ".", "'/Resources/config/config.xml'", ",", "$", "parameters", ")", ";", "if", "(", "'xml'", "===", "$", "format", "||", "'annotation'", "===", "$", "format", ")", "{", "$", "this", "->", "renderFile", "(", "'bundle/services.xml.twig'", ",", "$", "dir", ".", "'/Resources/config/services.xml'", ",", "$", "parameters", ")", ";", "}", "else", "{", "$", "this", "->", "renderFile", "(", "'bundle/services.'", ".", "$", "format", ".", "'.twig'", ",", "$", "dir", ".", "'/Resources/config/services.'", ".", "$", "format", ",", "$", "parameters", ")", ";", "}", "if", "(", "'annotation'", "!=", "$", "format", ")", "{", "$", "this", "->", "renderFile", "(", "'bundle/routing.'", ".", "$", "format", ".", "'.twig'", ",", "$", "dir", ".", "'/Resources/config/routing.'", ".", "$", "format", ",", "$", "parameters", ")", ";", "}", "}" ]
generate bundle code @param string $namespace namspace name @param string $bundle bundle name @param string $dir bundle dir @param string $format bundle condfig file format @return void
[ "generate", "bundle", "code" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/BundleGenerator.php#L35-L79
26,543
libgraviton/graviton
src/Graviton/DocumentBundle/DependencyInjection/Compiler/SolrDefinitionCompilerPass.php
SolrDefinitionCompilerPass.process
public function process(ContainerBuilder $container) { $this->documentMap = $container->get('graviton.document.map'); $map = []; foreach ($this->documentMap->getDocuments() as $document) { $solrFields = $document->getSolrFields(); if (is_array($solrFields) && !empty($solrFields)) { $map[$document->getClass()] = $this->getSolrWeightString($solrFields); } } $container->setParameter('graviton.document.solr.map', $map); }
php
public function process(ContainerBuilder $container) { $this->documentMap = $container->get('graviton.document.map'); $map = []; foreach ($this->documentMap->getDocuments() as $document) { $solrFields = $document->getSolrFields(); if (is_array($solrFields) && !empty($solrFields)) { $map[$document->getClass()] = $this->getSolrWeightString($solrFields); } } $container->setParameter('graviton.document.solr.map', $map); }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "this", "->", "documentMap", "=", "$", "container", "->", "get", "(", "'graviton.document.map'", ")", ";", "$", "map", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "documentMap", "->", "getDocuments", "(", ")", "as", "$", "document", ")", "{", "$", "solrFields", "=", "$", "document", "->", "getSolrFields", "(", ")", ";", "if", "(", "is_array", "(", "$", "solrFields", ")", "&&", "!", "empty", "(", "$", "solrFields", ")", ")", "{", "$", "map", "[", "$", "document", "->", "getClass", "(", ")", "]", "=", "$", "this", "->", "getSolrWeightString", "(", "$", "solrFields", ")", ";", "}", "}", "$", "container", "->", "setParameter", "(", "'graviton.document.solr.map'", ",", "$", "map", ")", ";", "}" ]
map with the weight string incorporated @param ContainerBuilder $container container builder @return void
[ "map", "with", "the", "weight", "string", "incorporated" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/SolrDefinitionCompilerPass.php#L30-L43
26,544
libgraviton/graviton
src/Graviton/DocumentBundle/DependencyInjection/Compiler/SolrDefinitionCompilerPass.php
SolrDefinitionCompilerPass.getSolrWeightString
private function getSolrWeightString(array $solrFields) { $weights = []; foreach ($solrFields as $field) { $weights[] = $field['name'].'^'.$field['weight']; } return implode(' ', $weights); }
php
private function getSolrWeightString(array $solrFields) { $weights = []; foreach ($solrFields as $field) { $weights[] = $field['name'].'^'.$field['weight']; } return implode(' ', $weights); }
[ "private", "function", "getSolrWeightString", "(", "array", "$", "solrFields", ")", "{", "$", "weights", "=", "[", "]", ";", "foreach", "(", "$", "solrFields", "as", "$", "field", ")", "{", "$", "weights", "[", "]", "=", "$", "field", "[", "'name'", "]", ".", "'^'", ".", "$", "field", "[", "'weight'", "]", ";", "}", "return", "implode", "(", "' '", ",", "$", "weights", ")", ";", "}" ]
Returns the solr weight string @param array $solrFields fields @return string weight string
[ "Returns", "the", "solr", "weight", "string" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/SolrDefinitionCompilerPass.php#L52-L60
26,545
libgraviton/graviton
src/Graviton/CoreBundle/Listener/RequestHostListener.php
RequestHostListener.onKernelRequest
public function onKernelRequest() { if (!is_null($this->host)) { $this->router->getContext()->setHost($this->host); } if (!is_null($this->portHttp)) { $this->router->getContext()->setHttpPort($this->portHttp); } if (!is_null($this->portHttps)) { $this->router->getContext()->setHttpsPort($this->portHttps); } }
php
public function onKernelRequest() { if (!is_null($this->host)) { $this->router->getContext()->setHost($this->host); } if (!is_null($this->portHttp)) { $this->router->getContext()->setHttpPort($this->portHttp); } if (!is_null($this->portHttps)) { $this->router->getContext()->setHttpsPort($this->portHttps); } }
[ "public", "function", "onKernelRequest", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "host", ")", ")", "{", "$", "this", "->", "router", "->", "getContext", "(", ")", "->", "setHost", "(", "$", "this", "->", "host", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "this", "->", "portHttp", ")", ")", "{", "$", "this", "->", "router", "->", "getContext", "(", ")", "->", "setHttpPort", "(", "$", "this", "->", "portHttp", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "this", "->", "portHttps", ")", ")", "{", "$", "this", "->", "router", "->", "getContext", "(", ")", "->", "setHttpsPort", "(", "$", "this", "->", "portHttps", ")", ";", "}", "}" ]
modify the router context params if configured @return void
[ "modify", "the", "router", "context", "params", "if", "configured" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/CoreBundle/Listener/RequestHostListener.php#L68-L81
26,546
libgraviton/graviton
src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php
ResourceGenerator.generate
public function generate( $bundleDir, $bundleNamespace, $bundleName, $document ) { $this->readServicesAndParams($bundleDir); $basename = $this->getBundleBaseName($document); if (!is_null($this->json)) { $this->json->setNamespace($bundleNamespace); } // add more info to the fields array $mapper = $this->mapper; $fields = array_map( function ($field) use ($mapper) { return $mapper->map($field, $this->json); }, $this->mapper->buildFields($this->json) ); $parameters = $this->parameterBuilder ->reset() ->setParameter('document', $document) ->setParameter('base', $bundleNamespace) ->setParameter('bundle', $bundleName) ->setParameter('json', $this->json) ->setParameter('fields', $fields) ->setParameter('basename', $basename) ->setParameter('isrecordOriginFlagSet', $this->json->isRecordOriginFlagSet()) ->setParameter('recordOriginModifiable', $this->json->isRecordOriginModifiable()) ->setParameter('isVersioning', $this->json->isVersionedService()) ->setParameter('collection', $this->json->getServiceCollection()) ->setParameter('indexes', $this->json->getIndexes()) ->setParameter('textIndexes', $this->json->getAllTextIndexes()) ->setParameter('solrFields', $this->json->getSolrFields()) ->setParameter('solrAggregate', $this->json->getSolrAggregate()) ->getParameters(); $this->generateDocument($parameters, $bundleDir, $document); $this->generateSerializer($parameters, $bundleDir, $document); $this->generateModel($parameters, $bundleDir, $document); if ($this->json instanceof JsonDefinition && $this->json->hasFixtures() === true) { $this->generateFixtures($parameters, $bundleDir, $document); } if ($this->generateController) { $this->generateController($parameters, $bundleDir, $document); } $this->persistServicesAndParams(); }
php
public function generate( $bundleDir, $bundleNamespace, $bundleName, $document ) { $this->readServicesAndParams($bundleDir); $basename = $this->getBundleBaseName($document); if (!is_null($this->json)) { $this->json->setNamespace($bundleNamespace); } // add more info to the fields array $mapper = $this->mapper; $fields = array_map( function ($field) use ($mapper) { return $mapper->map($field, $this->json); }, $this->mapper->buildFields($this->json) ); $parameters = $this->parameterBuilder ->reset() ->setParameter('document', $document) ->setParameter('base', $bundleNamespace) ->setParameter('bundle', $bundleName) ->setParameter('json', $this->json) ->setParameter('fields', $fields) ->setParameter('basename', $basename) ->setParameter('isrecordOriginFlagSet', $this->json->isRecordOriginFlagSet()) ->setParameter('recordOriginModifiable', $this->json->isRecordOriginModifiable()) ->setParameter('isVersioning', $this->json->isVersionedService()) ->setParameter('collection', $this->json->getServiceCollection()) ->setParameter('indexes', $this->json->getIndexes()) ->setParameter('textIndexes', $this->json->getAllTextIndexes()) ->setParameter('solrFields', $this->json->getSolrFields()) ->setParameter('solrAggregate', $this->json->getSolrAggregate()) ->getParameters(); $this->generateDocument($parameters, $bundleDir, $document); $this->generateSerializer($parameters, $bundleDir, $document); $this->generateModel($parameters, $bundleDir, $document); if ($this->json instanceof JsonDefinition && $this->json->hasFixtures() === true) { $this->generateFixtures($parameters, $bundleDir, $document); } if ($this->generateController) { $this->generateController($parameters, $bundleDir, $document); } $this->persistServicesAndParams(); }
[ "public", "function", "generate", "(", "$", "bundleDir", ",", "$", "bundleNamespace", ",", "$", "bundleName", ",", "$", "document", ")", "{", "$", "this", "->", "readServicesAndParams", "(", "$", "bundleDir", ")", ";", "$", "basename", "=", "$", "this", "->", "getBundleBaseName", "(", "$", "document", ")", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "json", ")", ")", "{", "$", "this", "->", "json", "->", "setNamespace", "(", "$", "bundleNamespace", ")", ";", "}", "// add more info to the fields array", "$", "mapper", "=", "$", "this", "->", "mapper", ";", "$", "fields", "=", "array_map", "(", "function", "(", "$", "field", ")", "use", "(", "$", "mapper", ")", "{", "return", "$", "mapper", "->", "map", "(", "$", "field", ",", "$", "this", "->", "json", ")", ";", "}", ",", "$", "this", "->", "mapper", "->", "buildFields", "(", "$", "this", "->", "json", ")", ")", ";", "$", "parameters", "=", "$", "this", "->", "parameterBuilder", "->", "reset", "(", ")", "->", "setParameter", "(", "'document'", ",", "$", "document", ")", "->", "setParameter", "(", "'base'", ",", "$", "bundleNamespace", ")", "->", "setParameter", "(", "'bundle'", ",", "$", "bundleName", ")", "->", "setParameter", "(", "'json'", ",", "$", "this", "->", "json", ")", "->", "setParameter", "(", "'fields'", ",", "$", "fields", ")", "->", "setParameter", "(", "'basename'", ",", "$", "basename", ")", "->", "setParameter", "(", "'isrecordOriginFlagSet'", ",", "$", "this", "->", "json", "->", "isRecordOriginFlagSet", "(", ")", ")", "->", "setParameter", "(", "'recordOriginModifiable'", ",", "$", "this", "->", "json", "->", "isRecordOriginModifiable", "(", ")", ")", "->", "setParameter", "(", "'isVersioning'", ",", "$", "this", "->", "json", "->", "isVersionedService", "(", ")", ")", "->", "setParameter", "(", "'collection'", ",", "$", "this", "->", "json", "->", "getServiceCollection", "(", ")", ")", "->", "setParameter", "(", "'indexes'", ",", "$", "this", "->", "json", "->", "getIndexes", "(", ")", ")", "->", "setParameter", "(", "'textIndexes'", ",", "$", "this", "->", "json", "->", "getAllTextIndexes", "(", ")", ")", "->", "setParameter", "(", "'solrFields'", ",", "$", "this", "->", "json", "->", "getSolrFields", "(", ")", ")", "->", "setParameter", "(", "'solrAggregate'", ",", "$", "this", "->", "json", "->", "getSolrAggregate", "(", ")", ")", "->", "getParameters", "(", ")", ";", "$", "this", "->", "generateDocument", "(", "$", "parameters", ",", "$", "bundleDir", ",", "$", "document", ")", ";", "$", "this", "->", "generateSerializer", "(", "$", "parameters", ",", "$", "bundleDir", ",", "$", "document", ")", ";", "$", "this", "->", "generateModel", "(", "$", "parameters", ",", "$", "bundleDir", ",", "$", "document", ")", ";", "if", "(", "$", "this", "->", "json", "instanceof", "JsonDefinition", "&&", "$", "this", "->", "json", "->", "hasFixtures", "(", ")", "===", "true", ")", "{", "$", "this", "->", "generateFixtures", "(", "$", "parameters", ",", "$", "bundleDir", ",", "$", "document", ")", ";", "}", "if", "(", "$", "this", "->", "generateController", ")", "{", "$", "this", "->", "generateController", "(", "$", "parameters", ",", "$", "bundleDir", ",", "$", "document", ")", ";", "}", "$", "this", "->", "persistServicesAndParams", "(", ")", ";", "}" ]
generate the resource with all its bits and parts @param string $bundleDir bundle dir @param string $bundleNamespace bundle namespace @param string $bundleName bundle name @param string $document document name @return void
[ "generate", "the", "resource", "with", "all", "its", "bits", "and", "parts" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php#L123-L177
26,547
libgraviton/graviton
src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php
ResourceGenerator.readServicesAndParams
protected function readServicesAndParams($bundleDir) { $this->servicesFile = $bundleDir.'/Resources/config/services.yml'; if ($this->fs->exists($this->servicesFile)) { $this->services = Yaml::parseFile($this->servicesFile); } if (!isset($this->services['services'])) { $this->services['services'] = []; } if (isset($this->services['parameters'])) { $this->parameters['parameters'] = $this->services['parameters']; unset($this->services['parameters']); } else { $this->parameters['parameters'] = []; } }
php
protected function readServicesAndParams($bundleDir) { $this->servicesFile = $bundleDir.'/Resources/config/services.yml'; if ($this->fs->exists($this->servicesFile)) { $this->services = Yaml::parseFile($this->servicesFile); } if (!isset($this->services['services'])) { $this->services['services'] = []; } if (isset($this->services['parameters'])) { $this->parameters['parameters'] = $this->services['parameters']; unset($this->services['parameters']); } else { $this->parameters['parameters'] = []; } }
[ "protected", "function", "readServicesAndParams", "(", "$", "bundleDir", ")", "{", "$", "this", "->", "servicesFile", "=", "$", "bundleDir", ".", "'/Resources/config/services.yml'", ";", "if", "(", "$", "this", "->", "fs", "->", "exists", "(", "$", "this", "->", "servicesFile", ")", ")", "{", "$", "this", "->", "services", "=", "Yaml", "::", "parseFile", "(", "$", "this", "->", "servicesFile", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "services", "[", "'services'", "]", ")", ")", "{", "$", "this", "->", "services", "[", "'services'", "]", "=", "[", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "services", "[", "'parameters'", "]", ")", ")", "{", "$", "this", "->", "parameters", "[", "'parameters'", "]", "=", "$", "this", "->", "services", "[", "'parameters'", "]", ";", "unset", "(", "$", "this", "->", "services", "[", "'parameters'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "parameters", "[", "'parameters'", "]", "=", "[", "]", ";", "}", "}" ]
reads the services.yml file @param string $bundleDir bundle dir @return void
[ "reads", "the", "services", ".", "yml", "file" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php#L186-L203
26,548
libgraviton/graviton
src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php
ResourceGenerator.persistServicesAndParams
protected function persistServicesAndParams() { $this->filesystem->dumpFile( $this->servicesFile, Yaml::dump(array_merge($this->parameters, $this->services)) ); }
php
protected function persistServicesAndParams() { $this->filesystem->dumpFile( $this->servicesFile, Yaml::dump(array_merge($this->parameters, $this->services)) ); }
[ "protected", "function", "persistServicesAndParams", "(", ")", "{", "$", "this", "->", "filesystem", "->", "dumpFile", "(", "$", "this", "->", "servicesFile", ",", "Yaml", "::", "dump", "(", "array_merge", "(", "$", "this", "->", "parameters", ",", "$", "this", "->", "services", ")", ")", ")", ";", "}" ]
writes the services.yml file which includes the params @return void
[ "writes", "the", "services", ".", "yml", "file", "which", "includes", "the", "params" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php#L210-L216
26,549
libgraviton/graviton
src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php
ResourceGenerator.generateDocument
protected function generateDocument($parameters, $dir, $document) { // doctrine mapping normal class $this->renderFile( 'document/Document.mongodb.yml.twig', $dir . '/Resources/config/doctrine/' . $document . '.mongodb.yml', $parameters ); // doctrine mapping embedded $this->renderFile( 'document/Document.mongodb.yml.twig', $dir . '/Resources/config/doctrine/' . $document . 'Embedded.mongodb.yml', array_merge( $parameters, [ 'document' => $document.'Embedded', 'docType' => 'embeddedDocument' ] ) ); $this->renderFile( 'document/Document.php.twig', $dir . '/Document/' . $document . '.php', $parameters ); $this->renderFile( 'document/DocumentEmbedded.php.twig', $dir . '/Document/' . $document . 'Embedded.php', $parameters ); $this->renderFile( 'document/DocumentBase.php.twig', $dir . '/Document/' . $document . 'Base.php', $parameters ); $this->generateServices($parameters, $dir, $document); }
php
protected function generateDocument($parameters, $dir, $document) { // doctrine mapping normal class $this->renderFile( 'document/Document.mongodb.yml.twig', $dir . '/Resources/config/doctrine/' . $document . '.mongodb.yml', $parameters ); // doctrine mapping embedded $this->renderFile( 'document/Document.mongodb.yml.twig', $dir . '/Resources/config/doctrine/' . $document . 'Embedded.mongodb.yml', array_merge( $parameters, [ 'document' => $document.'Embedded', 'docType' => 'embeddedDocument' ] ) ); $this->renderFile( 'document/Document.php.twig', $dir . '/Document/' . $document . '.php', $parameters ); $this->renderFile( 'document/DocumentEmbedded.php.twig', $dir . '/Document/' . $document . 'Embedded.php', $parameters ); $this->renderFile( 'document/DocumentBase.php.twig', $dir . '/Document/' . $document . 'Base.php', $parameters ); $this->generateServices($parameters, $dir, $document); }
[ "protected", "function", "generateDocument", "(", "$", "parameters", ",", "$", "dir", ",", "$", "document", ")", "{", "// doctrine mapping normal class", "$", "this", "->", "renderFile", "(", "'document/Document.mongodb.yml.twig'", ",", "$", "dir", ".", "'/Resources/config/doctrine/'", ".", "$", "document", ".", "'.mongodb.yml'", ",", "$", "parameters", ")", ";", "// doctrine mapping embedded", "$", "this", "->", "renderFile", "(", "'document/Document.mongodb.yml.twig'", ",", "$", "dir", ".", "'/Resources/config/doctrine/'", ".", "$", "document", ".", "'Embedded.mongodb.yml'", ",", "array_merge", "(", "$", "parameters", ",", "[", "'document'", "=>", "$", "document", ".", "'Embedded'", ",", "'docType'", "=>", "'embeddedDocument'", "]", ")", ")", ";", "$", "this", "->", "renderFile", "(", "'document/Document.php.twig'", ",", "$", "dir", ".", "'/Document/'", ".", "$", "document", ".", "'.php'", ",", "$", "parameters", ")", ";", "$", "this", "->", "renderFile", "(", "'document/DocumentEmbedded.php.twig'", ",", "$", "dir", ".", "'/Document/'", ".", "$", "document", ".", "'Embedded.php'", ",", "$", "parameters", ")", ";", "$", "this", "->", "renderFile", "(", "'document/DocumentBase.php.twig'", ",", "$", "dir", ".", "'/Document/'", ".", "$", "document", ".", "'Base.php'", ",", "$", "parameters", ")", ";", "$", "this", "->", "generateServices", "(", "$", "parameters", ",", "$", "dir", ",", "$", "document", ")", ";", "}" ]
generate document part of a resource @param array $parameters twig parameters @param string $dir base bundle dir @param string $document document name @return void
[ "generate", "document", "part", "of", "a", "resource" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php#L227-L266
26,550
libgraviton/graviton
src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php
ResourceGenerator.generateServices
protected function generateServices($parameters, $dir, $document) { $bundleParts = explode('\\', $parameters['base']); $shortName = $bundleParts[0]; $shortBundle = $this->getBundleBaseName($bundleParts[1]); $docName = implode( '.', array( strtolower($shortName), strtolower($shortBundle), 'document', strtolower($parameters['document']) ) ); $this->addParameter( $parameters['base'] . 'Document\\' . $parameters['document'], $docName . '.class' ); $this->addService( $docName, null, [], null, [], null, null, '%'. $docName . '.class%' ); $this->addParameter( (array) $parameters['json']->getRoles(), $docName . '.roles' ); $repoName = implode( '.', array( strtolower($shortName), strtolower($shortBundle), 'repository', strtolower($parameters['document']) ) ); $this->addService( $repoName, null, [], null, array( array( 'type' => 'string', 'value' => $parameters['bundle'] . ':' . $document ) ), 'doctrine_mongodb.odm.default_document_manager', 'getRepository', 'Doctrine\ODM\MongoDB\DocumentRepository' ); $this->addService( $repoName . 'embedded', null, [], null, array( array( 'type' => 'string', 'value' => $parameters['bundle'] . ':' . $document . 'Embedded' ) ), 'doctrine_mongodb.odm.default_document_manager', 'getRepository', 'Doctrine\ODM\MongoDB\DocumentRepository' ); }
php
protected function generateServices($parameters, $dir, $document) { $bundleParts = explode('\\', $parameters['base']); $shortName = $bundleParts[0]; $shortBundle = $this->getBundleBaseName($bundleParts[1]); $docName = implode( '.', array( strtolower($shortName), strtolower($shortBundle), 'document', strtolower($parameters['document']) ) ); $this->addParameter( $parameters['base'] . 'Document\\' . $parameters['document'], $docName . '.class' ); $this->addService( $docName, null, [], null, [], null, null, '%'. $docName . '.class%' ); $this->addParameter( (array) $parameters['json']->getRoles(), $docName . '.roles' ); $repoName = implode( '.', array( strtolower($shortName), strtolower($shortBundle), 'repository', strtolower($parameters['document']) ) ); $this->addService( $repoName, null, [], null, array( array( 'type' => 'string', 'value' => $parameters['bundle'] . ':' . $document ) ), 'doctrine_mongodb.odm.default_document_manager', 'getRepository', 'Doctrine\ODM\MongoDB\DocumentRepository' ); $this->addService( $repoName . 'embedded', null, [], null, array( array( 'type' => 'string', 'value' => $parameters['bundle'] . ':' . $document . 'Embedded' ) ), 'doctrine_mongodb.odm.default_document_manager', 'getRepository', 'Doctrine\ODM\MongoDB\DocumentRepository' ); }
[ "protected", "function", "generateServices", "(", "$", "parameters", ",", "$", "dir", ",", "$", "document", ")", "{", "$", "bundleParts", "=", "explode", "(", "'\\\\'", ",", "$", "parameters", "[", "'base'", "]", ")", ";", "$", "shortName", "=", "$", "bundleParts", "[", "0", "]", ";", "$", "shortBundle", "=", "$", "this", "->", "getBundleBaseName", "(", "$", "bundleParts", "[", "1", "]", ")", ";", "$", "docName", "=", "implode", "(", "'.'", ",", "array", "(", "strtolower", "(", "$", "shortName", ")", ",", "strtolower", "(", "$", "shortBundle", ")", ",", "'document'", ",", "strtolower", "(", "$", "parameters", "[", "'document'", "]", ")", ")", ")", ";", "$", "this", "->", "addParameter", "(", "$", "parameters", "[", "'base'", "]", ".", "'Document\\\\'", ".", "$", "parameters", "[", "'document'", "]", ",", "$", "docName", ".", "'.class'", ")", ";", "$", "this", "->", "addService", "(", "$", "docName", ",", "null", ",", "[", "]", ",", "null", ",", "[", "]", ",", "null", ",", "null", ",", "'%'", ".", "$", "docName", ".", "'.class%'", ")", ";", "$", "this", "->", "addParameter", "(", "(", "array", ")", "$", "parameters", "[", "'json'", "]", "->", "getRoles", "(", ")", ",", "$", "docName", ".", "'.roles'", ")", ";", "$", "repoName", "=", "implode", "(", "'.'", ",", "array", "(", "strtolower", "(", "$", "shortName", ")", ",", "strtolower", "(", "$", "shortBundle", ")", ",", "'repository'", ",", "strtolower", "(", "$", "parameters", "[", "'document'", "]", ")", ")", ")", ";", "$", "this", "->", "addService", "(", "$", "repoName", ",", "null", ",", "[", "]", ",", "null", ",", "array", "(", "array", "(", "'type'", "=>", "'string'", ",", "'value'", "=>", "$", "parameters", "[", "'bundle'", "]", ".", "':'", ".", "$", "document", ")", ")", ",", "'doctrine_mongodb.odm.default_document_manager'", ",", "'getRepository'", ",", "'Doctrine\\ODM\\MongoDB\\DocumentRepository'", ")", ";", "$", "this", "->", "addService", "(", "$", "repoName", ".", "'embedded'", ",", "null", ",", "[", "]", ",", "null", ",", "array", "(", "array", "(", "'type'", "=>", "'string'", ",", "'value'", "=>", "$", "parameters", "[", "'bundle'", "]", ".", "':'", ".", "$", "document", ".", "'Embedded'", ")", ")", ",", "'doctrine_mongodb.odm.default_document_manager'", ",", "'getRepository'", ",", "'Doctrine\\ODM\\MongoDB\\DocumentRepository'", ")", ";", "}" ]
update xml services @param array $parameters twig parameters @param string $dir base bundle dir @param string $document document name @return void
[ "update", "xml", "services" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php#L277-L355
26,551
libgraviton/graviton
src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php
ResourceGenerator.addService
protected function addService( $id, $parent = null, array $calls = [], $tag = null, array $arguments = [], $factoryService = null, $factoryMethod = null, $className = null ) { $service = []; $service['public'] = true; // classname if (is_null($className)) { $className = '%' . $id . '.class%'; } $service['class'] = $className; // parent if (!is_null($parent)) { $service['parent'] = $parent; } // factory if ($factoryService && $factoryMethod) { $service['factory'] = [ '@'.$factoryService, $factoryMethod ]; } foreach ($arguments as $argument) { if ($argument['type'] == 'service') { $service['arguments'][] = '@'.$argument['id']; } else { $service['arguments'][] = $argument['value']; } } // calls foreach ($calls as $call) { $service['calls'][] = [ $call['method'], ['@'.$call['service']] ]; } // tags if ($tag) { $thisTag = [ 'name' => $tag ]; if ($this->json instanceof JsonDefinition) { $thisTag['collection'] = $this->json->getId(); // is this read only? if ($this->json->isReadOnlyService()) { $thisTag['read-only'] = true; } // router base defined? $routerBase = $this->json->getRouterBase(); if ($routerBase !== false) { $thisTag['router-base'] = $routerBase; } } $service['tags'][] = $thisTag; } $this->services['services'][$id] = $service; }
php
protected function addService( $id, $parent = null, array $calls = [], $tag = null, array $arguments = [], $factoryService = null, $factoryMethod = null, $className = null ) { $service = []; $service['public'] = true; // classname if (is_null($className)) { $className = '%' . $id . '.class%'; } $service['class'] = $className; // parent if (!is_null($parent)) { $service['parent'] = $parent; } // factory if ($factoryService && $factoryMethod) { $service['factory'] = [ '@'.$factoryService, $factoryMethod ]; } foreach ($arguments as $argument) { if ($argument['type'] == 'service') { $service['arguments'][] = '@'.$argument['id']; } else { $service['arguments'][] = $argument['value']; } } // calls foreach ($calls as $call) { $service['calls'][] = [ $call['method'], ['@'.$call['service']] ]; } // tags if ($tag) { $thisTag = [ 'name' => $tag ]; if ($this->json instanceof JsonDefinition) { $thisTag['collection'] = $this->json->getId(); // is this read only? if ($this->json->isReadOnlyService()) { $thisTag['read-only'] = true; } // router base defined? $routerBase = $this->json->getRouterBase(); if ($routerBase !== false) { $thisTag['router-base'] = $routerBase; } } $service['tags'][] = $thisTag; } $this->services['services'][$id] = $service; }
[ "protected", "function", "addService", "(", "$", "id", ",", "$", "parent", "=", "null", ",", "array", "$", "calls", "=", "[", "]", ",", "$", "tag", "=", "null", ",", "array", "$", "arguments", "=", "[", "]", ",", "$", "factoryService", "=", "null", ",", "$", "factoryMethod", "=", "null", ",", "$", "className", "=", "null", ")", "{", "$", "service", "=", "[", "]", ";", "$", "service", "[", "'public'", "]", "=", "true", ";", "// classname", "if", "(", "is_null", "(", "$", "className", ")", ")", "{", "$", "className", "=", "'%'", ".", "$", "id", ".", "'.class%'", ";", "}", "$", "service", "[", "'class'", "]", "=", "$", "className", ";", "// parent", "if", "(", "!", "is_null", "(", "$", "parent", ")", ")", "{", "$", "service", "[", "'parent'", "]", "=", "$", "parent", ";", "}", "// factory", "if", "(", "$", "factoryService", "&&", "$", "factoryMethod", ")", "{", "$", "service", "[", "'factory'", "]", "=", "[", "'@'", ".", "$", "factoryService", ",", "$", "factoryMethod", "]", ";", "}", "foreach", "(", "$", "arguments", "as", "$", "argument", ")", "{", "if", "(", "$", "argument", "[", "'type'", "]", "==", "'service'", ")", "{", "$", "service", "[", "'arguments'", "]", "[", "]", "=", "'@'", ".", "$", "argument", "[", "'id'", "]", ";", "}", "else", "{", "$", "service", "[", "'arguments'", "]", "[", "]", "=", "$", "argument", "[", "'value'", "]", ";", "}", "}", "// calls", "foreach", "(", "$", "calls", "as", "$", "call", ")", "{", "$", "service", "[", "'calls'", "]", "[", "]", "=", "[", "$", "call", "[", "'method'", "]", ",", "[", "'@'", ".", "$", "call", "[", "'service'", "]", "]", "]", ";", "}", "// tags", "if", "(", "$", "tag", ")", "{", "$", "thisTag", "=", "[", "'name'", "=>", "$", "tag", "]", ";", "if", "(", "$", "this", "->", "json", "instanceof", "JsonDefinition", ")", "{", "$", "thisTag", "[", "'collection'", "]", "=", "$", "this", "->", "json", "->", "getId", "(", ")", ";", "// is this read only?", "if", "(", "$", "this", "->", "json", "->", "isReadOnlyService", "(", ")", ")", "{", "$", "thisTag", "[", "'read-only'", "]", "=", "true", ";", "}", "// router base defined?", "$", "routerBase", "=", "$", "this", "->", "json", "->", "getRouterBase", "(", ")", ";", "if", "(", "$", "routerBase", "!==", "false", ")", "{", "$", "thisTag", "[", "'router-base'", "]", "=", "$", "routerBase", ";", "}", "}", "$", "service", "[", "'tags'", "]", "[", "]", "=", "$", "thisTag", ";", "}", "$", "this", "->", "services", "[", "'services'", "]", "[", "$", "id", "]", "=", "$", "service", ";", "}" ]
add service to services.yml @param string $id id of new service @param string $parent parent for service @param array $calls methodCalls to add @param string $tag tag name or empty if no tag needed @param array $arguments service arguments @param string $factoryService factory service id @param string $factoryMethod factory method name @param string $className class name to override @return void
[ "add", "service", "to", "services", ".", "yml" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php#L385-L458
26,552
libgraviton/graviton
src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php
ResourceGenerator.generateSerializer
protected function generateSerializer(array $parameters, $dir, $document) { // @TODO in Embedded and document just render the differences.. $this->renderFile( 'serializer/Document.xml.twig', $dir . '/Resources/config/serializer/Document.' . $document . 'Embedded.xml', array_merge( $parameters, [ 'document' => $document.'Embedded', 'noIdField' => true, 'realIdField' => true ] ) ); foreach ($parameters['fields'] as $key => $field) { if (substr($field['serializerType'], 0, 14) == 'array<Graviton' && strpos($field['serializerType'], '\\Entity') === false && $field['relType'] == 'embed' ) { $parameters['fields'][$key]['serializerType'] = substr($field['serializerType'], 0, -1).'Embedded>'; } elseif (substr($field['serializerType'], 0, 8) == 'Graviton' && strpos($field['serializerType'], '\\Entity') === false && $field['relType'] == 'embed' ) { $parameters['fields'][$key]['serializerType'] = $field['serializerType'].'Embedded'; } } $this->renderFile( 'serializer/Document.xml.twig', $dir . '/Resources/config/serializer/Document.' . $document . '.xml', array_merge( $parameters, [ 'realIdField' => false ] ) ); $this->renderFile( 'serializer/Document.xml.twig', $dir . '/Resources/config/serializer/Document.' . $document . 'Base.xml', array_merge( $parameters, [ 'document' => $document.'Base', 'realIdField' => false ] ) ); }
php
protected function generateSerializer(array $parameters, $dir, $document) { // @TODO in Embedded and document just render the differences.. $this->renderFile( 'serializer/Document.xml.twig', $dir . '/Resources/config/serializer/Document.' . $document . 'Embedded.xml', array_merge( $parameters, [ 'document' => $document.'Embedded', 'noIdField' => true, 'realIdField' => true ] ) ); foreach ($parameters['fields'] as $key => $field) { if (substr($field['serializerType'], 0, 14) == 'array<Graviton' && strpos($field['serializerType'], '\\Entity') === false && $field['relType'] == 'embed' ) { $parameters['fields'][$key]['serializerType'] = substr($field['serializerType'], 0, -1).'Embedded>'; } elseif (substr($field['serializerType'], 0, 8) == 'Graviton' && strpos($field['serializerType'], '\\Entity') === false && $field['relType'] == 'embed' ) { $parameters['fields'][$key]['serializerType'] = $field['serializerType'].'Embedded'; } } $this->renderFile( 'serializer/Document.xml.twig', $dir . '/Resources/config/serializer/Document.' . $document . '.xml', array_merge( $parameters, [ 'realIdField' => false ] ) ); $this->renderFile( 'serializer/Document.xml.twig', $dir . '/Resources/config/serializer/Document.' . $document . 'Base.xml', array_merge( $parameters, [ 'document' => $document.'Base', 'realIdField' => false ] ) ); }
[ "protected", "function", "generateSerializer", "(", "array", "$", "parameters", ",", "$", "dir", ",", "$", "document", ")", "{", "// @TODO in Embedded and document just render the differences..", "$", "this", "->", "renderFile", "(", "'serializer/Document.xml.twig'", ",", "$", "dir", ".", "'/Resources/config/serializer/Document.'", ".", "$", "document", ".", "'Embedded.xml'", ",", "array_merge", "(", "$", "parameters", ",", "[", "'document'", "=>", "$", "document", ".", "'Embedded'", ",", "'noIdField'", "=>", "true", ",", "'realIdField'", "=>", "true", "]", ")", ")", ";", "foreach", "(", "$", "parameters", "[", "'fields'", "]", "as", "$", "key", "=>", "$", "field", ")", "{", "if", "(", "substr", "(", "$", "field", "[", "'serializerType'", "]", ",", "0", ",", "14", ")", "==", "'array<Graviton'", "&&", "strpos", "(", "$", "field", "[", "'serializerType'", "]", ",", "'\\\\Entity'", ")", "===", "false", "&&", "$", "field", "[", "'relType'", "]", "==", "'embed'", ")", "{", "$", "parameters", "[", "'fields'", "]", "[", "$", "key", "]", "[", "'serializerType'", "]", "=", "substr", "(", "$", "field", "[", "'serializerType'", "]", ",", "0", ",", "-", "1", ")", ".", "'Embedded>'", ";", "}", "elseif", "(", "substr", "(", "$", "field", "[", "'serializerType'", "]", ",", "0", ",", "8", ")", "==", "'Graviton'", "&&", "strpos", "(", "$", "field", "[", "'serializerType'", "]", ",", "'\\\\Entity'", ")", "===", "false", "&&", "$", "field", "[", "'relType'", "]", "==", "'embed'", ")", "{", "$", "parameters", "[", "'fields'", "]", "[", "$", "key", "]", "[", "'serializerType'", "]", "=", "$", "field", "[", "'serializerType'", "]", ".", "'Embedded'", ";", "}", "}", "$", "this", "->", "renderFile", "(", "'serializer/Document.xml.twig'", ",", "$", "dir", ".", "'/Resources/config/serializer/Document.'", ".", "$", "document", ".", "'.xml'", ",", "array_merge", "(", "$", "parameters", ",", "[", "'realIdField'", "=>", "false", "]", ")", ")", ";", "$", "this", "->", "renderFile", "(", "'serializer/Document.xml.twig'", ",", "$", "dir", ".", "'/Resources/config/serializer/Document.'", ".", "$", "document", ".", "'Base.xml'", ",", "array_merge", "(", "$", "parameters", ",", "[", "'document'", "=>", "$", "document", ".", "'Base'", ",", "'realIdField'", "=>", "false", "]", ")", ")", ";", "}" ]
generate serializer part of a resource @param array $parameters twig parameters @param string $dir base bundle dir @param string $document document name @return void
[ "generate", "serializer", "part", "of", "a", "resource" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php#L469-L519
26,553
libgraviton/graviton
src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php
ResourceGenerator.generateModel
protected function generateModel(array $parameters, $dir, $document) { $this->renderFile( 'model/Model.php.twig', $dir . '/Model/' . $document . '.php', $parameters ); $this->renderFile( 'model/schema.json.twig', $dir . '/Resources/config/schema/' . $document . '.json', $parameters ); // embedded versions $this->renderFile( 'model/Model.php.twig', $dir . '/Model/' . $document . 'Embedded.php', array_merge($parameters, ['document' => $document.'Embedded']) ); $this->renderFile( 'model/schema.json.twig', $dir . '/Resources/config/schema/' . $document . 'Embedded.json', array_merge($parameters, ['document' => $document.'Embedded']) ); $bundleParts = explode('\\', $parameters['base']); $shortName = strtolower($bundleParts[0]); $shortBundle = strtolower(substr($bundleParts[1], 0, -6)); $paramName = implode('.', array($shortName, $shortBundle, 'model', strtolower($parameters['document']))); $repoName = implode('.', array($shortName, $shortBundle, 'repository', strtolower($parameters['document']))); $this->addParameter($parameters['base'] . 'Model\\' . $parameters['document'], $paramName . '.class'); // normal service $this->addService( $paramName, 'graviton.rest.model', array( [ 'method' => 'setRepository', 'service' => $repoName ], ), null ); // embedded service $this->addParameter( $parameters['base'] . 'Model\\' . $parameters['document'] . 'Embedded', $paramName . 'embedded.class' ); $this->addService( $paramName . 'embedded', 'graviton.rest.model', array( [ 'method' => 'setRepository', 'service' => $repoName . 'embedded' ], ), null ); }
php
protected function generateModel(array $parameters, $dir, $document) { $this->renderFile( 'model/Model.php.twig', $dir . '/Model/' . $document . '.php', $parameters ); $this->renderFile( 'model/schema.json.twig', $dir . '/Resources/config/schema/' . $document . '.json', $parameters ); // embedded versions $this->renderFile( 'model/Model.php.twig', $dir . '/Model/' . $document . 'Embedded.php', array_merge($parameters, ['document' => $document.'Embedded']) ); $this->renderFile( 'model/schema.json.twig', $dir . '/Resources/config/schema/' . $document . 'Embedded.json', array_merge($parameters, ['document' => $document.'Embedded']) ); $bundleParts = explode('\\', $parameters['base']); $shortName = strtolower($bundleParts[0]); $shortBundle = strtolower(substr($bundleParts[1], 0, -6)); $paramName = implode('.', array($shortName, $shortBundle, 'model', strtolower($parameters['document']))); $repoName = implode('.', array($shortName, $shortBundle, 'repository', strtolower($parameters['document']))); $this->addParameter($parameters['base'] . 'Model\\' . $parameters['document'], $paramName . '.class'); // normal service $this->addService( $paramName, 'graviton.rest.model', array( [ 'method' => 'setRepository', 'service' => $repoName ], ), null ); // embedded service $this->addParameter( $parameters['base'] . 'Model\\' . $parameters['document'] . 'Embedded', $paramName . 'embedded.class' ); $this->addService( $paramName . 'embedded', 'graviton.rest.model', array( [ 'method' => 'setRepository', 'service' => $repoName . 'embedded' ], ), null ); }
[ "protected", "function", "generateModel", "(", "array", "$", "parameters", ",", "$", "dir", ",", "$", "document", ")", "{", "$", "this", "->", "renderFile", "(", "'model/Model.php.twig'", ",", "$", "dir", ".", "'/Model/'", ".", "$", "document", ".", "'.php'", ",", "$", "parameters", ")", ";", "$", "this", "->", "renderFile", "(", "'model/schema.json.twig'", ",", "$", "dir", ".", "'/Resources/config/schema/'", ".", "$", "document", ".", "'.json'", ",", "$", "parameters", ")", ";", "// embedded versions", "$", "this", "->", "renderFile", "(", "'model/Model.php.twig'", ",", "$", "dir", ".", "'/Model/'", ".", "$", "document", ".", "'Embedded.php'", ",", "array_merge", "(", "$", "parameters", ",", "[", "'document'", "=>", "$", "document", ".", "'Embedded'", "]", ")", ")", ";", "$", "this", "->", "renderFile", "(", "'model/schema.json.twig'", ",", "$", "dir", ".", "'/Resources/config/schema/'", ".", "$", "document", ".", "'Embedded.json'", ",", "array_merge", "(", "$", "parameters", ",", "[", "'document'", "=>", "$", "document", ".", "'Embedded'", "]", ")", ")", ";", "$", "bundleParts", "=", "explode", "(", "'\\\\'", ",", "$", "parameters", "[", "'base'", "]", ")", ";", "$", "shortName", "=", "strtolower", "(", "$", "bundleParts", "[", "0", "]", ")", ";", "$", "shortBundle", "=", "strtolower", "(", "substr", "(", "$", "bundleParts", "[", "1", "]", ",", "0", ",", "-", "6", ")", ")", ";", "$", "paramName", "=", "implode", "(", "'.'", ",", "array", "(", "$", "shortName", ",", "$", "shortBundle", ",", "'model'", ",", "strtolower", "(", "$", "parameters", "[", "'document'", "]", ")", ")", ")", ";", "$", "repoName", "=", "implode", "(", "'.'", ",", "array", "(", "$", "shortName", ",", "$", "shortBundle", ",", "'repository'", ",", "strtolower", "(", "$", "parameters", "[", "'document'", "]", ")", ")", ")", ";", "$", "this", "->", "addParameter", "(", "$", "parameters", "[", "'base'", "]", ".", "'Model\\\\'", ".", "$", "parameters", "[", "'document'", "]", ",", "$", "paramName", ".", "'.class'", ")", ";", "// normal service", "$", "this", "->", "addService", "(", "$", "paramName", ",", "'graviton.rest.model'", ",", "array", "(", "[", "'method'", "=>", "'setRepository'", ",", "'service'", "=>", "$", "repoName", "]", ",", ")", ",", "null", ")", ";", "// embedded service", "$", "this", "->", "addParameter", "(", "$", "parameters", "[", "'base'", "]", ".", "'Model\\\\'", ".", "$", "parameters", "[", "'document'", "]", ".", "'Embedded'", ",", "$", "paramName", ".", "'embedded.class'", ")", ";", "$", "this", "->", "addService", "(", "$", "paramName", ".", "'embedded'", ",", "'graviton.rest.model'", ",", "array", "(", "[", "'method'", "=>", "'setRepository'", ",", "'service'", "=>", "$", "repoName", ".", "'embedded'", "]", ",", ")", ",", "null", ")", ";", "}" ]
generate model part of a resource @param array $parameters twig parameters @param string $dir base bundle dir @param string $document document name @return void
[ "generate", "model", "part", "of", "a", "resource" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php#L530-L593
26,554
libgraviton/graviton
src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php
ResourceGenerator.generateController
protected function generateController(array $parameters, $dir, $document) { $this->renderFile( 'controller/DocumentController.php.twig', $dir . '/Controller/' . $document . 'Controller.php', $parameters ); $bundleParts = explode('\\', $parameters['base']); $shortName = strtolower($bundleParts[0]); $shortBundle = strtolower(substr($bundleParts[1], 0, -6)); $paramName = implode('.', array($shortName, $shortBundle, 'controller', strtolower($parameters['document']))); $this->addParameter( $parameters['base'] . 'Controller\\' . $parameters['document'] . 'Controller', $paramName . '.class' ); $this->addService( $paramName, $parameters['parent'], array( array( 'method' => 'setModel', 'service' => implode( '.', array($shortName, $shortBundle, 'model', strtolower($parameters['document'])) ) ) ), 'graviton.rest' ); }
php
protected function generateController(array $parameters, $dir, $document) { $this->renderFile( 'controller/DocumentController.php.twig', $dir . '/Controller/' . $document . 'Controller.php', $parameters ); $bundleParts = explode('\\', $parameters['base']); $shortName = strtolower($bundleParts[0]); $shortBundle = strtolower(substr($bundleParts[1], 0, -6)); $paramName = implode('.', array($shortName, $shortBundle, 'controller', strtolower($parameters['document']))); $this->addParameter( $parameters['base'] . 'Controller\\' . $parameters['document'] . 'Controller', $paramName . '.class' ); $this->addService( $paramName, $parameters['parent'], array( array( 'method' => 'setModel', 'service' => implode( '.', array($shortName, $shortBundle, 'model', strtolower($parameters['document'])) ) ) ), 'graviton.rest' ); }
[ "protected", "function", "generateController", "(", "array", "$", "parameters", ",", "$", "dir", ",", "$", "document", ")", "{", "$", "this", "->", "renderFile", "(", "'controller/DocumentController.php.twig'", ",", "$", "dir", ".", "'/Controller/'", ".", "$", "document", ".", "'Controller.php'", ",", "$", "parameters", ")", ";", "$", "bundleParts", "=", "explode", "(", "'\\\\'", ",", "$", "parameters", "[", "'base'", "]", ")", ";", "$", "shortName", "=", "strtolower", "(", "$", "bundleParts", "[", "0", "]", ")", ";", "$", "shortBundle", "=", "strtolower", "(", "substr", "(", "$", "bundleParts", "[", "1", "]", ",", "0", ",", "-", "6", ")", ")", ";", "$", "paramName", "=", "implode", "(", "'.'", ",", "array", "(", "$", "shortName", ",", "$", "shortBundle", ",", "'controller'", ",", "strtolower", "(", "$", "parameters", "[", "'document'", "]", ")", ")", ")", ";", "$", "this", "->", "addParameter", "(", "$", "parameters", "[", "'base'", "]", ".", "'Controller\\\\'", ".", "$", "parameters", "[", "'document'", "]", ".", "'Controller'", ",", "$", "paramName", ".", "'.class'", ")", ";", "$", "this", "->", "addService", "(", "$", "paramName", ",", "$", "parameters", "[", "'parent'", "]", ",", "array", "(", "array", "(", "'method'", "=>", "'setModel'", ",", "'service'", "=>", "implode", "(", "'.'", ",", "array", "(", "$", "shortName", ",", "$", "shortBundle", ",", "'model'", ",", "strtolower", "(", "$", "parameters", "[", "'document'", "]", ")", ")", ")", ")", ")", ",", "'graviton.rest'", ")", ";", "}" ]
generate RESTful controllers ans service configs @param array $parameters twig parameters @param string $dir base bundle dir @param string $document document name @return void
[ "generate", "RESTful", "controllers", "ans", "service", "configs" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php#L604-L636
26,555
libgraviton/graviton
src/Graviton/CoreBundle/Listener/JsonExceptionListener.php
JsonExceptionListener.onKernelException
public function onKernelException(GetResponseForExceptionEvent $event) { $exception = $event->getException(); // Should return a error 400 bad request if ($exception instanceof ValidationException || $exception instanceof SyntaxErrorException) { return; } // Some Exceptions have status code and if 400 it should be handled by them if (method_exists($exception, 'getStatusCode') && (400 == (int)$exception->getStatusCode())) { return; } $data = $this->decorateKnownCases($exception); if (!is_array($data)) { $data = [ 'code' => $exception->getCode(), 'exceptionClass' => get_class($exception), 'message' => $exception->getMessage() ]; if ($exception->getPrevious() instanceof \Exception) { $data['innerMessage'] = $exception->getPrevious()->getMessage(); } } if ($this->logger instanceof Logger) { $this->logger->critical($exception); } $response = new JsonResponse($data); $event->setResponse($response); }
php
public function onKernelException(GetResponseForExceptionEvent $event) { $exception = $event->getException(); // Should return a error 400 bad request if ($exception instanceof ValidationException || $exception instanceof SyntaxErrorException) { return; } // Some Exceptions have status code and if 400 it should be handled by them if (method_exists($exception, 'getStatusCode') && (400 == (int)$exception->getStatusCode())) { return; } $data = $this->decorateKnownCases($exception); if (!is_array($data)) { $data = [ 'code' => $exception->getCode(), 'exceptionClass' => get_class($exception), 'message' => $exception->getMessage() ]; if ($exception->getPrevious() instanceof \Exception) { $data['innerMessage'] = $exception->getPrevious()->getMessage(); } } if ($this->logger instanceof Logger) { $this->logger->critical($exception); } $response = new JsonResponse($data); $event->setResponse($response); }
[ "public", "function", "onKernelException", "(", "GetResponseForExceptionEvent", "$", "event", ")", "{", "$", "exception", "=", "$", "event", "->", "getException", "(", ")", ";", "// Should return a error 400 bad request", "if", "(", "$", "exception", "instanceof", "ValidationException", "||", "$", "exception", "instanceof", "SyntaxErrorException", ")", "{", "return", ";", "}", "// Some Exceptions have status code and if 400 it should be handled by them", "if", "(", "method_exists", "(", "$", "exception", ",", "'getStatusCode'", ")", "&&", "(", "400", "==", "(", "int", ")", "$", "exception", "->", "getStatusCode", "(", ")", ")", ")", "{", "return", ";", "}", "$", "data", "=", "$", "this", "->", "decorateKnownCases", "(", "$", "exception", ")", ";", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "$", "data", "=", "[", "'code'", "=>", "$", "exception", "->", "getCode", "(", ")", ",", "'exceptionClass'", "=>", "get_class", "(", "$", "exception", ")", ",", "'message'", "=>", "$", "exception", "->", "getMessage", "(", ")", "]", ";", "if", "(", "$", "exception", "->", "getPrevious", "(", ")", "instanceof", "\\", "Exception", ")", "{", "$", "data", "[", "'innerMessage'", "]", "=", "$", "exception", "->", "getPrevious", "(", ")", "->", "getMessage", "(", ")", ";", "}", "}", "if", "(", "$", "this", "->", "logger", "instanceof", "Logger", ")", "{", "$", "this", "->", "logger", "->", "critical", "(", "$", "exception", ")", ";", "}", "$", "response", "=", "new", "JsonResponse", "(", "$", "data", ")", ";", "$", "event", "->", "setResponse", "(", "$", "response", ")", ";", "}" ]
Should not handle Validation Exceptions and only service exceptions @param GetResponseForExceptionEvent $event Sf Event @return void
[ "Should", "not", "handle", "Validation", "Exceptions", "and", "only", "service", "exceptions" ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/CoreBundle/Listener/JsonExceptionListener.php#L49-L85
26,556
libgraviton/graviton
src/Graviton/CoreBundle/Listener/JsonExceptionListener.php
JsonExceptionListener.decorateKnownCases
private function decorateKnownCases($exception) { if ( $exception instanceof \ErrorException && strpos($exception->getMessage(), 'Undefined index: $id') !== false ) { return [ 'code' => $exception->getCode(), 'message' => 'An incomplete internal MongoDB ref has been discovered that can not be rendered. '. 'Did you pass a select() RQL statement and shaved off on the wrong level? Try to select a level '. 'higher.' ]; } elseif ( $exception instanceof SerializationException && strpos($exception->getMessage(), 'Cannot serialize content class') !== false ) { $error = $exception->getMessage(); $message = strpos($error, 'not be found.') !== false ? substr($error, 0, strpos($error, 'not be found.')).'not be found.' : $error; preg_match('/\bwith id: (.*);.*?\bdocument\\\(.*)".*?\bidentifier "(.*)"/is', $message, $matches); if (array_key_exists(3, $matches)) { $sentence = 'Internal Database reference error as been discovered. '. 'The object id: "%s" has a reference to document: "%s" with id: "%s" that could not be found.'; $message = sprintf($sentence, $matches[1], $matches[2], $matches[3]); } return [ 'code' => $exception->getCode(), 'message' => $message ]; } }
php
private function decorateKnownCases($exception) { if ( $exception instanceof \ErrorException && strpos($exception->getMessage(), 'Undefined index: $id') !== false ) { return [ 'code' => $exception->getCode(), 'message' => 'An incomplete internal MongoDB ref has been discovered that can not be rendered. '. 'Did you pass a select() RQL statement and shaved off on the wrong level? Try to select a level '. 'higher.' ]; } elseif ( $exception instanceof SerializationException && strpos($exception->getMessage(), 'Cannot serialize content class') !== false ) { $error = $exception->getMessage(); $message = strpos($error, 'not be found.') !== false ? substr($error, 0, strpos($error, 'not be found.')).'not be found.' : $error; preg_match('/\bwith id: (.*);.*?\bdocument\\\(.*)".*?\bidentifier "(.*)"/is', $message, $matches); if (array_key_exists(3, $matches)) { $sentence = 'Internal Database reference error as been discovered. '. 'The object id: "%s" has a reference to document: "%s" with id: "%s" that could not be found.'; $message = sprintf($sentence, $matches[1], $matches[2], $matches[3]); } return [ 'code' => $exception->getCode(), 'message' => $message ]; } }
[ "private", "function", "decorateKnownCases", "(", "$", "exception", ")", "{", "if", "(", "$", "exception", "instanceof", "\\", "ErrorException", "&&", "strpos", "(", "$", "exception", "->", "getMessage", "(", ")", ",", "'Undefined index: $id'", ")", "!==", "false", ")", "{", "return", "[", "'code'", "=>", "$", "exception", "->", "getCode", "(", ")", ",", "'message'", "=>", "'An incomplete internal MongoDB ref has been discovered that can not be rendered. '", ".", "'Did you pass a select() RQL statement and shaved off on the wrong level? Try to select a level '", ".", "'higher.'", "]", ";", "}", "elseif", "(", "$", "exception", "instanceof", "SerializationException", "&&", "strpos", "(", "$", "exception", "->", "getMessage", "(", ")", ",", "'Cannot serialize content class'", ")", "!==", "false", ")", "{", "$", "error", "=", "$", "exception", "->", "getMessage", "(", ")", ";", "$", "message", "=", "strpos", "(", "$", "error", ",", "'not be found.'", ")", "!==", "false", "?", "substr", "(", "$", "error", ",", "0", ",", "strpos", "(", "$", "error", ",", "'not be found.'", ")", ")", ".", "'not be found.'", ":", "$", "error", ";", "preg_match", "(", "'/\\bwith id: (.*);.*?\\bdocument\\\\\\(.*)\".*?\\bidentifier \"(.*)\"/is'", ",", "$", "message", ",", "$", "matches", ")", ";", "if", "(", "array_key_exists", "(", "3", ",", "$", "matches", ")", ")", "{", "$", "sentence", "=", "'Internal Database reference error as been discovered. '", ".", "'The object id: \"%s\" has a reference to document: \"%s\" with id: \"%s\" that could not be found.'", ";", "$", "message", "=", "sprintf", "(", "$", "sentence", ",", "$", "matches", "[", "1", "]", ",", "$", "matches", "[", "2", "]", ",", "$", "matches", "[", "3", "]", ")", ";", "}", "return", "[", "'code'", "=>", "$", "exception", "->", "getCode", "(", ")", ",", "'message'", "=>", "$", "message", "]", ";", "}", "}" ]
Here we can pick up known cases that can happen and render a more detailed error message for the client. It may be cumbersome, but it's good to detail error messages then just to let general error messages generate support issues and work for us. @param \Exception $exception exception @return array|null either a error message array or null if the general should be displayed
[ "Here", "we", "can", "pick", "up", "known", "cases", "that", "can", "happen", "and", "render", "a", "more", "detailed", "error", "message", "for", "the", "client", ".", "It", "may", "be", "cumbersome", "but", "it", "s", "good", "to", "detail", "error", "messages", "then", "just", "to", "let", "general", "error", "messages", "generate", "support", "issues", "and", "work", "for", "us", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/CoreBundle/Listener/JsonExceptionListener.php#L96-L126
26,557
libgraviton/graviton
src/Graviton/ProxyBundle/DependencyInjection/GravitonProxyExtension.php
GravitonProxyExtension.load
public function load(array $configs, ContainerBuilder $container) { parent::load($configs, $container); $configs = $this->processConfiguration(new Configuration(), $configs); $sources = $container->hasParameter('graviton.proxy.sources') ? $container->getParameter('graviton.proxy.sources') : []; $container->setParameter('graviton.proxy.sources', array_merge_recursive($configs['sources'], $sources)); }
php
public function load(array $configs, ContainerBuilder $container) { parent::load($configs, $container); $configs = $this->processConfiguration(new Configuration(), $configs); $sources = $container->hasParameter('graviton.proxy.sources') ? $container->getParameter('graviton.proxy.sources') : []; $container->setParameter('graviton.proxy.sources', array_merge_recursive($configs['sources'], $sources)); }
[ "public", "function", "load", "(", "array", "$", "configs", ",", "ContainerBuilder", "$", "container", ")", "{", "parent", "::", "load", "(", "$", "configs", ",", "$", "container", ")", ";", "$", "configs", "=", "$", "this", "->", "processConfiguration", "(", "new", "Configuration", "(", ")", ",", "$", "configs", ")", ";", "$", "sources", "=", "$", "container", "->", "hasParameter", "(", "'graviton.proxy.sources'", ")", "?", "$", "container", "->", "getParameter", "(", "'graviton.proxy.sources'", ")", ":", "[", "]", ";", "$", "container", "->", "setParameter", "(", "'graviton.proxy.sources'", ",", "array_merge_recursive", "(", "$", "configs", "[", "'sources'", "]", ",", "$", "sources", ")", ")", ";", "}" ]
Loads current configuration. @param array $configs Set of configuration options @param ContainerBuilder $container Instance of the SF2 container @return void
[ "Loads", "current", "configuration", "." ]
5eccfb2fba31dadf659f0f55edeb1ebca403563e
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/DependencyInjection/GravitonProxyExtension.php#L40-L50
26,558
iherwig/wcmf
src/wcmf/lib/presentation/format/impl/HierarchicalFormat.php
HierarchicalFormat.deserializeHierarchy
private function deserializeHierarchy($values) { if ($this->isSerializedNode($values)) { // the values represent a node $result = $this->deserializeNode($values); $node = $result['node']; $values = $result['data']; $values[$node->getOID()->__toString()] = $node; } else { foreach ($values as $key => $value) { if (is_array($value) || is_object($value)) { // array/object value $result = $this->deserializeHierarchy($value); // flatten the array, if the deserialization result is only an array // with size 1 and the key is an oid (e.g. if a node was deserialized) if (is_array($result) && sizeof($result) == 1 && ObjectId::isValid(key($result))) { unset($values[$key]); $values[key($result)] = current($result); } else { $values[$key] = $result; } } else { // string value $values[$key] = $value; } } } return $values; }
php
private function deserializeHierarchy($values) { if ($this->isSerializedNode($values)) { // the values represent a node $result = $this->deserializeNode($values); $node = $result['node']; $values = $result['data']; $values[$node->getOID()->__toString()] = $node; } else { foreach ($values as $key => $value) { if (is_array($value) || is_object($value)) { // array/object value $result = $this->deserializeHierarchy($value); // flatten the array, if the deserialization result is only an array // with size 1 and the key is an oid (e.g. if a node was deserialized) if (is_array($result) && sizeof($result) == 1 && ObjectId::isValid(key($result))) { unset($values[$key]); $values[key($result)] = current($result); } else { $values[$key] = $result; } } else { // string value $values[$key] = $value; } } } return $values; }
[ "private", "function", "deserializeHierarchy", "(", "$", "values", ")", "{", "if", "(", "$", "this", "->", "isSerializedNode", "(", "$", "values", ")", ")", "{", "// the values represent a node", "$", "result", "=", "$", "this", "->", "deserializeNode", "(", "$", "values", ")", ";", "$", "node", "=", "$", "result", "[", "'node'", "]", ";", "$", "values", "=", "$", "result", "[", "'data'", "]", ";", "$", "values", "[", "$", "node", "->", "getOID", "(", ")", "->", "__toString", "(", ")", "]", "=", "$", "node", ";", "}", "else", "{", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "||", "is_object", "(", "$", "value", ")", ")", "{", "// array/object value", "$", "result", "=", "$", "this", "->", "deserializeHierarchy", "(", "$", "value", ")", ";", "// flatten the array, if the deserialization result is only an array", "// with size 1 and the key is an oid (e.g. if a node was deserialized)", "if", "(", "is_array", "(", "$", "result", ")", "&&", "sizeof", "(", "$", "result", ")", "==", "1", "&&", "ObjectId", "::", "isValid", "(", "key", "(", "$", "result", ")", ")", ")", "{", "unset", "(", "$", "values", "[", "$", "key", "]", ")", ";", "$", "values", "[", "key", "(", "$", "result", ")", "]", "=", "current", "(", "$", "result", ")", ";", "}", "else", "{", "$", "values", "[", "$", "key", "]", "=", "$", "result", ";", "}", "}", "else", "{", "// string value", "$", "values", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "}", "return", "$", "values", ";", "}" ]
Deserialize the given values recursively @param $values @return Array
[ "Deserialize", "the", "given", "values", "recursively" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/presentation/format/impl/HierarchicalFormat.php#L48-L78
26,559
iherwig/wcmf
src/wcmf/lib/presentation/format/impl/HierarchicalFormat.php
HierarchicalFormat.serializeHierarchy
private function serializeHierarchy($values) { if ($this->isDeserializedNode($values)) { // the values represent a node $values = $this->serializeNode($values); } else { if (is_array($values) || ($values instanceof \Traversable)) { foreach ($values as $key => $value) { if ($value != null && !is_scalar($value)) { // array/object value $result = $this->serializeHierarchy($value); if (ObjectId::isValid($key)) { $values = $result; } else { $values[$key] = $result; } } else { // string value $values[$key] = $value; } } } } return $values; }
php
private function serializeHierarchy($values) { if ($this->isDeserializedNode($values)) { // the values represent a node $values = $this->serializeNode($values); } else { if (is_array($values) || ($values instanceof \Traversable)) { foreach ($values as $key => $value) { if ($value != null && !is_scalar($value)) { // array/object value $result = $this->serializeHierarchy($value); if (ObjectId::isValid($key)) { $values = $result; } else { $values[$key] = $result; } } else { // string value $values[$key] = $value; } } } } return $values; }
[ "private", "function", "serializeHierarchy", "(", "$", "values", ")", "{", "if", "(", "$", "this", "->", "isDeserializedNode", "(", "$", "values", ")", ")", "{", "// the values represent a node", "$", "values", "=", "$", "this", "->", "serializeNode", "(", "$", "values", ")", ";", "}", "else", "{", "if", "(", "is_array", "(", "$", "values", ")", "||", "(", "$", "values", "instanceof", "\\", "Traversable", ")", ")", "{", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "!=", "null", "&&", "!", "is_scalar", "(", "$", "value", ")", ")", "{", "// array/object value", "$", "result", "=", "$", "this", "->", "serializeHierarchy", "(", "$", "value", ")", ";", "if", "(", "ObjectId", "::", "isValid", "(", "$", "key", ")", ")", "{", "$", "values", "=", "$", "result", ";", "}", "else", "{", "$", "values", "[", "$", "key", "]", "=", "$", "result", ";", "}", "}", "else", "{", "// string value", "$", "values", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "}", "}", "return", "$", "values", ";", "}" ]
Serialize the given values recursively @param $values @return Array
[ "Serialize", "the", "given", "values", "recursively" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/presentation/format/impl/HierarchicalFormat.php#L85-L111
26,560
skie/plum_search
src/FormParameter/SelectParameter.php
SelectParameter.formInputConfig
public function formInputConfig() { $formConfig = parent::formInputConfig(); if (!array_key_exists('options', $formConfig)) { $options = $this->config('options'); $finder = $this->config('finder'); if (!empty($options) && is_array($options)) { $formConfig['options'] = $options; } elseif ($this->_allowedEmptyOptions()) { } elseif (!empty($finder)) { $formConfig['options'] = $finder; } } return $formConfig; }
php
public function formInputConfig() { $formConfig = parent::formInputConfig(); if (!array_key_exists('options', $formConfig)) { $options = $this->config('options'); $finder = $this->config('finder'); if (!empty($options) && is_array($options)) { $formConfig['options'] = $options; } elseif ($this->_allowedEmptyOptions()) { } elseif (!empty($finder)) { $formConfig['options'] = $finder; } } return $formConfig; }
[ "public", "function", "formInputConfig", "(", ")", "{", "$", "formConfig", "=", "parent", "::", "formInputConfig", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "'options'", ",", "$", "formConfig", ")", ")", "{", "$", "options", "=", "$", "this", "->", "config", "(", "'options'", ")", ";", "$", "finder", "=", "$", "this", "->", "config", "(", "'finder'", ")", ";", "if", "(", "!", "empty", "(", "$", "options", ")", "&&", "is_array", "(", "$", "options", ")", ")", "{", "$", "formConfig", "[", "'options'", "]", "=", "$", "options", ";", "}", "elseif", "(", "$", "this", "->", "_allowedEmptyOptions", "(", ")", ")", "{", "}", "elseif", "(", "!", "empty", "(", "$", "finder", ")", ")", "{", "$", "formConfig", "[", "'options'", "]", "=", "$", "finder", ";", "}", "}", "return", "$", "formConfig", ";", "}" ]
Returns input config @return array
[ "Returns", "input", "config" ]
24d981e240bff7c15731981d6f9b3056abdaf80e
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/FormParameter/SelectParameter.php#L74-L90
26,561
skie/plum_search
src/FormParameter/SelectParameter.php
SelectParameter._allowedEmptyOptions
protected function _allowedEmptyOptions() { $options = $this->config('options'); $allowEmptyOptions = $this->config('allowEmptyOptions'); return is_array($options) && !empty($allowEmptyOptions); }
php
protected function _allowedEmptyOptions() { $options = $this->config('options'); $allowEmptyOptions = $this->config('allowEmptyOptions'); return is_array($options) && !empty($allowEmptyOptions); }
[ "protected", "function", "_allowedEmptyOptions", "(", ")", "{", "$", "options", "=", "$", "this", "->", "config", "(", "'options'", ")", ";", "$", "allowEmptyOptions", "=", "$", "this", "->", "config", "(", "'allowEmptyOptions'", ")", ";", "return", "is_array", "(", "$", "options", ")", "&&", "!", "empty", "(", "$", "allowEmptyOptions", ")", ";", "}" ]
Check if empty options allowed @return bool
[ "Check", "if", "empty", "options", "allowed" ]
24d981e240bff7c15731981d6f9b3056abdaf80e
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/FormParameter/SelectParameter.php#L97-L103
26,562
iherwig/wcmf
src/wcmf/lib/util/I18nUtil.php
I18nUtil.getMessages
public static function getMessages($directory, $exclude, $pattern, $depth=0) { if ($depth == 0) { self::$baseDir = $directory; } if (substr($directory, -1) != '/') { $directory .= '/'; } if (is_dir($directory)) { $d = dir($directory); $d->rewind(); while(false !== ($file = $d->read())) { if($file != '.' && $file != '..' && !in_array($file, $exclude)) { if (is_dir($directory.$file)) { self::getMessages($directory.$file, $exclude, $pattern, ++$depth); } elseif (preg_match($pattern, $file)) { $messages = self::getMessagesFromFile($directory.$file); if (sizeof($messages) > 0) { $key = str_replace(self::$baseDir, '', $directory.$file); self::$result[$key] = $messages; } } } } $d->close(); } else { throw new IllegalArgumentException("The directory '".$directory."' does not exist."); } return self::$result; }
php
public static function getMessages($directory, $exclude, $pattern, $depth=0) { if ($depth == 0) { self::$baseDir = $directory; } if (substr($directory, -1) != '/') { $directory .= '/'; } if (is_dir($directory)) { $d = dir($directory); $d->rewind(); while(false !== ($file = $d->read())) { if($file != '.' && $file != '..' && !in_array($file, $exclude)) { if (is_dir($directory.$file)) { self::getMessages($directory.$file, $exclude, $pattern, ++$depth); } elseif (preg_match($pattern, $file)) { $messages = self::getMessagesFromFile($directory.$file); if (sizeof($messages) > 0) { $key = str_replace(self::$baseDir, '', $directory.$file); self::$result[$key] = $messages; } } } } $d->close(); } else { throw new IllegalArgumentException("The directory '".$directory."' does not exist."); } return self::$result; }
[ "public", "static", "function", "getMessages", "(", "$", "directory", ",", "$", "exclude", ",", "$", "pattern", ",", "$", "depth", "=", "0", ")", "{", "if", "(", "$", "depth", "==", "0", ")", "{", "self", "::", "$", "baseDir", "=", "$", "directory", ";", "}", "if", "(", "substr", "(", "$", "directory", ",", "-", "1", ")", "!=", "'/'", ")", "{", "$", "directory", ".=", "'/'", ";", "}", "if", "(", "is_dir", "(", "$", "directory", ")", ")", "{", "$", "d", "=", "dir", "(", "$", "directory", ")", ";", "$", "d", "->", "rewind", "(", ")", ";", "while", "(", "false", "!==", "(", "$", "file", "=", "$", "d", "->", "read", "(", ")", ")", ")", "{", "if", "(", "$", "file", "!=", "'.'", "&&", "$", "file", "!=", "'..'", "&&", "!", "in_array", "(", "$", "file", ",", "$", "exclude", ")", ")", "{", "if", "(", "is_dir", "(", "$", "directory", ".", "$", "file", ")", ")", "{", "self", "::", "getMessages", "(", "$", "directory", ".", "$", "file", ",", "$", "exclude", ",", "$", "pattern", ",", "++", "$", "depth", ")", ";", "}", "elseif", "(", "preg_match", "(", "$", "pattern", ",", "$", "file", ")", ")", "{", "$", "messages", "=", "self", "::", "getMessagesFromFile", "(", "$", "directory", ".", "$", "file", ")", ";", "if", "(", "sizeof", "(", "$", "messages", ")", ">", "0", ")", "{", "$", "key", "=", "str_replace", "(", "self", "::", "$", "baseDir", ",", "''", ",", "$", "directory", ".", "$", "file", ")", ";", "self", "::", "$", "result", "[", "$", "key", "]", "=", "$", "messages", ";", "}", "}", "}", "}", "$", "d", "->", "close", "(", ")", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"The directory '\"", ".", "$", "directory", ".", "\"' does not exist.\"", ")", ";", "}", "return", "self", "::", "$", "result", ";", "}" ]
Get all messages from a directory recursively. @param $directory The directory to search in @param $exclude Array of directory names that are excluded from search @param $pattern The pattern the names of the files to search in must match @param $depth Internal use only @return An assoziative array with the filenames as keys and the values as array of strings. @see I18nUtil::getMessagesFromFile
[ "Get", "all", "messages", "from", "a", "directory", "recursively", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/util/I18nUtil.php#L37-L68
26,563
iherwig/wcmf
src/wcmf/lib/util/I18nUtil.php
I18nUtil.createPHPLanguageFile
public static function createPHPLanguageFile($language, $messages) { $fileUtil = new FileUtil(); // get locale directory $config = ObjectFactory::getInstance('configuration'); $localeDir = $config->getDirectoryValue('localeDir', 'application'); $fileUtil->mkdirRec($localeDir); $file = $localeDir.'messages_'.$language.'.php'; // backup old file if (file_exists($file)) { rename($file, $file.".bak"); } $fh = fopen($file, "w"); // write header $header = <<<EOT <?php \$messages_{$language} = []; \$messages_{$language}[''] = ''; EOT; fwrite($fh, $header."\n"); // write messages foreach($messages as $message => $attributes) { $lines = '// file(s): '.$attributes['files']."\n"; $lines .= "\$messages_".$language."['".str_replace("'", "\'", $message)."'] = '".str_replace("'", "\'", $attributes['translation'])."';"."\n"; fwrite($fh, $lines); } // write footer $footer = <<<EOT ?> EOT; fwrite($fh, $footer."\n"); fclose($fh); }
php
public static function createPHPLanguageFile($language, $messages) { $fileUtil = new FileUtil(); // get locale directory $config = ObjectFactory::getInstance('configuration'); $localeDir = $config->getDirectoryValue('localeDir', 'application'); $fileUtil->mkdirRec($localeDir); $file = $localeDir.'messages_'.$language.'.php'; // backup old file if (file_exists($file)) { rename($file, $file.".bak"); } $fh = fopen($file, "w"); // write header $header = <<<EOT <?php \$messages_{$language} = []; \$messages_{$language}[''] = ''; EOT; fwrite($fh, $header."\n"); // write messages foreach($messages as $message => $attributes) { $lines = '// file(s): '.$attributes['files']."\n"; $lines .= "\$messages_".$language."['".str_replace("'", "\'", $message)."'] = '".str_replace("'", "\'", $attributes['translation'])."';"."\n"; fwrite($fh, $lines); } // write footer $footer = <<<EOT ?> EOT; fwrite($fh, $footer."\n"); fclose($fh); }
[ "public", "static", "function", "createPHPLanguageFile", "(", "$", "language", ",", "$", "messages", ")", "{", "$", "fileUtil", "=", "new", "FileUtil", "(", ")", ";", "// get locale directory", "$", "config", "=", "ObjectFactory", "::", "getInstance", "(", "'configuration'", ")", ";", "$", "localeDir", "=", "$", "config", "->", "getDirectoryValue", "(", "'localeDir'", ",", "'application'", ")", ";", "$", "fileUtil", "->", "mkdirRec", "(", "$", "localeDir", ")", ";", "$", "file", "=", "$", "localeDir", ".", "'messages_'", ".", "$", "language", ".", "'.php'", ";", "// backup old file", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "rename", "(", "$", "file", ",", "$", "file", ".", "\".bak\"", ")", ";", "}", "$", "fh", "=", "fopen", "(", "$", "file", ",", "\"w\"", ")", ";", "// write header", "$", "header", "=", " <<<EOT\n<?php\n\\$messages_{$language} = [];\n\\$messages_{$language}[''] = '';\nEOT", ";", "fwrite", "(", "$", "fh", ",", "$", "header", ".", "\"\\n\"", ")", ";", "// write messages", "foreach", "(", "$", "messages", "as", "$", "message", "=>", "$", "attributes", ")", "{", "$", "lines", "=", "'// file(s): '", ".", "$", "attributes", "[", "'files'", "]", ".", "\"\\n\"", ";", "$", "lines", ".=", "\"\\$messages_\"", ".", "$", "language", ".", "\"['\"", ".", "str_replace", "(", "\"'\"", ",", "\"\\'\"", ",", "$", "message", ")", ".", "\"'] = '\"", ".", "str_replace", "(", "\"'\"", ",", "\"\\'\"", ",", "$", "attributes", "[", "'translation'", "]", ")", ".", "\"';\"", ".", "\"\\n\"", ";", "fwrite", "(", "$", "fh", ",", "$", "lines", ")", ";", "}", "// write footer", "$", "footer", "=", " <<<EOT\n?>\nEOT", ";", "fwrite", "(", "$", "fh", ",", "$", "footer", ".", "\"\\n\"", ")", ";", "fclose", "(", "$", "fh", ")", ";", "}" ]
Create a message file for use with the Message class. The file will be created in the directory defined in configutation key 'localeDir' in 'application' section. @param $language The language of the file (language code e.g. 'de') @param $messages An assoziative array with the messages as keys and assoziative array with keys 'translation' and 'files' (occurences of the message) @return Boolean whether successful or not.
[ "Create", "a", "message", "file", "for", "use", "with", "the", "Message", "class", ".", "The", "file", "will", "be", "created", "in", "the", "directory", "defined", "in", "configutation", "key", "localeDir", "in", "application", "section", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/util/I18nUtil.php#L118-L155
26,564
vufind-org/vufindharvest
src/ResponseProcessor/SimpleXmlResponseProcessor.php
SimpleXmlResponseProcessor.logBadXML
protected function logBadXML($xml) { $file = @fopen($this->badXmlLog, 'a'); if (!$file) { throw new \Exception("Problem opening {$this->badXmlLog}."); } fputs($file, $xml . "\n\n"); fclose($file); }
php
protected function logBadXML($xml) { $file = @fopen($this->badXmlLog, 'a'); if (!$file) { throw new \Exception("Problem opening {$this->badXmlLog}."); } fputs($file, $xml . "\n\n"); fclose($file); }
[ "protected", "function", "logBadXML", "(", "$", "xml", ")", "{", "$", "file", "=", "@", "fopen", "(", "$", "this", "->", "badXmlLog", ",", "'a'", ")", ";", "if", "(", "!", "$", "file", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Problem opening {$this->badXmlLog}.\"", ")", ";", "}", "fputs", "(", "$", "file", ",", "$", "xml", ".", "\"\\n\\n\"", ")", ";", "fclose", "(", "$", "file", ")", ";", "}" ]
Log a bad XML response. @param string $xml Bad XML @return void
[ "Log", "a", "bad", "XML", "response", "." ]
43a42d1e2292fbba8974a26ace3d522551a1a88f
https://github.com/vufind-org/vufindharvest/blob/43a42d1e2292fbba8974a26ace3d522551a1a88f/src/ResponseProcessor/SimpleXmlResponseProcessor.php#L84-L92
26,565
vufind-org/vufindharvest
src/ResponseProcessor/SimpleXmlResponseProcessor.php
SimpleXmlResponseProcessor.sanitizeXml
protected function sanitizeXml($xml) { // Sanitize the XML if requested: $newXML = trim(preg_replace($this->sanitizeRegex, ' ', $xml, -1, $count)); if ($count > 0 && $this->badXmlLog) { $this->logBadXML($xml); } return $newXML; }
php
protected function sanitizeXml($xml) { // Sanitize the XML if requested: $newXML = trim(preg_replace($this->sanitizeRegex, ' ', $xml, -1, $count)); if ($count > 0 && $this->badXmlLog) { $this->logBadXML($xml); } return $newXML; }
[ "protected", "function", "sanitizeXml", "(", "$", "xml", ")", "{", "// Sanitize the XML if requested:", "$", "newXML", "=", "trim", "(", "preg_replace", "(", "$", "this", "->", "sanitizeRegex", ",", "' '", ",", "$", "xml", ",", "-", "1", ",", "$", "count", ")", ")", ";", "if", "(", "$", "count", ">", "0", "&&", "$", "this", "->", "badXmlLog", ")", "{", "$", "this", "->", "logBadXML", "(", "$", "xml", ")", ";", "}", "return", "$", "newXML", ";", "}" ]
Sanitize XML. @param string $xml XML to sanitize @return string
[ "Sanitize", "XML", "." ]
43a42d1e2292fbba8974a26ace3d522551a1a88f
https://github.com/vufind-org/vufindharvest/blob/43a42d1e2292fbba8974a26ace3d522551a1a88f/src/ResponseProcessor/SimpleXmlResponseProcessor.php#L101-L111
26,566
vufind-org/vufindharvest
src/ResponseProcessor/SimpleXmlResponseProcessor.php
SimpleXmlResponseProcessor.collectXmlErrors
protected function collectXmlErrors() { $callback = function ($e) { return trim($e->message); }; return implode('; ', array_map($callback, libxml_get_errors())); }
php
protected function collectXmlErrors() { $callback = function ($e) { return trim($e->message); }; return implode('; ', array_map($callback, libxml_get_errors())); }
[ "protected", "function", "collectXmlErrors", "(", ")", "{", "$", "callback", "=", "function", "(", "$", "e", ")", "{", "return", "trim", "(", "$", "e", "->", "message", ")", ";", "}", ";", "return", "implode", "(", "'; '", ",", "array_map", "(", "$", "callback", ",", "libxml_get_errors", "(", ")", ")", ")", ";", "}" ]
Collect LibXML errors into a single string. @return string
[ "Collect", "LibXML", "errors", "into", "a", "single", "string", "." ]
43a42d1e2292fbba8974a26ace3d522551a1a88f
https://github.com/vufind-org/vufindharvest/blob/43a42d1e2292fbba8974a26ace3d522551a1a88f/src/ResponseProcessor/SimpleXmlResponseProcessor.php#L118-L124
26,567
vufind-org/vufindharvest
src/ResponseProcessor/SimpleXmlResponseProcessor.php
SimpleXmlResponseProcessor.process
public function process($xml) { // Sanitize if necessary: if ($this->sanitize) { $xml = $this->sanitizeXml($xml); } // Parse the XML (newer versions of LibXML require a special flag for // large documents, and responses may be quite large): $flags = LIBXML_VERSION >= 20900 ? LIBXML_PARSEHUGE : 0; $oldSetting = libxml_use_internal_errors(true); $result = simplexml_load_string($xml, null, $flags); $errors = $this->collectXmlErrors(); libxml_use_internal_errors($oldSetting); if (!$result) { throw new \Exception('Problem loading XML: ' . $errors); } // If we got this far, we have a valid response: return $result; }
php
public function process($xml) { // Sanitize if necessary: if ($this->sanitize) { $xml = $this->sanitizeXml($xml); } // Parse the XML (newer versions of LibXML require a special flag for // large documents, and responses may be quite large): $flags = LIBXML_VERSION >= 20900 ? LIBXML_PARSEHUGE : 0; $oldSetting = libxml_use_internal_errors(true); $result = simplexml_load_string($xml, null, $flags); $errors = $this->collectXmlErrors(); libxml_use_internal_errors($oldSetting); if (!$result) { throw new \Exception('Problem loading XML: ' . $errors); } // If we got this far, we have a valid response: return $result; }
[ "public", "function", "process", "(", "$", "xml", ")", "{", "// Sanitize if necessary:", "if", "(", "$", "this", "->", "sanitize", ")", "{", "$", "xml", "=", "$", "this", "->", "sanitizeXml", "(", "$", "xml", ")", ";", "}", "// Parse the XML (newer versions of LibXML require a special flag for", "// large documents, and responses may be quite large):", "$", "flags", "=", "LIBXML_VERSION", ">=", "20900", "?", "LIBXML_PARSEHUGE", ":", "0", ";", "$", "oldSetting", "=", "libxml_use_internal_errors", "(", "true", ")", ";", "$", "result", "=", "simplexml_load_string", "(", "$", "xml", ",", "null", ",", "$", "flags", ")", ";", "$", "errors", "=", "$", "this", "->", "collectXmlErrors", "(", ")", ";", "libxml_use_internal_errors", "(", "$", "oldSetting", ")", ";", "if", "(", "!", "$", "result", ")", "{", "throw", "new", "\\", "Exception", "(", "'Problem loading XML: '", ".", "$", "errors", ")", ";", "}", "// If we got this far, we have a valid response:", "return", "$", "result", ";", "}" ]
Process an OAI-PMH response into a SimpleXML object. Throw an exception if an error is detected. @param string $xml Raw XML to process @return mixed @throws \Exception
[ "Process", "an", "OAI", "-", "PMH", "response", "into", "a", "SimpleXML", "object", ".", "Throw", "an", "exception", "if", "an", "error", "is", "detected", "." ]
43a42d1e2292fbba8974a26ace3d522551a1a88f
https://github.com/vufind-org/vufindharvest/blob/43a42d1e2292fbba8974a26ace3d522551a1a88f/src/ResponseProcessor/SimpleXmlResponseProcessor.php#L136-L156
26,568
iherwig/wcmf
src/wcmf/lib/model/PersistentIterator.php
PersistentIterator.save
public function save() { $state = ['end' => $this->end, 'oidList' => $this->oidList, 'processedOidList' => $this->processedOidList, 'currentOID' => $this->currentOid, 'currentDepth' => $this->currentDepth, 'aggregationKinds' => $this->aggregationKinds]; $this->session->set($this->id, $state); }
php
public function save() { $state = ['end' => $this->end, 'oidList' => $this->oidList, 'processedOidList' => $this->processedOidList, 'currentOID' => $this->currentOid, 'currentDepth' => $this->currentDepth, 'aggregationKinds' => $this->aggregationKinds]; $this->session->set($this->id, $state); }
[ "public", "function", "save", "(", ")", "{", "$", "state", "=", "[", "'end'", "=>", "$", "this", "->", "end", ",", "'oidList'", "=>", "$", "this", "->", "oidList", ",", "'processedOidList'", "=>", "$", "this", "->", "processedOidList", ",", "'currentOID'", "=>", "$", "this", "->", "currentOid", ",", "'currentDepth'", "=>", "$", "this", "->", "currentDepth", ",", "'aggregationKinds'", "=>", "$", "this", "->", "aggregationKinds", "]", ";", "$", "this", "->", "session", "->", "set", "(", "$", "this", "->", "id", ",", "$", "state", ")", ";", "}" ]
Save the iterator state to the session
[ "Save", "the", "iterator", "state", "to", "the", "session" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/PersistentIterator.php#L68-L72
26,569
iherwig/wcmf
src/wcmf/lib/model/PersistentIterator.php
PersistentIterator.load
public static function load($id, $persistenceFacade, $session) { // get state from session $state = $session->get($id); if ($state == null) { return null; } // create instance $instance = new PersistentIterator($id, $persistenceFacade, $session, $state['currentOID']); $instance->end = $state['end']; $instance->oidList = $state['oidList']; $instance->processedOidList = $state['processedOidList']; $instance->currentDepth = $state['currentDepth']; $instance->aggregationKinds = $state['aggregationKinds']; return $instance; }
php
public static function load($id, $persistenceFacade, $session) { // get state from session $state = $session->get($id); if ($state == null) { return null; } // create instance $instance = new PersistentIterator($id, $persistenceFacade, $session, $state['currentOID']); $instance->end = $state['end']; $instance->oidList = $state['oidList']; $instance->processedOidList = $state['processedOidList']; $instance->currentDepth = $state['currentDepth']; $instance->aggregationKinds = $state['aggregationKinds']; return $instance; }
[ "public", "static", "function", "load", "(", "$", "id", ",", "$", "persistenceFacade", ",", "$", "session", ")", "{", "// get state from session", "$", "state", "=", "$", "session", "->", "get", "(", "$", "id", ")", ";", "if", "(", "$", "state", "==", "null", ")", "{", "return", "null", ";", "}", "// create instance", "$", "instance", "=", "new", "PersistentIterator", "(", "$", "id", ",", "$", "persistenceFacade", ",", "$", "session", ",", "$", "state", "[", "'currentOID'", "]", ")", ";", "$", "instance", "->", "end", "=", "$", "state", "[", "'end'", "]", ";", "$", "instance", "->", "oidList", "=", "$", "state", "[", "'oidList'", "]", ";", "$", "instance", "->", "processedOidList", "=", "$", "state", "[", "'processedOidList'", "]", ";", "$", "instance", "->", "currentDepth", "=", "$", "state", "[", "'currentDepth'", "]", ";", "$", "instance", "->", "aggregationKinds", "=", "$", "state", "[", "'aggregationKinds'", "]", ";", "return", "$", "instance", ";", "}" ]
Load an iterator state from the session @param $id The unique iterator id used to store iterator's the state in the session @param $persistenceFacade @param $session @return PersistentIterator instance holding the saved state or null if unique id is not found
[ "Load", "an", "iterator", "state", "from", "the", "session" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/PersistentIterator.php#L90-L105
26,570
iherwig/wcmf
src/wcmf/lib/model/PersistentIterator.php
PersistentIterator.addToQueue
protected function addToQueue($oidList, $depth) { for ($i=sizeOf($oidList)-1; $i>=0; $i--) { $this->oidList[] = [$oidList[$i], $depth]; } }
php
protected function addToQueue($oidList, $depth) { for ($i=sizeOf($oidList)-1; $i>=0; $i--) { $this->oidList[] = [$oidList[$i], $depth]; } }
[ "protected", "function", "addToQueue", "(", "$", "oidList", ",", "$", "depth", ")", "{", "for", "(", "$", "i", "=", "sizeOf", "(", "$", "oidList", ")", "-", "1", ";", "$", "i", ">=", "0", ";", "$", "i", "--", ")", "{", "$", "this", "->", "oidList", "[", "]", "=", "[", "$", "oidList", "[", "$", "i", "]", ",", "$", "depth", "]", ";", "}", "}" ]
Add object ids to the processing queue. @param $oidList An array of object ids. @param $depth The depth of the object ids in the tree.
[ "Add", "object", "ids", "to", "the", "processing", "queue", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/PersistentIterator.php#L196-L200
26,571
GW2Treasures/gw2api
src/V2/Bulk/BulkEndpoint.php
BulkEndpoint.many
public function many( array $ids = [] ) { if( count( $ids ) === 0 ) { return []; } $pages = array_chunk( $ids, $this->maxPageSize() ); $requests = []; foreach( $pages as $page ) { $requests[] = [ 'ids' => implode( ',', $page ) ]; } $responses = $this->requestMany( $requests ); $result = []; foreach( $responses as $response ) { $result = array_merge( $result, $response->json() ); } return $result; }
php
public function many( array $ids = [] ) { if( count( $ids ) === 0 ) { return []; } $pages = array_chunk( $ids, $this->maxPageSize() ); $requests = []; foreach( $pages as $page ) { $requests[] = [ 'ids' => implode( ',', $page ) ]; } $responses = $this->requestMany( $requests ); $result = []; foreach( $responses as $response ) { $result = array_merge( $result, $response->json() ); } return $result; }
[ "public", "function", "many", "(", "array", "$", "ids", "=", "[", "]", ")", "{", "if", "(", "count", "(", "$", "ids", ")", "===", "0", ")", "{", "return", "[", "]", ";", "}", "$", "pages", "=", "array_chunk", "(", "$", "ids", ",", "$", "this", "->", "maxPageSize", "(", ")", ")", ";", "$", "requests", "=", "[", "]", ";", "foreach", "(", "$", "pages", "as", "$", "page", ")", "{", "$", "requests", "[", "]", "=", "[", "'ids'", "=>", "implode", "(", "','", ",", "$", "page", ")", "]", ";", "}", "$", "responses", "=", "$", "this", "->", "requestMany", "(", "$", "requests", ")", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "responses", "as", "$", "response", ")", "{", "$", "result", "=", "array_merge", "(", "$", "result", ",", "$", "response", "->", "json", "(", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Multiple entries by ids. @param string[]|int[] $ids @return array
[ "Multiple", "entries", "by", "ids", "." ]
c8795af0c1d0a434b9e530f779d5a95786db2176
https://github.com/GW2Treasures/gw2api/blob/c8795af0c1d0a434b9e530f779d5a95786db2176/src/V2/Bulk/BulkEndpoint.php#L48-L68
26,572
vufind-org/vufindharvest
src/OaiPmh/Harvester.php
Harvester.launch
public function launch() { // Normalize sets setting to an array: $sets = (array)$this->set; if (empty($sets)) { $sets = [null]; } // Load last state, if applicable (used to recover from server failure). if ($state = $this->stateManager->loadState()) { $this->write("Found saved state; attempting to resume.\n"); list($resumeSet, $resumeToken, $this->startDate) = $state; } // Loop through all of the selected sets: foreach ($sets as $set) { // If we're resuming and there are multiple sets, find the right one. if (isset($resumeToken) && $resumeSet != $set) { continue; } // If we have a token to resume from, pick up there now... if (isset($resumeToken)) { $token = $resumeToken; unset($resumeToken); } else { // ...otherwise, start harvesting at the requested date: $token = $this->getRecordsByDate( $this->startDate, $set, $this->harvestEndDate ); } // Keep harvesting as long as a resumption token is provided: while ($token !== false) { // Save current state in case we need to resume later: $this->stateManager->saveState($set, $token, $this->startDate); $token = $this->getRecordsByToken($token); } } // If we made it this far, all was successful, so we should clean up // the stored state. $this->stateManager->clearState(); }
php
public function launch() { // Normalize sets setting to an array: $sets = (array)$this->set; if (empty($sets)) { $sets = [null]; } // Load last state, if applicable (used to recover from server failure). if ($state = $this->stateManager->loadState()) { $this->write("Found saved state; attempting to resume.\n"); list($resumeSet, $resumeToken, $this->startDate) = $state; } // Loop through all of the selected sets: foreach ($sets as $set) { // If we're resuming and there are multiple sets, find the right one. if (isset($resumeToken) && $resumeSet != $set) { continue; } // If we have a token to resume from, pick up there now... if (isset($resumeToken)) { $token = $resumeToken; unset($resumeToken); } else { // ...otherwise, start harvesting at the requested date: $token = $this->getRecordsByDate( $this->startDate, $set, $this->harvestEndDate ); } // Keep harvesting as long as a resumption token is provided: while ($token !== false) { // Save current state in case we need to resume later: $this->stateManager->saveState($set, $token, $this->startDate); $token = $this->getRecordsByToken($token); } } // If we made it this far, all was successful, so we should clean up // the stored state. $this->stateManager->clearState(); }
[ "public", "function", "launch", "(", ")", "{", "// Normalize sets setting to an array:", "$", "sets", "=", "(", "array", ")", "$", "this", "->", "set", ";", "if", "(", "empty", "(", "$", "sets", ")", ")", "{", "$", "sets", "=", "[", "null", "]", ";", "}", "// Load last state, if applicable (used to recover from server failure).", "if", "(", "$", "state", "=", "$", "this", "->", "stateManager", "->", "loadState", "(", ")", ")", "{", "$", "this", "->", "write", "(", "\"Found saved state; attempting to resume.\\n\"", ")", ";", "list", "(", "$", "resumeSet", ",", "$", "resumeToken", ",", "$", "this", "->", "startDate", ")", "=", "$", "state", ";", "}", "// Loop through all of the selected sets:", "foreach", "(", "$", "sets", "as", "$", "set", ")", "{", "// If we're resuming and there are multiple sets, find the right one.", "if", "(", "isset", "(", "$", "resumeToken", ")", "&&", "$", "resumeSet", "!=", "$", "set", ")", "{", "continue", ";", "}", "// If we have a token to resume from, pick up there now...", "if", "(", "isset", "(", "$", "resumeToken", ")", ")", "{", "$", "token", "=", "$", "resumeToken", ";", "unset", "(", "$", "resumeToken", ")", ";", "}", "else", "{", "// ...otherwise, start harvesting at the requested date:", "$", "token", "=", "$", "this", "->", "getRecordsByDate", "(", "$", "this", "->", "startDate", ",", "$", "set", ",", "$", "this", "->", "harvestEndDate", ")", ";", "}", "// Keep harvesting as long as a resumption token is provided:", "while", "(", "$", "token", "!==", "false", ")", "{", "// Save current state in case we need to resume later:", "$", "this", "->", "stateManager", "->", "saveState", "(", "$", "set", ",", "$", "token", ",", "$", "this", "->", "startDate", ")", ";", "$", "token", "=", "$", "this", "->", "getRecordsByToken", "(", "$", "token", ")", ";", "}", "}", "// If we made it this far, all was successful, so we should clean up", "// the stored state.", "$", "this", "->", "stateManager", "->", "clearState", "(", ")", ";", "}" ]
Harvest all available documents. @return void
[ "Harvest", "all", "available", "documents", "." ]
43a42d1e2292fbba8974a26ace3d522551a1a88f
https://github.com/vufind-org/vufindharvest/blob/43a42d1e2292fbba8974a26ace3d522551a1a88f/src/OaiPmh/Harvester.php#L159-L202
26,573
vufind-org/vufindharvest
src/OaiPmh/Harvester.php
Harvester.loadGranularity
protected function loadGranularity() { $this->write("Autodetecting date granularity... "); $response = $this->sendRequest('Identify'); $this->granularity = (string)$response->Identify->granularity; $this->writeLine("found {$this->granularity}."); }
php
protected function loadGranularity() { $this->write("Autodetecting date granularity... "); $response = $this->sendRequest('Identify'); $this->granularity = (string)$response->Identify->granularity; $this->writeLine("found {$this->granularity}."); }
[ "protected", "function", "loadGranularity", "(", ")", "{", "$", "this", "->", "write", "(", "\"Autodetecting date granularity... \"", ")", ";", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "'Identify'", ")", ";", "$", "this", "->", "granularity", "=", "(", "string", ")", "$", "response", "->", "Identify", "->", "granularity", ";", "$", "this", "->", "writeLine", "(", "\"found {$this->granularity}.\"", ")", ";", "}" ]
Load date granularity from the server. @return void
[ "Load", "date", "granularity", "from", "the", "server", "." ]
43a42d1e2292fbba8974a26ace3d522551a1a88f
https://github.com/vufind-org/vufindharvest/blob/43a42d1e2292fbba8974a26ace3d522551a1a88f/src/OaiPmh/Harvester.php#L225-L231
26,574
vufind-org/vufindharvest
src/OaiPmh/Harvester.php
Harvester.checkResponseForErrors
protected function checkResponseForErrors($result) { // Detect errors and die if one is found: if ($result->error) { $attribs = $result->error->attributes(); // If this is a bad resumption token error and we're trying to // restore a prior state, we should clean up. if ($attribs['code'] == 'badResumptionToken' && $this->stateManager->loadState() ) { $this->stateManager->clearState(); throw new \Exception( "Token expired; removing last_state.txt. Please restart harvest." ); } throw new \Exception( "OAI-PMH error -- code: {$attribs['code']}, " . "value: {$result->error}" ); } }
php
protected function checkResponseForErrors($result) { // Detect errors and die if one is found: if ($result->error) { $attribs = $result->error->attributes(); // If this is a bad resumption token error and we're trying to // restore a prior state, we should clean up. if ($attribs['code'] == 'badResumptionToken' && $this->stateManager->loadState() ) { $this->stateManager->clearState(); throw new \Exception( "Token expired; removing last_state.txt. Please restart harvest." ); } throw new \Exception( "OAI-PMH error -- code: {$attribs['code']}, " . "value: {$result->error}" ); } }
[ "protected", "function", "checkResponseForErrors", "(", "$", "result", ")", "{", "// Detect errors and die if one is found:", "if", "(", "$", "result", "->", "error", ")", "{", "$", "attribs", "=", "$", "result", "->", "error", "->", "attributes", "(", ")", ";", "// If this is a bad resumption token error and we're trying to", "// restore a prior state, we should clean up.", "if", "(", "$", "attribs", "[", "'code'", "]", "==", "'badResumptionToken'", "&&", "$", "this", "->", "stateManager", "->", "loadState", "(", ")", ")", "{", "$", "this", "->", "stateManager", "->", "clearState", "(", ")", ";", "throw", "new", "\\", "Exception", "(", "\"Token expired; removing last_state.txt. Please restart harvest.\"", ")", ";", "}", "throw", "new", "\\", "Exception", "(", "\"OAI-PMH error -- code: {$attribs['code']}, \"", ".", "\"value: {$result->error}\"", ")", ";", "}", "}" ]
Check an OAI-PMH response for errors that need to be handled. @param object $result OAI-PMH response (SimpleXML object) @return void @throws \Exception
[ "Check", "an", "OAI", "-", "PMH", "response", "for", "errors", "that", "need", "to", "be", "handled", "." ]
43a42d1e2292fbba8974a26ace3d522551a1a88f
https://github.com/vufind-org/vufindharvest/blob/43a42d1e2292fbba8974a26ace3d522551a1a88f/src/OaiPmh/Harvester.php#L242-L263
26,575
vufind-org/vufindharvest
src/OaiPmh/Harvester.php
Harvester.getRecords
protected function getRecords($params) { // Make the OAI-PMH request: $response = $this->sendRequest('ListRecords', $params); // Save the records from the response: if ($response->ListRecords->record) { $this->writeLine( 'Processing ' . count($response->ListRecords->record) . " records..." ); $endDate = $this->writer->write($response->ListRecords->record); } // If we have a resumption token, keep going; otherwise, we're done -- save // the end date. if (isset($response->ListRecords->resumptionToken) && !empty($response->ListRecords->resumptionToken) ) { return $response->ListRecords->resumptionToken; } elseif (isset($endDate) && $endDate > 0) { $dateFormat = ($this->granularity == 'YYYY-MM-DD') ? 'Y-m-d' : 'Y-m-d\TH:i:s\Z'; $this->stateManager->saveDate(date($dateFormat, $endDate)); } return false; }
php
protected function getRecords($params) { // Make the OAI-PMH request: $response = $this->sendRequest('ListRecords', $params); // Save the records from the response: if ($response->ListRecords->record) { $this->writeLine( 'Processing ' . count($response->ListRecords->record) . " records..." ); $endDate = $this->writer->write($response->ListRecords->record); } // If we have a resumption token, keep going; otherwise, we're done -- save // the end date. if (isset($response->ListRecords->resumptionToken) && !empty($response->ListRecords->resumptionToken) ) { return $response->ListRecords->resumptionToken; } elseif (isset($endDate) && $endDate > 0) { $dateFormat = ($this->granularity == 'YYYY-MM-DD') ? 'Y-m-d' : 'Y-m-d\TH:i:s\Z'; $this->stateManager->saveDate(date($dateFormat, $endDate)); } return false; }
[ "protected", "function", "getRecords", "(", "$", "params", ")", "{", "// Make the OAI-PMH request:", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "'ListRecords'", ",", "$", "params", ")", ";", "// Save the records from the response:", "if", "(", "$", "response", "->", "ListRecords", "->", "record", ")", "{", "$", "this", "->", "writeLine", "(", "'Processing '", ".", "count", "(", "$", "response", "->", "ListRecords", "->", "record", ")", ".", "\" records...\"", ")", ";", "$", "endDate", "=", "$", "this", "->", "writer", "->", "write", "(", "$", "response", "->", "ListRecords", "->", "record", ")", ";", "}", "// If we have a resumption token, keep going; otherwise, we're done -- save", "// the end date.", "if", "(", "isset", "(", "$", "response", "->", "ListRecords", "->", "resumptionToken", ")", "&&", "!", "empty", "(", "$", "response", "->", "ListRecords", "->", "resumptionToken", ")", ")", "{", "return", "$", "response", "->", "ListRecords", "->", "resumptionToken", ";", "}", "elseif", "(", "isset", "(", "$", "endDate", ")", "&&", "$", "endDate", ">", "0", ")", "{", "$", "dateFormat", "=", "(", "$", "this", "->", "granularity", "==", "'YYYY-MM-DD'", ")", "?", "'Y-m-d'", ":", "'Y-m-d\\TH:i:s\\Z'", ";", "$", "this", "->", "stateManager", "->", "saveDate", "(", "date", "(", "$", "dateFormat", ",", "$", "endDate", ")", ")", ";", "}", "return", "false", ";", "}" ]
Harvest records using OAI-PMH. @param array $params GET parameters for ListRecords method. @return mixed Resumption token if provided, false if finished
[ "Harvest", "records", "using", "OAI", "-", "PMH", "." ]
43a42d1e2292fbba8974a26ace3d522551a1a88f
https://github.com/vufind-org/vufindharvest/blob/43a42d1e2292fbba8974a26ace3d522551a1a88f/src/OaiPmh/Harvester.php#L272-L297
26,576
vufind-org/vufindharvest
src/OaiPmh/Harvester.php
Harvester.getRecordsByDate
protected function getRecordsByDate($from = null, $set = null, $until = null) { $params = ['metadataPrefix' => $this->metadataPrefix]; if (!empty($from)) { $params['from'] = $from; } if (!empty($set)) { $params['set'] = $set; } if (!empty($until)) { $params['until'] = $until; } return $this->getRecords($params); }
php
protected function getRecordsByDate($from = null, $set = null, $until = null) { $params = ['metadataPrefix' => $this->metadataPrefix]; if (!empty($from)) { $params['from'] = $from; } if (!empty($set)) { $params['set'] = $set; } if (!empty($until)) { $params['until'] = $until; } return $this->getRecords($params); }
[ "protected", "function", "getRecordsByDate", "(", "$", "from", "=", "null", ",", "$", "set", "=", "null", ",", "$", "until", "=", "null", ")", "{", "$", "params", "=", "[", "'metadataPrefix'", "=>", "$", "this", "->", "metadataPrefix", "]", ";", "if", "(", "!", "empty", "(", "$", "from", ")", ")", "{", "$", "params", "[", "'from'", "]", "=", "$", "from", ";", "}", "if", "(", "!", "empty", "(", "$", "set", ")", ")", "{", "$", "params", "[", "'set'", "]", "=", "$", "set", ";", "}", "if", "(", "!", "empty", "(", "$", "until", ")", ")", "{", "$", "params", "[", "'until'", "]", "=", "$", "until", ";", "}", "return", "$", "this", "->", "getRecords", "(", "$", "params", ")", ";", "}" ]
Harvest records via OAI-PMH using date and set. @param string $from Harvest start date (null for no specific start). @param string $set Set to harvest (null for all records). @param string $until Harvest end date (null for no specific end). @return mixed Resumption token if provided, false if finished
[ "Harvest", "records", "via", "OAI", "-", "PMH", "using", "date", "and", "set", "." ]
43a42d1e2292fbba8974a26ace3d522551a1a88f
https://github.com/vufind-org/vufindharvest/blob/43a42d1e2292fbba8974a26ace3d522551a1a88f/src/OaiPmh/Harvester.php#L308-L321
26,577
iherwig/wcmf
src/wcmf/application/controller/AdminController.php
AdminController.clearCaches
protected function clearCaches() { $config = $this->getConfiguration(); foreach($config->getSections() as $section) { $sectionValues = $config->getSection($section, true); if (isset($sectionValues['__class'])) { $instance = ObjectFactory::getInstance($section); if ($instance instanceof Cache) { $instance->clearAll(); } elseif ($instance instanceof View) { $instance->clearCache(); } } } }
php
protected function clearCaches() { $config = $this->getConfiguration(); foreach($config->getSections() as $section) { $sectionValues = $config->getSection($section, true); if (isset($sectionValues['__class'])) { $instance = ObjectFactory::getInstance($section); if ($instance instanceof Cache) { $instance->clearAll(); } elseif ($instance instanceof View) { $instance->clearCache(); } } } }
[ "protected", "function", "clearCaches", "(", ")", "{", "$", "config", "=", "$", "this", "->", "getConfiguration", "(", ")", ";", "foreach", "(", "$", "config", "->", "getSections", "(", ")", "as", "$", "section", ")", "{", "$", "sectionValues", "=", "$", "config", "->", "getSection", "(", "$", "section", ",", "true", ")", ";", "if", "(", "isset", "(", "$", "sectionValues", "[", "'__class'", "]", ")", ")", "{", "$", "instance", "=", "ObjectFactory", "::", "getInstance", "(", "$", "section", ")", ";", "if", "(", "$", "instance", "instanceof", "Cache", ")", "{", "$", "instance", "->", "clearAll", "(", ")", ";", "}", "elseif", "(", "$", "instance", "instanceof", "View", ")", "{", "$", "instance", "->", "clearCache", "(", ")", ";", "}", "}", "}", "}" ]
Clear all cache instances found in the configuration
[ "Clear", "all", "cache", "instances", "found", "in", "the", "configuration" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/AdminController.php#L56-L70
26,578
iherwig/wcmf
src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php
RemoteCapablePersistenceFacade.getProxyObject
protected function getProxyObject(ObjectId $umi, $buildDepth) { self::$logger->debug("Get proxy object for: ".$umi); // local objects don't have a proxy if (strlen($umi->getPrefix()) == 0) { return null; } // check if the proxy object was loaded already $proxy = $this->getRegisteredProxyObject($umi, $buildDepth); // search the proxy object if requested for the first time if (!$proxy) { $persistenceFacade = ObjectFactory::getInstance('persistenceFacade'); $isRemoteCapableFacade = ($persistenceFacade instanceof RemoteCapablePersistenceFacadeImpl); $oldState = true; if ($isRemoteCapableFacade) { $oldState = $persistenceFacade->isResolvingProxies(); $persistenceFacade->setResolveProxies(false); } $proxy = $persistenceFacade->loadFirstObject($umi->getType(), $buildDepth, [$umi->getType().'.umi' => $umi->toString()]); if ($isRemoteCapableFacade) { $persistenceFacade->setResolveProxies($oldState); } if (!$proxy) { // the proxy has to be created self::$logger->debug("Creating..."); $proxy = $persistenceFacade->create($umi->getType(), BuildDepth::SINGLE); $proxy->setValue('umi', $umi); $proxy->save(); } $this->registerProxyObject($umi, $proxy, $buildDepth); } self::$logger->debug("Proxy oid: ".$proxy->getOID()); return $proxy; }
php
protected function getProxyObject(ObjectId $umi, $buildDepth) { self::$logger->debug("Get proxy object for: ".$umi); // local objects don't have a proxy if (strlen($umi->getPrefix()) == 0) { return null; } // check if the proxy object was loaded already $proxy = $this->getRegisteredProxyObject($umi, $buildDepth); // search the proxy object if requested for the first time if (!$proxy) { $persistenceFacade = ObjectFactory::getInstance('persistenceFacade'); $isRemoteCapableFacade = ($persistenceFacade instanceof RemoteCapablePersistenceFacadeImpl); $oldState = true; if ($isRemoteCapableFacade) { $oldState = $persistenceFacade->isResolvingProxies(); $persistenceFacade->setResolveProxies(false); } $proxy = $persistenceFacade->loadFirstObject($umi->getType(), $buildDepth, [$umi->getType().'.umi' => $umi->toString()]); if ($isRemoteCapableFacade) { $persistenceFacade->setResolveProxies($oldState); } if (!$proxy) { // the proxy has to be created self::$logger->debug("Creating..."); $proxy = $persistenceFacade->create($umi->getType(), BuildDepth::SINGLE); $proxy->setValue('umi', $umi); $proxy->save(); } $this->registerProxyObject($umi, $proxy, $buildDepth); } self::$logger->debug("Proxy oid: ".$proxy->getOID()); return $proxy; }
[ "protected", "function", "getProxyObject", "(", "ObjectId", "$", "umi", ",", "$", "buildDepth", ")", "{", "self", "::", "$", "logger", "->", "debug", "(", "\"Get proxy object for: \"", ".", "$", "umi", ")", ";", "// local objects don't have a proxy", "if", "(", "strlen", "(", "$", "umi", "->", "getPrefix", "(", ")", ")", "==", "0", ")", "{", "return", "null", ";", "}", "// check if the proxy object was loaded already", "$", "proxy", "=", "$", "this", "->", "getRegisteredProxyObject", "(", "$", "umi", ",", "$", "buildDepth", ")", ";", "// search the proxy object if requested for the first time", "if", "(", "!", "$", "proxy", ")", "{", "$", "persistenceFacade", "=", "ObjectFactory", "::", "getInstance", "(", "'persistenceFacade'", ")", ";", "$", "isRemoteCapableFacade", "=", "(", "$", "persistenceFacade", "instanceof", "RemoteCapablePersistenceFacadeImpl", ")", ";", "$", "oldState", "=", "true", ";", "if", "(", "$", "isRemoteCapableFacade", ")", "{", "$", "oldState", "=", "$", "persistenceFacade", "->", "isResolvingProxies", "(", ")", ";", "$", "persistenceFacade", "->", "setResolveProxies", "(", "false", ")", ";", "}", "$", "proxy", "=", "$", "persistenceFacade", "->", "loadFirstObject", "(", "$", "umi", "->", "getType", "(", ")", ",", "$", "buildDepth", ",", "[", "$", "umi", "->", "getType", "(", ")", ".", "'.umi'", "=>", "$", "umi", "->", "toString", "(", ")", "]", ")", ";", "if", "(", "$", "isRemoteCapableFacade", ")", "{", "$", "persistenceFacade", "->", "setResolveProxies", "(", "$", "oldState", ")", ";", "}", "if", "(", "!", "$", "proxy", ")", "{", "// the proxy has to be created", "self", "::", "$", "logger", "->", "debug", "(", "\"Creating...\"", ")", ";", "$", "proxy", "=", "$", "persistenceFacade", "->", "create", "(", "$", "umi", "->", "getType", "(", ")", ",", "BuildDepth", "::", "SINGLE", ")", ";", "$", "proxy", "->", "setValue", "(", "'umi'", ",", "$", "umi", ")", ";", "$", "proxy", "->", "save", "(", ")", ";", "}", "$", "this", "->", "registerProxyObject", "(", "$", "umi", ",", "$", "proxy", ",", "$", "buildDepth", ")", ";", "}", "self", "::", "$", "logger", "->", "debug", "(", "\"Proxy oid: \"", ".", "$", "proxy", "->", "getOID", "(", ")", ")", ";", "return", "$", "proxy", ";", "}" ]
Get the proxy object for a remote object. This method makes sure that a proxy for the given remote object exists. If it does not exist, it will be created. @param $umi The universal model id (oid with server prefix) @param $buildDepth buildDepth One of the BUILDDEPTH constants or a number describing the number of generations to build (except BuildDepth::REQUIRED) @return The proxy object.
[ "Get", "the", "proxy", "object", "for", "a", "remote", "object", ".", "This", "method", "makes", "sure", "that", "a", "proxy", "for", "the", "given", "remote", "object", "exists", ".", "If", "it", "does", "not", "exist", "it", "will", "be", "created", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php#L172-L207
26,579
iherwig/wcmf
src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php
RemoteCapablePersistenceFacade.registerProxyObject
protected function registerProxyObject(ObjectID $umi, PersistentObject $obj, $buildDepth) { $oid = $obj->getOID(); if (strlen($oid->getPrefix()) > 0) { self::$logger->debug("NOT A PROXY"); return; } $this->registerObject($umi, $obj, $buildDepth, self::PROXY_OBJECTS_SESSION_VARNAME); }
php
protected function registerProxyObject(ObjectID $umi, PersistentObject $obj, $buildDepth) { $oid = $obj->getOID(); if (strlen($oid->getPrefix()) > 0) { self::$logger->debug("NOT A PROXY"); return; } $this->registerObject($umi, $obj, $buildDepth, self::PROXY_OBJECTS_SESSION_VARNAME); }
[ "protected", "function", "registerProxyObject", "(", "ObjectID", "$", "umi", ",", "PersistentObject", "$", "obj", ",", "$", "buildDepth", ")", "{", "$", "oid", "=", "$", "obj", "->", "getOID", "(", ")", ";", "if", "(", "strlen", "(", "$", "oid", "->", "getPrefix", "(", ")", ")", ">", "0", ")", "{", "self", "::", "$", "logger", "->", "debug", "(", "\"NOT A PROXY\"", ")", ";", "return", ";", "}", "$", "this", "->", "registerObject", "(", "$", "umi", ",", "$", "obj", ",", "$", "buildDepth", ",", "self", "::", "PROXY_OBJECTS_SESSION_VARNAME", ")", ";", "}" ]
Save a proxy object in the session. @param $umi The universal model id (oid with server prefix) @param $obj The proxy object. @param $buildDepth The depth the object was loaded.
[ "Save", "a", "proxy", "object", "in", "the", "session", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php#L297-L304
26,580
iherwig/wcmf
src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php
RemoteCapablePersistenceFacade.registerRemoteObject
protected function registerRemoteObject(ObjectId $umi, PersistentObject $obj, $buildDepth) { // TODO: fix caching remote objects (invalidate cache entry, if an association to the object changes) return; $this->registerObject($umi, $obj, $buildDepth, self::REMOTE_OBJECTS_SESSION_VARNAME); }
php
protected function registerRemoteObject(ObjectId $umi, PersistentObject $obj, $buildDepth) { // TODO: fix caching remote objects (invalidate cache entry, if an association to the object changes) return; $this->registerObject($umi, $obj, $buildDepth, self::REMOTE_OBJECTS_SESSION_VARNAME); }
[ "protected", "function", "registerRemoteObject", "(", "ObjectId", "$", "umi", ",", "PersistentObject", "$", "obj", ",", "$", "buildDepth", ")", "{", "// TODO: fix caching remote objects (invalidate cache entry, if an association to the object changes)", "return", ";", "$", "this", "->", "registerObject", "(", "$", "umi", ",", "$", "obj", ",", "$", "buildDepth", ",", "self", "::", "REMOTE_OBJECTS_SESSION_VARNAME", ")", ";", "}" ]
Save a remote object in the session. @param $umi The universal model id (oid with server prefix) @param $obj The remote object. @param $buildDepth The depth the object was loaded.
[ "Save", "a", "remote", "object", "in", "the", "session", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php#L312-L317
26,581
iherwig/wcmf
src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php
RemoteCapablePersistenceFacade.registerObject
protected function registerObject(ObjectId $umi, PersistentObject $obj, $buildDepth, $varName) { if ($buildDepth == 0) { $buildDepth=BuildDepth::SINGLE; } // save the object in the session $umiStr = $umi->toString(); $objects = $this->session->get($varName); if (!isset($objects[$umiStr])) { $objects[$umiStr] = []; } $objects[$umiStr][$buildDepth] = $obj; $this->session->set($varName, $objects); }
php
protected function registerObject(ObjectId $umi, PersistentObject $obj, $buildDepth, $varName) { if ($buildDepth == 0) { $buildDepth=BuildDepth::SINGLE; } // save the object in the session $umiStr = $umi->toString(); $objects = $this->session->get($varName); if (!isset($objects[$umiStr])) { $objects[$umiStr] = []; } $objects[$umiStr][$buildDepth] = $obj; $this->session->set($varName, $objects); }
[ "protected", "function", "registerObject", "(", "ObjectId", "$", "umi", ",", "PersistentObject", "$", "obj", ",", "$", "buildDepth", ",", "$", "varName", ")", "{", "if", "(", "$", "buildDepth", "==", "0", ")", "{", "$", "buildDepth", "=", "BuildDepth", "::", "SINGLE", ";", "}", "// save the object in the session", "$", "umiStr", "=", "$", "umi", "->", "toString", "(", ")", ";", "$", "objects", "=", "$", "this", "->", "session", "->", "get", "(", "$", "varName", ")", ";", "if", "(", "!", "isset", "(", "$", "objects", "[", "$", "umiStr", "]", ")", ")", "{", "$", "objects", "[", "$", "umiStr", "]", "=", "[", "]", ";", "}", "$", "objects", "[", "$", "umiStr", "]", "[", "$", "buildDepth", "]", "=", "$", "obj", ";", "$", "this", "->", "session", "->", "set", "(", "$", "varName", ",", "$", "objects", ")", ";", "}" ]
Save a object in the given session variable. @param $umi The universal model id (oid with server prefix) @param $obj The object to register. @param $buildDepth The depth the object was loaded. @param $varName The session variable name.
[ "Save", "a", "object", "in", "the", "given", "session", "variable", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php#L326-L338
26,582
iherwig/wcmf
src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php
RemoteCapablePersistenceFacade.getRegisteredProxyObject
protected function getRegisteredProxyObject(ObjectId $umi, $buildDepth) { $proxy = $this->getRegisteredObject($umi, $buildDepth, self::PROXY_OBJECTS_SESSION_VARNAME); return $proxy; }
php
protected function getRegisteredProxyObject(ObjectId $umi, $buildDepth) { $proxy = $this->getRegisteredObject($umi, $buildDepth, self::PROXY_OBJECTS_SESSION_VARNAME); return $proxy; }
[ "protected", "function", "getRegisteredProxyObject", "(", "ObjectId", "$", "umi", ",", "$", "buildDepth", ")", "{", "$", "proxy", "=", "$", "this", "->", "getRegisteredObject", "(", "$", "umi", ",", "$", "buildDepth", ",", "self", "::", "PROXY_OBJECTS_SESSION_VARNAME", ")", ";", "return", "$", "proxy", ";", "}" ]
Get a proxy object from the session. @param $umi The universal model id (oid with server prefix) @param $buildDepth The requested build depth. @return The proxy object or null if not found.
[ "Get", "a", "proxy", "object", "from", "the", "session", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php#L346-L349
26,583
iherwig/wcmf
src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php
RemoteCapablePersistenceFacade.getRegisteredRemoteObject
protected function getRegisteredRemoteObject(ObjectId $umi, $buildDepth) { $object = $this->getRegisteredObject($umi, $buildDepth, self::REMOTE_OBJECTS_SESSION_VARNAME); return $object; }
php
protected function getRegisteredRemoteObject(ObjectId $umi, $buildDepth) { $object = $this->getRegisteredObject($umi, $buildDepth, self::REMOTE_OBJECTS_SESSION_VARNAME); return $object; }
[ "protected", "function", "getRegisteredRemoteObject", "(", "ObjectId", "$", "umi", ",", "$", "buildDepth", ")", "{", "$", "object", "=", "$", "this", "->", "getRegisteredObject", "(", "$", "umi", ",", "$", "buildDepth", ",", "self", "::", "REMOTE_OBJECTS_SESSION_VARNAME", ")", ";", "return", "$", "object", ";", "}" ]
Get a remote object from the session. @param $umi The universal model id (oid with server prefix) @param $buildDepth The requested build depth. @return The remote object or null if not found.
[ "Get", "a", "remote", "object", "from", "the", "session", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php#L357-L360
26,584
iherwig/wcmf
src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php
RemoteCapablePersistenceFacade.getRegisteredObject
protected function getRegisteredObject(ObjectId $umi, $buildDepth, $varName) { if ($buildDepth == 0) { $buildDepth=BuildDepth::SINGLE; } $umiStr = $umi->toString(); $objects = $this->session->get($varName); if (isset($objects[$umiStr]) && isset($objects[$umiStr][$buildDepth])) { return $objects[$umiStr][$buildDepth]; } // check if an object with larger build depth was stored already if ($buildDepth == BuildDepth::SINGLE) { $existingDepths = array_keys($objects[$umiStr]); foreach($existingDepths as $depth) { if ($depth > 0 || $depth == BuildDepth::INFINITE) { return $objects[$umiStr][$depth]; } } } return null; }
php
protected function getRegisteredObject(ObjectId $umi, $buildDepth, $varName) { if ($buildDepth == 0) { $buildDepth=BuildDepth::SINGLE; } $umiStr = $umi->toString(); $objects = $this->session->get($varName); if (isset($objects[$umiStr]) && isset($objects[$umiStr][$buildDepth])) { return $objects[$umiStr][$buildDepth]; } // check if an object with larger build depth was stored already if ($buildDepth == BuildDepth::SINGLE) { $existingDepths = array_keys($objects[$umiStr]); foreach($existingDepths as $depth) { if ($depth > 0 || $depth == BuildDepth::INFINITE) { return $objects[$umiStr][$depth]; } } } return null; }
[ "protected", "function", "getRegisteredObject", "(", "ObjectId", "$", "umi", ",", "$", "buildDepth", ",", "$", "varName", ")", "{", "if", "(", "$", "buildDepth", "==", "0", ")", "{", "$", "buildDepth", "=", "BuildDepth", "::", "SINGLE", ";", "}", "$", "umiStr", "=", "$", "umi", "->", "toString", "(", ")", ";", "$", "objects", "=", "$", "this", "->", "session", "->", "get", "(", "$", "varName", ")", ";", "if", "(", "isset", "(", "$", "objects", "[", "$", "umiStr", "]", ")", "&&", "isset", "(", "$", "objects", "[", "$", "umiStr", "]", "[", "$", "buildDepth", "]", ")", ")", "{", "return", "$", "objects", "[", "$", "umiStr", "]", "[", "$", "buildDepth", "]", ";", "}", "// check if an object with larger build depth was stored already", "if", "(", "$", "buildDepth", "==", "BuildDepth", "::", "SINGLE", ")", "{", "$", "existingDepths", "=", "array_keys", "(", "$", "objects", "[", "$", "umiStr", "]", ")", ";", "foreach", "(", "$", "existingDepths", "as", "$", "depth", ")", "{", "if", "(", "$", "depth", ">", "0", "||", "$", "depth", "==", "BuildDepth", "::", "INFINITE", ")", "{", "return", "$", "objects", "[", "$", "umiStr", "]", "[", "$", "depth", "]", ";", "}", "}", "}", "return", "null", ";", "}" ]
Get a object from the given session variable. @param $umi The universal model id (oid with server prefix) @param $buildDepth The requested build depth. @param $varName The session variable name @return The object or null if not found.
[ "Get", "a", "object", "from", "the", "given", "session", "variable", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php#L369-L388
26,585
iherwig/wcmf
src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php
RemoteCapablePersistenceFacade.makeUmis
protected function makeUmis($oids, $umiPrefix) { $result = []; foreach ($oids as $oid) { if (strlen($oid->getPrefix()) == 0) { $umi = new ObjectId($oid->getType(), $oid->getId(), $umiPrefix); $result[] = $umi; } } return $result; }
php
protected function makeUmis($oids, $umiPrefix) { $result = []; foreach ($oids as $oid) { if (strlen($oid->getPrefix()) == 0) { $umi = new ObjectId($oid->getType(), $oid->getId(), $umiPrefix); $result[] = $umi; } } return $result; }
[ "protected", "function", "makeUmis", "(", "$", "oids", ",", "$", "umiPrefix", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "oids", "as", "$", "oid", ")", "{", "if", "(", "strlen", "(", "$", "oid", "->", "getPrefix", "(", ")", ")", "==", "0", ")", "{", "$", "umi", "=", "new", "ObjectId", "(", "$", "oid", "->", "getType", "(", ")", ",", "$", "oid", "->", "getId", "(", ")", ",", "$", "umiPrefix", ")", ";", "$", "result", "[", "]", "=", "$", "umi", ";", "}", "}", "return", "$", "result", ";", "}" ]
Replace all object ids in an array with the umis according to the given umiPrefix. @param $oids The array of oids @param $umiPrefix The umi prefix @return The array of umis
[ "Replace", "all", "object", "ids", "in", "an", "array", "with", "the", "umis", "according", "to", "the", "given", "umiPrefix", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/impl/RemoteCapablePersistenceFacade.php#L397-L406
26,586
iherwig/wcmf
src/wcmf/lib/presentation/impl/DefaultRequestListener.php
DefaultRequestListener.listen
public function listen(ApplicationEvent $event) { if ($event->getStage() == ApplicationEvent::BEFORE_ROUTE_ACTION) { $request = $event->getRequest(); if ($request != null) { $this->transformRequest($request); } } else if ($event->getStage() == ApplicationEvent::AFTER_EXECUTE_CONTROLLER) { $request = $event->getRequest(); $response = $event->getResponse(); if ($request != null && $response != null) { $this->transformResponse($request, $response); } } }
php
public function listen(ApplicationEvent $event) { if ($event->getStage() == ApplicationEvent::BEFORE_ROUTE_ACTION) { $request = $event->getRequest(); if ($request != null) { $this->transformRequest($request); } } else if ($event->getStage() == ApplicationEvent::AFTER_EXECUTE_CONTROLLER) { $request = $event->getRequest(); $response = $event->getResponse(); if ($request != null && $response != null) { $this->transformResponse($request, $response); } } }
[ "public", "function", "listen", "(", "ApplicationEvent", "$", "event", ")", "{", "if", "(", "$", "event", "->", "getStage", "(", ")", "==", "ApplicationEvent", "::", "BEFORE_ROUTE_ACTION", ")", "{", "$", "request", "=", "$", "event", "->", "getRequest", "(", ")", ";", "if", "(", "$", "request", "!=", "null", ")", "{", "$", "this", "->", "transformRequest", "(", "$", "request", ")", ";", "}", "}", "else", "if", "(", "$", "event", "->", "getStage", "(", ")", "==", "ApplicationEvent", "::", "AFTER_EXECUTE_CONTROLLER", ")", "{", "$", "request", "=", "$", "event", "->", "getRequest", "(", ")", ";", "$", "response", "=", "$", "event", "->", "getResponse", "(", ")", ";", "if", "(", "$", "request", "!=", "null", "&&", "$", "response", "!=", "null", ")", "{", "$", "this", "->", "transformResponse", "(", "$", "request", ",", "$", "response", ")", ";", "}", "}", "}" ]
Listen to ApplicationEvent @param $event ApplicationEvent instance
[ "Listen", "to", "ApplicationEvent" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/presentation/impl/DefaultRequestListener.php#L40-L54
26,587
skie/plum_search
src/FormParameter/BaseParameter.php
BaseParameter._process
protected function _process() { $name = $this->config('field'); $this->value = $this->_registry->data($name); $this->_processed = true; }
php
protected function _process() { $name = $this->config('field'); $this->value = $this->_registry->data($name); $this->_processed = true; }
[ "protected", "function", "_process", "(", ")", "{", "$", "name", "=", "$", "this", "->", "config", "(", "'field'", ")", ";", "$", "this", "->", "value", "=", "$", "this", "->", "_registry", "->", "data", "(", "$", "name", ")", ";", "$", "this", "->", "_processed", "=", "true", ";", "}" ]
process param parsing @return void
[ "process", "param", "parsing" ]
24d981e240bff7c15731981d6f9b3056abdaf80e
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/FormParameter/BaseParameter.php#L111-L116
26,588
iherwig/wcmf
src/wcmf/lib/config/impl/InifileConfiguration.php
InifileConfiguration.processFile
protected function processFile($filename, $configArray=[], $parsedFiles=[]) { // avoid circular includes if (!in_array($filename, $parsedFiles)) { $parsedFiles[] = $filename; $content = $this->parseIniFile($filename); // process includes $includes = $this->getConfigIncludes($content); if ($includes) { $this->processValue($includes); foreach ($includes as $include) { $result = $this->processFile($this->configPath.$include, $configArray, $parsedFiles); $configArray = $this->configMerge($configArray, $result['config'], true); $parsedFiles = $result['files']; } } // process self $configArray = $this->configMerge($configArray, $content, true); } return ['config' => $configArray, 'files' => $parsedFiles]; }
php
protected function processFile($filename, $configArray=[], $parsedFiles=[]) { // avoid circular includes if (!in_array($filename, $parsedFiles)) { $parsedFiles[] = $filename; $content = $this->parseIniFile($filename); // process includes $includes = $this->getConfigIncludes($content); if ($includes) { $this->processValue($includes); foreach ($includes as $include) { $result = $this->processFile($this->configPath.$include, $configArray, $parsedFiles); $configArray = $this->configMerge($configArray, $result['config'], true); $parsedFiles = $result['files']; } } // process self $configArray = $this->configMerge($configArray, $content, true); } return ['config' => $configArray, 'files' => $parsedFiles]; }
[ "protected", "function", "processFile", "(", "$", "filename", ",", "$", "configArray", "=", "[", "]", ",", "$", "parsedFiles", "=", "[", "]", ")", "{", "// avoid circular includes\r", "if", "(", "!", "in_array", "(", "$", "filename", ",", "$", "parsedFiles", ")", ")", "{", "$", "parsedFiles", "[", "]", "=", "$", "filename", ";", "$", "content", "=", "$", "this", "->", "parseIniFile", "(", "$", "filename", ")", ";", "// process includes\r", "$", "includes", "=", "$", "this", "->", "getConfigIncludes", "(", "$", "content", ")", ";", "if", "(", "$", "includes", ")", "{", "$", "this", "->", "processValue", "(", "$", "includes", ")", ";", "foreach", "(", "$", "includes", "as", "$", "include", ")", "{", "$", "result", "=", "$", "this", "->", "processFile", "(", "$", "this", "->", "configPath", ".", "$", "include", ",", "$", "configArray", ",", "$", "parsedFiles", ")", ";", "$", "configArray", "=", "$", "this", "->", "configMerge", "(", "$", "configArray", ",", "$", "result", "[", "'config'", "]", ",", "true", ")", ";", "$", "parsedFiles", "=", "$", "result", "[", "'files'", "]", ";", "}", "}", "// process self\r", "$", "configArray", "=", "$", "this", "->", "configMerge", "(", "$", "configArray", ",", "$", "content", ",", "true", ")", ";", "}", "return", "[", "'config'", "=>", "$", "configArray", ",", "'files'", "=>", "$", "parsedFiles", "]", ";", "}" ]
Process the given file recursively @param $filename The filename @param $configArray Configuration array @param $parsedFiles Parsed files @return Associative array with keys 'config' (configuration array) and 'files' (array of parsed files)
[ "Process", "the", "given", "file", "recursively" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/config/impl/InifileConfiguration.php#L174-L196
26,589
iherwig/wcmf
src/wcmf/lib/config/impl/InifileConfiguration.php
InifileConfiguration.serialize
protected function serialize() { if (!$this->isModified() && ($cacheFile = $this->getSerializeFilename($this->addedFiles))) { if (self::$logger->isDebugEnabled()) { self::$logger->debug("Serialize configuration: ".join(',', $this->addedFiles)." to file: ".$cacheFile); } $this->fileUtil->mkdirRec(dirname($cacheFile)); if ($fh = @fopen($cacheFile, "w")) { if (@fwrite($fh, serialize(array_filter(get_object_vars($this), function($value, $name) { return $name != 'comments'; // don't store comments }, ARRAY_FILTER_USE_BOTH)))) { @fclose($fh); } } } }
php
protected function serialize() { if (!$this->isModified() && ($cacheFile = $this->getSerializeFilename($this->addedFiles))) { if (self::$logger->isDebugEnabled()) { self::$logger->debug("Serialize configuration: ".join(',', $this->addedFiles)." to file: ".$cacheFile); } $this->fileUtil->mkdirRec(dirname($cacheFile)); if ($fh = @fopen($cacheFile, "w")) { if (@fwrite($fh, serialize(array_filter(get_object_vars($this), function($value, $name) { return $name != 'comments'; // don't store comments }, ARRAY_FILTER_USE_BOTH)))) { @fclose($fh); } } } }
[ "protected", "function", "serialize", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isModified", "(", ")", "&&", "(", "$", "cacheFile", "=", "$", "this", "->", "getSerializeFilename", "(", "$", "this", "->", "addedFiles", ")", ")", ")", "{", "if", "(", "self", "::", "$", "logger", "->", "isDebugEnabled", "(", ")", ")", "{", "self", "::", "$", "logger", "->", "debug", "(", "\"Serialize configuration: \"", ".", "join", "(", "','", ",", "$", "this", "->", "addedFiles", ")", ".", "\" to file: \"", ".", "$", "cacheFile", ")", ";", "}", "$", "this", "->", "fileUtil", "->", "mkdirRec", "(", "dirname", "(", "$", "cacheFile", ")", ")", ";", "if", "(", "$", "fh", "=", "@", "fopen", "(", "$", "cacheFile", ",", "\"w\"", ")", ")", "{", "if", "(", "@", "fwrite", "(", "$", "fh", ",", "serialize", "(", "array_filter", "(", "get_object_vars", "(", "$", "this", ")", ",", "function", "(", "$", "value", ",", "$", "name", ")", "{", "return", "$", "name", "!=", "'comments'", ";", "// don't store comments\r", "}", ",", "ARRAY_FILTER_USE_BOTH", ")", ")", ")", ")", "{", "@", "fclose", "(", "$", "fh", ")", ";", "}", "}", "}", "}" ]
Store the instance in the file system. If the instance is modified, this call is ignored.
[ "Store", "the", "instance", "in", "the", "file", "system", ".", "If", "the", "instance", "is", "modified", "this", "call", "is", "ignored", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/config/impl/InifileConfiguration.php#L666-L680
26,590
iherwig/wcmf
src/wcmf/lib/config/impl/InifileConfiguration.php
InifileConfiguration.unserialize
protected function unserialize($parsedFiles) { if (!$this->isModified() && ($cacheFile = $this->getSerializeFilename($parsedFiles)) && file_exists($cacheFile)) { $parsedFiles[] = __FILE__; if (!$this->checkFileDate($parsedFiles, $cacheFile)) { $vars = unserialize(file_get_contents($cacheFile)); // check if included ini files were updated since last cache time $includes = $vars['containedFiles']; if (is_array($includes)) { if ($this->checkFileDate($includes, $cacheFile)) { return false; } } // everything is up-to-date foreach($vars as $key => $val) { $this->$key = $val; } return true; } } return false; }
php
protected function unserialize($parsedFiles) { if (!$this->isModified() && ($cacheFile = $this->getSerializeFilename($parsedFiles)) && file_exists($cacheFile)) { $parsedFiles[] = __FILE__; if (!$this->checkFileDate($parsedFiles, $cacheFile)) { $vars = unserialize(file_get_contents($cacheFile)); // check if included ini files were updated since last cache time $includes = $vars['containedFiles']; if (is_array($includes)) { if ($this->checkFileDate($includes, $cacheFile)) { return false; } } // everything is up-to-date foreach($vars as $key => $val) { $this->$key = $val; } return true; } } return false; }
[ "protected", "function", "unserialize", "(", "$", "parsedFiles", ")", "{", "if", "(", "!", "$", "this", "->", "isModified", "(", ")", "&&", "(", "$", "cacheFile", "=", "$", "this", "->", "getSerializeFilename", "(", "$", "parsedFiles", ")", ")", "&&", "file_exists", "(", "$", "cacheFile", ")", ")", "{", "$", "parsedFiles", "[", "]", "=", "__FILE__", ";", "if", "(", "!", "$", "this", "->", "checkFileDate", "(", "$", "parsedFiles", ",", "$", "cacheFile", ")", ")", "{", "$", "vars", "=", "unserialize", "(", "file_get_contents", "(", "$", "cacheFile", ")", ")", ";", "// check if included ini files were updated since last cache time\r", "$", "includes", "=", "$", "vars", "[", "'containedFiles'", "]", ";", "if", "(", "is_array", "(", "$", "includes", ")", ")", "{", "if", "(", "$", "this", "->", "checkFileDate", "(", "$", "includes", ",", "$", "cacheFile", ")", ")", "{", "return", "false", ";", "}", "}", "// everything is up-to-date\r", "foreach", "(", "$", "vars", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "this", "->", "$", "key", "=", "$", "val", ";", "}", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Retrieve parsed ini data from the file system and update the current instance. If the current instance is modified or any file given in parsedFiles is newer than the serialized data, this call is ignored. If InifileConfiguration class changed, the call will be ignored as well. @param $parsedFiles An array of ini filenames that must be contained in the data. @return Boolean whether the data could be retrieved or not
[ "Retrieve", "parsed", "ini", "data", "from", "the", "file", "system", "and", "update", "the", "current", "instance", ".", "If", "the", "current", "instance", "is", "modified", "or", "any", "file", "given", "in", "parsedFiles", "is", "newer", "than", "the", "serialized", "data", "this", "call", "is", "ignored", ".", "If", "InifileConfiguration", "class", "changed", "the", "call", "will", "be", "ignored", "as", "well", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/config/impl/InifileConfiguration.php#L690-L712
26,591
iherwig/wcmf
src/wcmf/lib/config/impl/InifileConfiguration.php
InifileConfiguration.checkFileDate
protected function checkFileDate($fileList, $referenceFile) { foreach ($fileList as $file) { if (@filemtime($file) > @filemtime($referenceFile)) { return true; } } return false; }
php
protected function checkFileDate($fileList, $referenceFile) { foreach ($fileList as $file) { if (@filemtime($file) > @filemtime($referenceFile)) { return true; } } return false; }
[ "protected", "function", "checkFileDate", "(", "$", "fileList", ",", "$", "referenceFile", ")", "{", "foreach", "(", "$", "fileList", "as", "$", "file", ")", "{", "if", "(", "@", "filemtime", "(", "$", "file", ")", ">", "@", "filemtime", "(", "$", "referenceFile", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check if one file in fileList is newer than the referenceFile. @param $fileList An array of files @param $referenceFile The file to check against @return True, if one of the files is newer, false else
[ "Check", "if", "one", "file", "in", "fileList", "is", "newer", "than", "the", "referenceFile", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/config/impl/InifileConfiguration.php#L735-L742
26,592
iherwig/wcmf
src/wcmf/lib/config/impl/InifileConfiguration.php
InifileConfiguration.configChanged
protected function configChanged() { if (self::$logger->isDebugEnabled()) { self::$logger->debug("Configuration is changed"); } if (ObjectFactory::isConfigured()) { if (self::$logger->isDebugEnabled()) { self::$logger->debug("Emitting change event"); } ObjectFactory::getInstance('eventManager')->dispatch(ConfigChangeEvent::NAME, new ConfigChangeEvent()); } }
php
protected function configChanged() { if (self::$logger->isDebugEnabled()) { self::$logger->debug("Configuration is changed"); } if (ObjectFactory::isConfigured()) { if (self::$logger->isDebugEnabled()) { self::$logger->debug("Emitting change event"); } ObjectFactory::getInstance('eventManager')->dispatch(ConfigChangeEvent::NAME, new ConfigChangeEvent()); } }
[ "protected", "function", "configChanged", "(", ")", "{", "if", "(", "self", "::", "$", "logger", "->", "isDebugEnabled", "(", ")", ")", "{", "self", "::", "$", "logger", "->", "debug", "(", "\"Configuration is changed\"", ")", ";", "}", "if", "(", "ObjectFactory", "::", "isConfigured", "(", ")", ")", "{", "if", "(", "self", "::", "$", "logger", "->", "isDebugEnabled", "(", ")", ")", "{", "self", "::", "$", "logger", "->", "debug", "(", "\"Emitting change event\"", ")", ";", "}", "ObjectFactory", "::", "getInstance", "(", "'eventManager'", ")", "->", "dispatch", "(", "ConfigChangeEvent", "::", "NAME", ",", "new", "ConfigChangeEvent", "(", ")", ")", ";", "}", "}" ]
Notify configuration change listeners
[ "Notify", "configuration", "change", "listeners" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/config/impl/InifileConfiguration.php#L747-L758
26,593
iherwig/wcmf
src/wcmf/lib/config/impl/InifileConfiguration.php
InifileConfiguration.buildLookupTable
protected function buildLookupTable() { $this->lookupTable = []; foreach ($this->configArray as $section => $entry) { // create section entry $lookupSectionKey = strtolower($section.':'); $this->lookupTable[$lookupSectionKey] = [$section]; // create key entries foreach ($entry as $key => $value) { $lookupKey = strtolower($lookupSectionKey.$key); $this->lookupTable[$lookupKey] = [$section, $key]; } } }
php
protected function buildLookupTable() { $this->lookupTable = []; foreach ($this->configArray as $section => $entry) { // create section entry $lookupSectionKey = strtolower($section.':'); $this->lookupTable[$lookupSectionKey] = [$section]; // create key entries foreach ($entry as $key => $value) { $lookupKey = strtolower($lookupSectionKey.$key); $this->lookupTable[$lookupKey] = [$section, $key]; } } }
[ "protected", "function", "buildLookupTable", "(", ")", "{", "$", "this", "->", "lookupTable", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "configArray", "as", "$", "section", "=>", "$", "entry", ")", "{", "// create section entry\r", "$", "lookupSectionKey", "=", "strtolower", "(", "$", "section", ".", "':'", ")", ";", "$", "this", "->", "lookupTable", "[", "$", "lookupSectionKey", "]", "=", "[", "$", "section", "]", ";", "// create key entries\r", "foreach", "(", "$", "entry", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "lookupKey", "=", "strtolower", "(", "$", "lookupSectionKey", ".", "$", "key", ")", ";", "$", "this", "->", "lookupTable", "[", "$", "lookupKey", "]", "=", "[", "$", "section", ",", "$", "key", "]", ";", "}", "}", "}" ]
Build the internal lookup table
[ "Build", "the", "internal", "lookup", "table" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/config/impl/InifileConfiguration.php#L763-L775
26,594
iherwig/wcmf
src/wcmf/lib/config/impl/InifileConfiguration.php
InifileConfiguration.lookup
protected function lookup($section, $key=null) { $lookupKey = strtolower($section).':'.strtolower($key); if (isset($this->lookupTable[$lookupKey])) { return $this->lookupTable[$lookupKey]; } return null; }
php
protected function lookup($section, $key=null) { $lookupKey = strtolower($section).':'.strtolower($key); if (isset($this->lookupTable[$lookupKey])) { return $this->lookupTable[$lookupKey]; } return null; }
[ "protected", "function", "lookup", "(", "$", "section", ",", "$", "key", "=", "null", ")", "{", "$", "lookupKey", "=", "strtolower", "(", "$", "section", ")", ".", "':'", ".", "strtolower", "(", "$", "key", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "lookupTable", "[", "$", "lookupKey", "]", ")", ")", "{", "return", "$", "this", "->", "lookupTable", "[", "$", "lookupKey", "]", ";", "}", "return", "null", ";", "}" ]
Lookup section and key. @param $section The section to lookup @param $key The key to lookup (optional) @return Array with section as first entry and key as second or null if not found
[ "Lookup", "section", "and", "key", "." ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/config/impl/InifileConfiguration.php#L783-L789
26,595
vufind-org/vufindharvest
src/OaiPmh/StateManager.php
StateManager.loadDate
public function loadDate() { return (file_exists($this->lastHarvestFile)) ? trim(current(file($this->lastHarvestFile))) : null; }
php
public function loadDate() { return (file_exists($this->lastHarvestFile)) ? trim(current(file($this->lastHarvestFile))) : null; }
[ "public", "function", "loadDate", "(", ")", "{", "return", "(", "file_exists", "(", "$", "this", "->", "lastHarvestFile", ")", ")", "?", "trim", "(", "current", "(", "file", "(", "$", "this", "->", "lastHarvestFile", ")", ")", ")", ":", "null", ";", "}" ]
Retrieve the date from the "last harvested" file and use it as our start date if it is available. @return string
[ "Retrieve", "the", "date", "from", "the", "last", "harvested", "file", "and", "use", "it", "as", "our", "start", "date", "if", "it", "is", "available", "." ]
43a42d1e2292fbba8974a26ace3d522551a1a88f
https://github.com/vufind-org/vufindharvest/blob/43a42d1e2292fbba8974a26ace3d522551a1a88f/src/OaiPmh/StateManager.php#L94-L98
26,596
iherwig/wcmf
src/wcmf/lib/model/impl/AbstractNodeSerializer.php
AbstractNodeSerializer.getNodeTemplate
protected function getNodeTemplate($oid) { // load object if existing to get the original data $originalNode = $this->persistenceFacade->load($oid, BuildDepth::SINGLE); // create the request node and copy the orignal data $class = get_class($this->persistenceFacade->create($oid->getType(), BuildDepth::SINGLE)); $node = new $class; if ($originalNode) { $originalNode->copyValues($node); } return $node; }
php
protected function getNodeTemplate($oid) { // load object if existing to get the original data $originalNode = $this->persistenceFacade->load($oid, BuildDepth::SINGLE); // create the request node and copy the orignal data $class = get_class($this->persistenceFacade->create($oid->getType(), BuildDepth::SINGLE)); $node = new $class; if ($originalNode) { $originalNode->copyValues($node); } return $node; }
[ "protected", "function", "getNodeTemplate", "(", "$", "oid", ")", "{", "// load object if existing to get the original data", "$", "originalNode", "=", "$", "this", "->", "persistenceFacade", "->", "load", "(", "$", "oid", ",", "BuildDepth", "::", "SINGLE", ")", ";", "// create the request node and copy the orignal data", "$", "class", "=", "get_class", "(", "$", "this", "->", "persistenceFacade", "->", "create", "(", "$", "oid", "->", "getType", "(", ")", ",", "BuildDepth", "::", "SINGLE", ")", ")", ";", "$", "node", "=", "new", "$", "class", ";", "if", "(", "$", "originalNode", ")", "{", "$", "originalNode", "->", "copyValues", "(", "$", "node", ")", ";", "}", "return", "$", "node", ";", "}" ]
Get a Node instance based on the original values to merge the deserialized values into @param $oid The object id of the Node @return Node
[ "Get", "a", "Node", "instance", "based", "on", "the", "original", "values", "to", "merge", "the", "deserialized", "values", "into" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/impl/AbstractNodeSerializer.php#L40-L51
26,597
iherwig/wcmf
src/wcmf/lib/model/impl/AbstractNodeSerializer.php
AbstractNodeSerializer.deserializeValue
protected function deserializeValue(Node $node, $key, $value) { if (!is_array($value)) { // force set value to avoid exceptions in this stage $node->setValue($key, $value, true); } else { $role = $key; if ($this->isMultiValued($node, $role)) { // deserialize children foreach($value as $childData) { $this->deserializeNode($childData, $node, $role); } } else { $this->deserializeNode($value, $node, $role); } } }
php
protected function deserializeValue(Node $node, $key, $value) { if (!is_array($value)) { // force set value to avoid exceptions in this stage $node->setValue($key, $value, true); } else { $role = $key; if ($this->isMultiValued($node, $role)) { // deserialize children foreach($value as $childData) { $this->deserializeNode($childData, $node, $role); } } else { $this->deserializeNode($value, $node, $role); } } }
[ "protected", "function", "deserializeValue", "(", "Node", "$", "node", ",", "$", "key", ",", "$", "value", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "// force set value to avoid exceptions in this stage", "$", "node", "->", "setValue", "(", "$", "key", ",", "$", "value", ",", "true", ")", ";", "}", "else", "{", "$", "role", "=", "$", "key", ";", "if", "(", "$", "this", "->", "isMultiValued", "(", "$", "node", ",", "$", "role", ")", ")", "{", "// deserialize children", "foreach", "(", "$", "value", "as", "$", "childData", ")", "{", "$", "this", "->", "deserializeNode", "(", "$", "childData", ",", "$", "node", ",", "$", "role", ")", ";", "}", "}", "else", "{", "$", "this", "->", "deserializeNode", "(", "$", "value", ",", "$", "node", ",", "$", "role", ")", ";", "}", "}", "}" ]
Deserialize a node value @param $node Node instance @param $key The value name or type if value is an array @param $value The value or child data, if value is an array
[ "Deserialize", "a", "node", "value" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/impl/AbstractNodeSerializer.php#L59-L76
26,598
iherwig/wcmf
src/wcmf/lib/model/impl/AbstractNodeSerializer.php
AbstractNodeSerializer.isMultiValued
protected function isMultiValued(Node $node, $role) { $isMultiValued = false; $mapper = $node->getMapper(); if ($mapper->hasRelation($role)) { $relation = $mapper->getRelation($role); $isMultiValued = $relation->isMultiValued(); } return $isMultiValued; }
php
protected function isMultiValued(Node $node, $role) { $isMultiValued = false; $mapper = $node->getMapper(); if ($mapper->hasRelation($role)) { $relation = $mapper->getRelation($role); $isMultiValued = $relation->isMultiValued(); } return $isMultiValued; }
[ "protected", "function", "isMultiValued", "(", "Node", "$", "node", ",", "$", "role", ")", "{", "$", "isMultiValued", "=", "false", ";", "$", "mapper", "=", "$", "node", "->", "getMapper", "(", ")", ";", "if", "(", "$", "mapper", "->", "hasRelation", "(", "$", "role", ")", ")", "{", "$", "relation", "=", "$", "mapper", "->", "getRelation", "(", "$", "role", ")", ";", "$", "isMultiValued", "=", "$", "relation", "->", "isMultiValued", "(", ")", ";", "}", "return", "$", "isMultiValued", ";", "}" ]
Check if a relation is multi valued @param $node The Node that has the relation @param $role The role of the relation
[ "Check", "if", "a", "relation", "is", "multi", "valued" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/impl/AbstractNodeSerializer.php#L83-L91
26,599
iherwig/wcmf
src/wcmf/lib/persistence/AttributeDescription.php
AttributeDescription.matchTags
public function matchTags(array $tags=[], $matchMode='all') { $numGivenTags = sizeof($tags); if (sizeof($numGivenTags) == 0) { return true; } $result = true; $diff = sizeof(array_diff($tags, $this->tags)); switch ($matchMode) { case 'all': $result = ($diff == 0); break; case 'none': $result = ($diff == $numGivenTags); break; case 'any': $result = ($diff < $numGivenTags); break; } return $result; }
php
public function matchTags(array $tags=[], $matchMode='all') { $numGivenTags = sizeof($tags); if (sizeof($numGivenTags) == 0) { return true; } $result = true; $diff = sizeof(array_diff($tags, $this->tags)); switch ($matchMode) { case 'all': $result = ($diff == 0); break; case 'none': $result = ($diff == $numGivenTags); break; case 'any': $result = ($diff < $numGivenTags); break; } return $result; }
[ "public", "function", "matchTags", "(", "array", "$", "tags", "=", "[", "]", ",", "$", "matchMode", "=", "'all'", ")", "{", "$", "numGivenTags", "=", "sizeof", "(", "$", "tags", ")", ";", "if", "(", "sizeof", "(", "$", "numGivenTags", ")", "==", "0", ")", "{", "return", "true", ";", "}", "$", "result", "=", "true", ";", "$", "diff", "=", "sizeof", "(", "array_diff", "(", "$", "tags", ",", "$", "this", "->", "tags", ")", ")", ";", "switch", "(", "$", "matchMode", ")", "{", "case", "'all'", ":", "$", "result", "=", "(", "$", "diff", "==", "0", ")", ";", "break", ";", "case", "'none'", ":", "$", "result", "=", "(", "$", "diff", "==", "$", "numGivenTags", ")", ";", "break", ";", "case", "'any'", ":", "$", "result", "=", "(", "$", "diff", "<", "$", "numGivenTags", ")", ";", "break", ";", "}", "return", "$", "result", ";", "}" ]
Check if this attribute is tagged with the given application specific tags @param $tags An array of tags that the attribute should match. Empty array results in true the given matchMode (default: empty array) @param $matchMode One of 'all', 'none', 'any', defines how the attribute's tags should match the given tags (default: 'all') @return True if the attribute tags satisfy the match mode, false else
[ "Check", "if", "this", "attribute", "is", "tagged", "with", "the", "given", "application", "specific", "tags" ]
2542b8d4139464d39a9a8ce8a954dfecf700c41b
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/AttributeDescription.php#L70-L89