repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
phpMussel/phpMussel | vault/classes/Maikuolan/L10N.php | L10N.getPlural | public function getPlural($Number, $String)
{
if (isset($this->Data[$String])) {
$Choices = $this->Data[$String];
$IntegerRule = $this->IntegerRule;
$FractionRule = $this->FractionRule;
} elseif (isset($this->Fallback[$String])) {
$Choices = $this->Fallback[$String];
$IntegerRule = $this->FallbackIntegerRule;
$FractionRule = $this->FallbackFractionRule;
} else {
return '';
}
if (!is_array($Choices)) {
return $Choices;
}
if (is_float($Number)) {
$Choice = $this->{$FractionRule}($Number);
} elseif (is_int($Number)) {
$Choice = $this->{$IntegerRule}($Number);
} else {
$Choice = 0;
}
if (isset($Choices[$Choice])) {
return $Choices[$Choice];
}
return isset($Choices[0]) ? $Choices[0] : '';
} | php | public function getPlural($Number, $String)
{
if (isset($this->Data[$String])) {
$Choices = $this->Data[$String];
$IntegerRule = $this->IntegerRule;
$FractionRule = $this->FractionRule;
} elseif (isset($this->Fallback[$String])) {
$Choices = $this->Fallback[$String];
$IntegerRule = $this->FallbackIntegerRule;
$FractionRule = $this->FallbackFractionRule;
} else {
return '';
}
if (!is_array($Choices)) {
return $Choices;
}
if (is_float($Number)) {
$Choice = $this->{$FractionRule}($Number);
} elseif (is_int($Number)) {
$Choice = $this->{$IntegerRule}($Number);
} else {
$Choice = 0;
}
if (isset($Choices[$Choice])) {
return $Choices[$Choice];
}
return isset($Choices[0]) ? $Choices[0] : '';
} | [
"public",
"function",
"getPlural",
"(",
"$",
"Number",
",",
"$",
"String",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"Data",
"[",
"$",
"String",
"]",
")",
")",
"{",
"$",
"Choices",
"=",
"$",
"this",
"->",
"Data",
"[",
"$",
"String",
"]",
";",
"$",
"IntegerRule",
"=",
"$",
"this",
"->",
"IntegerRule",
";",
"$",
"FractionRule",
"=",
"$",
"this",
"->",
"FractionRule",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"Fallback",
"[",
"$",
"String",
"]",
")",
")",
"{",
"$",
"Choices",
"=",
"$",
"this",
"->",
"Fallback",
"[",
"$",
"String",
"]",
";",
"$",
"IntegerRule",
"=",
"$",
"this",
"->",
"FallbackIntegerRule",
";",
"$",
"FractionRule",
"=",
"$",
"this",
"->",
"FallbackFractionRule",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"Choices",
")",
")",
"{",
"return",
"$",
"Choices",
";",
"}",
"if",
"(",
"is_float",
"(",
"$",
"Number",
")",
")",
"{",
"$",
"Choice",
"=",
"$",
"this",
"->",
"{",
"$",
"FractionRule",
"}",
"(",
"$",
"Number",
")",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"Number",
")",
")",
"{",
"$",
"Choice",
"=",
"$",
"this",
"->",
"{",
"$",
"IntegerRule",
"}",
"(",
"$",
"Number",
")",
";",
"}",
"else",
"{",
"$",
"Choice",
"=",
"0",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"Choices",
"[",
"$",
"Choice",
"]",
")",
")",
"{",
"return",
"$",
"Choices",
"[",
"$",
"Choice",
"]",
";",
"}",
"return",
"isset",
"(",
"$",
"Choices",
"[",
"0",
"]",
")",
"?",
"$",
"Choices",
"[",
"0",
"]",
":",
"''",
";",
"}"
] | Fetch an L10N string from a range of possible plural forms.
@param int|float $Number The quantity of the subject.
@param string $String Which L10N strings we're fetching from.
@return string The appropriate plural form as determined. | [
"Fetch",
"an",
"L10N",
"string",
"from",
"a",
"range",
"of",
"possible",
"plural",
"forms",
"."
] | 949bdf1c3c13a6fa24774fb205c3fc6c701b5102 | https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/L10N.php#L339-L366 | train |
phpMussel/phpMussel | vault/classes/Maikuolan/L10N.php | L10N.getString | public function getString($String)
{
if (isset($this->Data[$String])) {
return $this->Data[$String];
}
return isset($this->Fallback[$String]) ? $this->Fallback[$String] : '';
} | php | public function getString($String)
{
if (isset($this->Data[$String])) {
return $this->Data[$String];
}
return isset($this->Fallback[$String]) ? $this->Fallback[$String] : '';
} | [
"public",
"function",
"getString",
"(",
"$",
"String",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"Data",
"[",
"$",
"String",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"Data",
"[",
"$",
"String",
"]",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"Fallback",
"[",
"$",
"String",
"]",
")",
"?",
"$",
"this",
"->",
"Fallback",
"[",
"$",
"String",
"]",
":",
"''",
";",
"}"
] | Safely fetch an L10N string.
@param string $String The L10N string to fetch.
@return string The fetched L10N string. | [
"Safely",
"fetch",
"an",
"L10N",
"string",
"."
] | 949bdf1c3c13a6fa24774fb205c3fc6c701b5102 | https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/L10N.php#L374-L380 | train |
phpMussel/phpMussel | vault/classes/Maikuolan/YAML.php | YAML.normaliseValue | private function normaliseValue(&$Value, $ValueLen, $ValueLow)
{
foreach ([
['"', '"', 1],
["'", "'", 1],
['`', '`', 1],
["\x91", "\x92", 1],
["\x93", "\x94", 1],
["\xe2\x80\x98", "\xe2\x80\x99", 3],
["\xe2\x80\x9c", "\xe2\x80\x9d", 3]
] as $Wrapper) {
if (substr($Value, 0, $Wrapper[2]) === $Wrapper[0] && substr($Value, $ValueLen - $Wrapper[2]) === $Wrapper[1]) {
$Value = substr($Value, $Wrapper[2], $ValueLen - ($Wrapper[2] * 2));
return;
}
}
if ($ValueLow === 'true' || $ValueLow === 'y') {
$Value = true;
} elseif ($ValueLow === 'false' || $ValueLow === 'n') {
$Value = false;
} elseif (substr($Value, 0, 2) === '0x' && ($HexTest = substr($Value, 2)) && !preg_match('/[^\da-f]/i', $HexTest) && !($ValueLen % 2)) {
$Value = hex2bin($HexTest);
} elseif (preg_match('~^\d+$~', $Value)) {
$Value = (int)$Value;
} elseif (preg_match('~^\d+\.\d+$~', $Value)) {
$Value = (float)$Value;
} elseif (!$ValueLen) {
$Value = false;
} else {
$Value = (string)$Value;
}
} | php | private function normaliseValue(&$Value, $ValueLen, $ValueLow)
{
foreach ([
['"', '"', 1],
["'", "'", 1],
['`', '`', 1],
["\x91", "\x92", 1],
["\x93", "\x94", 1],
["\xe2\x80\x98", "\xe2\x80\x99", 3],
["\xe2\x80\x9c", "\xe2\x80\x9d", 3]
] as $Wrapper) {
if (substr($Value, 0, $Wrapper[2]) === $Wrapper[0] && substr($Value, $ValueLen - $Wrapper[2]) === $Wrapper[1]) {
$Value = substr($Value, $Wrapper[2], $ValueLen - ($Wrapper[2] * 2));
return;
}
}
if ($ValueLow === 'true' || $ValueLow === 'y') {
$Value = true;
} elseif ($ValueLow === 'false' || $ValueLow === 'n') {
$Value = false;
} elseif (substr($Value, 0, 2) === '0x' && ($HexTest = substr($Value, 2)) && !preg_match('/[^\da-f]/i', $HexTest) && !($ValueLen % 2)) {
$Value = hex2bin($HexTest);
} elseif (preg_match('~^\d+$~', $Value)) {
$Value = (int)$Value;
} elseif (preg_match('~^\d+\.\d+$~', $Value)) {
$Value = (float)$Value;
} elseif (!$ValueLen) {
$Value = false;
} else {
$Value = (string)$Value;
}
} | [
"private",
"function",
"normaliseValue",
"(",
"&",
"$",
"Value",
",",
"$",
"ValueLen",
",",
"$",
"ValueLow",
")",
"{",
"foreach",
"(",
"[",
"[",
"'\"'",
",",
"'\"'",
",",
"1",
"]",
",",
"[",
"\"'\"",
",",
"\"'\"",
",",
"1",
"]",
",",
"[",
"'`'",
",",
"'`'",
",",
"1",
"]",
",",
"[",
"\"\\x91\"",
",",
"\"\\x92\"",
",",
"1",
"]",
",",
"[",
"\"\\x93\"",
",",
"\"\\x94\"",
",",
"1",
"]",
",",
"[",
"\"\\xe2\\x80\\x98\"",
",",
"\"\\xe2\\x80\\x99\"",
",",
"3",
"]",
",",
"[",
"\"\\xe2\\x80\\x9c\"",
",",
"\"\\xe2\\x80\\x9d\"",
",",
"3",
"]",
"]",
"as",
"$",
"Wrapper",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"Value",
",",
"0",
",",
"$",
"Wrapper",
"[",
"2",
"]",
")",
"===",
"$",
"Wrapper",
"[",
"0",
"]",
"&&",
"substr",
"(",
"$",
"Value",
",",
"$",
"ValueLen",
"-",
"$",
"Wrapper",
"[",
"2",
"]",
")",
"===",
"$",
"Wrapper",
"[",
"1",
"]",
")",
"{",
"$",
"Value",
"=",
"substr",
"(",
"$",
"Value",
",",
"$",
"Wrapper",
"[",
"2",
"]",
",",
"$",
"ValueLen",
"-",
"(",
"$",
"Wrapper",
"[",
"2",
"]",
"*",
"2",
")",
")",
";",
"return",
";",
"}",
"}",
"if",
"(",
"$",
"ValueLow",
"===",
"'true'",
"||",
"$",
"ValueLow",
"===",
"'y'",
")",
"{",
"$",
"Value",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"ValueLow",
"===",
"'false'",
"||",
"$",
"ValueLow",
"===",
"'n'",
")",
"{",
"$",
"Value",
"=",
"false",
";",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"Value",
",",
"0",
",",
"2",
")",
"===",
"'0x'",
"&&",
"(",
"$",
"HexTest",
"=",
"substr",
"(",
"$",
"Value",
",",
"2",
")",
")",
"&&",
"!",
"preg_match",
"(",
"'/[^\\da-f]/i'",
",",
"$",
"HexTest",
")",
"&&",
"!",
"(",
"$",
"ValueLen",
"%",
"2",
")",
")",
"{",
"$",
"Value",
"=",
"hex2bin",
"(",
"$",
"HexTest",
")",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'~^\\d+$~'",
",",
"$",
"Value",
")",
")",
"{",
"$",
"Value",
"=",
"(",
"int",
")",
"$",
"Value",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'~^\\d+\\.\\d+$~'",
",",
"$",
"Value",
")",
")",
"{",
"$",
"Value",
"=",
"(",
"float",
")",
"$",
"Value",
";",
"}",
"elseif",
"(",
"!",
"$",
"ValueLen",
")",
"{",
"$",
"Value",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"Value",
"=",
"(",
"string",
")",
"$",
"Value",
";",
"}",
"}"
] | Normalises the values defined by the processLine method.
@param string|int|bool $Value The value to be normalised.
@param int $ValueLen The length of the value to be normalised.
@param string|int|bool $ValueLow The value to be normalised, lowercased. | [
"Normalises",
"the",
"values",
"defined",
"by",
"the",
"processLine",
"method",
"."
] | 949bdf1c3c13a6fa24774fb205c3fc6c701b5102 | https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/YAML.php#L53-L84 | train |
phpMussel/phpMussel | vault/classes/CompressionHandler.php | CompressionHandler.TryX | private function TryX($Using)
{
/** Guard. */
if (!function_exists($Using)) {
/** Missing prerequisite. */
return 1;
}
/** Try to decompress. */
$Try = $Using($this->Data);
/** Success. */
if ($Try !== false && is_string($Try)) {
$this->Data = $Try;
return 0;
}
/** Failure. */
return 2;
} | php | private function TryX($Using)
{
/** Guard. */
if (!function_exists($Using)) {
/** Missing prerequisite. */
return 1;
}
/** Try to decompress. */
$Try = $Using($this->Data);
/** Success. */
if ($Try !== false && is_string($Try)) {
$this->Data = $Try;
return 0;
}
/** Failure. */
return 2;
} | [
"private",
"function",
"TryX",
"(",
"$",
"Using",
")",
"{",
"/** Guard. */",
"if",
"(",
"!",
"function_exists",
"(",
"$",
"Using",
")",
")",
"{",
"/** Missing prerequisite. */",
"return",
"1",
";",
"}",
"/** Try to decompress. */",
"$",
"Try",
"=",
"$",
"Using",
"(",
"$",
"this",
"->",
"Data",
")",
";",
"/** Success. */",
"if",
"(",
"$",
"Try",
"!==",
"false",
"&&",
"is_string",
"(",
"$",
"Try",
")",
")",
"{",
"$",
"this",
"->",
"Data",
"=",
"$",
"Try",
";",
"return",
"0",
";",
"}",
"/** Failure. */",
"return",
"2",
";",
"}"
] | The basis for the other try methods.
@param string $Using What the try methods uses. | [
"The",
"basis",
"for",
"the",
"other",
"try",
"methods",
"."
] | 949bdf1c3c13a6fa24774fb205c3fc6c701b5102 | https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/CompressionHandler.php#L40-L59 | train |
phpMussel/phpMussel | vault/classes/CompressionHandler.php | CompressionHandler.TryEverything | public function TryEverything()
{
/** Fetch original data state. */
$Original = $this->Data;
/** For tracking errors. */
$Errors = &$this->Errors;
/**
* Seeing as we're effectively guessing which compression format has
* been used, and possibly it mightn't be compressed at all, there'll
* probably be warnings and notices generated. So, let's handle that
* cleanly.
*/
set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$Errors) {
$Errors[] = [$errno, $errstr, $errfile, $errline];
});
/** Loop until data state doesn't change anymore. */
while (true) {
if ($this->TryGz() === 0) {
continue;
}
if ($this->TryBz() === 0) {
continue;
}
if ($this->TryLzf() === 0) {
continue;
}
break;
}
/** We're done guessing, so we'll restore the previous error handler. */
restore_error_handler();
/**
* Compare original data state against current data state, and return
* whether they're the same or different. If the same, then data
* probably wasn't compressed to begin with.
*/
return ($Original === $this->Data);
} | php | public function TryEverything()
{
/** Fetch original data state. */
$Original = $this->Data;
/** For tracking errors. */
$Errors = &$this->Errors;
/**
* Seeing as we're effectively guessing which compression format has
* been used, and possibly it mightn't be compressed at all, there'll
* probably be warnings and notices generated. So, let's handle that
* cleanly.
*/
set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$Errors) {
$Errors[] = [$errno, $errstr, $errfile, $errline];
});
/** Loop until data state doesn't change anymore. */
while (true) {
if ($this->TryGz() === 0) {
continue;
}
if ($this->TryBz() === 0) {
continue;
}
if ($this->TryLzf() === 0) {
continue;
}
break;
}
/** We're done guessing, so we'll restore the previous error handler. */
restore_error_handler();
/**
* Compare original data state against current data state, and return
* whether they're the same or different. If the same, then data
* probably wasn't compressed to begin with.
*/
return ($Original === $this->Data);
} | [
"public",
"function",
"TryEverything",
"(",
")",
"{",
"/** Fetch original data state. */",
"$",
"Original",
"=",
"$",
"this",
"->",
"Data",
";",
"/** For tracking errors. */",
"$",
"Errors",
"=",
"&",
"$",
"this",
"->",
"Errors",
";",
"/**\n * Seeing as we're effectively guessing which compression format has\n * been used, and possibly it mightn't be compressed at all, there'll\n * probably be warnings and notices generated. So, let's handle that\n * cleanly.\n */",
"set_error_handler",
"(",
"function",
"(",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
"use",
"(",
"&",
"$",
"Errors",
")",
"{",
"$",
"Errors",
"[",
"]",
"=",
"[",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"errfile",
",",
"$",
"errline",
"]",
";",
"}",
")",
";",
"/** Loop until data state doesn't change anymore. */",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"TryGz",
"(",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"TryBz",
"(",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"TryLzf",
"(",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"break",
";",
"}",
"/** We're done guessing, so we'll restore the previous error handler. */",
"restore_error_handler",
"(",
")",
";",
"/**\n * Compare original data state against current data state, and return\n * whether they're the same or different. If the same, then data\n * probably wasn't compressed to begin with.\n */",
"return",
"(",
"$",
"Original",
"===",
"$",
"this",
"->",
"Data",
")",
";",
"}"
] | Try everything. | [
"Try",
"everything",
"."
] | 949bdf1c3c13a6fa24774fb205c3fc6c701b5102 | https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/CompressionHandler.php#L92-L133 | train |
phpMussel/phpMussel | vault/classes/ArchiveHandler.php | ZipHandler.EntryCRC | public function EntryCRC()
{
return (isset($this->StatIndex['crc']) && is_int($this->StatIndex['crc'])) ? dechex($this->StatIndex['crc']) : false;
} | php | public function EntryCRC()
{
return (isset($this->StatIndex['crc']) && is_int($this->StatIndex['crc'])) ? dechex($this->StatIndex['crc']) : false;
} | [
"public",
"function",
"EntryCRC",
"(",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"StatIndex",
"[",
"'crc'",
"]",
")",
"&&",
"is_int",
"(",
"$",
"this",
"->",
"StatIndex",
"[",
"'crc'",
"]",
")",
")",
"?",
"dechex",
"(",
"$",
"this",
"->",
"StatIndex",
"[",
"'crc'",
"]",
")",
":",
"false",
";",
"}"
] | Return the reported internal CRC hash for the entry, if it exists. | [
"Return",
"the",
"reported",
"internal",
"CRC",
"hash",
"for",
"the",
"entry",
"if",
"it",
"exists",
"."
] | 949bdf1c3c13a6fa24774fb205c3fc6c701b5102 | https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/ArchiveHandler.php#L184-L187 | train |
phpMussel/phpMussel | vault/classes/ArchiveHandler.php | TarHandler.EntryIsDirectory | public function EntryIsDirectory()
{
$Name = $this->EntryName();
return ((substr($Name, -1, 1) === "\\" || substr($Name, -1, 1) === '/') && $this->EntryActualSize === 0);
} | php | public function EntryIsDirectory()
{
$Name = $this->EntryName();
return ((substr($Name, -1, 1) === "\\" || substr($Name, -1, 1) === '/') && $this->EntryActualSize === 0);
} | [
"public",
"function",
"EntryIsDirectory",
"(",
")",
"{",
"$",
"Name",
"=",
"$",
"this",
"->",
"EntryName",
"(",
")",
";",
"return",
"(",
"(",
"substr",
"(",
"$",
"Name",
",",
"-",
"1",
",",
"1",
")",
"===",
"\"\\\\\"",
"||",
"substr",
"(",
"$",
"Name",
",",
"-",
"1",
",",
"1",
")",
"===",
"'/'",
")",
"&&",
"$",
"this",
"->",
"EntryActualSize",
"===",
"0",
")",
";",
"}"
] | Return whether the entry at the current entry pointer is a directory. | [
"Return",
"whether",
"the",
"entry",
"at",
"the",
"current",
"entry",
"pointer",
"is",
"a",
"directory",
"."
] | 949bdf1c3c13a6fa24774fb205c3fc6c701b5102 | https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/ArchiveHandler.php#L280-L284 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Behavior/Mapping/ParentSubscriber.php | ParentSubscriber.mapParent | private function mapParent($document, NodeInterface $node, $options = [])
{
// TODO: performance warning: We are eagerly fetching the parent node
$targetNode = $node->getParent();
// Do not map non-referenceable parent nodes
if (!$targetNode->hasProperty('jcr:uuid')) {
return;
}
$document->setParent($this->proxyFactory->createProxyForNode($document, $targetNode, $options));
} | php | private function mapParent($document, NodeInterface $node, $options = [])
{
// TODO: performance warning: We are eagerly fetching the parent node
$targetNode = $node->getParent();
// Do not map non-referenceable parent nodes
if (!$targetNode->hasProperty('jcr:uuid')) {
return;
}
$document->setParent($this->proxyFactory->createProxyForNode($document, $targetNode, $options));
} | [
"private",
"function",
"mapParent",
"(",
"$",
"document",
",",
"NodeInterface",
"$",
"node",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"// TODO: performance warning: We are eagerly fetching the parent node",
"$",
"targetNode",
"=",
"$",
"node",
"->",
"getParent",
"(",
")",
";",
"// Do not map non-referenceable parent nodes",
"if",
"(",
"!",
"$",
"targetNode",
"->",
"hasProperty",
"(",
"'jcr:uuid'",
")",
")",
"{",
"return",
";",
"}",
"$",
"document",
"->",
"setParent",
"(",
"$",
"this",
"->",
"proxyFactory",
"->",
"createProxyForNode",
"(",
"$",
"document",
",",
"$",
"targetNode",
",",
"$",
"options",
")",
")",
";",
"}"
] | Map parent document to given document.
@param object $document child-document
@param NodeInterface $node to determine parent
@param array $options options to load parent | [
"Map",
"parent",
"document",
"to",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Behavior/Mapping/ParentSubscriber.php#L163-L174 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Search/Subscriber/MediaSearchSubscriber.php | MediaSearchSubscriber.getImageUrl | private function getImageUrl($media, $locale)
{
$mediaApi = new Media($media, $locale);
$this->mediaManager->addFormatsAndUrl($mediaApi);
$formats = $mediaApi->getThumbnails();
if (!isset($formats[$this->searchImageFormat])) {
$this->logger->warning(sprintf(
'Media with ID "%s" does not have thumbnail format "%s". This thumbnail would be used by the search results.',
$media->getId(),
$this->searchImageFormat
));
return;
}
return $formats[$this->searchImageFormat];
} | php | private function getImageUrl($media, $locale)
{
$mediaApi = new Media($media, $locale);
$this->mediaManager->addFormatsAndUrl($mediaApi);
$formats = $mediaApi->getThumbnails();
if (!isset($formats[$this->searchImageFormat])) {
$this->logger->warning(sprintf(
'Media with ID "%s" does not have thumbnail format "%s". This thumbnail would be used by the search results.',
$media->getId(),
$this->searchImageFormat
));
return;
}
return $formats[$this->searchImageFormat];
} | [
"private",
"function",
"getImageUrl",
"(",
"$",
"media",
",",
"$",
"locale",
")",
"{",
"$",
"mediaApi",
"=",
"new",
"Media",
"(",
"$",
"media",
",",
"$",
"locale",
")",
";",
"$",
"this",
"->",
"mediaManager",
"->",
"addFormatsAndUrl",
"(",
"$",
"mediaApi",
")",
";",
"$",
"formats",
"=",
"$",
"mediaApi",
"->",
"getThumbnails",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"formats",
"[",
"$",
"this",
"->",
"searchImageFormat",
"]",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"sprintf",
"(",
"'Media with ID \"%s\" does not have thumbnail format \"%s\". This thumbnail would be used by the search results.'",
",",
"$",
"media",
"->",
"getId",
"(",
")",
",",
"$",
"this",
"->",
"searchImageFormat",
")",
")",
";",
"return",
";",
"}",
"return",
"$",
"formats",
"[",
"$",
"this",
"->",
"searchImageFormat",
"]",
";",
"}"
] | Return the image URL for the given media.
TODO: The media API needs to be improved here. | [
"Return",
"the",
"image",
"URL",
"for",
"the",
"given",
"media",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Search/Subscriber/MediaSearchSubscriber.php#L144-L161 | train |
sulu/sulu | src/Sulu/Bundle/SearchBundle/Search/Document.php | Document.removeSystemFields | public function removeSystemFields()
{
$properties = $this->fields;
unset(
$properties['created'],
$properties['changed'],
$properties['changer'],
$properties['changer_id'],
$properties['creator'],
$properties['creator_id']
);
foreach ($properties as $key => $field) {
// remove system fields
if ('__' == substr($key, 0, 2)) {
continue;
}
$this->properties[$key] = $field->getValue();
}
} | php | public function removeSystemFields()
{
$properties = $this->fields;
unset(
$properties['created'],
$properties['changed'],
$properties['changer'],
$properties['changer_id'],
$properties['creator'],
$properties['creator_id']
);
foreach ($properties as $key => $field) {
// remove system fields
if ('__' == substr($key, 0, 2)) {
continue;
}
$this->properties[$key] = $field->getValue();
}
} | [
"public",
"function",
"removeSystemFields",
"(",
")",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"fields",
";",
"unset",
"(",
"$",
"properties",
"[",
"'created'",
"]",
",",
"$",
"properties",
"[",
"'changed'",
"]",
",",
"$",
"properties",
"[",
"'changer'",
"]",
",",
"$",
"properties",
"[",
"'changer_id'",
"]",
",",
"$",
"properties",
"[",
"'creator'",
"]",
",",
"$",
"properties",
"[",
"'creator_id'",
"]",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"// remove system fields",
"if",
"(",
"'__'",
"==",
"substr",
"(",
"$",
"key",
",",
"0",
",",
"2",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"properties",
"[",
"$",
"key",
"]",
"=",
"$",
"field",
"->",
"getValue",
"(",
")",
";",
"}",
"}"
] | Called by the JMS Serializer before the document is serialized for the
web API.
Here we remove all system fields (which are available in the body
of the document anyway). | [
"Called",
"by",
"the",
"JMS",
"Serializer",
"before",
"the",
"document",
"is",
"serialized",
"for",
"the",
"web",
"API",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SearchBundle/Search/Document.php#L165-L185 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/NodeManager.php | NodeManager.find | public function find($identifier)
{
try {
if (UUIDHelper::isUUID($identifier)) {
return $this->session->getNodeByIdentifier($identifier);
}
return $this->session->getNode($identifier);
} catch (RepositoryException $e) {
throw new DocumentNotFoundException(sprintf(
'Could not find document with ID or path "%s"', $identifier
), null, $e);
}
} | php | public function find($identifier)
{
try {
if (UUIDHelper::isUUID($identifier)) {
return $this->session->getNodeByIdentifier($identifier);
}
return $this->session->getNode($identifier);
} catch (RepositoryException $e) {
throw new DocumentNotFoundException(sprintf(
'Could not find document with ID or path "%s"', $identifier
), null, $e);
}
} | [
"public",
"function",
"find",
"(",
"$",
"identifier",
")",
"{",
"try",
"{",
"if",
"(",
"UUIDHelper",
"::",
"isUUID",
"(",
"$",
"identifier",
")",
")",
"{",
"return",
"$",
"this",
"->",
"session",
"->",
"getNodeByIdentifier",
"(",
"$",
"identifier",
")",
";",
"}",
"return",
"$",
"this",
"->",
"session",
"->",
"getNode",
"(",
"$",
"identifier",
")",
";",
"}",
"catch",
"(",
"RepositoryException",
"$",
"e",
")",
"{",
"throw",
"new",
"DocumentNotFoundException",
"(",
"sprintf",
"(",
"'Could not find document with ID or path \"%s\"'",
",",
"$",
"identifier",
")",
",",
"null",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Find a document with the given path or UUID.
@param string $identifier UUID or path
@return NodeInterface
@throws DocumentNotFoundException | [
"Find",
"a",
"document",
"with",
"the",
"given",
"path",
"or",
"UUID",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/NodeManager.php#L48-L61 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/NodeManager.php | NodeManager.has | public function has($identifier)
{
$this->normalizeToPath($identifier);
try {
$this->find($identifier);
return true;
} catch (DocumentNotFoundException $e) {
return false;
}
} | php | public function has($identifier)
{
$this->normalizeToPath($identifier);
try {
$this->find($identifier);
return true;
} catch (DocumentNotFoundException $e) {
return false;
}
} | [
"public",
"function",
"has",
"(",
"$",
"identifier",
")",
"{",
"$",
"this",
"->",
"normalizeToPath",
"(",
"$",
"identifier",
")",
";",
"try",
"{",
"$",
"this",
"->",
"find",
"(",
"$",
"identifier",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"DocumentNotFoundException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Determine if a node exists at the specified path or if a UUID is given,
then if a node with the UUID exists.
@param string $identifier
@return bool | [
"Determine",
"if",
"a",
"node",
"exists",
"at",
"the",
"specified",
"path",
"or",
"if",
"a",
"UUID",
"is",
"given",
"then",
"if",
"a",
"node",
"with",
"the",
"UUID",
"exists",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/NodeManager.php#L71-L82 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/NodeManager.php | NodeManager.remove | public function remove($identifier)
{
$identifier = $this->normalizeToPath($identifier);
$this->session->removeItem($identifier);
} | php | public function remove($identifier)
{
$identifier = $this->normalizeToPath($identifier);
$this->session->removeItem($identifier);
} | [
"public",
"function",
"remove",
"(",
"$",
"identifier",
")",
"{",
"$",
"identifier",
"=",
"$",
"this",
"->",
"normalizeToPath",
"(",
"$",
"identifier",
")",
";",
"$",
"this",
"->",
"session",
"->",
"removeItem",
"(",
"$",
"identifier",
")",
";",
"}"
] | Remove the document with the given path or UUID.
@param string $identifier ID or path | [
"Remove",
"the",
"document",
"with",
"the",
"given",
"path",
"or",
"UUID",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/NodeManager.php#L89-L93 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/NodeManager.php | NodeManager.createPath | public function createPath($path)
{
$current = $this->session->getRootNode();
$segments = preg_split('#/#', $path, null, PREG_SPLIT_NO_EMPTY);
foreach ($segments as $segment) {
if ($current->hasNode($segment)) {
$current = $current->getNode($segment);
} else {
$current = $current->addNode($segment);
$current->addMixin('mix:referenceable');
$current->setProperty('jcr:uuid', UUIDHelper::generateUUID());
}
}
return $current;
} | php | public function createPath($path)
{
$current = $this->session->getRootNode();
$segments = preg_split('#/#', $path, null, PREG_SPLIT_NO_EMPTY);
foreach ($segments as $segment) {
if ($current->hasNode($segment)) {
$current = $current->getNode($segment);
} else {
$current = $current->addNode($segment);
$current->addMixin('mix:referenceable');
$current->setProperty('jcr:uuid', UUIDHelper::generateUUID());
}
}
return $current;
} | [
"public",
"function",
"createPath",
"(",
"$",
"path",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"session",
"->",
"getRootNode",
"(",
")",
";",
"$",
"segments",
"=",
"preg_split",
"(",
"'#/#'",
",",
"$",
"path",
",",
"null",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"foreach",
"(",
"$",
"segments",
"as",
"$",
"segment",
")",
"{",
"if",
"(",
"$",
"current",
"->",
"hasNode",
"(",
"$",
"segment",
")",
")",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"getNode",
"(",
"$",
"segment",
")",
";",
"}",
"else",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"addNode",
"(",
"$",
"segment",
")",
";",
"$",
"current",
"->",
"addMixin",
"(",
"'mix:referenceable'",
")",
";",
"$",
"current",
"->",
"setProperty",
"(",
"'jcr:uuid'",
",",
"UUIDHelper",
"::",
"generateUUID",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"current",
";",
"}"
] | Create a path.
@param string $path
@return NodeInterface | [
"Create",
"a",
"path",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/NodeManager.php#L161-L177 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/NodeManager.php | NodeManager.normalizeToPath | private function normalizeToPath($identifier)
{
if (UUIDHelper::isUUID($identifier)) {
$identifier = $this->session->getNodeByIdentifier($identifier)->getPath();
}
return $identifier;
} | php | private function normalizeToPath($identifier)
{
if (UUIDHelper::isUUID($identifier)) {
$identifier = $this->session->getNodeByIdentifier($identifier)->getPath();
}
return $identifier;
} | [
"private",
"function",
"normalizeToPath",
"(",
"$",
"identifier",
")",
"{",
"if",
"(",
"UUIDHelper",
"::",
"isUUID",
"(",
"$",
"identifier",
")",
")",
"{",
"$",
"identifier",
"=",
"$",
"this",
"->",
"session",
"->",
"getNodeByIdentifier",
"(",
"$",
"identifier",
")",
"->",
"getPath",
"(",
")",
";",
"}",
"return",
"$",
"identifier",
";",
"}"
] | Normalize the given path or ID to a path.
@param string $identifier
@return string | [
"Normalize",
"the",
"given",
"path",
"or",
"ID",
"to",
"a",
"path",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/NodeManager.php#L194-L201 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Category/KeywordManager.php | KeywordManager.handleOverwrite | private function handleOverwrite(KeywordInterface $keyword, CategoryInterface $category)
{
if (null !== $synonym = $this->findSynonym($keyword)) {
// reset entity and remove it from category
if ($this->entityManager->contains($keyword)) {
$this->entityManager->refresh($keyword);
}
$this->delete($keyword, $category);
// link this synonym to the category
$keyword = $synonym;
}
$categoryTranslation = $category->findTranslationByLocale($keyword->getLocale());
if (!$categoryTranslation) {
$categoryTranslation = $this->createTranslation($category, $keyword->getLocale());
}
// if keyword already exists in category
if ($categoryTranslation->hasKeyword($keyword)) {
return $keyword;
}
$keyword->addCategoryTranslation($categoryTranslation);
$categoryTranslation->addKeyword($keyword);
// FIXME category and meta will not be updated if only keyword was changed
$category->setChanged(new \DateTime());
$categoryTranslation->setChanged(new \DateTime());
return $keyword;
} | php | private function handleOverwrite(KeywordInterface $keyword, CategoryInterface $category)
{
if (null !== $synonym = $this->findSynonym($keyword)) {
// reset entity and remove it from category
if ($this->entityManager->contains($keyword)) {
$this->entityManager->refresh($keyword);
}
$this->delete($keyword, $category);
// link this synonym to the category
$keyword = $synonym;
}
$categoryTranslation = $category->findTranslationByLocale($keyword->getLocale());
if (!$categoryTranslation) {
$categoryTranslation = $this->createTranslation($category, $keyword->getLocale());
}
// if keyword already exists in category
if ($categoryTranslation->hasKeyword($keyword)) {
return $keyword;
}
$keyword->addCategoryTranslation($categoryTranslation);
$categoryTranslation->addKeyword($keyword);
// FIXME category and meta will not be updated if only keyword was changed
$category->setChanged(new \DateTime());
$categoryTranslation->setChanged(new \DateTime());
return $keyword;
} | [
"private",
"function",
"handleOverwrite",
"(",
"KeywordInterface",
"$",
"keyword",
",",
"CategoryInterface",
"$",
"category",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"synonym",
"=",
"$",
"this",
"->",
"findSynonym",
"(",
"$",
"keyword",
")",
")",
"{",
"// reset entity and remove it from category",
"if",
"(",
"$",
"this",
"->",
"entityManager",
"->",
"contains",
"(",
"$",
"keyword",
")",
")",
"{",
"$",
"this",
"->",
"entityManager",
"->",
"refresh",
"(",
"$",
"keyword",
")",
";",
"}",
"$",
"this",
"->",
"delete",
"(",
"$",
"keyword",
",",
"$",
"category",
")",
";",
"// link this synonym to the category",
"$",
"keyword",
"=",
"$",
"synonym",
";",
"}",
"$",
"categoryTranslation",
"=",
"$",
"category",
"->",
"findTranslationByLocale",
"(",
"$",
"keyword",
"->",
"getLocale",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"categoryTranslation",
")",
"{",
"$",
"categoryTranslation",
"=",
"$",
"this",
"->",
"createTranslation",
"(",
"$",
"category",
",",
"$",
"keyword",
"->",
"getLocale",
"(",
")",
")",
";",
"}",
"// if keyword already exists in category",
"if",
"(",
"$",
"categoryTranslation",
"->",
"hasKeyword",
"(",
"$",
"keyword",
")",
")",
"{",
"return",
"$",
"keyword",
";",
"}",
"$",
"keyword",
"->",
"addCategoryTranslation",
"(",
"$",
"categoryTranslation",
")",
";",
"$",
"categoryTranslation",
"->",
"addKeyword",
"(",
"$",
"keyword",
")",
";",
"// FIXME category and meta will not be updated if only keyword was changed",
"$",
"category",
"->",
"setChanged",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"$",
"categoryTranslation",
"->",
"setChanged",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"return",
"$",
"keyword",
";",
"}"
] | Overwrites given keyword.
@param CategoryInterface $category
@param KeywordInterface $keyword
@return KeywordInterface | [
"Overwrites",
"given",
"keyword",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Category/KeywordManager.php#L89-L120 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Category/KeywordManager.php | KeywordManager.handleDetach | private function handleDetach(KeywordInterface $keyword, CategoryInterface $category)
{
$keywordString = $keyword->getKeyword();
$keywordLocale = $keyword->getLocale();
// if keyword wont be deleted (because of multiple references)
// refresh it to be sure hat changes wont be written to
// database.
$this->entityManager->refresh($keyword);
// delete old keyword from category
$this->delete($keyword, $category);
// create new keyword
$newEntity = $this->keywordRepository->createNew();
$newEntity->setKeyword($keywordString);
$newEntity->setLocale($keywordLocale);
// add new keyword to category
return $this->save($newEntity, $category);
} | php | private function handleDetach(KeywordInterface $keyword, CategoryInterface $category)
{
$keywordString = $keyword->getKeyword();
$keywordLocale = $keyword->getLocale();
// if keyword wont be deleted (because of multiple references)
// refresh it to be sure hat changes wont be written to
// database.
$this->entityManager->refresh($keyword);
// delete old keyword from category
$this->delete($keyword, $category);
// create new keyword
$newEntity = $this->keywordRepository->createNew();
$newEntity->setKeyword($keywordString);
$newEntity->setLocale($keywordLocale);
// add new keyword to category
return $this->save($newEntity, $category);
} | [
"private",
"function",
"handleDetach",
"(",
"KeywordInterface",
"$",
"keyword",
",",
"CategoryInterface",
"$",
"category",
")",
"{",
"$",
"keywordString",
"=",
"$",
"keyword",
"->",
"getKeyword",
"(",
")",
";",
"$",
"keywordLocale",
"=",
"$",
"keyword",
"->",
"getLocale",
"(",
")",
";",
"// if keyword wont be deleted (because of multiple references)",
"// refresh it to be sure hat changes wont be written to",
"// database.",
"$",
"this",
"->",
"entityManager",
"->",
"refresh",
"(",
"$",
"keyword",
")",
";",
"// delete old keyword from category",
"$",
"this",
"->",
"delete",
"(",
"$",
"keyword",
",",
"$",
"category",
")",
";",
"// create new keyword",
"$",
"newEntity",
"=",
"$",
"this",
"->",
"keywordRepository",
"->",
"createNew",
"(",
")",
";",
"$",
"newEntity",
"->",
"setKeyword",
"(",
"$",
"keywordString",
")",
";",
"$",
"newEntity",
"->",
"setLocale",
"(",
"$",
"keywordLocale",
")",
";",
"// add new keyword to category",
"return",
"$",
"this",
"->",
"save",
"(",
"$",
"newEntity",
",",
"$",
"category",
")",
";",
"}"
] | Detach given and create new keyword entity.
@param CategoryInterface $category
@param KeywordInterface $keyword
@return KeywordInterface | [
"Detach",
"given",
"and",
"create",
"new",
"keyword",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Category/KeywordManager.php#L130-L150 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Category/KeywordManager.php | KeywordManager.findSynonym | private function findSynonym(KeywordInterface $keyword)
{
return $this->keywordRepository->findByKeyword($keyword->getKeyword(), $keyword->getLocale());
} | php | private function findSynonym(KeywordInterface $keyword)
{
return $this->keywordRepository->findByKeyword($keyword->getKeyword(), $keyword->getLocale());
} | [
"private",
"function",
"findSynonym",
"(",
"KeywordInterface",
"$",
"keyword",
")",
"{",
"return",
"$",
"this",
"->",
"keywordRepository",
"->",
"findByKeyword",
"(",
"$",
"keyword",
"->",
"getKeyword",
"(",
")",
",",
"$",
"keyword",
"->",
"getLocale",
"(",
")",
")",
";",
"}"
] | Find the same keyword in the database or returns null if no synonym exists.
@param KeywordInterface $keyword
@return KeywordInterface|null | [
"Find",
"the",
"same",
"keyword",
"in",
"the",
"database",
"or",
"returns",
"null",
"if",
"no",
"synonym",
"exists",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Category/KeywordManager.php#L184-L187 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Category/KeywordManager.php | KeywordManager.createTranslation | private function createTranslation(CategoryInterface $category, $locale)
{
$categoryTranslation = $this->categoryTranslationRepository->createNew();
$categoryTranslation->setLocale($locale);
$categoryTranslation->setTranslation('');
$categoryTranslation->setCategory($category);
$category->addTranslation($categoryTranslation);
$this->entityManager->persist($categoryTranslation);
return $categoryTranslation;
} | php | private function createTranslation(CategoryInterface $category, $locale)
{
$categoryTranslation = $this->categoryTranslationRepository->createNew();
$categoryTranslation->setLocale($locale);
$categoryTranslation->setTranslation('');
$categoryTranslation->setCategory($category);
$category->addTranslation($categoryTranslation);
$this->entityManager->persist($categoryTranslation);
return $categoryTranslation;
} | [
"private",
"function",
"createTranslation",
"(",
"CategoryInterface",
"$",
"category",
",",
"$",
"locale",
")",
"{",
"$",
"categoryTranslation",
"=",
"$",
"this",
"->",
"categoryTranslationRepository",
"->",
"createNew",
"(",
")",
";",
"$",
"categoryTranslation",
"->",
"setLocale",
"(",
"$",
"locale",
")",
";",
"$",
"categoryTranslation",
"->",
"setTranslation",
"(",
"''",
")",
";",
"$",
"categoryTranslation",
"->",
"setCategory",
"(",
"$",
"category",
")",
";",
"$",
"category",
"->",
"addTranslation",
"(",
"$",
"categoryTranslation",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"persist",
"(",
"$",
"categoryTranslation",
")",
";",
"return",
"$",
"categoryTranslation",
";",
"}"
] | Creates a new category translation for a given category and locale.
@param CategoryInterface $category
@param $locale
@return CategoryTranslationInterface | [
"Creates",
"a",
"new",
"category",
"translation",
"for",
"a",
"given",
"category",
"and",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Category/KeywordManager.php#L197-L208 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Twig/DispositionTypeTwigExtension.php | DispositionTypeTwigExtension.getMediaUrl | public function getMediaUrl(Media $media, $dispositionType = null)
{
$url = $media->getUrl();
if (ResponseHeaderBag::DISPOSITION_INLINE === $dispositionType) {
$url .= (false === strpos($url, '?') ? '?inline=1' : '&inline=1');
} elseif (ResponseHeaderBag::DISPOSITION_ATTACHMENT === $dispositionType) {
$url .= (false === strpos($url, '?') ? '?inline=0' : '&inline=0');
}
return $url;
} | php | public function getMediaUrl(Media $media, $dispositionType = null)
{
$url = $media->getUrl();
if (ResponseHeaderBag::DISPOSITION_INLINE === $dispositionType) {
$url .= (false === strpos($url, '?') ? '?inline=1' : '&inline=1');
} elseif (ResponseHeaderBag::DISPOSITION_ATTACHMENT === $dispositionType) {
$url .= (false === strpos($url, '?') ? '?inline=0' : '&inline=0');
}
return $url;
} | [
"public",
"function",
"getMediaUrl",
"(",
"Media",
"$",
"media",
",",
"$",
"dispositionType",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"$",
"media",
"->",
"getUrl",
"(",
")",
";",
"if",
"(",
"ResponseHeaderBag",
"::",
"DISPOSITION_INLINE",
"===",
"$",
"dispositionType",
")",
"{",
"$",
"url",
".=",
"(",
"false",
"===",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
"?",
"'?inline=1'",
":",
"'&inline=1'",
")",
";",
"}",
"elseif",
"(",
"ResponseHeaderBag",
"::",
"DISPOSITION_ATTACHMENT",
"===",
"$",
"dispositionType",
")",
"{",
"$",
"url",
".=",
"(",
"false",
"===",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
"?",
"'?inline=0'",
":",
"'&inline=0'",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Get media url.
@param Media $media
@param null|string $dispositionType
@return string | [
"Get",
"media",
"url",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Twig/DispositionTypeTwigExtension.php#L42-L53 | train |
sulu/sulu | src/Sulu/Component/Webspace/Url.php | Url.isValidLocale | public function isValidLocale($language, $country)
{
return ($this->getLanguage() === $language && $this->getCountry() === $country)
|| (empty($this->getLanguage()) && empty($this->getCountry()));
} | php | public function isValidLocale($language, $country)
{
return ($this->getLanguage() === $language && $this->getCountry() === $country)
|| (empty($this->getLanguage()) && empty($this->getCountry()));
} | [
"public",
"function",
"isValidLocale",
"(",
"$",
"language",
",",
"$",
"country",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"getLanguage",
"(",
")",
"===",
"$",
"language",
"&&",
"$",
"this",
"->",
"getCountry",
"(",
")",
"===",
"$",
"country",
")",
"||",
"(",
"empty",
"(",
"$",
"this",
"->",
"getLanguage",
"(",
")",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"getCountry",
"(",
")",
")",
")",
";",
"}"
] | Checks if this URL handles the locale for the given language and country.
@param string $language
@param string $country
@return bool | [
"Checks",
"if",
"this",
"URL",
"handles",
"the",
"locale",
"for",
"the",
"given",
"language",
"and",
"country",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Url.php#L219-L223 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Behavior/Audit/TimestampSubscriber.php | TimestampSubscriber.setTimestampsOnDocument | public function setTimestampsOnDocument(HydrateEvent $event)
{
$document = $event->getDocument();
if (!$this->supports($document)) {
return;
}
$accessor = $event->getAccessor();
$node = $event->getNode();
$locale = $this->documentInspector->getOriginalLocale($document);
$encoding = $this->getPropertyEncoding($document);
$accessor->set(
static::CHANGED,
$node->getPropertyValueWithDefault(
$this->propertyEncoder->encode($encoding, static::CHANGED, $locale),
null
)
);
$accessor->set(
static::CREATED,
$node->getPropertyValueWithDefault(
$this->propertyEncoder->encode($encoding, static::CREATED, $locale),
null
)
);
} | php | public function setTimestampsOnDocument(HydrateEvent $event)
{
$document = $event->getDocument();
if (!$this->supports($document)) {
return;
}
$accessor = $event->getAccessor();
$node = $event->getNode();
$locale = $this->documentInspector->getOriginalLocale($document);
$encoding = $this->getPropertyEncoding($document);
$accessor->set(
static::CHANGED,
$node->getPropertyValueWithDefault(
$this->propertyEncoder->encode($encoding, static::CHANGED, $locale),
null
)
);
$accessor->set(
static::CREATED,
$node->getPropertyValueWithDefault(
$this->propertyEncoder->encode($encoding, static::CREATED, $locale),
null
)
);
} | [
"public",
"function",
"setTimestampsOnDocument",
"(",
"HydrateEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"supports",
"(",
"$",
"document",
")",
")",
"{",
"return",
";",
"}",
"$",
"accessor",
"=",
"$",
"event",
"->",
"getAccessor",
"(",
")",
";",
"$",
"node",
"=",
"$",
"event",
"->",
"getNode",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"documentInspector",
"->",
"getOriginalLocale",
"(",
"$",
"document",
")",
";",
"$",
"encoding",
"=",
"$",
"this",
"->",
"getPropertyEncoding",
"(",
"$",
"document",
")",
";",
"$",
"accessor",
"->",
"set",
"(",
"static",
"::",
"CHANGED",
",",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"$",
"this",
"->",
"propertyEncoder",
"->",
"encode",
"(",
"$",
"encoding",
",",
"static",
"::",
"CHANGED",
",",
"$",
"locale",
")",
",",
"null",
")",
")",
";",
"$",
"accessor",
"->",
"set",
"(",
"static",
"::",
"CREATED",
",",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"$",
"this",
"->",
"propertyEncoder",
"->",
"encode",
"(",
"$",
"encoding",
",",
"static",
"::",
"CREATED",
",",
"$",
"locale",
")",
",",
"null",
")",
")",
";",
"}"
] | Sets the timestamps from the node to the document.
@param HydrateEvent $event | [
"Sets",
"the",
"timestamps",
"from",
"the",
"node",
"to",
"the",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Behavior/Audit/TimestampSubscriber.php#L70-L97 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Behavior/Audit/TimestampSubscriber.php | TimestampSubscriber.setTimestampsOnNodeForPersist | public function setTimestampsOnNodeForPersist(PersistEvent $event)
{
$document = $event->getDocument();
if (!$this->supports($document)) {
return;
}
$this->setTimestampsOnNode(
$document,
$event->getNode(),
$event->getAccessor(),
$this->documentInspector->getOriginalLocale($document),
new \DateTime()
);
} | php | public function setTimestampsOnNodeForPersist(PersistEvent $event)
{
$document = $event->getDocument();
if (!$this->supports($document)) {
return;
}
$this->setTimestampsOnNode(
$document,
$event->getNode(),
$event->getAccessor(),
$this->documentInspector->getOriginalLocale($document),
new \DateTime()
);
} | [
"public",
"function",
"setTimestampsOnNodeForPersist",
"(",
"PersistEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"supports",
"(",
"$",
"document",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"setTimestampsOnNode",
"(",
"$",
"document",
",",
"$",
"event",
"->",
"getNode",
"(",
")",
",",
"$",
"event",
"->",
"getAccessor",
"(",
")",
",",
"$",
"this",
"->",
"documentInspector",
"->",
"getOriginalLocale",
"(",
"$",
"document",
")",
",",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"}"
] | Sets the timestamps on the nodes for the persist operation.
@param PersistEvent $event | [
"Sets",
"the",
"timestamps",
"on",
"the",
"nodes",
"for",
"the",
"persist",
"operation",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Behavior/Audit/TimestampSubscriber.php#L104-L119 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Behavior/Audit/TimestampSubscriber.php | TimestampSubscriber.setTimestampsOnNode | public function setTimestampsOnNode(
LocalizedTimestampBehavior $document,
NodeInterface $node,
DocumentAccessor $accessor,
$locale,
$timestamp = null
) {
if (!$document instanceof TimestampBehavior && !$locale) {
return;
}
$encoding = $this->getPropertyEncoding($document);
$createdPropertyName = $this->propertyEncoder->encode($encoding, static::CREATED, $locale);
if (!$node->hasProperty($createdPropertyName)) {
$createdTimestamp = $document->getCreated() ?: $timestamp;
$accessor->set(static::CREATED, $createdTimestamp);
$node->setProperty($createdPropertyName, $createdTimestamp);
}
$changedTimestamp = $timestamp ?: $document->getChanged();
$accessor->set(static::CHANGED, $changedTimestamp);
$node->setProperty($this->propertyEncoder->encode($encoding, static::CHANGED, $locale), $changedTimestamp);
} | php | public function setTimestampsOnNode(
LocalizedTimestampBehavior $document,
NodeInterface $node,
DocumentAccessor $accessor,
$locale,
$timestamp = null
) {
if (!$document instanceof TimestampBehavior && !$locale) {
return;
}
$encoding = $this->getPropertyEncoding($document);
$createdPropertyName = $this->propertyEncoder->encode($encoding, static::CREATED, $locale);
if (!$node->hasProperty($createdPropertyName)) {
$createdTimestamp = $document->getCreated() ?: $timestamp;
$accessor->set(static::CREATED, $createdTimestamp);
$node->setProperty($createdPropertyName, $createdTimestamp);
}
$changedTimestamp = $timestamp ?: $document->getChanged();
$accessor->set(static::CHANGED, $changedTimestamp);
$node->setProperty($this->propertyEncoder->encode($encoding, static::CHANGED, $locale), $changedTimestamp);
} | [
"public",
"function",
"setTimestampsOnNode",
"(",
"LocalizedTimestampBehavior",
"$",
"document",
",",
"NodeInterface",
"$",
"node",
",",
"DocumentAccessor",
"$",
"accessor",
",",
"$",
"locale",
",",
"$",
"timestamp",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"TimestampBehavior",
"&&",
"!",
"$",
"locale",
")",
"{",
"return",
";",
"}",
"$",
"encoding",
"=",
"$",
"this",
"->",
"getPropertyEncoding",
"(",
"$",
"document",
")",
";",
"$",
"createdPropertyName",
"=",
"$",
"this",
"->",
"propertyEncoder",
"->",
"encode",
"(",
"$",
"encoding",
",",
"static",
"::",
"CREATED",
",",
"$",
"locale",
")",
";",
"if",
"(",
"!",
"$",
"node",
"->",
"hasProperty",
"(",
"$",
"createdPropertyName",
")",
")",
"{",
"$",
"createdTimestamp",
"=",
"$",
"document",
"->",
"getCreated",
"(",
")",
"?",
":",
"$",
"timestamp",
";",
"$",
"accessor",
"->",
"set",
"(",
"static",
"::",
"CREATED",
",",
"$",
"createdTimestamp",
")",
";",
"$",
"node",
"->",
"setProperty",
"(",
"$",
"createdPropertyName",
",",
"$",
"createdTimestamp",
")",
";",
"}",
"$",
"changedTimestamp",
"=",
"$",
"timestamp",
"?",
":",
"$",
"document",
"->",
"getChanged",
"(",
")",
";",
"$",
"accessor",
"->",
"set",
"(",
"static",
"::",
"CHANGED",
",",
"$",
"changedTimestamp",
")",
";",
"$",
"node",
"->",
"setProperty",
"(",
"$",
"this",
"->",
"propertyEncoder",
"->",
"encode",
"(",
"$",
"encoding",
",",
"static",
"::",
"CHANGED",
",",
"$",
"locale",
")",
",",
"$",
"changedTimestamp",
")",
";",
"}"
] | Set the timestamps on the node.
@param LocalizedTimestampBehavior $document
@param NodeInterface $node
@param DocumentAccessor $accessor
@param string $locale
@param \DateTime|null $timestamp The timestamp to set, will use the documents timestamps if null is provided | [
"Set",
"the",
"timestamps",
"on",
"the",
"node",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Behavior/Audit/TimestampSubscriber.php#L146-L169 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Behavior/Audit/TimestampSubscriber.php | TimestampSubscriber.setChangedForRestore | public function setChangedForRestore(RestoreEvent $event)
{
$document = $event->getDocument();
if (!$this->supports($document)) {
return;
}
$encoding = $this->getPropertyEncoding($document);
$event->getNode()->setProperty(
$this->propertyEncoder->encode(
$encoding,
static::CHANGED,
$this->documentInspector->getOriginalLocale($document)
),
new \DateTime()
);
} | php | public function setChangedForRestore(RestoreEvent $event)
{
$document = $event->getDocument();
if (!$this->supports($document)) {
return;
}
$encoding = $this->getPropertyEncoding($document);
$event->getNode()->setProperty(
$this->propertyEncoder->encode(
$encoding,
static::CHANGED,
$this->documentInspector->getOriginalLocale($document)
),
new \DateTime()
);
} | [
"public",
"function",
"setChangedForRestore",
"(",
"RestoreEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"supports",
"(",
"$",
"document",
")",
")",
"{",
"return",
";",
"}",
"$",
"encoding",
"=",
"$",
"this",
"->",
"getPropertyEncoding",
"(",
"$",
"document",
")",
";",
"$",
"event",
"->",
"getNode",
"(",
")",
"->",
"setProperty",
"(",
"$",
"this",
"->",
"propertyEncoder",
"->",
"encode",
"(",
"$",
"encoding",
",",
"static",
"::",
"CHANGED",
",",
"$",
"this",
"->",
"documentInspector",
"->",
"getOriginalLocale",
"(",
"$",
"document",
")",
")",
",",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"}"
] | Sets the changed timestamp when restoring a document.
@param RestoreEvent $event | [
"Sets",
"the",
"changed",
"timestamp",
"when",
"restoring",
"a",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Behavior/Audit/TimestampSubscriber.php#L176-L193 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure/LegacyPropertyFactory.php | LegacyPropertyFactory.createTranslatedProperty | public function createTranslatedProperty($property, $locale, StructureInterface $structure = null)
{
if ($property instanceof ItemMetadata) {
$property = $this->createProperty($property, $structure);
}
$property = new TranslatedProperty(
$property,
$locale,
$this->namespaceRegistry->getPrefix('content_localized')
);
return $property;
} | php | public function createTranslatedProperty($property, $locale, StructureInterface $structure = null)
{
if ($property instanceof ItemMetadata) {
$property = $this->createProperty($property, $structure);
}
$property = new TranslatedProperty(
$property,
$locale,
$this->namespaceRegistry->getPrefix('content_localized')
);
return $property;
} | [
"public",
"function",
"createTranslatedProperty",
"(",
"$",
"property",
",",
"$",
"locale",
",",
"StructureInterface",
"$",
"structure",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"property",
"instanceof",
"ItemMetadata",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"createProperty",
"(",
"$",
"property",
",",
"$",
"structure",
")",
";",
"}",
"$",
"property",
"=",
"new",
"TranslatedProperty",
"(",
"$",
"property",
",",
"$",
"locale",
",",
"$",
"this",
"->",
"namespaceRegistry",
"->",
"getPrefix",
"(",
"'content_localized'",
")",
")",
";",
"return",
"$",
"property",
";",
"}"
] | Create a new "translated" property.
@param object $property
@param string $locale
@return PropertyInterface | [
"Create",
"a",
"new",
"translated",
"property",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure/LegacyPropertyFactory.php#L54-L66 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure/LegacyPropertyFactory.php | LegacyPropertyFactory.createProperty | public function createProperty(ItemMetadata $property, StructureInterface $structure = null)
{
if ($property instanceof SectionMetadata) {
return $this->createSectionProperty($property, $structure);
}
if ($property instanceof BlockMetadata) {
return $this->createBlockProperty($property, $structure);
}
if (null === $property->getType()) {
throw new \RuntimeException(sprintf(
'Property name "%s" has no type.',
$property->getName()
));
}
$parameters = $this->convertArrayToParameters($property->getParameters());
$propertyBridge = new LegacyProperty(
$property->getName(),
[
'title' => $property->getTitles(),
'info_text' => $property->getDescriptions(),
'placeholder' => $property->getPlaceholders(),
],
$property->getType(),
$property->isRequired(),
$property->isLocalized(),
$property->getMaxOccurs(),
$property->getMinOccurs(),
$parameters,
[],
$property->getColSpan()
);
foreach ($property->getTags() as $tag) {
$propertyBridge->addTag(new PropertyTag($tag['name'], $tag['priority'], $tag['attributes']));
}
$propertyBridge->setStructure($structure);
return $propertyBridge;
} | php | public function createProperty(ItemMetadata $property, StructureInterface $structure = null)
{
if ($property instanceof SectionMetadata) {
return $this->createSectionProperty($property, $structure);
}
if ($property instanceof BlockMetadata) {
return $this->createBlockProperty($property, $structure);
}
if (null === $property->getType()) {
throw new \RuntimeException(sprintf(
'Property name "%s" has no type.',
$property->getName()
));
}
$parameters = $this->convertArrayToParameters($property->getParameters());
$propertyBridge = new LegacyProperty(
$property->getName(),
[
'title' => $property->getTitles(),
'info_text' => $property->getDescriptions(),
'placeholder' => $property->getPlaceholders(),
],
$property->getType(),
$property->isRequired(),
$property->isLocalized(),
$property->getMaxOccurs(),
$property->getMinOccurs(),
$parameters,
[],
$property->getColSpan()
);
foreach ($property->getTags() as $tag) {
$propertyBridge->addTag(new PropertyTag($tag['name'], $tag['priority'], $tag['attributes']));
}
$propertyBridge->setStructure($structure);
return $propertyBridge;
} | [
"public",
"function",
"createProperty",
"(",
"ItemMetadata",
"$",
"property",
",",
"StructureInterface",
"$",
"structure",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"property",
"instanceof",
"SectionMetadata",
")",
"{",
"return",
"$",
"this",
"->",
"createSectionProperty",
"(",
"$",
"property",
",",
"$",
"structure",
")",
";",
"}",
"if",
"(",
"$",
"property",
"instanceof",
"BlockMetadata",
")",
"{",
"return",
"$",
"this",
"->",
"createBlockProperty",
"(",
"$",
"property",
",",
"$",
"structure",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"property",
"->",
"getType",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Property name \"%s\" has no type.'",
",",
"$",
"property",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"$",
"parameters",
"=",
"$",
"this",
"->",
"convertArrayToParameters",
"(",
"$",
"property",
"->",
"getParameters",
"(",
")",
")",
";",
"$",
"propertyBridge",
"=",
"new",
"LegacyProperty",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"[",
"'title'",
"=>",
"$",
"property",
"->",
"getTitles",
"(",
")",
",",
"'info_text'",
"=>",
"$",
"property",
"->",
"getDescriptions",
"(",
")",
",",
"'placeholder'",
"=>",
"$",
"property",
"->",
"getPlaceholders",
"(",
")",
",",
"]",
",",
"$",
"property",
"->",
"getType",
"(",
")",
",",
"$",
"property",
"->",
"isRequired",
"(",
")",
",",
"$",
"property",
"->",
"isLocalized",
"(",
")",
",",
"$",
"property",
"->",
"getMaxOccurs",
"(",
")",
",",
"$",
"property",
"->",
"getMinOccurs",
"(",
")",
",",
"$",
"parameters",
",",
"[",
"]",
",",
"$",
"property",
"->",
"getColSpan",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"property",
"->",
"getTags",
"(",
")",
"as",
"$",
"tag",
")",
"{",
"$",
"propertyBridge",
"->",
"addTag",
"(",
"new",
"PropertyTag",
"(",
"$",
"tag",
"[",
"'name'",
"]",
",",
"$",
"tag",
"[",
"'priority'",
"]",
",",
"$",
"tag",
"[",
"'attributes'",
"]",
")",
")",
";",
"}",
"$",
"propertyBridge",
"->",
"setStructure",
"(",
"$",
"structure",
")",
";",
"return",
"$",
"propertyBridge",
";",
"}"
] | Create a new property.
@param Item $item
@return PropertyInterface $property | [
"Create",
"a",
"new",
"property",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure/LegacyPropertyFactory.php#L75-L117 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Bridge/Serializer/Subscriber/ChildrenSubscriber.php | ChildrenSubscriber.onPostSerialize | public function onPostSerialize(ObjectEvent $event)
{
$document = $event->getObject();
if (!$document instanceof ChildrenBehavior || !$this->documentRegistry->hasDocument($document)) {
return;
}
$visitor = $event->getVisitor();
$visitor->addData('hasSub', $this->documentInspector->hasChildren($document));
} | php | public function onPostSerialize(ObjectEvent $event)
{
$document = $event->getObject();
if (!$document instanceof ChildrenBehavior || !$this->documentRegistry->hasDocument($document)) {
return;
}
$visitor = $event->getVisitor();
$visitor->addData('hasSub', $this->documentInspector->hasChildren($document));
} | [
"public",
"function",
"onPostSerialize",
"(",
"ObjectEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getObject",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"ChildrenBehavior",
"||",
"!",
"$",
"this",
"->",
"documentRegistry",
"->",
"hasDocument",
"(",
"$",
"document",
")",
")",
"{",
"return",
";",
"}",
"$",
"visitor",
"=",
"$",
"event",
"->",
"getVisitor",
"(",
")",
";",
"$",
"visitor",
"->",
"addData",
"(",
"'hasSub'",
",",
"$",
"this",
"->",
"documentInspector",
"->",
"hasChildren",
"(",
"$",
"document",
")",
")",
";",
"}"
] | Adds a flag to indicate if the document has children.
@param ObjectEvent $event | [
"Adds",
"a",
"flag",
"to",
"indicate",
"if",
"the",
"document",
"has",
"children",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Bridge/Serializer/Subscriber/ChildrenSubscriber.php#L61-L71 | train |
sulu/sulu | src/Sulu/Component/Import/Import.php | Import.getParser | protected function getParser($format)
{
if (!isset($this->formatFilePaths[$format])) {
throw new FormatImporterNotFoundException($format);
}
return $this->formatFilePaths[$format];
} | php | protected function getParser($format)
{
if (!isset($this->formatFilePaths[$format])) {
throw new FormatImporterNotFoundException($format);
}
return $this->formatFilePaths[$format];
} | [
"protected",
"function",
"getParser",
"(",
"$",
"format",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"formatFilePaths",
"[",
"$",
"format",
"]",
")",
")",
"{",
"throw",
"new",
"FormatImporterNotFoundException",
"(",
"$",
"format",
")",
";",
"}",
"return",
"$",
"this",
"->",
"formatFilePaths",
"[",
"$",
"format",
"]",
";",
"}"
] | Returns the correct parser like XLIFF1.2.
@param $format
@return FormatImportInterface
@throws FormatImporterNotFoundException | [
"Returns",
"the",
"correct",
"parser",
"like",
"XLIFF1",
".",
"2",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Import/Import.php#L66-L73 | train |
sulu/sulu | src/Sulu/Component/Import/Import.php | Import.importProperty | protected function importProperty(
PropertyInterface $property,
NodeInterface $node,
StructureInterface $structure,
$value,
$webspaceKey,
$locale,
$format
) {
$contentType = $property->getContentTypeName();
if (!$this->importManager->hasImport($contentType, $format)) {
return;
}
$translateProperty = $this->legacyPropertyFactory->createTranslatedProperty($property, $locale, $structure);
$this->importManager->import($contentType, $node, $translateProperty, $value, null, $webspaceKey, $locale);
} | php | protected function importProperty(
PropertyInterface $property,
NodeInterface $node,
StructureInterface $structure,
$value,
$webspaceKey,
$locale,
$format
) {
$contentType = $property->getContentTypeName();
if (!$this->importManager->hasImport($contentType, $format)) {
return;
}
$translateProperty = $this->legacyPropertyFactory->createTranslatedProperty($property, $locale, $structure);
$this->importManager->import($contentType, $node, $translateProperty, $value, null, $webspaceKey, $locale);
} | [
"protected",
"function",
"importProperty",
"(",
"PropertyInterface",
"$",
"property",
",",
"NodeInterface",
"$",
"node",
",",
"StructureInterface",
"$",
"structure",
",",
"$",
"value",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
",",
"$",
"format",
")",
"{",
"$",
"contentType",
"=",
"$",
"property",
"->",
"getContentTypeName",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"importManager",
"->",
"hasImport",
"(",
"$",
"contentType",
",",
"$",
"format",
")",
")",
"{",
"return",
";",
"}",
"$",
"translateProperty",
"=",
"$",
"this",
"->",
"legacyPropertyFactory",
"->",
"createTranslatedProperty",
"(",
"$",
"property",
",",
"$",
"locale",
",",
"$",
"structure",
")",
";",
"$",
"this",
"->",
"importManager",
"->",
"import",
"(",
"$",
"contentType",
",",
"$",
"node",
",",
"$",
"translateProperty",
",",
"$",
"value",
",",
"null",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
")",
";",
"}"
] | Prepare document-property and import them.
@param PropertyInterface $property
@param NodeInterface $node
@param StructureInterface $structure
@param string $value
@param string $webspaceKey
@param string $locale
@param string $format | [
"Prepare",
"document",
"-",
"property",
"and",
"import",
"them",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Import/Import.php#L86-L103 | train |
sulu/sulu | src/Sulu/Component/SmartContent/Orm/BaseDataProvider.php | BaseDataProvider.decorateResourceItems | protected function decorateResourceItems(array $data, $locale)
{
return array_map(
function($item) {
$itemData = $this->serializer->serialize($item, 'array', $this->getSerializationContext());
$id = $this->getIdForItem($item);
if ($this->referenceStore) {
$this->referenceStore->add($id);
}
return new ArrayAccessItem($id, $itemData, $item);
},
$data
);
} | php | protected function decorateResourceItems(array $data, $locale)
{
return array_map(
function($item) {
$itemData = $this->serializer->serialize($item, 'array', $this->getSerializationContext());
$id = $this->getIdForItem($item);
if ($this->referenceStore) {
$this->referenceStore->add($id);
}
return new ArrayAccessItem($id, $itemData, $item);
},
$data
);
} | [
"protected",
"function",
"decorateResourceItems",
"(",
"array",
"$",
"data",
",",
"$",
"locale",
")",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"$",
"itemData",
"=",
"$",
"this",
"->",
"serializer",
"->",
"serialize",
"(",
"$",
"item",
",",
"'array'",
",",
"$",
"this",
"->",
"getSerializationContext",
"(",
")",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"getIdForItem",
"(",
"$",
"item",
")",
";",
"if",
"(",
"$",
"this",
"->",
"referenceStore",
")",
"{",
"$",
"this",
"->",
"referenceStore",
"->",
"add",
"(",
"$",
"id",
")",
";",
"}",
"return",
"new",
"ArrayAccessItem",
"(",
"$",
"id",
",",
"$",
"itemData",
",",
"$",
"item",
")",
";",
"}",
",",
"$",
"data",
")",
";",
"}"
] | Decorates result as resource item.
@param array $data
@param string $locale
@return ArrayAccessItem[] | [
"Decorates",
"result",
"as",
"resource",
"item",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/SmartContent/Orm/BaseDataProvider.php#L192-L207 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Entity/UrlType.php | UrlType.addUrl | public function addUrl(\Sulu\Bundle\ContactBundle\Entity\Url $urls)
{
$this->urls[] = $urls;
return $this;
} | php | public function addUrl(\Sulu\Bundle\ContactBundle\Entity\Url $urls)
{
$this->urls[] = $urls;
return $this;
} | [
"public",
"function",
"addUrl",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ContactBundle",
"\\",
"Entity",
"\\",
"Url",
"$",
"urls",
")",
"{",
"$",
"this",
"->",
"urls",
"[",
"]",
"=",
"$",
"urls",
";",
"return",
"$",
"this",
";",
"}"
] | Add urls.
@param \Sulu\Bundle\ContactBundle\Entity\Url $urls
@return UrlType | [
"Add",
"urls",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Entity/UrlType.php#L99-L104 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Entity/UrlType.php | UrlType.removeUrl | public function removeUrl(\Sulu\Bundle\ContactBundle\Entity\Url $urls)
{
$this->urls->removeElement($urls);
} | php | public function removeUrl(\Sulu\Bundle\ContactBundle\Entity\Url $urls)
{
$this->urls->removeElement($urls);
} | [
"public",
"function",
"removeUrl",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ContactBundle",
"\\",
"Entity",
"\\",
"Url",
"$",
"urls",
")",
"{",
"$",
"this",
"->",
"urls",
"->",
"removeElement",
"(",
"$",
"urls",
")",
";",
"}"
] | Remove urls.
@param \Sulu\Bundle\ContactBundle\Entity\Url $urls | [
"Remove",
"urls",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Entity/UrlType.php#L111-L114 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Search/EventSubscriber/StructureSubscriber.php | StructureSubscriber.indexDocumentAfterRemoveDraft | public function indexDocumentAfterRemoveDraft(RemoveDraftEvent $event)
{
$document = $event->getDocument();
if ($document instanceof WorkflowStageBehavior) {
// Set the workflowstage to test for indexing, because the wrong index will be updated otherwise
$document->setWorkflowStage(WorkflowStage::TEST);
}
$this->indexDocument($document);
if ($document instanceof WorkflowStageBehavior) {
// Reset the workflowstage to published, because after removing a draft the document will always be in
// the published state
$document->setWorkflowStage(WorkflowStage::PUBLISHED);
}
} | php | public function indexDocumentAfterRemoveDraft(RemoveDraftEvent $event)
{
$document = $event->getDocument();
if ($document instanceof WorkflowStageBehavior) {
// Set the workflowstage to test for indexing, because the wrong index will be updated otherwise
$document->setWorkflowStage(WorkflowStage::TEST);
}
$this->indexDocument($document);
if ($document instanceof WorkflowStageBehavior) {
// Reset the workflowstage to published, because after removing a draft the document will always be in
// the published state
$document->setWorkflowStage(WorkflowStage::PUBLISHED);
}
} | [
"public",
"function",
"indexDocumentAfterRemoveDraft",
"(",
"RemoveDraftEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"$",
"document",
"instanceof",
"WorkflowStageBehavior",
")",
"{",
"// Set the workflowstage to test for indexing, because the wrong index will be updated otherwise",
"$",
"document",
"->",
"setWorkflowStage",
"(",
"WorkflowStage",
"::",
"TEST",
")",
";",
"}",
"$",
"this",
"->",
"indexDocument",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"document",
"instanceof",
"WorkflowStageBehavior",
")",
"{",
"// Reset the workflowstage to published, because after removing a draft the document will always be in",
"// the published state",
"$",
"document",
"->",
"setWorkflowStage",
"(",
"WorkflowStage",
"::",
"PUBLISHED",
")",
";",
"}",
"}"
] | Indexes a document after its draft have been removed.
@param RemoveDraftEvent $event | [
"Indexes",
"a",
"document",
"after",
"its",
"draft",
"have",
"been",
"removed",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Search/EventSubscriber/StructureSubscriber.php#L81-L97 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Search/EventSubscriber/StructureSubscriber.php | StructureSubscriber.indexDocument | private function indexDocument($document)
{
if (!$document instanceof StructureBehavior) {
return;
}
if ($document instanceof SecurityBehavior && !empty($document->getPermissions())) {
return;
}
$this->searchManager->index($document);
} | php | private function indexDocument($document)
{
if (!$document instanceof StructureBehavior) {
return;
}
if ($document instanceof SecurityBehavior && !empty($document->getPermissions())) {
return;
}
$this->searchManager->index($document);
} | [
"private",
"function",
"indexDocument",
"(",
"$",
"document",
")",
"{",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"StructureBehavior",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"document",
"instanceof",
"SecurityBehavior",
"&&",
"!",
"empty",
"(",
"$",
"document",
"->",
"getPermissions",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"searchManager",
"->",
"index",
"(",
"$",
"document",
")",
";",
"}"
] | Index document in search implementation depending
on the publish state.
@param object $document | [
"Index",
"document",
"in",
"search",
"implementation",
"depending",
"on",
"the",
"publish",
"state",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Search/EventSubscriber/StructureSubscriber.php#L105-L116 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Search/EventSubscriber/StructureSubscriber.php | StructureSubscriber.deindexRemovedDocument | public function deindexRemovedDocument(RemoveEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof StructureBehavior) {
return;
}
if (!$document instanceof WorkflowStageBehavior) {
$this->searchManager->deindex($document);
} else {
$workflowStage = $document->getWorkflowStage();
foreach (WorkflowStage::$stages as $stage) {
$document->setWorkflowStage($stage);
$this->searchManager->deindex($document);
}
$document->setWorkflowStage($workflowStage);
}
} | php | public function deindexRemovedDocument(RemoveEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof StructureBehavior) {
return;
}
if (!$document instanceof WorkflowStageBehavior) {
$this->searchManager->deindex($document);
} else {
$workflowStage = $document->getWorkflowStage();
foreach (WorkflowStage::$stages as $stage) {
$document->setWorkflowStage($stage);
$this->searchManager->deindex($document);
}
$document->setWorkflowStage($workflowStage);
}
} | [
"public",
"function",
"deindexRemovedDocument",
"(",
"RemoveEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"StructureBehavior",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"WorkflowStageBehavior",
")",
"{",
"$",
"this",
"->",
"searchManager",
"->",
"deindex",
"(",
"$",
"document",
")",
";",
"}",
"else",
"{",
"$",
"workflowStage",
"=",
"$",
"document",
"->",
"getWorkflowStage",
"(",
")",
";",
"foreach",
"(",
"WorkflowStage",
"::",
"$",
"stages",
"as",
"$",
"stage",
")",
"{",
"$",
"document",
"->",
"setWorkflowStage",
"(",
"$",
"stage",
")",
";",
"$",
"this",
"->",
"searchManager",
"->",
"deindex",
"(",
"$",
"document",
")",
";",
"}",
"$",
"document",
"->",
"setWorkflowStage",
"(",
"$",
"workflowStage",
")",
";",
"}",
"}"
] | Schedules a document to be deindexed.
@param RemoveEvent $event | [
"Schedules",
"a",
"document",
"to",
"be",
"deindexed",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Search/EventSubscriber/StructureSubscriber.php#L123-L143 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Search/EventSubscriber/StructureSubscriber.php | StructureSubscriber.deindexUnpublishedDocument | public function deindexUnpublishedDocument(UnpublishEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof StructureBehavior) {
return;
}
$this->searchManager->deindex($document);
} | php | public function deindexUnpublishedDocument(UnpublishEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof StructureBehavior) {
return;
}
$this->searchManager->deindex($document);
} | [
"public",
"function",
"deindexUnpublishedDocument",
"(",
"UnpublishEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"StructureBehavior",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"searchManager",
"->",
"deindex",
"(",
"$",
"document",
")",
";",
"}"
] | Deindexes the document from the search index for the website.
@param UnpublishEvent $event | [
"Deindexes",
"the",
"document",
"from",
"the",
"search",
"index",
"for",
"the",
"website",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Search/EventSubscriber/StructureSubscriber.php#L150-L159 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/RedirectController.php | RedirectController.redirectWebspaceAction | public function redirectWebspaceAction(Request $request)
{
@trigger_error(__METHOD__ . '() is deprecated since version 1.6 and will be removed in 2.0. Replaced by ExceptionListener::redirectPartialMatch.', E_USER_DEPRECATED);
$url = $this->resolveRedirectUrl(
$request->get('redirect'),
$request->getUri(),
$request->get('_sulu')->getAttribute('resourceLocatorPrefix')
);
return new RedirectResponse($url, 301, ['Cache-Control' => 'private']);
} | php | public function redirectWebspaceAction(Request $request)
{
@trigger_error(__METHOD__ . '() is deprecated since version 1.6 and will be removed in 2.0. Replaced by ExceptionListener::redirectPartialMatch.', E_USER_DEPRECATED);
$url = $this->resolveRedirectUrl(
$request->get('redirect'),
$request->getUri(),
$request->get('_sulu')->getAttribute('resourceLocatorPrefix')
);
return new RedirectResponse($url, 301, ['Cache-Control' => 'private']);
} | [
"public",
"function",
"redirectWebspaceAction",
"(",
"Request",
"$",
"request",
")",
"{",
"@",
"trigger_error",
"(",
"__METHOD__",
".",
"'() is deprecated since version 1.6 and will be removed in 2.0. Replaced by ExceptionListener::redirectPartialMatch.'",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"resolveRedirectUrl",
"(",
"$",
"request",
"->",
"get",
"(",
"'redirect'",
")",
",",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"$",
"request",
"->",
"get",
"(",
"'_sulu'",
")",
"->",
"getAttribute",
"(",
"'resourceLocatorPrefix'",
")",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"url",
",",
"301",
",",
"[",
"'Cache-Control'",
"=>",
"'private'",
"]",
")",
";",
"}"
] | Creates a redirect for configured webspaces.
@param Request $request
@return RedirectResponse
@deprecated since 1.6 will be removed with 2.0. Replaced by ExceptionListener::redirectPartialMatch | [
"Creates",
"a",
"redirect",
"for",
"configured",
"webspaces",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/RedirectController.php#L34-L45 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/RedirectController.php | RedirectController.redirectToRouteAction | public function redirectToRouteAction(Request $request, $route, $permanent = false)
{
if ('' === $route) {
throw new HttpException($permanent ? 410 : 404);
}
$attributes = array_merge($request->attributes->get('_route_params'), $request->query->all());
unset($attributes['route'], $attributes['permanent']);
return new RedirectResponse(
$this->container->get('router')->generate($route, $attributes, UrlGeneratorInterface::ABSOLUTE_URL),
$permanent ? 301 : 302,
['Cache-Control' => 'private']
);
} | php | public function redirectToRouteAction(Request $request, $route, $permanent = false)
{
if ('' === $route) {
throw new HttpException($permanent ? 410 : 404);
}
$attributes = array_merge($request->attributes->get('_route_params'), $request->query->all());
unset($attributes['route'], $attributes['permanent']);
return new RedirectResponse(
$this->container->get('router')->generate($route, $attributes, UrlGeneratorInterface::ABSOLUTE_URL),
$permanent ? 301 : 302,
['Cache-Control' => 'private']
);
} | [
"public",
"function",
"redirectToRouteAction",
"(",
"Request",
"$",
"request",
",",
"$",
"route",
",",
"$",
"permanent",
"=",
"false",
")",
"{",
"if",
"(",
"''",
"===",
"$",
"route",
")",
"{",
"throw",
"new",
"HttpException",
"(",
"$",
"permanent",
"?",
"410",
":",
"404",
")",
";",
"}",
"$",
"attributes",
"=",
"array_merge",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_route_params'",
")",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
")",
";",
"unset",
"(",
"$",
"attributes",
"[",
"'route'",
"]",
",",
"$",
"attributes",
"[",
"'permanent'",
"]",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'router'",
")",
"->",
"generate",
"(",
"$",
"route",
",",
"$",
"attributes",
",",
"UrlGeneratorInterface",
"::",
"ABSOLUTE_URL",
")",
",",
"$",
"permanent",
"?",
"301",
":",
"302",
",",
"[",
"'Cache-Control'",
"=>",
"'private'",
"]",
")",
";",
"}"
] | Create a redirect response which uses a route to generate redirect.
@param Request $request
@param string $route
@param bool $permanent
@return RedirectResponse | [
"Create",
"a",
"redirect",
"response",
"which",
"uses",
"a",
"route",
"to",
"generate",
"redirect",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/RedirectController.php#L68-L82 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Collection/Manager/CollectionManager.php | CollectionManager.setBreadcrumbToCollection | protected function setBreadcrumbToCollection(Collection $collection, $locale, $breadcrumbEntities)
{
$breadcrumbApiEntities = [];
foreach ($breadcrumbEntities as $entity) {
$breadcrumbApiEntities[] = $this->getApiEntity($entity, $locale);
}
$collection->setBreadcrumb($breadcrumbApiEntities);
return $collection;
} | php | protected function setBreadcrumbToCollection(Collection $collection, $locale, $breadcrumbEntities)
{
$breadcrumbApiEntities = [];
foreach ($breadcrumbEntities as $entity) {
$breadcrumbApiEntities[] = $this->getApiEntity($entity, $locale);
}
$collection->setBreadcrumb($breadcrumbApiEntities);
return $collection;
} | [
"protected",
"function",
"setBreadcrumbToCollection",
"(",
"Collection",
"$",
"collection",
",",
"$",
"locale",
",",
"$",
"breadcrumbEntities",
")",
"{",
"$",
"breadcrumbApiEntities",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"breadcrumbEntities",
"as",
"$",
"entity",
")",
"{",
"$",
"breadcrumbApiEntities",
"[",
"]",
"=",
"$",
"this",
"->",
"getApiEntity",
"(",
"$",
"entity",
",",
"$",
"locale",
")",
";",
"}",
"$",
"collection",
"->",
"setBreadcrumb",
"(",
"$",
"breadcrumbApiEntities",
")",
";",
"return",
"$",
"collection",
";",
"}"
] | Sets the given breadcrumb entities as breadcrum on the given collection.
@return Collection | [
"Sets",
"the",
"given",
"breadcrumb",
"entities",
"as",
"breadcrum",
"on",
"the",
"given",
"collection",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Collection/Manager/CollectionManager.php#L505-L514 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Collection/Manager/CollectionManager.php | CollectionManager.getApiEntity | protected function getApiEntity(CollectionInterface $entity, $locale, $entities = null, $breadcrumbEntities = null)
{
$apiEntity = new Collection($entity, $locale);
$children = null;
if (null !== $entities) {
$children = [];
foreach ($entities as $possibleChild) {
if (null !== ($parent = $possibleChild->getParent()) && $parent->getId() === $entity->getId()) {
$children[] = $this->getApiEntity($possibleChild, $locale, $entities);
}
}
}
$apiEntity->setChildren($children);
if (null !== $entity->getParent()) {
$apiEntity->setParent($this->getApiEntity($entity->getParent(), $locale));
}
if (null !== $breadcrumbEntities) {
$this->setBreadcrumbToCollection($apiEntity, $locale, $breadcrumbEntities);
}
if ($entity && $entity->getId()) {
$apiEntity->setMediaCount($this->collectionRepository->countMedia($entity));
$apiEntity->setSubCollectionCount($this->collectionRepository->countSubCollections($entity));
}
return $this->addPreview($apiEntity);
} | php | protected function getApiEntity(CollectionInterface $entity, $locale, $entities = null, $breadcrumbEntities = null)
{
$apiEntity = new Collection($entity, $locale);
$children = null;
if (null !== $entities) {
$children = [];
foreach ($entities as $possibleChild) {
if (null !== ($parent = $possibleChild->getParent()) && $parent->getId() === $entity->getId()) {
$children[] = $this->getApiEntity($possibleChild, $locale, $entities);
}
}
}
$apiEntity->setChildren($children);
if (null !== $entity->getParent()) {
$apiEntity->setParent($this->getApiEntity($entity->getParent(), $locale));
}
if (null !== $breadcrumbEntities) {
$this->setBreadcrumbToCollection($apiEntity, $locale, $breadcrumbEntities);
}
if ($entity && $entity->getId()) {
$apiEntity->setMediaCount($this->collectionRepository->countMedia($entity));
$apiEntity->setSubCollectionCount($this->collectionRepository->countSubCollections($entity));
}
return $this->addPreview($apiEntity);
} | [
"protected",
"function",
"getApiEntity",
"(",
"CollectionInterface",
"$",
"entity",
",",
"$",
"locale",
",",
"$",
"entities",
"=",
"null",
",",
"$",
"breadcrumbEntities",
"=",
"null",
")",
"{",
"$",
"apiEntity",
"=",
"new",
"Collection",
"(",
"$",
"entity",
",",
"$",
"locale",
")",
";",
"$",
"children",
"=",
"null",
";",
"if",
"(",
"null",
"!==",
"$",
"entities",
")",
"{",
"$",
"children",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"possibleChild",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"parent",
"=",
"$",
"possibleChild",
"->",
"getParent",
"(",
")",
")",
"&&",
"$",
"parent",
"->",
"getId",
"(",
")",
"===",
"$",
"entity",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"children",
"[",
"]",
"=",
"$",
"this",
"->",
"getApiEntity",
"(",
"$",
"possibleChild",
",",
"$",
"locale",
",",
"$",
"entities",
")",
";",
"}",
"}",
"}",
"$",
"apiEntity",
"->",
"setChildren",
"(",
"$",
"children",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"entity",
"->",
"getParent",
"(",
")",
")",
"{",
"$",
"apiEntity",
"->",
"setParent",
"(",
"$",
"this",
"->",
"getApiEntity",
"(",
"$",
"entity",
"->",
"getParent",
"(",
")",
",",
"$",
"locale",
")",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"breadcrumbEntities",
")",
"{",
"$",
"this",
"->",
"setBreadcrumbToCollection",
"(",
"$",
"apiEntity",
",",
"$",
"locale",
",",
"$",
"breadcrumbEntities",
")",
";",
"}",
"if",
"(",
"$",
"entity",
"&&",
"$",
"entity",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"apiEntity",
"->",
"setMediaCount",
"(",
"$",
"this",
"->",
"collectionRepository",
"->",
"countMedia",
"(",
"$",
"entity",
")",
")",
";",
"$",
"apiEntity",
"->",
"setSubCollectionCount",
"(",
"$",
"this",
"->",
"collectionRepository",
"->",
"countSubCollections",
"(",
"$",
"entity",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"addPreview",
"(",
"$",
"apiEntity",
")",
";",
"}"
] | Prepare an api entity.
@param CollectionInterface $entity
@param string $locale
@param CollectionEntity[] $entities nested set
@param array $breadcrumbEntities
@return Collection | [
"Prepare",
"an",
"api",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Collection/Manager/CollectionManager.php#L682-L712 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Collection/Manager/CollectionManager.php | CollectionManager.getCurrentUser | protected function getCurrentUser()
{
if ($this->tokenStorage && ($token = $this->tokenStorage->getToken())) {
$user = $token->getUser();
if ($user instanceof UserInterface) {
return $user;
}
}
return;
} | php | protected function getCurrentUser()
{
if ($this->tokenStorage && ($token = $this->tokenStorage->getToken())) {
$user = $token->getUser();
if ($user instanceof UserInterface) {
return $user;
}
}
return;
} | [
"protected",
"function",
"getCurrentUser",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"tokenStorage",
"&&",
"(",
"$",
"token",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
")",
")",
"{",
"$",
"user",
"=",
"$",
"token",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"$",
"user",
"instanceof",
"UserInterface",
")",
"{",
"return",
"$",
"user",
";",
"}",
"}",
"return",
";",
"}"
] | Returns the current user from the token storage.
@return UserInterface|null | [
"Returns",
"the",
"current",
"user",
"from",
"the",
"token",
"storage",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Collection/Manager/CollectionManager.php#L719-L730 | train |
sulu/sulu | src/Sulu/Component/Util/XmlUtil.php | XmlUtil.getValueFromXPath | public static function getValueFromXPath($path, \DOMXPath $xpath, \DomNode $context = null, $default = null)
{
$result = $xpath->query($path, $context);
if (0 === $result->length) {
return $default;
}
$item = $result->item(0);
if (null === $item) {
return $default;
}
return $item->nodeValue;
} | php | public static function getValueFromXPath($path, \DOMXPath $xpath, \DomNode $context = null, $default = null)
{
$result = $xpath->query($path, $context);
if (0 === $result->length) {
return $default;
}
$item = $result->item(0);
if (null === $item) {
return $default;
}
return $item->nodeValue;
} | [
"public",
"static",
"function",
"getValueFromXPath",
"(",
"$",
"path",
",",
"\\",
"DOMXPath",
"$",
"xpath",
",",
"\\",
"DomNode",
"$",
"context",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"xpath",
"->",
"query",
"(",
"$",
"path",
",",
"$",
"context",
")",
";",
"if",
"(",
"0",
"===",
"$",
"result",
"->",
"length",
")",
"{",
"return",
"$",
"default",
";",
"}",
"$",
"item",
"=",
"$",
"result",
"->",
"item",
"(",
"0",
")",
";",
"if",
"(",
"null",
"===",
"$",
"item",
")",
"{",
"return",
"$",
"default",
";",
"}",
"return",
"$",
"item",
"->",
"nodeValue",
";",
"}"
] | Returns value of path.
@param string $path
@param \DOMXPath $xpath
@param \DomNode $context
@param mixed $default
@return bool|null|string|mixed | [
"Returns",
"value",
"of",
"path",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Util/XmlUtil.php#L29-L42 | train |
sulu/sulu | src/Sulu/Component/Util/XmlUtil.php | XmlUtil.getBooleanValueFromXPath | public static function getBooleanValueFromXPath($path, \DOMXPath $xpath, \DomNode $context = null, $default = null)
{
$value = self::getValueFromXPath($path, $xpath, $context, $default);
if (null === $value) {
return;
}
return 'true' === $value || true === $value;
} | php | public static function getBooleanValueFromXPath($path, \DOMXPath $xpath, \DomNode $context = null, $default = null)
{
$value = self::getValueFromXPath($path, $xpath, $context, $default);
if (null === $value) {
return;
}
return 'true' === $value || true === $value;
} | [
"public",
"static",
"function",
"getBooleanValueFromXPath",
"(",
"$",
"path",
",",
"\\",
"DOMXPath",
"$",
"xpath",
",",
"\\",
"DomNode",
"$",
"context",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"self",
"::",
"getValueFromXPath",
"(",
"$",
"path",
",",
"$",
"xpath",
",",
"$",
"context",
",",
"$",
"default",
")",
";",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"return",
";",
"}",
"return",
"'true'",
"===",
"$",
"value",
"||",
"true",
"===",
"$",
"value",
";",
"}"
] | Returns boolean value of path.
@param string $path
@param \DOMXPath $xpath
@param \DomNode $context
@param mixed $default
@return bool|null|string|mixed | [
"Returns",
"boolean",
"value",
"of",
"path",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Util/XmlUtil.php#L54-L63 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Twig/Seo/SeoTwigExtension.php | SeoTwigExtension.renderSeoTags | public function renderSeoTags(
\Twig_Environment $twig,
array $seoExtension,
array $content,
array $urls,
$shadowBaseLocale
) {
$template = 'SuluWebsiteBundle:Extension:seo.html.twig';
@trigger_error(sprintf(
'This twig extension is deprecated and should not be used anymore, include the "%s".',
$template
));
$defaultLocale = null;
$portal = $this->requestAnalyzer->getPortal();
if ($portal) {
$defaultLocale = $portal->getXDefaultLocalization()->getLocale();
}
return $twig->render(
$template,
[
'seo' => $seoExtension,
'content' => $content,
'urls' => $urls,
'defaultLocale' => $defaultLocale,
'shadowBaseLocale' => $shadowBaseLocale,
]
);
} | php | public function renderSeoTags(
\Twig_Environment $twig,
array $seoExtension,
array $content,
array $urls,
$shadowBaseLocale
) {
$template = 'SuluWebsiteBundle:Extension:seo.html.twig';
@trigger_error(sprintf(
'This twig extension is deprecated and should not be used anymore, include the "%s".',
$template
));
$defaultLocale = null;
$portal = $this->requestAnalyzer->getPortal();
if ($portal) {
$defaultLocale = $portal->getXDefaultLocalization()->getLocale();
}
return $twig->render(
$template,
[
'seo' => $seoExtension,
'content' => $content,
'urls' => $urls,
'defaultLocale' => $defaultLocale,
'shadowBaseLocale' => $shadowBaseLocale,
]
);
} | [
"public",
"function",
"renderSeoTags",
"(",
"\\",
"Twig_Environment",
"$",
"twig",
",",
"array",
"$",
"seoExtension",
",",
"array",
"$",
"content",
",",
"array",
"$",
"urls",
",",
"$",
"shadowBaseLocale",
")",
"{",
"$",
"template",
"=",
"'SuluWebsiteBundle:Extension:seo.html.twig'",
";",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'This twig extension is deprecated and should not be used anymore, include the \"%s\".'",
",",
"$",
"template",
")",
")",
";",
"$",
"defaultLocale",
"=",
"null",
";",
"$",
"portal",
"=",
"$",
"this",
"->",
"requestAnalyzer",
"->",
"getPortal",
"(",
")",
";",
"if",
"(",
"$",
"portal",
")",
"{",
"$",
"defaultLocale",
"=",
"$",
"portal",
"->",
"getXDefaultLocalization",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"}",
"return",
"$",
"twig",
"->",
"render",
"(",
"$",
"template",
",",
"[",
"'seo'",
"=>",
"$",
"seoExtension",
",",
"'content'",
"=>",
"$",
"content",
",",
"'urls'",
"=>",
"$",
"urls",
",",
"'defaultLocale'",
"=>",
"$",
"defaultLocale",
",",
"'shadowBaseLocale'",
"=>",
"$",
"shadowBaseLocale",
",",
"]",
")",
";",
"}"
] | Renders the correct title of the current page. The correct title is either the title provided by the SEO
extension, or the title of the content, if the SEO extension does not provide one.
@deprecated use the twig include function to render the seo | [
"Renders",
"the",
"correct",
"title",
"of",
"the",
"current",
"page",
".",
"The",
"correct",
"title",
"is",
"either",
"the",
"title",
"provided",
"by",
"the",
"SEO",
"extension",
"or",
"the",
"title",
"of",
"the",
"content",
"if",
"the",
"SEO",
"extension",
"does",
"not",
"provide",
"one",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Twig/Seo/SeoTwigExtension.php#L74-L104 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Media/ImageConverter/Scaler/Scaler.php | Scaler.getHeightWidth | private function getHeightWidth($x, $y, $retina, $forceRatio, $size, $mode)
{
$newWidth = $x;
$newHeight = $y;
// retina x2
if ($retina) {
$newWidth = $x * 2;
$newHeight = $y * 2;
}
// calculate height when not set
if (!$newHeight) {
$newHeight = $size->getHeight() / $size->getWidth() * $newWidth;
}
// calculate width when not set
if (!$newWidth) {
$newWidth = $size->getWidth() / $size->getHeight() * $newHeight;
}
// if image is smaller keep ratio
// e.g. when a square image is requested (200x200) and the original image is smaller (150x100)
// it still returns a squared image (100x100)
if (ImageInterface::THUMBNAIL_OUTBOUND === $mode && $forceRatio) {
if ($newWidth > $size->getWidth()) {
list($newHeight, $newWidth) = $this->getSizeInSameRatio(
$newHeight,
$newWidth,
$size->getWidth()
);
}
if ($newHeight > $size->getHeight()) {
list($newWidth, $newHeight) = $this->getSizeInSameRatio(
$newWidth,
$newHeight,
$size->getHeight()
);
}
}
return [$newWidth, $newHeight];
} | php | private function getHeightWidth($x, $y, $retina, $forceRatio, $size, $mode)
{
$newWidth = $x;
$newHeight = $y;
// retina x2
if ($retina) {
$newWidth = $x * 2;
$newHeight = $y * 2;
}
// calculate height when not set
if (!$newHeight) {
$newHeight = $size->getHeight() / $size->getWidth() * $newWidth;
}
// calculate width when not set
if (!$newWidth) {
$newWidth = $size->getWidth() / $size->getHeight() * $newHeight;
}
// if image is smaller keep ratio
// e.g. when a square image is requested (200x200) and the original image is smaller (150x100)
// it still returns a squared image (100x100)
if (ImageInterface::THUMBNAIL_OUTBOUND === $mode && $forceRatio) {
if ($newWidth > $size->getWidth()) {
list($newHeight, $newWidth) = $this->getSizeInSameRatio(
$newHeight,
$newWidth,
$size->getWidth()
);
}
if ($newHeight > $size->getHeight()) {
list($newWidth, $newHeight) = $this->getSizeInSameRatio(
$newWidth,
$newHeight,
$size->getHeight()
);
}
}
return [$newWidth, $newHeight];
} | [
"private",
"function",
"getHeightWidth",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"retina",
",",
"$",
"forceRatio",
",",
"$",
"size",
",",
"$",
"mode",
")",
"{",
"$",
"newWidth",
"=",
"$",
"x",
";",
"$",
"newHeight",
"=",
"$",
"y",
";",
"// retina x2",
"if",
"(",
"$",
"retina",
")",
"{",
"$",
"newWidth",
"=",
"$",
"x",
"*",
"2",
";",
"$",
"newHeight",
"=",
"$",
"y",
"*",
"2",
";",
"}",
"// calculate height when not set",
"if",
"(",
"!",
"$",
"newHeight",
")",
"{",
"$",
"newHeight",
"=",
"$",
"size",
"->",
"getHeight",
"(",
")",
"/",
"$",
"size",
"->",
"getWidth",
"(",
")",
"*",
"$",
"newWidth",
";",
"}",
"// calculate width when not set",
"if",
"(",
"!",
"$",
"newWidth",
")",
"{",
"$",
"newWidth",
"=",
"$",
"size",
"->",
"getWidth",
"(",
")",
"/",
"$",
"size",
"->",
"getHeight",
"(",
")",
"*",
"$",
"newHeight",
";",
"}",
"// if image is smaller keep ratio",
"// e.g. when a square image is requested (200x200) and the original image is smaller (150x100)",
"// it still returns a squared image (100x100)",
"if",
"(",
"ImageInterface",
"::",
"THUMBNAIL_OUTBOUND",
"===",
"$",
"mode",
"&&",
"$",
"forceRatio",
")",
"{",
"if",
"(",
"$",
"newWidth",
">",
"$",
"size",
"->",
"getWidth",
"(",
")",
")",
"{",
"list",
"(",
"$",
"newHeight",
",",
"$",
"newWidth",
")",
"=",
"$",
"this",
"->",
"getSizeInSameRatio",
"(",
"$",
"newHeight",
",",
"$",
"newWidth",
",",
"$",
"size",
"->",
"getWidth",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"newHeight",
">",
"$",
"size",
"->",
"getHeight",
"(",
")",
")",
"{",
"list",
"(",
"$",
"newWidth",
",",
"$",
"newHeight",
")",
"=",
"$",
"this",
"->",
"getSizeInSameRatio",
"(",
"$",
"newWidth",
",",
"$",
"newHeight",
",",
"$",
"size",
"->",
"getHeight",
"(",
")",
")",
";",
"}",
"}",
"return",
"[",
"$",
"newWidth",
",",
"$",
"newHeight",
"]",
";",
"}"
] | Gets the height and width of the resulting image, according to the given parameters.
@param $x
@param $y
@param $retina
@param $forceRatio
@param $size
@param $mode
@return array | [
"Gets",
"the",
"height",
"and",
"width",
"of",
"the",
"resulting",
"image",
"according",
"to",
"the",
"given",
"parameters",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Media/ImageConverter/Scaler/Scaler.php#L57-L100 | train |
sulu/sulu | src/Sulu/Bundle/CustomUrlBundle/Request/CustomUrlRequestProcessor.php | CustomUrlRequestProcessor.matchCustomUrl | private function matchCustomUrl($url, PortalInformation $portalInformation, Request $request)
{
$webspace = $portalInformation->getWebspace();
$routeDocument = $this->customUrlManager->findRouteByUrl(
rawurldecode($url),
$webspace->getKey()
);
if (!$routeDocument) {
return [];
} elseif ($routeDocument->isHistory()) {
// redirect happen => no portal is needed
return ['customUrlRoute' => $routeDocument];
}
$customUrlDocument = $this->customUrlManager->findByUrl(
rawurldecode($url),
$webspace->getKey(),
$routeDocument->getTargetDocument()->getTargetLocale()
);
if (null === $customUrlDocument
|| false === $customUrlDocument->isPublished()
|| null === $customUrlDocument->getTargetDocument()
|| WorkflowStage::PUBLISHED !== $customUrlDocument->getTargetDocument()->getWorkflowStage()
) {
// error happen because this custom-url is not published => no portal is needed
return ['customUrlRoute' => $routeDocument, 'customUrl' => $customUrlDocument];
}
$localization = Localization::createFromString($customUrlDocument->getTargetLocale());
$portalInformations = $this->webspaceManager->findPortalInformationsByWebspaceKeyAndLocale(
$portalInformation->getWebspace()->getKey(),
$localization->getLocale(),
$this->environment
);
if (0 === count($portalInformations)) {
return ['customUrlRoute' => $routeDocument, 'customUrl' => $customUrlDocument];
}
return [
'portalInformation' => $portalInformation,
'localization' => $localization,
'locale' => $localization->getLocale(),
'customUrlRoute' => $routeDocument,
'customUrl' => $customUrlDocument,
'urlExpression' => $this->generator->generate(
$customUrlDocument->getBaseDomain(),
$customUrlDocument->getDomainParts()
),
];
} | php | private function matchCustomUrl($url, PortalInformation $portalInformation, Request $request)
{
$webspace = $portalInformation->getWebspace();
$routeDocument = $this->customUrlManager->findRouteByUrl(
rawurldecode($url),
$webspace->getKey()
);
if (!$routeDocument) {
return [];
} elseif ($routeDocument->isHistory()) {
// redirect happen => no portal is needed
return ['customUrlRoute' => $routeDocument];
}
$customUrlDocument = $this->customUrlManager->findByUrl(
rawurldecode($url),
$webspace->getKey(),
$routeDocument->getTargetDocument()->getTargetLocale()
);
if (null === $customUrlDocument
|| false === $customUrlDocument->isPublished()
|| null === $customUrlDocument->getTargetDocument()
|| WorkflowStage::PUBLISHED !== $customUrlDocument->getTargetDocument()->getWorkflowStage()
) {
// error happen because this custom-url is not published => no portal is needed
return ['customUrlRoute' => $routeDocument, 'customUrl' => $customUrlDocument];
}
$localization = Localization::createFromString($customUrlDocument->getTargetLocale());
$portalInformations = $this->webspaceManager->findPortalInformationsByWebspaceKeyAndLocale(
$portalInformation->getWebspace()->getKey(),
$localization->getLocale(),
$this->environment
);
if (0 === count($portalInformations)) {
return ['customUrlRoute' => $routeDocument, 'customUrl' => $customUrlDocument];
}
return [
'portalInformation' => $portalInformation,
'localization' => $localization,
'locale' => $localization->getLocale(),
'customUrlRoute' => $routeDocument,
'customUrl' => $customUrlDocument,
'urlExpression' => $this->generator->generate(
$customUrlDocument->getBaseDomain(),
$customUrlDocument->getDomainParts()
),
];
} | [
"private",
"function",
"matchCustomUrl",
"(",
"$",
"url",
",",
"PortalInformation",
"$",
"portalInformation",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"webspace",
"=",
"$",
"portalInformation",
"->",
"getWebspace",
"(",
")",
";",
"$",
"routeDocument",
"=",
"$",
"this",
"->",
"customUrlManager",
"->",
"findRouteByUrl",
"(",
"rawurldecode",
"(",
"$",
"url",
")",
",",
"$",
"webspace",
"->",
"getKey",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"routeDocument",
")",
"{",
"return",
"[",
"]",
";",
"}",
"elseif",
"(",
"$",
"routeDocument",
"->",
"isHistory",
"(",
")",
")",
"{",
"// redirect happen => no portal is needed",
"return",
"[",
"'customUrlRoute'",
"=>",
"$",
"routeDocument",
"]",
";",
"}",
"$",
"customUrlDocument",
"=",
"$",
"this",
"->",
"customUrlManager",
"->",
"findByUrl",
"(",
"rawurldecode",
"(",
"$",
"url",
")",
",",
"$",
"webspace",
"->",
"getKey",
"(",
")",
",",
"$",
"routeDocument",
"->",
"getTargetDocument",
"(",
")",
"->",
"getTargetLocale",
"(",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"customUrlDocument",
"||",
"false",
"===",
"$",
"customUrlDocument",
"->",
"isPublished",
"(",
")",
"||",
"null",
"===",
"$",
"customUrlDocument",
"->",
"getTargetDocument",
"(",
")",
"||",
"WorkflowStage",
"::",
"PUBLISHED",
"!==",
"$",
"customUrlDocument",
"->",
"getTargetDocument",
"(",
")",
"->",
"getWorkflowStage",
"(",
")",
")",
"{",
"// error happen because this custom-url is not published => no portal is needed",
"return",
"[",
"'customUrlRoute'",
"=>",
"$",
"routeDocument",
",",
"'customUrl'",
"=>",
"$",
"customUrlDocument",
"]",
";",
"}",
"$",
"localization",
"=",
"Localization",
"::",
"createFromString",
"(",
"$",
"customUrlDocument",
"->",
"getTargetLocale",
"(",
")",
")",
";",
"$",
"portalInformations",
"=",
"$",
"this",
"->",
"webspaceManager",
"->",
"findPortalInformationsByWebspaceKeyAndLocale",
"(",
"$",
"portalInformation",
"->",
"getWebspace",
"(",
")",
"->",
"getKey",
"(",
")",
",",
"$",
"localization",
"->",
"getLocale",
"(",
")",
",",
"$",
"this",
"->",
"environment",
")",
";",
"if",
"(",
"0",
"===",
"count",
"(",
"$",
"portalInformations",
")",
")",
"{",
"return",
"[",
"'customUrlRoute'",
"=>",
"$",
"routeDocument",
",",
"'customUrl'",
"=>",
"$",
"customUrlDocument",
"]",
";",
"}",
"return",
"[",
"'portalInformation'",
"=>",
"$",
"portalInformation",
",",
"'localization'",
"=>",
"$",
"localization",
",",
"'locale'",
"=>",
"$",
"localization",
"->",
"getLocale",
"(",
")",
",",
"'customUrlRoute'",
"=>",
"$",
"routeDocument",
",",
"'customUrl'",
"=>",
"$",
"customUrlDocument",
",",
"'urlExpression'",
"=>",
"$",
"this",
"->",
"generator",
"->",
"generate",
"(",
"$",
"customUrlDocument",
"->",
"getBaseDomain",
"(",
")",
",",
"$",
"customUrlDocument",
"->",
"getDomainParts",
"(",
")",
")",
",",
"]",
";",
"}"
] | Matches given url to portal-information.
@param string $url
@param PortalInformation $portalInformation
@param Request $request
@return array | [
"Matches",
"given",
"url",
"to",
"portal",
"-",
"information",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CustomUrlBundle/Request/CustomUrlRequestProcessor.php#L115-L168 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Media/FormatManager/FormatManager.php | FormatManager.checkMimeTypeSupported | private function checkMimeTypeSupported($mimeType)
{
foreach ($this->supportedMimeTypes as $supportedMimeType) {
if (fnmatch($supportedMimeType, $mimeType)) {
return true;
}
}
return false;
} | php | private function checkMimeTypeSupported($mimeType)
{
foreach ($this->supportedMimeTypes as $supportedMimeType) {
if (fnmatch($supportedMimeType, $mimeType)) {
return true;
}
}
return false;
} | [
"private",
"function",
"checkMimeTypeSupported",
"(",
"$",
"mimeType",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"supportedMimeTypes",
"as",
"$",
"supportedMimeType",
")",
"{",
"if",
"(",
"fnmatch",
"(",
"$",
"supportedMimeType",
",",
"$",
"mimeType",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if the given mime type is supported, otherwise false.
@param $mimeType
@return bool | [
"Returns",
"true",
"if",
"the",
"given",
"mime",
"type",
"is",
"supported",
"otherwise",
"false",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Media/FormatManager/FormatManager.php#L346-L355 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Entity/ContactLocale.php | ContactLocale.setContact | public function setContact(\Sulu\Bundle\ContactBundle\Entity\ContactInterface $contact)
{
$this->contact = $contact;
return $this;
} | php | public function setContact(\Sulu\Bundle\ContactBundle\Entity\ContactInterface $contact)
{
$this->contact = $contact;
return $this;
} | [
"public",
"function",
"setContact",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ContactBundle",
"\\",
"Entity",
"\\",
"ContactInterface",
"$",
"contact",
")",
"{",
"$",
"this",
"->",
"contact",
"=",
"$",
"contact",
";",
"return",
"$",
"this",
";",
"}"
] | Set contact.
@param \Sulu\Bundle\ContactBundle\Entity\ContactInterface $contact
@return ContactLocale | [
"Set",
"contact",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Entity/ContactLocale.php#L75-L80 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Entity/Email.php | Email.setEmailType | public function setEmailType(\Sulu\Bundle\ContactBundle\Entity\EmailType $emailType)
{
$this->emailType = $emailType;
return $this;
} | php | public function setEmailType(\Sulu\Bundle\ContactBundle\Entity\EmailType $emailType)
{
$this->emailType = $emailType;
return $this;
} | [
"public",
"function",
"setEmailType",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ContactBundle",
"\\",
"Entity",
"\\",
"EmailType",
"$",
"emailType",
")",
"{",
"$",
"this",
"->",
"emailType",
"=",
"$",
"emailType",
";",
"return",
"$",
"this",
";",
"}"
] | Set emailType.
@param \Sulu\Bundle\ContactBundle\Entity\EmailType $emailType
@return Email | [
"Set",
"emailType",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Entity/Email.php#L102-L107 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php | RegistratorSubscriber.handleDefaultLocale | public function handleDefaultLocale(HydrateEvent $event)
{
// set the default locale
if (null === $event->getLocale()) {
$event->setLocale($this->documentRegistry->getDefaultLocale());
}
} | php | public function handleDefaultLocale(HydrateEvent $event)
{
// set the default locale
if (null === $event->getLocale()) {
$event->setLocale($this->documentRegistry->getDefaultLocale());
}
} | [
"public",
"function",
"handleDefaultLocale",
"(",
"HydrateEvent",
"$",
"event",
")",
"{",
"// set the default locale",
"if",
"(",
"null",
"===",
"$",
"event",
"->",
"getLocale",
"(",
")",
")",
"{",
"$",
"event",
"->",
"setLocale",
"(",
"$",
"this",
"->",
"documentRegistry",
"->",
"getDefaultLocale",
"(",
")",
")",
";",
"}",
"}"
] | Set the default locale for the hydration request.
@param HydrateEvent $event | [
"Set",
"the",
"default",
"locale",
"for",
"the",
"hydration",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php#L88-L94 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php | RegistratorSubscriber.handleDocumentFromRegistry | public function handleDocumentFromRegistry(HydrateEvent $event)
{
if ($event->hasDocument()) {
return;
}
$node = $event->getNode();
if (!$this->documentRegistry->hasNode($node, $event->getLocale())) {
return;
}
$document = $this->documentRegistry->getDocumentForNode($node, $event->getLocale());
$event->setDocument($document);
$options = $event->getOptions();
// if reydration is not required (f.e. we just want to retrieve the
// current state of the document, no matter it's current state) stop
// further event propagation - we have the document now.
if (isset($options['rehydrate']) && false === $options['rehydrate']) {
$event->stopPropagation();
}
} | php | public function handleDocumentFromRegistry(HydrateEvent $event)
{
if ($event->hasDocument()) {
return;
}
$node = $event->getNode();
if (!$this->documentRegistry->hasNode($node, $event->getLocale())) {
return;
}
$document = $this->documentRegistry->getDocumentForNode($node, $event->getLocale());
$event->setDocument($document);
$options = $event->getOptions();
// if reydration is not required (f.e. we just want to retrieve the
// current state of the document, no matter it's current state) stop
// further event propagation - we have the document now.
if (isset($options['rehydrate']) && false === $options['rehydrate']) {
$event->stopPropagation();
}
} | [
"public",
"function",
"handleDocumentFromRegistry",
"(",
"HydrateEvent",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"hasDocument",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"node",
"=",
"$",
"event",
"->",
"getNode",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"documentRegistry",
"->",
"hasNode",
"(",
"$",
"node",
",",
"$",
"event",
"->",
"getLocale",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"document",
"=",
"$",
"this",
"->",
"documentRegistry",
"->",
"getDocumentForNode",
"(",
"$",
"node",
",",
"$",
"event",
"->",
"getLocale",
"(",
")",
")",
";",
"$",
"event",
"->",
"setDocument",
"(",
"$",
"document",
")",
";",
"$",
"options",
"=",
"$",
"event",
"->",
"getOptions",
"(",
")",
";",
"// if reydration is not required (f.e. we just want to retrieve the",
"// current state of the document, no matter it's current state) stop",
"// further event propagation - we have the document now.",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'rehydrate'",
"]",
")",
"&&",
"false",
"===",
"$",
"options",
"[",
"'rehydrate'",
"]",
")",
"{",
"$",
"event",
"->",
"stopPropagation",
"(",
")",
";",
"}",
"}"
] | If there is already a document for the node registered, use that.
@param HydrateEvent $event | [
"If",
"there",
"is",
"already",
"a",
"document",
"for",
"the",
"node",
"registered",
"use",
"that",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php#L101-L124 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php | RegistratorSubscriber.handleStopPropagationAndResetLocale | public function handleStopPropagationAndResetLocale(HydrateEvent $event)
{
if (!$event->hasDocument()) {
return;
}
$locale = $event->getLocale();
$document = $event->getDocument();
$options = $event->getOptions();
$originalLocale = $this->documentRegistry->getOriginalLocaleForDocument($document);
if (
(!isset($options['rehydrate']) || false === $options['rehydrate']) &&
(true === $this->documentRegistry->isHydrated($document) && $originalLocale === $locale)
) {
$event->stopPropagation();
}
} | php | public function handleStopPropagationAndResetLocale(HydrateEvent $event)
{
if (!$event->hasDocument()) {
return;
}
$locale = $event->getLocale();
$document = $event->getDocument();
$options = $event->getOptions();
$originalLocale = $this->documentRegistry->getOriginalLocaleForDocument($document);
if (
(!isset($options['rehydrate']) || false === $options['rehydrate']) &&
(true === $this->documentRegistry->isHydrated($document) && $originalLocale === $locale)
) {
$event->stopPropagation();
}
} | [
"public",
"function",
"handleStopPropagationAndResetLocale",
"(",
"HydrateEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"hasDocument",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"locale",
"=",
"$",
"event",
"->",
"getLocale",
"(",
")",
";",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"$",
"options",
"=",
"$",
"event",
"->",
"getOptions",
"(",
")",
";",
"$",
"originalLocale",
"=",
"$",
"this",
"->",
"documentRegistry",
"->",
"getOriginalLocaleForDocument",
"(",
"$",
"document",
")",
";",
"if",
"(",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'rehydrate'",
"]",
")",
"||",
"false",
"===",
"$",
"options",
"[",
"'rehydrate'",
"]",
")",
"&&",
"(",
"true",
"===",
"$",
"this",
"->",
"documentRegistry",
"->",
"isHydrated",
"(",
"$",
"document",
")",
"&&",
"$",
"originalLocale",
"===",
"$",
"locale",
")",
")",
"{",
"$",
"event",
"->",
"stopPropagation",
"(",
")",
";",
"}",
"}"
] | Stop propagation if the document is already loaded in the requested locale.
@param HydrateEvent $event | [
"Stop",
"propagation",
"if",
"the",
"document",
"is",
"already",
"loaded",
"in",
"the",
"requested",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php#L131-L148 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php | RegistratorSubscriber.handleNodeFromRegistry | public function handleNodeFromRegistry($event)
{
if ($event->hasNode()) {
return;
}
$document = $event->getDocument();
if (!$this->documentRegistry->hasDocument($document)) {
return;
}
$node = $this->documentRegistry->getNodeForDocument($document);
$event->setNode($node);
} | php | public function handleNodeFromRegistry($event)
{
if ($event->hasNode()) {
return;
}
$document = $event->getDocument();
if (!$this->documentRegistry->hasDocument($document)) {
return;
}
$node = $this->documentRegistry->getNodeForDocument($document);
$event->setNode($node);
} | [
"public",
"function",
"handleNodeFromRegistry",
"(",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"hasNode",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"documentRegistry",
"->",
"hasDocument",
"(",
"$",
"document",
")",
")",
"{",
"return",
";",
"}",
"$",
"node",
"=",
"$",
"this",
"->",
"documentRegistry",
"->",
"getNodeForDocument",
"(",
"$",
"document",
")",
";",
"$",
"event",
"->",
"setNode",
"(",
"$",
"node",
")",
";",
"}"
] | If the node for the persisted document is in the registry.
@param PersistEvent|ReorderEvent $event | [
"If",
"the",
"node",
"for",
"the",
"persisted",
"document",
"is",
"in",
"the",
"registry",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php#L179-L193 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php | RegistratorSubscriber.handleRemove | public function handleRemove(RemoveEvent $event)
{
$document = $event->getDocument();
$this->documentRegistry->deregisterDocument($document);
} | php | public function handleRemove(RemoveEvent $event)
{
$document = $event->getDocument();
$this->documentRegistry->deregisterDocument($document);
} | [
"public",
"function",
"handleRemove",
"(",
"RemoveEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"$",
"this",
"->",
"documentRegistry",
"->",
"deregisterDocument",
"(",
"$",
"document",
")",
";",
"}"
] | Deregister removed documents.
@param RemoveEvent $event | [
"Deregister",
"removed",
"documents",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php#L220-L224 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php | RegistratorSubscriber.handleRegister | private function handleRegister(AbstractMappingEvent $event)
{
$node = $event->getNode();
$locale = $event->getLocale();
if (!$this->documentRegistry->hasNode($node, $locale)) {
$this->documentRegistry->registerDocument($event->getDocument(), $node, $locale);
}
} | php | private function handleRegister(AbstractMappingEvent $event)
{
$node = $event->getNode();
$locale = $event->getLocale();
if (!$this->documentRegistry->hasNode($node, $locale)) {
$this->documentRegistry->registerDocument($event->getDocument(), $node, $locale);
}
} | [
"private",
"function",
"handleRegister",
"(",
"AbstractMappingEvent",
"$",
"event",
")",
"{",
"$",
"node",
"=",
"$",
"event",
"->",
"getNode",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"event",
"->",
"getLocale",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"documentRegistry",
"->",
"hasNode",
"(",
"$",
"node",
",",
"$",
"locale",
")",
")",
"{",
"$",
"this",
"->",
"documentRegistry",
"->",
"registerDocument",
"(",
"$",
"event",
"->",
"getDocument",
"(",
")",
",",
"$",
"node",
",",
"$",
"locale",
")",
";",
"}",
"}"
] | Register the document.
@param AbstractMappingEvent $event | [
"Register",
"the",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Core/RegistratorSubscriber.php#L241-L249 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Block/BlockProperty.php | BlockProperty.doSetValue | public function doSetValue($value)
{
$items = $value;
if ($value instanceof PropertyValue) {
$items = $value->getValue();
}
if (null == $items) {
return;
}
// check value for single value
if (array_keys($items) !== range(0, count($items) - 1)) {
$items = [$items];
}
$this->properties = [];
for ($i = 0; $i < count($items); ++$i) {
$item = $items[$i];
$type = $this->initProperties($i, $item['type']);
/** @var PropertyInterface $subProperty */
foreach ($type->getChildProperties() as $subProperty) {
if (!isset($item[$subProperty->getName()])) {
continue;
}
$subName = $subProperty->getName();
$subValue = $item[$subName];
if ($subValue instanceof PropertyValue) {
$subValueProperty = new PropertyValue($subName, $subValue);
$subProperty->setPropertyValue($subValueProperty);
$item[$subName] = $subValueProperty;
} else {
$subProperty->setValue($subValue);
}
}
$items[$i] = $item;
}
if ($value instanceof PropertyValue) {
$value->setValue($items);
}
} | php | public function doSetValue($value)
{
$items = $value;
if ($value instanceof PropertyValue) {
$items = $value->getValue();
}
if (null == $items) {
return;
}
// check value for single value
if (array_keys($items) !== range(0, count($items) - 1)) {
$items = [$items];
}
$this->properties = [];
for ($i = 0; $i < count($items); ++$i) {
$item = $items[$i];
$type = $this->initProperties($i, $item['type']);
/** @var PropertyInterface $subProperty */
foreach ($type->getChildProperties() as $subProperty) {
if (!isset($item[$subProperty->getName()])) {
continue;
}
$subName = $subProperty->getName();
$subValue = $item[$subName];
if ($subValue instanceof PropertyValue) {
$subValueProperty = new PropertyValue($subName, $subValue);
$subProperty->setPropertyValue($subValueProperty);
$item[$subName] = $subValueProperty;
} else {
$subProperty->setValue($subValue);
}
}
$items[$i] = $item;
}
if ($value instanceof PropertyValue) {
$value->setValue($items);
}
} | [
"public",
"function",
"doSetValue",
"(",
"$",
"value",
")",
"{",
"$",
"items",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"value",
"instanceof",
"PropertyValue",
")",
"{",
"$",
"items",
"=",
"$",
"value",
"->",
"getValue",
"(",
")",
";",
"}",
"if",
"(",
"null",
"==",
"$",
"items",
")",
"{",
"return",
";",
"}",
"// check value for single value",
"if",
"(",
"array_keys",
"(",
"$",
"items",
")",
"!==",
"range",
"(",
"0",
",",
"count",
"(",
"$",
"items",
")",
"-",
"1",
")",
")",
"{",
"$",
"items",
"=",
"[",
"$",
"items",
"]",
";",
"}",
"$",
"this",
"->",
"properties",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"items",
")",
";",
"++",
"$",
"i",
")",
"{",
"$",
"item",
"=",
"$",
"items",
"[",
"$",
"i",
"]",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"initProperties",
"(",
"$",
"i",
",",
"$",
"item",
"[",
"'type'",
"]",
")",
";",
"/** @var PropertyInterface $subProperty */",
"foreach",
"(",
"$",
"type",
"->",
"getChildProperties",
"(",
")",
"as",
"$",
"subProperty",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"$",
"subProperty",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"subName",
"=",
"$",
"subProperty",
"->",
"getName",
"(",
")",
";",
"$",
"subValue",
"=",
"$",
"item",
"[",
"$",
"subName",
"]",
";",
"if",
"(",
"$",
"subValue",
"instanceof",
"PropertyValue",
")",
"{",
"$",
"subValueProperty",
"=",
"new",
"PropertyValue",
"(",
"$",
"subName",
",",
"$",
"subValue",
")",
";",
"$",
"subProperty",
"->",
"setPropertyValue",
"(",
"$",
"subValueProperty",
")",
";",
"$",
"item",
"[",
"$",
"subName",
"]",
"=",
"$",
"subValueProperty",
";",
"}",
"else",
"{",
"$",
"subProperty",
"->",
"setValue",
"(",
"$",
"subValue",
")",
";",
"}",
"}",
"$",
"items",
"[",
"$",
"i",
"]",
"=",
"$",
"item",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"PropertyValue",
")",
"{",
"$",
"value",
"->",
"setValue",
"(",
"$",
"items",
")",
";",
"}",
"}"
] | Sub properties need to be referenced to the PropertyValue so
that the "real" property is updated.
TODO: This is very tedious code. It is important to factor this out. | [
"Sub",
"properties",
"need",
"to",
"be",
"referenced",
"to",
"the",
"PropertyValue",
"so",
"that",
"the",
"real",
"property",
"is",
"updated",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Block/BlockProperty.php#L196-L242 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Block/BlockProperty.php | BlockProperty.getValue | public function getValue()
{
// if size of children smaller than minimum
if (count($this->properties) < $this->getMinOccurs()) {
for ($i = count($this->properties); $i < $this->getMinOccurs(); ++$i) {
$this->initProperties($i, $this->getDefaultTypeName());
}
}
$data = [];
foreach ($this->properties as $type) {
$result = ['type' => $type->getName()];
foreach ($type->getChildProperties() as $property) {
$result[$property->getName()] = $property->getValue();
}
$data[] = $result;
}
return $data;
} | php | public function getValue()
{
// if size of children smaller than minimum
if (count($this->properties) < $this->getMinOccurs()) {
for ($i = count($this->properties); $i < $this->getMinOccurs(); ++$i) {
$this->initProperties($i, $this->getDefaultTypeName());
}
}
$data = [];
foreach ($this->properties as $type) {
$result = ['type' => $type->getName()];
foreach ($type->getChildProperties() as $property) {
$result[$property->getName()] = $property->getValue();
}
$data[] = $result;
}
return $data;
} | [
"public",
"function",
"getValue",
"(",
")",
"{",
"// if size of children smaller than minimum",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"properties",
")",
"<",
"$",
"this",
"->",
"getMinOccurs",
"(",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"this",
"->",
"properties",
")",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"getMinOccurs",
"(",
")",
";",
"++",
"$",
"i",
")",
"{",
"$",
"this",
"->",
"initProperties",
"(",
"$",
"i",
",",
"$",
"this",
"->",
"getDefaultTypeName",
"(",
")",
")",
";",
"}",
"}",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"properties",
"as",
"$",
"type",
")",
"{",
"$",
"result",
"=",
"[",
"'type'",
"=>",
"$",
"type",
"->",
"getName",
"(",
")",
"]",
";",
"foreach",
"(",
"$",
"type",
"->",
"getChildProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"$",
"result",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"property",
"->",
"getValue",
"(",
")",
";",
"}",
"$",
"data",
"[",
"]",
"=",
"$",
"result",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | get value of sub properties.
@return array|mixed | [
"get",
"value",
"of",
"sub",
"properties",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Block/BlockProperty.php#L249-L268 | train |
sulu/sulu | src/Sulu/Bundle/PersistenceBundle/DependencyInjection/PersistenceExtensionTrait.php | PersistenceExtensionTrait.defineRepositories | private function defineRepositories(array $objects, ContainerBuilder $container)
{
foreach ($objects as $object => $services) {
if (array_key_exists('model', $services)) {
$repositoryDefinition = $this->getRepositoryDefinition($object, $services, $container);
$container->setDefinition(
$this->getContainerKey('repository', $object),
$repositoryDefinition
)->setPublic(true);
}
}
} | php | private function defineRepositories(array $objects, ContainerBuilder $container)
{
foreach ($objects as $object => $services) {
if (array_key_exists('model', $services)) {
$repositoryDefinition = $this->getRepositoryDefinition($object, $services, $container);
$container->setDefinition(
$this->getContainerKey('repository', $object),
$repositoryDefinition
)->setPublic(true);
}
}
} | [
"private",
"function",
"defineRepositories",
"(",
"array",
"$",
"objects",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"object",
"=>",
"$",
"services",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'model'",
",",
"$",
"services",
")",
")",
"{",
"$",
"repositoryDefinition",
"=",
"$",
"this",
"->",
"getRepositoryDefinition",
"(",
"$",
"object",
",",
"$",
"services",
",",
"$",
"container",
")",
";",
"$",
"container",
"->",
"setDefinition",
"(",
"$",
"this",
"->",
"getContainerKey",
"(",
"'repository'",
",",
"$",
"object",
")",
",",
"$",
"repositoryDefinition",
")",
"->",
"setPublic",
"(",
"true",
")",
";",
"}",
"}",
"}"
] | Define repositories.
@param array $objects
@param ContainerBuilder $container | [
"Define",
"repositories",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PersistenceBundle/DependencyInjection/PersistenceExtensionTrait.php#L52-L64 | train |
sulu/sulu | src/Sulu/Bundle/PersistenceBundle/DependencyInjection/PersistenceExtensionTrait.php | PersistenceExtensionTrait.getRepositoryDefinition | private function getRepositoryDefinition($object, array $services, ContainerBuilder $container)
{
$repositoryKey = $this->getContainerKey('repository', $object, '.class');
// default repository
$repositoryClass = 'Sulu\Component\Persistence\Repository\ORM\EntityRepository';
if ($container->hasParameter($repositoryKey)) {
$repositoryClass = $container->getParameter($repositoryKey);
}
if (isset($services['repository'])) {
$repositoryClass = $services['repository'];
}
$definition = new Definition($repositoryClass);
$definition->setArguments([
new Reference($this->getEntityManagerServiceKey()),
$this->getClassMetadataDefinition($services['model']),
]);
return $definition;
} | php | private function getRepositoryDefinition($object, array $services, ContainerBuilder $container)
{
$repositoryKey = $this->getContainerKey('repository', $object, '.class');
// default repository
$repositoryClass = 'Sulu\Component\Persistence\Repository\ORM\EntityRepository';
if ($container->hasParameter($repositoryKey)) {
$repositoryClass = $container->getParameter($repositoryKey);
}
if (isset($services['repository'])) {
$repositoryClass = $services['repository'];
}
$definition = new Definition($repositoryClass);
$definition->setArguments([
new Reference($this->getEntityManagerServiceKey()),
$this->getClassMetadataDefinition($services['model']),
]);
return $definition;
} | [
"private",
"function",
"getRepositoryDefinition",
"(",
"$",
"object",
",",
"array",
"$",
"services",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"repositoryKey",
"=",
"$",
"this",
"->",
"getContainerKey",
"(",
"'repository'",
",",
"$",
"object",
",",
"'.class'",
")",
";",
"// default repository",
"$",
"repositoryClass",
"=",
"'Sulu\\Component\\Persistence\\Repository\\ORM\\EntityRepository'",
";",
"if",
"(",
"$",
"container",
"->",
"hasParameter",
"(",
"$",
"repositoryKey",
")",
")",
"{",
"$",
"repositoryClass",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"$",
"repositoryKey",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"services",
"[",
"'repository'",
"]",
")",
")",
"{",
"$",
"repositoryClass",
"=",
"$",
"services",
"[",
"'repository'",
"]",
";",
"}",
"$",
"definition",
"=",
"new",
"Definition",
"(",
"$",
"repositoryClass",
")",
";",
"$",
"definition",
"->",
"setArguments",
"(",
"[",
"new",
"Reference",
"(",
"$",
"this",
"->",
"getEntityManagerServiceKey",
"(",
")",
")",
",",
"$",
"this",
"->",
"getClassMetadataDefinition",
"(",
"$",
"services",
"[",
"'model'",
"]",
")",
",",
"]",
")",
";",
"return",
"$",
"definition",
";",
"}"
] | Get the repository service definition.
@param string $object
@param array $services
@param ContainerBuilder $container
@return Definition | [
"Get",
"the",
"repository",
"service",
"definition",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PersistenceBundle/DependencyInjection/PersistenceExtensionTrait.php#L75-L97 | train |
sulu/sulu | src/Sulu/Bundle/PersistenceBundle/DependencyInjection/PersistenceExtensionTrait.php | PersistenceExtensionTrait.remapObjectParameters | private function remapObjectParameters(array $objects, ContainerBuilder $container)
{
foreach ($objects as $object => $services) {
foreach ($services as $service => $class) {
$container->setParameter(
sprintf(
'sulu.%s.%s.class',
$service,
$object
),
$class
);
}
}
} | php | private function remapObjectParameters(array $objects, ContainerBuilder $container)
{
foreach ($objects as $object => $services) {
foreach ($services as $service => $class) {
$container->setParameter(
sprintf(
'sulu.%s.%s.class',
$service,
$object
),
$class
);
}
}
} | [
"private",
"function",
"remapObjectParameters",
"(",
"array",
"$",
"objects",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"object",
"=>",
"$",
"services",
")",
"{",
"foreach",
"(",
"$",
"services",
"as",
"$",
"service",
"=>",
"$",
"class",
")",
"{",
"$",
"container",
"->",
"setParameter",
"(",
"sprintf",
"(",
"'sulu.%s.%s.class'",
",",
"$",
"service",
",",
"$",
"object",
")",
",",
"$",
"class",
")",
";",
"}",
"}",
"}"
] | Remap object parameters.
@param array $objects
@param ContainerBuilder $container | [
"Remap",
"object",
"parameters",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PersistenceBundle/DependencyInjection/PersistenceExtensionTrait.php#L124-L138 | train |
sulu/sulu | src/Sulu/Component/Localization/Localization.php | Localization.createFromString | public static function createFromString($locale, $format = self::UNDERSCORE)
{
$delimiter = '-';
if (in_array($format, [self::UNDERSCORE, self::LCID])) {
$delimiter = '_';
}
$parts = explode($delimiter, $locale);
$localization = new self();
$localization->setLanguage(strtolower($parts[0]));
if (count($parts) > 1) {
$localization->setCountry(strtolower($parts[1]));
}
return $localization;
} | php | public static function createFromString($locale, $format = self::UNDERSCORE)
{
$delimiter = '-';
if (in_array($format, [self::UNDERSCORE, self::LCID])) {
$delimiter = '_';
}
$parts = explode($delimiter, $locale);
$localization = new self();
$localization->setLanguage(strtolower($parts[0]));
if (count($parts) > 1) {
$localization->setCountry(strtolower($parts[1]));
}
return $localization;
} | [
"public",
"static",
"function",
"createFromString",
"(",
"$",
"locale",
",",
"$",
"format",
"=",
"self",
"::",
"UNDERSCORE",
")",
"{",
"$",
"delimiter",
"=",
"'-'",
";",
"if",
"(",
"in_array",
"(",
"$",
"format",
",",
"[",
"self",
"::",
"UNDERSCORE",
",",
"self",
"::",
"LCID",
"]",
")",
")",
"{",
"$",
"delimiter",
"=",
"'_'",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"locale",
")",
";",
"$",
"localization",
"=",
"new",
"self",
"(",
")",
";",
"$",
"localization",
"->",
"setLanguage",
"(",
"strtolower",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
">",
"1",
")",
"{",
"$",
"localization",
"->",
"setCountry",
"(",
"strtolower",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
")",
";",
"}",
"return",
"$",
"localization",
";",
"}"
] | Create an instance of localization for given locale.
@param string $locale
@param string $format
@return Localization | [
"Create",
"an",
"instance",
"of",
"localization",
"for",
"given",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Localization/Localization.php#L38-L54 | train |
sulu/sulu | src/Sulu/Component/Localization/Localization.php | Localization.getLocalization | public function getLocalization($delimiter = '_')
{
@trigger_error(__METHOD__ . '() is deprecated since version 1.2 and will be removed in 2.0. Use getLocale() instead.', E_USER_DEPRECATED);
$localization = $this->getLanguage();
if (null != $this->getCountry()) {
$localization .= $delimiter . $this->getCountry();
}
return $localization;
} | php | public function getLocalization($delimiter = '_')
{
@trigger_error(__METHOD__ . '() is deprecated since version 1.2 and will be removed in 2.0. Use getLocale() instead.', E_USER_DEPRECATED);
$localization = $this->getLanguage();
if (null != $this->getCountry()) {
$localization .= $delimiter . $this->getCountry();
}
return $localization;
} | [
"public",
"function",
"getLocalization",
"(",
"$",
"delimiter",
"=",
"'_'",
")",
"{",
"@",
"trigger_error",
"(",
"__METHOD__",
".",
"'() is deprecated since version 1.2 and will be removed in 2.0. Use getLocale() instead.'",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"localization",
"=",
"$",
"this",
"->",
"getLanguage",
"(",
")",
";",
"if",
"(",
"null",
"!=",
"$",
"this",
"->",
"getCountry",
"(",
")",
")",
"{",
"$",
"localization",
".=",
"$",
"delimiter",
".",
"$",
"this",
"->",
"getCountry",
"(",
")",
";",
"}",
"return",
"$",
"localization",
";",
"}"
] | Returns the localization code, which is a combination of the language and the country.
@param string $delimiter between language and country
@return string
@VirtualProperty
@deprecated use getLocale instead | [
"Returns",
"the",
"localization",
"code",
"which",
"is",
"a",
"combination",
"of",
"the",
"language",
"and",
"the",
"country",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Localization/Localization.php#L212-L222 | train |
sulu/sulu | src/Sulu/Component/Localization/Localization.php | Localization.getLocale | public function getLocale($format = self::UNDERSCORE)
{
$localization = strtolower($this->getLanguage());
if (null != $this->getCountry()) {
$country = strtolower($this->getCountry());
$delimiter = '-';
switch ($format) {
case self::UNDERSCORE:
$delimiter = '_';
break;
case self::ISO6391:
$country = strtoupper($country);
break;
case self::LCID:
$delimiter = '_';
$country = strtoupper($country);
break;
}
$localization .= $delimiter . $country;
}
return $localization;
} | php | public function getLocale($format = self::UNDERSCORE)
{
$localization = strtolower($this->getLanguage());
if (null != $this->getCountry()) {
$country = strtolower($this->getCountry());
$delimiter = '-';
switch ($format) {
case self::UNDERSCORE:
$delimiter = '_';
break;
case self::ISO6391:
$country = strtoupper($country);
break;
case self::LCID:
$delimiter = '_';
$country = strtoupper($country);
break;
}
$localization .= $delimiter . $country;
}
return $localization;
} | [
"public",
"function",
"getLocale",
"(",
"$",
"format",
"=",
"self",
"::",
"UNDERSCORE",
")",
"{",
"$",
"localization",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"getLanguage",
"(",
")",
")",
";",
"if",
"(",
"null",
"!=",
"$",
"this",
"->",
"getCountry",
"(",
")",
")",
"{",
"$",
"country",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"getCountry",
"(",
")",
")",
";",
"$",
"delimiter",
"=",
"'-'",
";",
"switch",
"(",
"$",
"format",
")",
"{",
"case",
"self",
"::",
"UNDERSCORE",
":",
"$",
"delimiter",
"=",
"'_'",
";",
"break",
";",
"case",
"self",
"::",
"ISO6391",
":",
"$",
"country",
"=",
"strtoupper",
"(",
"$",
"country",
")",
";",
"break",
";",
"case",
"self",
"::",
"LCID",
":",
"$",
"delimiter",
"=",
"'_'",
";",
"$",
"country",
"=",
"strtoupper",
"(",
"$",
"country",
")",
";",
"break",
";",
"}",
"$",
"localization",
".=",
"$",
"delimiter",
".",
"$",
"country",
";",
"}",
"return",
"$",
"localization",
";",
"}"
] | Returns the localization code, which is a combination of the language and the country in a specific format.
@param string $format requested localization format
@return string
@VirtualProperty | [
"Returns",
"the",
"localization",
"code",
"which",
"is",
"a",
"combination",
"of",
"the",
"language",
"and",
"the",
"country",
"in",
"a",
"specific",
"format",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Localization/Localization.php#L232-L257 | train |
sulu/sulu | src/Sulu/Component/Content/Types/TextEditor.php | TextEditor.validate | private function validate($content, $locale)
{
$validation = $this->markupParser->validate($content, $locale);
$regex = sprintf(self::INVALID_REGEX, $this->markupNamespace, $this->markupNamespace);
foreach ($validation as $tag => $state) {
if (false === strpos($tag, 'sulu-validation-state="' . $state . '"')) {
$newTag = preg_replace($regex, '$1 sulu-validation-state="' . $state . '"$2', $tag);
$content = str_replace($tag, $newTag, $content);
}
}
return $content;
} | php | private function validate($content, $locale)
{
$validation = $this->markupParser->validate($content, $locale);
$regex = sprintf(self::INVALID_REGEX, $this->markupNamespace, $this->markupNamespace);
foreach ($validation as $tag => $state) {
if (false === strpos($tag, 'sulu-validation-state="' . $state . '"')) {
$newTag = preg_replace($regex, '$1 sulu-validation-state="' . $state . '"$2', $tag);
$content = str_replace($tag, $newTag, $content);
}
}
return $content;
} | [
"private",
"function",
"validate",
"(",
"$",
"content",
",",
"$",
"locale",
")",
"{",
"$",
"validation",
"=",
"$",
"this",
"->",
"markupParser",
"->",
"validate",
"(",
"$",
"content",
",",
"$",
"locale",
")",
";",
"$",
"regex",
"=",
"sprintf",
"(",
"self",
"::",
"INVALID_REGEX",
",",
"$",
"this",
"->",
"markupNamespace",
",",
"$",
"this",
"->",
"markupNamespace",
")",
";",
"foreach",
"(",
"$",
"validation",
"as",
"$",
"tag",
"=>",
"$",
"state",
")",
"{",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"tag",
",",
"'sulu-validation-state=\"'",
".",
"$",
"state",
".",
"'\"'",
")",
")",
"{",
"$",
"newTag",
"=",
"preg_replace",
"(",
"$",
"regex",
",",
"'$1 sulu-validation-state=\"'",
".",
"$",
"state",
".",
"'\"$2'",
",",
"$",
"tag",
")",
";",
"$",
"content",
"=",
"str_replace",
"(",
"$",
"tag",
",",
"$",
"newTag",
",",
"$",
"content",
")",
";",
"}",
"}",
"return",
"$",
"content",
";",
"}"
] | Returns validated content.
@param string $content
@param string $locale
@return string | [
"Returns",
"validated",
"content",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Types/TextEditor.php#L87-L100 | train |
sulu/sulu | src/Sulu/Component/Content/Query/ListToTreeConverter.php | ListToTreeConverter.convert | public function convert($data)
{
if (empty($data)) {
return [];
}
$map = [];
$minDepth = 99;
foreach ($data as $item) {
$path = rtrim('/root' . $item['path'], '/');
$map[$path] = $item;
$parts = explode('/', $path);
$parts = array_filter($parts);
$depth = count($parts);
if ($minDepth > $depth) {
$minDepth = $depth;
}
}
uksort(
$map,
function($a, $b) use ($map) {
$depthDifference = substr_count($a, '/') - substr_count($b, '/');
if ($depthDifference > 0) {
return 1;
} elseif ($depthDifference < 0) {
return -1;
} else {
$aPosition = array_search($a, array_keys($map));
$bPosition = array_search($b, array_keys($map));
return ($aPosition < $bPosition) ? -1 : 1;
}
}
);
$tree = $this->explodeTree($map, '/');
for ($i = 0; $i < $minDepth - 1; ++$i) {
$tree['children'] = array_values($tree['children']);
if (!array_key_exists('children', $tree) || !array_key_exists(0, $tree['children'])) {
return [];
}
$tree = $tree['children'][0];
}
$tree = $this->toArray($tree);
return $tree['children'];
} | php | public function convert($data)
{
if (empty($data)) {
return [];
}
$map = [];
$minDepth = 99;
foreach ($data as $item) {
$path = rtrim('/root' . $item['path'], '/');
$map[$path] = $item;
$parts = explode('/', $path);
$parts = array_filter($parts);
$depth = count($parts);
if ($minDepth > $depth) {
$minDepth = $depth;
}
}
uksort(
$map,
function($a, $b) use ($map) {
$depthDifference = substr_count($a, '/') - substr_count($b, '/');
if ($depthDifference > 0) {
return 1;
} elseif ($depthDifference < 0) {
return -1;
} else {
$aPosition = array_search($a, array_keys($map));
$bPosition = array_search($b, array_keys($map));
return ($aPosition < $bPosition) ? -1 : 1;
}
}
);
$tree = $this->explodeTree($map, '/');
for ($i = 0; $i < $minDepth - 1; ++$i) {
$tree['children'] = array_values($tree['children']);
if (!array_key_exists('children', $tree) || !array_key_exists(0, $tree['children'])) {
return [];
}
$tree = $tree['children'][0];
}
$tree = $this->toArray($tree);
return $tree['children'];
} | [
"public",
"function",
"convert",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"map",
"=",
"[",
"]",
";",
"$",
"minDepth",
"=",
"99",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"item",
")",
"{",
"$",
"path",
"=",
"rtrim",
"(",
"'/root'",
".",
"$",
"item",
"[",
"'path'",
"]",
",",
"'/'",
")",
";",
"$",
"map",
"[",
"$",
"path",
"]",
"=",
"$",
"item",
";",
"$",
"parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"parts",
"=",
"array_filter",
"(",
"$",
"parts",
")",
";",
"$",
"depth",
"=",
"count",
"(",
"$",
"parts",
")",
";",
"if",
"(",
"$",
"minDepth",
">",
"$",
"depth",
")",
"{",
"$",
"minDepth",
"=",
"$",
"depth",
";",
"}",
"}",
"uksort",
"(",
"$",
"map",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"map",
")",
"{",
"$",
"depthDifference",
"=",
"substr_count",
"(",
"$",
"a",
",",
"'/'",
")",
"-",
"substr_count",
"(",
"$",
"b",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"depthDifference",
">",
"0",
")",
"{",
"return",
"1",
";",
"}",
"elseif",
"(",
"$",
"depthDifference",
"<",
"0",
")",
"{",
"return",
"-",
"1",
";",
"}",
"else",
"{",
"$",
"aPosition",
"=",
"array_search",
"(",
"$",
"a",
",",
"array_keys",
"(",
"$",
"map",
")",
")",
";",
"$",
"bPosition",
"=",
"array_search",
"(",
"$",
"b",
",",
"array_keys",
"(",
"$",
"map",
")",
")",
";",
"return",
"(",
"$",
"aPosition",
"<",
"$",
"bPosition",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
"}",
")",
";",
"$",
"tree",
"=",
"$",
"this",
"->",
"explodeTree",
"(",
"$",
"map",
",",
"'/'",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"minDepth",
"-",
"1",
";",
"++",
"$",
"i",
")",
"{",
"$",
"tree",
"[",
"'children'",
"]",
"=",
"array_values",
"(",
"$",
"tree",
"[",
"'children'",
"]",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'children'",
",",
"$",
"tree",
")",
"||",
"!",
"array_key_exists",
"(",
"0",
",",
"$",
"tree",
"[",
"'children'",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"tree",
"=",
"$",
"tree",
"[",
"'children'",
"]",
"[",
"0",
"]",
";",
"}",
"$",
"tree",
"=",
"$",
"this",
"->",
"toArray",
"(",
"$",
"tree",
")",
";",
"return",
"$",
"tree",
"[",
"'children'",
"]",
";",
"}"
] | generate a tree of the given data with the path property.
@param array $data
@return array | [
"generate",
"a",
"tree",
"of",
"the",
"given",
"data",
"with",
"the",
"path",
"property",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Query/ListToTreeConverter.php#L41-L92 | train |
sulu/sulu | src/Sulu/Component/Content/Query/ListToTreeConverter.php | ListToTreeConverter.explodeTree | private function explodeTree($array, $delimiter = '_', $baseval = false)
{
if (!is_array($array)) {
return false;
}
$splitRE = '/' . preg_quote($delimiter, '/') . '/';
$returnArr = [];
foreach ($array as $key => $val) {
// Get parent parts and the current leaf
$parts = preg_split($splitRE, $key, -1, PREG_SPLIT_NO_EMPTY);
$leafPart = array_pop($parts);
// Build parent structure
// Might be slow for really deep and large structures
$parentArr = &$returnArr;
foreach ($parts as $part) {
if (isset($parentArr['children'][$part])) {
if (!is_array($parentArr['children'][$part])) {
if ($baseval) {
$parentArr['children'][$part] = ['__base_val' => $parentArr[$part]];
} else {
$parentArr['children'][$part] = [];
}
}
$parentArr = &$parentArr['children'][$part];
} else {
$parentArr['children'][$part] = [];
$parentArr = &$parentArr['children'][$part];
}
}
// Add the final part to the structure
if (empty($parentArr['children'][$leafPart])) {
$parentArr['children'][$leafPart] = $val;
} elseif ($baseval && is_array($parentArr['children'][$leafPart])) {
$parentArr['children'][$leafPart]['__base_val'] = $val;
} else {
$parentArr['children'][$leafPart] = array_merge($val, $parentArr['children'][$leafPart]);
}
}
return $returnArr;
} | php | private function explodeTree($array, $delimiter = '_', $baseval = false)
{
if (!is_array($array)) {
return false;
}
$splitRE = '/' . preg_quote($delimiter, '/') . '/';
$returnArr = [];
foreach ($array as $key => $val) {
// Get parent parts and the current leaf
$parts = preg_split($splitRE, $key, -1, PREG_SPLIT_NO_EMPTY);
$leafPart = array_pop($parts);
// Build parent structure
// Might be slow for really deep and large structures
$parentArr = &$returnArr;
foreach ($parts as $part) {
if (isset($parentArr['children'][$part])) {
if (!is_array($parentArr['children'][$part])) {
if ($baseval) {
$parentArr['children'][$part] = ['__base_val' => $parentArr[$part]];
} else {
$parentArr['children'][$part] = [];
}
}
$parentArr = &$parentArr['children'][$part];
} else {
$parentArr['children'][$part] = [];
$parentArr = &$parentArr['children'][$part];
}
}
// Add the final part to the structure
if (empty($parentArr['children'][$leafPart])) {
$parentArr['children'][$leafPart] = $val;
} elseif ($baseval && is_array($parentArr['children'][$leafPart])) {
$parentArr['children'][$leafPart]['__base_val'] = $val;
} else {
$parentArr['children'][$leafPart] = array_merge($val, $parentArr['children'][$leafPart]);
}
}
return $returnArr;
} | [
"private",
"function",
"explodeTree",
"(",
"$",
"array",
",",
"$",
"delimiter",
"=",
"'_'",
",",
"$",
"baseval",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"splitRE",
"=",
"'/'",
".",
"preg_quote",
"(",
"$",
"delimiter",
",",
"'/'",
")",
".",
"'/'",
";",
"$",
"returnArr",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"// Get parent parts and the current leaf",
"$",
"parts",
"=",
"preg_split",
"(",
"$",
"splitRE",
",",
"$",
"key",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"leafPart",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"// Build parent structure",
"// Might be slow for really deep and large structures",
"$",
"parentArr",
"=",
"&",
"$",
"returnArr",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"part",
"]",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"part",
"]",
")",
")",
"{",
"if",
"(",
"$",
"baseval",
")",
"{",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"part",
"]",
"=",
"[",
"'__base_val'",
"=>",
"$",
"parentArr",
"[",
"$",
"part",
"]",
"]",
";",
"}",
"else",
"{",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"part",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"$",
"parentArr",
"=",
"&",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"part",
"]",
";",
"}",
"else",
"{",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"part",
"]",
"=",
"[",
"]",
";",
"$",
"parentArr",
"=",
"&",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"part",
"]",
";",
"}",
"}",
"// Add the final part to the structure",
"if",
"(",
"empty",
"(",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"leafPart",
"]",
")",
")",
"{",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"leafPart",
"]",
"=",
"$",
"val",
";",
"}",
"elseif",
"(",
"$",
"baseval",
"&&",
"is_array",
"(",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"leafPart",
"]",
")",
")",
"{",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"leafPart",
"]",
"[",
"'__base_val'",
"]",
"=",
"$",
"val",
";",
"}",
"else",
"{",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"leafPart",
"]",
"=",
"array_merge",
"(",
"$",
"val",
",",
"$",
"parentArr",
"[",
"'children'",
"]",
"[",
"$",
"leafPart",
"]",
")",
";",
"}",
"}",
"return",
"$",
"returnArr",
";",
"}"
] | Explode any single-dimensional array into a full blown tree structure,
based on the delimiters found in it's keys.
The following code block can be utilized by PEAR's Testing_DocTest
<code>
// Input //
$key_files = array(
"/etc/php5" => "/etc/php5",
"/etc/php5/cli" => "/etc/php5/cli",
"/etc/php5/cli/conf.d" => "/etc/php5/cli/conf.d",
"/etc/php5/cli/php.ini" => "/etc/php5/cli/php.ini",
"/etc/php5/conf.d" => "/etc/php5/conf.d",
"/etc/php5/conf.d/mysqli.ini" => "/etc/php5/conf.d/mysqli.ini",
"/etc/php5/conf.d/curl.ini" => "/etc/php5/conf.d/curl.ini",
"/etc/php5/conf.d/snmp.ini" => "/etc/php5/conf.d/snmp.ini",
"/etc/php5/conf.d/gd.ini" => "/etc/php5/conf.d/gd.ini",
"/etc/php5/apache2" => "/etc/php5/apache2",
"/etc/php5/apache2/conf.d" => "/etc/php5/apache2/conf.d",
"/etc/php5/apache2/php.ini" => "/etc/php5/apache2/php.ini"
);
// Execute //
$tree = explodeTree($key_files, "/", true);
// Show //
print_r($tree);
@author Kevin van Zonneveld <kevin@vanzonneveld.net>
@author Lachlan Donald
@author Takkie
@copyright 2008 Kevin van Zonneveld (http://kevin.vanzonneveld.net)
@license http://www.opensource.org/licenses/bsd-license.php New BSD Licence
@version SVN: Release: $Id: explodeTree.inc.php 89 2008-09-05 20:52:48Z kevin $
@see http://kevin.vanzonneveld.net/
@param array $array
@param string $delimiter
@param bool $baseval
@return array | [
"Explode",
"any",
"single",
"-",
"dimensional",
"array",
"into",
"a",
"full",
"blown",
"tree",
"structure",
"based",
"on",
"the",
"delimiters",
"found",
"in",
"it",
"s",
"keys",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Query/ListToTreeConverter.php#L167-L209 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Phpcr/RemoveSubscriber.php | RemoveSubscriber.handleRemove | public function handleRemove(RemoveEvent $event)
{
$document = $event->getDocument();
$node = $this->documentRegistry->getNodeForDocument($document);
$node->remove();
} | php | public function handleRemove(RemoveEvent $event)
{
$document = $event->getDocument();
$node = $this->documentRegistry->getNodeForDocument($document);
$node->remove();
} | [
"public",
"function",
"handleRemove",
"(",
"RemoveEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"documentRegistry",
"->",
"getNodeForDocument",
"(",
"$",
"document",
")",
";",
"$",
"node",
"->",
"remove",
"(",
")",
";",
"}"
] | Remove the given documents node from PHPCR session and optionally
remove any references to the node.
@param RemoveEvent $event | [
"Remove",
"the",
"given",
"documents",
"node",
"from",
"PHPCR",
"session",
"and",
"optionally",
"remove",
"any",
"references",
"to",
"the",
"node",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Phpcr/RemoveSubscriber.php#L59-L65 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/WebspaceCopyCommand.php | WebspaceCopyCommand.clearDestinationWebspace | protected function clearDestinationWebspace()
{
$homeDocument = $this->documentManager->find(
$this->sessionManager->getContentPath($this->webspaceKeyDestination)
);
foreach ($homeDocument->getChildren() as $child) {
$this->output->writeln('<info>Processing: </info>' . $child->getPath());
$this->documentManager->remove($child);
$this->documentManager->flush();
}
} | php | protected function clearDestinationWebspace()
{
$homeDocument = $this->documentManager->find(
$this->sessionManager->getContentPath($this->webspaceKeyDestination)
);
foreach ($homeDocument->getChildren() as $child) {
$this->output->writeln('<info>Processing: </info>' . $child->getPath());
$this->documentManager->remove($child);
$this->documentManager->flush();
}
} | [
"protected",
"function",
"clearDestinationWebspace",
"(",
")",
"{",
"$",
"homeDocument",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"find",
"(",
"$",
"this",
"->",
"sessionManager",
"->",
"getContentPath",
"(",
"$",
"this",
"->",
"webspaceKeyDestination",
")",
")",
";",
"foreach",
"(",
"$",
"homeDocument",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"'<info>Processing: </info>'",
".",
"$",
"child",
"->",
"getPath",
"(",
")",
")",
";",
"$",
"this",
"->",
"documentManager",
"->",
"remove",
"(",
"$",
"child",
")",
";",
"$",
"this",
"->",
"documentManager",
"->",
"flush",
"(",
")",
";",
"}",
"}"
] | Removes all pages from given webspace. | [
"Removes",
"all",
"pages",
"from",
"given",
"webspace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/WebspaceCopyCommand.php#L202-L212 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/WebspaceCopyCommand.php | WebspaceCopyCommand.updateBlocksStructure | protected function updateBlocksStructure(
array &$structureArray,
BlockMetadata $property,
$localeSource,
$localeDestination
) {
if (!array_key_exists($property->getName(), $structureArray) || !$structureArray[$property->getName()]) {
return;
}
foreach ($structureArray[$property->getName()] as &$structure) {
/** @var ItemMetadata $component */
$component = $property->getComponentByName($structure['type']);
/** @var PropertyMetadata $child */
foreach ($component->getChildren() as $child) {
if ($structure[$child->getName()]) {
$this->processContentType(
$child,
$structure,
$localeSource,
$localeDestination
);
}
}
}
} | php | protected function updateBlocksStructure(
array &$structureArray,
BlockMetadata $property,
$localeSource,
$localeDestination
) {
if (!array_key_exists($property->getName(), $structureArray) || !$structureArray[$property->getName()]) {
return;
}
foreach ($structureArray[$property->getName()] as &$structure) {
/** @var ItemMetadata $component */
$component = $property->getComponentByName($structure['type']);
/** @var PropertyMetadata $child */
foreach ($component->getChildren() as $child) {
if ($structure[$child->getName()]) {
$this->processContentType(
$child,
$structure,
$localeSource,
$localeDestination
);
}
}
}
} | [
"protected",
"function",
"updateBlocksStructure",
"(",
"array",
"&",
"$",
"structureArray",
",",
"BlockMetadata",
"$",
"property",
",",
"$",
"localeSource",
",",
"$",
"localeDestination",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"structureArray",
")",
"||",
"!",
"$",
"structureArray",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"structureArray",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"as",
"&",
"$",
"structure",
")",
"{",
"/** @var ItemMetadata $component */",
"$",
"component",
"=",
"$",
"property",
"->",
"getComponentByName",
"(",
"$",
"structure",
"[",
"'type'",
"]",
")",
";",
"/** @var PropertyMetadata $child */",
"foreach",
"(",
"$",
"component",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"structure",
"[",
"$",
"child",
"->",
"getName",
"(",
")",
"]",
")",
"{",
"$",
"this",
"->",
"processContentType",
"(",
"$",
"child",
",",
"$",
"structure",
",",
"$",
"localeSource",
",",
"$",
"localeDestination",
")",
";",
"}",
"}",
"}",
"}"
] | Process content type block.
@param array $structureArray
@param BlockMetadata $property
@param string $localeSource
@param string $localeDestination | [
"Process",
"content",
"type",
"block",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/WebspaceCopyCommand.php#L475-L500 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/WebspaceCopyCommand.php | WebspaceCopyCommand.updateSmartContentStructure | protected function updateSmartContentStructure(
array &$structureArray,
PropertyMetadata $property,
$localeSource,
$localeDestination
) {
/** @var PropertyParameter $parameter */
foreach ($property->getParameters() as $parameter) {
if (!array_key_exists($property->getName(), $structureArray)) {
continue;
}
if ('provider' !== $parameter['name'] || 'content' !== $parameter['value']) {
continue;
}
if (!array_key_exists('dataSource', $structureArray[$property->getName()])) {
continue;
}
$targetDocumentDestination = $this->getTargetDocumentDestination(
$structureArray[$property->getName()]['dataSource'],
$localeSource,
$localeDestination
);
if (!$targetDocumentDestination) {
continue;
}
$structureArray[$property->getName()]['dataSource'] = $targetDocumentDestination->getUuid();
}
} | php | protected function updateSmartContentStructure(
array &$structureArray,
PropertyMetadata $property,
$localeSource,
$localeDestination
) {
/** @var PropertyParameter $parameter */
foreach ($property->getParameters() as $parameter) {
if (!array_key_exists($property->getName(), $structureArray)) {
continue;
}
if ('provider' !== $parameter['name'] || 'content' !== $parameter['value']) {
continue;
}
if (!array_key_exists('dataSource', $structureArray[$property->getName()])) {
continue;
}
$targetDocumentDestination = $this->getTargetDocumentDestination(
$structureArray[$property->getName()]['dataSource'],
$localeSource,
$localeDestination
);
if (!$targetDocumentDestination) {
continue;
}
$structureArray[$property->getName()]['dataSource'] = $targetDocumentDestination->getUuid();
}
} | [
"protected",
"function",
"updateSmartContentStructure",
"(",
"array",
"&",
"$",
"structureArray",
",",
"PropertyMetadata",
"$",
"property",
",",
"$",
"localeSource",
",",
"$",
"localeDestination",
")",
"{",
"/** @var PropertyParameter $parameter */",
"foreach",
"(",
"$",
"property",
"->",
"getParameters",
"(",
")",
"as",
"$",
"parameter",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"structureArray",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"'provider'",
"!==",
"$",
"parameter",
"[",
"'name'",
"]",
"||",
"'content'",
"!==",
"$",
"parameter",
"[",
"'value'",
"]",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'dataSource'",
",",
"$",
"structureArray",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"targetDocumentDestination",
"=",
"$",
"this",
"->",
"getTargetDocumentDestination",
"(",
"$",
"structureArray",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"[",
"'dataSource'",
"]",
",",
"$",
"localeSource",
",",
"$",
"localeDestination",
")",
";",
"if",
"(",
"!",
"$",
"targetDocumentDestination",
")",
"{",
"continue",
";",
"}",
"$",
"structureArray",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"[",
"'dataSource'",
"]",
"=",
"$",
"targetDocumentDestination",
"->",
"getUuid",
"(",
")",
";",
"}",
"}"
] | Updates the smart content structure when the property `dataSource` is set and the target is in the same webspace.
@param array $structureArray
@param PropertyMetadata $property
@param string $localeSource
@param string $localeDestination | [
"Updates",
"the",
"smart",
"content",
"structure",
"when",
"the",
"property",
"dataSource",
"is",
"set",
"and",
"the",
"target",
"is",
"in",
"the",
"same",
"webspace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/WebspaceCopyCommand.php#L510-L542 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/WebspaceCopyCommand.php | WebspaceCopyCommand.updatePageSelection | protected function updatePageSelection(
array &$structureArray,
PropertyMetadata $property,
$localeSource,
$localeDestination
) {
if (!array_key_exists($property->getName(), $structureArray) || !$structureArray[$property->getName()]) {
return;
}
foreach ($structureArray[$property->getName()] as $key => $value) {
$targetDocumentDestination = $this->getTargetDocumentDestination(
$value,
$localeSource,
$localeDestination
);
if (!$targetDocumentDestination) {
continue;
}
$structureArray[$property->getName()][$key] = $targetDocumentDestination->getUuid();
}
} | php | protected function updatePageSelection(
array &$structureArray,
PropertyMetadata $property,
$localeSource,
$localeDestination
) {
if (!array_key_exists($property->getName(), $structureArray) || !$structureArray[$property->getName()]) {
return;
}
foreach ($structureArray[$property->getName()] as $key => $value) {
$targetDocumentDestination = $this->getTargetDocumentDestination(
$value,
$localeSource,
$localeDestination
);
if (!$targetDocumentDestination) {
continue;
}
$structureArray[$property->getName()][$key] = $targetDocumentDestination->getUuid();
}
} | [
"protected",
"function",
"updatePageSelection",
"(",
"array",
"&",
"$",
"structureArray",
",",
"PropertyMetadata",
"$",
"property",
",",
"$",
"localeSource",
",",
"$",
"localeDestination",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"structureArray",
")",
"||",
"!",
"$",
"structureArray",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"structureArray",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"targetDocumentDestination",
"=",
"$",
"this",
"->",
"getTargetDocumentDestination",
"(",
"$",
"value",
",",
"$",
"localeSource",
",",
"$",
"localeDestination",
")",
";",
"if",
"(",
"!",
"$",
"targetDocumentDestination",
")",
"{",
"continue",
";",
"}",
"$",
"structureArray",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"targetDocumentDestination",
"->",
"getUuid",
"(",
")",
";",
"}",
"}"
] | Updates references in structure for content type `page_selection`.
@param array $structureArray
@param PropertyMetadata $property
@param string $localeSource
@param string $localeDestination | [
"Updates",
"references",
"in",
"structure",
"for",
"content",
"type",
"page_selection",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/WebspaceCopyCommand.php#L604-L627 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/WebspaceCopyCommand.php | WebspaceCopyCommand.updateSinglePageSelection | protected function updateSinglePageSelection(
array &$structureArray,
PropertyMetadata $property,
$localeSource,
$localeDestination
) {
if (!array_key_exists($property->getName(), $structureArray) || !$structureArray[$property->getName()]) {
return;
}
$targetDocumentDestination = $this->getTargetDocumentDestination(
$structureArray[$property->getName()],
$localeSource,
$localeDestination
);
if (!$targetDocumentDestination) {
return;
}
$structureArray[$property->getName()] = $targetDocumentDestination->getUuid();
} | php | protected function updateSinglePageSelection(
array &$structureArray,
PropertyMetadata $property,
$localeSource,
$localeDestination
) {
if (!array_key_exists($property->getName(), $structureArray) || !$structureArray[$property->getName()]) {
return;
}
$targetDocumentDestination = $this->getTargetDocumentDestination(
$structureArray[$property->getName()],
$localeSource,
$localeDestination
);
if (!$targetDocumentDestination) {
return;
}
$structureArray[$property->getName()] = $targetDocumentDestination->getUuid();
} | [
"protected",
"function",
"updateSinglePageSelection",
"(",
"array",
"&",
"$",
"structureArray",
",",
"PropertyMetadata",
"$",
"property",
",",
"$",
"localeSource",
",",
"$",
"localeDestination",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"structureArray",
")",
"||",
"!",
"$",
"structureArray",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
")",
"{",
"return",
";",
"}",
"$",
"targetDocumentDestination",
"=",
"$",
"this",
"->",
"getTargetDocumentDestination",
"(",
"$",
"structureArray",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
",",
"$",
"localeSource",
",",
"$",
"localeDestination",
")",
";",
"if",
"(",
"!",
"$",
"targetDocumentDestination",
")",
"{",
"return",
";",
"}",
"$",
"structureArray",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"targetDocumentDestination",
"->",
"getUuid",
"(",
")",
";",
"}"
] | Updates references in structure for content type `single_page_selection`.
@param array $structureArray
@param PropertyMetadata $property
@param string $localeSource
@param string $localeDestination | [
"Updates",
"references",
"in",
"structure",
"for",
"content",
"type",
"single_page_selection",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/WebspaceCopyCommand.php#L637-L658 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/PositionController.php | PositionController.getAction | public function getAction($id)
{
$view = $this->responseGetById(
$id,
function($id) {
return $this->getDoctrine()
->getRepository(self::$entityName)
->find($id);
}
);
return $this->handleView($view);
} | php | public function getAction($id)
{
$view = $this->responseGetById(
$id,
function($id) {
return $this->getDoctrine()
->getRepository(self::$entityName)
->find($id);
}
);
return $this->handleView($view);
} | [
"public",
"function",
"getAction",
"(",
"$",
"id",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"responseGetById",
"(",
"$",
"id",
",",
"function",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"entityName",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Shows a single position for the given id.
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Shows",
"a",
"single",
"position",
"for",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/PositionController.php#L45-L57 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/PositionController.php | PositionController.cgetAction | public function cgetAction()
{
$list = new CollectionRepresentation(
$this->getDoctrine()->getRepository(self::$entityName)->findBy([], ['position' => 'ASC']),
self::$entityKey
);
$view = $this->view($list, 200);
return $this->handleView($view);
} | php | public function cgetAction()
{
$list = new CollectionRepresentation(
$this->getDoctrine()->getRepository(self::$entityName)->findBy([], ['position' => 'ASC']),
self::$entityKey
);
$view = $this->view($list, 200);
return $this->handleView($view);
} | [
"public",
"function",
"cgetAction",
"(",
")",
"{",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"entityName",
")",
"->",
"findBy",
"(",
"[",
"]",
",",
"[",
"'position'",
"=>",
"'ASC'",
"]",
")",
",",
"self",
"::",
"$",
"entityKey",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | lists all positions
optional parameter 'flat' calls listAction.
@return \Symfony\Component\HttpFoundation\Response | [
"lists",
"all",
"positions",
"optional",
"parameter",
"flat",
"calls",
"listAction",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/PositionController.php#L65-L75 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/PositionController.php | PositionController.postAction | public function postAction(Request $request)
{
$name = $request->get('position');
try {
if (null == $name) {
throw new RestException(
'There is no position-name for the given name'
);
}
$em = $this->getDoctrine()->getManager();
$position = new Position();
$position->setPosition($name);
$em->persist($position);
$em->flush();
$view = $this->view($position, 200);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $this->handleView($view);
} | php | public function postAction(Request $request)
{
$name = $request->get('position');
try {
if (null == $name) {
throw new RestException(
'There is no position-name for the given name'
);
}
$em = $this->getDoctrine()->getManager();
$position = new Position();
$position->setPosition($name);
$em->persist($position);
$em->flush();
$view = $this->view($position, 200);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"name",
"=",
"$",
"request",
"->",
"get",
"(",
"'position'",
")",
";",
"try",
"{",
"if",
"(",
"null",
"==",
"$",
"name",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'There is no position-name for the given name'",
")",
";",
"}",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"position",
"=",
"new",
"Position",
"(",
")",
";",
"$",
"position",
"->",
"setPosition",
"(",
"$",
"name",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"position",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"position",
",",
"200",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"re",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"re",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Creates a new position.
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Creates",
"a",
"new",
"position",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/PositionController.php#L84-L110 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Media/FormatCache/FormatCacheClearer.php | FormatCacheClearer.clear | public function clear($cache = null)
{
if (null !== $cache) {
if (!array_key_exists($cache, $this->caches)) {
throw new CacheNotFoundException($cache);
}
$this->caches[$cache]->clear();
} else {
foreach ($this->caches as $cache) {
$cache->clear();
}
}
} | php | public function clear($cache = null)
{
if (null !== $cache) {
if (!array_key_exists($cache, $this->caches)) {
throw new CacheNotFoundException($cache);
}
$this->caches[$cache]->clear();
} else {
foreach ($this->caches as $cache) {
$cache->clear();
}
}
} | [
"public",
"function",
"clear",
"(",
"$",
"cache",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"cache",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"cache",
",",
"$",
"this",
"->",
"caches",
")",
")",
"{",
"throw",
"new",
"CacheNotFoundException",
"(",
"$",
"cache",
")",
";",
"}",
"$",
"this",
"->",
"caches",
"[",
"$",
"cache",
"]",
"->",
"clear",
"(",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"caches",
"as",
"$",
"cache",
")",
"{",
"$",
"cache",
"->",
"clear",
"(",
")",
";",
"}",
"}",
"}"
] | Clear all or the given cache.
@param string $cache The alias of the cache
@throws CacheNotFoundException if the cache is not found | [
"Clear",
"all",
"or",
"the",
"given",
"cache",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Media/FormatCache/FormatCacheClearer.php#L33-L46 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Api/ConditionGroup.php | ConditionGroup.getConditions | public function getConditions()
{
$conditions = $this->entity->getConditions();
$result = [];
if ($conditions) {
foreach ($conditions as $condition) {
$result[] = new Condition($condition, $this->locale);
}
return $result;
}
return;
} | php | public function getConditions()
{
$conditions = $this->entity->getConditions();
$result = [];
if ($conditions) {
foreach ($conditions as $condition) {
$result[] = new Condition($condition, $this->locale);
}
return $result;
}
return;
} | [
"public",
"function",
"getConditions",
"(",
")",
"{",
"$",
"conditions",
"=",
"$",
"this",
"->",
"entity",
"->",
"getConditions",
"(",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"conditions",
")",
"{",
"foreach",
"(",
"$",
"conditions",
"as",
"$",
"condition",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"new",
"Condition",
"(",
"$",
"condition",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"return",
";",
"}"
] | Get conditions.
@VirtualProperty
@SerializedName("conditions")
@return null|Condition[] | [
"Get",
"conditions",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Api/ConditionGroup.php#L58-L71 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/FieldDescriptor/DoctrineConcatenationFieldDescriptor.php | DoctrineConcatenationFieldDescriptor.getSelect | public function getSelect()
{
$concat = null;
foreach ($this->fieldDescriptors as $fieldDescriptor) {
if (null == $concat) {
$concat = $fieldDescriptor->getSelect();
} else {
$concat = 'CONCAT(' . $concat . ', CONCAT(\'' . $this->glue . '\', ' . $fieldDescriptor->getSelect() . '))';
}
}
return $concat;
} | php | public function getSelect()
{
$concat = null;
foreach ($this->fieldDescriptors as $fieldDescriptor) {
if (null == $concat) {
$concat = $fieldDescriptor->getSelect();
} else {
$concat = 'CONCAT(' . $concat . ', CONCAT(\'' . $this->glue . '\', ' . $fieldDescriptor->getSelect() . '))';
}
}
return $concat;
} | [
"public",
"function",
"getSelect",
"(",
")",
"{",
"$",
"concat",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"fieldDescriptors",
"as",
"$",
"fieldDescriptor",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"concat",
")",
"{",
"$",
"concat",
"=",
"$",
"fieldDescriptor",
"->",
"getSelect",
"(",
")",
";",
"}",
"else",
"{",
"$",
"concat",
"=",
"'CONCAT('",
".",
"$",
"concat",
".",
"', CONCAT(\\''",
".",
"$",
"this",
"->",
"glue",
".",
"'\\', '",
".",
"$",
"fieldDescriptor",
"->",
"getSelect",
"(",
")",
".",
"'))'",
";",
"}",
"}",
"return",
"$",
"concat",
";",
"}"
] | Returns the select statement for this field without the alias.
@return string | [
"Returns",
"the",
"select",
"statement",
"for",
"this",
"field",
"without",
"the",
"alias",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/FieldDescriptor/DoctrineConcatenationFieldDescriptor.php#L60-L73 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/FieldDescriptor/DoctrineConcatenationFieldDescriptor.php | DoctrineConcatenationFieldDescriptor.getJoins | public function getJoins()
{
$joins = [];
foreach ($this->fieldDescriptors as $fieldDescriptor) {
$joins = array_merge($joins, $fieldDescriptor->getJoins());
}
return $joins;
} | php | public function getJoins()
{
$joins = [];
foreach ($this->fieldDescriptors as $fieldDescriptor) {
$joins = array_merge($joins, $fieldDescriptor->getJoins());
}
return $joins;
} | [
"public",
"function",
"getJoins",
"(",
")",
"{",
"$",
"joins",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fieldDescriptors",
"as",
"$",
"fieldDescriptor",
")",
"{",
"$",
"joins",
"=",
"array_merge",
"(",
"$",
"joins",
",",
"$",
"fieldDescriptor",
"->",
"getJoins",
"(",
")",
")",
";",
"}",
"return",
"$",
"joins",
";",
"}"
] | Returns all the joins required for this field.
@return DoctrineJoinDescriptor[] | [
"Returns",
"all",
"the",
"joins",
"required",
"for",
"this",
"field",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/FieldDescriptor/DoctrineConcatenationFieldDescriptor.php#L80-L89 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/CacheController.php | CacheController.clearAction | public function clearAction()
{
if (!$this->checkLivePermissionForAllWebspaces()) {
return new JsonResponse(null, 403);
}
$this->get('sulu_website.http_cache.clearer')->clear();
return new JsonResponse(null, 204);
} | php | public function clearAction()
{
if (!$this->checkLivePermissionForAllWebspaces()) {
return new JsonResponse(null, 403);
}
$this->get('sulu_website.http_cache.clearer')->clear();
return new JsonResponse(null, 204);
} | [
"public",
"function",
"clearAction",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"checkLivePermissionForAllWebspaces",
"(",
")",
")",
"{",
"return",
"new",
"JsonResponse",
"(",
"null",
",",
"403",
")",
";",
"}",
"$",
"this",
"->",
"get",
"(",
"'sulu_website.http_cache.clearer'",
")",
"->",
"clear",
"(",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"null",
",",
"204",
")",
";",
"}"
] | Clear the whole http_cache for website.
@return JsonResponse | [
"Clear",
"the",
"whole",
"http_cache",
"for",
"website",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/CacheController.php#L29-L38 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/CacheController.php | CacheController.checkLivePermissionForAllWebspaces | private function checkLivePermissionForAllWebspaces()
{
foreach ($this->get('sulu_core.webspace.webspace_manager')->getWebspaceCollection() as $webspace) {
$context = PageAdmin::SECURITY_CONTEXT_PREFIX . $webspace->getKey();
if (!$this->get('sulu_security.security_checker')->hasPermission($context, PermissionTypes::LIVE)) {
return false;
}
}
return true;
} | php | private function checkLivePermissionForAllWebspaces()
{
foreach ($this->get('sulu_core.webspace.webspace_manager')->getWebspaceCollection() as $webspace) {
$context = PageAdmin::SECURITY_CONTEXT_PREFIX . $webspace->getKey();
if (!$this->get('sulu_security.security_checker')->hasPermission($context, PermissionTypes::LIVE)) {
return false;
}
}
return true;
} | [
"private",
"function",
"checkLivePermissionForAllWebspaces",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.webspace.webspace_manager'",
")",
"->",
"getWebspaceCollection",
"(",
")",
"as",
"$",
"webspace",
")",
"{",
"$",
"context",
"=",
"PageAdmin",
"::",
"SECURITY_CONTEXT_PREFIX",
".",
"$",
"webspace",
"->",
"getKey",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"get",
"(",
"'sulu_security.security_checker'",
")",
"->",
"hasPermission",
"(",
"$",
"context",
",",
"PermissionTypes",
"::",
"LIVE",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Check the permissions for all webspaces.
Returns true if the user has live permission in all webspaces.
TODO should be replaced with a single webspace cache clear.
@return bool | [
"Check",
"the",
"permissions",
"for",
"all",
"webspaces",
".",
"Returns",
"true",
"if",
"the",
"user",
"has",
"live",
"permission",
"in",
"all",
"webspaces",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/CacheController.php#L48-L58 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Entity/Analytics.php | Analytics.addDomain | public function addDomain(Domain $domain)
{
if ($this->domains->contains($domain)) {
return $this;
}
$this->domains[] = $domain;
return $this;
} | php | public function addDomain(Domain $domain)
{
if ($this->domains->contains($domain)) {
return $this;
}
$this->domains[] = $domain;
return $this;
} | [
"public",
"function",
"addDomain",
"(",
"Domain",
"$",
"domain",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"domains",
"->",
"contains",
"(",
"$",
"domain",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"domains",
"[",
"]",
"=",
"$",
"domain",
";",
"return",
"$",
"this",
";",
"}"
] | Add domain.
@param Domain $domain
@return self | [
"Add",
"domain",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Entity/Analytics.php#L205-L214 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Entity/Analytics.php | Analytics.getDomains | public function getDomains()
{
if (0 === count($this->domains)) {
return null;
}
return $this->domains->map(function(Domain $domain) {
return $domain->getUrl();
});
} | php | public function getDomains()
{
if (0 === count($this->domains)) {
return null;
}
return $this->domains->map(function(Domain $domain) {
return $domain->getUrl();
});
} | [
"public",
"function",
"getDomains",
"(",
")",
"{",
"if",
"(",
"0",
"===",
"count",
"(",
"$",
"this",
"->",
"domains",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"domains",
"->",
"map",
"(",
"function",
"(",
"Domain",
"$",
"domain",
")",
"{",
"return",
"$",
"domain",
"->",
"getUrl",
"(",
")",
";",
"}",
")",
";",
"}"
] | Get domains.
@return Collection|Domain[]|null
@VirtualProperty | [
"Get",
"domains",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Entity/Analytics.php#L241-L250 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/ShadowLocaleSubscriber.php | ShadowLocaleSubscriber.handleHydrate | public function handleHydrate(AbstractMappingEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof ShadowLocaleBehavior || !$event->getOption('load_shadow_content')) {
return;
}
$node = $event->getNode();
$locale = $this->inspector->getOriginalLocale($document);
$shadowLocaleEnabled = $this->getShadowLocaleEnabled($node, $locale);
$document->setShadowLocaleEnabled($shadowLocaleEnabled);
if (!$shadowLocaleEnabled) {
return;
}
$shadowLocale = $this->getShadowLocale($node, $locale);
$document->setShadowLocale($shadowLocale);
$event->setLocale($shadowLocale);
$document->setLocale($shadowLocale);
} | php | public function handleHydrate(AbstractMappingEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof ShadowLocaleBehavior || !$event->getOption('load_shadow_content')) {
return;
}
$node = $event->getNode();
$locale = $this->inspector->getOriginalLocale($document);
$shadowLocaleEnabled = $this->getShadowLocaleEnabled($node, $locale);
$document->setShadowLocaleEnabled($shadowLocaleEnabled);
if (!$shadowLocaleEnabled) {
return;
}
$shadowLocale = $this->getShadowLocale($node, $locale);
$document->setShadowLocale($shadowLocale);
$event->setLocale($shadowLocale);
$document->setLocale($shadowLocale);
} | [
"public",
"function",
"handleHydrate",
"(",
"AbstractMappingEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"ShadowLocaleBehavior",
"||",
"!",
"$",
"event",
"->",
"getOption",
"(",
"'load_shadow_content'",
")",
")",
"{",
"return",
";",
"}",
"$",
"node",
"=",
"$",
"event",
"->",
"getNode",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"inspector",
"->",
"getOriginalLocale",
"(",
"$",
"document",
")",
";",
"$",
"shadowLocaleEnabled",
"=",
"$",
"this",
"->",
"getShadowLocaleEnabled",
"(",
"$",
"node",
",",
"$",
"locale",
")",
";",
"$",
"document",
"->",
"setShadowLocaleEnabled",
"(",
"$",
"shadowLocaleEnabled",
")",
";",
"if",
"(",
"!",
"$",
"shadowLocaleEnabled",
")",
"{",
"return",
";",
"}",
"$",
"shadowLocale",
"=",
"$",
"this",
"->",
"getShadowLocale",
"(",
"$",
"node",
",",
"$",
"locale",
")",
";",
"$",
"document",
"->",
"setShadowLocale",
"(",
"$",
"shadowLocale",
")",
";",
"$",
"event",
"->",
"setLocale",
"(",
"$",
"shadowLocale",
")",
";",
"$",
"document",
"->",
"setLocale",
"(",
"$",
"shadowLocale",
")",
";",
"}"
] | Update the locale to the shadow locale, if it is enabled.
Note that this should happen before the fallback locale has been resolved
@param AbstractMappingEvent $event | [
"Update",
"the",
"locale",
"to",
"the",
"shadow",
"locale",
"if",
"it",
"is",
"enabled",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/ShadowLocaleSubscriber.php#L116-L137 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/ShadowLocaleSubscriber.php | ShadowLocaleSubscriber.handlePersistUpdateUrl | public function handlePersistUpdateUrl(PersistEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof ShadowLocaleBehavior) {
return;
}
if (!$document->isShadowLocaleEnabled()) {
return;
}
$node = $event->getNode();
$structure = $this->inspector->getStructureMetadata($document);
if (false === $structure->hasPropertyWithTagName('sulu.rlp')) {
return;
}
$locatorProperty = $structure->getPropertyByTagName('sulu.rlp');
if ($node->getPropertyValueWithDefault(
$this->encoder->localizedSystemName(
$locatorProperty->getName(), $document->getLocale()
),
null
)) {
return;
}
$shadowLocator = $node->getPropertyValueWithDefault(
$this->encoder->localizedSystemName(
$locatorProperty->getName(), $document->getShadowLocale()
),
null
);
if (!$shadowLocator) {
return;
}
$event->getAccessor()->set(
'resourceSegment',
$shadowLocator
);
} | php | public function handlePersistUpdateUrl(PersistEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof ShadowLocaleBehavior) {
return;
}
if (!$document->isShadowLocaleEnabled()) {
return;
}
$node = $event->getNode();
$structure = $this->inspector->getStructureMetadata($document);
if (false === $structure->hasPropertyWithTagName('sulu.rlp')) {
return;
}
$locatorProperty = $structure->getPropertyByTagName('sulu.rlp');
if ($node->getPropertyValueWithDefault(
$this->encoder->localizedSystemName(
$locatorProperty->getName(), $document->getLocale()
),
null
)) {
return;
}
$shadowLocator = $node->getPropertyValueWithDefault(
$this->encoder->localizedSystemName(
$locatorProperty->getName(), $document->getShadowLocale()
),
null
);
if (!$shadowLocator) {
return;
}
$event->getAccessor()->set(
'resourceSegment',
$shadowLocator
);
} | [
"public",
"function",
"handlePersistUpdateUrl",
"(",
"PersistEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"ShadowLocaleBehavior",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"document",
"->",
"isShadowLocaleEnabled",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"node",
"=",
"$",
"event",
"->",
"getNode",
"(",
")",
";",
"$",
"structure",
"=",
"$",
"this",
"->",
"inspector",
"->",
"getStructureMetadata",
"(",
"$",
"document",
")",
";",
"if",
"(",
"false",
"===",
"$",
"structure",
"->",
"hasPropertyWithTagName",
"(",
"'sulu.rlp'",
")",
")",
"{",
"return",
";",
"}",
"$",
"locatorProperty",
"=",
"$",
"structure",
"->",
"getPropertyByTagName",
"(",
"'sulu.rlp'",
")",
";",
"if",
"(",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"$",
"this",
"->",
"encoder",
"->",
"localizedSystemName",
"(",
"$",
"locatorProperty",
"->",
"getName",
"(",
")",
",",
"$",
"document",
"->",
"getLocale",
"(",
")",
")",
",",
"null",
")",
")",
"{",
"return",
";",
"}",
"$",
"shadowLocator",
"=",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"$",
"this",
"->",
"encoder",
"->",
"localizedSystemName",
"(",
"$",
"locatorProperty",
"->",
"getName",
"(",
")",
",",
"$",
"document",
"->",
"getShadowLocale",
"(",
")",
")",
",",
"null",
")",
";",
"if",
"(",
"!",
"$",
"shadowLocator",
")",
"{",
"return",
";",
"}",
"$",
"event",
"->",
"getAccessor",
"(",
")",
"->",
"set",
"(",
"'resourceSegment'",
",",
"$",
"shadowLocator",
")",
";",
"}"
] | If this is a shadow document, update the URL to that of the shadowed document.
TODO: This is about caching and should be handled somewhere else.
@param PersistEvent $event | [
"If",
"this",
"is",
"a",
"shadow",
"document",
"update",
"the",
"URL",
"to",
"that",
"of",
"the",
"shadowed",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/ShadowLocaleSubscriber.php#L176-L221 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php | DocumentInspector.getContentPath | public function getContentPath(PathBehavior $document)
{
$path = $this->getPath($document);
$webspaceKey = $this->getWebspace($document);
return str_replace(
sprintf(
'/%s/%s/%s',
$this->pathSegmentRegistry->getPathSegment('base'),
$webspaceKey,
$this->pathSegmentRegistry->getPathSegment('content')
),
'',
$path
);
} | php | public function getContentPath(PathBehavior $document)
{
$path = $this->getPath($document);
$webspaceKey = $this->getWebspace($document);
return str_replace(
sprintf(
'/%s/%s/%s',
$this->pathSegmentRegistry->getPathSegment('base'),
$webspaceKey,
$this->pathSegmentRegistry->getPathSegment('content')
),
'',
$path
);
} | [
"public",
"function",
"getContentPath",
"(",
"PathBehavior",
"$",
"document",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getPath",
"(",
"$",
"document",
")",
";",
"$",
"webspaceKey",
"=",
"$",
"this",
"->",
"getWebspace",
"(",
"$",
"document",
")",
";",
"return",
"str_replace",
"(",
"sprintf",
"(",
"'/%s/%s/%s'",
",",
"$",
"this",
"->",
"pathSegmentRegistry",
"->",
"getPathSegment",
"(",
"'base'",
")",
",",
"$",
"webspaceKey",
",",
"$",
"this",
"->",
"pathSegmentRegistry",
"->",
"getPathSegment",
"(",
"'content'",
")",
")",
",",
"''",
",",
"$",
"path",
")",
";",
"}"
] | Return the path of the document in relation to the content root.
TODO: We need a better solution for retrieving webspace paths (the existing
"session manager" is not a good solution).
@param PathBehavior $document
@return string | [
"Return",
"the",
"path",
"of",
"the",
"document",
"in",
"relation",
"to",
"the",
"content",
"root",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php#L93-L108 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php | DocumentInspector.getStructureMetadata | public function getStructureMetadata(StructureBehavior $document)
{
try {
return $this->structureFactory->getStructureMetadata(
$this->getMetadata($document)->getAlias(),
$document->getStructureType()
);
} catch (StructureTypeNotFoundException $exception) {
return;
}
} | php | public function getStructureMetadata(StructureBehavior $document)
{
try {
return $this->structureFactory->getStructureMetadata(
$this->getMetadata($document)->getAlias(),
$document->getStructureType()
);
} catch (StructureTypeNotFoundException $exception) {
return;
}
} | [
"public",
"function",
"getStructureMetadata",
"(",
"StructureBehavior",
"$",
"document",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"structureFactory",
"->",
"getStructureMetadata",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
"$",
"document",
")",
"->",
"getAlias",
"(",
")",
",",
"$",
"document",
"->",
"getStructureType",
"(",
")",
")",
";",
"}",
"catch",
"(",
"StructureTypeNotFoundException",
"$",
"exception",
")",
"{",
"return",
";",
"}",
"}"
] | Return the structure for the given StructureBehavior implementing document.
@param StructureBehavior $document
@return StructureMetadata | [
"Return",
"the",
"structure",
"for",
"the",
"given",
"StructureBehavior",
"implementing",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php#L117-L127 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php | DocumentInspector.getLocalizationState | public function getLocalizationState($document)
{
if ($document instanceof ShadowLocaleBehavior) {
if (true === $document->isShadowLocaleEnabled()) {
return LocalizationState::SHADOW;
}
}
$originalLocale = $document->getOriginalLocale();
$currentLocale = $document->getLocale();
if ($originalLocale === $currentLocale) {
return LocalizationState::LOCALIZED;
}
return LocalizationState::GHOST;
} | php | public function getLocalizationState($document)
{
if ($document instanceof ShadowLocaleBehavior) {
if (true === $document->isShadowLocaleEnabled()) {
return LocalizationState::SHADOW;
}
}
$originalLocale = $document->getOriginalLocale();
$currentLocale = $document->getLocale();
if ($originalLocale === $currentLocale) {
return LocalizationState::LOCALIZED;
}
return LocalizationState::GHOST;
} | [
"public",
"function",
"getLocalizationState",
"(",
"$",
"document",
")",
"{",
"if",
"(",
"$",
"document",
"instanceof",
"ShadowLocaleBehavior",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"document",
"->",
"isShadowLocaleEnabled",
"(",
")",
")",
"{",
"return",
"LocalizationState",
"::",
"SHADOW",
";",
"}",
"}",
"$",
"originalLocale",
"=",
"$",
"document",
"->",
"getOriginalLocale",
"(",
")",
";",
"$",
"currentLocale",
"=",
"$",
"document",
"->",
"getLocale",
"(",
")",
";",
"if",
"(",
"$",
"originalLocale",
"===",
"$",
"currentLocale",
")",
"{",
"return",
"LocalizationState",
"::",
"LOCALIZED",
";",
"}",
"return",
"LocalizationState",
"::",
"GHOST",
";",
"}"
] | Return the localization state of the node.
@param object $document
@return string | [
"Return",
"the",
"localization",
"state",
"of",
"the",
"node",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php#L148-L164 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php | DocumentInspector.getLocale | public function getLocale($document)
{
if ($document instanceof LocaleBehavior) {
return $document->getLocale();
}
if ($this->documentRegistry->hasDocument($document)) {
return $this->documentRegistry->getLocaleForDocument($document);
}
return;
} | php | public function getLocale($document)
{
if ($document instanceof LocaleBehavior) {
return $document->getLocale();
}
if ($this->documentRegistry->hasDocument($document)) {
return $this->documentRegistry->getLocaleForDocument($document);
}
return;
} | [
"public",
"function",
"getLocale",
"(",
"$",
"document",
")",
"{",
"if",
"(",
"$",
"document",
"instanceof",
"LocaleBehavior",
")",
"{",
"return",
"$",
"document",
"->",
"getLocale",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"documentRegistry",
"->",
"hasDocument",
"(",
"$",
"document",
")",
")",
"{",
"return",
"$",
"this",
"->",
"documentRegistry",
"->",
"getLocaleForDocument",
"(",
"$",
"document",
")",
";",
"}",
"return",
";",
"}"
] | Return the locale for the given document or null
if the document is not managed.
@return string|null | [
"Return",
"the",
"locale",
"for",
"the",
"given",
"document",
"or",
"null",
"if",
"the",
"document",
"is",
"not",
"managed",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php#L172-L183 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php | DocumentInspector.getLocales | public function getLocales($document)
{
$locales = [];
$node = $this->getNode($document);
$prefix = $this->namespaceRegistry->getPrefix('system_localized');
foreach ($node->getProperties() as $property) {
preg_match(
sprintf('/^%s:([a-zA-Z_]*?)-.*/', $prefix),
$property->getName(),
$matches
);
if ($matches) {
$locales[$matches[1]] = $matches[1];
}
}
return array_values(array_unique($locales));
} | php | public function getLocales($document)
{
$locales = [];
$node = $this->getNode($document);
$prefix = $this->namespaceRegistry->getPrefix('system_localized');
foreach ($node->getProperties() as $property) {
preg_match(
sprintf('/^%s:([a-zA-Z_]*?)-.*/', $prefix),
$property->getName(),
$matches
);
if ($matches) {
$locales[$matches[1]] = $matches[1];
}
}
return array_values(array_unique($locales));
} | [
"public",
"function",
"getLocales",
"(",
"$",
"document",
")",
"{",
"$",
"locales",
"=",
"[",
"]",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"getNode",
"(",
"$",
"document",
")",
";",
"$",
"prefix",
"=",
"$",
"this",
"->",
"namespaceRegistry",
"->",
"getPrefix",
"(",
"'system_localized'",
")",
";",
"foreach",
"(",
"$",
"node",
"->",
"getProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"preg_match",
"(",
"sprintf",
"(",
"'/^%s:([a-zA-Z_]*?)-.*/'",
",",
"$",
"prefix",
")",
",",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"matches",
")",
"{",
"$",
"locales",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"array_values",
"(",
"array_unique",
"(",
"$",
"locales",
")",
")",
";",
"}"
] | Return the concrete localizations for the given document.
@param object $document
@return array | [
"Return",
"the",
"concrete",
"localizations",
"for",
"the",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php#L205-L224 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php | DocumentInspector.getConcreteLocales | public function getConcreteLocales($document)
{
$locales = $this->getLocales($document);
if ($document instanceof ShadowLocaleBehavior) {
$locales = array_diff($locales, array_keys($this->getShadowLocales($document)));
}
return array_values($locales);
} | php | public function getConcreteLocales($document)
{
$locales = $this->getLocales($document);
if ($document instanceof ShadowLocaleBehavior) {
$locales = array_diff($locales, array_keys($this->getShadowLocales($document)));
}
return array_values($locales);
} | [
"public",
"function",
"getConcreteLocales",
"(",
"$",
"document",
")",
"{",
"$",
"locales",
"=",
"$",
"this",
"->",
"getLocales",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"document",
"instanceof",
"ShadowLocaleBehavior",
")",
"{",
"$",
"locales",
"=",
"array_diff",
"(",
"$",
"locales",
",",
"array_keys",
"(",
"$",
"this",
"->",
"getShadowLocales",
"(",
"$",
"document",
")",
")",
")",
";",
"}",
"return",
"array_values",
"(",
"$",
"locales",
")",
";",
"}"
] | Return locales which are not shadows.
@param ShadowLocaleBehavior $document
@return array | [
"Return",
"locales",
"which",
"are",
"not",
"shadows",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php#L233-L242 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php | DocumentInspector.getShadowLocales | public function getShadowLocales(ShadowLocaleBehavior $document)
{
$shadowLocales = [];
$locales = $this->getLocales($document);
$node = $this->getNode($document);
foreach ($locales as $locale) {
$shadowEnabledName = $this->encoder->localizedSystemName(
ShadowLocaleSubscriber::SHADOW_ENABLED_FIELD,
$locale
);
$shadowLocaleName = $this->encoder->localizedSystemName(
ShadowLocaleSubscriber::SHADOW_LOCALE_FIELD,
$locale
);
if ($node->getPropertyValueWithDefault($shadowEnabledName, false)) {
$shadowLocales[$locale] = $node->getPropertyValue($shadowLocaleName);
}
}
return $shadowLocales;
} | php | public function getShadowLocales(ShadowLocaleBehavior $document)
{
$shadowLocales = [];
$locales = $this->getLocales($document);
$node = $this->getNode($document);
foreach ($locales as $locale) {
$shadowEnabledName = $this->encoder->localizedSystemName(
ShadowLocaleSubscriber::SHADOW_ENABLED_FIELD,
$locale
);
$shadowLocaleName = $this->encoder->localizedSystemName(
ShadowLocaleSubscriber::SHADOW_LOCALE_FIELD,
$locale
);
if ($node->getPropertyValueWithDefault($shadowEnabledName, false)) {
$shadowLocales[$locale] = $node->getPropertyValue($shadowLocaleName);
}
}
return $shadowLocales;
} | [
"public",
"function",
"getShadowLocales",
"(",
"ShadowLocaleBehavior",
"$",
"document",
")",
"{",
"$",
"shadowLocales",
"=",
"[",
"]",
";",
"$",
"locales",
"=",
"$",
"this",
"->",
"getLocales",
"(",
"$",
"document",
")",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"getNode",
"(",
"$",
"document",
")",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"locale",
")",
"{",
"$",
"shadowEnabledName",
"=",
"$",
"this",
"->",
"encoder",
"->",
"localizedSystemName",
"(",
"ShadowLocaleSubscriber",
"::",
"SHADOW_ENABLED_FIELD",
",",
"$",
"locale",
")",
";",
"$",
"shadowLocaleName",
"=",
"$",
"this",
"->",
"encoder",
"->",
"localizedSystemName",
"(",
"ShadowLocaleSubscriber",
"::",
"SHADOW_LOCALE_FIELD",
",",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"$",
"shadowEnabledName",
",",
"false",
")",
")",
"{",
"$",
"shadowLocales",
"[",
"$",
"locale",
"]",
"=",
"$",
"node",
"->",
"getPropertyValue",
"(",
"$",
"shadowLocaleName",
")",
";",
"}",
"}",
"return",
"$",
"shadowLocales",
";",
"}"
] | Return the enabled shadow locales for the given document.
@param ShadowLocaleBehavior $document
@return array | [
"Return",
"the",
"enabled",
"shadow",
"locales",
"for",
"the",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php#L251-L272 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php | DocumentInspector.getPublishedLocales | public function getPublishedLocales(ShadowLocaleBehavior $document)
{
$node = $this->getNode($document);
$locales = $this->getLocales($document);
$publishedLocales = [];
foreach ($locales as $locale) {
$publishedPropertyName = $this->encoder->localizedSystemName(
WorkflowStageSubscriber::PUBLISHED_FIELD,
$locale
);
if ($node->getPropertyValueWithDefault($publishedPropertyName, false)) {
$publishedLocales[] = $locale;
}
}
return $publishedLocales;
} | php | public function getPublishedLocales(ShadowLocaleBehavior $document)
{
$node = $this->getNode($document);
$locales = $this->getLocales($document);
$publishedLocales = [];
foreach ($locales as $locale) {
$publishedPropertyName = $this->encoder->localizedSystemName(
WorkflowStageSubscriber::PUBLISHED_FIELD,
$locale
);
if ($node->getPropertyValueWithDefault($publishedPropertyName, false)) {
$publishedLocales[] = $locale;
}
}
return $publishedLocales;
} | [
"public",
"function",
"getPublishedLocales",
"(",
"ShadowLocaleBehavior",
"$",
"document",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"getNode",
"(",
"$",
"document",
")",
";",
"$",
"locales",
"=",
"$",
"this",
"->",
"getLocales",
"(",
"$",
"document",
")",
";",
"$",
"publishedLocales",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"locale",
")",
"{",
"$",
"publishedPropertyName",
"=",
"$",
"this",
"->",
"encoder",
"->",
"localizedSystemName",
"(",
"WorkflowStageSubscriber",
"::",
"PUBLISHED_FIELD",
",",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"$",
"publishedPropertyName",
",",
"false",
")",
")",
"{",
"$",
"publishedLocales",
"[",
"]",
"=",
"$",
"locale",
";",
"}",
"}",
"return",
"$",
"publishedLocales",
";",
"}"
] | Return the published locales for the given document.
@param ShadowLocaleBehavior $document
@return array | [
"Return",
"the",
"published",
"locales",
"for",
"the",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php#L281-L299 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php | DocumentInspector.getLocalizedUrlsForPage | public function getLocalizedUrlsForPage(BasePageDocument $page)
{
$localizedUrls = [];
$webspaceKey = $this->getWebspace($page);
$webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey);
$node = $this->getNode($page);
$structure = $this->getStructureMetadata($page);
$resourceLocatorProperty = $structure->getPropertyByTagName('sulu.rlp');
foreach ($webspace->getAllLocalizations() as $localization) {
$resolvedLocale = $localization->getLocale();
$locale = $resolvedLocale;
$shadowEnabledName = $this->encoder->localizedSystemName(
ShadowLocaleSubscriber::SHADOW_ENABLED_FIELD,
$resolvedLocale
);
if (true === $node->getPropertyValueWithDefault($shadowEnabledName, false)) {
$shadowLocaleName = $this->encoder->localizedSystemName(
ShadowLocaleSubscriber::SHADOW_LOCALE_FIELD,
$resolvedLocale
);
$resolvedLocale = $node->getPropertyValue($shadowLocaleName);
}
$stageName = $this->encoder->localizedSystemName(
WorkflowStageSubscriber::WORKFLOW_STAGE_FIELD,
$resolvedLocale
);
if (false === $node->hasProperty($stageName)) {
continue;
}
$stage = $node->getProperty($stageName);
if (WorkflowStage::PUBLISHED !== $stage->getValue()) {
continue;
}
$url = $node->getPropertyValueWithDefault(
$this->encoder->localizedContentName($resourceLocatorProperty->getName(), $locale),
null
);
if (null === $url) {
continue;
}
$localizedUrls[$locale] = $url;
}
return $localizedUrls;
} | php | public function getLocalizedUrlsForPage(BasePageDocument $page)
{
$localizedUrls = [];
$webspaceKey = $this->getWebspace($page);
$webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey);
$node = $this->getNode($page);
$structure = $this->getStructureMetadata($page);
$resourceLocatorProperty = $structure->getPropertyByTagName('sulu.rlp');
foreach ($webspace->getAllLocalizations() as $localization) {
$resolvedLocale = $localization->getLocale();
$locale = $resolvedLocale;
$shadowEnabledName = $this->encoder->localizedSystemName(
ShadowLocaleSubscriber::SHADOW_ENABLED_FIELD,
$resolvedLocale
);
if (true === $node->getPropertyValueWithDefault($shadowEnabledName, false)) {
$shadowLocaleName = $this->encoder->localizedSystemName(
ShadowLocaleSubscriber::SHADOW_LOCALE_FIELD,
$resolvedLocale
);
$resolvedLocale = $node->getPropertyValue($shadowLocaleName);
}
$stageName = $this->encoder->localizedSystemName(
WorkflowStageSubscriber::WORKFLOW_STAGE_FIELD,
$resolvedLocale
);
if (false === $node->hasProperty($stageName)) {
continue;
}
$stage = $node->getProperty($stageName);
if (WorkflowStage::PUBLISHED !== $stage->getValue()) {
continue;
}
$url = $node->getPropertyValueWithDefault(
$this->encoder->localizedContentName($resourceLocatorProperty->getName(), $locale),
null
);
if (null === $url) {
continue;
}
$localizedUrls[$locale] = $url;
}
return $localizedUrls;
} | [
"public",
"function",
"getLocalizedUrlsForPage",
"(",
"BasePageDocument",
"$",
"page",
")",
"{",
"$",
"localizedUrls",
"=",
"[",
"]",
";",
"$",
"webspaceKey",
"=",
"$",
"this",
"->",
"getWebspace",
"(",
"$",
"page",
")",
";",
"$",
"webspace",
"=",
"$",
"this",
"->",
"webspaceManager",
"->",
"findWebspaceByKey",
"(",
"$",
"webspaceKey",
")",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"getNode",
"(",
"$",
"page",
")",
";",
"$",
"structure",
"=",
"$",
"this",
"->",
"getStructureMetadata",
"(",
"$",
"page",
")",
";",
"$",
"resourceLocatorProperty",
"=",
"$",
"structure",
"->",
"getPropertyByTagName",
"(",
"'sulu.rlp'",
")",
";",
"foreach",
"(",
"$",
"webspace",
"->",
"getAllLocalizations",
"(",
")",
"as",
"$",
"localization",
")",
"{",
"$",
"resolvedLocale",
"=",
"$",
"localization",
"->",
"getLocale",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"resolvedLocale",
";",
"$",
"shadowEnabledName",
"=",
"$",
"this",
"->",
"encoder",
"->",
"localizedSystemName",
"(",
"ShadowLocaleSubscriber",
"::",
"SHADOW_ENABLED_FIELD",
",",
"$",
"resolvedLocale",
")",
";",
"if",
"(",
"true",
"===",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"$",
"shadowEnabledName",
",",
"false",
")",
")",
"{",
"$",
"shadowLocaleName",
"=",
"$",
"this",
"->",
"encoder",
"->",
"localizedSystemName",
"(",
"ShadowLocaleSubscriber",
"::",
"SHADOW_LOCALE_FIELD",
",",
"$",
"resolvedLocale",
")",
";",
"$",
"resolvedLocale",
"=",
"$",
"node",
"->",
"getPropertyValue",
"(",
"$",
"shadowLocaleName",
")",
";",
"}",
"$",
"stageName",
"=",
"$",
"this",
"->",
"encoder",
"->",
"localizedSystemName",
"(",
"WorkflowStageSubscriber",
"::",
"WORKFLOW_STAGE_FIELD",
",",
"$",
"resolvedLocale",
")",
";",
"if",
"(",
"false",
"===",
"$",
"node",
"->",
"hasProperty",
"(",
"$",
"stageName",
")",
")",
"{",
"continue",
";",
"}",
"$",
"stage",
"=",
"$",
"node",
"->",
"getProperty",
"(",
"$",
"stageName",
")",
";",
"if",
"(",
"WorkflowStage",
"::",
"PUBLISHED",
"!==",
"$",
"stage",
"->",
"getValue",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"url",
"=",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"$",
"this",
"->",
"encoder",
"->",
"localizedContentName",
"(",
"$",
"resourceLocatorProperty",
"->",
"getName",
"(",
")",
",",
"$",
"locale",
")",
",",
"null",
")",
";",
"if",
"(",
"null",
"===",
"$",
"url",
")",
"{",
"continue",
";",
"}",
"$",
"localizedUrls",
"[",
"$",
"locale",
"]",
"=",
"$",
"url",
";",
"}",
"return",
"$",
"localizedUrls",
";",
"}"
] | Returns urls for given page for all locales in webspace.
TODO: Implement a router service instead of this.
@param BasePageDocument $page
@return array | [
"Returns",
"urls",
"for",
"given",
"page",
"for",
"all",
"locales",
"in",
"webspace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Bridge/DocumentInspector.php#L310-L365 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Controller/PageResourcelocatorController.php | PageResourcelocatorController.postGenerateAction | public function postGenerateAction(Request $request)
{
$parentUuid = $this->getRequestParameter($request, 'parent');
$parts = $this->getRequestParameter($request, 'parts', true);
$templateKey = $this->getRequestParameter($request, 'template', true);
$webspaceKey = $this->getRequestParameter($request, 'webspace', true);
$languageCode = $this->getLocale($request);
$result = $this->getResourceLocatorRepository()->generate(
$parts,
$parentUuid,
$webspaceKey,
$languageCode,
$templateKey
);
return $this->handleView($this->view($result));
} | php | public function postGenerateAction(Request $request)
{
$parentUuid = $this->getRequestParameter($request, 'parent');
$parts = $this->getRequestParameter($request, 'parts', true);
$templateKey = $this->getRequestParameter($request, 'template', true);
$webspaceKey = $this->getRequestParameter($request, 'webspace', true);
$languageCode = $this->getLocale($request);
$result = $this->getResourceLocatorRepository()->generate(
$parts,
$parentUuid,
$webspaceKey,
$languageCode,
$templateKey
);
return $this->handleView($this->view($result));
} | [
"public",
"function",
"postGenerateAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"parentUuid",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'parent'",
")",
";",
"$",
"parts",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'parts'",
",",
"true",
")",
";",
"$",
"templateKey",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'template'",
",",
"true",
")",
";",
"$",
"webspaceKey",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'webspace'",
",",
"true",
")",
";",
"$",
"languageCode",
"=",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"getResourceLocatorRepository",
"(",
")",
"->",
"generate",
"(",
"$",
"parts",
",",
"$",
"parentUuid",
",",
"$",
"webspaceKey",
",",
"$",
"languageCode",
",",
"$",
"templateKey",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"result",
")",
")",
";",
"}"
] | return resource-locator for sub-node.
@throws MissingArgumentException
@deprecated since 2.0, use ResourcelocatorController::postAction instead
@return Response | [
"return",
"resource",
"-",
"locator",
"for",
"sub",
"-",
"node",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Controller/PageResourcelocatorController.php#L36-L53 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Controller/PageResourcelocatorController.php | PageResourcelocatorController.cgetAction | public function cgetAction($id, Request $request)
{
list($webspaceKey, $languageCode) = $this->getWebspaceAndLanguage($request);
$result = $this->getResourceLocatorRepository()->getHistory($id, $webspaceKey, $languageCode);
return $this->handleView($this->view($result));
} | php | public function cgetAction($id, Request $request)
{
list($webspaceKey, $languageCode) = $this->getWebspaceAndLanguage($request);
$result = $this->getResourceLocatorRepository()->getHistory($id, $webspaceKey, $languageCode);
return $this->handleView($this->view($result));
} | [
"public",
"function",
"cgetAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"list",
"(",
"$",
"webspaceKey",
",",
"$",
"languageCode",
")",
"=",
"$",
"this",
"->",
"getWebspaceAndLanguage",
"(",
"$",
"request",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"getResourceLocatorRepository",
"(",
")",
"->",
"getHistory",
"(",
"$",
"id",
",",
"$",
"webspaceKey",
",",
"$",
"languageCode",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"result",
")",
")",
";",
"}"
] | return all resource locators for given node.
@param string $id
@param Request $request
@return Response | [
"return",
"all",
"resource",
"locators",
"for",
"given",
"node",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Controller/PageResourcelocatorController.php#L63-L69 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Controller/PageResourcelocatorController.php | PageResourcelocatorController.cdeleteAction | public function cdeleteAction($id, Request $request)
{
list($webspaceKey, $languageCode) = $this->getWebspaceAndLanguage($request);
$path = $this->getRequestParameter($request, 'ids', true); // TODO rename path to id in all function names
$this->getResourceLocatorRepository()->delete($path, $webspaceKey, $languageCode);
$this->getDocumentManager()->flush();
return $this->handleView($this->view());
} | php | public function cdeleteAction($id, Request $request)
{
list($webspaceKey, $languageCode) = $this->getWebspaceAndLanguage($request);
$path = $this->getRequestParameter($request, 'ids', true); // TODO rename path to id in all function names
$this->getResourceLocatorRepository()->delete($path, $webspaceKey, $languageCode);
$this->getDocumentManager()->flush();
return $this->handleView($this->view());
} | [
"public",
"function",
"cdeleteAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"list",
"(",
"$",
"webspaceKey",
",",
"$",
"languageCode",
")",
"=",
"$",
"this",
"->",
"getWebspaceAndLanguage",
"(",
"$",
"request",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'ids'",
",",
"true",
")",
";",
"// TODO rename path to id in all function names",
"$",
"this",
"->",
"getResourceLocatorRepository",
"(",
")",
"->",
"delete",
"(",
"$",
"path",
",",
"$",
"webspaceKey",
",",
"$",
"languageCode",
")",
";",
"$",
"this",
"->",
"getDocumentManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
")",
")",
";",
"}"
] | deletes resource locator with given path.
@param string $id
@param Request $request
@return Response | [
"deletes",
"resource",
"locator",
"with",
"given",
"path",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Controller/PageResourcelocatorController.php#L79-L88 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Controller/PageResourcelocatorController.php | PageResourcelocatorController.getWebspaceAndLanguage | private function getWebspaceAndLanguage(Request $request)
{
$webspaceKey = $this->getRequestParameter($request, 'webspace', true);
$languageCode = $this->getRequestParameter($request, 'language', true);
return [$webspaceKey, $languageCode];
} | php | private function getWebspaceAndLanguage(Request $request)
{
$webspaceKey = $this->getRequestParameter($request, 'webspace', true);
$languageCode = $this->getRequestParameter($request, 'language', true);
return [$webspaceKey, $languageCode];
} | [
"private",
"function",
"getWebspaceAndLanguage",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"webspaceKey",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'webspace'",
",",
"true",
")",
";",
"$",
"languageCode",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'language'",
",",
"true",
")",
";",
"return",
"[",
"$",
"webspaceKey",
",",
"$",
"languageCode",
"]",
";",
"}"
] | returns webspacekey and languagecode.
@param Request $request
@return array list($webspaceKey, $languageCode) | [
"returns",
"webspacekey",
"and",
"languagecode",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Controller/PageResourcelocatorController.php#L97-L103 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Navigation/NavigationMapper.php | NavigationMapper.generateNavigation | private function generateNavigation(
$contents,
$webspace,
$language,
$flat = false,
$context = null,
$breakOnNotInNavigation = false,
$recursive = true
) {
$result = [];
/** @var StructureInterface $content */
foreach ($contents as $content) {
if ($this->inNavigation($content, $context)) {
$url = $content->getResourceLocator();
$title = $content->getNodeName();
$children = $recursive ? $this->generateChildNavigation($content, $webspace, $language, $flat, $context) : [];
if (false === $flat) {
$result[] = new NavigationItem(
$title,
$url,
isset($content->getExt()['excerpt']) ? $content->getExt()['excerpt'] : null,
$children,
$content->getUuid(),
$content->getNodeType()
);
} else {
$result[] = new NavigationItem(
$title,
$url,
isset($content->getExt()['excerpt']) ? $content->getExt()['excerpt'] : null,
null,
$content->getUuid(),
$content->getNodeType()
);
$result = array_merge($result, $children);
}
} elseif (true === $flat) {
$children = $recursive ? $this->generateChildNavigation($content, $webspace, $language, $flat, $context) : [];
$result = array_merge($result, $children);
} elseif ($breakOnNotInNavigation) {
break;
}
}
return $result;
} | php | private function generateNavigation(
$contents,
$webspace,
$language,
$flat = false,
$context = null,
$breakOnNotInNavigation = false,
$recursive = true
) {
$result = [];
/** @var StructureInterface $content */
foreach ($contents as $content) {
if ($this->inNavigation($content, $context)) {
$url = $content->getResourceLocator();
$title = $content->getNodeName();
$children = $recursive ? $this->generateChildNavigation($content, $webspace, $language, $flat, $context) : [];
if (false === $flat) {
$result[] = new NavigationItem(
$title,
$url,
isset($content->getExt()['excerpt']) ? $content->getExt()['excerpt'] : null,
$children,
$content->getUuid(),
$content->getNodeType()
);
} else {
$result[] = new NavigationItem(
$title,
$url,
isset($content->getExt()['excerpt']) ? $content->getExt()['excerpt'] : null,
null,
$content->getUuid(),
$content->getNodeType()
);
$result = array_merge($result, $children);
}
} elseif (true === $flat) {
$children = $recursive ? $this->generateChildNavigation($content, $webspace, $language, $flat, $context) : [];
$result = array_merge($result, $children);
} elseif ($breakOnNotInNavigation) {
break;
}
}
return $result;
} | [
"private",
"function",
"generateNavigation",
"(",
"$",
"contents",
",",
"$",
"webspace",
",",
"$",
"language",
",",
"$",
"flat",
"=",
"false",
",",
"$",
"context",
"=",
"null",
",",
"$",
"breakOnNotInNavigation",
"=",
"false",
",",
"$",
"recursive",
"=",
"true",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"/** @var StructureInterface $content */",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"content",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"inNavigation",
"(",
"$",
"content",
",",
"$",
"context",
")",
")",
"{",
"$",
"url",
"=",
"$",
"content",
"->",
"getResourceLocator",
"(",
")",
";",
"$",
"title",
"=",
"$",
"content",
"->",
"getNodeName",
"(",
")",
";",
"$",
"children",
"=",
"$",
"recursive",
"?",
"$",
"this",
"->",
"generateChildNavigation",
"(",
"$",
"content",
",",
"$",
"webspace",
",",
"$",
"language",
",",
"$",
"flat",
",",
"$",
"context",
")",
":",
"[",
"]",
";",
"if",
"(",
"false",
"===",
"$",
"flat",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"new",
"NavigationItem",
"(",
"$",
"title",
",",
"$",
"url",
",",
"isset",
"(",
"$",
"content",
"->",
"getExt",
"(",
")",
"[",
"'excerpt'",
"]",
")",
"?",
"$",
"content",
"->",
"getExt",
"(",
")",
"[",
"'excerpt'",
"]",
":",
"null",
",",
"$",
"children",
",",
"$",
"content",
"->",
"getUuid",
"(",
")",
",",
"$",
"content",
"->",
"getNodeType",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"new",
"NavigationItem",
"(",
"$",
"title",
",",
"$",
"url",
",",
"isset",
"(",
"$",
"content",
"->",
"getExt",
"(",
")",
"[",
"'excerpt'",
"]",
")",
"?",
"$",
"content",
"->",
"getExt",
"(",
")",
"[",
"'excerpt'",
"]",
":",
"null",
",",
"null",
",",
"$",
"content",
"->",
"getUuid",
"(",
")",
",",
"$",
"content",
"->",
"getNodeType",
"(",
")",
")",
";",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"children",
")",
";",
"}",
"}",
"elseif",
"(",
"true",
"===",
"$",
"flat",
")",
"{",
"$",
"children",
"=",
"$",
"recursive",
"?",
"$",
"this",
"->",
"generateChildNavigation",
"(",
"$",
"content",
",",
"$",
"webspace",
",",
"$",
"language",
",",
"$",
"flat",
",",
"$",
"context",
")",
":",
"[",
"]",
";",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"children",
")",
";",
"}",
"elseif",
"(",
"$",
"breakOnNotInNavigation",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | generate navigation items for given contents. | [
"generate",
"navigation",
"items",
"for",
"given",
"contents",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Navigation/NavigationMapper.php#L157-L204 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.