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,300
|
libgraviton/graviton
|
src/Graviton/I18nBundle/Listener/I18nRqlParsingListener.php
|
I18nRqlParsingListener.isTranslatableFieldNode
|
private function isTranslatableFieldNode()
{
$isTranslatableField = false;
if (isset($this->mapping[$this->className]) &&
in_array($this->getDocumentFieldName(), $this->mapping[$this->className])
) {
$isTranslatableField = true;
}
return $isTranslatableField;
}
|
php
|
private function isTranslatableFieldNode()
{
$isTranslatableField = false;
if (isset($this->mapping[$this->className]) &&
in_array($this->getDocumentFieldName(), $this->mapping[$this->className])
) {
$isTranslatableField = true;
}
return $isTranslatableField;
}
|
[
"private",
"function",
"isTranslatableFieldNode",
"(",
")",
"{",
"$",
"isTranslatableField",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"mapping",
"[",
"$",
"this",
"->",
"className",
"]",
")",
"&&",
"in_array",
"(",
"$",
"this",
"->",
"getDocumentFieldName",
"(",
")",
",",
"$",
"this",
"->",
"mapping",
"[",
"$",
"this",
"->",
"className",
"]",
")",
")",
"{",
"$",
"isTranslatableField",
"=",
"true",
";",
"}",
"return",
"$",
"isTranslatableField",
";",
"}"
] |
Returns true if the current node affects a translatable field
@return bool true if yes, false if not
|
[
"Returns",
"true",
"if",
"the",
"current",
"node",
"affects",
"a",
"translatable",
"field"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/I18nBundle/Listener/I18nRqlParsingListener.php#L158-L168
|
26,301
|
libgraviton/graviton
|
src/Graviton/I18nBundle/Listener/I18nRqlParsingListener.php
|
I18nRqlParsingListener.getEqNode
|
private function getEqNode($fieldName, $fieldValue)
{
$node = new EqNode($fieldName, $fieldValue);
$this->createdNodes[] = $node;
return $node;
}
|
php
|
private function getEqNode($fieldName, $fieldValue)
{
$node = new EqNode($fieldName, $fieldValue);
$this->createdNodes[] = $node;
return $node;
}
|
[
"private",
"function",
"getEqNode",
"(",
"$",
"fieldName",
",",
"$",
"fieldValue",
")",
"{",
"$",
"node",
"=",
"new",
"EqNode",
"(",
"$",
"fieldName",
",",
"$",
"fieldValue",
")",
";",
"$",
"this",
"->",
"createdNodes",
"[",
"]",
"=",
"$",
"node",
";",
"return",
"$",
"node",
";",
"}"
] |
get EqNode instance and remember that we created it..
@param string $fieldName field name
@param string $fieldValue field value
@return EqNode node
|
[
"get",
"EqNode",
"instance",
"and",
"remember",
"that",
"we",
"created",
"it",
".."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/I18nBundle/Listener/I18nRqlParsingListener.php#L178-L183
|
26,302
|
libgraviton/graviton
|
src/Graviton/I18nBundle/Listener/I18nRqlParsingListener.php
|
I18nRqlParsingListener.isOurNode
|
private function isOurNode($node)
{
foreach ($this->createdNodes as $createdNode) {
if ($createdNode == $node) {
return true;
}
}
return false;
}
|
php
|
private function isOurNode($node)
{
foreach ($this->createdNodes as $createdNode) {
if ($createdNode == $node) {
return true;
}
}
return false;
}
|
[
"private",
"function",
"isOurNode",
"(",
"$",
"node",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"createdNodes",
"as",
"$",
"createdNode",
")",
"{",
"if",
"(",
"$",
"createdNode",
"==",
"$",
"node",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
check if we created the node previously
@param EqNode $node node
@return bool true if yes, false otherwise
|
[
"check",
"if",
"we",
"created",
"the",
"node",
"previously"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/I18nBundle/Listener/I18nRqlParsingListener.php#L192-L200
|
26,303
|
libgraviton/graviton
|
src/Graviton/I18nBundle/Listener/I18nRqlParsingListener.php
|
I18nRqlParsingListener.nodeFieldNameHasLanguage
|
private function nodeFieldNameHasLanguage()
{
$parts = explode('.', $this->node->getField());
if (!empty($parts)) {
$lastPart = $parts[count($parts) - 1];
// only remove when language
if (in_array($lastPart, $this->intUtils->getLanguages())) {
return true;
}
}
return false;
}
|
php
|
private function nodeFieldNameHasLanguage()
{
$parts = explode('.', $this->node->getField());
if (!empty($parts)) {
$lastPart = $parts[count($parts) - 1];
// only remove when language
if (in_array($lastPart, $this->intUtils->getLanguages())) {
return true;
}
}
return false;
}
|
[
"private",
"function",
"nodeFieldNameHasLanguage",
"(",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"this",
"->",
"node",
"->",
"getField",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"parts",
")",
")",
"{",
"$",
"lastPart",
"=",
"$",
"parts",
"[",
"count",
"(",
"$",
"parts",
")",
"-",
"1",
"]",
";",
"// only remove when language",
"if",
"(",
"in_array",
"(",
"$",
"lastPart",
",",
"$",
"this",
"->",
"intUtils",
"->",
"getLanguages",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
if the node field name targets a language or not
@return bool true if yes, false otherwise
|
[
"if",
"the",
"node",
"field",
"name",
"targets",
"a",
"language",
"or",
"not"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/I18nBundle/Listener/I18nRqlParsingListener.php#L223-L234
|
26,304
|
libgraviton/graviton
|
src/Graviton/I18nBundle/Listener/I18nRqlParsingListener.php
|
I18nRqlParsingListener.getAllPossibleTranslatableStrings
|
private function getAllPossibleTranslatableStrings()
{
$matchingTranslations = [];
// is it a glob?
if ($this->node->getValue() instanceof \Xiag\Rql\Parser\DataType\Glob) {
$userValue = $this->node->getValue()->toRegex();
$useWildcard = true;
} else {
$userValue = $this->node->getValue();
$useWildcard = false;
}
$matchingTranslatables = $this->intUtils->findMatchingTranslatables(
$userValue,
$this->getClientSearchLanguage(),
$useWildcard
);
foreach ($matchingTranslatables as $translatable) {
$originalString = $translatable->getOriginal();
if (!empty($originalString)) {
$matchingTranslations[] = $originalString;
}
}
return array_unique($matchingTranslations);
}
|
php
|
private function getAllPossibleTranslatableStrings()
{
$matchingTranslations = [];
// is it a glob?
if ($this->node->getValue() instanceof \Xiag\Rql\Parser\DataType\Glob) {
$userValue = $this->node->getValue()->toRegex();
$useWildcard = true;
} else {
$userValue = $this->node->getValue();
$useWildcard = false;
}
$matchingTranslatables = $this->intUtils->findMatchingTranslatables(
$userValue,
$this->getClientSearchLanguage(),
$useWildcard
);
foreach ($matchingTranslatables as $translatable) {
$originalString = $translatable->getOriginal();
if (!empty($originalString)) {
$matchingTranslations[] = $originalString;
}
}
return array_unique($matchingTranslations);
}
|
[
"private",
"function",
"getAllPossibleTranslatableStrings",
"(",
")",
"{",
"$",
"matchingTranslations",
"=",
"[",
"]",
";",
"// is it a glob?",
"if",
"(",
"$",
"this",
"->",
"node",
"->",
"getValue",
"(",
")",
"instanceof",
"\\",
"Xiag",
"\\",
"Rql",
"\\",
"Parser",
"\\",
"DataType",
"\\",
"Glob",
")",
"{",
"$",
"userValue",
"=",
"$",
"this",
"->",
"node",
"->",
"getValue",
"(",
")",
"->",
"toRegex",
"(",
")",
";",
"$",
"useWildcard",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"userValue",
"=",
"$",
"this",
"->",
"node",
"->",
"getValue",
"(",
")",
";",
"$",
"useWildcard",
"=",
"false",
";",
"}",
"$",
"matchingTranslatables",
"=",
"$",
"this",
"->",
"intUtils",
"->",
"findMatchingTranslatables",
"(",
"$",
"userValue",
",",
"$",
"this",
"->",
"getClientSearchLanguage",
"(",
")",
",",
"$",
"useWildcard",
")",
";",
"foreach",
"(",
"$",
"matchingTranslatables",
"as",
"$",
"translatable",
")",
"{",
"$",
"originalString",
"=",
"$",
"translatable",
"->",
"getOriginal",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"originalString",
")",
")",
"{",
"$",
"matchingTranslations",
"[",
"]",
"=",
"$",
"originalString",
";",
"}",
"}",
"return",
"array_unique",
"(",
"$",
"matchingTranslations",
")",
";",
"}"
] |
Looks up all matching Translatables and returns them uniquified
@return array matching english strings
|
[
"Looks",
"up",
"all",
"matching",
"Translatables",
"and",
"returns",
"them",
"uniquified"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/I18nBundle/Listener/I18nRqlParsingListener.php#L252-L279
|
26,305
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/ReadOnlyFieldsCompilerPass.php
|
ReadOnlyFieldsCompilerPass.process
|
public function process(ContainerBuilder $container)
{
$this->documentMap = $container->get('graviton.document.map');
$map = [];
foreach ($this->documentMap->getDocuments() as $document) {
$readOnlyFields = $this->documentMap->getFieldNamesFlat(
$document,
'',
'',
function ($field) {
return $field->isReadOnly();
}
);
if (!empty($readOnlyFields)) {
foreach ($readOnlyFields as $key => $readOnlyField) {
if (substr($readOnlyField, -2) == '.0') {
unset($readOnlyFields[$key]);
}
}
$map[$document->getClass()] = array_values($readOnlyFields);
}
}
$container->setParameter('graviton.document.readonly.fields', $map);
}
|
php
|
public function process(ContainerBuilder $container)
{
$this->documentMap = $container->get('graviton.document.map');
$map = [];
foreach ($this->documentMap->getDocuments() as $document) {
$readOnlyFields = $this->documentMap->getFieldNamesFlat(
$document,
'',
'',
function ($field) {
return $field->isReadOnly();
}
);
if (!empty($readOnlyFields)) {
foreach ($readOnlyFields as $key => $readOnlyField) {
if (substr($readOnlyField, -2) == '.0') {
unset($readOnlyFields[$key]);
}
}
$map[$document->getClass()] = array_values($readOnlyFields);
}
}
$container->setParameter('graviton.document.readonly.fields', $map);
}
|
[
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"this",
"->",
"documentMap",
"=",
"$",
"container",
"->",
"get",
"(",
"'graviton.document.map'",
")",
";",
"$",
"map",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"documentMap",
"->",
"getDocuments",
"(",
")",
"as",
"$",
"document",
")",
"{",
"$",
"readOnlyFields",
"=",
"$",
"this",
"->",
"documentMap",
"->",
"getFieldNamesFlat",
"(",
"$",
"document",
",",
"''",
",",
"''",
",",
"function",
"(",
"$",
"field",
")",
"{",
"return",
"$",
"field",
"->",
"isReadOnly",
"(",
")",
";",
"}",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"readOnlyFields",
")",
")",
"{",
"foreach",
"(",
"$",
"readOnlyFields",
"as",
"$",
"key",
"=>",
"$",
"readOnlyField",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"readOnlyField",
",",
"-",
"2",
")",
"==",
"'.0'",
")",
"{",
"unset",
"(",
"$",
"readOnlyFields",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"map",
"[",
"$",
"document",
"->",
"getClass",
"(",
")",
"]",
"=",
"array_values",
"(",
"$",
"readOnlyFields",
")",
";",
"}",
"}",
"$",
"container",
"->",
"setParameter",
"(",
"'graviton.document.readonly.fields'",
",",
"$",
"map",
")",
";",
"}"
] |
Make readOnly fields map and set it to parameter
@param ContainerBuilder $container container builder
@return void
|
[
"Make",
"readOnly",
"fields",
"map",
"and",
"set",
"it",
"to",
"parameter"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/ReadOnlyFieldsCompilerPass.php#L31-L58
|
26,306
|
duncan3dc/domparser
|
src/Html/Element.php
|
Element.hasClass
|
public function hasClass($className)
{
if (!$class = $this->dom->getAttribute("class")) {
return false;
}
$classes = explode(" ", $class);
return in_array($className, $classes, true);
}
|
php
|
public function hasClass($className)
{
if (!$class = $this->dom->getAttribute("class")) {
return false;
}
$classes = explode(" ", $class);
return in_array($className, $classes, true);
}
|
[
"public",
"function",
"hasClass",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"$",
"class",
"=",
"$",
"this",
"->",
"dom",
"->",
"getAttribute",
"(",
"\"class\"",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"classes",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"class",
")",
";",
"return",
"in_array",
"(",
"$",
"className",
",",
"$",
"classes",
",",
"true",
")",
";",
"}"
] |
Check if this element has the specified class applied to it.
@param string $className The name of the class to check for (case-sensitive)
@return bool
|
[
"Check",
"if",
"this",
"element",
"has",
"the",
"specified",
"class",
"applied",
"to",
"it",
"."
] |
d5523b58337cab3b9ad90e8d135f87793795f93f
|
https://github.com/duncan3dc/domparser/blob/d5523b58337cab3b9ad90e8d135f87793795f93f/src/Html/Element.php#L21-L30
|
26,307
|
libgraviton/graviton
|
src/Graviton/ExceptionBundle/Listener/RestExceptionListener.php
|
RestExceptionListener.getSerializedContent
|
public function getSerializedContent($content)
{
$serializationContext = clone $this->serializationContext;
return $this->serializer->serialize(
$content,
'json',
$serializationContext
);
}
|
php
|
public function getSerializedContent($content)
{
$serializationContext = clone $this->serializationContext;
return $this->serializer->serialize(
$content,
'json',
$serializationContext
);
}
|
[
"public",
"function",
"getSerializedContent",
"(",
"$",
"content",
")",
"{",
"$",
"serializationContext",
"=",
"clone",
"$",
"this",
"->",
"serializationContext",
";",
"return",
"$",
"this",
"->",
"serializer",
"->",
"serialize",
"(",
"$",
"content",
",",
"'json'",
",",
"$",
"serializationContext",
")",
";",
"}"
] |
Serialize the given content
@param mixed $content Content
@return string $content Json content
|
[
"Serialize",
"the",
"given",
"content"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ExceptionBundle/Listener/RestExceptionListener.php#L75-L84
|
26,308
|
libgraviton/graviton
|
src/Graviton/RestBundle/Restriction/Manager.php
|
Manager.handle
|
public function handle(DocumentRepository $repository)
{
$className = $repository->getClassName();
if (isset($this->restrictedFieldMap[$className]) && !empty($this->restrictedFieldMap[$className])) {
$nodes = [];
foreach ($this->restrictedFieldMap[$className] as $fieldPath => $handlers) {
$nodes = array_merge(
$nodes,
$this->getHandlerValue($repository, $fieldPath, $handlers)
);
}
return new AndNode($nodes);
}
return false;
}
|
php
|
public function handle(DocumentRepository $repository)
{
$className = $repository->getClassName();
if (isset($this->restrictedFieldMap[$className]) && !empty($this->restrictedFieldMap[$className])) {
$nodes = [];
foreach ($this->restrictedFieldMap[$className] as $fieldPath => $handlers) {
$nodes = array_merge(
$nodes,
$this->getHandlerValue($repository, $fieldPath, $handlers)
);
}
return new AndNode($nodes);
}
return false;
}
|
[
"public",
"function",
"handle",
"(",
"DocumentRepository",
"$",
"repository",
")",
"{",
"$",
"className",
"=",
"$",
"repository",
"->",
"getClassName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"restrictedFieldMap",
"[",
"$",
"className",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"restrictedFieldMap",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"nodes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"restrictedFieldMap",
"[",
"$",
"className",
"]",
"as",
"$",
"fieldPath",
"=>",
"$",
"handlers",
")",
"{",
"$",
"nodes",
"=",
"array_merge",
"(",
"$",
"nodes",
",",
"$",
"this",
"->",
"getHandlerValue",
"(",
"$",
"repository",
",",
"$",
"fieldPath",
",",
"$",
"handlers",
")",
")",
";",
"}",
"return",
"new",
"AndNode",
"(",
"$",
"nodes",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
handle the request for a given entity
@param DocumentRepository $repository repository
@return bool|AndNode either false if no restrictions or an AndNode for filtering
|
[
"handle",
"the",
"request",
"for",
"a",
"given",
"entity"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Restriction/Manager.php#L60-L74
|
26,309
|
libgraviton/graviton
|
src/Graviton/RestBundle/Restriction/Manager.php
|
Manager.getHandlerValue
|
private function getHandlerValue(DocumentRepository $repository, $fieldPath, array $handlers)
{
$nodes = [];
foreach ($handlers as $handler) {
if (!self::$handlers[$handler] instanceof HandlerInterface) {
throw new \LogicException(
'Specified handler "'.$handler.'" is not registered with RestrictionManager!'
);
}
$value = self::$handlers[$handler]->getValue($repository, $fieldPath);
if (!$value instanceof AbstractQueryNode) {
$value = new EqNode($fieldPath, $value);
}
$nodes[] = $value;
}
return $nodes;
}
|
php
|
private function getHandlerValue(DocumentRepository $repository, $fieldPath, array $handlers)
{
$nodes = [];
foreach ($handlers as $handler) {
if (!self::$handlers[$handler] instanceof HandlerInterface) {
throw new \LogicException(
'Specified handler "'.$handler.'" is not registered with RestrictionManager!'
);
}
$value = self::$handlers[$handler]->getValue($repository, $fieldPath);
if (!$value instanceof AbstractQueryNode) {
$value = new EqNode($fieldPath, $value);
}
$nodes[] = $value;
}
return $nodes;
}
|
[
"private",
"function",
"getHandlerValue",
"(",
"DocumentRepository",
"$",
"repository",
",",
"$",
"fieldPath",
",",
"array",
"$",
"handlers",
")",
"{",
"$",
"nodes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"handler",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"handlers",
"[",
"$",
"handler",
"]",
"instanceof",
"HandlerInterface",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Specified handler \"'",
".",
"$",
"handler",
".",
"'\" is not registered with RestrictionManager!'",
")",
";",
"}",
"$",
"value",
"=",
"self",
"::",
"$",
"handlers",
"[",
"$",
"handler",
"]",
"->",
"getValue",
"(",
"$",
"repository",
",",
"$",
"fieldPath",
")",
";",
"if",
"(",
"!",
"$",
"value",
"instanceof",
"AbstractQueryNode",
")",
"{",
"$",
"value",
"=",
"new",
"EqNode",
"(",
"$",
"fieldPath",
",",
"$",
"value",
")",
";",
"}",
"$",
"nodes",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"nodes",
";",
"}"
] |
gets the value to restrict data. the handler can also return a AbstractQueryNode. not only a string
@param DocumentRepository $repository the repository
@param string $fieldPath path to the field (can be complex; same syntax as in rql!)
@param array $handlers the specified handlers (array with handler names)
@return array the rql nodes
|
[
"gets",
"the",
"value",
"to",
"restrict",
"data",
".",
"the",
"handler",
"can",
"also",
"return",
"a",
"AbstractQueryNode",
".",
"not",
"only",
"a",
"string"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Restriction/Manager.php#L85-L104
|
26,310
|
libgraviton/graviton
|
src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php
|
LinkHeaderResponseListener.onKernelResponse
|
public function onKernelResponse(FilterResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$response = $event->getResponse();
$request = $event->getRequest();
// extract various info from route
$routeName = $request->get('_route');
$routeParts = explode('.', $routeName);
$routeType = end($routeParts);
$this->linkHeader = LinkHeader::fromResponse($response);
// add common headers
$this->addCommonHeaders($request, $response);
// add self Link header
$selfUrl = $this->addSelfLinkHeader($routeName, $routeType, $request);
// dispatch this!
// add paging Link element when applicable
if ($routeType == 'all' && $request->attributes->get('paging')) {
$this->generatePagingLinksHeaders($routeName, $request, $response);
}
// add schema link header element
$this->generateSchemaLinkHeader($routeName, $request, $response);
// finally set link header
$response->headers->set(
'Link',
(string) $this->linkHeader
);
$event->setResponse($response);
// dispatch the "selfaware" event
$event->getRequest()->attributes->set('selfLink', $selfUrl);
$dispatcher->dispatch('graviton.rest.response.selfaware', $event);
}
|
php
|
public function onKernelResponse(FilterResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$response = $event->getResponse();
$request = $event->getRequest();
// extract various info from route
$routeName = $request->get('_route');
$routeParts = explode('.', $routeName);
$routeType = end($routeParts);
$this->linkHeader = LinkHeader::fromResponse($response);
// add common headers
$this->addCommonHeaders($request, $response);
// add self Link header
$selfUrl = $this->addSelfLinkHeader($routeName, $routeType, $request);
// dispatch this!
// add paging Link element when applicable
if ($routeType == 'all' && $request->attributes->get('paging')) {
$this->generatePagingLinksHeaders($routeName, $request, $response);
}
// add schema link header element
$this->generateSchemaLinkHeader($routeName, $request, $response);
// finally set link header
$response->headers->set(
'Link',
(string) $this->linkHeader
);
$event->setResponse($response);
// dispatch the "selfaware" event
$event->getRequest()->attributes->set('selfLink', $selfUrl);
$dispatcher->dispatch('graviton.rest.response.selfaware', $event);
}
|
[
"public",
"function",
"onKernelResponse",
"(",
"FilterResponseEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"$",
"response",
"=",
"$",
"event",
"->",
"getResponse",
"(",
")",
";",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"// extract various info from route",
"$",
"routeName",
"=",
"$",
"request",
"->",
"get",
"(",
"'_route'",
")",
";",
"$",
"routeParts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"routeName",
")",
";",
"$",
"routeType",
"=",
"end",
"(",
"$",
"routeParts",
")",
";",
"$",
"this",
"->",
"linkHeader",
"=",
"LinkHeader",
"::",
"fromResponse",
"(",
"$",
"response",
")",
";",
"// add common headers",
"$",
"this",
"->",
"addCommonHeaders",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"// add self Link header",
"$",
"selfUrl",
"=",
"$",
"this",
"->",
"addSelfLinkHeader",
"(",
"$",
"routeName",
",",
"$",
"routeType",
",",
"$",
"request",
")",
";",
"// dispatch this!",
"// add paging Link element when applicable",
"if",
"(",
"$",
"routeType",
"==",
"'all'",
"&&",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'paging'",
")",
")",
"{",
"$",
"this",
"->",
"generatePagingLinksHeaders",
"(",
"$",
"routeName",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
"// add schema link header element",
"$",
"this",
"->",
"generateSchemaLinkHeader",
"(",
"$",
"routeName",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"// finally set link header",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Link'",
",",
"(",
"string",
")",
"$",
"this",
"->",
"linkHeader",
")",
";",
"$",
"event",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"// dispatch the \"selfaware\" event",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"attributes",
"->",
"set",
"(",
"'selfLink'",
",",
"$",
"selfUrl",
")",
";",
"$",
"dispatcher",
"->",
"dispatch",
"(",
"'graviton.rest.response.selfaware'",
",",
"$",
"event",
")",
";",
"}"
] |
add our Link header items
@param FilterResponseEvent $event response listener event
@param string $eventName event name
@param EventDispatcherInterface $dispatcher dispatcher
@return void
|
[
"add",
"our",
"Link",
"header",
"items"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php#L56-L94
|
26,311
|
libgraviton/graviton
|
src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php
|
LinkHeaderResponseListener.addCommonHeaders
|
private function addCommonHeaders(Request $request, Response $response)
{
// replace content-type if a schema was requested
if ($request->attributes->get('schemaRequest')) {
$response->headers->set('Content-Type', 'application/schema+json');
}
if ($request->attributes->has('recordCount')) {
$response->headers->set(
'X-Record-Count',
(string) $request->attributes->get('recordCount')
);
}
// search source header?
if ($request->attributes->has('X-Search-Source')) {
$response->headers->set(
'X-Search-Source',
(string) $request->attributes->get('X-Search-Source')
);
}
}
|
php
|
private function addCommonHeaders(Request $request, Response $response)
{
// replace content-type if a schema was requested
if ($request->attributes->get('schemaRequest')) {
$response->headers->set('Content-Type', 'application/schema+json');
}
if ($request->attributes->has('recordCount')) {
$response->headers->set(
'X-Record-Count',
(string) $request->attributes->get('recordCount')
);
}
// search source header?
if ($request->attributes->has('X-Search-Source')) {
$response->headers->set(
'X-Search-Source',
(string) $request->attributes->get('X-Search-Source')
);
}
}
|
[
"private",
"function",
"addCommonHeaders",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"// replace content-type if a schema was requested",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'schemaRequest'",
")",
")",
"{",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Type'",
",",
"'application/schema+json'",
")",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"has",
"(",
"'recordCount'",
")",
")",
"{",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'X-Record-Count'",
",",
"(",
"string",
")",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'recordCount'",
")",
")",
";",
"}",
"// search source header?",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"has",
"(",
"'X-Search-Source'",
")",
")",
"{",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'X-Search-Source'",
",",
"(",
"string",
")",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'X-Search-Source'",
")",
")",
";",
"}",
"}"
] |
add common headers
@param Request $request request
@param Response $response response
@return void
|
[
"add",
"common",
"headers"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php#L104-L125
|
26,312
|
libgraviton/graviton
|
src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php
|
LinkHeaderResponseListener.addSelfLinkHeader
|
private function addSelfLinkHeader($routeName, $routeType, Request $request)
{
$routeParams = $request->get('_route_params');
if (!is_array($routeParams)) {
$routeParams = [];
}
if (($routeType == 'post' || $routeType == 'postNoSlash') || $routeType != 'all') {
// handle post request by rewriting self link to newly created resource
$routeParams['id'] = $request->get('id');
}
// rewrite post routes to get
if ($routeType == 'post' || $routeType == 'postNoSlash') {
$parts = explode('.', $routeName);
array_pop($parts);
$parts[] = 'get';
$routeName = implode('.', $parts);
}
$selfLinkUrl = $this->router->generate($routeName, $routeParams, UrlGeneratorInterface::ABSOLUTE_URL);
$queryString = $request->server->get('QUERY_STRING', '');
// if no rql was set, we set our default current limits
if ($request->attributes->get('paging') === true && strpos($queryString, 'limit(') === false) {
$limit = sprintf(
'limit(%s,%s)',
$request->attributes->get('perPage'),
$request->attributes->get('startAt')
);
if (!empty($queryString)) {
$queryString .= '&';
}
$queryString .= $limit;
}
if (!empty($queryString)) {
$selfLinkUrl .= '?' . strtr($queryString, [',' => '%2C']);
}
$this->linkHeader->add(
new LinkHeaderItem(
$selfLinkUrl,
['rel' => 'self']
)
);
return $selfLinkUrl;
}
|
php
|
private function addSelfLinkHeader($routeName, $routeType, Request $request)
{
$routeParams = $request->get('_route_params');
if (!is_array($routeParams)) {
$routeParams = [];
}
if (($routeType == 'post' || $routeType == 'postNoSlash') || $routeType != 'all') {
// handle post request by rewriting self link to newly created resource
$routeParams['id'] = $request->get('id');
}
// rewrite post routes to get
if ($routeType == 'post' || $routeType == 'postNoSlash') {
$parts = explode('.', $routeName);
array_pop($parts);
$parts[] = 'get';
$routeName = implode('.', $parts);
}
$selfLinkUrl = $this->router->generate($routeName, $routeParams, UrlGeneratorInterface::ABSOLUTE_URL);
$queryString = $request->server->get('QUERY_STRING', '');
// if no rql was set, we set our default current limits
if ($request->attributes->get('paging') === true && strpos($queryString, 'limit(') === false) {
$limit = sprintf(
'limit(%s,%s)',
$request->attributes->get('perPage'),
$request->attributes->get('startAt')
);
if (!empty($queryString)) {
$queryString .= '&';
}
$queryString .= $limit;
}
if (!empty($queryString)) {
$selfLinkUrl .= '?' . strtr($queryString, [',' => '%2C']);
}
$this->linkHeader->add(
new LinkHeaderItem(
$selfLinkUrl,
['rel' => 'self']
)
);
return $selfLinkUrl;
}
|
[
"private",
"function",
"addSelfLinkHeader",
"(",
"$",
"routeName",
",",
"$",
"routeType",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"routeParams",
"=",
"$",
"request",
"->",
"get",
"(",
"'_route_params'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"routeParams",
")",
")",
"{",
"$",
"routeParams",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"(",
"$",
"routeType",
"==",
"'post'",
"||",
"$",
"routeType",
"==",
"'postNoSlash'",
")",
"||",
"$",
"routeType",
"!=",
"'all'",
")",
"{",
"// handle post request by rewriting self link to newly created resource",
"$",
"routeParams",
"[",
"'id'",
"]",
"=",
"$",
"request",
"->",
"get",
"(",
"'id'",
")",
";",
"}",
"// rewrite post routes to get",
"if",
"(",
"$",
"routeType",
"==",
"'post'",
"||",
"$",
"routeType",
"==",
"'postNoSlash'",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"routeName",
")",
";",
"array_pop",
"(",
"$",
"parts",
")",
";",
"$",
"parts",
"[",
"]",
"=",
"'get'",
";",
"$",
"routeName",
"=",
"implode",
"(",
"'.'",
",",
"$",
"parts",
")",
";",
"}",
"$",
"selfLinkUrl",
"=",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"$",
"routeName",
",",
"$",
"routeParams",
",",
"UrlGeneratorInterface",
"::",
"ABSOLUTE_URL",
")",
";",
"$",
"queryString",
"=",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'QUERY_STRING'",
",",
"''",
")",
";",
"// if no rql was set, we set our default current limits",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'paging'",
")",
"===",
"true",
"&&",
"strpos",
"(",
"$",
"queryString",
",",
"'limit('",
")",
"===",
"false",
")",
"{",
"$",
"limit",
"=",
"sprintf",
"(",
"'limit(%s,%s)'",
",",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'perPage'",
")",
",",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'startAt'",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"queryString",
")",
")",
"{",
"$",
"queryString",
".=",
"'&'",
";",
"}",
"$",
"queryString",
".=",
"$",
"limit",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"queryString",
")",
")",
"{",
"$",
"selfLinkUrl",
".=",
"'?'",
".",
"strtr",
"(",
"$",
"queryString",
",",
"[",
"','",
"=>",
"'%2C'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"linkHeader",
"->",
"add",
"(",
"new",
"LinkHeaderItem",
"(",
"$",
"selfLinkUrl",
",",
"[",
"'rel'",
"=>",
"'self'",
"]",
")",
")",
";",
"return",
"$",
"selfLinkUrl",
";",
"}"
] |
Add "self" Link header item
@param string $routeName route name
@param string $routeType route type
@param Request $request request
@return string the "self" link url
|
[
"Add",
"self",
"Link",
"header",
"item"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php#L136-L186
|
26,313
|
libgraviton/graviton
|
src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php
|
LinkHeaderResponseListener.generateSchemaLinkHeader
|
private function generateSchemaLinkHeader($routeName, Request $request, Response $response)
{
if ($request->get('_route') != 'graviton.core.static.main.all') {
try {
$schemaRoute = SchemaUtils::getSchemaRouteName($routeName);
$this->linkHeader->add(
new LinkHeaderItem(
$this->router->generate($schemaRoute, [], UrlGeneratorInterface::ABSOLUTE_URL),
['rel' => 'schema']
)
);
} catch (\Exception $e) {
// nothing to do..
}
}
}
|
php
|
private function generateSchemaLinkHeader($routeName, Request $request, Response $response)
{
if ($request->get('_route') != 'graviton.core.static.main.all') {
try {
$schemaRoute = SchemaUtils::getSchemaRouteName($routeName);
$this->linkHeader->add(
new LinkHeaderItem(
$this->router->generate($schemaRoute, [], UrlGeneratorInterface::ABSOLUTE_URL),
['rel' => 'schema']
)
);
} catch (\Exception $e) {
// nothing to do..
}
}
}
|
[
"private",
"function",
"generateSchemaLinkHeader",
"(",
"$",
"routeName",
",",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'_route'",
")",
"!=",
"'graviton.core.static.main.all'",
")",
"{",
"try",
"{",
"$",
"schemaRoute",
"=",
"SchemaUtils",
"::",
"getSchemaRouteName",
"(",
"$",
"routeName",
")",
";",
"$",
"this",
"->",
"linkHeader",
"->",
"add",
"(",
"new",
"LinkHeaderItem",
"(",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"$",
"schemaRoute",
",",
"[",
"]",
",",
"UrlGeneratorInterface",
"::",
"ABSOLUTE_URL",
")",
",",
"[",
"'rel'",
"=>",
"'schema'",
"]",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// nothing to do..",
"}",
"}",
"}"
] |
generates the schema rel in the Link header
@param string $routeName route name
@param Request $request request
@param Response $response response
@return void
|
[
"generates",
"the",
"schema",
"rel",
"in",
"the",
"Link",
"header"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php#L198-L213
|
26,314
|
libgraviton/graviton
|
src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php
|
LinkHeaderResponseListener.generatePagingLinksHeaders
|
private function generatePagingLinksHeaders($routeName, Request $request, Response $response)
{
$rql = '';
if ($request->attributes->get('hasRql', false)) {
$rql = $request->attributes->get('rawRql', '');
}
$this->generateLinks(
$routeName,
$request->attributes->get('page'),
$request->attributes->get('numPages'),
$request->attributes->get('perPage'),
$request,
$rql
);
$response->headers->set(
'X-Total-Count',
(string) $request->attributes->get('totalCount')
);
}
|
php
|
private function generatePagingLinksHeaders($routeName, Request $request, Response $response)
{
$rql = '';
if ($request->attributes->get('hasRql', false)) {
$rql = $request->attributes->get('rawRql', '');
}
$this->generateLinks(
$routeName,
$request->attributes->get('page'),
$request->attributes->get('numPages'),
$request->attributes->get('perPage'),
$request,
$rql
);
$response->headers->set(
'X-Total-Count',
(string) $request->attributes->get('totalCount')
);
}
|
[
"private",
"function",
"generatePagingLinksHeaders",
"(",
"$",
"routeName",
",",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"rql",
"=",
"''",
";",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'hasRql'",
",",
"false",
")",
")",
"{",
"$",
"rql",
"=",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'rawRql'",
",",
"''",
")",
";",
"}",
"$",
"this",
"->",
"generateLinks",
"(",
"$",
"routeName",
",",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'page'",
")",
",",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'numPages'",
")",
",",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'perPage'",
")",
",",
"$",
"request",
",",
"$",
"rql",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'X-Total-Count'",
",",
"(",
"string",
")",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'totalCount'",
")",
")",
";",
"}"
] |
generates the paging Link header items
@param string $routeName route name
@param Request $request request
@param Response $response response
@return void
|
[
"generates",
"the",
"paging",
"Link",
"header",
"items"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php#L224-L244
|
26,315
|
libgraviton/graviton
|
src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php
|
LinkHeaderResponseListener.generateLinks
|
private function generateLinks($route, $page, $numPages, $perPage, Request $request, $rql)
{
if ($page > 2) {
$this->generateLink($route, 1, $perPage, 'first', $request, $rql);
}
if ($page > 1) {
$this->generateLink($route, $page - 1, $perPage, 'prev', $request, $rql);
}
if ($page < $numPages) {
$this->generateLink($route, $page + 1, $perPage, 'next', $request, $rql);
}
if ($page != $numPages) {
$this->generateLink($route, $numPages, $perPage, 'last', $request, $rql);
}
}
|
php
|
private function generateLinks($route, $page, $numPages, $perPage, Request $request, $rql)
{
if ($page > 2) {
$this->generateLink($route, 1, $perPage, 'first', $request, $rql);
}
if ($page > 1) {
$this->generateLink($route, $page - 1, $perPage, 'prev', $request, $rql);
}
if ($page < $numPages) {
$this->generateLink($route, $page + 1, $perPage, 'next', $request, $rql);
}
if ($page != $numPages) {
$this->generateLink($route, $numPages, $perPage, 'last', $request, $rql);
}
}
|
[
"private",
"function",
"generateLinks",
"(",
"$",
"route",
",",
"$",
"page",
",",
"$",
"numPages",
",",
"$",
"perPage",
",",
"Request",
"$",
"request",
",",
"$",
"rql",
")",
"{",
"if",
"(",
"$",
"page",
">",
"2",
")",
"{",
"$",
"this",
"->",
"generateLink",
"(",
"$",
"route",
",",
"1",
",",
"$",
"perPage",
",",
"'first'",
",",
"$",
"request",
",",
"$",
"rql",
")",
";",
"}",
"if",
"(",
"$",
"page",
">",
"1",
")",
"{",
"$",
"this",
"->",
"generateLink",
"(",
"$",
"route",
",",
"$",
"page",
"-",
"1",
",",
"$",
"perPage",
",",
"'prev'",
",",
"$",
"request",
",",
"$",
"rql",
")",
";",
"}",
"if",
"(",
"$",
"page",
"<",
"$",
"numPages",
")",
"{",
"$",
"this",
"->",
"generateLink",
"(",
"$",
"route",
",",
"$",
"page",
"+",
"1",
",",
"$",
"perPage",
",",
"'next'",
",",
"$",
"request",
",",
"$",
"rql",
")",
";",
"}",
"if",
"(",
"$",
"page",
"!=",
"$",
"numPages",
")",
"{",
"$",
"this",
"->",
"generateLink",
"(",
"$",
"route",
",",
"$",
"numPages",
",",
"$",
"perPage",
",",
"'last'",
",",
"$",
"request",
",",
"$",
"rql",
")",
";",
"}",
"}"
] |
generate headers for all paging links
@param string $route name of route
@param integer $page page to link to
@param integer $numPages number of all pages
@param integer $perPage number of records per page
@param Request $request request to get rawRql from
@param string $rql rql query string
@return void
|
[
"generate",
"headers",
"for",
"all",
"paging",
"links"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php#L258-L272
|
26,316
|
libgraviton/graviton
|
src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php
|
LinkHeaderResponseListener.generateLink
|
private function generateLink($routeName, $page, $perPage, $type, Request $request, $rql)
{
$limit = '';
if ($perPage) {
$page = ($page - 1) * $perPage;
$limit = sprintf('limit(%s,%s)', $perPage, $page);
}
if (strpos($rql, 'limit') !== false) {
$rql = preg_replace('/limit\(.*\)/U', $limit, $rql);
} elseif (empty($rql)) {
$rql .= $limit;
} else {
$rql .= '&'.$limit;
}
$url = $this->getRqlUrl(
$request,
$this->router->generate($routeName, [], UrlGeneratorInterface::ABSOLUTE_URL) .
'?' . strtr($rql, [',' => '%2C'])
);
$this->linkHeader->add(new LinkHeaderItem($url, array('rel' => $type)));
}
|
php
|
private function generateLink($routeName, $page, $perPage, $type, Request $request, $rql)
{
$limit = '';
if ($perPage) {
$page = ($page - 1) * $perPage;
$limit = sprintf('limit(%s,%s)', $perPage, $page);
}
if (strpos($rql, 'limit') !== false) {
$rql = preg_replace('/limit\(.*\)/U', $limit, $rql);
} elseif (empty($rql)) {
$rql .= $limit;
} else {
$rql .= '&'.$limit;
}
$url = $this->getRqlUrl(
$request,
$this->router->generate($routeName, [], UrlGeneratorInterface::ABSOLUTE_URL) .
'?' . strtr($rql, [',' => '%2C'])
);
$this->linkHeader->add(new LinkHeaderItem($url, array('rel' => $type)));
}
|
[
"private",
"function",
"generateLink",
"(",
"$",
"routeName",
",",
"$",
"page",
",",
"$",
"perPage",
",",
"$",
"type",
",",
"Request",
"$",
"request",
",",
"$",
"rql",
")",
"{",
"$",
"limit",
"=",
"''",
";",
"if",
"(",
"$",
"perPage",
")",
"{",
"$",
"page",
"=",
"(",
"$",
"page",
"-",
"1",
")",
"*",
"$",
"perPage",
";",
"$",
"limit",
"=",
"sprintf",
"(",
"'limit(%s,%s)'",
",",
"$",
"perPage",
",",
"$",
"page",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"rql",
",",
"'limit'",
")",
"!==",
"false",
")",
"{",
"$",
"rql",
"=",
"preg_replace",
"(",
"'/limit\\(.*\\)/U'",
",",
"$",
"limit",
",",
"$",
"rql",
")",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"rql",
")",
")",
"{",
"$",
"rql",
".=",
"$",
"limit",
";",
"}",
"else",
"{",
"$",
"rql",
".=",
"'&'",
".",
"$",
"limit",
";",
"}",
"$",
"url",
"=",
"$",
"this",
"->",
"getRqlUrl",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"$",
"routeName",
",",
"[",
"]",
",",
"UrlGeneratorInterface",
"::",
"ABSOLUTE_URL",
")",
".",
"'?'",
".",
"strtr",
"(",
"$",
"rql",
",",
"[",
"','",
"=>",
"'%2C'",
"]",
")",
")",
";",
"$",
"this",
"->",
"linkHeader",
"->",
"add",
"(",
"new",
"LinkHeaderItem",
"(",
"$",
"url",
",",
"array",
"(",
"'rel'",
"=>",
"$",
"type",
")",
")",
")",
";",
"}"
] |
generate link header passed on params and type
@param string $routeName use with router to generate urls
@param integer $page page to link to
@param integer $perPage number of items per page
@param string $type rel type of link to generate
@param Request $request request to get rawRql from
@param string $rql rql query string
@return string
|
[
"generate",
"link",
"header",
"passed",
"on",
"params",
"and",
"type"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php#L286-L308
|
26,317
|
libgraviton/graviton
|
src/Graviton/AnalyticsBundle/Model/AnalyticModel.php
|
AnalyticModel.getAggregate
|
public function getAggregate($params = [])
{
if ($this->getMultipipeline()) {
$pipelines = [];
foreach ($this->class as $name => $className) {
if (!class_exists($className)) {
throw new \LogicException("Analytics class '" . $className . "' does not exist!");
}
$class = new $className();
$class->setParams($params);
$pipelines[$name] = $class->get();
}
return $pipelines;
} else {
$className = $this->class;
if (!class_exists($className)) {
throw new \LogicException("Analytics class '" . $className . "' does not exist!");
}
$class = new $className();
$class->setParams($params);
return $class->get();
}
}
|
php
|
public function getAggregate($params = [])
{
if ($this->getMultipipeline()) {
$pipelines = [];
foreach ($this->class as $name => $className) {
if (!class_exists($className)) {
throw new \LogicException("Analytics class '" . $className . "' does not exist!");
}
$class = new $className();
$class->setParams($params);
$pipelines[$name] = $class->get();
}
return $pipelines;
} else {
$className = $this->class;
if (!class_exists($className)) {
throw new \LogicException("Analytics class '" . $className . "' does not exist!");
}
$class = new $className();
$class->setParams($params);
return $class->get();
}
}
|
[
"public",
"function",
"getAggregate",
"(",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getMultipipeline",
"(",
")",
")",
"{",
"$",
"pipelines",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"class",
"as",
"$",
"name",
"=>",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"Analytics class '\"",
".",
"$",
"className",
".",
"\"' does not exist!\"",
")",
";",
"}",
"$",
"class",
"=",
"new",
"$",
"className",
"(",
")",
";",
"$",
"class",
"->",
"setParams",
"(",
"$",
"params",
")",
";",
"$",
"pipelines",
"[",
"$",
"name",
"]",
"=",
"$",
"class",
"->",
"get",
"(",
")",
";",
"}",
"return",
"$",
"pipelines",
";",
"}",
"else",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"class",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"Analytics class '\"",
".",
"$",
"className",
".",
"\"' does not exist!\"",
")",
";",
"}",
"$",
"class",
"=",
"new",
"$",
"className",
"(",
")",
";",
"$",
"class",
"->",
"setParams",
"(",
"$",
"params",
")",
";",
"return",
"$",
"class",
"->",
"get",
"(",
")",
";",
"}",
"}"
] |
Build a output Db Model aggregation pipeline array.
@param array $params params
@return array the pipeline
|
[
"Build",
"a",
"output",
"Db",
"Model",
"aggregation",
"pipeline",
"array",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/AnalyticsBundle/Model/AnalyticModel.php#L279-L301
|
26,318
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/RestrictionFieldsCompilerPass.php
|
RestrictionFieldsCompilerPass.process
|
public function process(ContainerBuilder $container)
{
$this->documentMap = $container->get('graviton.document.map');
$map = [];
foreach ($this->documentMap->getDocuments() as $document) {
$restrictionFields = $this->documentMap->getFieldNamesFlat(
$document,
'',
'',
function ($field) {
return $field->getRestrictions();
},
true
);
$finalRestrictionFields = [];
foreach ($restrictionFields as $key => $field) {
// cleanup name! .0. has to be .. for rql!
$key = preg_replace('@\.([0-9]+)\.@i', '..', $key);
$finalRestrictionFields[$key] = $field->getRestrictions();
}
$map[$document->getClass()] = $finalRestrictionFields;
}
$container->setParameter('graviton.document.restriction.fields', $map);
}
|
php
|
public function process(ContainerBuilder $container)
{
$this->documentMap = $container->get('graviton.document.map');
$map = [];
foreach ($this->documentMap->getDocuments() as $document) {
$restrictionFields = $this->documentMap->getFieldNamesFlat(
$document,
'',
'',
function ($field) {
return $field->getRestrictions();
},
true
);
$finalRestrictionFields = [];
foreach ($restrictionFields as $key => $field) {
// cleanup name! .0. has to be .. for rql!
$key = preg_replace('@\.([0-9]+)\.@i', '..', $key);
$finalRestrictionFields[$key] = $field->getRestrictions();
}
$map[$document->getClass()] = $finalRestrictionFields;
}
$container->setParameter('graviton.document.restriction.fields', $map);
}
|
[
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"this",
"->",
"documentMap",
"=",
"$",
"container",
"->",
"get",
"(",
"'graviton.document.map'",
")",
";",
"$",
"map",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"documentMap",
"->",
"getDocuments",
"(",
")",
"as",
"$",
"document",
")",
"{",
"$",
"restrictionFields",
"=",
"$",
"this",
"->",
"documentMap",
"->",
"getFieldNamesFlat",
"(",
"$",
"document",
",",
"''",
",",
"''",
",",
"function",
"(",
"$",
"field",
")",
"{",
"return",
"$",
"field",
"->",
"getRestrictions",
"(",
")",
";",
"}",
",",
"true",
")",
";",
"$",
"finalRestrictionFields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"restrictionFields",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"// cleanup name! .0. has to be .. for rql!",
"$",
"key",
"=",
"preg_replace",
"(",
"'@\\.([0-9]+)\\.@i'",
",",
"'..'",
",",
"$",
"key",
")",
";",
"$",
"finalRestrictionFields",
"[",
"$",
"key",
"]",
"=",
"$",
"field",
"->",
"getRestrictions",
"(",
")",
";",
"}",
"$",
"map",
"[",
"$",
"document",
"->",
"getClass",
"(",
")",
"]",
"=",
"$",
"finalRestrictionFields",
";",
"}",
"$",
"container",
"->",
"setParameter",
"(",
"'graviton.document.restriction.fields'",
",",
"$",
"map",
")",
";",
"}"
] |
prepare a map of base data restrictions for Restriction\Manager
@param ContainerBuilder $container container builder
@return void
|
[
"prepare",
"a",
"map",
"of",
"base",
"data",
"restrictions",
"for",
"Restriction",
"\\",
"Manager"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/RestrictionFieldsCompilerPass.php#L31-L58
|
26,319
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/Loader/Strategy/DirStrategy.php
|
DirStrategy.load
|
public function load($input)
{
return array_map(
function (SplFileInfo $file) {
return $file->getContents();
},
array_values(iterator_to_array($this->getFinder($input)))
);
}
|
php
|
public function load($input)
{
return array_map(
function (SplFileInfo $file) {
return $file->getContents();
},
array_values(iterator_to_array($this->getFinder($input)))
);
}
|
[
"public",
"function",
"load",
"(",
"$",
"input",
")",
"{",
"return",
"array_map",
"(",
"function",
"(",
"SplFileInfo",
"$",
"file",
")",
"{",
"return",
"$",
"file",
"->",
"getContents",
"(",
")",
";",
"}",
",",
"array_values",
"(",
"iterator_to_array",
"(",
"$",
"this",
"->",
"getFinder",
"(",
"$",
"input",
")",
")",
")",
")",
";",
"}"
] |
load raw JSON data
@param string|null $input input from command
@return string[]
|
[
"load",
"raw",
"JSON",
"data"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/Loader/Strategy/DirStrategy.php#L37-L45
|
26,320
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/DocumentFieldNamesCompilerPass.php
|
DocumentFieldNamesCompilerPass.getFieldNames
|
private function getFieldNames(Document $document)
{
$result = [];
foreach ($document->getFields() as $field) {
$result[$field->getFieldName()] = $field->getExposedName();
}
return $result;
}
|
php
|
private function getFieldNames(Document $document)
{
$result = [];
foreach ($document->getFields() as $field) {
$result[$field->getFieldName()] = $field->getExposedName();
}
return $result;
}
|
[
"private",
"function",
"getFieldNames",
"(",
"Document",
"$",
"document",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"document",
"->",
"getFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"result",
"[",
"$",
"field",
"->",
"getFieldName",
"(",
")",
"]",
"=",
"$",
"field",
"->",
"getExposedName",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Get field names
@param Document $document Document
@return array
|
[
"Get",
"field",
"names"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/DocumentFieldNamesCompilerPass.php#L49-L56
|
26,321
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Composer/ScriptHandler.php
|
ScriptHandler.generateDynamicBundles
|
public static function generateDynamicBundles(Event $event)
{
$options = self::getOptions($event);
$consolePath = $options['symfony-app-dir'];
$cmd = escapeshellarg('graviton:generate:dynamicbundles').' --json';
self::executeCommand($event, $consolePath, $cmd);
}
|
php
|
public static function generateDynamicBundles(Event $event)
{
$options = self::getOptions($event);
$consolePath = $options['symfony-app-dir'];
$cmd = escapeshellarg('graviton:generate:dynamicbundles').' --json';
self::executeCommand($event, $consolePath, $cmd);
}
|
[
"public",
"static",
"function",
"generateDynamicBundles",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"options",
"=",
"self",
"::",
"getOptions",
"(",
"$",
"event",
")",
";",
"$",
"consolePath",
"=",
"$",
"options",
"[",
"'symfony-app-dir'",
"]",
";",
"$",
"cmd",
"=",
"escapeshellarg",
"(",
"'graviton:generate:dynamicbundles'",
")",
".",
"' --json'",
";",
"self",
"::",
"executeCommand",
"(",
"$",
"event",
",",
"$",
"consolePath",
",",
"$",
"cmd",
")",
";",
"}"
] |
Generates dynamic bundles
@param CommandEvent $event Event
@return void
|
[
"Generates",
"dynamic",
"bundles"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Composer/ScriptHandler.php#L27-L34
|
26,322
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/Utils/ConstraintNormalizer.php
|
ConstraintNormalizer.normalize
|
public static function normalize(Constraint $constraint)
{
return [
'name' => $constraint->getName(),
'options' => array_map(
function (ConstraintOption $option) {
return [
'name' => $option->getName(),
'value' => $option->getValue(),
];
},
$constraint->getOptions()
),
];
}
|
php
|
public static function normalize(Constraint $constraint)
{
return [
'name' => $constraint->getName(),
'options' => array_map(
function (ConstraintOption $option) {
return [
'name' => $option->getName(),
'value' => $option->getValue(),
];
},
$constraint->getOptions()
),
];
}
|
[
"public",
"static",
"function",
"normalize",
"(",
"Constraint",
"$",
"constraint",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"constraint",
"->",
"getName",
"(",
")",
",",
"'options'",
"=>",
"array_map",
"(",
"function",
"(",
"ConstraintOption",
"$",
"option",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"option",
"->",
"getName",
"(",
")",
",",
"'value'",
"=>",
"$",
"option",
"->",
"getValue",
"(",
")",
",",
"]",
";",
"}",
",",
"$",
"constraint",
"->",
"getOptions",
"(",
")",
")",
",",
"]",
";",
"}"
] |
Convert constraint to array to selerialile it via json_encode
@param Constraint $constraint Constraint
@return array
|
[
"Convert",
"constraint",
"to",
"array",
"to",
"selerialile",
"it",
"via",
"json_encode"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/Utils/ConstraintNormalizer.php#L25-L39
|
26,323
|
libgraviton/graviton
|
src/Graviton/LogBundle/Monolog/Processor/RequestIdProcessor.php
|
RequestIdProcessor.processRecord
|
public function processRecord(array $record)
{
if (is_null($this->requestId)) {
$this->requestId = uniqid('');
}
$record['extra']['requestId'] = $this->requestId;
return $record;
}
|
php
|
public function processRecord(array $record)
{
if (is_null($this->requestId)) {
$this->requestId = uniqid('');
}
$record['extra']['requestId'] = $this->requestId;
return $record;
}
|
[
"public",
"function",
"processRecord",
"(",
"array",
"$",
"record",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"requestId",
")",
")",
"{",
"$",
"this",
"->",
"requestId",
"=",
"uniqid",
"(",
"''",
")",
";",
"}",
"$",
"record",
"[",
"'extra'",
"]",
"[",
"'requestId'",
"]",
"=",
"$",
"this",
"->",
"requestId",
";",
"return",
"$",
"record",
";",
"}"
] |
processes the record and adds a random request id
@param array $record record
@return array new record
|
[
"processes",
"the",
"record",
"and",
"adds",
"a",
"random",
"request",
"id"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/LogBundle/Monolog/Processor/RequestIdProcessor.php#L28-L37
|
26,324
|
libgraviton/graviton
|
src/Graviton/SecurityBundle/Authentication/Strategies/CookieFieldStrategy.php
|
CookieFieldStrategy.apply
|
public function apply(Request $request)
{
$bagValue = $this->extractFieldInfo($request->cookies, $this->field);
// this needs to be available in a later state of the application
$this->extractAdUsername($request, $bagValue);
return $this->extractCoreId($request, $bagValue);
}
|
php
|
public function apply(Request $request)
{
$bagValue = $this->extractFieldInfo($request->cookies, $this->field);
// this needs to be available in a later state of the application
$this->extractAdUsername($request, $bagValue);
return $this->extractCoreId($request, $bagValue);
}
|
[
"public",
"function",
"apply",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"bagValue",
"=",
"$",
"this",
"->",
"extractFieldInfo",
"(",
"$",
"request",
"->",
"cookies",
",",
"$",
"this",
"->",
"field",
")",
";",
"// this needs to be available in a later state of the application",
"$",
"this",
"->",
"extractAdUsername",
"(",
"$",
"request",
",",
"$",
"bagValue",
")",
";",
"return",
"$",
"this",
"->",
"extractCoreId",
"(",
"$",
"request",
",",
"$",
"bagValue",
")",
";",
"}"
] |
Applies the defined strategy on the provided request.
Value may contain a coma separated string values, we use first as identifier.
@param Request $request request to handle
@return string
|
[
"Applies",
"the",
"defined",
"strategy",
"on",
"the",
"provided",
"request",
".",
"Value",
"may",
"contain",
"a",
"coma",
"separated",
"string",
"values",
"we",
"use",
"first",
"as",
"identifier",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SecurityBundle/Authentication/Strategies/CookieFieldStrategy.php#L52-L60
|
26,325
|
libgraviton/graviton
|
src/Graviton/SecurityBundle/Authentication/Strategies/CookieFieldStrategy.php
|
CookieFieldStrategy.extractAdUsername
|
protected function extractAdUsername(Request $request, $value)
{
$pattern = "/((?m)(?<=\b".self::COOKIE_FIELD_NAME."=)[^;]*)/i";
preg_match($pattern, $value, $matches);
if ($matches) {
$request->attributes->set(self::CONFIGURATION_PARAMETER_USER_ID, $matches[0]);
return $matches[0];
}
return $value;
}
|
php
|
protected function extractAdUsername(Request $request, $value)
{
$pattern = "/((?m)(?<=\b".self::COOKIE_FIELD_NAME."=)[^;]*)/i";
preg_match($pattern, $value, $matches);
if ($matches) {
$request->attributes->set(self::CONFIGURATION_PARAMETER_USER_ID, $matches[0]);
return $matches[0];
}
return $value;
}
|
[
"protected",
"function",
"extractAdUsername",
"(",
"Request",
"$",
"request",
",",
"$",
"value",
")",
"{",
"$",
"pattern",
"=",
"\"/((?m)(?<=\\b\"",
".",
"self",
"::",
"COOKIE_FIELD_NAME",
".",
"\"=)[^;]*)/i\"",
";",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"value",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"matches",
")",
"{",
"$",
"request",
"->",
"attributes",
"->",
"set",
"(",
"self",
"::",
"CONFIGURATION_PARAMETER_USER_ID",
",",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"return",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Finds and extracts the ad username from the cookie.
@param Request $request Request stack that controls the lifecycle of requests
@param string $value The string the value of self::COOKIE_FIELD_NAME shall be extracted from.
@return string
|
[
"Finds",
"and",
"extracts",
"the",
"ad",
"username",
"from",
"the",
"cookie",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SecurityBundle/Authentication/Strategies/CookieFieldStrategy.php#L80-L92
|
26,326
|
libgraviton/graviton
|
src/Graviton/SecurityBundle/Authentication/Strategies/CookieFieldStrategy.php
|
CookieFieldStrategy.extractCoreId
|
protected function extractCoreId(Request $request, $text)
{
$pattern = "/((?m)(?<=\b".self::COOKIE_VALUE_CORE_ID."=)[^;]*)/i";
preg_match($pattern, $text, $matches);
if ($matches) {
$request->attributes->set(self::CONFIGURATION_PARAMETER_CORE_ID, $matches[0]);
return $matches[0];
}
return $text;
}
|
php
|
protected function extractCoreId(Request $request, $text)
{
$pattern = "/((?m)(?<=\b".self::COOKIE_VALUE_CORE_ID."=)[^;]*)/i";
preg_match($pattern, $text, $matches);
if ($matches) {
$request->attributes->set(self::CONFIGURATION_PARAMETER_CORE_ID, $matches[0]);
return $matches[0];
}
return $text;
}
|
[
"protected",
"function",
"extractCoreId",
"(",
"Request",
"$",
"request",
",",
"$",
"text",
")",
"{",
"$",
"pattern",
"=",
"\"/((?m)(?<=\\b\"",
".",
"self",
"::",
"COOKIE_VALUE_CORE_ID",
".",
"\"=)[^;]*)/i\"",
";",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"text",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"matches",
")",
"{",
"$",
"request",
"->",
"attributes",
"->",
"set",
"(",
"self",
"::",
"CONFIGURATION_PARAMETER_CORE_ID",
",",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"return",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"text",
";",
"}"
] |
Finds and extracts the core system id from tha cookie.
@param Request $request Request stack that controls the lifecycle of requests
@param string $text String to be examined for the core id.
@return string
|
[
"Finds",
"and",
"extracts",
"the",
"core",
"system",
"id",
"from",
"tha",
"cookie",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SecurityBundle/Authentication/Strategies/CookieFieldStrategy.php#L102-L114
|
26,327
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/Entity/Translatable.php
|
Translatable.getDefaultLanguage
|
public static function getDefaultLanguage()
{
if (!is_null(self::$defaultLanguage)) {
return self::$defaultLanguage;
}
if (!file_exists(self::$defaultLanguageFile)) {
throw new \LogicException('Default language file '.self::$defaultLanguageFile.' does not exist');
}
self::$defaultLanguage = file_get_contents(self::$defaultLanguageFile);
return self::$defaultLanguage;
}
|
php
|
public static function getDefaultLanguage()
{
if (!is_null(self::$defaultLanguage)) {
return self::$defaultLanguage;
}
if (!file_exists(self::$defaultLanguageFile)) {
throw new \LogicException('Default language file '.self::$defaultLanguageFile.' does not exist');
}
self::$defaultLanguage = file_get_contents(self::$defaultLanguageFile);
return self::$defaultLanguage;
}
|
[
"public",
"static",
"function",
"getDefaultLanguage",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"self",
"::",
"$",
"defaultLanguage",
")",
")",
"{",
"return",
"self",
"::",
"$",
"defaultLanguage",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"self",
"::",
"$",
"defaultLanguageFile",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Default language file '",
".",
"self",
"::",
"$",
"defaultLanguageFile",
".",
"' does not exist'",
")",
";",
"}",
"self",
"::",
"$",
"defaultLanguage",
"=",
"file_get_contents",
"(",
"self",
"::",
"$",
"defaultLanguageFile",
")",
";",
"return",
"self",
"::",
"$",
"defaultLanguage",
";",
"}"
] |
returns the default language as statically generated in a file
@return string default language
|
[
"returns",
"the",
"default",
"language",
"as",
"statically",
"generated",
"in",
"a",
"file"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Entity/Translatable.php#L60-L72
|
26,328
|
libgraviton/graviton
|
src/Graviton/SecurityBundle/Authentication/Strategies/MultiStrategy.php
|
MultiStrategy.apply
|
public function apply(Request $request)
{
foreach ($this->strategies as $strategy) {
$name = $strategy->apply($request);
if ($strategy->stopPropagation()) {
$this->roles = $strategy->getRoles();
return $name;
}
}
return false;
}
|
php
|
public function apply(Request $request)
{
foreach ($this->strategies as $strategy) {
$name = $strategy->apply($request);
if ($strategy->stopPropagation()) {
$this->roles = $strategy->getRoles();
return $name;
}
}
return false;
}
|
[
"public",
"function",
"apply",
"(",
"Request",
"$",
"request",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"strategies",
"as",
"$",
"strategy",
")",
"{",
"$",
"name",
"=",
"$",
"strategy",
"->",
"apply",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"strategy",
"->",
"stopPropagation",
"(",
")",
")",
"{",
"$",
"this",
"->",
"roles",
"=",
"$",
"strategy",
"->",
"getRoles",
"(",
")",
";",
"return",
"$",
"name",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Applies the defined strategies on the provided request.
@param Request $request request to handle
@return string
|
[
"Applies",
"the",
"defined",
"strategies",
"on",
"the",
"provided",
"request",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SecurityBundle/Authentication/Strategies/MultiStrategy.php#L45-L56
|
26,329
|
libgraviton/graviton
|
src/Graviton/RestBundle/Restriction/Handler/Whoami.php
|
Whoami.getValue
|
public function getValue(DocumentRepository $repository, $fieldPath)
{
$user = 'anonymous';
$securityUser = $this->securityUtils->getSecurityUser();
if ($securityUser instanceof SecurityUser) {
$user = trim(strtolower($securityUser->getUsername()));
}
return $user;
}
|
php
|
public function getValue(DocumentRepository $repository, $fieldPath)
{
$user = 'anonymous';
$securityUser = $this->securityUtils->getSecurityUser();
if ($securityUser instanceof SecurityUser) {
$user = trim(strtolower($securityUser->getUsername()));
}
return $user;
}
|
[
"public",
"function",
"getValue",
"(",
"DocumentRepository",
"$",
"repository",
",",
"$",
"fieldPath",
")",
"{",
"$",
"user",
"=",
"'anonymous'",
";",
"$",
"securityUser",
"=",
"$",
"this",
"->",
"securityUtils",
"->",
"getSecurityUser",
"(",
")",
";",
"if",
"(",
"$",
"securityUser",
"instanceof",
"SecurityUser",
")",
"{",
"$",
"user",
"=",
"trim",
"(",
"strtolower",
"(",
"$",
"securityUser",
"->",
"getUsername",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] |
gets the actual value or an AbstractQueryNode that is used to filter the data.
@param DocumentRepository $repository the repository
@param string $fieldPath field path
@return string|AbstractQueryNode string for eq() filtering or a AbstractQueryNode instance
|
[
"gets",
"the",
"actual",
"value",
"or",
"an",
"AbstractQueryNode",
"that",
"is",
"used",
"to",
"filter",
"the",
"data",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Restriction/Handler/Whoami.php#L52-L62
|
26,330
|
libgraviton/graviton
|
src/Graviton/RestBundle/Serializer/ContextFactoryAbstract.php
|
ContextFactoryAbstract.workOnInstance
|
protected function workOnInstance(Context $context)
{
$context = $context->setSerializeNull($this->setSerializeNull);
// group override?
if (true === $this->overrideHeaderAllowed &&
$this->requestStack instanceof RequestStack &&
$this->requestStack->getCurrentRequest() instanceof Request
) {
$headerValue = $this->requestStack->getCurrentRequest()->headers->get($this->overrideHeaderName);
if (!is_null($headerValue)) {
$this->groups = array_map('trim', explode(',', $headerValue));
}
}
$serializerGroups = [GroupsExclusionStrategy::DEFAULT_GROUP];
if (is_array($this->groups) && !empty($this->groups)) {
$serializerGroups = array_merge($serializerGroups, $this->groups);
}
foreach ($this->exclusionStrategies as $strategy) {
$context->addExclusionStrategy($strategy);
}
return $context->setGroups($serializerGroups);
}
|
php
|
protected function workOnInstance(Context $context)
{
$context = $context->setSerializeNull($this->setSerializeNull);
// group override?
if (true === $this->overrideHeaderAllowed &&
$this->requestStack instanceof RequestStack &&
$this->requestStack->getCurrentRequest() instanceof Request
) {
$headerValue = $this->requestStack->getCurrentRequest()->headers->get($this->overrideHeaderName);
if (!is_null($headerValue)) {
$this->groups = array_map('trim', explode(',', $headerValue));
}
}
$serializerGroups = [GroupsExclusionStrategy::DEFAULT_GROUP];
if (is_array($this->groups) && !empty($this->groups)) {
$serializerGroups = array_merge($serializerGroups, $this->groups);
}
foreach ($this->exclusionStrategies as $strategy) {
$context->addExclusionStrategy($strategy);
}
return $context->setGroups($serializerGroups);
}
|
[
"protected",
"function",
"workOnInstance",
"(",
"Context",
"$",
"context",
")",
"{",
"$",
"context",
"=",
"$",
"context",
"->",
"setSerializeNull",
"(",
"$",
"this",
"->",
"setSerializeNull",
")",
";",
"// group override?",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"overrideHeaderAllowed",
"&&",
"$",
"this",
"->",
"requestStack",
"instanceof",
"RequestStack",
"&&",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
"instanceof",
"Request",
")",
"{",
"$",
"headerValue",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
"->",
"headers",
"->",
"get",
"(",
"$",
"this",
"->",
"overrideHeaderName",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"headerValue",
")",
")",
"{",
"$",
"this",
"->",
"groups",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"headerValue",
")",
")",
";",
"}",
"}",
"$",
"serializerGroups",
"=",
"[",
"GroupsExclusionStrategy",
"::",
"DEFAULT_GROUP",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"groups",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"groups",
")",
")",
"{",
"$",
"serializerGroups",
"=",
"array_merge",
"(",
"$",
"serializerGroups",
",",
"$",
"this",
"->",
"groups",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"exclusionStrategies",
"as",
"$",
"strategy",
")",
"{",
"$",
"context",
"->",
"addExclusionStrategy",
"(",
"$",
"strategy",
")",
";",
"}",
"return",
"$",
"context",
"->",
"setGroups",
"(",
"$",
"serializerGroups",
")",
";",
"}"
] |
sets the necessary properties on the context
@param Context $context context
@return Context context
|
[
"sets",
"the",
"necessary",
"properties",
"on",
"the",
"context"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Serializer/ContextFactoryAbstract.php#L131-L156
|
26,331
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/DependencyInjection/Compiler/GeneratorHashCompilerPass.php
|
GeneratorHashCompilerPass.process
|
public function process(ContainerBuilder $container)
{
// first type of hash: the genhash'es of all GravitonDyn bundles
$dir = $container->getParameter('graviton.generator.dynamicbundle.dir');
$dynHash = '';
if (is_dir($dir)) {
$finder = (new Finder())
->in($dir)
->files()
->sortByName()
->name('genhash');
foreach ($finder as $file) {
$dynHash .= DIRECTORY_SEPARATOR . $file->getContents();
}
}
// 2nd hash: configuration of our own graviton things (static stuff)
$staticHash = '';
if (is_dir(__DIR__.'/../../../')) {
$finder = (new Finder())
->in(__DIR__ . '/../../../')
->path('/serializer/')
->path('/doctrine/')
->path('/schema/')
->notPath('/Tests/')
->files()
->sortByName()
->name('*.xml')
->name('*.json');
foreach ($finder as $file) {
$staticHash .= DIRECTORY_SEPARATOR . sha1_file($file->getPathname());
}
}
$dynHash = sha1($dynHash);
$staticHash = sha1($staticHash);
$allHash = sha1($dynHash . DIRECTORY_SEPARATOR . $staticHash);
$container->setParameter('graviton.generator.hash.dyn', $dynHash);
$container->setParameter('graviton.generator.hash.static', $staticHash);
$container->setParameter('graviton.generator.hash.all', $allHash);
}
|
php
|
public function process(ContainerBuilder $container)
{
// first type of hash: the genhash'es of all GravitonDyn bundles
$dir = $container->getParameter('graviton.generator.dynamicbundle.dir');
$dynHash = '';
if (is_dir($dir)) {
$finder = (new Finder())
->in($dir)
->files()
->sortByName()
->name('genhash');
foreach ($finder as $file) {
$dynHash .= DIRECTORY_SEPARATOR . $file->getContents();
}
}
// 2nd hash: configuration of our own graviton things (static stuff)
$staticHash = '';
if (is_dir(__DIR__.'/../../../')) {
$finder = (new Finder())
->in(__DIR__ . '/../../../')
->path('/serializer/')
->path('/doctrine/')
->path('/schema/')
->notPath('/Tests/')
->files()
->sortByName()
->name('*.xml')
->name('*.json');
foreach ($finder as $file) {
$staticHash .= DIRECTORY_SEPARATOR . sha1_file($file->getPathname());
}
}
$dynHash = sha1($dynHash);
$staticHash = sha1($staticHash);
$allHash = sha1($dynHash . DIRECTORY_SEPARATOR . $staticHash);
$container->setParameter('graviton.generator.hash.dyn', $dynHash);
$container->setParameter('graviton.generator.hash.static', $staticHash);
$container->setParameter('graviton.generator.hash.all', $allHash);
}
|
[
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"// first type of hash: the genhash'es of all GravitonDyn bundles",
"$",
"dir",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'graviton.generator.dynamicbundle.dir'",
")",
";",
"$",
"dynHash",
"=",
"''",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"finder",
"=",
"(",
"new",
"Finder",
"(",
")",
")",
"->",
"in",
"(",
"$",
"dir",
")",
"->",
"files",
"(",
")",
"->",
"sortByName",
"(",
")",
"->",
"name",
"(",
"'genhash'",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"dynHash",
".=",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
"->",
"getContents",
"(",
")",
";",
"}",
"}",
"// 2nd hash: configuration of our own graviton things (static stuff)",
"$",
"staticHash",
"=",
"''",
";",
"if",
"(",
"is_dir",
"(",
"__DIR__",
".",
"'/../../../'",
")",
")",
"{",
"$",
"finder",
"=",
"(",
"new",
"Finder",
"(",
")",
")",
"->",
"in",
"(",
"__DIR__",
".",
"'/../../../'",
")",
"->",
"path",
"(",
"'/serializer/'",
")",
"->",
"path",
"(",
"'/doctrine/'",
")",
"->",
"path",
"(",
"'/schema/'",
")",
"->",
"notPath",
"(",
"'/Tests/'",
")",
"->",
"files",
"(",
")",
"->",
"sortByName",
"(",
")",
"->",
"name",
"(",
"'*.xml'",
")",
"->",
"name",
"(",
"'*.json'",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"staticHash",
".=",
"DIRECTORY_SEPARATOR",
".",
"sha1_file",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"}",
"$",
"dynHash",
"=",
"sha1",
"(",
"$",
"dynHash",
")",
";",
"$",
"staticHash",
"=",
"sha1",
"(",
"$",
"staticHash",
")",
";",
"$",
"allHash",
"=",
"sha1",
"(",
"$",
"dynHash",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"staticHash",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'graviton.generator.hash.dyn'",
",",
"$",
"dynHash",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'graviton.generator.hash.static'",
",",
"$",
"staticHash",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'graviton.generator.hash.all'",
",",
"$",
"allHash",
")",
";",
"}"
] |
generate the hashes
@param ContainerBuilder $container container builder
@return void
|
[
"generate",
"the",
"hashes"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/DependencyInjection/Compiler/GeneratorHashCompilerPass.php#L27-L71
|
26,332
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Generator/DynamicBundleBundleGenerator.php
|
DynamicBundleBundleGenerator.generate
|
public function generate(array $bundleList, $bundleBundleNamespace, $bundleName, $targetFilename)
{
$absoluteList = [];
foreach ($bundleList as $namespace) {
$absoluteList[] = '\\' . str_replace('/', '\\', $namespace) .
'\\' . str_replace('/', '', $namespace);
}
if (is_array($this->additions)) {
$absoluteList = array_merge($absoluteList, $this->additions);
}
$absoluteList = array_unique($absoluteList);
sort($absoluteList);
$parameters = array(
'namespace' => str_replace('/', '\\', $bundleBundleNamespace),
'bundleName' => $bundleName,
'bundleClassList' => $absoluteList
);
$this->renderFile('bundle/DynamicBundleBundle.php.twig', $targetFilename, $parameters);
}
|
php
|
public function generate(array $bundleList, $bundleBundleNamespace, $bundleName, $targetFilename)
{
$absoluteList = [];
foreach ($bundleList as $namespace) {
$absoluteList[] = '\\' . str_replace('/', '\\', $namespace) .
'\\' . str_replace('/', '', $namespace);
}
if (is_array($this->additions)) {
$absoluteList = array_merge($absoluteList, $this->additions);
}
$absoluteList = array_unique($absoluteList);
sort($absoluteList);
$parameters = array(
'namespace' => str_replace('/', '\\', $bundleBundleNamespace),
'bundleName' => $bundleName,
'bundleClassList' => $absoluteList
);
$this->renderFile('bundle/DynamicBundleBundle.php.twig', $targetFilename, $parameters);
}
|
[
"public",
"function",
"generate",
"(",
"array",
"$",
"bundleList",
",",
"$",
"bundleBundleNamespace",
",",
"$",
"bundleName",
",",
"$",
"targetFilename",
")",
"{",
"$",
"absoluteList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"bundleList",
"as",
"$",
"namespace",
")",
"{",
"$",
"absoluteList",
"[",
"]",
"=",
"'\\\\'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"namespace",
")",
".",
"'\\\\'",
".",
"str_replace",
"(",
"'/'",
",",
"''",
",",
"$",
"namespace",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"additions",
")",
")",
"{",
"$",
"absoluteList",
"=",
"array_merge",
"(",
"$",
"absoluteList",
",",
"$",
"this",
"->",
"additions",
")",
";",
"}",
"$",
"absoluteList",
"=",
"array_unique",
"(",
"$",
"absoluteList",
")",
";",
"sort",
"(",
"$",
"absoluteList",
")",
";",
"$",
"parameters",
"=",
"array",
"(",
"'namespace'",
"=>",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"bundleBundleNamespace",
")",
",",
"'bundleName'",
"=>",
"$",
"bundleName",
",",
"'bundleClassList'",
"=>",
"$",
"absoluteList",
")",
";",
"$",
"this",
"->",
"renderFile",
"(",
"'bundle/DynamicBundleBundle.php.twig'",
",",
"$",
"targetFilename",
",",
"$",
"parameters",
")",
";",
"}"
] |
Generate the BundleBundle
@param array $bundleList List of bundles
@param string $bundleBundleNamespace Namespace of our BundleBundle
@param string $bundleName Name of the bundle
@param string $targetFilename Where to write the list to
@return void
|
[
"Generate",
"the",
"BundleBundle"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/DynamicBundleBundleGenerator.php#L47-L69
|
26,333
|
libgraviton/graviton
|
src/Graviton/CacheBundle/Listener/IfNoneMatchResponseListener.php
|
IfNoneMatchResponseListener.onKernelResponse
|
public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
$request = $event->getRequest();
$ifNoneMatch = $request->headers->get('if-none-match');
$etag = $response->headers->get('ETag', 'empty');
if ($ifNoneMatch === $etag) {
$response->setStatusCode(304);
$response->setContent(null);
}
}
|
php
|
public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
$request = $event->getRequest();
$ifNoneMatch = $request->headers->get('if-none-match');
$etag = $response->headers->get('ETag', 'empty');
if ($ifNoneMatch === $etag) {
$response->setStatusCode(304);
$response->setContent(null);
}
}
|
[
"public",
"function",
"onKernelResponse",
"(",
"FilterResponseEvent",
"$",
"event",
")",
"{",
"$",
"response",
"=",
"$",
"event",
"->",
"getResponse",
"(",
")",
";",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"$",
"ifNoneMatch",
"=",
"$",
"request",
"->",
"headers",
"->",
"get",
"(",
"'if-none-match'",
")",
";",
"$",
"etag",
"=",
"$",
"response",
"->",
"headers",
"->",
"get",
"(",
"'ETag'",
",",
"'empty'",
")",
";",
"if",
"(",
"$",
"ifNoneMatch",
"===",
"$",
"etag",
")",
"{",
"$",
"response",
"->",
"setStatusCode",
"(",
"304",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"null",
")",
";",
"}",
"}"
] |
add a IfNoneMatch header to the response
@param FilterResponseEvent $event response listener event
@return void
|
[
"add",
"a",
"IfNoneMatch",
"header",
"to",
"the",
"response"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/CacheBundle/Listener/IfNoneMatchResponseListener.php#L26-L38
|
26,334
|
libgraviton/graviton
|
src/Graviton/CoreBundle/Compiler/HttpClientOptionsCompilerPass.php
|
HttpClientOptionsCompilerPass.process
|
public function process(ContainerBuilder $container)
{
$baseOptions = [
'verify' => false
];
// system settings envs
if (isset($_ENV['HTTP_PROXY']) && !empty($_ENV['HTTP_PROXY'])) {
$this->setProxy($_ENV['HTTP_PROXY'], 'http');
}
if (isset($_ENV['HTTPS_PROXY']) && !empty($_ENV['HTTPS_PROXY'])) {
$this->setProxy($_ENV['HTTPS_PROXY'], 'https');
}
if (isset($_ENV['NO_PROXY']) && !empty($_ENV['NO_PROXY'])) {
$this->setNoProxyList($_ENV['NO_PROXY']);
}
// is there the old setting?
if (isset($_ENV['GRAVITON_PROXY_CURLOPTS'])) {
$yamlSettings = Yaml::parse($_ENV['GRAVITON_PROXY_CURLOPTS']);
if (is_array($yamlSettings) && isset($yamlSettings['proxy'])) {
$this->setProxy($yamlSettings['proxy']);
}
if (is_array($yamlSettings) && isset($yamlSettings['noproxy'])) {
$this->setNoProxyList($yamlSettings['noproxy']);
}
}
// new settings -> override all
if (null !== $container->getParameter('graviton.proxy')) {
$this->setProxy($container->getParameter('graviton.proxy'));
}
if (null !== $container->getParameter('graviton.noproxy')) {
$this->setNoProxyList($container->getParameter('graviton.noproxy'));
}
// any proxy?
if (!empty($this->proxySettings)) {
$baseOptions['proxy'] = $this->proxySettings;
}
$container->setParameter(
'graviton.core.http.client.options',
$baseOptions
);
}
|
php
|
public function process(ContainerBuilder $container)
{
$baseOptions = [
'verify' => false
];
// system settings envs
if (isset($_ENV['HTTP_PROXY']) && !empty($_ENV['HTTP_PROXY'])) {
$this->setProxy($_ENV['HTTP_PROXY'], 'http');
}
if (isset($_ENV['HTTPS_PROXY']) && !empty($_ENV['HTTPS_PROXY'])) {
$this->setProxy($_ENV['HTTPS_PROXY'], 'https');
}
if (isset($_ENV['NO_PROXY']) && !empty($_ENV['NO_PROXY'])) {
$this->setNoProxyList($_ENV['NO_PROXY']);
}
// is there the old setting?
if (isset($_ENV['GRAVITON_PROXY_CURLOPTS'])) {
$yamlSettings = Yaml::parse($_ENV['GRAVITON_PROXY_CURLOPTS']);
if (is_array($yamlSettings) && isset($yamlSettings['proxy'])) {
$this->setProxy($yamlSettings['proxy']);
}
if (is_array($yamlSettings) && isset($yamlSettings['noproxy'])) {
$this->setNoProxyList($yamlSettings['noproxy']);
}
}
// new settings -> override all
if (null !== $container->getParameter('graviton.proxy')) {
$this->setProxy($container->getParameter('graviton.proxy'));
}
if (null !== $container->getParameter('graviton.noproxy')) {
$this->setNoProxyList($container->getParameter('graviton.noproxy'));
}
// any proxy?
if (!empty($this->proxySettings)) {
$baseOptions['proxy'] = $this->proxySettings;
}
$container->setParameter(
'graviton.core.http.client.options',
$baseOptions
);
}
|
[
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"baseOptions",
"=",
"[",
"'verify'",
"=>",
"false",
"]",
";",
"// system settings envs",
"if",
"(",
"isset",
"(",
"$",
"_ENV",
"[",
"'HTTP_PROXY'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"_ENV",
"[",
"'HTTP_PROXY'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setProxy",
"(",
"$",
"_ENV",
"[",
"'HTTP_PROXY'",
"]",
",",
"'http'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_ENV",
"[",
"'HTTPS_PROXY'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"_ENV",
"[",
"'HTTPS_PROXY'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setProxy",
"(",
"$",
"_ENV",
"[",
"'HTTPS_PROXY'",
"]",
",",
"'https'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_ENV",
"[",
"'NO_PROXY'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"_ENV",
"[",
"'NO_PROXY'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setNoProxyList",
"(",
"$",
"_ENV",
"[",
"'NO_PROXY'",
"]",
")",
";",
"}",
"// is there the old setting?",
"if",
"(",
"isset",
"(",
"$",
"_ENV",
"[",
"'GRAVITON_PROXY_CURLOPTS'",
"]",
")",
")",
"{",
"$",
"yamlSettings",
"=",
"Yaml",
"::",
"parse",
"(",
"$",
"_ENV",
"[",
"'GRAVITON_PROXY_CURLOPTS'",
"]",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"yamlSettings",
")",
"&&",
"isset",
"(",
"$",
"yamlSettings",
"[",
"'proxy'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setProxy",
"(",
"$",
"yamlSettings",
"[",
"'proxy'",
"]",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"yamlSettings",
")",
"&&",
"isset",
"(",
"$",
"yamlSettings",
"[",
"'noproxy'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setNoProxyList",
"(",
"$",
"yamlSettings",
"[",
"'noproxy'",
"]",
")",
";",
"}",
"}",
"// new settings -> override all",
"if",
"(",
"null",
"!==",
"$",
"container",
"->",
"getParameter",
"(",
"'graviton.proxy'",
")",
")",
"{",
"$",
"this",
"->",
"setProxy",
"(",
"$",
"container",
"->",
"getParameter",
"(",
"'graviton.proxy'",
")",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"container",
"->",
"getParameter",
"(",
"'graviton.noproxy'",
")",
")",
"{",
"$",
"this",
"->",
"setNoProxyList",
"(",
"$",
"container",
"->",
"getParameter",
"(",
"'graviton.noproxy'",
")",
")",
";",
"}",
"// any proxy?",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"proxySettings",
")",
")",
"{",
"$",
"baseOptions",
"[",
"'proxy'",
"]",
"=",
"$",
"this",
"->",
"proxySettings",
";",
"}",
"$",
"container",
"->",
"setParameter",
"(",
"'graviton.core.http.client.options'",
",",
"$",
"baseOptions",
")",
";",
"}"
] |
add guzzle options
@param ContainerBuilder $container Container
@return void
|
[
"add",
"guzzle",
"options"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/CoreBundle/Compiler/HttpClientOptionsCompilerPass.php#L32-L77
|
26,335
|
libgraviton/graviton
|
src/Graviton/CoreBundle/Compiler/HttpClientOptionsCompilerPass.php
|
HttpClientOptionsCompilerPass.setProxy
|
private function setProxy($proxy, $onlyProtocol = null)
{
$proxy = trim($proxy);
if (null == $onlyProtocol) {
$this->proxySettings['http'] = $proxy;
$this->proxySettings['https'] = $proxy;
} else {
$this->proxySettings[$onlyProtocol] = $proxy;
}
}
|
php
|
private function setProxy($proxy, $onlyProtocol = null)
{
$proxy = trim($proxy);
if (null == $onlyProtocol) {
$this->proxySettings['http'] = $proxy;
$this->proxySettings['https'] = $proxy;
} else {
$this->proxySettings[$onlyProtocol] = $proxy;
}
}
|
[
"private",
"function",
"setProxy",
"(",
"$",
"proxy",
",",
"$",
"onlyProtocol",
"=",
"null",
")",
"{",
"$",
"proxy",
"=",
"trim",
"(",
"$",
"proxy",
")",
";",
"if",
"(",
"null",
"==",
"$",
"onlyProtocol",
")",
"{",
"$",
"this",
"->",
"proxySettings",
"[",
"'http'",
"]",
"=",
"$",
"proxy",
";",
"$",
"this",
"->",
"proxySettings",
"[",
"'https'",
"]",
"=",
"$",
"proxy",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"proxySettings",
"[",
"$",
"onlyProtocol",
"]",
"=",
"$",
"proxy",
";",
"}",
"}"
] |
set the proxy
@param string $proxy the proxy
@param null|boolean $onlyProtocol only set certain protocol
@return void
|
[
"set",
"the",
"proxy"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/CoreBundle/Compiler/HttpClientOptionsCompilerPass.php#L87-L96
|
26,336
|
libgraviton/graviton
|
src/Graviton/CoreBundle/Compiler/HttpClientOptionsCompilerPass.php
|
HttpClientOptionsCompilerPass.setNoProxyList
|
private function setNoProxyList($list)
{
if (is_array($list)) {
$this->proxySettings['no'] = array_map('trim', $list);
return;
}
if (is_string($list) && strpos($list, ',') !== false) {
$this->proxySettings['no'] = explode(',', $list);
} elseif (is_string($list) && strpos($list, ' ') !== false) {
$this->proxySettings['no'] = explode(' ', $list);
}
$this->proxySettings['no'] = array_map('trim', $this->proxySettings['no']);
}
|
php
|
private function setNoProxyList($list)
{
if (is_array($list)) {
$this->proxySettings['no'] = array_map('trim', $list);
return;
}
if (is_string($list) && strpos($list, ',') !== false) {
$this->proxySettings['no'] = explode(',', $list);
} elseif (is_string($list) && strpos($list, ' ') !== false) {
$this->proxySettings['no'] = explode(' ', $list);
}
$this->proxySettings['no'] = array_map('trim', $this->proxySettings['no']);
}
|
[
"private",
"function",
"setNoProxyList",
"(",
"$",
"list",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"list",
")",
")",
"{",
"$",
"this",
"->",
"proxySettings",
"[",
"'no'",
"]",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"list",
")",
";",
"return",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"list",
")",
"&&",
"strpos",
"(",
"$",
"list",
",",
"','",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"proxySettings",
"[",
"'no'",
"]",
"=",
"explode",
"(",
"','",
",",
"$",
"list",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"list",
")",
"&&",
"strpos",
"(",
"$",
"list",
",",
"' '",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"proxySettings",
"[",
"'no'",
"]",
"=",
"explode",
"(",
"' '",
",",
"$",
"list",
")",
";",
"}",
"$",
"this",
"->",
"proxySettings",
"[",
"'no'",
"]",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"this",
"->",
"proxySettings",
"[",
"'no'",
"]",
")",
";",
"}"
] |
set the no proxy setting
@param string $list either string or array
@return void
|
[
"set",
"the",
"no",
"proxy",
"setting"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/CoreBundle/Compiler/HttpClientOptionsCompilerPass.php#L105-L118
|
26,337
|
libgraviton/graviton
|
src/Graviton/SchemaBundle/Serializer/Handler/SchemaAdditionalPropertiesHandler.php
|
SchemaAdditionalPropertiesHandler.serializeSchemaAdditionalPropertiesToJson
|
public function serializeSchemaAdditionalPropertiesToJson(
JsonSerializationVisitor $visitor,
SchemaAdditionalProperties $additionalProperties,
array $type,
Context $context
) {
$properties = $additionalProperties->getProperties();
// case for v4 schema
if (is_bool($properties)) {
return $visitor->visitBoolean($properties, [], $context);
}
// case for schema inside additionalProperties, swagger exclusive
if ($properties instanceof Schema) {
return $visitor->getNavigator()->accept(
$properties,
['name' => 'Graviton\SchemaBundle\Document\Schema'],
$context
);
}
}
|
php
|
public function serializeSchemaAdditionalPropertiesToJson(
JsonSerializationVisitor $visitor,
SchemaAdditionalProperties $additionalProperties,
array $type,
Context $context
) {
$properties = $additionalProperties->getProperties();
// case for v4 schema
if (is_bool($properties)) {
return $visitor->visitBoolean($properties, [], $context);
}
// case for schema inside additionalProperties, swagger exclusive
if ($properties instanceof Schema) {
return $visitor->getNavigator()->accept(
$properties,
['name' => 'Graviton\SchemaBundle\Document\Schema'],
$context
);
}
}
|
[
"public",
"function",
"serializeSchemaAdditionalPropertiesToJson",
"(",
"JsonSerializationVisitor",
"$",
"visitor",
",",
"SchemaAdditionalProperties",
"$",
"additionalProperties",
",",
"array",
"$",
"type",
",",
"Context",
"$",
"context",
")",
"{",
"$",
"properties",
"=",
"$",
"additionalProperties",
"->",
"getProperties",
"(",
")",
";",
"// case for v4 schema",
"if",
"(",
"is_bool",
"(",
"$",
"properties",
")",
")",
"{",
"return",
"$",
"visitor",
"->",
"visitBoolean",
"(",
"$",
"properties",
",",
"[",
"]",
",",
"$",
"context",
")",
";",
"}",
"// case for schema inside additionalProperties, swagger exclusive",
"if",
"(",
"$",
"properties",
"instanceof",
"Schema",
")",
"{",
"return",
"$",
"visitor",
"->",
"getNavigator",
"(",
")",
"->",
"accept",
"(",
"$",
"properties",
",",
"[",
"'name'",
"=>",
"'Graviton\\SchemaBundle\\Document\\Schema'",
"]",
",",
"$",
"context",
")",
";",
"}",
"}"
] |
Serialize additionalProperties to JSON
@param JsonSerializationVisitor $visitor Visitor
@param SchemaAdditionalProperties $additionalProperties properties
@param array $type Type
@param Context $context Context
@return string|null
|
[
"Serialize",
"additionalProperties",
"to",
"JSON"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/Serializer/Handler/SchemaAdditionalPropertiesHandler.php#L33-L55
|
26,338
|
libgraviton/graviton
|
src/Graviton/AnalyticsBundle/Manager/ServiceManager.php
|
ServiceManager.getServices
|
public function getServices()
{
$services = $this->cacheProvider->fetch(self::CACHE_KEY_SERVICES_URLS);
if (is_array($services)) {
return $services;
}
$services = [];
foreach ($this->analyticsServices as $name => $service) {
if (is_numeric($name)) {
continue;
}
$services[] = [
'$ref' => $this->router->generate(
'graviton_analytics_service',
[
'service' => $service['route']
],
false
),
'profile' => $this->router->generate(
'graviton_analytics_service_schema',
[
'service' => $service['route']
],
true
)
];
}
$this->cacheProvider->save(
self::CACHE_KEY_SERVICES_URLS,
$services,
$this->cacheTimeMetadata
);
return $services;
}
|
php
|
public function getServices()
{
$services = $this->cacheProvider->fetch(self::CACHE_KEY_SERVICES_URLS);
if (is_array($services)) {
return $services;
}
$services = [];
foreach ($this->analyticsServices as $name => $service) {
if (is_numeric($name)) {
continue;
}
$services[] = [
'$ref' => $this->router->generate(
'graviton_analytics_service',
[
'service' => $service['route']
],
false
),
'profile' => $this->router->generate(
'graviton_analytics_service_schema',
[
'service' => $service['route']
],
true
)
];
}
$this->cacheProvider->save(
self::CACHE_KEY_SERVICES_URLS,
$services,
$this->cacheTimeMetadata
);
return $services;
}
|
[
"public",
"function",
"getServices",
"(",
")",
"{",
"$",
"services",
"=",
"$",
"this",
"->",
"cacheProvider",
"->",
"fetch",
"(",
"self",
"::",
"CACHE_KEY_SERVICES_URLS",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"services",
")",
")",
"{",
"return",
"$",
"services",
";",
"}",
"$",
"services",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"analyticsServices",
"as",
"$",
"name",
"=>",
"$",
"service",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"name",
")",
")",
"{",
"continue",
";",
"}",
"$",
"services",
"[",
"]",
"=",
"[",
"'$ref'",
"=>",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"'graviton_analytics_service'",
",",
"[",
"'service'",
"=>",
"$",
"service",
"[",
"'route'",
"]",
"]",
",",
"false",
")",
",",
"'profile'",
"=>",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"'graviton_analytics_service_schema'",
",",
"[",
"'service'",
"=>",
"$",
"service",
"[",
"'route'",
"]",
"]",
",",
"true",
")",
"]",
";",
"}",
"$",
"this",
"->",
"cacheProvider",
"->",
"save",
"(",
"self",
"::",
"CACHE_KEY_SERVICES_URLS",
",",
"$",
"services",
",",
"$",
"this",
"->",
"cacheTimeMetadata",
")",
";",
"return",
"$",
"services",
";",
"}"
] |
Return array of available services
@return array
|
[
"Return",
"array",
"of",
"available",
"services"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/AnalyticsBundle/Manager/ServiceManager.php#L107-L143
|
26,339
|
libgraviton/graviton
|
src/Graviton/AnalyticsBundle/Manager/ServiceManager.php
|
ServiceManager.getData
|
public function getData()
{
$serviceRoute = $this->requestStack->getCurrentRequest()
->get('service');
// Locate the model definition
$model = $this->getAnalyticModel($serviceRoute);
$cacheTime = $model->getCacheTime();
$cacheKey = $this->getCacheKey($model);
//Cached data if configured
if ($cacheTime &&
!$this->requestStack->getCurrentRequest()->headers->has($this->skipCacheHeaderName) &&
$cache = $this->cacheProvider->fetch($cacheKey)
) {
return $cache;
}
$data = $this->analyticsManager->getData($model, $this->getServiceParameters($model));
if ($cacheTime) {
$this->cacheProvider->save($cacheKey, $data, $cacheTime);
}
return $data;
}
|
php
|
public function getData()
{
$serviceRoute = $this->requestStack->getCurrentRequest()
->get('service');
// Locate the model definition
$model = $this->getAnalyticModel($serviceRoute);
$cacheTime = $model->getCacheTime();
$cacheKey = $this->getCacheKey($model);
//Cached data if configured
if ($cacheTime &&
!$this->requestStack->getCurrentRequest()->headers->has($this->skipCacheHeaderName) &&
$cache = $this->cacheProvider->fetch($cacheKey)
) {
return $cache;
}
$data = $this->analyticsManager->getData($model, $this->getServiceParameters($model));
if ($cacheTime) {
$this->cacheProvider->save($cacheKey, $data, $cacheTime);
}
return $data;
}
|
[
"public",
"function",
"getData",
"(",
")",
"{",
"$",
"serviceRoute",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
"->",
"get",
"(",
"'service'",
")",
";",
"// Locate the model definition",
"$",
"model",
"=",
"$",
"this",
"->",
"getAnalyticModel",
"(",
"$",
"serviceRoute",
")",
";",
"$",
"cacheTime",
"=",
"$",
"model",
"->",
"getCacheTime",
"(",
")",
";",
"$",
"cacheKey",
"=",
"$",
"this",
"->",
"getCacheKey",
"(",
"$",
"model",
")",
";",
"//Cached data if configured",
"if",
"(",
"$",
"cacheTime",
"&&",
"!",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
"->",
"headers",
"->",
"has",
"(",
"$",
"this",
"->",
"skipCacheHeaderName",
")",
"&&",
"$",
"cache",
"=",
"$",
"this",
"->",
"cacheProvider",
"->",
"fetch",
"(",
"$",
"cacheKey",
")",
")",
"{",
"return",
"$",
"cache",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"analyticsManager",
"->",
"getData",
"(",
"$",
"model",
",",
"$",
"this",
"->",
"getServiceParameters",
"(",
"$",
"model",
")",
")",
";",
"if",
"(",
"$",
"cacheTime",
")",
"{",
"$",
"this",
"->",
"cacheProvider",
"->",
"save",
"(",
"$",
"cacheKey",
",",
"$",
"data",
",",
"$",
"cacheTime",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Will map and find data for defined route
@return array
|
[
"Will",
"map",
"and",
"find",
"data",
"for",
"defined",
"route"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/AnalyticsBundle/Manager/ServiceManager.php#L169-L195
|
26,340
|
libgraviton/graviton
|
src/Graviton/AnalyticsBundle/Manager/ServiceManager.php
|
ServiceManager.getCacheKey
|
private function getCacheKey($schema)
{
return self::CACHE_KEY_SERVICES_PREFIX
. $schema->getRoute()
. sha1(serialize($this->requestStack->getCurrentRequest()->query->all()));
}
|
php
|
private function getCacheKey($schema)
{
return self::CACHE_KEY_SERVICES_PREFIX
. $schema->getRoute()
. sha1(serialize($this->requestStack->getCurrentRequest()->query->all()));
}
|
[
"private",
"function",
"getCacheKey",
"(",
"$",
"schema",
")",
"{",
"return",
"self",
"::",
"CACHE_KEY_SERVICES_PREFIX",
".",
"$",
"schema",
"->",
"getRoute",
"(",
")",
".",
"sha1",
"(",
"serialize",
"(",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
"->",
"query",
"->",
"all",
"(",
")",
")",
")",
";",
"}"
] |
generate a cache key also based on query
@param AnalyticModel $schema schema
@return string cache key
|
[
"generate",
"a",
"cache",
"key",
"also",
"based",
"on",
"query"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/AnalyticsBundle/Manager/ServiceManager.php#L204-L209
|
26,341
|
libgraviton/graviton
|
src/Graviton/AnalyticsBundle/Manager/ServiceManager.php
|
ServiceManager.getSchema
|
public function getSchema()
{
$serviceRoute = $this->requestStack->getCurrentRequest()
->get('service');
// Locate the schema definition
$model = $this->getAnalyticModel($serviceRoute);
return $model->getSchema();
}
|
php
|
public function getSchema()
{
$serviceRoute = $this->requestStack->getCurrentRequest()
->get('service');
// Locate the schema definition
$model = $this->getAnalyticModel($serviceRoute);
return $model->getSchema();
}
|
[
"public",
"function",
"getSchema",
"(",
")",
"{",
"$",
"serviceRoute",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
"->",
"get",
"(",
"'service'",
")",
";",
"// Locate the schema definition",
"$",
"model",
"=",
"$",
"this",
"->",
"getAnalyticModel",
"(",
"$",
"serviceRoute",
")",
";",
"return",
"$",
"model",
"->",
"getSchema",
"(",
")",
";",
"}"
] |
Locate and display service definition schema
@return mixed
|
[
"Locate",
"and",
"display",
"service",
"definition",
"schema"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/AnalyticsBundle/Manager/ServiceManager.php#L216-L225
|
26,342
|
libgraviton/graviton
|
src/Graviton/AnalyticsBundle/Manager/ServiceManager.php
|
ServiceManager.getServiceParameters
|
private function getServiceParameters(AnalyticModel $model)
{
$params = [];
if (!is_array($model->getParams())) {
return $params;
}
foreach ($model->getParams() as $param) {
if (!isset($param['name'])) {
throw new \LogicException("Incorrect spec (no name) of param in analytics route " . $model->getRoute());
}
$paramValue = $this->requestStack->getCurrentRequest()->query->get($param['name'], null);
// default set?
if (is_null($paramValue) && isset($param['default'])) {
$paramValue = $param['default'];
}
// required missing?
if (is_null($paramValue) && (isset($param['required']) && $param['required'] === true)) {
throw new AnalyticUsageException(
sprintf(
"Missing parameter '%s' in analytics route '%s'",
$param['name'],
$model->getRoute()
)
);
}
if (!is_null($param['type']) && !is_null($paramValue)) {
switch ($param['type']) {
case "integer":
$paramValue = intval($paramValue);
// more than max? limit to max..
if (isset($param['max']) && is_numeric($param['max']) && intval($param['max']) < $paramValue) {
$paramValue = intval($param['max']);
}
break;
case "boolean":
$paramValue = boolval($paramValue);
break;
case "array":
$paramValue = explode(',', $paramValue);
break;
case "date":
$paramValue = new UTCDateTime($this->dateConverter->getDateTimeFromString($paramValue));
break;
case "regex":
$paramValue = new Regex($paramValue, 'i');
break;
case "mongoid":
$paramValue = new \MongoId($paramValue);
break;
case "array<integer>":
$paramValue = array_map('intval', explode(',', $paramValue));
break;
case "array<boolean>":
$paramValue = array_map('boolval', explode(',', $paramValue));
break;
}
}
if (!is_null($paramValue)) {
$params[$param['name']] = $paramValue;
}
}
return $params;
}
|
php
|
private function getServiceParameters(AnalyticModel $model)
{
$params = [];
if (!is_array($model->getParams())) {
return $params;
}
foreach ($model->getParams() as $param) {
if (!isset($param['name'])) {
throw new \LogicException("Incorrect spec (no name) of param in analytics route " . $model->getRoute());
}
$paramValue = $this->requestStack->getCurrentRequest()->query->get($param['name'], null);
// default set?
if (is_null($paramValue) && isset($param['default'])) {
$paramValue = $param['default'];
}
// required missing?
if (is_null($paramValue) && (isset($param['required']) && $param['required'] === true)) {
throw new AnalyticUsageException(
sprintf(
"Missing parameter '%s' in analytics route '%s'",
$param['name'],
$model->getRoute()
)
);
}
if (!is_null($param['type']) && !is_null($paramValue)) {
switch ($param['type']) {
case "integer":
$paramValue = intval($paramValue);
// more than max? limit to max..
if (isset($param['max']) && is_numeric($param['max']) && intval($param['max']) < $paramValue) {
$paramValue = intval($param['max']);
}
break;
case "boolean":
$paramValue = boolval($paramValue);
break;
case "array":
$paramValue = explode(',', $paramValue);
break;
case "date":
$paramValue = new UTCDateTime($this->dateConverter->getDateTimeFromString($paramValue));
break;
case "regex":
$paramValue = new Regex($paramValue, 'i');
break;
case "mongoid":
$paramValue = new \MongoId($paramValue);
break;
case "array<integer>":
$paramValue = array_map('intval', explode(',', $paramValue));
break;
case "array<boolean>":
$paramValue = array_map('boolval', explode(',', $paramValue));
break;
}
}
if (!is_null($paramValue)) {
$params[$param['name']] = $paramValue;
}
}
return $params;
}
|
[
"private",
"function",
"getServiceParameters",
"(",
"AnalyticModel",
"$",
"model",
")",
"{",
"$",
"params",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"model",
"->",
"getParams",
"(",
")",
")",
")",
"{",
"return",
"$",
"params",
";",
"}",
"foreach",
"(",
"$",
"model",
"->",
"getParams",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"param",
"[",
"'name'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"Incorrect spec (no name) of param in analytics route \"",
".",
"$",
"model",
"->",
"getRoute",
"(",
")",
")",
";",
"}",
"$",
"paramValue",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
"->",
"query",
"->",
"get",
"(",
"$",
"param",
"[",
"'name'",
"]",
",",
"null",
")",
";",
"// default set?",
"if",
"(",
"is_null",
"(",
"$",
"paramValue",
")",
"&&",
"isset",
"(",
"$",
"param",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"paramValue",
"=",
"$",
"param",
"[",
"'default'",
"]",
";",
"}",
"// required missing?",
"if",
"(",
"is_null",
"(",
"$",
"paramValue",
")",
"&&",
"(",
"isset",
"(",
"$",
"param",
"[",
"'required'",
"]",
")",
"&&",
"$",
"param",
"[",
"'required'",
"]",
"===",
"true",
")",
")",
"{",
"throw",
"new",
"AnalyticUsageException",
"(",
"sprintf",
"(",
"\"Missing parameter '%s' in analytics route '%s'\"",
",",
"$",
"param",
"[",
"'name'",
"]",
",",
"$",
"model",
"->",
"getRoute",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"param",
"[",
"'type'",
"]",
")",
"&&",
"!",
"is_null",
"(",
"$",
"paramValue",
")",
")",
"{",
"switch",
"(",
"$",
"param",
"[",
"'type'",
"]",
")",
"{",
"case",
"\"integer\"",
":",
"$",
"paramValue",
"=",
"intval",
"(",
"$",
"paramValue",
")",
";",
"// more than max? limit to max..",
"if",
"(",
"isset",
"(",
"$",
"param",
"[",
"'max'",
"]",
")",
"&&",
"is_numeric",
"(",
"$",
"param",
"[",
"'max'",
"]",
")",
"&&",
"intval",
"(",
"$",
"param",
"[",
"'max'",
"]",
")",
"<",
"$",
"paramValue",
")",
"{",
"$",
"paramValue",
"=",
"intval",
"(",
"$",
"param",
"[",
"'max'",
"]",
")",
";",
"}",
"break",
";",
"case",
"\"boolean\"",
":",
"$",
"paramValue",
"=",
"boolval",
"(",
"$",
"paramValue",
")",
";",
"break",
";",
"case",
"\"array\"",
":",
"$",
"paramValue",
"=",
"explode",
"(",
"','",
",",
"$",
"paramValue",
")",
";",
"break",
";",
"case",
"\"date\"",
":",
"$",
"paramValue",
"=",
"new",
"UTCDateTime",
"(",
"$",
"this",
"->",
"dateConverter",
"->",
"getDateTimeFromString",
"(",
"$",
"paramValue",
")",
")",
";",
"break",
";",
"case",
"\"regex\"",
":",
"$",
"paramValue",
"=",
"new",
"Regex",
"(",
"$",
"paramValue",
",",
"'i'",
")",
";",
"break",
";",
"case",
"\"mongoid\"",
":",
"$",
"paramValue",
"=",
"new",
"\\",
"MongoId",
"(",
"$",
"paramValue",
")",
";",
"break",
";",
"case",
"\"array<integer>\"",
":",
"$",
"paramValue",
"=",
"array_map",
"(",
"'intval'",
",",
"explode",
"(",
"','",
",",
"$",
"paramValue",
")",
")",
";",
"break",
";",
"case",
"\"array<boolean>\"",
":",
"$",
"paramValue",
"=",
"array_map",
"(",
"'boolval'",
",",
"explode",
"(",
"','",
",",
"$",
"paramValue",
")",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"paramValue",
")",
")",
"{",
"$",
"params",
"[",
"$",
"param",
"[",
"'name'",
"]",
"]",
"=",
"$",
"paramValue",
";",
"}",
"}",
"return",
"$",
"params",
";",
"}"
] |
returns the params as passed from the user
@param AnalyticModel $model model
@return array the params, converted as specified
@throws AnalyticUsageException
|
[
"returns",
"the",
"params",
"as",
"passed",
"from",
"the",
"user"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/AnalyticsBundle/Manager/ServiceManager.php#L235-L305
|
26,343
|
libgraviton/graviton
|
src/Graviton/RestBundle/GravitonRestBundle.php
|
GravitonRestBundle.build
|
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new RestServicesCompilerPass);
$container->addCompilerPass(new RqlQueryRoutesCompilerPass());
}
|
php
|
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new RestServicesCompilerPass);
$container->addCompilerPass(new RqlQueryRoutesCompilerPass());
}
|
[
"public",
"function",
"build",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"parent",
"::",
"build",
"(",
"$",
"container",
")",
";",
"$",
"container",
"->",
"addCompilerPass",
"(",
"new",
"RestServicesCompilerPass",
")",
";",
"$",
"container",
"->",
"addCompilerPass",
"(",
"new",
"RqlQueryRoutesCompilerPass",
"(",
")",
")",
";",
"}"
] |
load compiler pass rest route loader
@param ContainerBuilder $container container builder
@return void
|
[
"load",
"compiler",
"pass",
"rest",
"route",
"loader"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/GravitonRestBundle.php#L47-L53
|
26,344
|
libgraviton/graviton
|
src/Graviton/RestBundle/Listener/JsonRequestListener.php
|
JsonRequestListener.onKernelRequest
|
public function onKernelRequest(RestEvent $event)
{
$request = $event->getRequest();
if ($request->headers->has('Accept')) {
$format = $request->getFormat($request->headers->get('Accept'));
if (!empty($format)) {
$request->setRequestFormat($format);
}
}
}
|
php
|
public function onKernelRequest(RestEvent $event)
{
$request = $event->getRequest();
if ($request->headers->has('Accept')) {
$format = $request->getFormat($request->headers->get('Accept'));
if (!empty($format)) {
$request->setRequestFormat($format);
}
}
}
|
[
"public",
"function",
"onKernelRequest",
"(",
"RestEvent",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"headers",
"->",
"has",
"(",
"'Accept'",
")",
")",
"{",
"$",
"format",
"=",
"$",
"request",
"->",
"getFormat",
"(",
"$",
"request",
"->",
"headers",
"->",
"get",
"(",
"'Accept'",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"format",
")",
")",
"{",
"$",
"request",
"->",
"setRequestFormat",
"(",
"$",
"format",
")",
";",
"}",
"}",
"}"
] |
Validate the json input to prevent errors in the following components
@param RestEvent $event Event
@return void|null
|
[
"Validate",
"the",
"json",
"input",
"to",
"prevent",
"errors",
"in",
"the",
"following",
"components"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Listener/JsonRequestListener.php#L24-L36
|
26,345
|
libgraviton/graviton
|
src/Graviton/RestBundle/Subscriber/RestEventSubscriber.php
|
RestEventSubscriber.onKernelRequest
|
public function onKernelRequest(GetResponseEvent $event, $name, EventDispatcherInterface $dispatcher)
{
$restEvent = $this->getEventObject($event);
if ($restEvent instanceof RestEvent) {
$dispatcher->dispatch("graviton.rest.request", $restEvent);
}
}
|
php
|
public function onKernelRequest(GetResponseEvent $event, $name, EventDispatcherInterface $dispatcher)
{
$restEvent = $this->getEventObject($event);
if ($restEvent instanceof RestEvent) {
$dispatcher->dispatch("graviton.rest.request", $restEvent);
}
}
|
[
"public",
"function",
"onKernelRequest",
"(",
"GetResponseEvent",
"$",
"event",
",",
"$",
"name",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"$",
"restEvent",
"=",
"$",
"this",
"->",
"getEventObject",
"(",
"$",
"event",
")",
";",
"if",
"(",
"$",
"restEvent",
"instanceof",
"RestEvent",
")",
"{",
"$",
"dispatcher",
"->",
"dispatch",
"(",
"\"graviton.rest.request\"",
",",
"$",
"restEvent",
")",
";",
"}",
"}"
] |
Handler for kernel.request events
@param GetResponseEvent $event Event
@param string $name Event name
@param EventDispatcherInterface $dispatcher Event dispatcher
@return void
|
[
"Handler",
"for",
"kernel",
".",
"request",
"events"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Subscriber/RestEventSubscriber.php#L82-L88
|
26,346
|
libgraviton/graviton
|
src/Graviton/RestBundle/Subscriber/RestEventSubscriber.php
|
RestEventSubscriber.getEventObject
|
private function getEventObject(Event $event)
{
// get the service name
list ($serviceName) = explode(":", $event->getRequest()->get('_controller'));
// get the controller which handles this request
if ($this->container->has($serviceName)) {
$controller = $this->container->get($serviceName);
$restEvent = $this->restEvent;
$restEvent->setRequest($event->getRequest());
$restEvent->setResponse($this->response);
$restEvent->setController($controller);
$returnEvent = $restEvent;
} else {
$returnEvent = $event;
}
return $returnEvent;
}
|
php
|
private function getEventObject(Event $event)
{
// get the service name
list ($serviceName) = explode(":", $event->getRequest()->get('_controller'));
// get the controller which handles this request
if ($this->container->has($serviceName)) {
$controller = $this->container->get($serviceName);
$restEvent = $this->restEvent;
$restEvent->setRequest($event->getRequest());
$restEvent->setResponse($this->response);
$restEvent->setController($controller);
$returnEvent = $restEvent;
} else {
$returnEvent = $event;
}
return $returnEvent;
}
|
[
"private",
"function",
"getEventObject",
"(",
"Event",
"$",
"event",
")",
"{",
"// get the service name",
"list",
"(",
"$",
"serviceName",
")",
"=",
"explode",
"(",
"\":\"",
",",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'_controller'",
")",
")",
";",
"// get the controller which handles this request",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"$",
"serviceName",
")",
")",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"serviceName",
")",
";",
"$",
"restEvent",
"=",
"$",
"this",
"->",
"restEvent",
";",
"$",
"restEvent",
"->",
"setRequest",
"(",
"$",
"event",
"->",
"getRequest",
"(",
")",
")",
";",
"$",
"restEvent",
"->",
"setResponse",
"(",
"$",
"this",
"->",
"response",
")",
";",
"$",
"restEvent",
"->",
"setController",
"(",
"$",
"controller",
")",
";",
"$",
"returnEvent",
"=",
"$",
"restEvent",
";",
"}",
"else",
"{",
"$",
"returnEvent",
"=",
"$",
"event",
";",
"}",
"return",
"$",
"returnEvent",
";",
"}"
] |
Get a RestEvent object -> put this in a factory
@param Event $event Original event (kernel.request / kernel.response)
@return RestEvent $restEvent
|
[
"Get",
"a",
"RestEvent",
"object",
"-",
">",
"put",
"this",
"in",
"a",
"factory"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Subscriber/RestEventSubscriber.php#L97-L116
|
26,347
|
libgraviton/graviton
|
src/Graviton/ProxyBundle/Definition/ApiDefinition.php
|
ApiDefinition.hasEndpoint
|
public function hasEndpoint($endpoint)
{
$retVal = false;
if (isset($this->endpoints)) {
$retVal = in_array($endpoint, $this->endpoints);
}
return $retVal;
}
|
php
|
public function hasEndpoint($endpoint)
{
$retVal = false;
if (isset($this->endpoints)) {
$retVal = in_array($endpoint, $this->endpoints);
}
return $retVal;
}
|
[
"public",
"function",
"hasEndpoint",
"(",
"$",
"endpoint",
")",
"{",
"$",
"retVal",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"endpoints",
")",
")",
"{",
"$",
"retVal",
"=",
"in_array",
"(",
"$",
"endpoint",
",",
"$",
"this",
"->",
"endpoints",
")",
";",
"}",
"return",
"$",
"retVal",
";",
"}"
] |
check if an endpoint exists
@param string $endpoint endpoint
@return boolean
|
[
"check",
"if",
"an",
"endpoint",
"exists"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Definition/ApiDefinition.php#L127-L135
|
26,348
|
libgraviton/graviton
|
src/Graviton/ProxyBundle/Definition/ApiDefinition.php
|
ApiDefinition.getEndpoints
|
public function getEndpoints($withHost = true, $prefix = null, $host = '', $withBasePath = true)
{
$endpoints = [];
$basePath = "";
if ($withHost) {
$basePath = (empty($host)) ? $this->getHost() : $host;
}
if (!empty($prefix)) {
$basePath .= $prefix;
}
if ($withBasePath && isset($this->basePath)) {
$basePath .= $this->basePath;
}
foreach ($this->endpoints as $endpoint) {
$endpoints[] = $basePath.$endpoint;
}
return $endpoints;
}
|
php
|
public function getEndpoints($withHost = true, $prefix = null, $host = '', $withBasePath = true)
{
$endpoints = [];
$basePath = "";
if ($withHost) {
$basePath = (empty($host)) ? $this->getHost() : $host;
}
if (!empty($prefix)) {
$basePath .= $prefix;
}
if ($withBasePath && isset($this->basePath)) {
$basePath .= $this->basePath;
}
foreach ($this->endpoints as $endpoint) {
$endpoints[] = $basePath.$endpoint;
}
return $endpoints;
}
|
[
"public",
"function",
"getEndpoints",
"(",
"$",
"withHost",
"=",
"true",
",",
"$",
"prefix",
"=",
"null",
",",
"$",
"host",
"=",
"''",
",",
"$",
"withBasePath",
"=",
"true",
")",
"{",
"$",
"endpoints",
"=",
"[",
"]",
";",
"$",
"basePath",
"=",
"\"\"",
";",
"if",
"(",
"$",
"withHost",
")",
"{",
"$",
"basePath",
"=",
"(",
"empty",
"(",
"$",
"host",
")",
")",
"?",
"$",
"this",
"->",
"getHost",
"(",
")",
":",
"$",
"host",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"prefix",
")",
")",
"{",
"$",
"basePath",
".=",
"$",
"prefix",
";",
"}",
"if",
"(",
"$",
"withBasePath",
"&&",
"isset",
"(",
"$",
"this",
"->",
"basePath",
")",
")",
"{",
"$",
"basePath",
".=",
"$",
"this",
"->",
"basePath",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"endpoints",
"as",
"$",
"endpoint",
")",
"{",
"$",
"endpoints",
"[",
"]",
"=",
"$",
"basePath",
".",
"$",
"endpoint",
";",
"}",
"return",
"$",
"endpoints",
";",
"}"
] |
get all defined API endpoints
@param boolean $withHost url with hostname
@param string $prefix add a prefix to the url (blub/endpoint/url)
@param string $host Host to be used instead of the host defined in the swagger json
@param bool $withBasePath Defines whether the API's base path should be included or not
@return array
|
[
"get",
"all",
"defined",
"API",
"endpoints"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Definition/ApiDefinition.php#L147-L165
|
26,349
|
libgraviton/graviton
|
src/Graviton/ProxyBundle/Definition/ApiDefinition.php
|
ApiDefinition.getSchema
|
public function getSchema($endpoint)
{
//remove base path
if ('/' !== $this->basePath) {
$endpoint = str_replace($this->basePath, '', $endpoint);
}
$retVal = new \stdClass();
if (array_key_exists($endpoint, $this->schemes)) {
$retVal = $this->schemes[$endpoint];
}
return $retVal;
}
|
php
|
public function getSchema($endpoint)
{
//remove base path
if ('/' !== $this->basePath) {
$endpoint = str_replace($this->basePath, '', $endpoint);
}
$retVal = new \stdClass();
if (array_key_exists($endpoint, $this->schemes)) {
$retVal = $this->schemes[$endpoint];
}
return $retVal;
}
|
[
"public",
"function",
"getSchema",
"(",
"$",
"endpoint",
")",
"{",
"//remove base path",
"if",
"(",
"'/'",
"!==",
"$",
"this",
"->",
"basePath",
")",
"{",
"$",
"endpoint",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"basePath",
",",
"''",
",",
"$",
"endpoint",
")",
";",
"}",
"$",
"retVal",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"endpoint",
",",
"$",
"this",
"->",
"schemes",
")",
")",
"{",
"$",
"retVal",
"=",
"$",
"this",
"->",
"schemes",
"[",
"$",
"endpoint",
"]",
";",
"}",
"return",
"$",
"retVal",
";",
"}"
] |
get a schema for an endpoint
@param string $endpoint endpoint
@return \stdClass
|
[
"get",
"a",
"schema",
"for",
"an",
"endpoint"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Definition/ApiDefinition.php#L187-L199
|
26,350
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.hasController
|
public function hasController()
{
return $this->def->getService() !== null &&
$this->def->getService()->getRouterBase() !== null;
}
|
php
|
public function hasController()
{
return $this->def->getService() !== null &&
$this->def->getService()->getRouterBase() !== null;
}
|
[
"public",
"function",
"hasController",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"!==",
"null",
"&&",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getRouterBase",
"(",
")",
"!==",
"null",
";",
"}"
] |
Returns whether this definition requires the generation
of a controller. normally yes, but sometimes not ;-)
@return bool true if yes, false if no
|
[
"Returns",
"whether",
"this",
"definition",
"requires",
"the",
"generation",
"of",
"a",
"controller",
".",
"normally",
"yes",
"but",
"sometimes",
"not",
";",
"-",
")"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L94-L98
|
26,351
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.isReadOnlyService
|
public function isReadOnlyService()
{
if ($this->def->getService() === null) {
return false;
}
return $this->def->getService()->getReadOnly();
}
|
php
|
public function isReadOnlyService()
{
if ($this->def->getService() === null) {
return false;
}
return $this->def->getService()->getReadOnly();
}
|
[
"public",
"function",
"isReadOnlyService",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getReadOnly",
"(",
")",
";",
"}"
] |
Returns whether this service is read-only
@return bool true if yes, false if not
|
[
"Returns",
"whether",
"this",
"service",
"is",
"read",
"-",
"only"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L147-L154
|
26,352
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.isVersionedService
|
public function isVersionedService()
{
if ($this->def->getService() === null || !$this->def->getService()->getVersioning()) {
return false;
}
return (boolean) $this->def->getService()->getVersioning();
}
|
php
|
public function isVersionedService()
{
if ($this->def->getService() === null || !$this->def->getService()->getVersioning()) {
return false;
}
return (boolean) $this->def->getService()->getVersioning();
}
|
[
"public",
"function",
"isVersionedService",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"===",
"null",
"||",
"!",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getVersioning",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"boolean",
")",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getVersioning",
"(",
")",
";",
"}"
] |
Returns whether this service is versioning
@return bool true if yes, false if not
|
[
"Returns",
"whether",
"this",
"service",
"is",
"versioning"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L161-L168
|
26,353
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.getRouterBase
|
public function getRouterBase()
{
if ($this->def->getService() === null ||
$this->def->getService()->getRouterBase() === null) {
return false;
}
$routerBase = $this->def->getService()->getRouterBase();
if (substr($routerBase, 0, 1) !== '/') {
$routerBase = '/' . $routerBase;
}
if (substr($routerBase, -1) === '/') {
$routerBase = substr($routerBase, 0, -1);
}
return $routerBase;
}
|
php
|
public function getRouterBase()
{
if ($this->def->getService() === null ||
$this->def->getService()->getRouterBase() === null) {
return false;
}
$routerBase = $this->def->getService()->getRouterBase();
if (substr($routerBase, 0, 1) !== '/') {
$routerBase = '/' . $routerBase;
}
if (substr($routerBase, -1) === '/') {
$routerBase = substr($routerBase, 0, -1);
}
return $routerBase;
}
|
[
"public",
"function",
"getRouterBase",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"===",
"null",
"||",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getRouterBase",
"(",
")",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"$",
"routerBase",
"=",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getRouterBase",
"(",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"routerBase",
",",
"0",
",",
"1",
")",
"!==",
"'/'",
")",
"{",
"$",
"routerBase",
"=",
"'/'",
".",
"$",
"routerBase",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"routerBase",
",",
"-",
"1",
")",
"===",
"'/'",
")",
"{",
"$",
"routerBase",
"=",
"substr",
"(",
"$",
"routerBase",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"return",
"$",
"routerBase",
";",
"}"
] |
Returns a router base path. false if default should be used.
@return string router base, i.e. /bundle/name/
|
[
"Returns",
"a",
"router",
"base",
"path",
".",
"false",
"if",
"default",
"should",
"be",
"used",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L215-L231
|
26,354
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.getBaseController
|
public function getBaseController()
{
if ($this->def->getService() === null ||
$this->def->getService()->getBaseController() === null) {
return 'RestController';
}
return $this->def->getService()->getBaseController();
}
|
php
|
public function getBaseController()
{
if ($this->def->getService() === null ||
$this->def->getService()->getBaseController() === null) {
return 'RestController';
}
return $this->def->getService()->getBaseController();
}
|
[
"public",
"function",
"getBaseController",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"===",
"null",
"||",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getBaseController",
"(",
")",
"===",
"null",
")",
"{",
"return",
"'RestController'",
";",
"}",
"return",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getBaseController",
"(",
")",
";",
"}"
] |
Returns the Controller classname this services' controller shout inherit.
Defaults to the RestController of the RestBundle of course.
@return string base controller
|
[
"Returns",
"the",
"Controller",
"classname",
"this",
"services",
"controller",
"shout",
"inherit",
".",
"Defaults",
"to",
"the",
"RestController",
"of",
"the",
"RestBundle",
"of",
"course",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L239-L247
|
26,355
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.getParentService
|
public function getParentService()
{
if ($this->def->getService() === null ||
$this->def->getService()->getParent() === null) {
return 'graviton.rest.controller';
}
return $this->def->getService()->getParent();
}
|
php
|
public function getParentService()
{
if ($this->def->getService() === null ||
$this->def->getService()->getParent() === null) {
return 'graviton.rest.controller';
}
return $this->def->getService()->getParent();
}
|
[
"public",
"function",
"getParentService",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"===",
"null",
"||",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getParent",
"(",
")",
"===",
"null",
")",
"{",
"return",
"'graviton.rest.controller'",
";",
"}",
"return",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getParent",
"(",
")",
";",
"}"
] |
Returns the parent service to use when adding the service xml
Defaults to graviton.rest.controller
@return string base controller
|
[
"Returns",
"the",
"parent",
"service",
"to",
"use",
"when",
"adding",
"the",
"service",
"xml"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L256-L264
|
26,356
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.getFields
|
public function getFields()
{
$hierarchy = [];
foreach ($this->def->getTarget()->getFields() as $field) {
$hierarchy = array_merge_recursive(
$hierarchy,
$this->createFieldHierarchyRecursive($field, $field->getName())
);
}
$fields = [];
/*******
* CONDITIONAL GENERATED FIELD AREA
*
* so simplify things, you can put fields here that should be conditionally created by Graviton.
* @TODO refactor into a FieldBuilder* type of thing where different builders can add fields conditionally.
*/
// Versioning field, for version control.
if ($this->def->getService() && $this->def->getService()->getVersioning()) {
$definition = new Schema\Field();
$constraint = new Constraint();
$constraint->setName('versioning');
$definition->setName(VersionServiceConstraint::FIELD_NAME)->setTitle('Version')->setType('int')
->setConstraints([$constraint])
->setDescription('Document version. You need to send current version if you want to update.');
$fields['version'] = $this->processSimpleField('version', $definition);
}
/*******
* add fields as defined in the definition file.
*/
foreach ($hierarchy as $name => $definition) {
$fields[$name] = $this->processFieldHierarchyRecursive($name, $definition);
}
return $fields;
}
|
php
|
public function getFields()
{
$hierarchy = [];
foreach ($this->def->getTarget()->getFields() as $field) {
$hierarchy = array_merge_recursive(
$hierarchy,
$this->createFieldHierarchyRecursive($field, $field->getName())
);
}
$fields = [];
/*******
* CONDITIONAL GENERATED FIELD AREA
*
* so simplify things, you can put fields here that should be conditionally created by Graviton.
* @TODO refactor into a FieldBuilder* type of thing where different builders can add fields conditionally.
*/
// Versioning field, for version control.
if ($this->def->getService() && $this->def->getService()->getVersioning()) {
$definition = new Schema\Field();
$constraint = new Constraint();
$constraint->setName('versioning');
$definition->setName(VersionServiceConstraint::FIELD_NAME)->setTitle('Version')->setType('int')
->setConstraints([$constraint])
->setDescription('Document version. You need to send current version if you want to update.');
$fields['version'] = $this->processSimpleField('version', $definition);
}
/*******
* add fields as defined in the definition file.
*/
foreach ($hierarchy as $name => $definition) {
$fields[$name] = $this->processFieldHierarchyRecursive($name, $definition);
}
return $fields;
}
|
[
"public",
"function",
"getFields",
"(",
")",
"{",
"$",
"hierarchy",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"def",
"->",
"getTarget",
"(",
")",
"->",
"getFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"hierarchy",
"=",
"array_merge_recursive",
"(",
"$",
"hierarchy",
",",
"$",
"this",
"->",
"createFieldHierarchyRecursive",
"(",
"$",
"field",
",",
"$",
"field",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"$",
"fields",
"=",
"[",
"]",
";",
"/*******\n * CONDITIONAL GENERATED FIELD AREA\n *\n * so simplify things, you can put fields here that should be conditionally created by Graviton.\n * @TODO refactor into a FieldBuilder* type of thing where different builders can add fields conditionally.\n */",
"// Versioning field, for version control.",
"if",
"(",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"&&",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getVersioning",
"(",
")",
")",
"{",
"$",
"definition",
"=",
"new",
"Schema",
"\\",
"Field",
"(",
")",
";",
"$",
"constraint",
"=",
"new",
"Constraint",
"(",
")",
";",
"$",
"constraint",
"->",
"setName",
"(",
"'versioning'",
")",
";",
"$",
"definition",
"->",
"setName",
"(",
"VersionServiceConstraint",
"::",
"FIELD_NAME",
")",
"->",
"setTitle",
"(",
"'Version'",
")",
"->",
"setType",
"(",
"'int'",
")",
"->",
"setConstraints",
"(",
"[",
"$",
"constraint",
"]",
")",
"->",
"setDescription",
"(",
"'Document version. You need to send current version if you want to update.'",
")",
";",
"$",
"fields",
"[",
"'version'",
"]",
"=",
"$",
"this",
"->",
"processSimpleField",
"(",
"'version'",
",",
"$",
"definition",
")",
";",
"}",
"/*******\n * add fields as defined in the definition file.\n */",
"foreach",
"(",
"$",
"hierarchy",
"as",
"$",
"name",
"=>",
"$",
"definition",
")",
"{",
"$",
"fields",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"processFieldHierarchyRecursive",
"(",
"$",
"name",
",",
"$",
"definition",
")",
";",
"}",
"return",
"$",
"fields",
";",
"}"
] |
Returns the field definition
@return DefinitionElementInterface[] Fields
|
[
"Returns",
"the",
"field",
"definition"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L284-L323
|
26,357
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.getRelations
|
public function getRelations()
{
if ($this->def->getTarget() === null) {
return [];
}
$relations = [];
foreach ($this->def->getTarget()->getRelations() as $relation) {
$relations[$relation->getLocalProperty()] = $relation;
}
return $relations;
}
|
php
|
public function getRelations()
{
if ($this->def->getTarget() === null) {
return [];
}
$relations = [];
foreach ($this->def->getTarget()->getRelations() as $relation) {
$relations[$relation->getLocalProperty()] = $relation;
}
return $relations;
}
|
[
"public",
"function",
"getRelations",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"def",
"->",
"getTarget",
"(",
")",
"===",
"null",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"relations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"def",
"->",
"getTarget",
"(",
")",
"->",
"getRelations",
"(",
")",
"as",
"$",
"relation",
")",
"{",
"$",
"relations",
"[",
"$",
"relation",
"->",
"getLocalProperty",
"(",
")",
"]",
"=",
"$",
"relation",
";",
"}",
"return",
"$",
"relations",
";",
"}"
] |
Get target relations which are explictly defined
@return Schema\Relation[] relations
|
[
"Get",
"target",
"relations",
"which",
"are",
"explictly",
"defined"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L408-L420
|
26,358
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.getRelation
|
private function getRelation($field)
{
$relations = $this->getRelations();
return isset($relations[$field]) ? $relations[$field] : null;
}
|
php
|
private function getRelation($field)
{
$relations = $this->getRelations();
return isset($relations[$field]) ? $relations[$field] : null;
}
|
[
"private",
"function",
"getRelation",
"(",
"$",
"field",
")",
"{",
"$",
"relations",
"=",
"$",
"this",
"->",
"getRelations",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"relations",
"[",
"$",
"field",
"]",
")",
"?",
"$",
"relations",
"[",
"$",
"field",
"]",
":",
"null",
";",
"}"
] |
Get relation by field name
@param string $field Field name
@return Schema\Relation|null
|
[
"Get",
"relation",
"by",
"field",
"name"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L428-L432
|
26,359
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.getSolrFields
|
public function getSolrFields()
{
$solr = $this->def->getSolr();
if (!$solr instanceof Solr) {
return [];
}
$fields = [];
foreach ($solr->getFields() as $field) {
$fields[] = [
'name' => $field->getName(),
'type' => $field->getType(),
'weight' => $field->getWeight()
];
}
return $fields;
}
|
php
|
public function getSolrFields()
{
$solr = $this->def->getSolr();
if (!$solr instanceof Solr) {
return [];
}
$fields = [];
foreach ($solr->getFields() as $field) {
$fields[] = [
'name' => $field->getName(),
'type' => $field->getType(),
'weight' => $field->getWeight()
];
}
return $fields;
}
|
[
"public",
"function",
"getSolrFields",
"(",
")",
"{",
"$",
"solr",
"=",
"$",
"this",
"->",
"def",
"->",
"getSolr",
"(",
")",
";",
"if",
"(",
"!",
"$",
"solr",
"instanceof",
"Solr",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"solr",
"->",
"getFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"fields",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"field",
"->",
"getName",
"(",
")",
",",
"'type'",
"=>",
"$",
"field",
"->",
"getType",
"(",
")",
",",
"'weight'",
"=>",
"$",
"field",
"->",
"getWeight",
"(",
")",
"]",
";",
"}",
"return",
"$",
"fields",
";",
"}"
] |
gets information about solr
@return array|Schema\Solr
|
[
"gets",
"information",
"about",
"solr"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L467-L484
|
26,360
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.isRecordOriginModifiable
|
public function isRecordOriginModifiable()
{
$retVal = false;
if ($this->isRecordOriginFlagSet()) {
$retVal = $this->def->getService()->getRecordOriginModifiable();
}
return $retVal;
}
|
php
|
public function isRecordOriginModifiable()
{
$retVal = false;
if ($this->isRecordOriginFlagSet()) {
$retVal = $this->def->getService()->getRecordOriginModifiable();
}
return $retVal;
}
|
[
"public",
"function",
"isRecordOriginModifiable",
"(",
")",
"{",
"$",
"retVal",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"isRecordOriginFlagSet",
"(",
")",
")",
"{",
"$",
"retVal",
"=",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getRecordOriginModifiable",
"(",
")",
";",
"}",
"return",
"$",
"retVal",
";",
"}"
] |
Can record origin be modified
@return bool
|
[
"Can",
"record",
"origin",
"be",
"modified"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L505-L513
|
26,361
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Definition/JsonDefinition.php
|
JsonDefinition.isRecordOriginFlagSet
|
public function isRecordOriginFlagSet()
{
$retVal = false;
if ($this->def->getService() !== null
&& is_object($this->def->getService())
&& $this->def->getService()->getRecordOriginModifiable() !== null) {
$retVal = true;
}
return $retVal;
}
|
php
|
public function isRecordOriginFlagSet()
{
$retVal = false;
if ($this->def->getService() !== null
&& is_object($this->def->getService())
&& $this->def->getService()->getRecordOriginModifiable() !== null) {
$retVal = true;
}
return $retVal;
}
|
[
"public",
"function",
"isRecordOriginFlagSet",
"(",
")",
"{",
"$",
"retVal",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"!==",
"null",
"&&",
"is_object",
"(",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"def",
"->",
"getService",
"(",
")",
"->",
"getRecordOriginModifiable",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"retVal",
"=",
"true",
";",
"}",
"return",
"$",
"retVal",
";",
"}"
] |
check if the RecordOriginModifiable flag is set
@return bool
|
[
"check",
"if",
"the",
"RecordOriginModifiable",
"flag",
"is",
"set"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Definition/JsonDefinition.php#L520-L530
|
26,362
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/Serializer/Handler/DateHandler.php
|
DateHandler.deserializeDateTimeFromJson
|
public function deserializeDateTimeFromJson(JsonDeserializationVisitor $visitor, $data, array $type)
{
if (null === $data) {
return null;
}
return parent::deserializeDateTimeFromJson(
$visitor,
$this->dateConverter->getDateTimeStringInFormat($data),
$type
);
}
|
php
|
public function deserializeDateTimeFromJson(JsonDeserializationVisitor $visitor, $data, array $type)
{
if (null === $data) {
return null;
}
return parent::deserializeDateTimeFromJson(
$visitor,
$this->dateConverter->getDateTimeStringInFormat($data),
$type
);
}
|
[
"public",
"function",
"deserializeDateTimeFromJson",
"(",
"JsonDeserializationVisitor",
"$",
"visitor",
",",
"$",
"data",
",",
"array",
"$",
"type",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"data",
")",
"{",
"return",
"null",
";",
"}",
"return",
"parent",
"::",
"deserializeDateTimeFromJson",
"(",
"$",
"visitor",
",",
"$",
"this",
"->",
"dateConverter",
"->",
"getDateTimeStringInFormat",
"(",
"$",
"data",
")",
",",
"$",
"type",
")",
";",
"}"
] |
serialize datetime from json
@param JsonDeserializationVisitor $visitor visitor
@param string $data data
@param array $type type
@return \DateTime|null DateTime instance
|
[
"serialize",
"datetime",
"from",
"json"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Serializer/Handler/DateHandler.php#L71-L82
|
26,363
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/Serializer/Handler/DateHandler.php
|
DateHandler.serializeDateTime
|
public function serializeDateTime(VisitorInterface $visitor, \DateTime $date, array $type, Context $context)
{
return $visitor->visitString($this->dateConverter->formatDateTime($date), $type, $context);
}
|
php
|
public function serializeDateTime(VisitorInterface $visitor, \DateTime $date, array $type, Context $context)
{
return $visitor->visitString($this->dateConverter->formatDateTime($date), $type, $context);
}
|
[
"public",
"function",
"serializeDateTime",
"(",
"VisitorInterface",
"$",
"visitor",
",",
"\\",
"DateTime",
"$",
"date",
",",
"array",
"$",
"type",
",",
"Context",
"$",
"context",
")",
"{",
"return",
"$",
"visitor",
"->",
"visitString",
"(",
"$",
"this",
"->",
"dateConverter",
"->",
"formatDateTime",
"(",
"$",
"date",
")",
",",
"$",
"type",
",",
"$",
"context",
")",
";",
"}"
] |
serialize datetime to json
@param VisitorInterface $visitor visitor
@param \DateTime $date data
@param array $type type
@param Context $context context
@return string serialized date
|
[
"serialize",
"datetime",
"to",
"json"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/Serializer/Handler/DateHandler.php#L94-L97
|
26,364
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php
|
DocumentMap.loadDoctrineClassMap
|
private function loadDoctrineClassMap(Finder $finder)
{
$classMap = [];
foreach ($finder as $file) {
$classMap = array_merge(
$classMap,
Yaml::parseFile($file)
);
}
// filter out superclasses
$classMap = array_filter(
$classMap,
function ($classEntry) {
return (!isset($classEntry['type']) || $classEntry['type'] != 'mappedSuperclass');
}
);
return $classMap;
}
|
php
|
private function loadDoctrineClassMap(Finder $finder)
{
$classMap = [];
foreach ($finder as $file) {
$classMap = array_merge(
$classMap,
Yaml::parseFile($file)
);
}
// filter out superclasses
$classMap = array_filter(
$classMap,
function ($classEntry) {
return (!isset($classEntry['type']) || $classEntry['type'] != 'mappedSuperclass');
}
);
return $classMap;
}
|
[
"private",
"function",
"loadDoctrineClassMap",
"(",
"Finder",
"$",
"finder",
")",
"{",
"$",
"classMap",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"classMap",
"=",
"array_merge",
"(",
"$",
"classMap",
",",
"Yaml",
"::",
"parseFile",
"(",
"$",
"file",
")",
")",
";",
"}",
"// filter out superclasses",
"$",
"classMap",
"=",
"array_filter",
"(",
"$",
"classMap",
",",
"function",
"(",
"$",
"classEntry",
")",
"{",
"return",
"(",
"!",
"isset",
"(",
"$",
"classEntry",
"[",
"'type'",
"]",
")",
"||",
"$",
"classEntry",
"[",
"'type'",
"]",
"!=",
"'mappedSuperclass'",
")",
";",
"}",
")",
";",
"return",
"$",
"classMap",
";",
"}"
] |
Load doctrine class map
@param Finder $finder Mapping finder
@return array
|
[
"Load",
"doctrine",
"class",
"map"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php#L210-L229
|
26,365
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php
|
DocumentMap.loadSerializerClassMap
|
private function loadSerializerClassMap(Finder $finder)
{
$classMap = [];
foreach ($finder as $file) {
$document = new \DOMDocument();
$document->load($file);
$xpath = new \DOMXPath($document);
$classMap = array_reduce(
iterator_to_array($xpath->query('//class')),
function (array $classMap, \DOMElement $element) {
$classMap[$element->getAttribute('name')] = $element;
return $classMap;
},
$classMap
);
}
return $classMap;
}
|
php
|
private function loadSerializerClassMap(Finder $finder)
{
$classMap = [];
foreach ($finder as $file) {
$document = new \DOMDocument();
$document->load($file);
$xpath = new \DOMXPath($document);
$classMap = array_reduce(
iterator_to_array($xpath->query('//class')),
function (array $classMap, \DOMElement $element) {
$classMap[$element->getAttribute('name')] = $element;
return $classMap;
},
$classMap
);
}
return $classMap;
}
|
[
"private",
"function",
"loadSerializerClassMap",
"(",
"Finder",
"$",
"finder",
")",
"{",
"$",
"classMap",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"document",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"$",
"document",
"->",
"load",
"(",
"$",
"file",
")",
";",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXPath",
"(",
"$",
"document",
")",
";",
"$",
"classMap",
"=",
"array_reduce",
"(",
"iterator_to_array",
"(",
"$",
"xpath",
"->",
"query",
"(",
"'//class'",
")",
")",
",",
"function",
"(",
"array",
"$",
"classMap",
",",
"\\",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"classMap",
"[",
"$",
"element",
"->",
"getAttribute",
"(",
"'name'",
")",
"]",
"=",
"$",
"element",
";",
"return",
"$",
"classMap",
";",
"}",
",",
"$",
"classMap",
")",
";",
"}",
"return",
"$",
"classMap",
";",
"}"
] |
Load serializer class map
@param Finder $finder Mapping finder
@return array
|
[
"Load",
"serializer",
"class",
"map"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php#L237-L257
|
26,366
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php
|
DocumentMap.loadSchemaClassMap
|
private function loadSchemaClassMap(Finder $finder)
{
$classMap = [];
foreach ($finder as $file) {
$schema = json_decode(file_get_contents($file), true);
if (!isset($schema['x-documentClass'])) {
continue;
}
foreach ($schema['required'] as $field) {
$classMap[$schema['x-documentClass']][$field]['required'] = true;
}
foreach ($schema['searchable'] as $field) {
$classMap[$schema['x-documentClass']][$field]['searchable'] = 1;
}
foreach ($schema['readOnlyFields'] as $field) {
$classMap[$schema['x-documentClass']][$field]['readOnly'] = true;
}
// flags from fields
if (is_array($schema['properties'])) {
foreach ($schema['properties'] as $fieldName => $field) {
if (isset($field['recordOriginException']) && $field['recordOriginException'] == true) {
$classMap[$schema['x-documentClass']][$fieldName]['recordOriginException'] = true;
}
if (isset($field['x-restrictions'])) {
$classMap[$schema['x-documentClass']][$fieldName]['restrictions'] = $field['x-restrictions'];
} else {
$classMap[$schema['x-documentClass']][$fieldName]['restrictions'] = [];
}
}
}
if (isset($schema['solr']) && is_array($schema['solr']) && !empty($schema['solr'])) {
$classMap[$schema['x-documentClass']]['_base']['solr'] = $schema['solr'];
} else {
$classMap[$schema['x-documentClass']]['_base']['solr'] = [];
}
}
return $classMap;
}
|
php
|
private function loadSchemaClassMap(Finder $finder)
{
$classMap = [];
foreach ($finder as $file) {
$schema = json_decode(file_get_contents($file), true);
if (!isset($schema['x-documentClass'])) {
continue;
}
foreach ($schema['required'] as $field) {
$classMap[$schema['x-documentClass']][$field]['required'] = true;
}
foreach ($schema['searchable'] as $field) {
$classMap[$schema['x-documentClass']][$field]['searchable'] = 1;
}
foreach ($schema['readOnlyFields'] as $field) {
$classMap[$schema['x-documentClass']][$field]['readOnly'] = true;
}
// flags from fields
if (is_array($schema['properties'])) {
foreach ($schema['properties'] as $fieldName => $field) {
if (isset($field['recordOriginException']) && $field['recordOriginException'] == true) {
$classMap[$schema['x-documentClass']][$fieldName]['recordOriginException'] = true;
}
if (isset($field['x-restrictions'])) {
$classMap[$schema['x-documentClass']][$fieldName]['restrictions'] = $field['x-restrictions'];
} else {
$classMap[$schema['x-documentClass']][$fieldName]['restrictions'] = [];
}
}
}
if (isset($schema['solr']) && is_array($schema['solr']) && !empty($schema['solr'])) {
$classMap[$schema['x-documentClass']]['_base']['solr'] = $schema['solr'];
} else {
$classMap[$schema['x-documentClass']]['_base']['solr'] = [];
}
}
return $classMap;
}
|
[
"private",
"function",
"loadSchemaClassMap",
"(",
"Finder",
"$",
"finder",
")",
"{",
"$",
"classMap",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"schema",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"schema",
"[",
"'x-documentClass'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"schema",
"[",
"'required'",
"]",
"as",
"$",
"field",
")",
"{",
"$",
"classMap",
"[",
"$",
"schema",
"[",
"'x-documentClass'",
"]",
"]",
"[",
"$",
"field",
"]",
"[",
"'required'",
"]",
"=",
"true",
";",
"}",
"foreach",
"(",
"$",
"schema",
"[",
"'searchable'",
"]",
"as",
"$",
"field",
")",
"{",
"$",
"classMap",
"[",
"$",
"schema",
"[",
"'x-documentClass'",
"]",
"]",
"[",
"$",
"field",
"]",
"[",
"'searchable'",
"]",
"=",
"1",
";",
"}",
"foreach",
"(",
"$",
"schema",
"[",
"'readOnlyFields'",
"]",
"as",
"$",
"field",
")",
"{",
"$",
"classMap",
"[",
"$",
"schema",
"[",
"'x-documentClass'",
"]",
"]",
"[",
"$",
"field",
"]",
"[",
"'readOnly'",
"]",
"=",
"true",
";",
"}",
"// flags from fields",
"if",
"(",
"is_array",
"(",
"$",
"schema",
"[",
"'properties'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"schema",
"[",
"'properties'",
"]",
"as",
"$",
"fieldName",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'recordOriginException'",
"]",
")",
"&&",
"$",
"field",
"[",
"'recordOriginException'",
"]",
"==",
"true",
")",
"{",
"$",
"classMap",
"[",
"$",
"schema",
"[",
"'x-documentClass'",
"]",
"]",
"[",
"$",
"fieldName",
"]",
"[",
"'recordOriginException'",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'x-restrictions'",
"]",
")",
")",
"{",
"$",
"classMap",
"[",
"$",
"schema",
"[",
"'x-documentClass'",
"]",
"]",
"[",
"$",
"fieldName",
"]",
"[",
"'restrictions'",
"]",
"=",
"$",
"field",
"[",
"'x-restrictions'",
"]",
";",
"}",
"else",
"{",
"$",
"classMap",
"[",
"$",
"schema",
"[",
"'x-documentClass'",
"]",
"]",
"[",
"$",
"fieldName",
"]",
"[",
"'restrictions'",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"schema",
"[",
"'solr'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"schema",
"[",
"'solr'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"schema",
"[",
"'solr'",
"]",
")",
")",
"{",
"$",
"classMap",
"[",
"$",
"schema",
"[",
"'x-documentClass'",
"]",
"]",
"[",
"'_base'",
"]",
"[",
"'solr'",
"]",
"=",
"$",
"schema",
"[",
"'solr'",
"]",
";",
"}",
"else",
"{",
"$",
"classMap",
"[",
"$",
"schema",
"[",
"'x-documentClass'",
"]",
"]",
"[",
"'_base'",
"]",
"[",
"'solr'",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"return",
"$",
"classMap",
";",
"}"
] |
Load schema class map
@param Finder $finder Mapping finder
@return array
|
[
"Load",
"schema",
"class",
"map"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php#L265-L307
|
26,367
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php
|
DocumentMap.getSerializerFields
|
private function getSerializerFields(\DOMElement $mapping)
{
$xpath = new \DOMXPath($mapping->ownerDocument);
return array_map(
function (\DOMElement $element) {
return [
'fieldName' => $element->getAttribute('name'),
'fieldType' => $this->getSerializerFieldType($element),
'exposedName' => $element->getAttribute('serialized-name') ?: $element->getAttribute('name'),
'readOnly' => $element->getAttribute('read-only') === 'true',
'searchable' => (int) $element->getAttribute('searchable')
];
},
iterator_to_array($xpath->query('property', $mapping))
);
}
|
php
|
private function getSerializerFields(\DOMElement $mapping)
{
$xpath = new \DOMXPath($mapping->ownerDocument);
return array_map(
function (\DOMElement $element) {
return [
'fieldName' => $element->getAttribute('name'),
'fieldType' => $this->getSerializerFieldType($element),
'exposedName' => $element->getAttribute('serialized-name') ?: $element->getAttribute('name'),
'readOnly' => $element->getAttribute('read-only') === 'true',
'searchable' => (int) $element->getAttribute('searchable')
];
},
iterator_to_array($xpath->query('property', $mapping))
);
}
|
[
"private",
"function",
"getSerializerFields",
"(",
"\\",
"DOMElement",
"$",
"mapping",
")",
"{",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXPath",
"(",
"$",
"mapping",
"->",
"ownerDocument",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"\\",
"DOMElement",
"$",
"element",
")",
"{",
"return",
"[",
"'fieldName'",
"=>",
"$",
"element",
"->",
"getAttribute",
"(",
"'name'",
")",
",",
"'fieldType'",
"=>",
"$",
"this",
"->",
"getSerializerFieldType",
"(",
"$",
"element",
")",
",",
"'exposedName'",
"=>",
"$",
"element",
"->",
"getAttribute",
"(",
"'serialized-name'",
")",
"?",
":",
"$",
"element",
"->",
"getAttribute",
"(",
"'name'",
")",
",",
"'readOnly'",
"=>",
"$",
"element",
"->",
"getAttribute",
"(",
"'read-only'",
")",
"===",
"'true'",
",",
"'searchable'",
"=>",
"(",
"int",
")",
"$",
"element",
"->",
"getAttribute",
"(",
"'searchable'",
")",
"]",
";",
"}",
",",
"iterator_to_array",
"(",
"$",
"xpath",
"->",
"query",
"(",
"'property'",
",",
"$",
"mapping",
")",
")",
")",
";",
"}"
] |
Get serializer fields
@param \DOMElement $mapping Serializer XML mapping
@return array
|
[
"Get",
"serializer",
"fields"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php#L315-L331
|
26,368
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php
|
DocumentMap.getSerializerFieldType
|
private function getSerializerFieldType(\DOMElement $field)
{
if ($field->getAttribute('type')) {
return $field->getAttribute('type');
}
$xpath = new \DOMXPath($field->ownerDocument);
$type = $xpath->query('type', $field)->item(0);
return $type === null ? null : $type->nodeValue;
}
|
php
|
private function getSerializerFieldType(\DOMElement $field)
{
if ($field->getAttribute('type')) {
return $field->getAttribute('type');
}
$xpath = new \DOMXPath($field->ownerDocument);
$type = $xpath->query('type', $field)->item(0);
return $type === null ? null : $type->nodeValue;
}
|
[
"private",
"function",
"getSerializerFieldType",
"(",
"\\",
"DOMElement",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"getAttribute",
"(",
"'type'",
")",
")",
"{",
"return",
"$",
"field",
"->",
"getAttribute",
"(",
"'type'",
")",
";",
"}",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXPath",
"(",
"$",
"field",
"->",
"ownerDocument",
")",
";",
"$",
"type",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'type'",
",",
"$",
"field",
")",
"->",
"item",
"(",
"0",
")",
";",
"return",
"$",
"type",
"===",
"null",
"?",
"null",
":",
"$",
"type",
"->",
"nodeValue",
";",
"}"
] |
Get serializer field type
@param \DOMElement $field Field node
@return string|null
|
[
"Get",
"serializer",
"field",
"type"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php#L339-L349
|
26,369
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php
|
DocumentMap.getDoctrineFields
|
private function getDoctrineFields(array $mapping)
{
if (!isset($mapping['fields'])) {
return [];
}
return array_map(
function ($key, $value) {
if (!isset($value['type'])) {
$value['type'] = '';
}
return [
'name' => $key,
'type' => $value['type']
];
},
array_keys($mapping['fields']),
$mapping['fields']
);
}
|
php
|
private function getDoctrineFields(array $mapping)
{
if (!isset($mapping['fields'])) {
return [];
}
return array_map(
function ($key, $value) {
if (!isset($value['type'])) {
$value['type'] = '';
}
return [
'name' => $key,
'type' => $value['type']
];
},
array_keys($mapping['fields']),
$mapping['fields']
);
}
|
[
"private",
"function",
"getDoctrineFields",
"(",
"array",
"$",
"mapping",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'fields'",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"array_map",
"(",
"function",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"value",
"[",
"'type'",
"]",
"=",
"''",
";",
"}",
"return",
"[",
"'name'",
"=>",
"$",
"key",
",",
"'type'",
"=>",
"$",
"value",
"[",
"'type'",
"]",
"]",
";",
"}",
",",
"array_keys",
"(",
"$",
"mapping",
"[",
"'fields'",
"]",
")",
",",
"$",
"mapping",
"[",
"'fields'",
"]",
")",
";",
"}"
] |
Get doctrine document fields
@param array $mapping Doctrine mapping
@return array
|
[
"Get",
"doctrine",
"document",
"fields"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php#L357-L377
|
26,370
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php
|
DocumentMap.getRelationList
|
private function getRelationList($mapping, $suffix)
{
if (!isset($mapping['embed'.$suffix]) && !isset($mapping['reference'.$suffix])) {
return [];
}
$relations = [];
if (isset($mapping['embed'.$suffix])) {
$relations = array_merge($relations, $mapping['embed'.$suffix]);
}
if (isset($mapping['reference'.$suffix])) {
$relations = array_merge($relations, $mapping['reference'.$suffix]);
}
return array_map(
function ($key, $value) {
return [
'name' => $key,
'type' => $value['targetDocument']
];
},
array_keys($relations),
$relations
);
}
|
php
|
private function getRelationList($mapping, $suffix)
{
if (!isset($mapping['embed'.$suffix]) && !isset($mapping['reference'.$suffix])) {
return [];
}
$relations = [];
if (isset($mapping['embed'.$suffix])) {
$relations = array_merge($relations, $mapping['embed'.$suffix]);
}
if (isset($mapping['reference'.$suffix])) {
$relations = array_merge($relations, $mapping['reference'.$suffix]);
}
return array_map(
function ($key, $value) {
return [
'name' => $key,
'type' => $value['targetDocument']
];
},
array_keys($relations),
$relations
);
}
|
[
"private",
"function",
"getRelationList",
"(",
"$",
"mapping",
",",
"$",
"suffix",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'embed'",
".",
"$",
"suffix",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'reference'",
".",
"$",
"suffix",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"relations",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'embed'",
".",
"$",
"suffix",
"]",
")",
")",
"{",
"$",
"relations",
"=",
"array_merge",
"(",
"$",
"relations",
",",
"$",
"mapping",
"[",
"'embed'",
".",
"$",
"suffix",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'reference'",
".",
"$",
"suffix",
"]",
")",
")",
"{",
"$",
"relations",
"=",
"array_merge",
"(",
"$",
"relations",
",",
"$",
"mapping",
"[",
"'reference'",
".",
"$",
"suffix",
"]",
")",
";",
"}",
"return",
"array_map",
"(",
"function",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"key",
",",
"'type'",
"=>",
"$",
"value",
"[",
"'targetDocument'",
"]",
"]",
";",
"}",
",",
"array_keys",
"(",
"$",
"relations",
")",
",",
"$",
"relations",
")",
";",
"}"
] |
gets list of relations
@param array $mapping mapping
@param string $suffix suffix
@return array relations
|
[
"gets",
"list",
"of",
"relations"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php#L409-L433
|
26,371
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php
|
DocumentMap.getFieldNamesFlat
|
public function getFieldNamesFlat(
Document $document,
$documentPrefix = '',
$exposedPrefix = '',
callable $callback = null,
$returnFullField = false
) {
$result = [];
foreach ($document->getFields() as $field) {
if ($this->getFlatFieldCheckCallback($field, $callback)) {
if ($returnFullField) {
$setValue = $field;
} else {
$setValue = $exposedPrefix . $field->getExposedName();
}
$result[$documentPrefix . $field->getFieldName()] = $setValue;
}
if ($field instanceof ArrayField) {
if ($this->getFlatFieldCheckCallback($field, $callback)) {
if ($returnFullField) {
$setValue = $field;
} else {
$setValue = $exposedPrefix . $field->getExposedName() . '.0';
}
$result[$documentPrefix . $field->getFieldName() . '.0'] = $setValue;
}
} elseif ($field instanceof EmbedOne) {
$result = array_merge(
$result,
$this->getFieldNamesFlat(
$field->getDocument(),
$documentPrefix.$field->getFieldName().'.',
$exposedPrefix.$field->getExposedName().'.',
$callback,
$returnFullField
)
);
} elseif ($field instanceof EmbedMany) {
if ($this->getFlatFieldCheckCallback($field, $callback)) {
if ($returnFullField) {
$setValue = $field;
} else {
$setValue = $exposedPrefix . $field->getExposedName() . '.0';
}
$result[$documentPrefix . $field->getFieldName() . '.0'] = $setValue;
}
$result = array_merge(
$result,
$this->getFieldNamesFlat(
$field->getDocument(),
$documentPrefix.$field->getFieldName().'.0.',
$exposedPrefix.$field->getExposedName().'.0.',
$callback,
$returnFullField
)
);
}
}
return $result;
}
|
php
|
public function getFieldNamesFlat(
Document $document,
$documentPrefix = '',
$exposedPrefix = '',
callable $callback = null,
$returnFullField = false
) {
$result = [];
foreach ($document->getFields() as $field) {
if ($this->getFlatFieldCheckCallback($field, $callback)) {
if ($returnFullField) {
$setValue = $field;
} else {
$setValue = $exposedPrefix . $field->getExposedName();
}
$result[$documentPrefix . $field->getFieldName()] = $setValue;
}
if ($field instanceof ArrayField) {
if ($this->getFlatFieldCheckCallback($field, $callback)) {
if ($returnFullField) {
$setValue = $field;
} else {
$setValue = $exposedPrefix . $field->getExposedName() . '.0';
}
$result[$documentPrefix . $field->getFieldName() . '.0'] = $setValue;
}
} elseif ($field instanceof EmbedOne) {
$result = array_merge(
$result,
$this->getFieldNamesFlat(
$field->getDocument(),
$documentPrefix.$field->getFieldName().'.',
$exposedPrefix.$field->getExposedName().'.',
$callback,
$returnFullField
)
);
} elseif ($field instanceof EmbedMany) {
if ($this->getFlatFieldCheckCallback($field, $callback)) {
if ($returnFullField) {
$setValue = $field;
} else {
$setValue = $exposedPrefix . $field->getExposedName() . '.0';
}
$result[$documentPrefix . $field->getFieldName() . '.0'] = $setValue;
}
$result = array_merge(
$result,
$this->getFieldNamesFlat(
$field->getDocument(),
$documentPrefix.$field->getFieldName().'.0.',
$exposedPrefix.$field->getExposedName().'.0.',
$callback,
$returnFullField
)
);
}
}
return $result;
}
|
[
"public",
"function",
"getFieldNamesFlat",
"(",
"Document",
"$",
"document",
",",
"$",
"documentPrefix",
"=",
"''",
",",
"$",
"exposedPrefix",
"=",
"''",
",",
"callable",
"$",
"callback",
"=",
"null",
",",
"$",
"returnFullField",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"document",
"->",
"getFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getFlatFieldCheckCallback",
"(",
"$",
"field",
",",
"$",
"callback",
")",
")",
"{",
"if",
"(",
"$",
"returnFullField",
")",
"{",
"$",
"setValue",
"=",
"$",
"field",
";",
"}",
"else",
"{",
"$",
"setValue",
"=",
"$",
"exposedPrefix",
".",
"$",
"field",
"->",
"getExposedName",
"(",
")",
";",
"}",
"$",
"result",
"[",
"$",
"documentPrefix",
".",
"$",
"field",
"->",
"getFieldName",
"(",
")",
"]",
"=",
"$",
"setValue",
";",
"}",
"if",
"(",
"$",
"field",
"instanceof",
"ArrayField",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getFlatFieldCheckCallback",
"(",
"$",
"field",
",",
"$",
"callback",
")",
")",
"{",
"if",
"(",
"$",
"returnFullField",
")",
"{",
"$",
"setValue",
"=",
"$",
"field",
";",
"}",
"else",
"{",
"$",
"setValue",
"=",
"$",
"exposedPrefix",
".",
"$",
"field",
"->",
"getExposedName",
"(",
")",
".",
"'.0'",
";",
"}",
"$",
"result",
"[",
"$",
"documentPrefix",
".",
"$",
"field",
"->",
"getFieldName",
"(",
")",
".",
"'.0'",
"]",
"=",
"$",
"setValue",
";",
"}",
"}",
"elseif",
"(",
"$",
"field",
"instanceof",
"EmbedOne",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"getFieldNamesFlat",
"(",
"$",
"field",
"->",
"getDocument",
"(",
")",
",",
"$",
"documentPrefix",
".",
"$",
"field",
"->",
"getFieldName",
"(",
")",
".",
"'.'",
",",
"$",
"exposedPrefix",
".",
"$",
"field",
"->",
"getExposedName",
"(",
")",
".",
"'.'",
",",
"$",
"callback",
",",
"$",
"returnFullField",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"field",
"instanceof",
"EmbedMany",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getFlatFieldCheckCallback",
"(",
"$",
"field",
",",
"$",
"callback",
")",
")",
"{",
"if",
"(",
"$",
"returnFullField",
")",
"{",
"$",
"setValue",
"=",
"$",
"field",
";",
"}",
"else",
"{",
"$",
"setValue",
"=",
"$",
"exposedPrefix",
".",
"$",
"field",
"->",
"getExposedName",
"(",
")",
".",
"'.0'",
";",
"}",
"$",
"result",
"[",
"$",
"documentPrefix",
".",
"$",
"field",
"->",
"getFieldName",
"(",
")",
".",
"'.0'",
"]",
"=",
"$",
"setValue",
";",
"}",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"getFieldNamesFlat",
"(",
"$",
"field",
"->",
"getDocument",
"(",
")",
",",
"$",
"documentPrefix",
".",
"$",
"field",
"->",
"getFieldName",
"(",
")",
".",
"'.0.'",
",",
"$",
"exposedPrefix",
".",
"$",
"field",
"->",
"getExposedName",
"(",
")",
".",
"'.0.'",
",",
"$",
"callback",
",",
"$",
"returnFullField",
")",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Gets an array of all fields, flat with full internal name in dot notation as key and
the exposed field name as value. You can pass a callable to limit the fields return a subset of fields.
If the callback returns true, the field will be included in the output. You will get the field definition
passed to your callback.
@param Document $document The document
@param string $documentPrefix Document field prefix
@param string $exposedPrefix Exposed field prefix
@param callable $callback An optional callback where you can influence the number of fields returned
@param boolean $returnFullField if true, the function returns the full field object instead of the full path
@return array
|
[
"Gets",
"an",
"array",
"of",
"all",
"fields",
"flat",
"with",
"full",
"internal",
"name",
"in",
"dot",
"notation",
"as",
"key",
"and",
"the",
"exposed",
"field",
"name",
"as",
"value",
".",
"You",
"can",
"pass",
"a",
"callable",
"to",
"limit",
"the",
"fields",
"return",
"a",
"subset",
"of",
"fields",
".",
"If",
"the",
"callback",
"returns",
"true",
"the",
"field",
"will",
"be",
"included",
"in",
"the",
"output",
".",
"You",
"will",
"get",
"the",
"field",
"definition",
"passed",
"to",
"your",
"callback",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php#L449-L510
|
26,372
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php
|
DocumentMap.getFlatFieldCheckCallback
|
private function getFlatFieldCheckCallback($field, callable $callback = null)
{
if (!is_callable($callback)) {
return true;
}
return call_user_func($callback, $field);
}
|
php
|
private function getFlatFieldCheckCallback($field, callable $callback = null)
{
if (!is_callable($callback)) {
return true;
}
return call_user_func($callback, $field);
}
|
[
"private",
"function",
"getFlatFieldCheckCallback",
"(",
"$",
"field",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"field",
")",
";",
"}"
] |
Simple function to check whether a given shall be returned in the output of getFieldNamesFlat
and the optional given callback there.
@param AbstractField $field field
@param callable|null $callback optional callback
@return bool|mixed true if field should be returned, false otherwise
|
[
"Simple",
"function",
"to",
"check",
"whether",
"a",
"given",
"shall",
"be",
"returned",
"in",
"the",
"output",
"of",
"getFieldNamesFlat",
"and",
"the",
"optional",
"given",
"callback",
"there",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/Utils/DocumentMap.php#L521-L528
|
26,373
|
libgraviton/graviton
|
src/Graviton/ProxyBundle/DependencyInjection/Compiler/TransformerPass.php
|
TransformerPass.registerTaggedTransformation
|
private function registerTaggedTransformation(ContainerBuilder $container, Definition $definition, $tag, $callable)
{
$taggedServices = $container->findTaggedServiceIds($tag);
foreach ($taggedServices as $id => $tags) {
foreach ($tags as $attributes) {
$definition->addMethodCall(
$callable,
array(
$attributes["alias"],
$attributes["endpoint"],
new Reference($id)
)
);
}
}
}
|
php
|
private function registerTaggedTransformation(ContainerBuilder $container, Definition $definition, $tag, $callable)
{
$taggedServices = $container->findTaggedServiceIds($tag);
foreach ($taggedServices as $id => $tags) {
foreach ($tags as $attributes) {
$definition->addMethodCall(
$callable,
array(
$attributes["alias"],
$attributes["endpoint"],
new Reference($id)
)
);
}
}
}
|
[
"private",
"function",
"registerTaggedTransformation",
"(",
"ContainerBuilder",
"$",
"container",
",",
"Definition",
"$",
"definition",
",",
"$",
"tag",
",",
"$",
"callable",
")",
"{",
"$",
"taggedServices",
"=",
"$",
"container",
"->",
"findTaggedServiceIds",
"(",
"$",
"tag",
")",
";",
"foreach",
"(",
"$",
"taggedServices",
"as",
"$",
"id",
"=>",
"$",
"tags",
")",
"{",
"foreach",
"(",
"$",
"tags",
"as",
"$",
"attributes",
")",
"{",
"$",
"definition",
"->",
"addMethodCall",
"(",
"$",
"callable",
",",
"array",
"(",
"$",
"attributes",
"[",
"\"alias\"",
"]",
",",
"$",
"attributes",
"[",
"\"endpoint\"",
"]",
",",
"new",
"Reference",
"(",
"$",
"id",
")",
")",
")",
";",
"}",
"}",
"}"
] |
Adds the found services to the TransformationHandler
@param ContainerBuilder $container Symfony Service Container
@param Definition $definition Service the services shall be add to.
@param string $tag Tag identifying the service to be added
@param string $callable Name of the method to call to add the tagged service.
@return void
|
[
"Adds",
"the",
"found",
"services",
"to",
"the",
"TransformationHandler"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/DependencyInjection/Compiler/TransformerPass.php#L71-L87
|
26,374
|
libgraviton/graviton
|
app/AppKernel.php
|
AppKernel.initializeContainer
|
protected function initializeContainer()
{
static $first = true;
if ('test' !== $this->getEnvironment()) {
parent::initializeContainer();
return;
}
$debug = $this->debug;
if (!$first) {
// disable debug mode on all but the first initialization
$this->debug = false;
}
// will not work with --process-isolation
$first = false;
try {
parent::initializeContainer();
} catch (\Exception $e) {
$this->debug = $debug;
throw $e;
}
$this->debug = $debug;
}
|
php
|
protected function initializeContainer()
{
static $first = true;
if ('test' !== $this->getEnvironment()) {
parent::initializeContainer();
return;
}
$debug = $this->debug;
if (!$first) {
// disable debug mode on all but the first initialization
$this->debug = false;
}
// will not work with --process-isolation
$first = false;
try {
parent::initializeContainer();
} catch (\Exception $e) {
$this->debug = $debug;
throw $e;
}
$this->debug = $debug;
}
|
[
"protected",
"function",
"initializeContainer",
"(",
")",
"{",
"static",
"$",
"first",
"=",
"true",
";",
"if",
"(",
"'test'",
"!==",
"$",
"this",
"->",
"getEnvironment",
"(",
")",
")",
"{",
"parent",
"::",
"initializeContainer",
"(",
")",
";",
"return",
";",
"}",
"$",
"debug",
"=",
"$",
"this",
"->",
"debug",
";",
"if",
"(",
"!",
"$",
"first",
")",
"{",
"// disable debug mode on all but the first initialization",
"$",
"this",
"->",
"debug",
"=",
"false",
";",
"}",
"// will not work with --process-isolation",
"$",
"first",
"=",
"false",
";",
"try",
"{",
"parent",
"::",
"initializeContainer",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"debug",
"=",
"$",
"debug",
";",
"throw",
"$",
"e",
";",
"}",
"$",
"this",
"->",
"debug",
"=",
"$",
"debug",
";",
"}"
] |
dont rebuild container with debug over and over again during tests
This is very much what is described in http://kriswallsmith.net/post/27979797907
@return void
|
[
"dont",
"rebuild",
"container",
"with",
"debug",
"over",
"and",
"over",
"again",
"during",
"tests"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/app/AppKernel.php#L119-L146
|
26,375
|
libgraviton/graviton
|
src/Graviton/SecurityBundle/User/Model/ModelFactory.php
|
ModelFactory.create
|
public function create()
{
$serviceId = $this->container->getParameter('graviton.security.authentication.provider.model');
$service = $this->container->get('graviton.security.authentication.provider.model.noop');
if (!empty($serviceId) && $this->container->has($serviceId)) {
$service = $this->container->get($serviceId);
}
return $service;
}
|
php
|
public function create()
{
$serviceId = $this->container->getParameter('graviton.security.authentication.provider.model');
$service = $this->container->get('graviton.security.authentication.provider.model.noop');
if (!empty($serviceId) && $this->container->has($serviceId)) {
$service = $this->container->get($serviceId);
}
return $service;
}
|
[
"public",
"function",
"create",
"(",
")",
"{",
"$",
"serviceId",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'graviton.security.authentication.provider.model'",
")",
";",
"$",
"service",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'graviton.security.authentication.provider.model.noop'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"serviceId",
")",
"&&",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"$",
"serviceId",
")",
")",
"{",
"$",
"service",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"serviceId",
")",
";",
"}",
"return",
"$",
"service",
";",
"}"
] |
Determines what service to be used.
@return \Graviton\RestBundle\Model\ModelInterface
|
[
"Determines",
"what",
"service",
"to",
"be",
"used",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SecurityBundle/User/Model/ModelFactory.php#L39-L49
|
26,376
|
libgraviton/graviton
|
src/Graviton/SchemaBundle/Constraint/ReadOnlyFieldConstraint.php
|
ReadOnlyFieldConstraint.propertyExists
|
private function propertyExists($object, $fieldName)
{
if (property_exists($object, $fieldName)) {
return true;
}
foreach (explode('.', $fieldName) as $field) {
if (property_exists($object, $field)) {
$object = $object->{$field};
if (!is_object($object)) {
break;
}
continue;
} else {
return false;
}
}
return true;
}
|
php
|
private function propertyExists($object, $fieldName)
{
if (property_exists($object, $fieldName)) {
return true;
}
foreach (explode('.', $fieldName) as $field) {
if (property_exists($object, $field)) {
$object = $object->{$field};
if (!is_object($object)) {
break;
}
continue;
} else {
return false;
}
}
return true;
}
|
[
"private",
"function",
"propertyExists",
"(",
"$",
"object",
",",
"$",
"fieldName",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"object",
",",
"$",
"fieldName",
")",
")",
"{",
"return",
"true",
";",
"}",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"fieldName",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"object",
",",
"$",
"field",
")",
")",
"{",
"$",
"object",
"=",
"$",
"object",
"->",
"{",
"$",
"field",
"}",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"break",
";",
"}",
"continue",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
To validate before accessor brakes with not found field
@param object $object To be parsed
@param string $fieldName Field name, dot chained.
@return bool
|
[
"To",
"validate",
"before",
"accessor",
"brakes",
"with",
"not",
"found",
"field"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/Constraint/ReadOnlyFieldConstraint.php#L103-L121
|
26,377
|
libgraviton/graviton
|
src/Graviton/ProxyBundle/Service/MappingTransformer.php
|
MappingTransformer.transform
|
public function transform($raw, array $mapping, $transformed = [])
{
foreach ($mapping as $destination => $source) {
$value = $this->propertyAccessor->isReadable($raw, $source) ?
$this->propertyAccessor->getValue($raw, $source) : null;
$this->propertyAccessor->setValue($transformed, $destination, $value);
}
return $transformed;
}
|
php
|
public function transform($raw, array $mapping, $transformed = [])
{
foreach ($mapping as $destination => $source) {
$value = $this->propertyAccessor->isReadable($raw, $source) ?
$this->propertyAccessor->getValue($raw, $source) : null;
$this->propertyAccessor->setValue($transformed, $destination, $value);
}
return $transformed;
}
|
[
"public",
"function",
"transform",
"(",
"$",
"raw",
",",
"array",
"$",
"mapping",
",",
"$",
"transformed",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"mapping",
"as",
"$",
"destination",
"=>",
"$",
"source",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"propertyAccessor",
"->",
"isReadable",
"(",
"$",
"raw",
",",
"$",
"source",
")",
"?",
"$",
"this",
"->",
"propertyAccessor",
"->",
"getValue",
"(",
"$",
"raw",
",",
"$",
"source",
")",
":",
"null",
";",
"$",
"this",
"->",
"propertyAccessor",
"->",
"setValue",
"(",
"$",
"transformed",
",",
"$",
"destination",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"transformed",
";",
"}"
] |
Applies the given mapping on a given object or array.
@param object|array $raw The input object or array
@param array $mapping The mapping
@param object|array $transformed The output object or array.
@return array
|
[
"Applies",
"the",
"given",
"mapping",
"on",
"a",
"given",
"object",
"or",
"array",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/ProxyBundle/Service/MappingTransformer.php#L43-L51
|
26,378
|
libgraviton/graviton
|
src/Graviton/CoreBundle/GravitonCoreBundle.php
|
GravitonCoreBundle.build
|
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new VersionCompilerPass(new PrettyVersions()));
$container->addCompilerPass(new EnvParametersCompilerPass());
$container->addCompilerPass(new RouteLoaderCompilerPass());
$container->addCompilerPass(new HttpClientOptionsCompilerPass());
}
|
php
|
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new VersionCompilerPass(new PrettyVersions()));
$container->addCompilerPass(new EnvParametersCompilerPass());
$container->addCompilerPass(new RouteLoaderCompilerPass());
$container->addCompilerPass(new HttpClientOptionsCompilerPass());
}
|
[
"public",
"function",
"build",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"parent",
"::",
"build",
"(",
"$",
"container",
")",
";",
"$",
"container",
"->",
"addCompilerPass",
"(",
"new",
"VersionCompilerPass",
"(",
"new",
"PrettyVersions",
"(",
")",
")",
")",
";",
"$",
"container",
"->",
"addCompilerPass",
"(",
"new",
"EnvParametersCompilerPass",
"(",
")",
")",
";",
"$",
"container",
"->",
"addCompilerPass",
"(",
"new",
"RouteLoaderCompilerPass",
"(",
")",
")",
";",
"$",
"container",
"->",
"addCompilerPass",
"(",
"new",
"HttpClientOptionsCompilerPass",
"(",
")",
")",
";",
"}"
] |
load version compiler pass
@param ContainerBuilder $container container builder
@return void
|
[
"load",
"version",
"compiler",
"pass"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/CoreBundle/GravitonCoreBundle.php#L74-L82
|
26,379
|
libgraviton/graviton
|
src/Graviton/GeneratorBundle/Generator/ResourceGenerator/FieldMapper.php
|
FieldMapper.buildFields
|
public function buildFields(JsonDefinition $jsonDefinition)
{
$fields = [];
foreach ($jsonDefinition->getFields() as $field) {
if ($field->getName() != 'id') {
$fields[] = [
'fieldName' => $field->getName(),
'type' => $field->getTypeDoctrine()
];
}
}
return $fields;
}
|
php
|
public function buildFields(JsonDefinition $jsonDefinition)
{
$fields = [];
foreach ($jsonDefinition->getFields() as $field) {
if ($field->getName() != 'id') {
$fields[] = [
'fieldName' => $field->getName(),
'type' => $field->getTypeDoctrine()
];
}
}
return $fields;
}
|
[
"public",
"function",
"buildFields",
"(",
"JsonDefinition",
"$",
"jsonDefinition",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"jsonDefinition",
"->",
"getFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"getName",
"(",
")",
"!=",
"'id'",
")",
"{",
"$",
"fields",
"[",
"]",
"=",
"[",
"'fieldName'",
"=>",
"$",
"field",
"->",
"getName",
"(",
")",
",",
"'type'",
"=>",
"$",
"field",
"->",
"getTypeDoctrine",
"(",
")",
"]",
";",
"}",
"}",
"return",
"$",
"fields",
";",
"}"
] |
builds the initial fields array with a json definition
@param JsonDefinition $jsonDefinition definition
@return array fields
|
[
"builds",
"the",
"initial",
"fields",
"array",
"with",
"a",
"json",
"definition"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/GeneratorBundle/Generator/ResourceGenerator/FieldMapper.php#L39-L52
|
26,380
|
libgraviton/graviton
|
src/Graviton/CoreBundle/Event/HomepageRenderEvent.php
|
HomepageRenderEvent.addRoute
|
public function addRoute($url, $schemaUrl)
{
$this->addedRoutes[] = [
'$ref' => $this->normalizeRelativeUrl($url),
'profile' => $this->normalizeRelativeUrl($schemaUrl)
];
}
|
php
|
public function addRoute($url, $schemaUrl)
{
$this->addedRoutes[] = [
'$ref' => $this->normalizeRelativeUrl($url),
'profile' => $this->normalizeRelativeUrl($schemaUrl)
];
}
|
[
"public",
"function",
"addRoute",
"(",
"$",
"url",
",",
"$",
"schemaUrl",
")",
"{",
"$",
"this",
"->",
"addedRoutes",
"[",
"]",
"=",
"[",
"'$ref'",
"=>",
"$",
"this",
"->",
"normalizeRelativeUrl",
"(",
"$",
"url",
")",
",",
"'profile'",
"=>",
"$",
"this",
"->",
"normalizeRelativeUrl",
"(",
"$",
"schemaUrl",
")",
"]",
";",
"}"
] |
add a route to the homepage
@param string $url relative (to root) url to the service
@param string $schemaUrl relative (to root) url to the schema
@return void
|
[
"add",
"a",
"route",
"to",
"the",
"homepage"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/CoreBundle/Event/HomepageRenderEvent.php#L39-L45
|
26,381
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/TranslatableFieldsCompilerPass.php
|
TranslatableFieldsCompilerPass.process
|
public function process(ContainerBuilder $container)
{
$this->documentMap = $container->get('graviton.document.map');
$map = [];
foreach ($this->documentMap->getDocuments() as $document) {
$map[$document->getClass()] = $this->getTranslatableFields($document);
}
$container->setParameter('graviton.document.type.translatable.fields', $map);
// write default language to a file so we can statically read it out
file_put_contents(
__DIR__.'/../../Entity/Translatable.defaultLanguage',
$container->getParameter('graviton.translator.default.locale')
);
}
|
php
|
public function process(ContainerBuilder $container)
{
$this->documentMap = $container->get('graviton.document.map');
$map = [];
foreach ($this->documentMap->getDocuments() as $document) {
$map[$document->getClass()] = $this->getTranslatableFields($document);
}
$container->setParameter('graviton.document.type.translatable.fields', $map);
// write default language to a file so we can statically read it out
file_put_contents(
__DIR__.'/../../Entity/Translatable.defaultLanguage',
$container->getParameter('graviton.translator.default.locale')
);
}
|
[
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"this",
"->",
"documentMap",
"=",
"$",
"container",
"->",
"get",
"(",
"'graviton.document.map'",
")",
";",
"$",
"map",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"documentMap",
"->",
"getDocuments",
"(",
")",
"as",
"$",
"document",
")",
"{",
"$",
"map",
"[",
"$",
"document",
"->",
"getClass",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"getTranslatableFields",
"(",
"$",
"document",
")",
";",
"}",
"$",
"container",
"->",
"setParameter",
"(",
"'graviton.document.type.translatable.fields'",
",",
"$",
"map",
")",
";",
"// write default language to a file so we can statically read it out",
"file_put_contents",
"(",
"__DIR__",
".",
"'/../../Entity/Translatable.defaultLanguage'",
",",
"$",
"container",
"->",
"getParameter",
"(",
"'graviton.translator.default.locale'",
")",
")",
";",
"}"
] |
Make translatable fields map and set it to parameter
@param ContainerBuilder $container container builder
@return void
|
[
"Make",
"translatable",
"fields",
"map",
"and",
"set",
"it",
"to",
"parameter"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/TranslatableFieldsCompilerPass.php#L36-L50
|
26,382
|
libgraviton/graviton
|
src/Graviton/DocumentBundle/DependencyInjection/Compiler/TranslatableFieldsCompilerPass.php
|
TranslatableFieldsCompilerPass.getTranslatableFields
|
private function getTranslatableFields(Document $document, $prefix = '')
{
$result = [];
foreach ($document->getFields() as $field) {
if ($field instanceof Field) {
if ($field->getType() == 'translatable') {
$result[] = $prefix.$field->getExposedName();
}
} elseif ($field instanceof EmbedOne) {
$result = array_merge(
$result,
$this->getTranslatableFields(
$field->getDocument(),
$prefix.$field->getExposedName().'.'
)
);
} elseif ($field instanceof EmbedMany) {
$result = array_merge(
$result,
$this->getTranslatableFields(
$field->getDocument(),
$prefix.$field->getExposedName().'.0.'
)
);
}
}
return $result;
}
|
php
|
private function getTranslatableFields(Document $document, $prefix = '')
{
$result = [];
foreach ($document->getFields() as $field) {
if ($field instanceof Field) {
if ($field->getType() == 'translatable') {
$result[] = $prefix.$field->getExposedName();
}
} elseif ($field instanceof EmbedOne) {
$result = array_merge(
$result,
$this->getTranslatableFields(
$field->getDocument(),
$prefix.$field->getExposedName().'.'
)
);
} elseif ($field instanceof EmbedMany) {
$result = array_merge(
$result,
$this->getTranslatableFields(
$field->getDocument(),
$prefix.$field->getExposedName().'.0.'
)
);
}
}
return $result;
}
|
[
"private",
"function",
"getTranslatableFields",
"(",
"Document",
"$",
"document",
",",
"$",
"prefix",
"=",
"''",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"document",
"->",
"getFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"Field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"getType",
"(",
")",
"==",
"'translatable'",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"prefix",
".",
"$",
"field",
"->",
"getExposedName",
"(",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"field",
"instanceof",
"EmbedOne",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"getTranslatableFields",
"(",
"$",
"field",
"->",
"getDocument",
"(",
")",
",",
"$",
"prefix",
".",
"$",
"field",
"->",
"getExposedName",
"(",
")",
".",
"'.'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"field",
"instanceof",
"EmbedMany",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"getTranslatableFields",
"(",
"$",
"field",
"->",
"getDocument",
"(",
")",
",",
"$",
"prefix",
".",
"$",
"field",
"->",
"getExposedName",
"(",
")",
".",
"'.0.'",
")",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Get document fields
@param Document $document Document
@param string $prefix Field prefix
@return array
|
[
"Get",
"document",
"fields"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/DocumentBundle/DependencyInjection/Compiler/TranslatableFieldsCompilerPass.php#L59-L87
|
26,383
|
libgraviton/graviton
|
src/Graviton/SchemaBundle/Constraint/Builder/RangeConstraintBuilder.php
|
RangeConstraintBuilder.supportsConstraint
|
public function supportsConstraint($type, array $options = [])
{
if (in_array($type, $this->types)) {
$this->type = $type;
return true;
}
return false;
}
|
php
|
public function supportsConstraint($type, array $options = [])
{
if (in_array($type, $this->types)) {
$this->type = $type;
return true;
}
return false;
}
|
[
"public",
"function",
"supportsConstraint",
"(",
"$",
"type",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"types",
")",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"$",
"type",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
if this builder supports a given constraint
@param string $type Field type
@param array $options Options
@return bool
|
[
"if",
"this",
"builder",
"supports",
"a",
"given",
"constraint"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/Constraint/Builder/RangeConstraintBuilder.php#L41-L49
|
26,384
|
libgraviton/graviton
|
src/Graviton/SchemaBundle/SchemaUtils.php
|
SchemaUtils.getCollectionSchema
|
public function getCollectionSchema($modelName, DocumentModel $model)
{
$collectionSchema = new Schema;
$collectionSchema->setTitle(sprintf('Array of %s objects', $modelName));
$collectionSchema->setType('array');
$collectionSchema->setItems($this->getModelSchema($modelName, $model));
return $collectionSchema;
}
|
php
|
public function getCollectionSchema($modelName, DocumentModel $model)
{
$collectionSchema = new Schema;
$collectionSchema->setTitle(sprintf('Array of %s objects', $modelName));
$collectionSchema->setType('array');
$collectionSchema->setItems($this->getModelSchema($modelName, $model));
return $collectionSchema;
}
|
[
"public",
"function",
"getCollectionSchema",
"(",
"$",
"modelName",
",",
"DocumentModel",
"$",
"model",
")",
"{",
"$",
"collectionSchema",
"=",
"new",
"Schema",
";",
"$",
"collectionSchema",
"->",
"setTitle",
"(",
"sprintf",
"(",
"'Array of %s objects'",
",",
"$",
"modelName",
")",
")",
";",
"$",
"collectionSchema",
"->",
"setType",
"(",
"'array'",
")",
";",
"$",
"collectionSchema",
"->",
"setItems",
"(",
"$",
"this",
"->",
"getModelSchema",
"(",
"$",
"modelName",
",",
"$",
"model",
")",
")",
";",
"return",
"$",
"collectionSchema",
";",
"}"
] |
get schema for an array of models
@param string $modelName name of model
@param DocumentModel $model model
@return Schema
|
[
"get",
"schema",
"for",
"an",
"array",
"of",
"models"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/SchemaUtils.php#L163-L170
|
26,385
|
libgraviton/graviton
|
src/Graviton/SchemaBundle/SchemaUtils.php
|
SchemaUtils.getSchemaVariationName
|
private function getSchemaVariationName($userData, $variations)
{
foreach ($variations as $variationName => $expressions) {
$results = array_map(
function ($expression) use ($userData) {
return $this->jmesRuntime->__invoke($expression, $userData);
},
$expressions
);
$results = array_unique($results);
if (count($results) == 1 && $results[0] === true) {
return $variationName;
}
}
return null;
}
|
php
|
private function getSchemaVariationName($userData, $variations)
{
foreach ($variations as $variationName => $expressions) {
$results = array_map(
function ($expression) use ($userData) {
return $this->jmesRuntime->__invoke($expression, $userData);
},
$expressions
);
$results = array_unique($results);
if (count($results) == 1 && $results[0] === true) {
return $variationName;
}
}
return null;
}
|
[
"private",
"function",
"getSchemaVariationName",
"(",
"$",
"userData",
",",
"$",
"variations",
")",
"{",
"foreach",
"(",
"$",
"variations",
"as",
"$",
"variationName",
"=>",
"$",
"expressions",
")",
"{",
"$",
"results",
"=",
"array_map",
"(",
"function",
"(",
"$",
"expression",
")",
"use",
"(",
"$",
"userData",
")",
"{",
"return",
"$",
"this",
"->",
"jmesRuntime",
"->",
"__invoke",
"(",
"$",
"expression",
",",
"$",
"userData",
")",
";",
"}",
",",
"$",
"expressions",
")",
";",
"$",
"results",
"=",
"array_unique",
"(",
"$",
"results",
")",
";",
"if",
"(",
"count",
"(",
"$",
"results",
")",
"==",
"1",
"&&",
"$",
"results",
"[",
"0",
"]",
"===",
"true",
")",
"{",
"return",
"$",
"variationName",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
gets the name of the variation to apply based on userdata and the service definition
@param \stdClass $userData user data
@param \stdClass $variations variations as defined in schema
@return string|null the variation name or null if none
|
[
"gets",
"the",
"name",
"of",
"the",
"variation",
"to",
"apply",
"based",
"on",
"userdata",
"and",
"the",
"service",
"definition"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/SchemaUtils.php#L482-L500
|
26,386
|
libgraviton/graviton
|
src/Graviton/SchemaBundle/SchemaUtils.php
|
SchemaUtils.makeTranslatable
|
public function makeTranslatable(Schema $property, $languages)
{
$property->setType('object');
$property->setTranslatable(true);
array_walk(
$languages,
function ($language) use ($property) {
$schema = new Schema;
$schema->setType('string');
$schema->setTitle('Translated String');
$schema->setDescription('String in ' . $language . ' locale.');
$property->addProperty($language, $schema);
}
);
$property->setRequired(['en']);
return $property;
}
|
php
|
public function makeTranslatable(Schema $property, $languages)
{
$property->setType('object');
$property->setTranslatable(true);
array_walk(
$languages,
function ($language) use ($property) {
$schema = new Schema;
$schema->setType('string');
$schema->setTitle('Translated String');
$schema->setDescription('String in ' . $language . ' locale.');
$property->addProperty($language, $schema);
}
);
$property->setRequired(['en']);
return $property;
}
|
[
"public",
"function",
"makeTranslatable",
"(",
"Schema",
"$",
"property",
",",
"$",
"languages",
")",
"{",
"$",
"property",
"->",
"setType",
"(",
"'object'",
")",
";",
"$",
"property",
"->",
"setTranslatable",
"(",
"true",
")",
";",
"array_walk",
"(",
"$",
"languages",
",",
"function",
"(",
"$",
"language",
")",
"use",
"(",
"$",
"property",
")",
"{",
"$",
"schema",
"=",
"new",
"Schema",
";",
"$",
"schema",
"->",
"setType",
"(",
"'string'",
")",
";",
"$",
"schema",
"->",
"setTitle",
"(",
"'Translated String'",
")",
";",
"$",
"schema",
"->",
"setDescription",
"(",
"'String in '",
".",
"$",
"language",
".",
"' locale.'",
")",
";",
"$",
"property",
"->",
"addProperty",
"(",
"$",
"language",
",",
"$",
"schema",
")",
";",
"}",
")",
";",
"$",
"property",
"->",
"setRequired",
"(",
"[",
"'en'",
"]",
")",
";",
"return",
"$",
"property",
";",
"}"
] |
turn a property into a translatable property
@param Schema $property simple string property
@param string[] $languages available languages
@return Schema
|
[
"turn",
"a",
"property",
"into",
"a",
"translatable",
"property"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/SchemaUtils.php#L510-L527
|
26,387
|
libgraviton/graviton
|
src/Graviton/SchemaBundle/SchemaUtils.php
|
SchemaUtils.makeArrayTranslatable
|
public function makeArrayTranslatable(Schema $property, $languages)
{
$property->setType('array');
$property->setItems($this->makeTranslatable(new Schema(), $languages));
return $property;
}
|
php
|
public function makeArrayTranslatable(Schema $property, $languages)
{
$property->setType('array');
$property->setItems($this->makeTranslatable(new Schema(), $languages));
return $property;
}
|
[
"public",
"function",
"makeArrayTranslatable",
"(",
"Schema",
"$",
"property",
",",
"$",
"languages",
")",
"{",
"$",
"property",
"->",
"setType",
"(",
"'array'",
")",
";",
"$",
"property",
"->",
"setItems",
"(",
"$",
"this",
"->",
"makeTranslatable",
"(",
"new",
"Schema",
"(",
")",
",",
"$",
"languages",
")",
")",
";",
"return",
"$",
"property",
";",
"}"
] |
turn a array property into a translatable property
@param Schema $property simple string property
@param string[] $languages available languages
@return Schema
|
[
"turn",
"a",
"array",
"property",
"into",
"a",
"translatable",
"property"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/SchemaUtils.php#L537-L542
|
26,388
|
libgraviton/graviton
|
src/Graviton/SchemaBundle/SchemaUtils.php
|
SchemaUtils.getSchemaRouteName
|
public static function getSchemaRouteName($routeName)
{
$routeParts = explode('.', $routeName);
$routeType = array_pop($routeParts);
// check if we need to create an item or collection schema
$realRouteType = 'canonicalSchema';
if ($routeType != 'options' && $routeType != 'all') {
$realRouteType = 'canonicalIdSchema';
}
return implode('.', array_merge($routeParts, array($realRouteType)));
}
|
php
|
public static function getSchemaRouteName($routeName)
{
$routeParts = explode('.', $routeName);
$routeType = array_pop($routeParts);
// check if we need to create an item or collection schema
$realRouteType = 'canonicalSchema';
if ($routeType != 'options' && $routeType != 'all') {
$realRouteType = 'canonicalIdSchema';
}
return implode('.', array_merge($routeParts, array($realRouteType)));
}
|
[
"public",
"static",
"function",
"getSchemaRouteName",
"(",
"$",
"routeName",
")",
"{",
"$",
"routeParts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"routeName",
")",
";",
"$",
"routeType",
"=",
"array_pop",
"(",
"$",
"routeParts",
")",
";",
"// check if we need to create an item or collection schema",
"$",
"realRouteType",
"=",
"'canonicalSchema'",
";",
"if",
"(",
"$",
"routeType",
"!=",
"'options'",
"&&",
"$",
"routeType",
"!=",
"'all'",
")",
"{",
"$",
"realRouteType",
"=",
"'canonicalIdSchema'",
";",
"}",
"return",
"implode",
"(",
"'.'",
",",
"array_merge",
"(",
"$",
"routeParts",
",",
"array",
"(",
"$",
"realRouteType",
")",
")",
")",
";",
"}"
] |
get canonical route to a schema based on a route
@param string $routeName route name
@return string schema route name
|
[
"get",
"canonical",
"route",
"to",
"a",
"schema",
"based",
"on",
"a",
"route"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/SchemaUtils.php#L551-L563
|
26,389
|
libgraviton/graviton
|
src/Graviton/SchemaBundle/SchemaUtils.php
|
SchemaUtils.getCollectionItemType
|
private function getCollectionItemType($className, $fieldName)
{
$serializerMetadata = $this->serializerMetadataFactory->getMetadataForClass($className);
if ($serializerMetadata === null) {
return null;
}
if (!isset($serializerMetadata->propertyMetadata[$fieldName])) {
return null;
}
$type = $serializerMetadata->propertyMetadata[$fieldName]->type;
return isset($type['name'], $type['params'][0]['name']) && $type['name'] === 'array' ?
$type['params'][0]['name'] :
null;
}
|
php
|
private function getCollectionItemType($className, $fieldName)
{
$serializerMetadata = $this->serializerMetadataFactory->getMetadataForClass($className);
if ($serializerMetadata === null) {
return null;
}
if (!isset($serializerMetadata->propertyMetadata[$fieldName])) {
return null;
}
$type = $serializerMetadata->propertyMetadata[$fieldName]->type;
return isset($type['name'], $type['params'][0]['name']) && $type['name'] === 'array' ?
$type['params'][0]['name'] :
null;
}
|
[
"private",
"function",
"getCollectionItemType",
"(",
"$",
"className",
",",
"$",
"fieldName",
")",
"{",
"$",
"serializerMetadata",
"=",
"$",
"this",
"->",
"serializerMetadataFactory",
"->",
"getMetadataForClass",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"serializerMetadata",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"serializerMetadata",
"->",
"propertyMetadata",
"[",
"$",
"fieldName",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"type",
"=",
"$",
"serializerMetadata",
"->",
"propertyMetadata",
"[",
"$",
"fieldName",
"]",
"->",
"type",
";",
"return",
"isset",
"(",
"$",
"type",
"[",
"'name'",
"]",
",",
"$",
"type",
"[",
"'params'",
"]",
"[",
"0",
"]",
"[",
"'name'",
"]",
")",
"&&",
"$",
"type",
"[",
"'name'",
"]",
"===",
"'array'",
"?",
"$",
"type",
"[",
"'params'",
"]",
"[",
"0",
"]",
"[",
"'name'",
"]",
":",
"null",
";",
"}"
] |
Get item type of collection field
@param string $className Class name
@param string $fieldName Field name
@return string|null
|
[
"Get",
"item",
"type",
"of",
"collection",
"field"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/SchemaBundle/SchemaUtils.php#L572-L586
|
26,390
|
libgraviton/graviton
|
src/Graviton/RestBundle/Service/RestUtils.php
|
RestUtils.serializeContent
|
public function serializeContent($content, $format = 'json')
{
try {
return $this->getSerializer()->serialize(
$content,
$format
);
} catch (\Exception $e) {
$msg = sprintf(
'Cannot serialize content class: %s; with id: %s; Message: %s',
get_class($content),
method_exists($content, 'getId') ? $content->getId() : '-no id-',
str_replace('MongoDBODMProxies\__CG__\GravitonDyn', '', $e->getMessage())
);
$this->logger->alert($msg);
throw new \Exception($msg, $e->getCode());
}
}
|
php
|
public function serializeContent($content, $format = 'json')
{
try {
return $this->getSerializer()->serialize(
$content,
$format
);
} catch (\Exception $e) {
$msg = sprintf(
'Cannot serialize content class: %s; with id: %s; Message: %s',
get_class($content),
method_exists($content, 'getId') ? $content->getId() : '-no id-',
str_replace('MongoDBODMProxies\__CG__\GravitonDyn', '', $e->getMessage())
);
$this->logger->alert($msg);
throw new \Exception($msg, $e->getCode());
}
}
|
[
"public",
"function",
"serializeContent",
"(",
"$",
"content",
",",
"$",
"format",
"=",
"'json'",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"getSerializer",
"(",
")",
"->",
"serialize",
"(",
"$",
"content",
",",
"$",
"format",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"sprintf",
"(",
"'Cannot serialize content class: %s; with id: %s; Message: %s'",
",",
"get_class",
"(",
"$",
"content",
")",
",",
"method_exists",
"(",
"$",
"content",
",",
"'getId'",
")",
"?",
"$",
"content",
"->",
"getId",
"(",
")",
":",
"'-no id-'",
",",
"str_replace",
"(",
"'MongoDBODMProxies\\__CG__\\GravitonDyn'",
",",
"''",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"alert",
"(",
"$",
"msg",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"msg",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"}"
] |
Public function to serialize stuff according to the serializer rules.
@param object $content Any content to serialize
@param string $format Which format to serialize into
@throws \Exception
@return string $content Json content
|
[
"Public",
"function",
"to",
"serialize",
"stuff",
"according",
"to",
"the",
"serializer",
"rules",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Service/RestUtils.php#L143-L160
|
26,391
|
libgraviton/graviton
|
src/Graviton/RestBundle/Service/RestUtils.php
|
RestUtils.validateContent
|
public function validateContent($content, DocumentModel $model)
{
if (is_string($content)) {
$content = json_decode($content);
}
return $this->schemaValidator->validate(
$content,
$this->schemaUtils->getModelSchema(null, $model, true, true, true, $content)
);
}
|
php
|
public function validateContent($content, DocumentModel $model)
{
if (is_string($content)) {
$content = json_decode($content);
}
return $this->schemaValidator->validate(
$content,
$this->schemaUtils->getModelSchema(null, $model, true, true, true, $content)
);
}
|
[
"public",
"function",
"validateContent",
"(",
"$",
"content",
",",
"DocumentModel",
"$",
"model",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"content",
")",
")",
"{",
"$",
"content",
"=",
"json_decode",
"(",
"$",
"content",
")",
";",
"}",
"return",
"$",
"this",
"->",
"schemaValidator",
"->",
"validate",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"schemaUtils",
"->",
"getModelSchema",
"(",
"null",
",",
"$",
"model",
",",
"true",
",",
"true",
",",
"true",
",",
"$",
"content",
")",
")",
";",
"}"
] |
Validates content with the given schema, returning an array of errors.
If all is good, you will receive an empty array.
@param object $content \stdClass of the request content
@param DocumentModel $model the model to check the schema for
@return \Graviton\JsonSchemaBundle\Exception\ValidationExceptionError[]
@throws \Exception
|
[
"Validates",
"content",
"with",
"the",
"given",
"schema",
"returning",
"an",
"array",
"of",
"errors",
".",
"If",
"all",
"is",
"good",
"you",
"will",
"receive",
"an",
"empty",
"array",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Service/RestUtils.php#L194-L204
|
26,392
|
libgraviton/graviton
|
src/Graviton/RestBundle/Service/RestUtils.php
|
RestUtils.checkJsonRequest
|
public function checkJsonRequest(Request $request, Response $response, DocumentModel $model, $content = '')
{
if (empty($content)) {
$content = $request->getContent();
}
if (is_resource($content)) {
throw new BadRequestHttpException('unexpected resource in validation');
}
// is request body empty
if ($content === '') {
$e = new NoInputException();
$e->setResponse($response);
throw $e;
}
$input = json_decode($content, true);
if (JSON_ERROR_NONE !== json_last_error()) {
$e = new MalformedInputException($this->getLastJsonErrorMessage());
$e->setErrorType(json_last_error());
$e->setResponse($response);
throw $e;
}
if (!is_array($input)) {
$e = new MalformedInputException('JSON request body must be an object');
$e->setResponse($response);
throw $e;
}
if ($request->getMethod() == 'PUT' && array_key_exists('id', $input)) {
// we need to check for id mismatches....
if ($request->attributes->get('id') != $input['id']) {
$e = new MalformedInputException('Record ID in your payload must be the same');
$e->setResponse($response);
throw $e;
}
}
if ($request->getMethod() == 'POST' &&
array_key_exists('id', $input) &&
!$model->isIdInPostAllowed()
) {
$e = new MalformedInputException(
'"id" can not be given on a POST request. Do a PUT request instead to update an existing record.'
);
$e->setResponse($response);
throw $e;
}
}
|
php
|
public function checkJsonRequest(Request $request, Response $response, DocumentModel $model, $content = '')
{
if (empty($content)) {
$content = $request->getContent();
}
if (is_resource($content)) {
throw new BadRequestHttpException('unexpected resource in validation');
}
// is request body empty
if ($content === '') {
$e = new NoInputException();
$e->setResponse($response);
throw $e;
}
$input = json_decode($content, true);
if (JSON_ERROR_NONE !== json_last_error()) {
$e = new MalformedInputException($this->getLastJsonErrorMessage());
$e->setErrorType(json_last_error());
$e->setResponse($response);
throw $e;
}
if (!is_array($input)) {
$e = new MalformedInputException('JSON request body must be an object');
$e->setResponse($response);
throw $e;
}
if ($request->getMethod() == 'PUT' && array_key_exists('id', $input)) {
// we need to check for id mismatches....
if ($request->attributes->get('id') != $input['id']) {
$e = new MalformedInputException('Record ID in your payload must be the same');
$e->setResponse($response);
throw $e;
}
}
if ($request->getMethod() == 'POST' &&
array_key_exists('id', $input) &&
!$model->isIdInPostAllowed()
) {
$e = new MalformedInputException(
'"id" can not be given on a POST request. Do a PUT request instead to update an existing record.'
);
$e->setResponse($response);
throw $e;
}
}
|
[
"public",
"function",
"checkJsonRequest",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
",",
"DocumentModel",
"$",
"model",
",",
"$",
"content",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"content",
")",
")",
"{",
"$",
"content",
"=",
"$",
"request",
"->",
"getContent",
"(",
")",
";",
"}",
"if",
"(",
"is_resource",
"(",
"$",
"content",
")",
")",
"{",
"throw",
"new",
"BadRequestHttpException",
"(",
"'unexpected resource in validation'",
")",
";",
"}",
"// is request body empty",
"if",
"(",
"$",
"content",
"===",
"''",
")",
"{",
"$",
"e",
"=",
"new",
"NoInputException",
"(",
")",
";",
"$",
"e",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"throw",
"$",
"e",
";",
"}",
"$",
"input",
"=",
"json_decode",
"(",
"$",
"content",
",",
"true",
")",
";",
"if",
"(",
"JSON_ERROR_NONE",
"!==",
"json_last_error",
"(",
")",
")",
"{",
"$",
"e",
"=",
"new",
"MalformedInputException",
"(",
"$",
"this",
"->",
"getLastJsonErrorMessage",
"(",
")",
")",
";",
"$",
"e",
"->",
"setErrorType",
"(",
"json_last_error",
"(",
")",
")",
";",
"$",
"e",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"throw",
"$",
"e",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"input",
")",
")",
"{",
"$",
"e",
"=",
"new",
"MalformedInputException",
"(",
"'JSON request body must be an object'",
")",
";",
"$",
"e",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"throw",
"$",
"e",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"==",
"'PUT'",
"&&",
"array_key_exists",
"(",
"'id'",
",",
"$",
"input",
")",
")",
"{",
"// we need to check for id mismatches....",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'id'",
")",
"!=",
"$",
"input",
"[",
"'id'",
"]",
")",
"{",
"$",
"e",
"=",
"new",
"MalformedInputException",
"(",
"'Record ID in your payload must be the same'",
")",
";",
"$",
"e",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"==",
"'POST'",
"&&",
"array_key_exists",
"(",
"'id'",
",",
"$",
"input",
")",
"&&",
"!",
"$",
"model",
"->",
"isIdInPostAllowed",
"(",
")",
")",
"{",
"$",
"e",
"=",
"new",
"MalformedInputException",
"(",
"'\"id\" can not be given on a POST request. Do a PUT request instead to update an existing record.'",
")",
";",
"$",
"e",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}"
] |
validate raw json input
@param Request $request request
@param Response $response response
@param DocumentModel $model model
@param string $content Alternative request content.
@return void
|
[
"validate",
"raw",
"json",
"input"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Service/RestUtils.php#L216-L265
|
26,393
|
libgraviton/graviton
|
src/Graviton/RestBundle/Service/RestUtils.php
|
RestUtils.checkJsonPatchRequest
|
public function checkJsonPatchRequest(array $jsonPatch)
{
foreach ($jsonPatch as $operation) {
if (!is_array($operation)) {
throw new InvalidJsonPatchException('Patch request should be an array of operations.');
}
if (array_key_exists('path', $operation) && trim($operation['path']) == '/id') {
throw new InvalidJsonPatchException('Change/remove of ID not allowed');
}
}
}
|
php
|
public function checkJsonPatchRequest(array $jsonPatch)
{
foreach ($jsonPatch as $operation) {
if (!is_array($operation)) {
throw new InvalidJsonPatchException('Patch request should be an array of operations.');
}
if (array_key_exists('path', $operation) && trim($operation['path']) == '/id') {
throw new InvalidJsonPatchException('Change/remove of ID not allowed');
}
}
}
|
[
"public",
"function",
"checkJsonPatchRequest",
"(",
"array",
"$",
"jsonPatch",
")",
"{",
"foreach",
"(",
"$",
"jsonPatch",
"as",
"$",
"operation",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"operation",
")",
")",
"{",
"throw",
"new",
"InvalidJsonPatchException",
"(",
"'Patch request should be an array of operations.'",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'path'",
",",
"$",
"operation",
")",
"&&",
"trim",
"(",
"$",
"operation",
"[",
"'path'",
"]",
")",
"==",
"'/id'",
")",
"{",
"throw",
"new",
"InvalidJsonPatchException",
"(",
"'Change/remove of ID not allowed'",
")",
";",
"}",
"}",
"}"
] |
Validate JSON patch for any object
@param array $jsonPatch json patch as array
@throws InvalidJsonPatchException
@return void
|
[
"Validate",
"JSON",
"patch",
"for",
"any",
"object"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Service/RestUtils.php#L275-L285
|
26,394
|
libgraviton/graviton
|
src/Graviton/RestBundle/Service/RestUtils.php
|
RestUtils.getOptionRoutes
|
public function getOptionRoutes()
{
$cached = $this->cacheProvider->fetch('cached_restutils_route_options');
if ($cached) {
return $cached;
}
$ret = array_filter(
$this->router->getRouteCollection()->all(),
function ($route) {
if (!in_array('OPTIONS', $route->getMethods())) {
return false;
}
// ignore all schema routes
if (strpos($route->getPath(), '/schema') === 0) {
return false;
}
if ($route->getPath() == '/' || $route->getPath() == '/core/version') {
return false;
}
return is_null($route->getRequirement('id'));
}
);
$this->cacheProvider->save('cached_restutils_route_options', $ret);
return $ret;
}
|
php
|
public function getOptionRoutes()
{
$cached = $this->cacheProvider->fetch('cached_restutils_route_options');
if ($cached) {
return $cached;
}
$ret = array_filter(
$this->router->getRouteCollection()->all(),
function ($route) {
if (!in_array('OPTIONS', $route->getMethods())) {
return false;
}
// ignore all schema routes
if (strpos($route->getPath(), '/schema') === 0) {
return false;
}
if ($route->getPath() == '/' || $route->getPath() == '/core/version') {
return false;
}
return is_null($route->getRequirement('id'));
}
);
$this->cacheProvider->save('cached_restutils_route_options', $ret);
return $ret;
}
|
[
"public",
"function",
"getOptionRoutes",
"(",
")",
"{",
"$",
"cached",
"=",
"$",
"this",
"->",
"cacheProvider",
"->",
"fetch",
"(",
"'cached_restutils_route_options'",
")",
";",
"if",
"(",
"$",
"cached",
")",
"{",
"return",
"$",
"cached",
";",
"}",
"$",
"ret",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"router",
"->",
"getRouteCollection",
"(",
")",
"->",
"all",
"(",
")",
",",
"function",
"(",
"$",
"route",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"'OPTIONS'",
",",
"$",
"route",
"->",
"getMethods",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"// ignore all schema routes",
"if",
"(",
"strpos",
"(",
"$",
"route",
"->",
"getPath",
"(",
")",
",",
"'/schema'",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"route",
"->",
"getPath",
"(",
")",
"==",
"'/'",
"||",
"$",
"route",
"->",
"getPath",
"(",
")",
"==",
"'/core/version'",
")",
"{",
"return",
"false",
";",
"}",
"return",
"is_null",
"(",
"$",
"route",
"->",
"getRequirement",
"(",
"'id'",
")",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"cacheProvider",
"->",
"save",
"(",
"'cached_restutils_route_options'",
",",
"$",
"ret",
")",
";",
"return",
"$",
"ret",
";",
"}"
] |
It has been deemed that we search for OPTION routes in order to detect our
service routes and then derive the rest from them.
@return array An array with option routes
|
[
"It",
"has",
"been",
"deemed",
"that",
"we",
"search",
"for",
"OPTION",
"routes",
"in",
"order",
"to",
"detect",
"our",
"service",
"routes",
"and",
"then",
"derive",
"the",
"rest",
"from",
"them",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Service/RestUtils.php#L319-L344
|
26,395
|
libgraviton/graviton
|
src/Graviton/RestBundle/Service/RestUtils.php
|
RestUtils.getModelFromRoute
|
public function getModelFromRoute(Route $route)
{
$ret = false;
$controller = $this->getControllerFromRoute($route);
if ($controller instanceof RestController) {
$ret = $controller->getModel();
}
return $ret;
}
|
php
|
public function getModelFromRoute(Route $route)
{
$ret = false;
$controller = $this->getControllerFromRoute($route);
if ($controller instanceof RestController) {
$ret = $controller->getModel();
}
return $ret;
}
|
[
"public",
"function",
"getModelFromRoute",
"(",
"Route",
"$",
"route",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"$",
"controller",
"=",
"$",
"this",
"->",
"getControllerFromRoute",
"(",
"$",
"route",
")",
";",
"if",
"(",
"$",
"controller",
"instanceof",
"RestController",
")",
"{",
"$",
"ret",
"=",
"$",
"controller",
"->",
"getModel",
"(",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Gets the Model assigned to the RestController
@param Route $route Route
@return bool|object The model or false
@throws \Exception
|
[
"Gets",
"the",
"Model",
"assigned",
"to",
"the",
"RestController"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Service/RestUtils.php#L381-L391
|
26,396
|
libgraviton/graviton
|
src/Graviton/RestBundle/Service/RestUtils.php
|
RestUtils.getControllerFromRoute
|
public function getControllerFromRoute(Route $route)
{
$ret = false;
$actionParts = explode(':', $route->getDefault('_controller'));
if (count($actionParts) == 2) {
$ret = $this->container->get($actionParts[0]);
}
return $ret;
}
|
php
|
public function getControllerFromRoute(Route $route)
{
$ret = false;
$actionParts = explode(':', $route->getDefault('_controller'));
if (count($actionParts) == 2) {
$ret = $this->container->get($actionParts[0]);
}
return $ret;
}
|
[
"public",
"function",
"getControllerFromRoute",
"(",
"Route",
"$",
"route",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"$",
"actionParts",
"=",
"explode",
"(",
"':'",
",",
"$",
"route",
"->",
"getDefault",
"(",
"'_controller'",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"actionParts",
")",
"==",
"2",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"actionParts",
"[",
"0",
"]",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Gets the controller from a Route
@param Route $route Route
@return bool|object The controller or false
|
[
"Gets",
"the",
"controller",
"from",
"a",
"Route"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Service/RestUtils.php#L400-L410
|
26,397
|
libgraviton/graviton
|
src/Graviton/RestBundle/Service/RestUtils.php
|
RestUtils.serialize
|
public function serialize($result)
{
try {
// array is serialized as an object {"0":{...},"1":{...},...} when data contains an empty objects
// we serialize each item because we can assume this bug affects only root array element
if (is_array($result) && array_keys($result) === range(0, count($result) - 1)) {
$result = array_map(
function ($item) {
return $this->serializeContent($item);
},
$result
);
return '['.implode(',', array_filter($result)).']';
}
return $this->serializeContent($result);
} catch (\Exception $e) {
throw new SerializationException($e);
}
}
|
php
|
public function serialize($result)
{
try {
// array is serialized as an object {"0":{...},"1":{...},...} when data contains an empty objects
// we serialize each item because we can assume this bug affects only root array element
if (is_array($result) && array_keys($result) === range(0, count($result) - 1)) {
$result = array_map(
function ($item) {
return $this->serializeContent($item);
},
$result
);
return '['.implode(',', array_filter($result)).']';
}
return $this->serializeContent($result);
} catch (\Exception $e) {
throw new SerializationException($e);
}
}
|
[
"public",
"function",
"serialize",
"(",
"$",
"result",
")",
"{",
"try",
"{",
"// array is serialized as an object {\"0\":{...},\"1\":{...},...} when data contains an empty objects",
"// we serialize each item because we can assume this bug affects only root array element",
"if",
"(",
"is_array",
"(",
"$",
"result",
")",
"&&",
"array_keys",
"(",
"$",
"result",
")",
"===",
"range",
"(",
"0",
",",
"count",
"(",
"$",
"result",
")",
"-",
"1",
")",
")",
"{",
"$",
"result",
"=",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"$",
"this",
"->",
"serializeContent",
"(",
"$",
"item",
")",
";",
"}",
",",
"$",
"result",
")",
";",
"return",
"'['",
".",
"implode",
"(",
"','",
",",
"array_filter",
"(",
"$",
"result",
")",
")",
".",
"']'",
";",
"}",
"return",
"$",
"this",
"->",
"serializeContent",
"(",
"$",
"result",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"SerializationException",
"(",
"$",
"e",
")",
";",
"}",
"}"
] |
Serialize the given record and throw an exception if something went wrong
@param object|object[] $result Record(s)
@throws \Graviton\ExceptionBundle\Exception\SerializationException
@return string $content Json content
|
[
"Serialize",
"the",
"given",
"record",
"and",
"throw",
"an",
"exception",
"if",
"something",
"went",
"wrong"
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Service/RestUtils.php#L438-L458
|
26,398
|
libgraviton/graviton
|
src/Graviton/RestBundle/Service/RestUtils.php
|
RestUtils.validateRequest
|
public function validateRequest($content, DocumentModel $model)
{
$errors = $this->validateContent($content, $model);
if (!empty($errors)) {
throw new ValidationException($errors);
}
return $this->deserialize($content, $model->getEntityClass());
}
|
php
|
public function validateRequest($content, DocumentModel $model)
{
$errors = $this->validateContent($content, $model);
if (!empty($errors)) {
throw new ValidationException($errors);
}
return $this->deserialize($content, $model->getEntityClass());
}
|
[
"public",
"function",
"validateRequest",
"(",
"$",
"content",
",",
"DocumentModel",
"$",
"model",
")",
"{",
"$",
"errors",
"=",
"$",
"this",
"->",
"validateContent",
"(",
"$",
"content",
",",
"$",
"model",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"errors",
")",
")",
"{",
"throw",
"new",
"ValidationException",
"(",
"$",
"errors",
")",
";",
"}",
"return",
"$",
"this",
"->",
"deserialize",
"(",
"$",
"content",
",",
"$",
"model",
"->",
"getEntityClass",
"(",
")",
")",
";",
"}"
] |
Validates the current request on schema violations. If there are errors,
the exception is thrown. If not, the deserialized record is returned.
@param object|string $content \stdClass of the request content
@param DocumentModel $model the model to check the schema for
@return ValidationExceptionError|Object
@throws \Exception
|
[
"Validates",
"the",
"current",
"request",
"on",
"schema",
"violations",
".",
"If",
"there",
"are",
"errors",
"the",
"exception",
"is",
"thrown",
".",
"If",
"not",
"the",
"deserialized",
"record",
"is",
"returned",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/Service/RestUtils.php#L494-L501
|
26,399
|
libgraviton/graviton
|
src/Graviton/RestBundle/ExclusionStrategy/SelectExclusionStrategy.php
|
SelectExclusionStrategy.createArrayByPath
|
private function createArrayByPath($path)
{
$keys = explode('.', $path);
$val = true;
$localArray = [];
for ($i=count($keys)-1; $i>=0; $i--) {
$localArray = [$keys[$i]=>$val];
$val = $localArray;
}
return $localArray;
}
|
php
|
private function createArrayByPath($path)
{
$keys = explode('.', $path);
$val = true;
$localArray = [];
for ($i=count($keys)-1; $i>=0; $i--) {
$localArray = [$keys[$i]=>$val];
$val = $localArray;
}
return $localArray;
}
|
[
"private",
"function",
"createArrayByPath",
"(",
"$",
"path",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"path",
")",
";",
"$",
"val",
"=",
"true",
";",
"$",
"localArray",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"keys",
")",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"$",
"i",
"--",
")",
"{",
"$",
"localArray",
"=",
"[",
"$",
"keys",
"[",
"$",
"i",
"]",
"=>",
"$",
"val",
"]",
";",
"$",
"val",
"=",
"$",
"localArray",
";",
"}",
"return",
"$",
"localArray",
";",
"}"
] |
Convert dot string to array.
@param string $path string dotted array
@return array
|
[
"Convert",
"dot",
"string",
"to",
"array",
"."
] |
5eccfb2fba31dadf659f0f55edeb1ebca403563e
|
https://github.com/libgraviton/graviton/blob/5eccfb2fba31dadf659f0f55edeb1ebca403563e/src/Graviton/RestBundle/ExclusionStrategy/SelectExclusionStrategy.php#L62-L72
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.