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 |
---|---|---|---|---|---|---|---|---|---|---|---|
netgen-layouts/layouts-core | bundles/BlockManagerAdminBundle/EventListener/LayoutView/RelatedLayoutsCountListener.php | RelatedLayoutsCountListener.onBuildView | public function onBuildView(CollectViewParametersEvent $event): void
{
$view = $event->getView();
if (!$view instanceof LayoutViewInterface) {
return;
}
if ($view->getContext() !== ViewInterface::CONTEXT_ADMIN) {
return;
}
$layout = $view->getLayout();
$relatedLayoutsCount = 0;
if ($layout->isShared() && $layout->isPublished()) {
$relatedLayoutsCount = $this->layoutService->getRelatedLayoutsCount($layout);
}
$event->addParameter('related_layouts_count', $relatedLayoutsCount);
} | php | public function onBuildView(CollectViewParametersEvent $event): void
{
$view = $event->getView();
if (!$view instanceof LayoutViewInterface) {
return;
}
if ($view->getContext() !== ViewInterface::CONTEXT_ADMIN) {
return;
}
$layout = $view->getLayout();
$relatedLayoutsCount = 0;
if ($layout->isShared() && $layout->isPublished()) {
$relatedLayoutsCount = $this->layoutService->getRelatedLayoutsCount($layout);
}
$event->addParameter('related_layouts_count', $relatedLayoutsCount);
} | [
"public",
"function",
"onBuildView",
"(",
"CollectViewParametersEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"view",
"=",
"$",
"event",
"->",
"getView",
"(",
")",
";",
"if",
"(",
"!",
"$",
"view",
"instanceof",
"LayoutViewInterface",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"view",
"->",
"getContext",
"(",
")",
"!==",
"ViewInterface",
"::",
"CONTEXT_ADMIN",
")",
"{",
"return",
";",
"}",
"$",
"layout",
"=",
"$",
"view",
"->",
"getLayout",
"(",
")",
";",
"$",
"relatedLayoutsCount",
"=",
"0",
";",
"if",
"(",
"$",
"layout",
"->",
"isShared",
"(",
")",
"&&",
"$",
"layout",
"->",
"isPublished",
"(",
")",
")",
"{",
"$",
"relatedLayoutsCount",
"=",
"$",
"this",
"->",
"layoutService",
"->",
"getRelatedLayoutsCount",
"(",
"$",
"layout",
")",
";",
"}",
"$",
"event",
"->",
"addParameter",
"(",
"'related_layouts_count'",
",",
"$",
"relatedLayoutsCount",
")",
";",
"}"
]
| Injects the number of layouts connected to the shared layout
provided by the event. | [
"Injects",
"the",
"number",
"of",
"layouts",
"connected",
"to",
"the",
"shared",
"layout",
"provided",
"by",
"the",
"event",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerAdminBundle/EventListener/LayoutView/RelatedLayoutsCountListener.php#L35-L54 | train |
netgen-layouts/layouts-core | lib/API/Values/Config/ConfigStruct.php | ConfigStruct.fillParametersFromHash | public function fillParametersFromHash(ConfigDefinitionInterface $configDefinition, array $values, bool $doImport = false): void
{
$this->fillFromHash($configDefinition, $values, $doImport);
} | php | public function fillParametersFromHash(ConfigDefinitionInterface $configDefinition, array $values, bool $doImport = false): void
{
$this->fillFromHash($configDefinition, $values, $doImport);
} | [
"public",
"function",
"fillParametersFromHash",
"(",
"ConfigDefinitionInterface",
"$",
"configDefinition",
",",
"array",
"$",
"values",
",",
"bool",
"$",
"doImport",
"=",
"false",
")",
":",
"void",
"{",
"$",
"this",
"->",
"fillFromHash",
"(",
"$",
"configDefinition",
",",
"$",
"values",
",",
"$",
"doImport",
")",
";",
"}"
]
| Fills the parameter values based on provided array of values.
If any of the parameters is missing from the input array, the default value
based on parameter definition from the config definition will be used.
The values in the array need to be in hash format of the value
i.e. the format acceptable by the ParameterTypeInterface::fromHash method.
If $doImport is set to true, the values will be considered as coming from an import,
meaning it will be processed using ParameterTypeInterface::import method instead of
ParameterTypeInterface::fromHash method. | [
"Fills",
"the",
"parameter",
"values",
"based",
"on",
"provided",
"array",
"of",
"values",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/API/Values/Config/ConfigStruct.php#L36-L39 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/EventListener/AjaxBlockRequestListener.php | AjaxBlockRequestListener.onKernelRequest | public function onKernelRequest(GetResponseEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
if ($request->attributes->get('_route') !== 'ngbm_ajax_block') {
return;
}
if ($request->attributes->has('ngbmContextUri')) {
return;
}
// This is a naive implementation which removes the need to deconstruct
// the URI with parse_url/parse_str and then rebuilding it, just to remove
// a single query parameter with a known name and format.
$requestUri = preg_replace(
['/&page=\d+/', '/\?page=\d+&/', '/\?page=\d+/'],
['', '?', ''],
$request->getRequestUri()
);
$request->attributes->set('ngbmContextUri', $requestUri);
} | php | public function onKernelRequest(GetResponseEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
if ($request->attributes->get('_route') !== 'ngbm_ajax_block') {
return;
}
if ($request->attributes->has('ngbmContextUri')) {
return;
}
// This is a naive implementation which removes the need to deconstruct
// the URI with parse_url/parse_str and then rebuilding it, just to remove
// a single query parameter with a known name and format.
$requestUri = preg_replace(
['/&page=\d+/', '/\?page=\d+&/', '/\?page=\d+/'],
['', '?', ''],
$request->getRequestUri()
);
$request->attributes->set('ngbmContextUri', $requestUri);
} | [
"public",
"function",
"onKernelRequest",
"(",
"GetResponseEvent",
"$",
"event",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"isMasterRequest",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_route'",
")",
"!==",
"'ngbm_ajax_block'",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"has",
"(",
"'ngbmContextUri'",
")",
")",
"{",
"return",
";",
"}",
"// This is a naive implementation which removes the need to deconstruct",
"// the URI with parse_url/parse_str and then rebuilding it, just to remove",
"// a single query parameter with a known name and format.",
"$",
"requestUri",
"=",
"preg_replace",
"(",
"[",
"'/&page=\\d+/'",
",",
"'/\\?page=\\d+&/'",
",",
"'/\\?page=\\d+/'",
"]",
",",
"[",
"''",
",",
"'?'",
",",
"''",
"]",
",",
"$",
"request",
"->",
"getRequestUri",
"(",
")",
")",
";",
"$",
"request",
"->",
"attributes",
"->",
"set",
"(",
"'ngbmContextUri'",
",",
"$",
"requestUri",
")",
";",
"}"
]
| Removes the "page" query parameter from the AJAX block request URI
in order to remove the need to hash the page number, which greatly
simplifies generating URIs to single pages of AJAX block request.
If we were to hash the page parameter too, JavaScript code would not
be able to generate the link to a single page simply by changing the
page number. | [
"Removes",
"the",
"page",
"query",
"parameter",
"from",
"the",
"AJAX",
"block",
"request",
"URI",
"in",
"order",
"to",
"remove",
"the",
"need",
"to",
"hash",
"the",
"page",
"number",
"which",
"greatly",
"simplifies",
"generating",
"URIs",
"to",
"single",
"pages",
"of",
"AJAX",
"block",
"request",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/EventListener/AjaxBlockRequestListener.php#L28-L53 | train |
netgen-layouts/layouts-core | lib/Serializer/Normalizer/V1/LayoutNormalizer.php | LayoutNormalizer.getZones | private function getZones(Layout $layout, LayoutTypeInterface $layoutType): Generator
{
foreach ($layout as $zoneIdentifier => $zone) {
$linkedZone = $zone->getLinkedZone();
yield [
'identifier' => $zoneIdentifier,
'name' => $this->getZoneName($zone, $layoutType),
'block_ids' => $this->blockService->loadZoneBlocks($zone)->getBlockIds(),
'allowed_block_definitions' => $this->getAllowedBlocks(
$zone,
$layoutType
),
'linked_layout_id' => $linkedZone ? $linkedZone->getLayoutId() : null,
'linked_zone_identifier' => $linkedZone ? $linkedZone->getIdentifier() : null,
];
}
} | php | private function getZones(Layout $layout, LayoutTypeInterface $layoutType): Generator
{
foreach ($layout as $zoneIdentifier => $zone) {
$linkedZone = $zone->getLinkedZone();
yield [
'identifier' => $zoneIdentifier,
'name' => $this->getZoneName($zone, $layoutType),
'block_ids' => $this->blockService->loadZoneBlocks($zone)->getBlockIds(),
'allowed_block_definitions' => $this->getAllowedBlocks(
$zone,
$layoutType
),
'linked_layout_id' => $linkedZone ? $linkedZone->getLayoutId() : null,
'linked_zone_identifier' => $linkedZone ? $linkedZone->getIdentifier() : null,
];
}
} | [
"private",
"function",
"getZones",
"(",
"Layout",
"$",
"layout",
",",
"LayoutTypeInterface",
"$",
"layoutType",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"layout",
"as",
"$",
"zoneIdentifier",
"=>",
"$",
"zone",
")",
"{",
"$",
"linkedZone",
"=",
"$",
"zone",
"->",
"getLinkedZone",
"(",
")",
";",
"yield",
"[",
"'identifier'",
"=>",
"$",
"zoneIdentifier",
",",
"'name'",
"=>",
"$",
"this",
"->",
"getZoneName",
"(",
"$",
"zone",
",",
"$",
"layoutType",
")",
",",
"'block_ids'",
"=>",
"$",
"this",
"->",
"blockService",
"->",
"loadZoneBlocks",
"(",
"$",
"zone",
")",
"->",
"getBlockIds",
"(",
")",
",",
"'allowed_block_definitions'",
"=>",
"$",
"this",
"->",
"getAllowedBlocks",
"(",
"$",
"zone",
",",
"$",
"layoutType",
")",
",",
"'linked_layout_id'",
"=>",
"$",
"linkedZone",
"?",
"$",
"linkedZone",
"->",
"getLayoutId",
"(",
")",
":",
"null",
",",
"'linked_zone_identifier'",
"=>",
"$",
"linkedZone",
"?",
"$",
"linkedZone",
"->",
"getIdentifier",
"(",
")",
":",
"null",
",",
"]",
";",
"}",
"}"
]
| Returns the array with layout zones. | [
"Returns",
"the",
"array",
"with",
"layout",
"zones",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Serializer/Normalizer/V1/LayoutNormalizer.php#L93-L110 | train |
netgen-layouts/layouts-core | lib/Serializer/Normalizer/V1/LayoutNormalizer.php | LayoutNormalizer.getZoneName | private function getZoneName(Zone $zone, LayoutTypeInterface $layoutType): string
{
if ($layoutType->hasZone($zone->getIdentifier())) {
return $layoutType->getZone($zone->getIdentifier())->getName();
}
return $zone->getIdentifier();
} | php | private function getZoneName(Zone $zone, LayoutTypeInterface $layoutType): string
{
if ($layoutType->hasZone($zone->getIdentifier())) {
return $layoutType->getZone($zone->getIdentifier())->getName();
}
return $zone->getIdentifier();
} | [
"private",
"function",
"getZoneName",
"(",
"Zone",
"$",
"zone",
",",
"LayoutTypeInterface",
"$",
"layoutType",
")",
":",
"string",
"{",
"if",
"(",
"$",
"layoutType",
"->",
"hasZone",
"(",
"$",
"zone",
"->",
"getIdentifier",
"(",
")",
")",
")",
"{",
"return",
"$",
"layoutType",
"->",
"getZone",
"(",
"$",
"zone",
"->",
"getIdentifier",
"(",
")",
")",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"zone",
"->",
"getIdentifier",
"(",
")",
";",
"}"
]
| Returns provided zone name. | [
"Returns",
"provided",
"zone",
"name",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Serializer/Normalizer/V1/LayoutNormalizer.php#L115-L122 | train |
netgen-layouts/layouts-core | lib/Serializer/Normalizer/V1/LayoutNormalizer.php | LayoutNormalizer.getAllowedBlocks | private function getAllowedBlocks(Zone $zone, LayoutTypeInterface $layoutType)
{
if ($layoutType->hasZone($zone->getIdentifier())) {
$layoutTypeZone = $layoutType->getZone($zone->getIdentifier());
$allowedBlockDefinitions = $layoutTypeZone->getAllowedBlockDefinitions();
if (count($allowedBlockDefinitions) > 0) {
return $allowedBlockDefinitions;
}
}
return true;
} | php | private function getAllowedBlocks(Zone $zone, LayoutTypeInterface $layoutType)
{
if ($layoutType->hasZone($zone->getIdentifier())) {
$layoutTypeZone = $layoutType->getZone($zone->getIdentifier());
$allowedBlockDefinitions = $layoutTypeZone->getAllowedBlockDefinitions();
if (count($allowedBlockDefinitions) > 0) {
return $allowedBlockDefinitions;
}
}
return true;
} | [
"private",
"function",
"getAllowedBlocks",
"(",
"Zone",
"$",
"zone",
",",
"LayoutTypeInterface",
"$",
"layoutType",
")",
"{",
"if",
"(",
"$",
"layoutType",
"->",
"hasZone",
"(",
"$",
"zone",
"->",
"getIdentifier",
"(",
")",
")",
")",
"{",
"$",
"layoutTypeZone",
"=",
"$",
"layoutType",
"->",
"getZone",
"(",
"$",
"zone",
"->",
"getIdentifier",
"(",
")",
")",
";",
"$",
"allowedBlockDefinitions",
"=",
"$",
"layoutTypeZone",
"->",
"getAllowedBlockDefinitions",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"allowedBlockDefinitions",
")",
">",
"0",
")",
"{",
"return",
"$",
"allowedBlockDefinitions",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Returns all allowed block definitions from provided zone or
true if all block definitions are allowed.
@param \Netgen\BlockManager\API\Values\Layout\Zone $zone
@param \Netgen\BlockManager\Layout\Type\LayoutTypeInterface $layoutType
@return string[]|bool | [
"Returns",
"all",
"allowed",
"block",
"definitions",
"from",
"provided",
"zone",
"or",
"true",
"if",
"all",
"block",
"definitions",
"are",
"allowed",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Serializer/Normalizer/V1/LayoutNormalizer.php#L133-L145 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Block/BlockTypeGroupPass.php | BlockTypeGroupPass.generateBlockTypeGroupConfig | private function generateBlockTypeGroupConfig(array $blockTypeGroups, array $blockTypes): array
{
$missingBlockTypes = [];
// We will add all blocks which are not located in any group to a custom group
// if it exists
if (isset($blockTypeGroups['custom'])) {
foreach (array_keys($blockTypes) as $blockType) {
foreach ($blockTypeGroups as $blockTypeGroup) {
if (in_array($blockType, $blockTypeGroup['block_types'], true)) {
continue 2;
}
}
$missingBlockTypes[] = $blockType;
}
$blockTypeGroups['custom']['block_types'] = array_merge(
$blockTypeGroups['custom']['block_types'],
$missingBlockTypes
);
}
return $blockTypeGroups;
} | php | private function generateBlockTypeGroupConfig(array $blockTypeGroups, array $blockTypes): array
{
$missingBlockTypes = [];
// We will add all blocks which are not located in any group to a custom group
// if it exists
if (isset($blockTypeGroups['custom'])) {
foreach (array_keys($blockTypes) as $blockType) {
foreach ($blockTypeGroups as $blockTypeGroup) {
if (in_array($blockType, $blockTypeGroup['block_types'], true)) {
continue 2;
}
}
$missingBlockTypes[] = $blockType;
}
$blockTypeGroups['custom']['block_types'] = array_merge(
$blockTypeGroups['custom']['block_types'],
$missingBlockTypes
);
}
return $blockTypeGroups;
} | [
"private",
"function",
"generateBlockTypeGroupConfig",
"(",
"array",
"$",
"blockTypeGroups",
",",
"array",
"$",
"blockTypes",
")",
":",
"array",
"{",
"$",
"missingBlockTypes",
"=",
"[",
"]",
";",
"// We will add all blocks which are not located in any group to a custom group",
"// if it exists",
"if",
"(",
"isset",
"(",
"$",
"blockTypeGroups",
"[",
"'custom'",
"]",
")",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"blockTypes",
")",
"as",
"$",
"blockType",
")",
"{",
"foreach",
"(",
"$",
"blockTypeGroups",
"as",
"$",
"blockTypeGroup",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"blockType",
",",
"$",
"blockTypeGroup",
"[",
"'block_types'",
"]",
",",
"true",
")",
")",
"{",
"continue",
"2",
";",
"}",
"}",
"$",
"missingBlockTypes",
"[",
"]",
"=",
"$",
"blockType",
";",
"}",
"$",
"blockTypeGroups",
"[",
"'custom'",
"]",
"[",
"'block_types'",
"]",
"=",
"array_merge",
"(",
"$",
"blockTypeGroups",
"[",
"'custom'",
"]",
"[",
"'block_types'",
"]",
",",
"$",
"missingBlockTypes",
")",
";",
"}",
"return",
"$",
"blockTypeGroups",
";",
"}"
]
| Generates the block type group configuration from provided block types. | [
"Generates",
"the",
"block",
"type",
"group",
"configuration",
"from",
"provided",
"block",
"types",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Block/BlockTypeGroupPass.php#L40-L64 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Block/BlockTypeGroupPass.php | BlockTypeGroupPass.buildBlockTypeGroups | private function buildBlockTypeGroups(ContainerBuilder $container, array $blockTypeGroups, array $blockTypes): Generator
{
foreach ($blockTypeGroups as $identifier => $blockTypeGroup) {
$serviceIdentifier = sprintf('netgen_block_manager.block.block_type_group.%s', $identifier);
$blockTypeReferences = [];
foreach ($blockTypeGroup['block_types'] as $blockTypeIdentifier) {
if (isset($blockTypes[$blockTypeIdentifier])) {
$blockTypeReferences[] = new Reference(
sprintf(
'netgen_block_manager.block.block_type.%s',
$blockTypeIdentifier
)
);
}
}
$container->register($serviceIdentifier, BlockTypeGroup::class)
->setArguments([$identifier, $blockTypeGroup, $blockTypeReferences])
->setLazy(true)
->setPublic(true)
->setFactory([BlockTypeGroupFactory::class, 'buildBlockTypeGroup']);
yield $identifier => new Reference($serviceIdentifier);
}
} | php | private function buildBlockTypeGroups(ContainerBuilder $container, array $blockTypeGroups, array $blockTypes): Generator
{
foreach ($blockTypeGroups as $identifier => $blockTypeGroup) {
$serviceIdentifier = sprintf('netgen_block_manager.block.block_type_group.%s', $identifier);
$blockTypeReferences = [];
foreach ($blockTypeGroup['block_types'] as $blockTypeIdentifier) {
if (isset($blockTypes[$blockTypeIdentifier])) {
$blockTypeReferences[] = new Reference(
sprintf(
'netgen_block_manager.block.block_type.%s',
$blockTypeIdentifier
)
);
}
}
$container->register($serviceIdentifier, BlockTypeGroup::class)
->setArguments([$identifier, $blockTypeGroup, $blockTypeReferences])
->setLazy(true)
->setPublic(true)
->setFactory([BlockTypeGroupFactory::class, 'buildBlockTypeGroup']);
yield $identifier => new Reference($serviceIdentifier);
}
} | [
"private",
"function",
"buildBlockTypeGroups",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"blockTypeGroups",
",",
"array",
"$",
"blockTypes",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"blockTypeGroups",
"as",
"$",
"identifier",
"=>",
"$",
"blockTypeGroup",
")",
"{",
"$",
"serviceIdentifier",
"=",
"sprintf",
"(",
"'netgen_block_manager.block.block_type_group.%s'",
",",
"$",
"identifier",
")",
";",
"$",
"blockTypeReferences",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"blockTypeGroup",
"[",
"'block_types'",
"]",
"as",
"$",
"blockTypeIdentifier",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"blockTypes",
"[",
"$",
"blockTypeIdentifier",
"]",
")",
")",
"{",
"$",
"blockTypeReferences",
"[",
"]",
"=",
"new",
"Reference",
"(",
"sprintf",
"(",
"'netgen_block_manager.block.block_type.%s'",
",",
"$",
"blockTypeIdentifier",
")",
")",
";",
"}",
"}",
"$",
"container",
"->",
"register",
"(",
"$",
"serviceIdentifier",
",",
"BlockTypeGroup",
"::",
"class",
")",
"->",
"setArguments",
"(",
"[",
"$",
"identifier",
",",
"$",
"blockTypeGroup",
",",
"$",
"blockTypeReferences",
"]",
")",
"->",
"setLazy",
"(",
"true",
")",
"->",
"setPublic",
"(",
"true",
")",
"->",
"setFactory",
"(",
"[",
"BlockTypeGroupFactory",
"::",
"class",
",",
"'buildBlockTypeGroup'",
"]",
")",
";",
"yield",
"$",
"identifier",
"=>",
"new",
"Reference",
"(",
"$",
"serviceIdentifier",
")",
";",
"}",
"}"
]
| Builds the block type group objects from provided configuration. | [
"Builds",
"the",
"block",
"type",
"group",
"objects",
"from",
"provided",
"configuration",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Block/BlockTypeGroupPass.php#L69-L94 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.loadBlockData | public function loadBlockData($blockId, int $status): array
{
$query = $this->getBlockSelectQuery();
$query->where(
$query->expr()->eq('b.id', ':id')
)
->setParameter('id', $blockId, Type::INTEGER);
$this->applyStatusCondition($query, $status, 'b.status');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | php | public function loadBlockData($blockId, int $status): array
{
$query = $this->getBlockSelectQuery();
$query->where(
$query->expr()->eq('b.id', ':id')
)
->setParameter('id', $blockId, Type::INTEGER);
$this->applyStatusCondition($query, $status, 'b.status');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | [
"public",
"function",
"loadBlockData",
"(",
"$",
"blockId",
",",
"int",
"$",
"status",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getBlockSelectQuery",
"(",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'b.id'",
",",
"':id'",
")",
")",
"->",
"setParameter",
"(",
"'id'",
",",
"$",
"blockId",
",",
"Type",
"::",
"INTEGER",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"status",
",",
"'b.status'",
")",
";",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
]
| Loads all block data.
@param int|string $blockId
@param int $status
@return array | [
"Loads",
"all",
"block",
"data",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L26-L37 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.loadCollectionReferencesData | public function loadCollectionReferencesData(Block $block, ?string $identifier = null): array
{
$query = $this->connection->createQueryBuilder();
$query->select('block_id', 'block_status', 'collection_id', 'collection_status', 'identifier')
->from('ngbm_block_collection')
->where(
$query->expr()->eq('block_id', ':block_id')
)
->setParameter('block_id', $block->id, Type::INTEGER)
->orderBy('identifier', 'ASC');
$this->applyStatusCondition($query, $block->status, 'block_status');
if ($identifier !== null) {
$query->andWhere($query->expr()->eq('identifier', ':identifier'))
->setParameter('identifier', $identifier, Type::STRING);
}
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | php | public function loadCollectionReferencesData(Block $block, ?string $identifier = null): array
{
$query = $this->connection->createQueryBuilder();
$query->select('block_id', 'block_status', 'collection_id', 'collection_status', 'identifier')
->from('ngbm_block_collection')
->where(
$query->expr()->eq('block_id', ':block_id')
)
->setParameter('block_id', $block->id, Type::INTEGER)
->orderBy('identifier', 'ASC');
$this->applyStatusCondition($query, $block->status, 'block_status');
if ($identifier !== null) {
$query->andWhere($query->expr()->eq('identifier', ':identifier'))
->setParameter('identifier', $identifier, Type::STRING);
}
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | [
"public",
"function",
"loadCollectionReferencesData",
"(",
"Block",
"$",
"block",
",",
"?",
"string",
"$",
"identifier",
"=",
"null",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"select",
"(",
"'block_id'",
",",
"'block_status'",
",",
"'collection_id'",
",",
"'collection_status'",
",",
"'identifier'",
")",
"->",
"from",
"(",
"'ngbm_block_collection'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'block_id'",
",",
"':block_id'",
")",
")",
"->",
"setParameter",
"(",
"'block_id'",
",",
"$",
"block",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"orderBy",
"(",
"'identifier'",
",",
"'ASC'",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"block",
"->",
"status",
",",
"'block_status'",
")",
";",
"if",
"(",
"$",
"identifier",
"!==",
"null",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'identifier'",
",",
"':identifier'",
")",
")",
"->",
"setParameter",
"(",
"'identifier'",
",",
"$",
"identifier",
",",
"Type",
"::",
"STRING",
")",
";",
"}",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
]
| Loads all collection reference data. | [
"Loads",
"all",
"collection",
"reference",
"data",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L42-L61 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.loadLayoutBlocksData | public function loadLayoutBlocksData(Layout $layout): array
{
$query = $this->getBlockSelectQuery();
$query->where(
$query->expr()->eq('b.layout_id', ':layout_id')
)
->setParameter('layout_id', $layout->id, Type::INTEGER);
$this->applyStatusCondition($query, $layout->status, 'b.status');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | php | public function loadLayoutBlocksData(Layout $layout): array
{
$query = $this->getBlockSelectQuery();
$query->where(
$query->expr()->eq('b.layout_id', ':layout_id')
)
->setParameter('layout_id', $layout->id, Type::INTEGER);
$this->applyStatusCondition($query, $layout->status, 'b.status');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | [
"public",
"function",
"loadLayoutBlocksData",
"(",
"Layout",
"$",
"layout",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getBlockSelectQuery",
"(",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'b.layout_id'",
",",
"':layout_id'",
")",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"layout",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"layout",
"->",
"status",
",",
"'b.status'",
")",
";",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
]
| Loads all layout block data. | [
"Loads",
"all",
"layout",
"block",
"data",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L66-L77 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.loadZoneBlocksData | public function loadZoneBlocksData(Zone $zone): array
{
$query = $this->getBlockSelectQuery();
$query->where(
$query->expr()->like('b.path', ':path')
)
->setParameter('path', '%/' . $zone->rootBlockId . '/%', Type::STRING);
$this->applyStatusCondition($query, $zone->status, 'b.status');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | php | public function loadZoneBlocksData(Zone $zone): array
{
$query = $this->getBlockSelectQuery();
$query->where(
$query->expr()->like('b.path', ':path')
)
->setParameter('path', '%/' . $zone->rootBlockId . '/%', Type::STRING);
$this->applyStatusCondition($query, $zone->status, 'b.status');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | [
"public",
"function",
"loadZoneBlocksData",
"(",
"Zone",
"$",
"zone",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getBlockSelectQuery",
"(",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"like",
"(",
"'b.path'",
",",
"':path'",
")",
")",
"->",
"setParameter",
"(",
"'path'",
",",
"'%/'",
".",
"$",
"zone",
"->",
"rootBlockId",
".",
"'/%'",
",",
"Type",
"::",
"STRING",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"zone",
"->",
"status",
",",
"'b.status'",
")",
";",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
]
| Loads all zone block data. | [
"Loads",
"all",
"zone",
"block",
"data",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L82-L93 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.loadChildBlocksData | public function loadChildBlocksData(Block $block, ?string $placeholder = null): array
{
$query = $this->getBlockSelectQuery();
$query->where(
$query->expr()->eq('b.parent_id', ':parent_id')
)
->setParameter('parent_id', $block->id, Type::INTEGER)
->addOrderBy('b.placeholder', 'ASC')
->addOrderBy('b.position', 'ASC');
if ($placeholder !== null) {
$query->andWhere(
$query->expr()->eq('b.placeholder', ':placeholder')
)
->setParameter('placeholder', $placeholder, Type::STRING);
}
$this->applyStatusCondition($query, $block->status, 'b.status');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | php | public function loadChildBlocksData(Block $block, ?string $placeholder = null): array
{
$query = $this->getBlockSelectQuery();
$query->where(
$query->expr()->eq('b.parent_id', ':parent_id')
)
->setParameter('parent_id', $block->id, Type::INTEGER)
->addOrderBy('b.placeholder', 'ASC')
->addOrderBy('b.position', 'ASC');
if ($placeholder !== null) {
$query->andWhere(
$query->expr()->eq('b.placeholder', ':placeholder')
)
->setParameter('placeholder', $placeholder, Type::STRING);
}
$this->applyStatusCondition($query, $block->status, 'b.status');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | [
"public",
"function",
"loadChildBlocksData",
"(",
"Block",
"$",
"block",
",",
"?",
"string",
"$",
"placeholder",
"=",
"null",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getBlockSelectQuery",
"(",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'b.parent_id'",
",",
"':parent_id'",
")",
")",
"->",
"setParameter",
"(",
"'parent_id'",
",",
"$",
"block",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"addOrderBy",
"(",
"'b.placeholder'",
",",
"'ASC'",
")",
"->",
"addOrderBy",
"(",
"'b.position'",
",",
"'ASC'",
")",
";",
"if",
"(",
"$",
"placeholder",
"!==",
"null",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'b.placeholder'",
",",
"':placeholder'",
")",
")",
"->",
"setParameter",
"(",
"'placeholder'",
",",
"$",
"placeholder",
",",
"Type",
"::",
"STRING",
")",
";",
"}",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"block",
"->",
"status",
",",
"'b.status'",
")",
";",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
]
| Loads all child block data from specified block, optionally filtered by placeholder. | [
"Loads",
"all",
"child",
"block",
"data",
"from",
"specified",
"block",
"optionally",
"filtered",
"by",
"placeholder",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L98-L118 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.createBlockTranslation | public function createBlockTranslation(Block $block, string $locale): void
{
$query = $this->connection->createQueryBuilder()
->insert('ngbm_block_translation')
->values(
[
'block_id' => ':block_id',
'status' => ':status',
'locale' => ':locale',
'parameters' => ':parameters',
]
)
->setParameter('block_id', $block->id, Type::INTEGER)
->setParameter('status', $block->status, Type::INTEGER)
->setParameter('locale', $locale, Type::STRING)
->setParameter('parameters', $block->parameters[$locale], Type::JSON_ARRAY);
$query->execute();
} | php | public function createBlockTranslation(Block $block, string $locale): void
{
$query = $this->connection->createQueryBuilder()
->insert('ngbm_block_translation')
->values(
[
'block_id' => ':block_id',
'status' => ':status',
'locale' => ':locale',
'parameters' => ':parameters',
]
)
->setParameter('block_id', $block->id, Type::INTEGER)
->setParameter('status', $block->status, Type::INTEGER)
->setParameter('locale', $locale, Type::STRING)
->setParameter('parameters', $block->parameters[$locale], Type::JSON_ARRAY);
$query->execute();
} | [
"public",
"function",
"createBlockTranslation",
"(",
"Block",
"$",
"block",
",",
"string",
"$",
"locale",
")",
":",
"void",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
"->",
"insert",
"(",
"'ngbm_block_translation'",
")",
"->",
"values",
"(",
"[",
"'block_id'",
"=>",
"':block_id'",
",",
"'status'",
"=>",
"':status'",
",",
"'locale'",
"=>",
"':locale'",
",",
"'parameters'",
"=>",
"':parameters'",
",",
"]",
")",
"->",
"setParameter",
"(",
"'block_id'",
",",
"$",
"block",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'status'",
",",
"$",
"block",
"->",
"status",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'locale'",
",",
"$",
"locale",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'parameters'",
",",
"$",
"block",
"->",
"parameters",
"[",
"$",
"locale",
"]",
",",
"Type",
"::",
"JSON_ARRAY",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
]
| Creates a block translation. | [
"Creates",
"a",
"block",
"translation",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L227-L245 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.createCollectionReference | public function createCollectionReference(CollectionReference $collectionReference): void
{
$query = $this->connection->createQueryBuilder();
$query->insert('ngbm_block_collection')
->values(
[
'block_id' => ':block_id',
'block_status' => ':block_status',
'collection_id' => ':collection_id',
'collection_status' => ':collection_status',
'identifier' => ':identifier',
]
)
->setParameter('block_id', $collectionReference->blockId, Type::INTEGER)
->setParameter('block_status', $collectionReference->blockStatus, Type::INTEGER)
->setParameter('collection_id', $collectionReference->collectionId, Type::INTEGER)
->setParameter('collection_status', $collectionReference->collectionStatus, Type::INTEGER)
->setParameter('identifier', $collectionReference->identifier, Type::STRING);
$query->execute();
} | php | public function createCollectionReference(CollectionReference $collectionReference): void
{
$query = $this->connection->createQueryBuilder();
$query->insert('ngbm_block_collection')
->values(
[
'block_id' => ':block_id',
'block_status' => ':block_status',
'collection_id' => ':collection_id',
'collection_status' => ':collection_status',
'identifier' => ':identifier',
]
)
->setParameter('block_id', $collectionReference->blockId, Type::INTEGER)
->setParameter('block_status', $collectionReference->blockStatus, Type::INTEGER)
->setParameter('collection_id', $collectionReference->collectionId, Type::INTEGER)
->setParameter('collection_status', $collectionReference->collectionStatus, Type::INTEGER)
->setParameter('identifier', $collectionReference->identifier, Type::STRING);
$query->execute();
} | [
"public",
"function",
"createCollectionReference",
"(",
"CollectionReference",
"$",
"collectionReference",
")",
":",
"void",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"insert",
"(",
"'ngbm_block_collection'",
")",
"->",
"values",
"(",
"[",
"'block_id'",
"=>",
"':block_id'",
",",
"'block_status'",
"=>",
"':block_status'",
",",
"'collection_id'",
"=>",
"':collection_id'",
",",
"'collection_status'",
"=>",
"':collection_status'",
",",
"'identifier'",
"=>",
"':identifier'",
",",
"]",
")",
"->",
"setParameter",
"(",
"'block_id'",
",",
"$",
"collectionReference",
"->",
"blockId",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'block_status'",
",",
"$",
"collectionReference",
"->",
"blockStatus",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'collection_id'",
",",
"$",
"collectionReference",
"->",
"collectionId",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'collection_status'",
",",
"$",
"collectionReference",
"->",
"collectionStatus",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'identifier'",
",",
"$",
"collectionReference",
"->",
"identifier",
",",
"Type",
"::",
"STRING",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
]
| Creates the collection reference. | [
"Creates",
"the",
"collection",
"reference",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L250-L271 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.updateBlockTranslation | public function updateBlockTranslation(Block $block, string $locale): void
{
$query = $this->connection->createQueryBuilder();
$query
->update('ngbm_block_translation')
->set('parameters', ':parameters')
->where(
$query->expr()->andX(
$query->expr()->eq('block_id', ':block_id'),
$query->expr()->eq('locale', ':locale')
)
)
->setParameter('block_id', $block->id, Type::INTEGER)
->setParameter('locale', $locale, Type::STRING)
->setParameter('parameters', $block->parameters[$locale], Type::JSON_ARRAY);
$this->applyStatusCondition($query, $block->status);
$query->execute();
} | php | public function updateBlockTranslation(Block $block, string $locale): void
{
$query = $this->connection->createQueryBuilder();
$query
->update('ngbm_block_translation')
->set('parameters', ':parameters')
->where(
$query->expr()->andX(
$query->expr()->eq('block_id', ':block_id'),
$query->expr()->eq('locale', ':locale')
)
)
->setParameter('block_id', $block->id, Type::INTEGER)
->setParameter('locale', $locale, Type::STRING)
->setParameter('parameters', $block->parameters[$locale], Type::JSON_ARRAY);
$this->applyStatusCondition($query, $block->status);
$query->execute();
} | [
"public",
"function",
"updateBlockTranslation",
"(",
"Block",
"$",
"block",
",",
"string",
"$",
"locale",
")",
":",
"void",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"update",
"(",
"'ngbm_block_translation'",
")",
"->",
"set",
"(",
"'parameters'",
",",
"':parameters'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'block_id'",
",",
"':block_id'",
")",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'locale'",
",",
"':locale'",
")",
")",
")",
"->",
"setParameter",
"(",
"'block_id'",
",",
"$",
"block",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'locale'",
",",
"$",
"locale",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'parameters'",
",",
"$",
"block",
"->",
"parameters",
"[",
"$",
"locale",
"]",
",",
"Type",
"::",
"JSON_ARRAY",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"block",
"->",
"status",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
]
| Updates a block translation. | [
"Updates",
"a",
"block",
"translation",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L322-L341 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.moveBlock | public function moveBlock(Block $block, Block $targetBlock, string $placeholder, int $position): void
{
$query = $this->connection->createQueryBuilder();
$query
->update('ngbm_block')
->set('position', ':position')
->set('parent_id', ':parent_id')
->set('placeholder', ':placeholder')
->where(
$query->expr()->eq('id', ':id')
)
->setParameter('id', $block->id, Type::INTEGER)
->setParameter('position', $position, Type::INTEGER)
->setParameter('parent_id', $targetBlock->id, Type::INTEGER)
->setParameter('placeholder', $placeholder, Type::STRING);
$this->applyStatusCondition($query, $block->status);
$query->execute();
$depthDifference = $block->depth - ($targetBlock->depth + 1);
$query = $this->connection->createQueryBuilder();
$query
->update('ngbm_block')
->set('layout_id', ':layout_id')
->set('depth', 'depth - :depth_difference')
->set('path', 'replace(path, :old_path, :new_path)')
->where(
$query->expr()->like('path', ':path')
)
->setParameter('layout_id', $targetBlock->layoutId, Type::INTEGER)
->setParameter('depth_difference', $depthDifference, Type::INTEGER)
->setParameter('old_path', $block->path, Type::STRING)
->setParameter('new_path', $targetBlock->path . $block->id . '/', Type::STRING)
->setParameter('path', $block->path . '%', Type::STRING);
$this->applyStatusCondition($query, $block->status);
$query->execute();
} | php | public function moveBlock(Block $block, Block $targetBlock, string $placeholder, int $position): void
{
$query = $this->connection->createQueryBuilder();
$query
->update('ngbm_block')
->set('position', ':position')
->set('parent_id', ':parent_id')
->set('placeholder', ':placeholder')
->where(
$query->expr()->eq('id', ':id')
)
->setParameter('id', $block->id, Type::INTEGER)
->setParameter('position', $position, Type::INTEGER)
->setParameter('parent_id', $targetBlock->id, Type::INTEGER)
->setParameter('placeholder', $placeholder, Type::STRING);
$this->applyStatusCondition($query, $block->status);
$query->execute();
$depthDifference = $block->depth - ($targetBlock->depth + 1);
$query = $this->connection->createQueryBuilder();
$query
->update('ngbm_block')
->set('layout_id', ':layout_id')
->set('depth', 'depth - :depth_difference')
->set('path', 'replace(path, :old_path, :new_path)')
->where(
$query->expr()->like('path', ':path')
)
->setParameter('layout_id', $targetBlock->layoutId, Type::INTEGER)
->setParameter('depth_difference', $depthDifference, Type::INTEGER)
->setParameter('old_path', $block->path, Type::STRING)
->setParameter('new_path', $targetBlock->path . $block->id . '/', Type::STRING)
->setParameter('path', $block->path . '%', Type::STRING);
$this->applyStatusCondition($query, $block->status);
$query->execute();
} | [
"public",
"function",
"moveBlock",
"(",
"Block",
"$",
"block",
",",
"Block",
"$",
"targetBlock",
",",
"string",
"$",
"placeholder",
",",
"int",
"$",
"position",
")",
":",
"void",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"update",
"(",
"'ngbm_block'",
")",
"->",
"set",
"(",
"'position'",
",",
"':position'",
")",
"->",
"set",
"(",
"'parent_id'",
",",
"':parent_id'",
")",
"->",
"set",
"(",
"'placeholder'",
",",
"':placeholder'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'id'",
",",
"':id'",
")",
")",
"->",
"setParameter",
"(",
"'id'",
",",
"$",
"block",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'position'",
",",
"$",
"position",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'parent_id'",
",",
"$",
"targetBlock",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'placeholder'",
",",
"$",
"placeholder",
",",
"Type",
"::",
"STRING",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"block",
"->",
"status",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"$",
"depthDifference",
"=",
"$",
"block",
"->",
"depth",
"-",
"(",
"$",
"targetBlock",
"->",
"depth",
"+",
"1",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"update",
"(",
"'ngbm_block'",
")",
"->",
"set",
"(",
"'layout_id'",
",",
"':layout_id'",
")",
"->",
"set",
"(",
"'depth'",
",",
"'depth - :depth_difference'",
")",
"->",
"set",
"(",
"'path'",
",",
"'replace(path, :old_path, :new_path)'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"like",
"(",
"'path'",
",",
"':path'",
")",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"targetBlock",
"->",
"layoutId",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'depth_difference'",
",",
"$",
"depthDifference",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'old_path'",
",",
"$",
"block",
"->",
"path",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'new_path'",
",",
"$",
"targetBlock",
"->",
"path",
".",
"$",
"block",
"->",
"id",
".",
"'/'",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'path'",
",",
"$",
"block",
"->",
"path",
".",
"'%'",
",",
"Type",
"::",
"STRING",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"block",
"->",
"status",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
]
| Moves a block. If the target block is not provided, the block is only moved within its
current parent ID and placeholder. | [
"Moves",
"a",
"block",
".",
"If",
"the",
"target",
"block",
"is",
"not",
"provided",
"the",
"block",
"is",
"only",
"moved",
"within",
"its",
"current",
"parent",
"ID",
"and",
"placeholder",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L347-L389 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.deleteCollectionReferences | public function deleteCollectionReferences(array $blockIds, ?int $status = null): void
{
$query = $this->connection->createQueryBuilder();
$query->delete('ngbm_block_collection')
->where(
$query->expr()->in('block_id', [':block_id'])
)
->setParameter('block_id', $blockIds, Connection::PARAM_INT_ARRAY);
if ($status !== null) {
$this->applyStatusCondition($query, $status, 'block_status', 'block_status');
}
$query->execute();
} | php | public function deleteCollectionReferences(array $blockIds, ?int $status = null): void
{
$query = $this->connection->createQueryBuilder();
$query->delete('ngbm_block_collection')
->where(
$query->expr()->in('block_id', [':block_id'])
)
->setParameter('block_id', $blockIds, Connection::PARAM_INT_ARRAY);
if ($status !== null) {
$this->applyStatusCondition($query, $status, 'block_status', 'block_status');
}
$query->execute();
} | [
"public",
"function",
"deleteCollectionReferences",
"(",
"array",
"$",
"blockIds",
",",
"?",
"int",
"$",
"status",
"=",
"null",
")",
":",
"void",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"delete",
"(",
"'ngbm_block_collection'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"in",
"(",
"'block_id'",
",",
"[",
"':block_id'",
"]",
")",
")",
"->",
"setParameter",
"(",
"'block_id'",
",",
"$",
"blockIds",
",",
"Connection",
"::",
"PARAM_INT_ARRAY",
")",
";",
"if",
"(",
"$",
"status",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"status",
",",
"'block_status'",
",",
"'block_status'",
")",
";",
"}",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
]
| Deletes the collection reference. | [
"Deletes",
"the",
"collection",
"reference",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L440-L455 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.loadSubBlockIds | public function loadSubBlockIds($blockId, ?int $status = null): array
{
$query = $this->connection->createQueryBuilder();
$query->select('DISTINCT id')
->from('ngbm_block')
->where(
$query->expr()->like('path', ':path')
)
->setParameter('path', '%/' . (int) $blockId . '/%', Type::STRING);
if ($status !== null) {
$this->applyStatusCondition($query, $status);
}
$result = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return array_column($result, 'id');
} | php | public function loadSubBlockIds($blockId, ?int $status = null): array
{
$query = $this->connection->createQueryBuilder();
$query->select('DISTINCT id')
->from('ngbm_block')
->where(
$query->expr()->like('path', ':path')
)
->setParameter('path', '%/' . (int) $blockId . '/%', Type::STRING);
if ($status !== null) {
$this->applyStatusCondition($query, $status);
}
$result = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return array_column($result, 'id');
} | [
"public",
"function",
"loadSubBlockIds",
"(",
"$",
"blockId",
",",
"?",
"int",
"$",
"status",
"=",
"null",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"select",
"(",
"'DISTINCT id'",
")",
"->",
"from",
"(",
"'ngbm_block'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"like",
"(",
"'path'",
",",
"':path'",
")",
")",
"->",
"setParameter",
"(",
"'path'",
",",
"'%/'",
".",
"(",
"int",
")",
"$",
"blockId",
".",
"'/%'",
",",
"Type",
"::",
"STRING",
")",
";",
"if",
"(",
"$",
"status",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"status",
")",
";",
"}",
"$",
"result",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"return",
"array_column",
"(",
"$",
"result",
",",
"'id'",
")",
";",
"}"
]
| Loads all sub block IDs.
@param int|string $blockId
@param int $status
@return array | [
"Loads",
"all",
"sub",
"block",
"IDs",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L465-L482 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.loadLayoutBlockIds | public function loadLayoutBlockIds($layoutId, ?int $status = null): array
{
$query = $this->connection->createQueryBuilder();
$query->select('DISTINCT id')
->from('ngbm_block')
->where(
$query->expr()->eq('layout_id', ':layout_id')
)
->setParameter('layout_id', $layoutId, Type::INTEGER);
if ($status !== null) {
$this->applyStatusCondition($query, $status);
}
$result = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return array_column($result, 'id');
} | php | public function loadLayoutBlockIds($layoutId, ?int $status = null): array
{
$query = $this->connection->createQueryBuilder();
$query->select('DISTINCT id')
->from('ngbm_block')
->where(
$query->expr()->eq('layout_id', ':layout_id')
)
->setParameter('layout_id', $layoutId, Type::INTEGER);
if ($status !== null) {
$this->applyStatusCondition($query, $status);
}
$result = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return array_column($result, 'id');
} | [
"public",
"function",
"loadLayoutBlockIds",
"(",
"$",
"layoutId",
",",
"?",
"int",
"$",
"status",
"=",
"null",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"select",
"(",
"'DISTINCT id'",
")",
"->",
"from",
"(",
"'ngbm_block'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'layout_id'",
",",
"':layout_id'",
")",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"layoutId",
",",
"Type",
"::",
"INTEGER",
")",
";",
"if",
"(",
"$",
"status",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"status",
")",
";",
"}",
"$",
"result",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"return",
"array_column",
"(",
"$",
"result",
",",
"'id'",
")",
";",
"}"
]
| Loads all layout block IDs.
@param int|string $layoutId
@param int $status
@return array | [
"Loads",
"all",
"layout",
"block",
"IDs",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L492-L509 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php | BlockQueryHandler.loadBlockCollectionIds | public function loadBlockCollectionIds(array $blockIds, ?int $status = null): array
{
$query = $this->connection->createQueryBuilder();
$query->select('DISTINCT bc.collection_id')
->from('ngbm_block_collection', 'bc')
->where(
$query->expr()->in('bc.block_id', [':block_id'])
)
->setParameter('block_id', $blockIds, Connection::PARAM_INT_ARRAY);
if ($status !== null) {
$this->applyStatusCondition($query, $status, 'bc.block_status', 'block_status');
}
$result = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return array_column($result, 'collection_id');
} | php | public function loadBlockCollectionIds(array $blockIds, ?int $status = null): array
{
$query = $this->connection->createQueryBuilder();
$query->select('DISTINCT bc.collection_id')
->from('ngbm_block_collection', 'bc')
->where(
$query->expr()->in('bc.block_id', [':block_id'])
)
->setParameter('block_id', $blockIds, Connection::PARAM_INT_ARRAY);
if ($status !== null) {
$this->applyStatusCondition($query, $status, 'bc.block_status', 'block_status');
}
$result = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return array_column($result, 'collection_id');
} | [
"public",
"function",
"loadBlockCollectionIds",
"(",
"array",
"$",
"blockIds",
",",
"?",
"int",
"$",
"status",
"=",
"null",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"select",
"(",
"'DISTINCT bc.collection_id'",
")",
"->",
"from",
"(",
"'ngbm_block_collection'",
",",
"'bc'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"in",
"(",
"'bc.block_id'",
",",
"[",
"':block_id'",
"]",
")",
")",
"->",
"setParameter",
"(",
"'block_id'",
",",
"$",
"blockIds",
",",
"Connection",
"::",
"PARAM_INT_ARRAY",
")",
";",
"if",
"(",
"$",
"status",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"status",
",",
"'bc.block_status'",
",",
"'block_status'",
")",
";",
"}",
"$",
"result",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"return",
"array_column",
"(",
"$",
"result",
",",
"'collection_id'",
")",
";",
"}"
]
| Loads all block collection IDs. | [
"Loads",
"all",
"block",
"collection",
"IDs",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/BlockQueryHandler.php#L514-L531 | train |
netgen-layouts/layouts-core | lib/Serializer/Normalizer/V1/PlaceholderNormalizer.php | PlaceholderNormalizer.buildViewValues | private function buildViewValues(iterable $values, int $version): Generator
{
foreach ($values as $key => $value) {
yield $key => new View($value, $version);
}
} | php | private function buildViewValues(iterable $values, int $version): Generator
{
foreach ($values as $key => $value) {
yield $key => new View($value, $version);
}
} | [
"private",
"function",
"buildViewValues",
"(",
"iterable",
"$",
"values",
",",
"int",
"$",
"version",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"yield",
"$",
"key",
"=>",
"new",
"View",
"(",
"$",
"value",
",",
"$",
"version",
")",
";",
"}",
"}"
]
| Builds the list of View objects for provided list of values. | [
"Builds",
"the",
"list",
"of",
"View",
"objects",
"for",
"provided",
"list",
"of",
"values",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Serializer/Normalizer/V1/PlaceholderNormalizer.php#L42-L47 | train |
netgen-layouts/layouts-core | lib/Layout/Type/LayoutTypeFactory.php | LayoutTypeFactory.buildLayoutType | public static function buildLayoutType(string $identifier, array $config): LayoutTypeInterface
{
$zones = [];
foreach ($config['zones'] as $zoneIdentifier => $zoneConfig) {
$zones[$zoneIdentifier] = Zone::fromArray(
[
'identifier' => $zoneIdentifier,
'name' => $zoneConfig['name'],
'allowedBlockDefinitions' => $zoneConfig['allowed_block_definitions'],
]
);
}
return LayoutType::fromArray(
[
'identifier' => $identifier,
'isEnabled' => $config['enabled'],
'name' => $config['name'],
'icon' => $config['icon'],
'zones' => $zones,
]
);
} | php | public static function buildLayoutType(string $identifier, array $config): LayoutTypeInterface
{
$zones = [];
foreach ($config['zones'] as $zoneIdentifier => $zoneConfig) {
$zones[$zoneIdentifier] = Zone::fromArray(
[
'identifier' => $zoneIdentifier,
'name' => $zoneConfig['name'],
'allowedBlockDefinitions' => $zoneConfig['allowed_block_definitions'],
]
);
}
return LayoutType::fromArray(
[
'identifier' => $identifier,
'isEnabled' => $config['enabled'],
'name' => $config['name'],
'icon' => $config['icon'],
'zones' => $zones,
]
);
} | [
"public",
"static",
"function",
"buildLayoutType",
"(",
"string",
"$",
"identifier",
",",
"array",
"$",
"config",
")",
":",
"LayoutTypeInterface",
"{",
"$",
"zones",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"config",
"[",
"'zones'",
"]",
"as",
"$",
"zoneIdentifier",
"=>",
"$",
"zoneConfig",
")",
"{",
"$",
"zones",
"[",
"$",
"zoneIdentifier",
"]",
"=",
"Zone",
"::",
"fromArray",
"(",
"[",
"'identifier'",
"=>",
"$",
"zoneIdentifier",
",",
"'name'",
"=>",
"$",
"zoneConfig",
"[",
"'name'",
"]",
",",
"'allowedBlockDefinitions'",
"=>",
"$",
"zoneConfig",
"[",
"'allowed_block_definitions'",
"]",
",",
"]",
")",
";",
"}",
"return",
"LayoutType",
"::",
"fromArray",
"(",
"[",
"'identifier'",
"=>",
"$",
"identifier",
",",
"'isEnabled'",
"=>",
"$",
"config",
"[",
"'enabled'",
"]",
",",
"'name'",
"=>",
"$",
"config",
"[",
"'name'",
"]",
",",
"'icon'",
"=>",
"$",
"config",
"[",
"'icon'",
"]",
",",
"'zones'",
"=>",
"$",
"zones",
",",
"]",
")",
";",
"}"
]
| Builds the layout type. | [
"Builds",
"the",
"layout",
"type",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Layout/Type/LayoutTypeFactory.php#L12-L35 | train |
netgen-layouts/layouts-core | lib/Core/Validator/BlockValidator.php | BlockValidator.validateBlockCreateStruct | public function validateBlockCreateStruct(BlockCreateStruct $blockCreateStruct): void
{
$this->validate(
$blockCreateStruct,
[
new BlockCreateStructConstraint(),
]
);
$this->validate(
$blockCreateStruct,
new ConfigAwareStructConstraint(
[
'payload' => $blockCreateStruct->getDefinition(),
]
)
);
$collectionCreateStructs = $blockCreateStruct->getCollectionCreateStructs();
if (count($collectionCreateStructs) > 0) {
foreach ($collectionCreateStructs as $collectionCreateStruct) {
$this->collectionValidator->validateCollectionCreateStruct($collectionCreateStruct);
}
}
} | php | public function validateBlockCreateStruct(BlockCreateStruct $blockCreateStruct): void
{
$this->validate(
$blockCreateStruct,
[
new BlockCreateStructConstraint(),
]
);
$this->validate(
$blockCreateStruct,
new ConfigAwareStructConstraint(
[
'payload' => $blockCreateStruct->getDefinition(),
]
)
);
$collectionCreateStructs = $blockCreateStruct->getCollectionCreateStructs();
if (count($collectionCreateStructs) > 0) {
foreach ($collectionCreateStructs as $collectionCreateStruct) {
$this->collectionValidator->validateCollectionCreateStruct($collectionCreateStruct);
}
}
} | [
"public",
"function",
"validateBlockCreateStruct",
"(",
"BlockCreateStruct",
"$",
"blockCreateStruct",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"blockCreateStruct",
",",
"[",
"new",
"BlockCreateStructConstraint",
"(",
")",
",",
"]",
")",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"blockCreateStruct",
",",
"new",
"ConfigAwareStructConstraint",
"(",
"[",
"'payload'",
"=>",
"$",
"blockCreateStruct",
"->",
"getDefinition",
"(",
")",
",",
"]",
")",
")",
";",
"$",
"collectionCreateStructs",
"=",
"$",
"blockCreateStruct",
"->",
"getCollectionCreateStructs",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"collectionCreateStructs",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"collectionCreateStructs",
"as",
"$",
"collectionCreateStruct",
")",
"{",
"$",
"this",
"->",
"collectionValidator",
"->",
"validateCollectionCreateStruct",
"(",
"$",
"collectionCreateStruct",
")",
";",
"}",
"}",
"}"
]
| Validates the provided block create struct.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"block",
"create",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/BlockValidator.php#L31-L55 | train |
netgen-layouts/layouts-core | lib/Core/Validator/BlockValidator.php | BlockValidator.validateBlockUpdateStruct | public function validateBlockUpdateStruct(Block $block, BlockUpdateStruct $blockUpdateStruct): void
{
$this->validate(
$blockUpdateStruct,
[
new BlockUpdateStructConstraint(
[
'payload' => $block,
]
),
]
);
$this->validate(
$blockUpdateStruct,
new ConfigAwareStructConstraint(
[
'payload' => $block->getDefinition(),
'allowMissingFields' => true,
]
)
);
} | php | public function validateBlockUpdateStruct(Block $block, BlockUpdateStruct $blockUpdateStruct): void
{
$this->validate(
$blockUpdateStruct,
[
new BlockUpdateStructConstraint(
[
'payload' => $block,
]
),
]
);
$this->validate(
$blockUpdateStruct,
new ConfigAwareStructConstraint(
[
'payload' => $block->getDefinition(),
'allowMissingFields' => true,
]
)
);
} | [
"public",
"function",
"validateBlockUpdateStruct",
"(",
"Block",
"$",
"block",
",",
"BlockUpdateStruct",
"$",
"blockUpdateStruct",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"blockUpdateStruct",
",",
"[",
"new",
"BlockUpdateStructConstraint",
"(",
"[",
"'payload'",
"=>",
"$",
"block",
",",
"]",
")",
",",
"]",
")",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"blockUpdateStruct",
",",
"new",
"ConfigAwareStructConstraint",
"(",
"[",
"'payload'",
"=>",
"$",
"block",
"->",
"getDefinition",
"(",
")",
",",
"'allowMissingFields'",
"=>",
"true",
",",
"]",
")",
")",
";",
"}"
]
| Validates the provided block update struct.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"block",
"update",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/BlockValidator.php#L62-L84 | train |
netgen-layouts/layouts-core | lib/Block/BlockDefinition/Configuration/Collection.php | Collection.isValidQueryType | public function isValidQueryType(string $queryType): bool
{
if (!is_array($this->validQueryTypes)) {
return true;
}
return in_array($queryType, $this->validQueryTypes, true);
} | php | public function isValidQueryType(string $queryType): bool
{
if (!is_array($this->validQueryTypes)) {
return true;
}
return in_array($queryType, $this->validQueryTypes, true);
} | [
"public",
"function",
"isValidQueryType",
"(",
"string",
"$",
"queryType",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"validQueryTypes",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"in_array",
"(",
"$",
"queryType",
",",
"$",
"this",
"->",
"validQueryTypes",
",",
"true",
")",
";",
"}"
]
| Returns if the provided query type is valid. | [
"Returns",
"if",
"the",
"provided",
"query",
"type",
"is",
"valid",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Block/BlockDefinition/Configuration/Collection.php#L49-L56 | train |
netgen-layouts/layouts-core | lib/Block/BlockDefinition/Configuration/Collection.php | Collection.isValidItemType | public function isValidItemType(string $itemType): bool
{
if (!is_array($this->validItemTypes)) {
return true;
}
return in_array($itemType, $this->validItemTypes, true);
} | php | public function isValidItemType(string $itemType): bool
{
if (!is_array($this->validItemTypes)) {
return true;
}
return in_array($itemType, $this->validItemTypes, true);
} | [
"public",
"function",
"isValidItemType",
"(",
"string",
"$",
"itemType",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"validItemTypes",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"in_array",
"(",
"$",
"itemType",
",",
"$",
"this",
"->",
"validItemTypes",
",",
"true",
")",
";",
"}"
]
| Returns if the provided item type is valid. | [
"Returns",
"if",
"the",
"provided",
"item",
"type",
"is",
"valid",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Block/BlockDefinition/Configuration/Collection.php#L71-L78 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/CollectionStructBuilder.php | CollectionStructBuilder.newCollectionCreateStruct | public function newCollectionCreateStruct(?QueryCreateStruct $queryCreateStruct = null): CollectionCreateStruct
{
$struct = new CollectionCreateStruct();
$struct->queryCreateStruct = $queryCreateStruct;
return $struct;
} | php | public function newCollectionCreateStruct(?QueryCreateStruct $queryCreateStruct = null): CollectionCreateStruct
{
$struct = new CollectionCreateStruct();
$struct->queryCreateStruct = $queryCreateStruct;
return $struct;
} | [
"public",
"function",
"newCollectionCreateStruct",
"(",
"?",
"QueryCreateStruct",
"$",
"queryCreateStruct",
"=",
"null",
")",
":",
"CollectionCreateStruct",
"{",
"$",
"struct",
"=",
"new",
"CollectionCreateStruct",
"(",
")",
";",
"$",
"struct",
"->",
"queryCreateStruct",
"=",
"$",
"queryCreateStruct",
";",
"return",
"$",
"struct",
";",
"}"
]
| Creates a new collection create struct. | [
"Creates",
"a",
"new",
"collection",
"create",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/CollectionStructBuilder.php#L34-L40 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/CollectionStructBuilder.php | CollectionStructBuilder.newCollectionUpdateStruct | public function newCollectionUpdateStruct(?Collection $collection = null): CollectionUpdateStruct
{
$collectionUpdateStruct = new CollectionUpdateStruct();
if ($collection !== null) {
$collectionUpdateStruct->offset = $collection->getOffset();
$collectionUpdateStruct->limit = $collection->getLimit() ?? 0;
}
return $collectionUpdateStruct;
} | php | public function newCollectionUpdateStruct(?Collection $collection = null): CollectionUpdateStruct
{
$collectionUpdateStruct = new CollectionUpdateStruct();
if ($collection !== null) {
$collectionUpdateStruct->offset = $collection->getOffset();
$collectionUpdateStruct->limit = $collection->getLimit() ?? 0;
}
return $collectionUpdateStruct;
} | [
"public",
"function",
"newCollectionUpdateStruct",
"(",
"?",
"Collection",
"$",
"collection",
"=",
"null",
")",
":",
"CollectionUpdateStruct",
"{",
"$",
"collectionUpdateStruct",
"=",
"new",
"CollectionUpdateStruct",
"(",
")",
";",
"if",
"(",
"$",
"collection",
"!==",
"null",
")",
"{",
"$",
"collectionUpdateStruct",
"->",
"offset",
"=",
"$",
"collection",
"->",
"getOffset",
"(",
")",
";",
"$",
"collectionUpdateStruct",
"->",
"limit",
"=",
"$",
"collection",
"->",
"getLimit",
"(",
")",
"??",
"0",
";",
"}",
"return",
"$",
"collectionUpdateStruct",
";",
"}"
]
| Creates a new collection update struct.
If collection is provided, initial data is copied from the collection. | [
"Creates",
"a",
"new",
"collection",
"update",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/CollectionStructBuilder.php#L47-L57 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/CollectionStructBuilder.php | CollectionStructBuilder.newItemCreateStruct | public function newItemCreateStruct(ItemDefinitionInterface $itemDefinition, $value): ItemCreateStruct
{
$struct = new ItemCreateStruct();
$struct->definition = $itemDefinition;
$struct->value = $value;
return $struct;
} | php | public function newItemCreateStruct(ItemDefinitionInterface $itemDefinition, $value): ItemCreateStruct
{
$struct = new ItemCreateStruct();
$struct->definition = $itemDefinition;
$struct->value = $value;
return $struct;
} | [
"public",
"function",
"newItemCreateStruct",
"(",
"ItemDefinitionInterface",
"$",
"itemDefinition",
",",
"$",
"value",
")",
":",
"ItemCreateStruct",
"{",
"$",
"struct",
"=",
"new",
"ItemCreateStruct",
"(",
")",
";",
"$",
"struct",
"->",
"definition",
"=",
"$",
"itemDefinition",
";",
"$",
"struct",
"->",
"value",
"=",
"$",
"value",
";",
"return",
"$",
"struct",
";",
"}"
]
| Creates a new item create struct from provided values.
@param \Netgen\BlockManager\Collection\Item\ItemDefinitionInterface $itemDefinition
@param int|string $value
@return \Netgen\BlockManager\API\Values\Collection\ItemCreateStruct | [
"Creates",
"a",
"new",
"item",
"create",
"struct",
"from",
"provided",
"values",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/CollectionStructBuilder.php#L67-L74 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/CollectionStructBuilder.php | CollectionStructBuilder.newItemUpdateStruct | public function newItemUpdateStruct(?Item $item = null): ItemUpdateStruct
{
$itemUpdateStruct = new ItemUpdateStruct();
if (!$item instanceof Item) {
return $itemUpdateStruct;
}
$this->configStructBuilder->buildConfigUpdateStructs($item, $itemUpdateStruct);
return $itemUpdateStruct;
} | php | public function newItemUpdateStruct(?Item $item = null): ItemUpdateStruct
{
$itemUpdateStruct = new ItemUpdateStruct();
if (!$item instanceof Item) {
return $itemUpdateStruct;
}
$this->configStructBuilder->buildConfigUpdateStructs($item, $itemUpdateStruct);
return $itemUpdateStruct;
} | [
"public",
"function",
"newItemUpdateStruct",
"(",
"?",
"Item",
"$",
"item",
"=",
"null",
")",
":",
"ItemUpdateStruct",
"{",
"$",
"itemUpdateStruct",
"=",
"new",
"ItemUpdateStruct",
"(",
")",
";",
"if",
"(",
"!",
"$",
"item",
"instanceof",
"Item",
")",
"{",
"return",
"$",
"itemUpdateStruct",
";",
"}",
"$",
"this",
"->",
"configStructBuilder",
"->",
"buildConfigUpdateStructs",
"(",
"$",
"item",
",",
"$",
"itemUpdateStruct",
")",
";",
"return",
"$",
"itemUpdateStruct",
";",
"}"
]
| Creates a new item update struct.
If item is provided, initial data is copied from the item. | [
"Creates",
"a",
"new",
"item",
"update",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/CollectionStructBuilder.php#L81-L92 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/CollectionStructBuilder.php | CollectionStructBuilder.newQueryUpdateStruct | public function newQueryUpdateStruct(string $locale, ?Query $query = null): QueryUpdateStruct
{
$queryUpdateStruct = new QueryUpdateStruct();
$queryUpdateStruct->locale = $locale;
if (!$query instanceof Query) {
return $queryUpdateStruct;
}
$queryUpdateStruct->fillParametersFromQuery($query);
return $queryUpdateStruct;
} | php | public function newQueryUpdateStruct(string $locale, ?Query $query = null): QueryUpdateStruct
{
$queryUpdateStruct = new QueryUpdateStruct();
$queryUpdateStruct->locale = $locale;
if (!$query instanceof Query) {
return $queryUpdateStruct;
}
$queryUpdateStruct->fillParametersFromQuery($query);
return $queryUpdateStruct;
} | [
"public",
"function",
"newQueryUpdateStruct",
"(",
"string",
"$",
"locale",
",",
"?",
"Query",
"$",
"query",
"=",
"null",
")",
":",
"QueryUpdateStruct",
"{",
"$",
"queryUpdateStruct",
"=",
"new",
"QueryUpdateStruct",
"(",
")",
";",
"$",
"queryUpdateStruct",
"->",
"locale",
"=",
"$",
"locale",
";",
"if",
"(",
"!",
"$",
"query",
"instanceof",
"Query",
")",
"{",
"return",
"$",
"queryUpdateStruct",
";",
"}",
"$",
"queryUpdateStruct",
"->",
"fillParametersFromQuery",
"(",
"$",
"query",
")",
";",
"return",
"$",
"queryUpdateStruct",
";",
"}"
]
| Creates a new query update struct for provided locale.
If query is provided, initial data is copied from the query. | [
"Creates",
"a",
"new",
"query",
"update",
"struct",
"for",
"provided",
"locale",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/CollectionStructBuilder.php#L107-L119 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/QueryHandler.php | QueryHandler.applyStatusCondition | public function applyStatusCondition(QueryBuilder $query, ?int $status, string $statusColumn = 'status', string $paramName = 'status'): void
{
$query->andWhere($query->expr()->eq($statusColumn, ':' . $paramName))
->setParameter($paramName, $status, Type::INTEGER);
} | php | public function applyStatusCondition(QueryBuilder $query, ?int $status, string $statusColumn = 'status', string $paramName = 'status'): void
{
$query->andWhere($query->expr()->eq($statusColumn, ':' . $paramName))
->setParameter($paramName, $status, Type::INTEGER);
} | [
"public",
"function",
"applyStatusCondition",
"(",
"QueryBuilder",
"$",
"query",
",",
"?",
"int",
"$",
"status",
",",
"string",
"$",
"statusColumn",
"=",
"'status'",
",",
"string",
"$",
"paramName",
"=",
"'status'",
")",
":",
"void",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"$",
"statusColumn",
",",
"':'",
".",
"$",
"paramName",
")",
")",
"->",
"setParameter",
"(",
"$",
"paramName",
",",
"$",
"status",
",",
"Type",
"::",
"INTEGER",
")",
";",
"}"
]
| Applies status condition to the query. | [
"Applies",
"status",
"condition",
"to",
"the",
"query",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/QueryHandler.php#L33-L37 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/QueryHandler.php | QueryHandler.applyOffsetAndLimit | public function applyOffsetAndLimit(QueryBuilder $query, ?int $offset, ?int $limit): void
{
$query->setFirstResult($offset ?? 0);
if (is_int($limit) && $limit > 0) {
$query->setMaxResults($limit);
}
} | php | public function applyOffsetAndLimit(QueryBuilder $query, ?int $offset, ?int $limit): void
{
$query->setFirstResult($offset ?? 0);
if (is_int($limit) && $limit > 0) {
$query->setMaxResults($limit);
}
} | [
"public",
"function",
"applyOffsetAndLimit",
"(",
"QueryBuilder",
"$",
"query",
",",
"?",
"int",
"$",
"offset",
",",
"?",
"int",
"$",
"limit",
")",
":",
"void",
"{",
"$",
"query",
"->",
"setFirstResult",
"(",
"$",
"offset",
"??",
"0",
")",
";",
"if",
"(",
"is_int",
"(",
"$",
"limit",
")",
"&&",
"$",
"limit",
">",
"0",
")",
"{",
"$",
"query",
"->",
"setMaxResults",
"(",
"$",
"limit",
")",
";",
"}",
"}"
]
| Applies offset and limit to the query. | [
"Applies",
"offset",
"and",
"limit",
"to",
"the",
"query",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/QueryHandler.php#L42-L49 | train |
netgen-layouts/layouts-core | lib/Browser/Backend/LayoutBackend.php | LayoutBackend.buildItems | private function buildItems(LayoutList $layouts): Generator
{
foreach ($layouts as $layout) {
yield $this->buildItem($layout);
}
} | php | private function buildItems(LayoutList $layouts): Generator
{
foreach ($layouts as $layout) {
yield $this->buildItem($layout);
}
} | [
"private",
"function",
"buildItems",
"(",
"LayoutList",
"$",
"layouts",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"layouts",
"as",
"$",
"layout",
")",
"{",
"yield",
"$",
"this",
"->",
"buildItem",
"(",
"$",
"layout",
")",
";",
"}",
"}"
]
| Builds the items from provided layouts. | [
"Builds",
"the",
"items",
"from",
"provided",
"layouts",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Browser/Backend/LayoutBackend.php#L110-L115 | train |
netgen-layouts/layouts-core | lib/Block/BlockType/BlockTypeGroup.php | BlockTypeGroup.getBlockTypes | public function getBlockTypes(bool $onlyEnabled = false): array
{
if (!$onlyEnabled) {
return $this->blockTypes;
}
return array_values(
array_filter(
$this->blockTypes,
static function (BlockType $blockType): bool {
return $blockType->isEnabled();
}
)
);
} | php | public function getBlockTypes(bool $onlyEnabled = false): array
{
if (!$onlyEnabled) {
return $this->blockTypes;
}
return array_values(
array_filter(
$this->blockTypes,
static function (BlockType $blockType): bool {
return $blockType->isEnabled();
}
)
);
} | [
"public",
"function",
"getBlockTypes",
"(",
"bool",
"$",
"onlyEnabled",
"=",
"false",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"onlyEnabled",
")",
"{",
"return",
"$",
"this",
"->",
"blockTypes",
";",
"}",
"return",
"array_values",
"(",
"array_filter",
"(",
"$",
"this",
"->",
"blockTypes",
",",
"static",
"function",
"(",
"BlockType",
"$",
"blockType",
")",
":",
"bool",
"{",
"return",
"$",
"blockType",
"->",
"isEnabled",
"(",
")",
";",
"}",
")",
")",
";",
"}"
]
| Returns the block types in this group.
@param bool $onlyEnabled
@return \Netgen\BlockManager\Block\BlockType\BlockType[] | [
"Returns",
"the",
"block",
"types",
"in",
"this",
"group",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Block/BlockType/BlockTypeGroup.php#L70-L84 | train |
netgen-layouts/layouts-core | lib/Collection/Result/CollectionRunnerFactory.php | CollectionRunnerFactory.getCollectionRunner | public function getCollectionRunner(Collection $collection, int $flags = 0): CollectionRunnerInterface
{
$collectionQuery = $collection->getQuery();
if ($collectionQuery instanceof Query) {
$queryRunner = $this->getQueryRunner($collectionQuery, $flags);
return new DynamicCollectionRunner($queryRunner, $this->visibilityResolver);
}
return new ManualCollectionRunner($this->visibilityResolver);
} | php | public function getCollectionRunner(Collection $collection, int $flags = 0): CollectionRunnerInterface
{
$collectionQuery = $collection->getQuery();
if ($collectionQuery instanceof Query) {
$queryRunner = $this->getQueryRunner($collectionQuery, $flags);
return new DynamicCollectionRunner($queryRunner, $this->visibilityResolver);
}
return new ManualCollectionRunner($this->visibilityResolver);
} | [
"public",
"function",
"getCollectionRunner",
"(",
"Collection",
"$",
"collection",
",",
"int",
"$",
"flags",
"=",
"0",
")",
":",
"CollectionRunnerInterface",
"{",
"$",
"collectionQuery",
"=",
"$",
"collection",
"->",
"getQuery",
"(",
")",
";",
"if",
"(",
"$",
"collectionQuery",
"instanceof",
"Query",
")",
"{",
"$",
"queryRunner",
"=",
"$",
"this",
"->",
"getQueryRunner",
"(",
"$",
"collectionQuery",
",",
"$",
"flags",
")",
";",
"return",
"new",
"DynamicCollectionRunner",
"(",
"$",
"queryRunner",
",",
"$",
"this",
"->",
"visibilityResolver",
")",
";",
"}",
"return",
"new",
"ManualCollectionRunner",
"(",
"$",
"this",
"->",
"visibilityResolver",
")",
";",
"}"
]
| Builds and returns the collection runner for provided collection. | [
"Builds",
"and",
"returns",
"the",
"collection",
"runner",
"for",
"provided",
"collection",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Result/CollectionRunnerFactory.php#L33-L44 | train |
netgen-layouts/layouts-core | lib/Collection/Result/CollectionRunnerFactory.php | CollectionRunnerFactory.getQueryRunner | private function getQueryRunner(Query $query, int $flags = 0): QueryRunnerInterface
{
$showContextualSlots = (bool) ($flags & ResultSet::INCLUDE_UNKNOWN_ITEMS);
if ($showContextualSlots && $query->isContextual()) {
return new ContextualQueryRunner();
}
return new QueryRunner($this->cmsItemBuilder);
} | php | private function getQueryRunner(Query $query, int $flags = 0): QueryRunnerInterface
{
$showContextualSlots = (bool) ($flags & ResultSet::INCLUDE_UNKNOWN_ITEMS);
if ($showContextualSlots && $query->isContextual()) {
return new ContextualQueryRunner();
}
return new QueryRunner($this->cmsItemBuilder);
} | [
"private",
"function",
"getQueryRunner",
"(",
"Query",
"$",
"query",
",",
"int",
"$",
"flags",
"=",
"0",
")",
":",
"QueryRunnerInterface",
"{",
"$",
"showContextualSlots",
"=",
"(",
"bool",
")",
"(",
"$",
"flags",
"&",
"ResultSet",
"::",
"INCLUDE_UNKNOWN_ITEMS",
")",
";",
"if",
"(",
"$",
"showContextualSlots",
"&&",
"$",
"query",
"->",
"isContextual",
"(",
")",
")",
"{",
"return",
"new",
"ContextualQueryRunner",
"(",
")",
";",
"}",
"return",
"new",
"QueryRunner",
"(",
"$",
"this",
"->",
"cmsItemBuilder",
")",
";",
"}"
]
| Builds the query runner for the provided query based on provided flags. | [
"Builds",
"the",
"query",
"runner",
"for",
"the",
"provided",
"query",
"based",
"on",
"provided",
"flags",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Result/CollectionRunnerFactory.php#L49-L58 | train |
netgen-layouts/layouts-core | bundles/BlockManagerAdminBundle/Menu/MainMenuBuilder.php | MainMenuBuilder.createMenu | public function createMenu(): ItemInterface
{
$menu = $this->factory->createItem('root');
if ($this->authorizationChecker->isGranted('nglayouts:ui:access')) {
$menu
->addChild('layout_resolver', ['route' => 'ngbm_admin_layout_resolver_index'])
->setLabel('menu.main_menu.layout_resolver')
->setExtra('translation_domain', 'ngbm_admin');
$menu
->addChild('layouts', ['route' => 'ngbm_admin_layouts_index'])
->setLabel('menu.main_menu.layouts')
->setExtra('translation_domain', 'ngbm_admin');
$menu
->addChild('shared_layouts', ['route' => 'ngbm_admin_shared_layouts_index'])
->setLabel('menu.main_menu.shared_layouts')
->setExtra('translation_domain', 'ngbm_admin');
}
$this->eventDispatcher->dispatch(
new ConfigureMenuEvent($this->factory, $menu),
BlockManagerAdminEvents::CONFIGURE_MENU
);
return $menu;
} | php | public function createMenu(): ItemInterface
{
$menu = $this->factory->createItem('root');
if ($this->authorizationChecker->isGranted('nglayouts:ui:access')) {
$menu
->addChild('layout_resolver', ['route' => 'ngbm_admin_layout_resolver_index'])
->setLabel('menu.main_menu.layout_resolver')
->setExtra('translation_domain', 'ngbm_admin');
$menu
->addChild('layouts', ['route' => 'ngbm_admin_layouts_index'])
->setLabel('menu.main_menu.layouts')
->setExtra('translation_domain', 'ngbm_admin');
$menu
->addChild('shared_layouts', ['route' => 'ngbm_admin_shared_layouts_index'])
->setLabel('menu.main_menu.shared_layouts')
->setExtra('translation_domain', 'ngbm_admin');
}
$this->eventDispatcher->dispatch(
new ConfigureMenuEvent($this->factory, $menu),
BlockManagerAdminEvents::CONFIGURE_MENU
);
return $menu;
} | [
"public",
"function",
"createMenu",
"(",
")",
":",
"ItemInterface",
"{",
"$",
"menu",
"=",
"$",
"this",
"->",
"factory",
"->",
"createItem",
"(",
"'root'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"authorizationChecker",
"->",
"isGranted",
"(",
"'nglayouts:ui:access'",
")",
")",
"{",
"$",
"menu",
"->",
"addChild",
"(",
"'layout_resolver'",
",",
"[",
"'route'",
"=>",
"'ngbm_admin_layout_resolver_index'",
"]",
")",
"->",
"setLabel",
"(",
"'menu.main_menu.layout_resolver'",
")",
"->",
"setExtra",
"(",
"'translation_domain'",
",",
"'ngbm_admin'",
")",
";",
"$",
"menu",
"->",
"addChild",
"(",
"'layouts'",
",",
"[",
"'route'",
"=>",
"'ngbm_admin_layouts_index'",
"]",
")",
"->",
"setLabel",
"(",
"'menu.main_menu.layouts'",
")",
"->",
"setExtra",
"(",
"'translation_domain'",
",",
"'ngbm_admin'",
")",
";",
"$",
"menu",
"->",
"addChild",
"(",
"'shared_layouts'",
",",
"[",
"'route'",
"=>",
"'ngbm_admin_shared_layouts_index'",
"]",
")",
"->",
"setLabel",
"(",
"'menu.main_menu.shared_layouts'",
")",
"->",
"setExtra",
"(",
"'translation_domain'",
",",
"'ngbm_admin'",
")",
";",
"}",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"ConfigureMenuEvent",
"(",
"$",
"this",
"->",
"factory",
",",
"$",
"menu",
")",
",",
"BlockManagerAdminEvents",
"::",
"CONFIGURE_MENU",
")",
";",
"return",
"$",
"menu",
";",
"}"
]
| Builds the main menu. | [
"Builds",
"the",
"main",
"menu",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerAdminBundle/Menu/MainMenuBuilder.php#L45-L72 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/NetgenBlockManagerExtension.php | NetgenBlockManagerExtension.getPlugin | public function getPlugin(string $pluginName): ExtensionPluginInterface
{
if (!isset($this->plugins[$pluginName])) {
throw new RuntimeException(
sprintf(
'Extension plugin "%s" does not exist',
$pluginName
)
);
}
return $this->plugins[$pluginName];
} | php | public function getPlugin(string $pluginName): ExtensionPluginInterface
{
if (!isset($this->plugins[$pluginName])) {
throw new RuntimeException(
sprintf(
'Extension plugin "%s" does not exist',
$pluginName
)
);
}
return $this->plugins[$pluginName];
} | [
"public",
"function",
"getPlugin",
"(",
"string",
"$",
"pluginName",
")",
":",
"ExtensionPluginInterface",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"plugins",
"[",
"$",
"pluginName",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Extension plugin \"%s\" does not exist'",
",",
"$",
"pluginName",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"plugins",
"[",
"$",
"pluginName",
"]",
";",
"}"
]
| Returns the plugin by name. Name of the plugin is its fully qualified class name.
@throws \Netgen\BlockManager\Exception\RuntimeException If the specified plugin does not exist | [
"Returns",
"the",
"plugin",
"by",
"name",
".",
"Name",
"of",
"the",
"plugin",
"is",
"its",
"fully",
"qualified",
"class",
"name",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/NetgenBlockManagerExtension.php#L61-L73 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/NetgenBlockManagerExtension.php | NetgenBlockManagerExtension.loadConfigFiles | private function loadConfigFiles(ContainerBuilder $container): void
{
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config')
);
$loader->load('default_settings.yml');
$loader->load('services/errors.yml');
$loader->load('services/view/providers.yml');
$loader->load('services/view/matchers.yml');
$loader->load('services/view/view.yml');
$loader->load('services/items.yml');
$loader->load('services/block_definitions.yml');
$loader->load('services/config_definitions.yml');
$loader->load('services/forms.yml');
$loader->load('services/context.yml');
$loader->load('services/commands.yml');
$loader->load('services/design.yml');
$loader->load('services/security.yml');
$loader->load('services/utils.yml');
$loader->load('services/layout_resolver/layout_resolver.yml');
$loader->load('services/layout_resolver/condition_types.yml');
$loader->load('services/layout_resolver/target_handlers.yml');
$loader->load('services/layout_resolver/target_types.yml');
$loader->load('services/layout_resolver/forms.yml');
$loader->load('browser/services.yml');
$loader->load('services/layouts.yml');
$loader->load('services/collections.yml');
$loader->load('services/param_converters.yml');
$loader->load('services/event_listeners.yml');
$loader->load('services/configuration.yml');
$loader->load('services/controllers.yml');
$loader->load('services/normalizers.yml');
$loader->load('services/validators.yml');
$loader->load('services/templating.yml');
$loader->load('services/parameters.yml');
$loader->load('services/http_cache.yml');
$loader->load('services/locale.yml');
$loader->load('services/transfer/serialization_visitors.yml');
$loader->load('services/transfer/services.yml');
$loader->load('services/api.yml');
} | php | private function loadConfigFiles(ContainerBuilder $container): void
{
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config')
);
$loader->load('default_settings.yml');
$loader->load('services/errors.yml');
$loader->load('services/view/providers.yml');
$loader->load('services/view/matchers.yml');
$loader->load('services/view/view.yml');
$loader->load('services/items.yml');
$loader->load('services/block_definitions.yml');
$loader->load('services/config_definitions.yml');
$loader->load('services/forms.yml');
$loader->load('services/context.yml');
$loader->load('services/commands.yml');
$loader->load('services/design.yml');
$loader->load('services/security.yml');
$loader->load('services/utils.yml');
$loader->load('services/layout_resolver/layout_resolver.yml');
$loader->load('services/layout_resolver/condition_types.yml');
$loader->load('services/layout_resolver/target_handlers.yml');
$loader->load('services/layout_resolver/target_types.yml');
$loader->load('services/layout_resolver/forms.yml');
$loader->load('browser/services.yml');
$loader->load('services/layouts.yml');
$loader->load('services/collections.yml');
$loader->load('services/param_converters.yml');
$loader->load('services/event_listeners.yml');
$loader->load('services/configuration.yml');
$loader->load('services/controllers.yml');
$loader->load('services/normalizers.yml');
$loader->load('services/validators.yml');
$loader->load('services/templating.yml');
$loader->load('services/parameters.yml');
$loader->load('services/http_cache.yml');
$loader->load('services/locale.yml');
$loader->load('services/transfer/serialization_visitors.yml');
$loader->load('services/transfer/services.yml');
$loader->load('services/api.yml');
} | [
"private",
"function",
"loadConfigFiles",
"(",
"ContainerBuilder",
"$",
"container",
")",
":",
"void",
"{",
"$",
"loader",
"=",
"new",
"YamlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/../Resources/config'",
")",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'default_settings.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/errors.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/view/providers.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/view/matchers.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/view/view.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/items.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/block_definitions.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/config_definitions.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/forms.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/context.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/commands.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/design.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/security.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/utils.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/layout_resolver/layout_resolver.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/layout_resolver/condition_types.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/layout_resolver/target_handlers.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/layout_resolver/target_types.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/layout_resolver/forms.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'browser/services.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/layouts.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/collections.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/param_converters.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/event_listeners.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/configuration.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/controllers.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/normalizers.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/validators.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/templating.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/parameters.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/http_cache.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/locale.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/transfer/serialization_visitors.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/transfer/services.yml'",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services/api.yml'",
")",
";",
"}"
]
| Loads configuration from various YAML files. | [
"Loads",
"configuration",
"from",
"various",
"YAML",
"files",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/NetgenBlockManagerExtension.php#L168-L216 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/NetgenBlockManagerExtension.php | NetgenBlockManagerExtension.validateCurrentDesign | private function validateCurrentDesign(string $currentDesign, array $designList): void
{
if ($currentDesign !== 'standard' && !in_array($currentDesign, $designList, true)) {
throw new InvalidConfigurationException(
sprintf(
'Design "%s" does not exist. Available designs are: %s',
$currentDesign,
implode(', ', $designList)
)
);
}
} | php | private function validateCurrentDesign(string $currentDesign, array $designList): void
{
if ($currentDesign !== 'standard' && !in_array($currentDesign, $designList, true)) {
throw new InvalidConfigurationException(
sprintf(
'Design "%s" does not exist. Available designs are: %s',
$currentDesign,
implode(', ', $designList)
)
);
}
} | [
"private",
"function",
"validateCurrentDesign",
"(",
"string",
"$",
"currentDesign",
",",
"array",
"$",
"designList",
")",
":",
"void",
"{",
"if",
"(",
"$",
"currentDesign",
"!==",
"'standard'",
"&&",
"!",
"in_array",
"(",
"$",
"currentDesign",
",",
"$",
"designList",
",",
"true",
")",
")",
"{",
"throw",
"new",
"InvalidConfigurationException",
"(",
"sprintf",
"(",
"'Design \"%s\" does not exist. Available designs are: %s'",
",",
"$",
"currentDesign",
",",
"implode",
"(",
"', '",
",",
"$",
"designList",
")",
")",
")",
";",
"}",
"}"
]
| Validates that the design specified in configuration exists in the system.
@throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException If design does not exist | [
"Validates",
"that",
"the",
"design",
"specified",
"in",
"configuration",
"exists",
"in",
"the",
"system",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/NetgenBlockManagerExtension.php#L223-L234 | train |
netgen-layouts/layouts-core | lib/Collection/Result/Pagerfanta/PagerFactory.php | PagerFactory.getPager | public function getPager(Collection $collection, int $startPage, ?int $maxPages = null, int $flags = 0): Pagerfanta
{
$maxTotalCount = null;
if (is_int($maxPages) && $maxPages > 0) {
$maxTotalCount = $maxPages * $this->getMaxPerPage($collection);
}
$pagerAdapter = new ResultBuilderAdapter(
$this->resultBuilder,
$collection,
$collection->getOffset(),
$maxTotalCount,
$flags
);
return $this->buildPager($pagerAdapter, $collection, $startPage);
} | php | public function getPager(Collection $collection, int $startPage, ?int $maxPages = null, int $flags = 0): Pagerfanta
{
$maxTotalCount = null;
if (is_int($maxPages) && $maxPages > 0) {
$maxTotalCount = $maxPages * $this->getMaxPerPage($collection);
}
$pagerAdapter = new ResultBuilderAdapter(
$this->resultBuilder,
$collection,
$collection->getOffset(),
$maxTotalCount,
$flags
);
return $this->buildPager($pagerAdapter, $collection, $startPage);
} | [
"public",
"function",
"getPager",
"(",
"Collection",
"$",
"collection",
",",
"int",
"$",
"startPage",
",",
"?",
"int",
"$",
"maxPages",
"=",
"null",
",",
"int",
"$",
"flags",
"=",
"0",
")",
":",
"Pagerfanta",
"{",
"$",
"maxTotalCount",
"=",
"null",
";",
"if",
"(",
"is_int",
"(",
"$",
"maxPages",
")",
"&&",
"$",
"maxPages",
">",
"0",
")",
"{",
"$",
"maxTotalCount",
"=",
"$",
"maxPages",
"*",
"$",
"this",
"->",
"getMaxPerPage",
"(",
"$",
"collection",
")",
";",
"}",
"$",
"pagerAdapter",
"=",
"new",
"ResultBuilderAdapter",
"(",
"$",
"this",
"->",
"resultBuilder",
",",
"$",
"collection",
",",
"$",
"collection",
"->",
"getOffset",
"(",
")",
",",
"$",
"maxTotalCount",
",",
"$",
"flags",
")",
";",
"return",
"$",
"this",
"->",
"buildPager",
"(",
"$",
"pagerAdapter",
",",
"$",
"collection",
",",
"$",
"startPage",
")",
";",
"}"
]
| Builds and returns the Pagerfanta pager for provided collection.
The pager starting page will be set to $startPage. | [
"Builds",
"and",
"returns",
"the",
"Pagerfanta",
"pager",
"for",
"provided",
"collection",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Result/Pagerfanta/PagerFactory.php#L35-L51 | train |
netgen-layouts/layouts-core | lib/Collection/Result/Pagerfanta/PagerFactory.php | PagerFactory.buildPager | private function buildPager(AdapterInterface $adapter, Collection $collection, int $startPage): Pagerfanta
{
$pager = new Pagerfanta($adapter);
$pager->setNormalizeOutOfRangePages(true);
$pager->setMaxPerPage($this->getMaxPerPage($collection));
$pager->setCurrentPage($startPage > 0 ? $startPage : 1);
return $pager;
} | php | private function buildPager(AdapterInterface $adapter, Collection $collection, int $startPage): Pagerfanta
{
$pager = new Pagerfanta($adapter);
$pager->setNormalizeOutOfRangePages(true);
$pager->setMaxPerPage($this->getMaxPerPage($collection));
$pager->setCurrentPage($startPage > 0 ? $startPage : 1);
return $pager;
} | [
"private",
"function",
"buildPager",
"(",
"AdapterInterface",
"$",
"adapter",
",",
"Collection",
"$",
"collection",
",",
"int",
"$",
"startPage",
")",
":",
"Pagerfanta",
"{",
"$",
"pager",
"=",
"new",
"Pagerfanta",
"(",
"$",
"adapter",
")",
";",
"$",
"pager",
"->",
"setNormalizeOutOfRangePages",
"(",
"true",
")",
";",
"$",
"pager",
"->",
"setMaxPerPage",
"(",
"$",
"this",
"->",
"getMaxPerPage",
"(",
"$",
"collection",
")",
")",
";",
"$",
"pager",
"->",
"setCurrentPage",
"(",
"$",
"startPage",
">",
"0",
"?",
"$",
"startPage",
":",
"1",
")",
";",
"return",
"$",
"pager",
";",
"}"
]
| Builds the pager from provided adapter. | [
"Builds",
"the",
"pager",
"from",
"provided",
"adapter",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Result/Pagerfanta/PagerFactory.php#L56-L65 | train |
netgen-layouts/layouts-core | lib/Collection/Result/Pagerfanta/PagerFactory.php | PagerFactory.getMaxPerPage | private function getMaxPerPage(Collection $collection): int
{
$limit = $collection->getLimit() ?? 0;
return $limit > 0 && $limit < $this->maxLimit ? $limit : $this->maxLimit;
} | php | private function getMaxPerPage(Collection $collection): int
{
$limit = $collection->getLimit() ?? 0;
return $limit > 0 && $limit < $this->maxLimit ? $limit : $this->maxLimit;
} | [
"private",
"function",
"getMaxPerPage",
"(",
"Collection",
"$",
"collection",
")",
":",
"int",
"{",
"$",
"limit",
"=",
"$",
"collection",
"->",
"getLimit",
"(",
")",
"??",
"0",
";",
"return",
"$",
"limit",
">",
"0",
"&&",
"$",
"limit",
"<",
"$",
"this",
"->",
"maxLimit",
"?",
"$",
"limit",
":",
"$",
"this",
"->",
"maxLimit",
";",
"}"
]
| Returns the maximum number of items per page for the provided collection,
while taking into account the injected maximum number of items. | [
"Returns",
"the",
"maximum",
"number",
"of",
"items",
"per",
"page",
"for",
"the",
"provided",
"collection",
"while",
"taking",
"into",
"account",
"the",
"injected",
"maximum",
"number",
"of",
"items",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Result/Pagerfanta/PagerFactory.php#L71-L76 | train |
netgen-layouts/layouts-core | lib/Core/Mapper/ParameterMapper.php | ParameterMapper.mapParameters | public function mapParameters(ParameterDefinitionCollectionInterface $definitions, array $values): Generator
{
foreach ($definitions->getParameterDefinitions() as $parameterDefinition) {
$parameterName = $parameterDefinition->getName();
$parameterType = $parameterDefinition->getType();
$value = array_key_exists($parameterName, $values) ?
$parameterType->fromHash($parameterDefinition, $values[$parameterName]) :
$parameterDefinition->getDefaultValue();
yield $parameterName => Parameter::fromArray(
[
'name' => $parameterName,
'parameterDefinition' => $parameterDefinition,
'value' => $value,
'isEmpty' => $parameterType->isValueEmpty($parameterDefinition, $value),
]
);
if ($parameterDefinition instanceof CompoundParameterDefinition) {
yield from $this->mapParameters($parameterDefinition, $values);
}
}
} | php | public function mapParameters(ParameterDefinitionCollectionInterface $definitions, array $values): Generator
{
foreach ($definitions->getParameterDefinitions() as $parameterDefinition) {
$parameterName = $parameterDefinition->getName();
$parameterType = $parameterDefinition->getType();
$value = array_key_exists($parameterName, $values) ?
$parameterType->fromHash($parameterDefinition, $values[$parameterName]) :
$parameterDefinition->getDefaultValue();
yield $parameterName => Parameter::fromArray(
[
'name' => $parameterName,
'parameterDefinition' => $parameterDefinition,
'value' => $value,
'isEmpty' => $parameterType->isValueEmpty($parameterDefinition, $value),
]
);
if ($parameterDefinition instanceof CompoundParameterDefinition) {
yield from $this->mapParameters($parameterDefinition, $values);
}
}
} | [
"public",
"function",
"mapParameters",
"(",
"ParameterDefinitionCollectionInterface",
"$",
"definitions",
",",
"array",
"$",
"values",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"definitions",
"->",
"getParameterDefinitions",
"(",
")",
"as",
"$",
"parameterDefinition",
")",
"{",
"$",
"parameterName",
"=",
"$",
"parameterDefinition",
"->",
"getName",
"(",
")",
";",
"$",
"parameterType",
"=",
"$",
"parameterDefinition",
"->",
"getType",
"(",
")",
";",
"$",
"value",
"=",
"array_key_exists",
"(",
"$",
"parameterName",
",",
"$",
"values",
")",
"?",
"$",
"parameterType",
"->",
"fromHash",
"(",
"$",
"parameterDefinition",
",",
"$",
"values",
"[",
"$",
"parameterName",
"]",
")",
":",
"$",
"parameterDefinition",
"->",
"getDefaultValue",
"(",
")",
";",
"yield",
"$",
"parameterName",
"=>",
"Parameter",
"::",
"fromArray",
"(",
"[",
"'name'",
"=>",
"$",
"parameterName",
",",
"'parameterDefinition'",
"=>",
"$",
"parameterDefinition",
",",
"'value'",
"=>",
"$",
"value",
",",
"'isEmpty'",
"=>",
"$",
"parameterType",
"->",
"isValueEmpty",
"(",
"$",
"parameterDefinition",
",",
"$",
"value",
")",
",",
"]",
")",
";",
"if",
"(",
"$",
"parameterDefinition",
"instanceof",
"CompoundParameterDefinition",
")",
"{",
"yield",
"from",
"$",
"this",
"->",
"mapParameters",
"(",
"$",
"parameterDefinition",
",",
"$",
"values",
")",
";",
"}",
"}",
"}"
]
| Maps the parameter values based on provided collection of parameters. | [
"Maps",
"the",
"parameter",
"values",
"based",
"on",
"provided",
"collection",
"of",
"parameters",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Mapper/ParameterMapper.php#L17-L40 | train |
netgen-layouts/layouts-core | lib/Core/Mapper/ParameterMapper.php | ParameterMapper.serializeValues | public function serializeValues(ParameterDefinitionCollectionInterface $definitions, array $values, array $fallbackValues = []): Generator
{
yield from $fallbackValues;
foreach ($definitions->getParameterDefinitions() as $parameterDefinition) {
$parameterName = $parameterDefinition->getName();
if (!array_key_exists($parameterName, $values)) {
continue;
}
yield $parameterName => $parameterDefinition->getType()->toHash(
$parameterDefinition,
$values[$parameterName]
);
if ($parameterDefinition instanceof CompoundParameterDefinition) {
yield from $this->serializeValues($parameterDefinition, $values);
}
}
} | php | public function serializeValues(ParameterDefinitionCollectionInterface $definitions, array $values, array $fallbackValues = []): Generator
{
yield from $fallbackValues;
foreach ($definitions->getParameterDefinitions() as $parameterDefinition) {
$parameterName = $parameterDefinition->getName();
if (!array_key_exists($parameterName, $values)) {
continue;
}
yield $parameterName => $parameterDefinition->getType()->toHash(
$parameterDefinition,
$values[$parameterName]
);
if ($parameterDefinition instanceof CompoundParameterDefinition) {
yield from $this->serializeValues($parameterDefinition, $values);
}
}
} | [
"public",
"function",
"serializeValues",
"(",
"ParameterDefinitionCollectionInterface",
"$",
"definitions",
",",
"array",
"$",
"values",
",",
"array",
"$",
"fallbackValues",
"=",
"[",
"]",
")",
":",
"Generator",
"{",
"yield",
"from",
"$",
"fallbackValues",
";",
"foreach",
"(",
"$",
"definitions",
"->",
"getParameterDefinitions",
"(",
")",
"as",
"$",
"parameterDefinition",
")",
"{",
"$",
"parameterName",
"=",
"$",
"parameterDefinition",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"parameterName",
",",
"$",
"values",
")",
")",
"{",
"continue",
";",
"}",
"yield",
"$",
"parameterName",
"=>",
"$",
"parameterDefinition",
"->",
"getType",
"(",
")",
"->",
"toHash",
"(",
"$",
"parameterDefinition",
",",
"$",
"values",
"[",
"$",
"parameterName",
"]",
")",
";",
"if",
"(",
"$",
"parameterDefinition",
"instanceof",
"CompoundParameterDefinition",
")",
"{",
"yield",
"from",
"$",
"this",
"->",
"serializeValues",
"(",
"$",
"parameterDefinition",
",",
"$",
"values",
")",
";",
"}",
"}",
"}"
]
| Serializes the parameter values based on provided collection of parameters. | [
"Serializes",
"the",
"parameter",
"values",
"based",
"on",
"provided",
"collection",
"of",
"parameters",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Mapper/ParameterMapper.php#L45-L64 | train |
netgen-layouts/layouts-core | lib/Parameters/ParameterBuilderFactory.php | ParameterBuilderFactory.resolveOptions | protected function resolveOptions(array $config): array
{
$optionsResolver = new OptionsResolver();
$optionsResolver->setDefault('name', null);
$optionsResolver->setDefault('type', null);
$optionsResolver->setDefault('options', []);
$optionsResolver->setDefault('parent', null);
$optionsResolver->setRequired(['name', 'type', 'options', 'parent']);
$optionsResolver->setAllowedTypes('name', ['null', 'string']);
$optionsResolver->setAllowedTypes('type', ['null', 'string', ParameterTypeInterface::class]);
$optionsResolver->setAllowedTypes('options', 'array');
$optionsResolver->setAllowedTypes('parent', ['null', ParameterBuilderInterface::class]);
$optionsResolver->setNormalizer(
'type',
function (Options $options, $value) {
if (!is_string($value)) {
return $value;
}
return $this->parameterTypeRegistry->getParameterTypeByClass($value);
}
);
return $optionsResolver->resolve($config);
} | php | protected function resolveOptions(array $config): array
{
$optionsResolver = new OptionsResolver();
$optionsResolver->setDefault('name', null);
$optionsResolver->setDefault('type', null);
$optionsResolver->setDefault('options', []);
$optionsResolver->setDefault('parent', null);
$optionsResolver->setRequired(['name', 'type', 'options', 'parent']);
$optionsResolver->setAllowedTypes('name', ['null', 'string']);
$optionsResolver->setAllowedTypes('type', ['null', 'string', ParameterTypeInterface::class]);
$optionsResolver->setAllowedTypes('options', 'array');
$optionsResolver->setAllowedTypes('parent', ['null', ParameterBuilderInterface::class]);
$optionsResolver->setNormalizer(
'type',
function (Options $options, $value) {
if (!is_string($value)) {
return $value;
}
return $this->parameterTypeRegistry->getParameterTypeByClass($value);
}
);
return $optionsResolver->resolve($config);
} | [
"protected",
"function",
"resolveOptions",
"(",
"array",
"$",
"config",
")",
":",
"array",
"{",
"$",
"optionsResolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"$",
"optionsResolver",
"->",
"setDefault",
"(",
"'name'",
",",
"null",
")",
";",
"$",
"optionsResolver",
"->",
"setDefault",
"(",
"'type'",
",",
"null",
")",
";",
"$",
"optionsResolver",
"->",
"setDefault",
"(",
"'options'",
",",
"[",
"]",
")",
";",
"$",
"optionsResolver",
"->",
"setDefault",
"(",
"'parent'",
",",
"null",
")",
";",
"$",
"optionsResolver",
"->",
"setRequired",
"(",
"[",
"'name'",
",",
"'type'",
",",
"'options'",
",",
"'parent'",
"]",
")",
";",
"$",
"optionsResolver",
"->",
"setAllowedTypes",
"(",
"'name'",
",",
"[",
"'null'",
",",
"'string'",
"]",
")",
";",
"$",
"optionsResolver",
"->",
"setAllowedTypes",
"(",
"'type'",
",",
"[",
"'null'",
",",
"'string'",
",",
"ParameterTypeInterface",
"::",
"class",
"]",
")",
";",
"$",
"optionsResolver",
"->",
"setAllowedTypes",
"(",
"'options'",
",",
"'array'",
")",
";",
"$",
"optionsResolver",
"->",
"setAllowedTypes",
"(",
"'parent'",
",",
"[",
"'null'",
",",
"ParameterBuilderInterface",
"::",
"class",
"]",
")",
";",
"$",
"optionsResolver",
"->",
"setNormalizer",
"(",
"'type'",
",",
"function",
"(",
"Options",
"$",
"options",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"parameterTypeRegistry",
"->",
"getParameterTypeByClass",
"(",
"$",
"value",
")",
";",
"}",
")",
";",
"return",
"$",
"optionsResolver",
"->",
"resolve",
"(",
"$",
"config",
")",
";",
"}"
]
| Resolves the provided parameter builder configuration. | [
"Resolves",
"the",
"provided",
"parameter",
"builder",
"configuration",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Parameters/ParameterBuilderFactory.php#L39-L67 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/Mapper/LayoutMapper.php | LayoutMapper.mapLayouts | public function mapLayouts(array $data): array
{
$layouts = [];
foreach ($data as $dataItem) {
$layoutId = (int) $dataItem['id'];
$locale = $dataItem['locale'];
if (!isset($layouts[$layoutId])) {
$layouts[$layoutId] = [
'id' => $layoutId,
'type' => $dataItem['type'],
'name' => $dataItem['name'],
'description' => $dataItem['description'],
'created' => (int) $dataItem['created'],
'modified' => (int) $dataItem['modified'],
'status' => (int) $dataItem['status'],
'shared' => (bool) $dataItem['shared'],
'mainLocale' => $dataItem['main_locale'],
];
}
$layouts[$layoutId]['availableLocales'][] = $locale;
}
return array_values(
array_map(
static function (array $layoutData): Layout {
sort($layoutData['availableLocales']);
return Layout::fromArray($layoutData);
},
$layouts
)
);
} | php | public function mapLayouts(array $data): array
{
$layouts = [];
foreach ($data as $dataItem) {
$layoutId = (int) $dataItem['id'];
$locale = $dataItem['locale'];
if (!isset($layouts[$layoutId])) {
$layouts[$layoutId] = [
'id' => $layoutId,
'type' => $dataItem['type'],
'name' => $dataItem['name'],
'description' => $dataItem['description'],
'created' => (int) $dataItem['created'],
'modified' => (int) $dataItem['modified'],
'status' => (int) $dataItem['status'],
'shared' => (bool) $dataItem['shared'],
'mainLocale' => $dataItem['main_locale'],
];
}
$layouts[$layoutId]['availableLocales'][] = $locale;
}
return array_values(
array_map(
static function (array $layoutData): Layout {
sort($layoutData['availableLocales']);
return Layout::fromArray($layoutData);
},
$layouts
)
);
} | [
"public",
"function",
"mapLayouts",
"(",
"array",
"$",
"data",
")",
":",
"array",
"{",
"$",
"layouts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"dataItem",
")",
"{",
"$",
"layoutId",
"=",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'id'",
"]",
";",
"$",
"locale",
"=",
"$",
"dataItem",
"[",
"'locale'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"layouts",
"[",
"$",
"layoutId",
"]",
")",
")",
"{",
"$",
"layouts",
"[",
"$",
"layoutId",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"layoutId",
",",
"'type'",
"=>",
"$",
"dataItem",
"[",
"'type'",
"]",
",",
"'name'",
"=>",
"$",
"dataItem",
"[",
"'name'",
"]",
",",
"'description'",
"=>",
"$",
"dataItem",
"[",
"'description'",
"]",
",",
"'created'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'created'",
"]",
",",
"'modified'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'modified'",
"]",
",",
"'status'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'status'",
"]",
",",
"'shared'",
"=>",
"(",
"bool",
")",
"$",
"dataItem",
"[",
"'shared'",
"]",
",",
"'mainLocale'",
"=>",
"$",
"dataItem",
"[",
"'main_locale'",
"]",
",",
"]",
";",
"}",
"$",
"layouts",
"[",
"$",
"layoutId",
"]",
"[",
"'availableLocales'",
"]",
"[",
"]",
"=",
"$",
"locale",
";",
"}",
"return",
"array_values",
"(",
"array_map",
"(",
"static",
"function",
"(",
"array",
"$",
"layoutData",
")",
":",
"Layout",
"{",
"sort",
"(",
"$",
"layoutData",
"[",
"'availableLocales'",
"]",
")",
";",
"return",
"Layout",
"::",
"fromArray",
"(",
"$",
"layoutData",
")",
";",
"}",
",",
"$",
"layouts",
")",
")",
";",
"}"
]
| Maps data from database to layout values.
@return \Netgen\BlockManager\Persistence\Values\Layout\Layout[] | [
"Maps",
"data",
"from",
"database",
"to",
"layout",
"values",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/Mapper/LayoutMapper.php#L17-L52 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/Mapper/LayoutMapper.php | LayoutMapper.mapZones | public function mapZones(array $data): array
{
$zones = [];
foreach ($data as $dataItem) {
$zones[$dataItem['identifier']] = Zone::fromArray(
[
'identifier' => $dataItem['identifier'],
'layoutId' => (int) $dataItem['layout_id'],
'status' => (int) $dataItem['status'],
'rootBlockId' => (int) $dataItem['root_block_id'],
'linkedLayoutId' => $dataItem['linked_layout_id'] !== null ? (int) $dataItem['linked_layout_id'] : null,
'linkedZoneIdentifier' => $dataItem['linked_zone_identifier'],
]
);
}
return $zones;
} | php | public function mapZones(array $data): array
{
$zones = [];
foreach ($data as $dataItem) {
$zones[$dataItem['identifier']] = Zone::fromArray(
[
'identifier' => $dataItem['identifier'],
'layoutId' => (int) $dataItem['layout_id'],
'status' => (int) $dataItem['status'],
'rootBlockId' => (int) $dataItem['root_block_id'],
'linkedLayoutId' => $dataItem['linked_layout_id'] !== null ? (int) $dataItem['linked_layout_id'] : null,
'linkedZoneIdentifier' => $dataItem['linked_zone_identifier'],
]
);
}
return $zones;
} | [
"public",
"function",
"mapZones",
"(",
"array",
"$",
"data",
")",
":",
"array",
"{",
"$",
"zones",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"dataItem",
")",
"{",
"$",
"zones",
"[",
"$",
"dataItem",
"[",
"'identifier'",
"]",
"]",
"=",
"Zone",
"::",
"fromArray",
"(",
"[",
"'identifier'",
"=>",
"$",
"dataItem",
"[",
"'identifier'",
"]",
",",
"'layoutId'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'layout_id'",
"]",
",",
"'status'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'status'",
"]",
",",
"'rootBlockId'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'root_block_id'",
"]",
",",
"'linkedLayoutId'",
"=>",
"$",
"dataItem",
"[",
"'linked_layout_id'",
"]",
"!==",
"null",
"?",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'linked_layout_id'",
"]",
":",
"null",
",",
"'linkedZoneIdentifier'",
"=>",
"$",
"dataItem",
"[",
"'linked_zone_identifier'",
"]",
",",
"]",
")",
";",
"}",
"return",
"$",
"zones",
";",
"}"
]
| Maps data from database to zone values.
@return \Netgen\BlockManager\Persistence\Values\Layout\Zone[] | [
"Maps",
"data",
"from",
"database",
"to",
"zone",
"values",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/Mapper/LayoutMapper.php#L59-L77 | train |
netgen-layouts/layouts-core | bundles/BlockManagerAdminBundle/EventListener/AdminAuthenticationExceptionListener.php | AdminAuthenticationExceptionListener.onException | public function onException(GetResponseForExceptionEvent $event): void
{
$attributes = $event->getRequest()->attributes;
if ($attributes->get(SetIsAdminRequestListener::ADMIN_FLAG_NAME) !== true) {
return;
}
if (!$event->getRequest()->isXmlHttpRequest()) {
return;
}
$exception = $event->getException();
if (!$exception instanceof AuthenticationException && !$exception instanceof AccessDeniedException) {
return;
}
$event->setException(new AccessDeniedHttpException());
$event->stopPropagation();
} | php | public function onException(GetResponseForExceptionEvent $event): void
{
$attributes = $event->getRequest()->attributes;
if ($attributes->get(SetIsAdminRequestListener::ADMIN_FLAG_NAME) !== true) {
return;
}
if (!$event->getRequest()->isXmlHttpRequest()) {
return;
}
$exception = $event->getException();
if (!$exception instanceof AuthenticationException && !$exception instanceof AccessDeniedException) {
return;
}
$event->setException(new AccessDeniedHttpException());
$event->stopPropagation();
} | [
"public",
"function",
"onException",
"(",
"GetResponseForExceptionEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"attributes",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"attributes",
";",
"if",
"(",
"$",
"attributes",
"->",
"get",
"(",
"SetIsAdminRequestListener",
"::",
"ADMIN_FLAG_NAME",
")",
"!==",
"true",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"exception",
"=",
"$",
"event",
"->",
"getException",
"(",
")",
";",
"if",
"(",
"!",
"$",
"exception",
"instanceof",
"AuthenticationException",
"&&",
"!",
"$",
"exception",
"instanceof",
"AccessDeniedException",
")",
"{",
"return",
";",
"}",
"$",
"event",
"->",
"setException",
"(",
"new",
"AccessDeniedHttpException",
"(",
")",
")",
";",
"$",
"event",
"->",
"stopPropagation",
"(",
")",
";",
"}"
]
| Converts Symfony authentication exceptions to HTTP Access Denied exception. | [
"Converts",
"Symfony",
"authentication",
"exceptions",
"to",
"HTTP",
"Access",
"Denied",
"exception",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerAdminBundle/EventListener/AdminAuthenticationExceptionListener.php#L25-L44 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Controller/API/V1/BlockCollection/ChangeCollectionType.php | ChangeCollectionType.validateChangeCollectionType | private function validateChangeCollectionType(Block $block, string $collectionIdentifier, int $newType, string $queryType): void
{
$this->validate(
$newType,
[
new Constraints\NotBlank(),
new Constraints\Choice(
[
'choices' => [
Collection::TYPE_MANUAL,
Collection::TYPE_DYNAMIC,
],
'strict' => true,
]
),
],
'new_type'
);
$blockDefinition = $block->getDefinition();
if (!$blockDefinition->hasCollection($collectionIdentifier)) {
return;
}
$collectionConfig = $blockDefinition->getCollection($collectionIdentifier);
if ($newType === Collection::TYPE_DYNAMIC) {
if (!$collectionConfig->isValidQueryType($queryType)) {
throw ValidationException::validationFailed(
'new_type',
sprintf(
'Query type "%s" is not allowed in selected block.',
$queryType
)
);
}
} elseif ($newType === Collection::TYPE_MANUAL) {
if ($collectionConfig->getValidItemTypes() === []) {
throw ValidationException::validationFailed(
'new_type',
'Selected block does not allow manual collections.'
);
}
}
} | php | private function validateChangeCollectionType(Block $block, string $collectionIdentifier, int $newType, string $queryType): void
{
$this->validate(
$newType,
[
new Constraints\NotBlank(),
new Constraints\Choice(
[
'choices' => [
Collection::TYPE_MANUAL,
Collection::TYPE_DYNAMIC,
],
'strict' => true,
]
),
],
'new_type'
);
$blockDefinition = $block->getDefinition();
if (!$blockDefinition->hasCollection($collectionIdentifier)) {
return;
}
$collectionConfig = $blockDefinition->getCollection($collectionIdentifier);
if ($newType === Collection::TYPE_DYNAMIC) {
if (!$collectionConfig->isValidQueryType($queryType)) {
throw ValidationException::validationFailed(
'new_type',
sprintf(
'Query type "%s" is not allowed in selected block.',
$queryType
)
);
}
} elseif ($newType === Collection::TYPE_MANUAL) {
if ($collectionConfig->getValidItemTypes() === []) {
throw ValidationException::validationFailed(
'new_type',
'Selected block does not allow manual collections.'
);
}
}
} | [
"private",
"function",
"validateChangeCollectionType",
"(",
"Block",
"$",
"block",
",",
"string",
"$",
"collectionIdentifier",
",",
"int",
"$",
"newType",
",",
"string",
"$",
"queryType",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"newType",
",",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Choice",
"(",
"[",
"'choices'",
"=>",
"[",
"Collection",
"::",
"TYPE_MANUAL",
",",
"Collection",
"::",
"TYPE_DYNAMIC",
",",
"]",
",",
"'strict'",
"=>",
"true",
",",
"]",
")",
",",
"]",
",",
"'new_type'",
")",
";",
"$",
"blockDefinition",
"=",
"$",
"block",
"->",
"getDefinition",
"(",
")",
";",
"if",
"(",
"!",
"$",
"blockDefinition",
"->",
"hasCollection",
"(",
"$",
"collectionIdentifier",
")",
")",
"{",
"return",
";",
"}",
"$",
"collectionConfig",
"=",
"$",
"blockDefinition",
"->",
"getCollection",
"(",
"$",
"collectionIdentifier",
")",
";",
"if",
"(",
"$",
"newType",
"===",
"Collection",
"::",
"TYPE_DYNAMIC",
")",
"{",
"if",
"(",
"!",
"$",
"collectionConfig",
"->",
"isValidQueryType",
"(",
"$",
"queryType",
")",
")",
"{",
"throw",
"ValidationException",
"::",
"validationFailed",
"(",
"'new_type'",
",",
"sprintf",
"(",
"'Query type \"%s\" is not allowed in selected block.'",
",",
"$",
"queryType",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"newType",
"===",
"Collection",
"::",
"TYPE_MANUAL",
")",
"{",
"if",
"(",
"$",
"collectionConfig",
"->",
"getValidItemTypes",
"(",
")",
"===",
"[",
"]",
")",
"{",
"throw",
"ValidationException",
"::",
"validationFailed",
"(",
"'new_type'",
",",
"'Selected block does not allow manual collections.'",
")",
";",
"}",
"}",
"}"
]
| Validates block creation parameters from the request.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If validation failed | [
"Validates",
"block",
"creation",
"parameters",
"from",
"the",
"request",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Controller/API/V1/BlockCollection/ChangeCollectionType.php#L81-L125 | train |
netgen-layouts/layouts-core | lib/Serializer/Normalizer/V1/LayoutTypeNormalizer.php | LayoutTypeNormalizer.getZones | private function getZones(LayoutTypeInterface $layoutType): Generator
{
foreach ($layoutType->getZones() as $zone) {
$allowedBlockDefinitions = $zone->getAllowedBlockDefinitions();
yield [
'identifier' => $zone->getIdentifier(),
'name' => $zone->getName(),
'allowed_block_definitions' => count($allowedBlockDefinitions) > 0 ?
$allowedBlockDefinitions :
true,
];
}
} | php | private function getZones(LayoutTypeInterface $layoutType): Generator
{
foreach ($layoutType->getZones() as $zone) {
$allowedBlockDefinitions = $zone->getAllowedBlockDefinitions();
yield [
'identifier' => $zone->getIdentifier(),
'name' => $zone->getName(),
'allowed_block_definitions' => count($allowedBlockDefinitions) > 0 ?
$allowedBlockDefinitions :
true,
];
}
} | [
"private",
"function",
"getZones",
"(",
"LayoutTypeInterface",
"$",
"layoutType",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"layoutType",
"->",
"getZones",
"(",
")",
"as",
"$",
"zone",
")",
"{",
"$",
"allowedBlockDefinitions",
"=",
"$",
"zone",
"->",
"getAllowedBlockDefinitions",
"(",
")",
";",
"yield",
"[",
"'identifier'",
"=>",
"$",
"zone",
"->",
"getIdentifier",
"(",
")",
",",
"'name'",
"=>",
"$",
"zone",
"->",
"getName",
"(",
")",
",",
"'allowed_block_definitions'",
"=>",
"count",
"(",
"$",
"allowedBlockDefinitions",
")",
">",
"0",
"?",
"$",
"allowedBlockDefinitions",
":",
"true",
",",
"]",
";",
"}",
"}"
]
| Returns the array with layout type zones. | [
"Returns",
"the",
"array",
"with",
"layout",
"type",
"zones",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Serializer/Normalizer/V1/LayoutTypeNormalizer.php#L41-L54 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/EventListener/ViewRendererListener.php | ViewRendererListener.onView | public function onView(GetResponseForControllerResultEvent $event): void
{
$view = $event->getControllerResult();
if (!$view instanceof ViewInterface) {
return;
}
$response = $view->getResponse();
if (!$response instanceof Response) {
return;
}
$renderedView = '';
try {
$renderedView = $this->viewRenderer->renderView($view);
} catch (Throwable $t) {
$this->errorHandler->handleError($t);
}
$response->setContent($renderedView);
$event->setResponse($response);
} | php | public function onView(GetResponseForControllerResultEvent $event): void
{
$view = $event->getControllerResult();
if (!$view instanceof ViewInterface) {
return;
}
$response = $view->getResponse();
if (!$response instanceof Response) {
return;
}
$renderedView = '';
try {
$renderedView = $this->viewRenderer->renderView($view);
} catch (Throwable $t) {
$this->errorHandler->handleError($t);
}
$response->setContent($renderedView);
$event->setResponse($response);
} | [
"public",
"function",
"onView",
"(",
"GetResponseForControllerResultEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"view",
"=",
"$",
"event",
"->",
"getControllerResult",
"(",
")",
";",
"if",
"(",
"!",
"$",
"view",
"instanceof",
"ViewInterface",
")",
"{",
"return",
";",
"}",
"$",
"response",
"=",
"$",
"view",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"!",
"$",
"response",
"instanceof",
"Response",
")",
"{",
"return",
";",
"}",
"$",
"renderedView",
"=",
"''",
";",
"try",
"{",
"$",
"renderedView",
"=",
"$",
"this",
"->",
"viewRenderer",
"->",
"renderView",
"(",
"$",
"view",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"t",
")",
"{",
"$",
"this",
"->",
"errorHandler",
"->",
"handleError",
"(",
"$",
"t",
")",
";",
"}",
"$",
"response",
"->",
"setContent",
"(",
"$",
"renderedView",
")",
";",
"$",
"event",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"}"
]
| Renders the view provided by the event. | [
"Renders",
"the",
"view",
"provided",
"by",
"the",
"event",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/EventListener/ViewRendererListener.php#L42-L65 | train |
netgen-layouts/layouts-core | lib/Serializer/Normalizer/V1/CollectionResultSetNormalizer.php | CollectionResultSetNormalizer.getOverflowItems | private function getOverflowItems(ResultSet $resultSet): Generator
{
$includedPositions = [];
foreach ($resultSet->getResults() as $result) {
if ($result->getItem() instanceof ManualItem) {
$includedPositions[] = $result->getItem()->getCollectionItem()->getPosition();
}
if ($result->getSubItem() instanceof ManualItem) {
$includedPositions[] = $result->getSubItem()->getCollectionItem()->getPosition();
}
}
foreach ($resultSet->getCollection()->getItems() as $item) {
if (!in_array($item->getPosition(), $includedPositions, true)) {
yield $item;
}
}
} | php | private function getOverflowItems(ResultSet $resultSet): Generator
{
$includedPositions = [];
foreach ($resultSet->getResults() as $result) {
if ($result->getItem() instanceof ManualItem) {
$includedPositions[] = $result->getItem()->getCollectionItem()->getPosition();
}
if ($result->getSubItem() instanceof ManualItem) {
$includedPositions[] = $result->getSubItem()->getCollectionItem()->getPosition();
}
}
foreach ($resultSet->getCollection()->getItems() as $item) {
if (!in_array($item->getPosition(), $includedPositions, true)) {
yield $item;
}
}
} | [
"private",
"function",
"getOverflowItems",
"(",
"ResultSet",
"$",
"resultSet",
")",
":",
"Generator",
"{",
"$",
"includedPositions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"resultSet",
"->",
"getResults",
"(",
")",
"as",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"result",
"->",
"getItem",
"(",
")",
"instanceof",
"ManualItem",
")",
"{",
"$",
"includedPositions",
"[",
"]",
"=",
"$",
"result",
"->",
"getItem",
"(",
")",
"->",
"getCollectionItem",
"(",
")",
"->",
"getPosition",
"(",
")",
";",
"}",
"if",
"(",
"$",
"result",
"->",
"getSubItem",
"(",
")",
"instanceof",
"ManualItem",
")",
"{",
"$",
"includedPositions",
"[",
"]",
"=",
"$",
"result",
"->",
"getSubItem",
"(",
")",
"->",
"getCollectionItem",
"(",
")",
"->",
"getPosition",
"(",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"resultSet",
"->",
"getCollection",
"(",
")",
"->",
"getItems",
"(",
")",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"item",
"->",
"getPosition",
"(",
")",
",",
"$",
"includedPositions",
",",
"true",
")",
")",
"{",
"yield",
"$",
"item",
";",
"}",
"}",
"}"
]
| Returns all items from the collection which are overflown. Overflown items
are those NOT included in the provided result set, as defined by collection
offset and limit. | [
"Returns",
"all",
"items",
"from",
"the",
"collection",
"which",
"are",
"overflown",
".",
"Overflown",
"items",
"are",
"those",
"NOT",
"included",
"in",
"the",
"provided",
"result",
"set",
"as",
"defined",
"by",
"collection",
"offset",
"and",
"limit",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Serializer/Normalizer/V1/CollectionResultSetNormalizer.php#L45-L63 | train |
netgen-layouts/layouts-core | bundles/BlockManagerAdminBundle/EventListener/LayoutView/CacheEnabledListener.php | CacheEnabledListener.onBuildView | public function onBuildView(CollectViewParametersEvent $event): void
{
$view = $event->getView();
if (!$view instanceof LayoutViewInterface) {
return;
}
if ($view->getContext() !== ViewInterface::CONTEXT_ADMIN) {
return;
}
$event->addParameter('http_cache_enabled', $this->cacheEnabled);
} | php | public function onBuildView(CollectViewParametersEvent $event): void
{
$view = $event->getView();
if (!$view instanceof LayoutViewInterface) {
return;
}
if ($view->getContext() !== ViewInterface::CONTEXT_ADMIN) {
return;
}
$event->addParameter('http_cache_enabled', $this->cacheEnabled);
} | [
"public",
"function",
"onBuildView",
"(",
"CollectViewParametersEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"view",
"=",
"$",
"event",
"->",
"getView",
"(",
")",
";",
"if",
"(",
"!",
"$",
"view",
"instanceof",
"LayoutViewInterface",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"view",
"->",
"getContext",
"(",
")",
"!==",
"ViewInterface",
"::",
"CONTEXT_ADMIN",
")",
"{",
"return",
";",
"}",
"$",
"event",
"->",
"addParameter",
"(",
"'http_cache_enabled'",
",",
"$",
"this",
"->",
"cacheEnabled",
")",
";",
"}"
]
| Injects if the HTTP cache clearing is enabled or not. | [
"Injects",
"if",
"the",
"HTTP",
"cache",
"clearing",
"is",
"enabled",
"or",
"not",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerAdminBundle/EventListener/LayoutView/CacheEnabledListener.php#L35-L47 | train |
netgen-layouts/layouts-core | lib/Collection/Result/DynamicCollectionRunner.php | DynamicCollectionRunner.buildManualResult | private function buildManualResult(CollectionItem $collectionItem, Iterator $queryIterator): ?Result
{
if (!$this->visibilityResolver->isVisible($collectionItem) || !$collectionItem->isValid()) {
$queryValue = $this->getQueryValue($queryIterator);
if (!$queryValue instanceof CmsItemInterface) {
return null;
}
return new Result($collectionItem->getPosition(), $queryValue, new ManualItem($collectionItem));
}
return new Result($collectionItem->getPosition(), new ManualItem($collectionItem));
} | php | private function buildManualResult(CollectionItem $collectionItem, Iterator $queryIterator): ?Result
{
if (!$this->visibilityResolver->isVisible($collectionItem) || !$collectionItem->isValid()) {
$queryValue = $this->getQueryValue($queryIterator);
if (!$queryValue instanceof CmsItemInterface) {
return null;
}
return new Result($collectionItem->getPosition(), $queryValue, new ManualItem($collectionItem));
}
return new Result($collectionItem->getPosition(), new ManualItem($collectionItem));
} | [
"private",
"function",
"buildManualResult",
"(",
"CollectionItem",
"$",
"collectionItem",
",",
"Iterator",
"$",
"queryIterator",
")",
":",
"?",
"Result",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"visibilityResolver",
"->",
"isVisible",
"(",
"$",
"collectionItem",
")",
"||",
"!",
"$",
"collectionItem",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"queryValue",
"=",
"$",
"this",
"->",
"getQueryValue",
"(",
"$",
"queryIterator",
")",
";",
"if",
"(",
"!",
"$",
"queryValue",
"instanceof",
"CmsItemInterface",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"Result",
"(",
"$",
"collectionItem",
"->",
"getPosition",
"(",
")",
",",
"$",
"queryValue",
",",
"new",
"ManualItem",
"(",
"$",
"collectionItem",
")",
")",
";",
"}",
"return",
"new",
"Result",
"(",
"$",
"collectionItem",
"->",
"getPosition",
"(",
")",
",",
"new",
"ManualItem",
"(",
"$",
"collectionItem",
")",
")",
";",
"}"
]
| Builds the result from a manual item.
When manual items are invisible or invalid, they are pushed to the subitem role,
and the item which is displayed is the next query value. | [
"Builds",
"the",
"result",
"from",
"a",
"manual",
"item",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Result/DynamicCollectionRunner.php#L84-L96 | train |
netgen-layouts/layouts-core | lib/Collection/Result/DynamicCollectionRunner.php | DynamicCollectionRunner.getQueryValue | private function getQueryValue(Iterator $queryIterator)
{
if (!$queryIterator->valid()) {
return null;
}
$queryValue = $queryIterator->current();
$queryIterator->next();
return $queryValue;
} | php | private function getQueryValue(Iterator $queryIterator)
{
if (!$queryIterator->valid()) {
return null;
}
$queryValue = $queryIterator->current();
$queryIterator->next();
return $queryValue;
} | [
"private",
"function",
"getQueryValue",
"(",
"Iterator",
"$",
"queryIterator",
")",
"{",
"if",
"(",
"!",
"$",
"queryIterator",
"->",
"valid",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"queryValue",
"=",
"$",
"queryIterator",
"->",
"current",
"(",
")",
";",
"$",
"queryIterator",
"->",
"next",
"(",
")",
";",
"return",
"$",
"queryValue",
";",
"}"
]
| Returns the current value from the query and advances the iterator.
@param \Iterator $queryIterator
@return mixed | [
"Returns",
"the",
"current",
"value",
"from",
"the",
"query",
"and",
"advances",
"the",
"iterator",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Result/DynamicCollectionRunner.php#L105-L115 | train |
netgen-layouts/layouts-core | lib/Collection/Result/DynamicCollectionRunner.php | DynamicCollectionRunner.runQuery | private function runQuery(Collection $collection, int $offset, int $limit): Iterator
{
$collectionQuery = $collection->getQuery();
if (!$collectionQuery instanceof Query) {
return new ArrayIterator();
}
$queryOffset = $offset - $this->getManualItemsCount($collection, 0, $offset);
$queryLimit = $limit - $this->getManualItemsCount($collection, $offset, $offset + $limit);
return $this->queryRunner->runQuery($collectionQuery, $queryOffset, $queryLimit);
} | php | private function runQuery(Collection $collection, int $offset, int $limit): Iterator
{
$collectionQuery = $collection->getQuery();
if (!$collectionQuery instanceof Query) {
return new ArrayIterator();
}
$queryOffset = $offset - $this->getManualItemsCount($collection, 0, $offset);
$queryLimit = $limit - $this->getManualItemsCount($collection, $offset, $offset + $limit);
return $this->queryRunner->runQuery($collectionQuery, $queryOffset, $queryLimit);
} | [
"private",
"function",
"runQuery",
"(",
"Collection",
"$",
"collection",
",",
"int",
"$",
"offset",
",",
"int",
"$",
"limit",
")",
":",
"Iterator",
"{",
"$",
"collectionQuery",
"=",
"$",
"collection",
"->",
"getQuery",
"(",
")",
";",
"if",
"(",
"!",
"$",
"collectionQuery",
"instanceof",
"Query",
")",
"{",
"return",
"new",
"ArrayIterator",
"(",
")",
";",
"}",
"$",
"queryOffset",
"=",
"$",
"offset",
"-",
"$",
"this",
"->",
"getManualItemsCount",
"(",
"$",
"collection",
",",
"0",
",",
"$",
"offset",
")",
";",
"$",
"queryLimit",
"=",
"$",
"limit",
"-",
"$",
"this",
"->",
"getManualItemsCount",
"(",
"$",
"collection",
",",
"$",
"offset",
",",
"$",
"offset",
"+",
"$",
"limit",
")",
";",
"return",
"$",
"this",
"->",
"queryRunner",
"->",
"runQuery",
"(",
"$",
"collectionQuery",
",",
"$",
"queryOffset",
",",
"$",
"queryLimit",
")",
";",
"}"
]
| Returns the iterator that can be used to iterate over provided collection query. | [
"Returns",
"the",
"iterator",
"that",
"can",
"be",
"used",
"to",
"iterate",
"over",
"provided",
"collection",
"query",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Result/DynamicCollectionRunner.php#L120-L131 | train |
netgen-layouts/layouts-core | bundles/BlockManagerDebugBundle/EventListener/DataCollector/BlockViewListener.php | BlockViewListener.onBuildView | public function onBuildView(CollectViewParametersEvent $event): void
{
$view = $event->getView();
if (!$view instanceof BlockViewInterface) {
return;
}
if (!in_array($view->getContext(), $this->enabledContexts, true)) {
return;
}
$this->dataCollector->collectBlockView($view);
} | php | public function onBuildView(CollectViewParametersEvent $event): void
{
$view = $event->getView();
if (!$view instanceof BlockViewInterface) {
return;
}
if (!in_array($view->getContext(), $this->enabledContexts, true)) {
return;
}
$this->dataCollector->collectBlockView($view);
} | [
"public",
"function",
"onBuildView",
"(",
"CollectViewParametersEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"view",
"=",
"$",
"event",
"->",
"getView",
"(",
")",
";",
"if",
"(",
"!",
"$",
"view",
"instanceof",
"BlockViewInterface",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"view",
"->",
"getContext",
"(",
")",
",",
"$",
"this",
"->",
"enabledContexts",
",",
"true",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"dataCollector",
"->",
"collectBlockView",
"(",
"$",
"view",
")",
";",
"}"
]
| Includes results built from all block collections, if specified so. | [
"Includes",
"results",
"built",
"from",
"all",
"block",
"collections",
"if",
"specified",
"so",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerDebugBundle/EventListener/DataCollector/BlockViewListener.php#L43-L56 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Block/BlockTypePass.php | BlockTypePass.generateBlockTypeConfig | private function generateBlockTypeConfig(array $blockTypes, array $blockDefinitions): array
{
foreach ($blockDefinitions as $identifier => $blockDefinition) {
if (
isset($blockTypes[$identifier]['definition_identifier']) &&
$blockTypes[$identifier]['definition_identifier'] !== '' &&
$blockTypes[$identifier]['definition_identifier'] !== null &&
$blockTypes[$identifier]['definition_identifier'] !== $identifier
) {
// We skip the block types which have been completely redefined
// i.e. had the block definition identifier changed
continue;
}
if (!isset($blockTypes[$identifier])) {
$blockTypes[$identifier] = [
'name' => $blockDefinition['name'],
'icon' => $blockDefinition['icon'],
'enabled' => $blockDefinition['enabled'],
'definition_identifier' => $identifier,
'defaults' => [],
];
continue;
}
if (!$blockDefinition['enabled']) {
$blockTypes[$identifier]['enabled'] = false;
} elseif (!isset($blockTypes[$identifier]['enabled'])) {
$blockTypes[$identifier]['enabled'] = true;
}
$blockTypes[$identifier] += [
'name' => $blockDefinition['name'],
'icon' => $blockDefinition['icon'],
'definition_identifier' => $identifier,
];
}
foreach ($blockTypes as $identifier => $blockType) {
$definitionIdentifier = $blockType['definition_identifier'] ?? $identifier;
if (!isset($blockDefinitions[$definitionIdentifier])) {
continue;
}
if (!$blockDefinitions[$definitionIdentifier]['enabled']) {
$blockTypes[$identifier]['enabled'] = false;
}
}
return $blockTypes;
} | php | private function generateBlockTypeConfig(array $blockTypes, array $blockDefinitions): array
{
foreach ($blockDefinitions as $identifier => $blockDefinition) {
if (
isset($blockTypes[$identifier]['definition_identifier']) &&
$blockTypes[$identifier]['definition_identifier'] !== '' &&
$blockTypes[$identifier]['definition_identifier'] !== null &&
$blockTypes[$identifier]['definition_identifier'] !== $identifier
) {
// We skip the block types which have been completely redefined
// i.e. had the block definition identifier changed
continue;
}
if (!isset($blockTypes[$identifier])) {
$blockTypes[$identifier] = [
'name' => $blockDefinition['name'],
'icon' => $blockDefinition['icon'],
'enabled' => $blockDefinition['enabled'],
'definition_identifier' => $identifier,
'defaults' => [],
];
continue;
}
if (!$blockDefinition['enabled']) {
$blockTypes[$identifier]['enabled'] = false;
} elseif (!isset($blockTypes[$identifier]['enabled'])) {
$blockTypes[$identifier]['enabled'] = true;
}
$blockTypes[$identifier] += [
'name' => $blockDefinition['name'],
'icon' => $blockDefinition['icon'],
'definition_identifier' => $identifier,
];
}
foreach ($blockTypes as $identifier => $blockType) {
$definitionIdentifier = $blockType['definition_identifier'] ?? $identifier;
if (!isset($blockDefinitions[$definitionIdentifier])) {
continue;
}
if (!$blockDefinitions[$definitionIdentifier]['enabled']) {
$blockTypes[$identifier]['enabled'] = false;
}
}
return $blockTypes;
} | [
"private",
"function",
"generateBlockTypeConfig",
"(",
"array",
"$",
"blockTypes",
",",
"array",
"$",
"blockDefinitions",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"blockDefinitions",
"as",
"$",
"identifier",
"=>",
"$",
"blockDefinition",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"blockTypes",
"[",
"$",
"identifier",
"]",
"[",
"'definition_identifier'",
"]",
")",
"&&",
"$",
"blockTypes",
"[",
"$",
"identifier",
"]",
"[",
"'definition_identifier'",
"]",
"!==",
"''",
"&&",
"$",
"blockTypes",
"[",
"$",
"identifier",
"]",
"[",
"'definition_identifier'",
"]",
"!==",
"null",
"&&",
"$",
"blockTypes",
"[",
"$",
"identifier",
"]",
"[",
"'definition_identifier'",
"]",
"!==",
"$",
"identifier",
")",
"{",
"// We skip the block types which have been completely redefined",
"// i.e. had the block definition identifier changed",
"continue",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"blockTypes",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"$",
"blockTypes",
"[",
"$",
"identifier",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"blockDefinition",
"[",
"'name'",
"]",
",",
"'icon'",
"=>",
"$",
"blockDefinition",
"[",
"'icon'",
"]",
",",
"'enabled'",
"=>",
"$",
"blockDefinition",
"[",
"'enabled'",
"]",
",",
"'definition_identifier'",
"=>",
"$",
"identifier",
",",
"'defaults'",
"=>",
"[",
"]",
",",
"]",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"blockDefinition",
"[",
"'enabled'",
"]",
")",
"{",
"$",
"blockTypes",
"[",
"$",
"identifier",
"]",
"[",
"'enabled'",
"]",
"=",
"false",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"blockTypes",
"[",
"$",
"identifier",
"]",
"[",
"'enabled'",
"]",
")",
")",
"{",
"$",
"blockTypes",
"[",
"$",
"identifier",
"]",
"[",
"'enabled'",
"]",
"=",
"true",
";",
"}",
"$",
"blockTypes",
"[",
"$",
"identifier",
"]",
"+=",
"[",
"'name'",
"=>",
"$",
"blockDefinition",
"[",
"'name'",
"]",
",",
"'icon'",
"=>",
"$",
"blockDefinition",
"[",
"'icon'",
"]",
",",
"'definition_identifier'",
"=>",
"$",
"identifier",
",",
"]",
";",
"}",
"foreach",
"(",
"$",
"blockTypes",
"as",
"$",
"identifier",
"=>",
"$",
"blockType",
")",
"{",
"$",
"definitionIdentifier",
"=",
"$",
"blockType",
"[",
"'definition_identifier'",
"]",
"??",
"$",
"identifier",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"blockDefinitions",
"[",
"$",
"definitionIdentifier",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"blockDefinitions",
"[",
"$",
"definitionIdentifier",
"]",
"[",
"'enabled'",
"]",
")",
"{",
"$",
"blockTypes",
"[",
"$",
"identifier",
"]",
"[",
"'enabled'",
"]",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"blockTypes",
";",
"}"
]
| Generates the block type configuration from provided block definitions. | [
"Generates",
"the",
"block",
"type",
"configuration",
"from",
"provided",
"block",
"definitions",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Block/BlockTypePass.php#L42-L94 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Block/BlockTypePass.php | BlockTypePass.buildBlockTypes | private function buildBlockTypes(ContainerBuilder $container, array $blockTypes): Generator
{
foreach ($blockTypes as $identifier => $blockType) {
$serviceIdentifier = sprintf('netgen_block_manager.block.block_type.%s', $identifier);
$container->register($serviceIdentifier, BlockType::class)
->setArguments(
[
$identifier,
$blockType,
new Reference(
sprintf(
'netgen_block_manager.block.block_definition.%s',
$blockType['definition_identifier']
)
),
]
)
->setLazy(true)
->setPublic(true)
->setFactory([BlockTypeFactory::class, 'buildBlockType']);
yield $identifier => new Reference($serviceIdentifier);
}
} | php | private function buildBlockTypes(ContainerBuilder $container, array $blockTypes): Generator
{
foreach ($blockTypes as $identifier => $blockType) {
$serviceIdentifier = sprintf('netgen_block_manager.block.block_type.%s', $identifier);
$container->register($serviceIdentifier, BlockType::class)
->setArguments(
[
$identifier,
$blockType,
new Reference(
sprintf(
'netgen_block_manager.block.block_definition.%s',
$blockType['definition_identifier']
)
),
]
)
->setLazy(true)
->setPublic(true)
->setFactory([BlockTypeFactory::class, 'buildBlockType']);
yield $identifier => new Reference($serviceIdentifier);
}
} | [
"private",
"function",
"buildBlockTypes",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"blockTypes",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"blockTypes",
"as",
"$",
"identifier",
"=>",
"$",
"blockType",
")",
"{",
"$",
"serviceIdentifier",
"=",
"sprintf",
"(",
"'netgen_block_manager.block.block_type.%s'",
",",
"$",
"identifier",
")",
";",
"$",
"container",
"->",
"register",
"(",
"$",
"serviceIdentifier",
",",
"BlockType",
"::",
"class",
")",
"->",
"setArguments",
"(",
"[",
"$",
"identifier",
",",
"$",
"blockType",
",",
"new",
"Reference",
"(",
"sprintf",
"(",
"'netgen_block_manager.block.block_definition.%s'",
",",
"$",
"blockType",
"[",
"'definition_identifier'",
"]",
")",
")",
",",
"]",
")",
"->",
"setLazy",
"(",
"true",
")",
"->",
"setPublic",
"(",
"true",
")",
"->",
"setFactory",
"(",
"[",
"BlockTypeFactory",
"::",
"class",
",",
"'buildBlockType'",
"]",
")",
";",
"yield",
"$",
"identifier",
"=>",
"new",
"Reference",
"(",
"$",
"serviceIdentifier",
")",
";",
"}",
"}"
]
| Builds the block type objects from provided configuration. | [
"Builds",
"the",
"block",
"type",
"objects",
"from",
"provided",
"configuration",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Block/BlockTypePass.php#L99-L123 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Block/BlockTypePass.php | BlockTypePass.validateBlockTypes | private function validateBlockTypes(array $blockTypes, array $blockDefinitions): void
{
foreach ($blockTypes as $identifier => $blockType) {
if (!isset($blockDefinitions[$blockType['definition_identifier']])) {
throw new RuntimeException(
sprintf(
'Block definition "%s" used in "%s" block type does not exist.',
$blockType['definition_identifier'],
$identifier
)
);
}
}
} | php | private function validateBlockTypes(array $blockTypes, array $blockDefinitions): void
{
foreach ($blockTypes as $identifier => $blockType) {
if (!isset($blockDefinitions[$blockType['definition_identifier']])) {
throw new RuntimeException(
sprintf(
'Block definition "%s" used in "%s" block type does not exist.',
$blockType['definition_identifier'],
$identifier
)
);
}
}
} | [
"private",
"function",
"validateBlockTypes",
"(",
"array",
"$",
"blockTypes",
",",
"array",
"$",
"blockDefinitions",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"blockTypes",
"as",
"$",
"identifier",
"=>",
"$",
"blockType",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"blockDefinitions",
"[",
"$",
"blockType",
"[",
"'definition_identifier'",
"]",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Block definition \"%s\" used in \"%s\" block type does not exist.'",
",",
"$",
"blockType",
"[",
"'definition_identifier'",
"]",
",",
"$",
"identifier",
")",
")",
";",
"}",
"}",
"}"
]
| Validates block type config.
@throws \Netgen\BlockManager\Exception\RuntimeException If validation failed | [
"Validates",
"block",
"type",
"config",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Block/BlockTypePass.php#L130-L143 | train |
netgen-layouts/layouts-core | lib/Parameters/Form/Type/ParametersType.php | ParametersType.includeParameter | private function includeParameter(ParameterDefinition $parameterDefinition, array $groups): bool
{
$parameterGroups = $parameterDefinition->getGroups();
if (count($parameterGroups) === 0 || count($groups) === 0) {
return true;
}
return count(array_intersect($parameterGroups, $groups)) > 0;
} | php | private function includeParameter(ParameterDefinition $parameterDefinition, array $groups): bool
{
$parameterGroups = $parameterDefinition->getGroups();
if (count($parameterGroups) === 0 || count($groups) === 0) {
return true;
}
return count(array_intersect($parameterGroups, $groups)) > 0;
} | [
"private",
"function",
"includeParameter",
"(",
"ParameterDefinition",
"$",
"parameterDefinition",
",",
"array",
"$",
"groups",
")",
":",
"bool",
"{",
"$",
"parameterGroups",
"=",
"$",
"parameterDefinition",
"->",
"getGroups",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parameterGroups",
")",
"===",
"0",
"||",
"count",
"(",
"$",
"groups",
")",
"===",
"0",
")",
"{",
"return",
"true",
";",
"}",
"return",
"count",
"(",
"array_intersect",
"(",
"$",
"parameterGroups",
",",
"$",
"groups",
")",
")",
">",
"0",
";",
"}"
]
| Returns if the parameter will be included in the form based on provided groups. | [
"Returns",
"if",
"the",
"parameter",
"will",
"be",
"included",
"in",
"the",
"form",
"based",
"on",
"provided",
"groups",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Parameters/Form/Type/ParametersType.php#L125-L134 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/Handler/BlockHandler.php | BlockHandler.copyBlockCollections | private function copyBlockCollections(Block $block, Block $targetBlock): void
{
$collectionReferences = $this->loadCollectionReferences($block);
foreach ($collectionReferences as $collectionReference) {
$collection = $this->collectionHandler->loadCollection(
$collectionReference->collectionId,
$collectionReference->collectionStatus
);
$collection = $this->collectionHandler->copyCollection($collection);
$newCollectionReference = CollectionReference::fromArray(
[
'blockId' => $targetBlock->id,
'blockStatus' => $targetBlock->status,
'collectionId' => $collection->id,
'collectionStatus' => $collection->status,
'identifier' => $collectionReference->identifier,
]
);
$this->queryHandler->createCollectionReference($newCollectionReference);
}
} | php | private function copyBlockCollections(Block $block, Block $targetBlock): void
{
$collectionReferences = $this->loadCollectionReferences($block);
foreach ($collectionReferences as $collectionReference) {
$collection = $this->collectionHandler->loadCollection(
$collectionReference->collectionId,
$collectionReference->collectionStatus
);
$collection = $this->collectionHandler->copyCollection($collection);
$newCollectionReference = CollectionReference::fromArray(
[
'blockId' => $targetBlock->id,
'blockStatus' => $targetBlock->status,
'collectionId' => $collection->id,
'collectionStatus' => $collection->status,
'identifier' => $collectionReference->identifier,
]
);
$this->queryHandler->createCollectionReference($newCollectionReference);
}
} | [
"private",
"function",
"copyBlockCollections",
"(",
"Block",
"$",
"block",
",",
"Block",
"$",
"targetBlock",
")",
":",
"void",
"{",
"$",
"collectionReferences",
"=",
"$",
"this",
"->",
"loadCollectionReferences",
"(",
"$",
"block",
")",
";",
"foreach",
"(",
"$",
"collectionReferences",
"as",
"$",
"collectionReference",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"collectionHandler",
"->",
"loadCollection",
"(",
"$",
"collectionReference",
"->",
"collectionId",
",",
"$",
"collectionReference",
"->",
"collectionStatus",
")",
";",
"$",
"collection",
"=",
"$",
"this",
"->",
"collectionHandler",
"->",
"copyCollection",
"(",
"$",
"collection",
")",
";",
"$",
"newCollectionReference",
"=",
"CollectionReference",
"::",
"fromArray",
"(",
"[",
"'blockId'",
"=>",
"$",
"targetBlock",
"->",
"id",
",",
"'blockStatus'",
"=>",
"$",
"targetBlock",
"->",
"status",
",",
"'collectionId'",
"=>",
"$",
"collection",
"->",
"id",
",",
"'collectionStatus'",
"=>",
"$",
"collection",
"->",
"status",
",",
"'identifier'",
"=>",
"$",
"collectionReference",
"->",
"identifier",
",",
"]",
")",
";",
"$",
"this",
"->",
"queryHandler",
"->",
"createCollectionReference",
"(",
"$",
"newCollectionReference",
")",
";",
"}",
"}"
]
| Copies all block collections to another block. | [
"Copies",
"all",
"block",
"collections",
"to",
"another",
"block",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/Handler/BlockHandler.php#L502-L526 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/Handler/BlockHandler.php | BlockHandler.createBlockCollectionsStatus | private function createBlockCollectionsStatus(Block $block, int $newStatus): void
{
$collectionReferences = $this->loadCollectionReferences($block);
foreach ($collectionReferences as $collectionReference) {
$collection = $this->collectionHandler->loadCollection(
$collectionReference->collectionId,
$collectionReference->collectionStatus
);
$collection = $this->collectionHandler->createCollectionStatus(
$collection,
$newStatus
);
$newCollectionReference = CollectionReference::fromArray(
[
'blockId' => $block->id,
'blockStatus' => $newStatus,
'collectionId' => $collection->id,
'collectionStatus' => $collection->status,
'identifier' => $collectionReference->identifier,
]
);
$this->queryHandler->createCollectionReference($newCollectionReference);
}
} | php | private function createBlockCollectionsStatus(Block $block, int $newStatus): void
{
$collectionReferences = $this->loadCollectionReferences($block);
foreach ($collectionReferences as $collectionReference) {
$collection = $this->collectionHandler->loadCollection(
$collectionReference->collectionId,
$collectionReference->collectionStatus
);
$collection = $this->collectionHandler->createCollectionStatus(
$collection,
$newStatus
);
$newCollectionReference = CollectionReference::fromArray(
[
'blockId' => $block->id,
'blockStatus' => $newStatus,
'collectionId' => $collection->id,
'collectionStatus' => $collection->status,
'identifier' => $collectionReference->identifier,
]
);
$this->queryHandler->createCollectionReference($newCollectionReference);
}
} | [
"private",
"function",
"createBlockCollectionsStatus",
"(",
"Block",
"$",
"block",
",",
"int",
"$",
"newStatus",
")",
":",
"void",
"{",
"$",
"collectionReferences",
"=",
"$",
"this",
"->",
"loadCollectionReferences",
"(",
"$",
"block",
")",
";",
"foreach",
"(",
"$",
"collectionReferences",
"as",
"$",
"collectionReference",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"collectionHandler",
"->",
"loadCollection",
"(",
"$",
"collectionReference",
"->",
"collectionId",
",",
"$",
"collectionReference",
"->",
"collectionStatus",
")",
";",
"$",
"collection",
"=",
"$",
"this",
"->",
"collectionHandler",
"->",
"createCollectionStatus",
"(",
"$",
"collection",
",",
"$",
"newStatus",
")",
";",
"$",
"newCollectionReference",
"=",
"CollectionReference",
"::",
"fromArray",
"(",
"[",
"'blockId'",
"=>",
"$",
"block",
"->",
"id",
",",
"'blockStatus'",
"=>",
"$",
"newStatus",
",",
"'collectionId'",
"=>",
"$",
"collection",
"->",
"id",
",",
"'collectionStatus'",
"=>",
"$",
"collection",
"->",
"status",
",",
"'identifier'",
"=>",
"$",
"collectionReference",
"->",
"identifier",
",",
"]",
")",
";",
"$",
"this",
"->",
"queryHandler",
"->",
"createCollectionReference",
"(",
"$",
"newCollectionReference",
")",
";",
"}",
"}"
]
| Creates a new status for all collections in specified block.
This method does not create new status for sub-block collections,
so any process that works with this method needs to take care of that. | [
"Creates",
"a",
"new",
"status",
"for",
"all",
"collections",
"in",
"specified",
"block",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/Handler/BlockHandler.php#L534-L561 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/Handler/BlockHandler.php | BlockHandler.deleteBlockCollections | private function deleteBlockCollections(array $blockIds, ?int $status = null): void
{
$collectionIds = $this->queryHandler->loadBlockCollectionIds($blockIds, $status);
foreach ($collectionIds as $collectionId) {
$this->collectionHandler->deleteCollection($collectionId, $status);
}
$this->queryHandler->deleteCollectionReferences($blockIds, $status);
} | php | private function deleteBlockCollections(array $blockIds, ?int $status = null): void
{
$collectionIds = $this->queryHandler->loadBlockCollectionIds($blockIds, $status);
foreach ($collectionIds as $collectionId) {
$this->collectionHandler->deleteCollection($collectionId, $status);
}
$this->queryHandler->deleteCollectionReferences($blockIds, $status);
} | [
"private",
"function",
"deleteBlockCollections",
"(",
"array",
"$",
"blockIds",
",",
"?",
"int",
"$",
"status",
"=",
"null",
")",
":",
"void",
"{",
"$",
"collectionIds",
"=",
"$",
"this",
"->",
"queryHandler",
"->",
"loadBlockCollectionIds",
"(",
"$",
"blockIds",
",",
"$",
"status",
")",
";",
"foreach",
"(",
"$",
"collectionIds",
"as",
"$",
"collectionId",
")",
"{",
"$",
"this",
"->",
"collectionHandler",
"->",
"deleteCollection",
"(",
"$",
"collectionId",
",",
"$",
"status",
")",
";",
"}",
"$",
"this",
"->",
"queryHandler",
"->",
"deleteCollectionReferences",
"(",
"$",
"blockIds",
",",
"$",
"status",
")",
";",
"}"
]
| Deletes block collections with specified block IDs.
This method does not delete block collections from sub-blocks,
so this should be used only when deleting the entire layout. | [
"Deletes",
"block",
"collections",
"with",
"specified",
"block",
"IDs",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/Handler/BlockHandler.php#L569-L577 | train |
netgen-layouts/layouts-core | lib/View/TemplateResolver.php | TemplateResolver.matches | private function matches(ViewInterface $view, array $matchConfig): bool
{
foreach ($matchConfig as $matcher => $matcherConfig) {
if (!isset($this->matchers[$matcher])) {
throw TemplateResolverException::noTemplateMatcher($matcher);
}
$matcherConfig = !is_array($matcherConfig) ? [$matcherConfig] : $matcherConfig;
if (!$this->matchers[$matcher]->match($view, $matcherConfig)) {
return false;
}
}
return true;
} | php | private function matches(ViewInterface $view, array $matchConfig): bool
{
foreach ($matchConfig as $matcher => $matcherConfig) {
if (!isset($this->matchers[$matcher])) {
throw TemplateResolverException::noTemplateMatcher($matcher);
}
$matcherConfig = !is_array($matcherConfig) ? [$matcherConfig] : $matcherConfig;
if (!$this->matchers[$matcher]->match($view, $matcherConfig)) {
return false;
}
}
return true;
} | [
"private",
"function",
"matches",
"(",
"ViewInterface",
"$",
"view",
",",
"array",
"$",
"matchConfig",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"matchConfig",
"as",
"$",
"matcher",
"=>",
"$",
"matcherConfig",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"matchers",
"[",
"$",
"matcher",
"]",
")",
")",
"{",
"throw",
"TemplateResolverException",
"::",
"noTemplateMatcher",
"(",
"$",
"matcher",
")",
";",
"}",
"$",
"matcherConfig",
"=",
"!",
"is_array",
"(",
"$",
"matcherConfig",
")",
"?",
"[",
"$",
"matcherConfig",
"]",
":",
"$",
"matcherConfig",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"matchers",
"[",
"$",
"matcher",
"]",
"->",
"match",
"(",
"$",
"view",
",",
"$",
"matcherConfig",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Matches the view to provided config with configured matchers. | [
"Matches",
"the",
"view",
"to",
"provided",
"config",
"with",
"configured",
"matchers",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/View/TemplateResolver.php#L81-L95 | train |
netgen-layouts/layouts-core | lib/View/TemplateResolver.php | TemplateResolver.evaluateParameters | private function evaluateParameters(ViewInterface $view, array $parameters): Generator
{
foreach ($parameters as $key => $value) {
if (is_string($value) && mb_strpos($value, '@=') === 0) {
$expressionLanguage = new ExpressionLanguage();
$value = $expressionLanguage->evaluate(
mb_substr($value, 2),
[
'view' => $view,
] + $view->getParameters()
);
}
yield $key => $value;
}
} | php | private function evaluateParameters(ViewInterface $view, array $parameters): Generator
{
foreach ($parameters as $key => $value) {
if (is_string($value) && mb_strpos($value, '@=') === 0) {
$expressionLanguage = new ExpressionLanguage();
$value = $expressionLanguage->evaluate(
mb_substr($value, 2),
[
'view' => $view,
] + $view->getParameters()
);
}
yield $key => $value;
}
} | [
"private",
"function",
"evaluateParameters",
"(",
"ViewInterface",
"$",
"view",
",",
"array",
"$",
"parameters",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"mb_strpos",
"(",
"$",
"value",
",",
"'@='",
")",
"===",
"0",
")",
"{",
"$",
"expressionLanguage",
"=",
"new",
"ExpressionLanguage",
"(",
")",
";",
"$",
"value",
"=",
"$",
"expressionLanguage",
"->",
"evaluate",
"(",
"mb_substr",
"(",
"$",
"value",
",",
"2",
")",
",",
"[",
"'view'",
"=>",
"$",
"view",
",",
"]",
"+",
"$",
"view",
"->",
"getParameters",
"(",
")",
")",
";",
"}",
"yield",
"$",
"key",
"=>",
"$",
"value",
";",
"}",
"}"
]
| Iterates over all provided parameters and evaluates the values with expression
engine if the parameter value specifies so. | [
"Iterates",
"over",
"all",
"provided",
"parameters",
"and",
"evaluates",
"the",
"values",
"with",
"expression",
"engine",
"if",
"the",
"parameter",
"value",
"specifies",
"so",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/View/TemplateResolver.php#L101-L116 | train |
phwoolcon/phwoolcon | src/Controller.php | Controller.jsonReturn | protected function jsonReturn(array $array, $httpCode = 200, $contentType = 'application/json')
{
return $this->response->setHeader('Content-Type', $contentType)
->setStatusCode($httpCode)
->setJsonContent($array);
} | php | protected function jsonReturn(array $array, $httpCode = 200, $contentType = 'application/json')
{
return $this->response->setHeader('Content-Type', $contentType)
->setStatusCode($httpCode)
->setJsonContent($array);
} | [
"protected",
"function",
"jsonReturn",
"(",
"array",
"$",
"array",
",",
"$",
"httpCode",
"=",
"200",
",",
"$",
"contentType",
"=",
"'application/json'",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"$",
"contentType",
")",
"->",
"setStatusCode",
"(",
"$",
"httpCode",
")",
"->",
"setJsonContent",
"(",
"$",
"array",
")",
";",
"}"
]
| response json content
@param array $array
@param int $httpCode
@param string $contentType
@return \Phalcon\Http\Response | [
"response",
"json",
"content"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/Controller.php#L124-L129 | train |
phwoolcon/phwoolcon | src/Controller.php | Controller.input | protected function input($key = null, $defaultValue = null)
{
return is_null($key) ? $_REQUEST : fnGet($_REQUEST, $key, $defaultValue);
} | php | protected function input($key = null, $defaultValue = null)
{
return is_null($key) ? $_REQUEST : fnGet($_REQUEST, $key, $defaultValue);
} | [
"protected",
"function",
"input",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"return",
"is_null",
"(",
"$",
"key",
")",
"?",
"$",
"_REQUEST",
":",
"fnGet",
"(",
"$",
"_REQUEST",
",",
"$",
"key",
",",
"$",
"defaultValue",
")",
";",
"}"
]
| Get input from request
@param string $key
@param mixed $defaultValue
@return mixed | [
"Get",
"input",
"from",
"request"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/Controller.php#L150-L153 | train |
phwoolcon/phwoolcon | src/View/Widget.php | Widget.builtInLabel | protected static function builtInLabel(array $parameters, $innerHtml)
{
return Tag::tagHtml('label', $parameters, false, true) . $innerHtml . Tag::tagHtmlClose('label');
} | php | protected static function builtInLabel(array $parameters, $innerHtml)
{
return Tag::tagHtml('label', $parameters, false, true) . $innerHtml . Tag::tagHtmlClose('label');
} | [
"protected",
"static",
"function",
"builtInLabel",
"(",
"array",
"$",
"parameters",
",",
"$",
"innerHtml",
")",
"{",
"return",
"Tag",
"::",
"tagHtml",
"(",
"'label'",
",",
"$",
"parameters",
",",
"false",
",",
"true",
")",
".",
"$",
"innerHtml",
".",
"Tag",
"::",
"tagHtmlClose",
"(",
"'label'",
")",
";",
"}"
]
| Make a label element
Required parameters:
$innerHtml
Optional parameters:
'for', 'class', or other html attributes
@param array $parameters
@param string $innerHtml
@return string | [
"Make",
"a",
"label",
"element"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/View/Widget.php#L75-L78 | train |
phwoolcon/phwoolcon | src/View/Widget.php | Widget.builtInMultipleChoose | protected static function builtInMultipleChoose(array $parameters)
{
static::checkRequiredParameters($parameters, ['id', 'options']);
$options = (array)$parameters['options'];
$parameters[0] = $id = $parameters['id'];
$expand = isset($parameters['expand']) ? $parameters['expand'] : 'auto';
unset($parameters['options'], $parameters['expand']);
// Expand select into radio buttons
if ($expand === true || ($expand == 'auto' && count($options) < 5)) {
$html = [];
$i = 0;
$radioParams = $parameters;
$labelOn = isset($radioParams['labelOn']) ? $radioParams['labelOn'] : 'right';
$prefix = isset($radioParams['prefix']) ? $radioParams['prefix'] : '';
$suffix = isset($radioParams['suffix']) ? $radioParams['suffix'] : '';
unset($radioParams['expand'], $radioParams['labelOn'], $radioParams['prefix'], $radioParams['suffix']);
unset($radioParams['options'], $radioParams['useEmpty'], $radioParams['emptyText']);
$selected = isset($parameters['value']) ? array_flip((array)$parameters['value']) : [];
foreach ($options as $value => $label) {
$radioParams['id'] = $radioId = $id . '_' . $i;
$radioParams['value'] = $value;
if (isset($selected[(string)$value])) {
$radioParams['checked'] = 'checked';
} else {
$radioParams['checked'] = null;
}
$checkbox = Tag::checkField($radioParams);
if ($labelOn == 'right') {
$checkbox .= PHP_EOL . $label;
} else {
$checkbox = $label . PHP_EOL . $checkbox;
}
$checkbox = static::label(['for' => $radioId], $checkbox);
++$i;
$html[] = $prefix . $checkbox . $suffix;
}
return implode(PHP_EOL, $html);
}
$parameters['multiple'] = true;
return Tag::select($parameters, $options);
} | php | protected static function builtInMultipleChoose(array $parameters)
{
static::checkRequiredParameters($parameters, ['id', 'options']);
$options = (array)$parameters['options'];
$parameters[0] = $id = $parameters['id'];
$expand = isset($parameters['expand']) ? $parameters['expand'] : 'auto';
unset($parameters['options'], $parameters['expand']);
// Expand select into radio buttons
if ($expand === true || ($expand == 'auto' && count($options) < 5)) {
$html = [];
$i = 0;
$radioParams = $parameters;
$labelOn = isset($radioParams['labelOn']) ? $radioParams['labelOn'] : 'right';
$prefix = isset($radioParams['prefix']) ? $radioParams['prefix'] : '';
$suffix = isset($radioParams['suffix']) ? $radioParams['suffix'] : '';
unset($radioParams['expand'], $radioParams['labelOn'], $radioParams['prefix'], $radioParams['suffix']);
unset($radioParams['options'], $radioParams['useEmpty'], $radioParams['emptyText']);
$selected = isset($parameters['value']) ? array_flip((array)$parameters['value']) : [];
foreach ($options as $value => $label) {
$radioParams['id'] = $radioId = $id . '_' . $i;
$radioParams['value'] = $value;
if (isset($selected[(string)$value])) {
$radioParams['checked'] = 'checked';
} else {
$radioParams['checked'] = null;
}
$checkbox = Tag::checkField($radioParams);
if ($labelOn == 'right') {
$checkbox .= PHP_EOL . $label;
} else {
$checkbox = $label . PHP_EOL . $checkbox;
}
$checkbox = static::label(['for' => $radioId], $checkbox);
++$i;
$html[] = $prefix . $checkbox . $suffix;
}
return implode(PHP_EOL, $html);
}
$parameters['multiple'] = true;
return Tag::select($parameters, $options);
} | [
"protected",
"static",
"function",
"builtInMultipleChoose",
"(",
"array",
"$",
"parameters",
")",
"{",
"static",
"::",
"checkRequiredParameters",
"(",
"$",
"parameters",
",",
"[",
"'id'",
",",
"'options'",
"]",
")",
";",
"$",
"options",
"=",
"(",
"array",
")",
"$",
"parameters",
"[",
"'options'",
"]",
";",
"$",
"parameters",
"[",
"0",
"]",
"=",
"$",
"id",
"=",
"$",
"parameters",
"[",
"'id'",
"]",
";",
"$",
"expand",
"=",
"isset",
"(",
"$",
"parameters",
"[",
"'expand'",
"]",
")",
"?",
"$",
"parameters",
"[",
"'expand'",
"]",
":",
"'auto'",
";",
"unset",
"(",
"$",
"parameters",
"[",
"'options'",
"]",
",",
"$",
"parameters",
"[",
"'expand'",
"]",
")",
";",
"// Expand select into radio buttons",
"if",
"(",
"$",
"expand",
"===",
"true",
"||",
"(",
"$",
"expand",
"==",
"'auto'",
"&&",
"count",
"(",
"$",
"options",
")",
"<",
"5",
")",
")",
"{",
"$",
"html",
"=",
"[",
"]",
";",
"$",
"i",
"=",
"0",
";",
"$",
"radioParams",
"=",
"$",
"parameters",
";",
"$",
"labelOn",
"=",
"isset",
"(",
"$",
"radioParams",
"[",
"'labelOn'",
"]",
")",
"?",
"$",
"radioParams",
"[",
"'labelOn'",
"]",
":",
"'right'",
";",
"$",
"prefix",
"=",
"isset",
"(",
"$",
"radioParams",
"[",
"'prefix'",
"]",
")",
"?",
"$",
"radioParams",
"[",
"'prefix'",
"]",
":",
"''",
";",
"$",
"suffix",
"=",
"isset",
"(",
"$",
"radioParams",
"[",
"'suffix'",
"]",
")",
"?",
"$",
"radioParams",
"[",
"'suffix'",
"]",
":",
"''",
";",
"unset",
"(",
"$",
"radioParams",
"[",
"'expand'",
"]",
",",
"$",
"radioParams",
"[",
"'labelOn'",
"]",
",",
"$",
"radioParams",
"[",
"'prefix'",
"]",
",",
"$",
"radioParams",
"[",
"'suffix'",
"]",
")",
";",
"unset",
"(",
"$",
"radioParams",
"[",
"'options'",
"]",
",",
"$",
"radioParams",
"[",
"'useEmpty'",
"]",
",",
"$",
"radioParams",
"[",
"'emptyText'",
"]",
")",
";",
"$",
"selected",
"=",
"isset",
"(",
"$",
"parameters",
"[",
"'value'",
"]",
")",
"?",
"array_flip",
"(",
"(",
"array",
")",
"$",
"parameters",
"[",
"'value'",
"]",
")",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"value",
"=>",
"$",
"label",
")",
"{",
"$",
"radioParams",
"[",
"'id'",
"]",
"=",
"$",
"radioId",
"=",
"$",
"id",
".",
"'_'",
".",
"$",
"i",
";",
"$",
"radioParams",
"[",
"'value'",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"isset",
"(",
"$",
"selected",
"[",
"(",
"string",
")",
"$",
"value",
"]",
")",
")",
"{",
"$",
"radioParams",
"[",
"'checked'",
"]",
"=",
"'checked'",
";",
"}",
"else",
"{",
"$",
"radioParams",
"[",
"'checked'",
"]",
"=",
"null",
";",
"}",
"$",
"checkbox",
"=",
"Tag",
"::",
"checkField",
"(",
"$",
"radioParams",
")",
";",
"if",
"(",
"$",
"labelOn",
"==",
"'right'",
")",
"{",
"$",
"checkbox",
".=",
"PHP_EOL",
".",
"$",
"label",
";",
"}",
"else",
"{",
"$",
"checkbox",
"=",
"$",
"label",
".",
"PHP_EOL",
".",
"$",
"checkbox",
";",
"}",
"$",
"checkbox",
"=",
"static",
"::",
"label",
"(",
"[",
"'for'",
"=>",
"$",
"radioId",
"]",
",",
"$",
"checkbox",
")",
";",
"++",
"$",
"i",
";",
"$",
"html",
"[",
"]",
"=",
"$",
"prefix",
".",
"$",
"checkbox",
".",
"$",
"suffix",
";",
"}",
"return",
"implode",
"(",
"PHP_EOL",
",",
"$",
"html",
")",
";",
"}",
"$",
"parameters",
"[",
"'multiple'",
"]",
"=",
"true",
";",
"return",
"Tag",
"::",
"select",
"(",
"$",
"parameters",
",",
"$",
"options",
")",
";",
"}"
]
| Make a multiple select widget, if options < 5 it will be expanded into radios by default
Required parameters:
'id', 'options' (in array)
Optional parameters:
'name', 'class', 'value' (selected value) or other html attributes
'expand' (true or false, by default 'auto')
'useEmpty', 'emptyText' (used in select mode)
'prefix', 'suffix' (used to wrap radios in expanded mode)
'labelOn' ('left' or 'right', by default 'right', used to identify radios in expanded mode)
@param array $parameters
@return string | [
"Make",
"a",
"multiple",
"select",
"widget",
"if",
"options",
"<",
"5",
"it",
"will",
"be",
"expanded",
"into",
"radios",
"by",
"default"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/View/Widget.php#L95-L136 | train |
phwoolcon/phwoolcon | src/View/Widget.php | Widget.builtInSingleChoose | protected static function builtInSingleChoose(array $parameters)
{
static::checkRequiredParameters($parameters, ['id', 'options']);
$options = (array)$parameters['options'];
$parameters[0] = $id = $parameters['id'];
$expand = isset($parameters['expand']) ? $parameters['expand'] : 'auto';
unset($parameters['options'], $parameters['expand']);
// Expand select into radio buttons
if ($expand === true || ($expand == 'auto' && count($options) < 5)) {
$html = [];
$i = 0;
$radioParams = $parameters;
$labelOn = isset($radioParams['labelOn']) ? $radioParams['labelOn'] : 'right';
$prefix = isset($radioParams['prefix']) ? $radioParams['prefix'] : '';
$suffix = isset($radioParams['suffix']) ? $radioParams['suffix'] : '';
unset($radioParams['expand'], $radioParams['labelOn'], $radioParams['prefix'], $radioParams['suffix']);
unset($radioParams['options'], $radioParams['useEmpty'], $radioParams['emptyText']);
$selected = isset($parameters['value']) ? (string)$parameters['value'] : '';
foreach ($options as $value => $label) {
$radioParams['id'] = $radioId = $id . '_' . $i;
$radioParams['value'] = $value;
if ((string)$value === $selected) {
$radioParams['checked'] = 'checked';
} else {
$radioParams['checked'] = null;
}
$radio = Tag::radioField($radioParams);
if ($labelOn == 'right') {
$radio .= PHP_EOL . $label;
} else {
$radio = $label . PHP_EOL . $radio;
}
$radio = static::label(['for' => $radioId], $radio);
++$i;
$html[] = $prefix . $radio . $suffix;
}
return implode(PHP_EOL, $html);
}
return Tag::select($parameters, $options);
} | php | protected static function builtInSingleChoose(array $parameters)
{
static::checkRequiredParameters($parameters, ['id', 'options']);
$options = (array)$parameters['options'];
$parameters[0] = $id = $parameters['id'];
$expand = isset($parameters['expand']) ? $parameters['expand'] : 'auto';
unset($parameters['options'], $parameters['expand']);
// Expand select into radio buttons
if ($expand === true || ($expand == 'auto' && count($options) < 5)) {
$html = [];
$i = 0;
$radioParams = $parameters;
$labelOn = isset($radioParams['labelOn']) ? $radioParams['labelOn'] : 'right';
$prefix = isset($radioParams['prefix']) ? $radioParams['prefix'] : '';
$suffix = isset($radioParams['suffix']) ? $radioParams['suffix'] : '';
unset($radioParams['expand'], $radioParams['labelOn'], $radioParams['prefix'], $radioParams['suffix']);
unset($radioParams['options'], $radioParams['useEmpty'], $radioParams['emptyText']);
$selected = isset($parameters['value']) ? (string)$parameters['value'] : '';
foreach ($options as $value => $label) {
$radioParams['id'] = $radioId = $id . '_' . $i;
$radioParams['value'] = $value;
if ((string)$value === $selected) {
$radioParams['checked'] = 'checked';
} else {
$radioParams['checked'] = null;
}
$radio = Tag::radioField($radioParams);
if ($labelOn == 'right') {
$radio .= PHP_EOL . $label;
} else {
$radio = $label . PHP_EOL . $radio;
}
$radio = static::label(['for' => $radioId], $radio);
++$i;
$html[] = $prefix . $radio . $suffix;
}
return implode(PHP_EOL, $html);
}
return Tag::select($parameters, $options);
} | [
"protected",
"static",
"function",
"builtInSingleChoose",
"(",
"array",
"$",
"parameters",
")",
"{",
"static",
"::",
"checkRequiredParameters",
"(",
"$",
"parameters",
",",
"[",
"'id'",
",",
"'options'",
"]",
")",
";",
"$",
"options",
"=",
"(",
"array",
")",
"$",
"parameters",
"[",
"'options'",
"]",
";",
"$",
"parameters",
"[",
"0",
"]",
"=",
"$",
"id",
"=",
"$",
"parameters",
"[",
"'id'",
"]",
";",
"$",
"expand",
"=",
"isset",
"(",
"$",
"parameters",
"[",
"'expand'",
"]",
")",
"?",
"$",
"parameters",
"[",
"'expand'",
"]",
":",
"'auto'",
";",
"unset",
"(",
"$",
"parameters",
"[",
"'options'",
"]",
",",
"$",
"parameters",
"[",
"'expand'",
"]",
")",
";",
"// Expand select into radio buttons",
"if",
"(",
"$",
"expand",
"===",
"true",
"||",
"(",
"$",
"expand",
"==",
"'auto'",
"&&",
"count",
"(",
"$",
"options",
")",
"<",
"5",
")",
")",
"{",
"$",
"html",
"=",
"[",
"]",
";",
"$",
"i",
"=",
"0",
";",
"$",
"radioParams",
"=",
"$",
"parameters",
";",
"$",
"labelOn",
"=",
"isset",
"(",
"$",
"radioParams",
"[",
"'labelOn'",
"]",
")",
"?",
"$",
"radioParams",
"[",
"'labelOn'",
"]",
":",
"'right'",
";",
"$",
"prefix",
"=",
"isset",
"(",
"$",
"radioParams",
"[",
"'prefix'",
"]",
")",
"?",
"$",
"radioParams",
"[",
"'prefix'",
"]",
":",
"''",
";",
"$",
"suffix",
"=",
"isset",
"(",
"$",
"radioParams",
"[",
"'suffix'",
"]",
")",
"?",
"$",
"radioParams",
"[",
"'suffix'",
"]",
":",
"''",
";",
"unset",
"(",
"$",
"radioParams",
"[",
"'expand'",
"]",
",",
"$",
"radioParams",
"[",
"'labelOn'",
"]",
",",
"$",
"radioParams",
"[",
"'prefix'",
"]",
",",
"$",
"radioParams",
"[",
"'suffix'",
"]",
")",
";",
"unset",
"(",
"$",
"radioParams",
"[",
"'options'",
"]",
",",
"$",
"radioParams",
"[",
"'useEmpty'",
"]",
",",
"$",
"radioParams",
"[",
"'emptyText'",
"]",
")",
";",
"$",
"selected",
"=",
"isset",
"(",
"$",
"parameters",
"[",
"'value'",
"]",
")",
"?",
"(",
"string",
")",
"$",
"parameters",
"[",
"'value'",
"]",
":",
"''",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"value",
"=>",
"$",
"label",
")",
"{",
"$",
"radioParams",
"[",
"'id'",
"]",
"=",
"$",
"radioId",
"=",
"$",
"id",
".",
"'_'",
".",
"$",
"i",
";",
"$",
"radioParams",
"[",
"'value'",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"(",
"string",
")",
"$",
"value",
"===",
"$",
"selected",
")",
"{",
"$",
"radioParams",
"[",
"'checked'",
"]",
"=",
"'checked'",
";",
"}",
"else",
"{",
"$",
"radioParams",
"[",
"'checked'",
"]",
"=",
"null",
";",
"}",
"$",
"radio",
"=",
"Tag",
"::",
"radioField",
"(",
"$",
"radioParams",
")",
";",
"if",
"(",
"$",
"labelOn",
"==",
"'right'",
")",
"{",
"$",
"radio",
".=",
"PHP_EOL",
".",
"$",
"label",
";",
"}",
"else",
"{",
"$",
"radio",
"=",
"$",
"label",
".",
"PHP_EOL",
".",
"$",
"radio",
";",
"}",
"$",
"radio",
"=",
"static",
"::",
"label",
"(",
"[",
"'for'",
"=>",
"$",
"radioId",
"]",
",",
"$",
"radio",
")",
";",
"++",
"$",
"i",
";",
"$",
"html",
"[",
"]",
"=",
"$",
"prefix",
".",
"$",
"radio",
".",
"$",
"suffix",
";",
"}",
"return",
"implode",
"(",
"PHP_EOL",
",",
"$",
"html",
")",
";",
"}",
"return",
"Tag",
"::",
"select",
"(",
"$",
"parameters",
",",
"$",
"options",
")",
";",
"}"
]
| Make a single select widget, if options < 5 it will be expanded into radios by default
Required parameters:
'id', 'options' (in array)
Optional parameters:
'name', 'class', 'value' (selected value) or other html attributes
'expand' (true or false, by default 'auto')
'useEmpty', 'emptyText' (used in select mode)
'prefix', 'suffix' (used to wrap radios in expanded mode)
'labelOn' ('left' or 'right', by default 'right', used to identify radios in expanded mode)
@param array $parameters
@return string | [
"Make",
"a",
"single",
"select",
"widget",
"if",
"options",
"<",
"5",
"it",
"will",
"be",
"expanded",
"into",
"radios",
"by",
"default"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/View/Widget.php#L153-L193 | train |
phwoolcon/phwoolcon | src/Model.php | Model.initialize | public function initialize()
{
$this->initializeConnections();
$this->_table and $this->setSource($this->_table);
$this->keepSnapshots(true);
} | php | public function initialize()
{
$this->initializeConnections();
$this->_table and $this->setSource($this->_table);
$this->keepSnapshots(true);
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"$",
"this",
"->",
"initializeConnections",
"(",
")",
";",
"$",
"this",
"->",
"_table",
"and",
"$",
"this",
"->",
"setSource",
"(",
"$",
"this",
"->",
"_table",
")",
";",
"$",
"this",
"->",
"keepSnapshots",
"(",
"true",
")",
";",
"}"
]
| Runs once, only when the model instance is created at the first time
@throws PhalconDb\Exception | [
"Runs",
"once",
"only",
"when",
"the",
"model",
"instance",
"is",
"created",
"at",
"the",
"first",
"time"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/Model.php#L265-L270 | train |
phwoolcon/phwoolcon | src/Daemon/Service.php | Service.getServiceInfo | protected function getServiceInfo($instance = null)
{
$file = $this->runDir . 'service-info.php';
$info = is_file($file) ? include($file) : [];
return $instance ? fnGet($info, $instance, []) : $info;
} | php | protected function getServiceInfo($instance = null)
{
$file = $this->runDir . 'service-info.php';
$info = is_file($file) ? include($file) : [];
return $instance ? fnGet($info, $instance, []) : $info;
} | [
"protected",
"function",
"getServiceInfo",
"(",
"$",
"instance",
"=",
"null",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"runDir",
".",
"'service-info.php'",
";",
"$",
"info",
"=",
"is_file",
"(",
"$",
"file",
")",
"?",
"include",
"(",
"$",
"file",
")",
":",
"[",
"]",
";",
"return",
"$",
"instance",
"?",
"fnGet",
"(",
"$",
"info",
",",
"$",
"instance",
",",
"[",
"]",
")",
":",
"$",
"info",
";",
"}"
]
| Get service info, including pid, manager pid and port
@param string $instance Specify instance name (e.g. "current", "old").
If not specified, return combined info of all instances.
@return array An array containing service info | [
"Get",
"service",
"info",
"including",
"pid",
"manager",
"pid",
"and",
"port"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/Daemon/Service.php#L149-L154 | train |
phwoolcon/phwoolcon | src/Daemon/Service.php | Service.onStart | public function onStart(SwooleServer $server)
{
@cli_set_process_title($this->name . ': master process/reactor threads; port=' . $this->swoolePort);
// Send SIGTERM to master pid to shutdown service
$this->pid = $server->master_pid;
// Send SIGUSR1 to master pid to reload workers
$this->managerPid = $server->manager_pid;
$this->startCommandHandler();
$this->updateServiceInfo('current', [
'pid' => $this->pid,
'manager_pid' => $this->managerPid,
'port' => $this->swoolePort,
]);
$this->cliOutput('info', "pid = {$this->pid}; port = {$this->swoolePort}");
$this->cliOutput('info', 'Service started.');
} | php | public function onStart(SwooleServer $server)
{
@cli_set_process_title($this->name . ': master process/reactor threads; port=' . $this->swoolePort);
// Send SIGTERM to master pid to shutdown service
$this->pid = $server->master_pid;
// Send SIGUSR1 to master pid to reload workers
$this->managerPid = $server->manager_pid;
$this->startCommandHandler();
$this->updateServiceInfo('current', [
'pid' => $this->pid,
'manager_pid' => $this->managerPid,
'port' => $this->swoolePort,
]);
$this->cliOutput('info', "pid = {$this->pid}; port = {$this->swoolePort}");
$this->cliOutput('info', 'Service started.');
} | [
"public",
"function",
"onStart",
"(",
"SwooleServer",
"$",
"server",
")",
"{",
"@",
"cli_set_process_title",
"(",
"$",
"this",
"->",
"name",
".",
"': master process/reactor threads; port='",
".",
"$",
"this",
"->",
"swoolePort",
")",
";",
"// Send SIGTERM to master pid to shutdown service",
"$",
"this",
"->",
"pid",
"=",
"$",
"server",
"->",
"master_pid",
";",
"// Send SIGUSR1 to master pid to reload workers",
"$",
"this",
"->",
"managerPid",
"=",
"$",
"server",
"->",
"manager_pid",
";",
"$",
"this",
"->",
"startCommandHandler",
"(",
")",
";",
"$",
"this",
"->",
"updateServiceInfo",
"(",
"'current'",
",",
"[",
"'pid'",
"=>",
"$",
"this",
"->",
"pid",
",",
"'manager_pid'",
"=>",
"$",
"this",
"->",
"managerPid",
",",
"'port'",
"=>",
"$",
"this",
"->",
"swoolePort",
",",
"]",
")",
";",
"$",
"this",
"->",
"cliOutput",
"(",
"'info'",
",",
"\"pid = {$this->pid}; port = {$this->swoolePort}\"",
")",
";",
"$",
"this",
"->",
"cliOutput",
"(",
"'info'",
",",
"'Service started.'",
")",
";",
"}"
]
| Callback after service started
@param SwooleServer $server | [
"Callback",
"after",
"service",
"started"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/Daemon/Service.php#L253-L270 | train |
phwoolcon/phwoolcon | src/Daemon/Service.php | Service.prepareServiceAwareComponents | protected function prepareServiceAwareComponents()
{
/* @var Di\Service $service */
foreach (static::$di->getServices() as $name => $service) {
if (!$service->isShared()) {
continue;
}
$component = static::$di->getShared($name);
if ($component instanceof ServiceAwareInterface) {
$this->serviceAwareComponents[$name] = $component;
}
}
// Listen for further components
Events::attach('di:afterServiceResolve', Closure::bind(function (Event $event) {
$data = $event->getData();
$name = $data['name'];
$component = $data['instance'];
if ($component instanceof ServiceAwareInterface) {
$this->serviceAwareComponents[$name] = $component;
}
}, $this));
} | php | protected function prepareServiceAwareComponents()
{
/* @var Di\Service $service */
foreach (static::$di->getServices() as $name => $service) {
if (!$service->isShared()) {
continue;
}
$component = static::$di->getShared($name);
if ($component instanceof ServiceAwareInterface) {
$this->serviceAwareComponents[$name] = $component;
}
}
// Listen for further components
Events::attach('di:afterServiceResolve', Closure::bind(function (Event $event) {
$data = $event->getData();
$name = $data['name'];
$component = $data['instance'];
if ($component instanceof ServiceAwareInterface) {
$this->serviceAwareComponents[$name] = $component;
}
}, $this));
} | [
"protected",
"function",
"prepareServiceAwareComponents",
"(",
")",
"{",
"/* @var Di\\Service $service */",
"foreach",
"(",
"static",
"::",
"$",
"di",
"->",
"getServices",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"service",
")",
"{",
"if",
"(",
"!",
"$",
"service",
"->",
"isShared",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"component",
"=",
"static",
"::",
"$",
"di",
"->",
"getShared",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"component",
"instanceof",
"ServiceAwareInterface",
")",
"{",
"$",
"this",
"->",
"serviceAwareComponents",
"[",
"$",
"name",
"]",
"=",
"$",
"component",
";",
"}",
"}",
"// Listen for further components",
"Events",
"::",
"attach",
"(",
"'di:afterServiceResolve'",
",",
"Closure",
"::",
"bind",
"(",
"function",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"data",
"=",
"$",
"event",
"->",
"getData",
"(",
")",
";",
"$",
"name",
"=",
"$",
"data",
"[",
"'name'",
"]",
";",
"$",
"component",
"=",
"$",
"data",
"[",
"'instance'",
"]",
";",
"if",
"(",
"$",
"component",
"instanceof",
"ServiceAwareInterface",
")",
"{",
"$",
"this",
"->",
"serviceAwareComponents",
"[",
"$",
"name",
"]",
"=",
"$",
"component",
";",
"}",
"}",
",",
"$",
"this",
")",
")",
";",
"}"
]
| Resolve service aware components
Each component will be reset before every request is handled | [
"Resolve",
"service",
"aware",
"components",
"Each",
"component",
"will",
"be",
"reset",
"before",
"every",
"request",
"is",
"handled"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/Daemon/Service.php#L316-L337 | train |
phwoolcon/phwoolcon | src/Daemon/Service.php | Service.sendCommand | public function sendCommand($command, $port = null, &$error = null)
{
$port or $port = $this->choosePort();
$sockFile = $this->runDir . "command-{$port}.sock";
if (!$socket = @stream_socket_client('unix://' . $sockFile, $errNo, $errStr, 5)) {
$error = ['err' => $errNo, 'message' => $errStr];
return "$errStr ($errNo)";
}
$error = false;
fwrite($socket, $command, strlen($command));
$response = fread($socket, 8192);
fclose($socket);
return $response;
} | php | public function sendCommand($command, $port = null, &$error = null)
{
$port or $port = $this->choosePort();
$sockFile = $this->runDir . "command-{$port}.sock";
if (!$socket = @stream_socket_client('unix://' . $sockFile, $errNo, $errStr, 5)) {
$error = ['err' => $errNo, 'message' => $errStr];
return "$errStr ($errNo)";
}
$error = false;
fwrite($socket, $command, strlen($command));
$response = fread($socket, 8192);
fclose($socket);
return $response;
} | [
"public",
"function",
"sendCommand",
"(",
"$",
"command",
",",
"$",
"port",
"=",
"null",
",",
"&",
"$",
"error",
"=",
"null",
")",
"{",
"$",
"port",
"or",
"$",
"port",
"=",
"$",
"this",
"->",
"choosePort",
"(",
")",
";",
"$",
"sockFile",
"=",
"$",
"this",
"->",
"runDir",
".",
"\"command-{$port}.sock\"",
";",
"if",
"(",
"!",
"$",
"socket",
"=",
"@",
"stream_socket_client",
"(",
"'unix://'",
".",
"$",
"sockFile",
",",
"$",
"errNo",
",",
"$",
"errStr",
",",
"5",
")",
")",
"{",
"$",
"error",
"=",
"[",
"'err'",
"=>",
"$",
"errNo",
",",
"'message'",
"=>",
"$",
"errStr",
"]",
";",
"return",
"\"$errStr ($errNo)\"",
";",
"}",
"$",
"error",
"=",
"false",
";",
"fwrite",
"(",
"$",
"socket",
",",
"$",
"command",
",",
"strlen",
"(",
"$",
"command",
")",
")",
";",
"$",
"response",
"=",
"fread",
"(",
"$",
"socket",
",",
"8192",
")",
";",
"fclose",
"(",
"$",
"socket",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Send command to service command handler
@param string $command
@param integer $port
@param $error
@return string | [
"Send",
"command",
"to",
"service",
"command",
"handler"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/Daemon/Service.php#L422-L435 | train |
phwoolcon/phwoolcon | src/Model/MetaData/InCache.php | InCache.read | public function read($key)
{
$this->_cachedData or $this->_cachedData = Cache::get('model-metadata');
return isset($this->_cachedData[$key]) ? $this->_cachedData[$key] : null;
} | php | public function read($key)
{
$this->_cachedData or $this->_cachedData = Cache::get('model-metadata');
return isset($this->_cachedData[$key]) ? $this->_cachedData[$key] : null;
} | [
"public",
"function",
"read",
"(",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"_cachedData",
"or",
"$",
"this",
"->",
"_cachedData",
"=",
"Cache",
"::",
"get",
"(",
"'model-metadata'",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"_cachedData",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"_cachedData",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
]
| Reads meta-data from files
@param string $key
@return mixed | [
"Reads",
"meta",
"-",
"data",
"from",
"files"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/Model/MetaData/InCache.php#L35-L39 | train |
phwoolcon/phwoolcon | src/Model/MetaData/InCache.php | InCache.write | public function write($key, $data)
{
$this->_cachedData[$key] = $data;
Cache::set('model-metadata', $this->_cachedData, Cache::TTL_ONE_MONTH);
} | php | public function write($key, $data)
{
$this->_cachedData[$key] = $data;
Cache::set('model-metadata', $this->_cachedData, Cache::TTL_ONE_MONTH);
} | [
"public",
"function",
"write",
"(",
"$",
"key",
",",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"_cachedData",
"[",
"$",
"key",
"]",
"=",
"$",
"data",
";",
"Cache",
"::",
"set",
"(",
"'model-metadata'",
",",
"$",
"this",
"->",
"_cachedData",
",",
"Cache",
"::",
"TTL_ONE_MONTH",
")",
";",
"}"
]
| Writes the meta-data to files
@param string $key
@param array $data | [
"Writes",
"the",
"meta",
"-",
"data",
"to",
"files"
]
| 67bec88ff6f2552ee1cb9b8ea389c91125697b11 | https://github.com/phwoolcon/phwoolcon/blob/67bec88ff6f2552ee1cb9b8ea389c91125697b11/src/Model/MetaData/InCache.php#L47-L51 | train |
wata727/pahout | src/Tool/DuplicateCaseCondition.php | DuplicateCaseCondition.run | public function run(string $file, Node $node): array
{
$hints = [];
$case_conds = [];
foreach ($node->children as $case) {
$cond = $case->children['cond'];
foreach ($case_conds as $case_cond) {
if ($this->isEqualsWithoutLineno($case_cond, $cond)) {
$hints[] = new Hint(
self::HINT_TYPE,
self::HINT_MESSAGE,
$file,
$case->lineno,
self::HINT_LINK
);
}
}
$case_conds[] = $cond;
}
return $hints;
} | php | public function run(string $file, Node $node): array
{
$hints = [];
$case_conds = [];
foreach ($node->children as $case) {
$cond = $case->children['cond'];
foreach ($case_conds as $case_cond) {
if ($this->isEqualsWithoutLineno($case_cond, $cond)) {
$hints[] = new Hint(
self::HINT_TYPE,
self::HINT_MESSAGE,
$file,
$case->lineno,
self::HINT_LINK
);
}
}
$case_conds[] = $cond;
}
return $hints;
} | [
"public",
"function",
"run",
"(",
"string",
"$",
"file",
",",
"Node",
"$",
"node",
")",
":",
"array",
"{",
"$",
"hints",
"=",
"[",
"]",
";",
"$",
"case_conds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"node",
"->",
"children",
"as",
"$",
"case",
")",
"{",
"$",
"cond",
"=",
"$",
"case",
"->",
"children",
"[",
"'cond'",
"]",
";",
"foreach",
"(",
"$",
"case_conds",
"as",
"$",
"case_cond",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEqualsWithoutLineno",
"(",
"$",
"case_cond",
",",
"$",
"cond",
")",
")",
"{",
"$",
"hints",
"[",
"]",
"=",
"new",
"Hint",
"(",
"self",
"::",
"HINT_TYPE",
",",
"self",
"::",
"HINT_MESSAGE",
",",
"$",
"file",
",",
"$",
"case",
"->",
"lineno",
",",
"self",
"::",
"HINT_LINK",
")",
";",
"}",
"}",
"$",
"case_conds",
"[",
"]",
"=",
"$",
"cond",
";",
"}",
"return",
"$",
"hints",
";",
"}"
]
| Detect case condition in switch statement.
@param string $file File name to be analyzed.
@param Node $node AST node to be analyzed.
@return Hint[] List of hints obtained from results. | [
"Detect",
"case",
"condition",
"in",
"switch",
"statement",
"."
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Tool/DuplicateCaseCondition.php#L67-L89 | train |
wata727/pahout | src/Tool/UnreachableCatch.php | UnreachableCatch.run | public function run(string $file, Node $node): array
{
while (count($node->children) >= 2) {
$catch = array_shift($node->children);
// If the class specification includes `Throwable`, doesn't allow any catch expressions after that.
if ($this->isIncludeThrowableNode($catch)) {
foreach ($node->children as $after_catch) {
if (!$this->isIncludeThrowableNode($after_catch)) {
return [new Hint(
self::HINT_TYPE,
self::HINT_MESSAGE,
$file,
$after_catch->lineno,
self::HINT_LINK
)];
}
}
}
// If the class specification includes `Exception`, doesn't allow catch expressions other than `Throwable` after that.
if ($this->isIncludeExceptionNode($catch)) {
foreach ($node->children as $after_catch) {
if (!$this->isIncludeExceptionNode($after_catch)
&& !$this->isIncludeThrowableNode($after_catch)) {
return [new Hint(
self::HINT_TYPE,
self::HINT_MESSAGE,
$file,
$after_catch->lineno,
self::HINT_LINK
)];
}
}
}
}
return [];
} | php | public function run(string $file, Node $node): array
{
while (count($node->children) >= 2) {
$catch = array_shift($node->children);
// If the class specification includes `Throwable`, doesn't allow any catch expressions after that.
if ($this->isIncludeThrowableNode($catch)) {
foreach ($node->children as $after_catch) {
if (!$this->isIncludeThrowableNode($after_catch)) {
return [new Hint(
self::HINT_TYPE,
self::HINT_MESSAGE,
$file,
$after_catch->lineno,
self::HINT_LINK
)];
}
}
}
// If the class specification includes `Exception`, doesn't allow catch expressions other than `Throwable` after that.
if ($this->isIncludeExceptionNode($catch)) {
foreach ($node->children as $after_catch) {
if (!$this->isIncludeExceptionNode($after_catch)
&& !$this->isIncludeThrowableNode($after_catch)) {
return [new Hint(
self::HINT_TYPE,
self::HINT_MESSAGE,
$file,
$after_catch->lineno,
self::HINT_LINK
)];
}
}
}
}
return [];
} | [
"public",
"function",
"run",
"(",
"string",
"$",
"file",
",",
"Node",
"$",
"node",
")",
":",
"array",
"{",
"while",
"(",
"count",
"(",
"$",
"node",
"->",
"children",
")",
">=",
"2",
")",
"{",
"$",
"catch",
"=",
"array_shift",
"(",
"$",
"node",
"->",
"children",
")",
";",
"// If the class specification includes `Throwable`, doesn't allow any catch expressions after that.",
"if",
"(",
"$",
"this",
"->",
"isIncludeThrowableNode",
"(",
"$",
"catch",
")",
")",
"{",
"foreach",
"(",
"$",
"node",
"->",
"children",
"as",
"$",
"after_catch",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isIncludeThrowableNode",
"(",
"$",
"after_catch",
")",
")",
"{",
"return",
"[",
"new",
"Hint",
"(",
"self",
"::",
"HINT_TYPE",
",",
"self",
"::",
"HINT_MESSAGE",
",",
"$",
"file",
",",
"$",
"after_catch",
"->",
"lineno",
",",
"self",
"::",
"HINT_LINK",
")",
"]",
";",
"}",
"}",
"}",
"// If the class specification includes `Exception`, doesn't allow catch expressions other than `Throwable` after that.",
"if",
"(",
"$",
"this",
"->",
"isIncludeExceptionNode",
"(",
"$",
"catch",
")",
")",
"{",
"foreach",
"(",
"$",
"node",
"->",
"children",
"as",
"$",
"after_catch",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isIncludeExceptionNode",
"(",
"$",
"after_catch",
")",
"&&",
"!",
"$",
"this",
"->",
"isIncludeThrowableNode",
"(",
"$",
"after_catch",
")",
")",
"{",
"return",
"[",
"new",
"Hint",
"(",
"self",
"::",
"HINT_TYPE",
",",
"self",
"::",
"HINT_MESSAGE",
",",
"$",
"file",
",",
"$",
"after_catch",
"->",
"lineno",
",",
"self",
"::",
"HINT_LINK",
")",
"]",
";",
"}",
"}",
"}",
"}",
"return",
"[",
"]",
";",
"}"
]
| Detect a catch expression not reachable by catch expressions of `Exception` or `Throwable`
@param string $file File name to be analyzed.
@param Node $node AST node to be analyzed.
@return Hint[] List of hints obtained from results. | [
"Detect",
"a",
"catch",
"expression",
"not",
"reachable",
"by",
"catch",
"expressions",
"of",
"Exception",
"or",
"Throwable"
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Tool/UnreachableCatch.php#L61-L99 | train |
wata727/pahout | src/Tool/UnreachableCatch.php | UnreachableCatch.isIncludeExceptionNode | private function isIncludeExceptionNode(Node $node): bool
{
foreach ($node->children['class']->children as $class) {
if ($class->children['name'] === 'Exception') {
return true;
}
}
return false;
} | php | private function isIncludeExceptionNode(Node $node): bool
{
foreach ($node->children['class']->children as $class) {
if ($class->children['name'] === 'Exception') {
return true;
}
}
return false;
} | [
"private",
"function",
"isIncludeExceptionNode",
"(",
"Node",
"$",
"node",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"node",
"->",
"children",
"[",
"'class'",
"]",
"->",
"children",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"class",
"->",
"children",
"[",
"'name'",
"]",
"===",
"'Exception'",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Check if the node catches `Exception`
@param Node $node The node to check.
@return boolean Result. | [
"Check",
"if",
"the",
"node",
"catches",
"Exception"
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Tool/UnreachableCatch.php#L107-L116 | train |
wata727/pahout | src/Tool/UnreachableCatch.php | UnreachableCatch.isIncludeThrowableNode | private function isIncludeThrowableNode(Node $node): bool
{
foreach ($node->children['class']->children as $class) {
if ($class->children['name'] === 'Throwable') {
return true;
}
}
return false;
} | php | private function isIncludeThrowableNode(Node $node): bool
{
foreach ($node->children['class']->children as $class) {
if ($class->children['name'] === 'Throwable') {
return true;
}
}
return false;
} | [
"private",
"function",
"isIncludeThrowableNode",
"(",
"Node",
"$",
"node",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"node",
"->",
"children",
"[",
"'class'",
"]",
"->",
"children",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"class",
"->",
"children",
"[",
"'name'",
"]",
"===",
"'Throwable'",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Check if the node catches `Throwable`
@param Node $node The node to check.
@return boolean Result. | [
"Check",
"if",
"the",
"node",
"catches",
"Throwable"
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Tool/UnreachableCatch.php#L124-L133 | train |
wata727/pahout | src/Formatter.php | Formatter.create | public static function create(OutputInterface $output, array $files, array $hints): Base
{
switch (Config::getInstance()->format) {
case 'pretty':
return new Pretty($output, $files, $hints);
case 'json':
return new JSON($output, $files, $hints);
default:
return new Pretty($output, $files, $hints);
}
} | php | public static function create(OutputInterface $output, array $files, array $hints): Base
{
switch (Config::getInstance()->format) {
case 'pretty':
return new Pretty($output, $files, $hints);
case 'json':
return new JSON($output, $files, $hints);
default:
return new Pretty($output, $files, $hints);
}
} | [
"public",
"static",
"function",
"create",
"(",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"files",
",",
"array",
"$",
"hints",
")",
":",
"Base",
"{",
"switch",
"(",
"Config",
"::",
"getInstance",
"(",
")",
"->",
"format",
")",
"{",
"case",
"'pretty'",
":",
"return",
"new",
"Pretty",
"(",
"$",
"output",
",",
"$",
"files",
",",
"$",
"hints",
")",
";",
"case",
"'json'",
":",
"return",
"new",
"JSON",
"(",
"$",
"output",
",",
"$",
"files",
",",
"$",
"hints",
")",
";",
"default",
":",
"return",
"new",
"Pretty",
"(",
"$",
"output",
",",
"$",
"files",
",",
"$",
"hints",
")",
";",
"}",
"}"
]
| Factory method that returns the specified formatter.
@param OutputInterface $output The output interface of symfony console.
@param string[] $files List of analyzed file names.
@param Hint[] $hints Hint list obtained as a result of analysis.
@return Base The specified formatter instance. | [
"Factory",
"method",
"that",
"returns",
"the",
"specified",
"formatter",
"."
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Formatter.php#L26-L36 | train |
wata727/pahout | src/Command/Check.php | Check.configure | protected function configure()
{
$this->setName('check')
->setDescription('A pair programming partner for writing better PHP')
->addArgument('files', InputArgument::IS_ARRAY, 'List of file names or directory names to be analyzed')
->addOption(
'php-version',
null,
InputOption::VALUE_OPTIONAL,
'Target PHP version <comment>[default: runtime version]</>',
null
)
->addOption(
'ignore-tools',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Ignore tool types <comment>[default: Nothing to ignore]</>',
null
)
->addOption(
'ignore-paths',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Ignore files and directories <comment>[default: Nothing to ignore]</>',
null
)
->addOption(
'extensions',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'File extensions to be analyzed <comment>[default: php]</>',
null
)
->addOption(
'vendor',
null,
InputOption::VALUE_OPTIONAL,
'Check vendor directory <comment>[default: false]</>',
null
)
->addOption(
'format',
'f',
InputOption::VALUE_OPTIONAL,
'Output format <comment>[default: "pretty", possibles: "pretty", "json"]</>',
null
)
->addOption(
'config',
'c',
InputOption::VALUE_OPTIONAL,
'Config file path',
'.pahout.yaml'
)
->addOption(
'only-tools',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Check only the given tool types'
);
} | php | protected function configure()
{
$this->setName('check')
->setDescription('A pair programming partner for writing better PHP')
->addArgument('files', InputArgument::IS_ARRAY, 'List of file names or directory names to be analyzed')
->addOption(
'php-version',
null,
InputOption::VALUE_OPTIONAL,
'Target PHP version <comment>[default: runtime version]</>',
null
)
->addOption(
'ignore-tools',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Ignore tool types <comment>[default: Nothing to ignore]</>',
null
)
->addOption(
'ignore-paths',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Ignore files and directories <comment>[default: Nothing to ignore]</>',
null
)
->addOption(
'extensions',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'File extensions to be analyzed <comment>[default: php]</>',
null
)
->addOption(
'vendor',
null,
InputOption::VALUE_OPTIONAL,
'Check vendor directory <comment>[default: false]</>',
null
)
->addOption(
'format',
'f',
InputOption::VALUE_OPTIONAL,
'Output format <comment>[default: "pretty", possibles: "pretty", "json"]</>',
null
)
->addOption(
'config',
'c',
InputOption::VALUE_OPTIONAL,
'Config file path',
'.pahout.yaml'
)
->addOption(
'only-tools',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Check only the given tool types'
);
} | [
"protected",
"function",
"configure",
"(",
")",
"{",
"$",
"this",
"->",
"setName",
"(",
"'check'",
")",
"->",
"setDescription",
"(",
"'A pair programming partner for writing better PHP'",
")",
"->",
"addArgument",
"(",
"'files'",
",",
"InputArgument",
"::",
"IS_ARRAY",
",",
"'List of file names or directory names to be analyzed'",
")",
"->",
"addOption",
"(",
"'php-version'",
",",
"null",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
",",
"'Target PHP version <comment>[default: runtime version]</>'",
",",
"null",
")",
"->",
"addOption",
"(",
"'ignore-tools'",
",",
"null",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
"|",
"InputOption",
"::",
"VALUE_IS_ARRAY",
",",
"'Ignore tool types <comment>[default: Nothing to ignore]</>'",
",",
"null",
")",
"->",
"addOption",
"(",
"'ignore-paths'",
",",
"null",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
"|",
"InputOption",
"::",
"VALUE_IS_ARRAY",
",",
"'Ignore files and directories <comment>[default: Nothing to ignore]</>'",
",",
"null",
")",
"->",
"addOption",
"(",
"'extensions'",
",",
"null",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
"|",
"InputOption",
"::",
"VALUE_IS_ARRAY",
",",
"'File extensions to be analyzed <comment>[default: php]</>'",
",",
"null",
")",
"->",
"addOption",
"(",
"'vendor'",
",",
"null",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
",",
"'Check vendor directory <comment>[default: false]</>'",
",",
"null",
")",
"->",
"addOption",
"(",
"'format'",
",",
"'f'",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
",",
"'Output format <comment>[default: \"pretty\", possibles: \"pretty\", \"json\"]</>'",
",",
"null",
")",
"->",
"addOption",
"(",
"'config'",
",",
"'c'",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
",",
"'Config file path'",
",",
"'.pahout.yaml'",
")",
"->",
"addOption",
"(",
"'only-tools'",
",",
"null",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
"|",
"InputOption",
"::",
"VALUE_IS_ARRAY",
",",
"'Check only the given tool types'",
")",
";",
"}"
]
| Define commands and other options.
Default values are not specified for configuration merging.
@return void
Argument 2 (shortcut) is null but \Pahout\Command\Check::addOption() takes string defined at vendor/symfony/console/Command/Command.php: vendoring library causes this warnings :(
@suppress PhanTypeMismatchArgument | [
"Define",
"commands",
"and",
"other",
"options",
"."
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Command/Check.php#L45-L105 | train |
wata727/pahout | src/Command/Check.php | Check.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
Logger::getInstance($output)->info('Start Pahout command');
Config::load($input->getOptions(), $input->getOption('config'));
Logger::getInstance()->info('Start instruction');
Logger::getInstance()->info('files: '.implode(',', $input->getArgument('files')));
$pahout = new Pahout($input->getArgument('files'));
$pahout->instruct();
Logger::getInstance()->info('End instruction');
Logger::getInstance()->info('Start formatter');
$formatter = Formatter::create($output, $pahout->files, $pahout->hints);
$formatter->print();
Logger::getInstance()->info('End formatter');
Logger::getInstance()->info('End Pahout command');
if (count($pahout->hints) === 0) {
return self::EXIT_CODE_HINT_NOT_FOUND;
} else {
return self::EXIT_CODE_HINT_FOUND;
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
Logger::getInstance($output)->info('Start Pahout command');
Config::load($input->getOptions(), $input->getOption('config'));
Logger::getInstance()->info('Start instruction');
Logger::getInstance()->info('files: '.implode(',', $input->getArgument('files')));
$pahout = new Pahout($input->getArgument('files'));
$pahout->instruct();
Logger::getInstance()->info('End instruction');
Logger::getInstance()->info('Start formatter');
$formatter = Formatter::create($output, $pahout->files, $pahout->hints);
$formatter->print();
Logger::getInstance()->info('End formatter');
Logger::getInstance()->info('End Pahout command');
if (count($pahout->hints) === 0) {
return self::EXIT_CODE_HINT_NOT_FOUND;
} else {
return self::EXIT_CODE_HINT_FOUND;
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"Logger",
"::",
"getInstance",
"(",
"$",
"output",
")",
"->",
"info",
"(",
"'Start Pahout command'",
")",
";",
"Config",
"::",
"load",
"(",
"$",
"input",
"->",
"getOptions",
"(",
")",
",",
"$",
"input",
"->",
"getOption",
"(",
"'config'",
")",
")",
";",
"Logger",
"::",
"getInstance",
"(",
")",
"->",
"info",
"(",
"'Start instruction'",
")",
";",
"Logger",
"::",
"getInstance",
"(",
")",
"->",
"info",
"(",
"'files: '",
".",
"implode",
"(",
"','",
",",
"$",
"input",
"->",
"getArgument",
"(",
"'files'",
")",
")",
")",
";",
"$",
"pahout",
"=",
"new",
"Pahout",
"(",
"$",
"input",
"->",
"getArgument",
"(",
"'files'",
")",
")",
";",
"$",
"pahout",
"->",
"instruct",
"(",
")",
";",
"Logger",
"::",
"getInstance",
"(",
")",
"->",
"info",
"(",
"'End instruction'",
")",
";",
"Logger",
"::",
"getInstance",
"(",
")",
"->",
"info",
"(",
"'Start formatter'",
")",
";",
"$",
"formatter",
"=",
"Formatter",
"::",
"create",
"(",
"$",
"output",
",",
"$",
"pahout",
"->",
"files",
",",
"$",
"pahout",
"->",
"hints",
")",
";",
"$",
"formatter",
"->",
"print",
"(",
")",
";",
"Logger",
"::",
"getInstance",
"(",
")",
"->",
"info",
"(",
"'End formatter'",
")",
";",
"Logger",
"::",
"getInstance",
"(",
")",
"->",
"info",
"(",
"'End Pahout command'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"pahout",
"->",
"hints",
")",
"===",
"0",
")",
"{",
"return",
"self",
"::",
"EXIT_CODE_HINT_NOT_FOUND",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"EXIT_CODE_HINT_FOUND",
";",
"}",
"}"
]
| CLI execution entrypoint
It is executed in the following steps.
1. Setup config.
2. Parse PHP scripts and traverse AST nodes.
3. Print hints.
@param InputInterface $input The input interface of symfony console.
@param OutputInterface $output The output interface of symfony console.
@return integer|null | [
"CLI",
"execution",
"entrypoint"
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Command/Check.php#L120-L144 | train |
wata727/pahout | src/Annotation/Rebel.php | Rebel.isAffected | public function isAffected(Hint $hint): bool
{
return $hint->filename === $this->filename
&& $hint->type === $this->body
&& ($this->start_line - 1) <= $hint->lineno
&& $hint->lineno <= ($this->end_line + 1);
} | php | public function isAffected(Hint $hint): bool
{
return $hint->filename === $this->filename
&& $hint->type === $this->body
&& ($this->start_line - 1) <= $hint->lineno
&& $hint->lineno <= ($this->end_line + 1);
} | [
"public",
"function",
"isAffected",
"(",
"Hint",
"$",
"hint",
")",
":",
"bool",
"{",
"return",
"$",
"hint",
"->",
"filename",
"===",
"$",
"this",
"->",
"filename",
"&&",
"$",
"hint",
"->",
"type",
"===",
"$",
"this",
"->",
"body",
"&&",
"(",
"$",
"this",
"->",
"start_line",
"-",
"1",
")",
"<=",
"$",
"hint",
"->",
"lineno",
"&&",
"$",
"hint",
"->",
"lineno",
"<=",
"(",
"$",
"this",
"->",
"end_line",
"+",
"1",
")",
";",
"}"
]
| Determine whether hint is target of annotation
It checks file name, hint type, and the range of comments.
@param Hint $hint An instance of Hint.
@return boolean If the hint is affected by this annotion, true, otherwise false. | [
"Determine",
"whether",
"hint",
"is",
"target",
"of",
"annotation"
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Annotation/Rebel.php#L48-L54 | train |
appaydin/pd-user | Model/User.php | User.getRoles | public function getRoles(): ?array
{
$roles = $this->roles;
$groupRoles = [[]];
foreach ($this->getGroups() as $group) {
$groupRoles[] = $group->getRoles();
}
$groupRoles = array_merge(...$groupRoles);
return array_unique(array_merge($roles, $groupRoles));
} | php | public function getRoles(): ?array
{
$roles = $this->roles;
$groupRoles = [[]];
foreach ($this->getGroups() as $group) {
$groupRoles[] = $group->getRoles();
}
$groupRoles = array_merge(...$groupRoles);
return array_unique(array_merge($roles, $groupRoles));
} | [
"public",
"function",
"getRoles",
"(",
")",
":",
"?",
"array",
"{",
"$",
"roles",
"=",
"$",
"this",
"->",
"roles",
";",
"$",
"groupRoles",
"=",
"[",
"[",
"]",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getGroups",
"(",
")",
"as",
"$",
"group",
")",
"{",
"$",
"groupRoles",
"[",
"]",
"=",
"$",
"group",
"->",
"getRoles",
"(",
")",
";",
"}",
"$",
"groupRoles",
"=",
"array_merge",
"(",
"...",
"$",
"groupRoles",
")",
";",
"return",
"array_unique",
"(",
"array_merge",
"(",
"$",
"roles",
",",
"$",
"groupRoles",
")",
")",
";",
"}"
]
| Group combined Roles.
@return array | [
"Group",
"combined",
"Roles",
"."
]
| b233534d93a12942b6b4ddc646a0732a3dff65a0 | https://github.com/appaydin/pd-user/blob/b233534d93a12942b6b4ddc646a0732a3dff65a0/Model/User.php#L354-L365 | train |
GrahamCampbell/Guzzle-Factory | src/GuzzleFactory.php | GuzzleFactory.make | public static function make(array $options = [], int $backoff = null, array $codes = null)
{
$config = array_merge(['connect_timeout' => self::CONNECT_TIMEOUT, 'timeout' => self::TIMEOUT], $options);
$config['handler'] = self::handler($backoff, $codes, $options['handler'] ?? null);
return new Client($config);
} | php | public static function make(array $options = [], int $backoff = null, array $codes = null)
{
$config = array_merge(['connect_timeout' => self::CONNECT_TIMEOUT, 'timeout' => self::TIMEOUT], $options);
$config['handler'] = self::handler($backoff, $codes, $options['handler'] ?? null);
return new Client($config);
} | [
"public",
"static",
"function",
"make",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
",",
"int",
"$",
"backoff",
"=",
"null",
",",
"array",
"$",
"codes",
"=",
"null",
")",
"{",
"$",
"config",
"=",
"array_merge",
"(",
"[",
"'connect_timeout'",
"=>",
"self",
"::",
"CONNECT_TIMEOUT",
",",
"'timeout'",
"=>",
"self",
"::",
"TIMEOUT",
"]",
",",
"$",
"options",
")",
";",
"$",
"config",
"[",
"'handler'",
"]",
"=",
"self",
"::",
"handler",
"(",
"$",
"backoff",
",",
"$",
"codes",
",",
"$",
"options",
"[",
"'handler'",
"]",
"??",
"null",
")",
";",
"return",
"new",
"Client",
"(",
"$",
"config",
")",
";",
"}"
]
| Create a new guzzle client.
@param array $options
@param int|null $backoff
@param int[]|null $codes
@return \GuzzleHttp\Client | [
"Create",
"a",
"new",
"guzzle",
"client",
"."
]
| d6494ec2d5cf1068e13489dac60336ba031766b1 | https://github.com/GrahamCampbell/Guzzle-Factory/blob/d6494ec2d5cf1068e13489dac60336ba031766b1/src/GuzzleFactory.php#L68-L74 | train |
GrahamCampbell/Guzzle-Factory | src/GuzzleFactory.php | GuzzleFactory.handler | public static function handler(int $backoff = null, array $codes = null, HandlerStack $stack = null)
{
$stack = $stack ?: HandlerStack::create();
$stack->push(Middleware::retry(function ($retries, RequestInterface $request, ResponseInterface $response = null, TransferException $exception = null) use ($codes) {
return $retries < 3 && ($exception instanceof ConnectException || ($response && ($response->getStatusCode() >= 500 || in_array($response->getStatusCode(), $codes === null ? self::CODES : $codes, true))));
}, function ($retries) use ($backoff) {
return (int) pow(2, $retries) * ($backoff === null ? self::BACKOFF : $backoff);
}));
return $stack;
} | php | public static function handler(int $backoff = null, array $codes = null, HandlerStack $stack = null)
{
$stack = $stack ?: HandlerStack::create();
$stack->push(Middleware::retry(function ($retries, RequestInterface $request, ResponseInterface $response = null, TransferException $exception = null) use ($codes) {
return $retries < 3 && ($exception instanceof ConnectException || ($response && ($response->getStatusCode() >= 500 || in_array($response->getStatusCode(), $codes === null ? self::CODES : $codes, true))));
}, function ($retries) use ($backoff) {
return (int) pow(2, $retries) * ($backoff === null ? self::BACKOFF : $backoff);
}));
return $stack;
} | [
"public",
"static",
"function",
"handler",
"(",
"int",
"$",
"backoff",
"=",
"null",
",",
"array",
"$",
"codes",
"=",
"null",
",",
"HandlerStack",
"$",
"stack",
"=",
"null",
")",
"{",
"$",
"stack",
"=",
"$",
"stack",
"?",
":",
"HandlerStack",
"::",
"create",
"(",
")",
";",
"$",
"stack",
"->",
"push",
"(",
"Middleware",
"::",
"retry",
"(",
"function",
"(",
"$",
"retries",
",",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
"=",
"null",
",",
"TransferException",
"$",
"exception",
"=",
"null",
")",
"use",
"(",
"$",
"codes",
")",
"{",
"return",
"$",
"retries",
"<",
"3",
"&&",
"(",
"$",
"exception",
"instanceof",
"ConnectException",
"||",
"(",
"$",
"response",
"&&",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
">=",
"500",
"||",
"in_array",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"codes",
"===",
"null",
"?",
"self",
"::",
"CODES",
":",
"$",
"codes",
",",
"true",
")",
")",
")",
")",
";",
"}",
",",
"function",
"(",
"$",
"retries",
")",
"use",
"(",
"$",
"backoff",
")",
"{",
"return",
"(",
"int",
")",
"pow",
"(",
"2",
",",
"$",
"retries",
")",
"*",
"(",
"$",
"backoff",
"===",
"null",
"?",
"self",
"::",
"BACKOFF",
":",
"$",
"backoff",
")",
";",
"}",
")",
")",
";",
"return",
"$",
"stack",
";",
"}"
]
| Create a new guzzle handler stack.
@param int|null $backoff
@param int[]|null $codes
@param \GuzzleHttp\HandlerStack|null $stack
@return \GuzzleHttp\HandlerStack | [
"Create",
"a",
"new",
"guzzle",
"handler",
"stack",
"."
]
| d6494ec2d5cf1068e13489dac60336ba031766b1 | https://github.com/GrahamCampbell/Guzzle-Factory/blob/d6494ec2d5cf1068e13489dac60336ba031766b1/src/GuzzleFactory.php#L85-L96 | train |
wata727/pahout | src/Tool/MultipleCatch.php | MultipleCatch.run | public function run(string $file, Node $node): array
{
$hints = [];
$catch_block_list = [];
foreach ($node->children as $catch) {
$klasses = $catch->children['class'];
$stmts = $catch->children['stmts'];
foreach ($catch_block_list as $catch_block) {
$catch_klasses = $catch_block->children['class'];
$catch_stmts = $catch_block->children['stmts'];
if ($this->isEqualsWithoutLineno($catch_stmts, $stmts)) {
$hints[] = new Hint(
self::HINT_TYPE,
$this->messages(array_merge($catch_klasses->children, $klasses->children)),
$file,
$catch_stmts->lineno,
self::HINT_LINK
);
}
}
$catch_block_list[] = $catch;
}
return $hints;
} | php | public function run(string $file, Node $node): array
{
$hints = [];
$catch_block_list = [];
foreach ($node->children as $catch) {
$klasses = $catch->children['class'];
$stmts = $catch->children['stmts'];
foreach ($catch_block_list as $catch_block) {
$catch_klasses = $catch_block->children['class'];
$catch_stmts = $catch_block->children['stmts'];
if ($this->isEqualsWithoutLineno($catch_stmts, $stmts)) {
$hints[] = new Hint(
self::HINT_TYPE,
$this->messages(array_merge($catch_klasses->children, $klasses->children)),
$file,
$catch_stmts->lineno,
self::HINT_LINK
);
}
}
$catch_block_list[] = $catch;
}
return $hints;
} | [
"public",
"function",
"run",
"(",
"string",
"$",
"file",
",",
"Node",
"$",
"node",
")",
":",
"array",
"{",
"$",
"hints",
"=",
"[",
"]",
";",
"$",
"catch_block_list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"node",
"->",
"children",
"as",
"$",
"catch",
")",
"{",
"$",
"klasses",
"=",
"$",
"catch",
"->",
"children",
"[",
"'class'",
"]",
";",
"$",
"stmts",
"=",
"$",
"catch",
"->",
"children",
"[",
"'stmts'",
"]",
";",
"foreach",
"(",
"$",
"catch_block_list",
"as",
"$",
"catch_block",
")",
"{",
"$",
"catch_klasses",
"=",
"$",
"catch_block",
"->",
"children",
"[",
"'class'",
"]",
";",
"$",
"catch_stmts",
"=",
"$",
"catch_block",
"->",
"children",
"[",
"'stmts'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"isEqualsWithoutLineno",
"(",
"$",
"catch_stmts",
",",
"$",
"stmts",
")",
")",
"{",
"$",
"hints",
"[",
"]",
"=",
"new",
"Hint",
"(",
"self",
"::",
"HINT_TYPE",
",",
"$",
"this",
"->",
"messages",
"(",
"array_merge",
"(",
"$",
"catch_klasses",
"->",
"children",
",",
"$",
"klasses",
"->",
"children",
")",
")",
",",
"$",
"file",
",",
"$",
"catch_stmts",
"->",
"lineno",
",",
"self",
"::",
"HINT_LINK",
")",
";",
"}",
"}",
"$",
"catch_block_list",
"[",
"]",
"=",
"$",
"catch",
";",
"}",
"return",
"$",
"hints",
";",
"}"
]
| Detect catch blocks of the same implementation.
@param string $file File name to be analyzed.
@param Node $node AST node to be analyzed.
@return Hint[] List of hints obtained from results. | [
"Detect",
"catch",
"blocks",
"of",
"the",
"same",
"implementation",
"."
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Tool/MultipleCatch.php#L63-L88 | train |
wata727/pahout | src/Tool/MultipleCatch.php | MultipleCatch.messages | private function messages(array $exceptions)
{
$names = array_map(function ($exception) {
return $exception->children['name'];
}, $exceptions);
if (count($names) > 1) {
$last = array_slice($names, -1);
$message = implode("`, `", array_slice($names, 0, count($names) - 1));
$message = "`$message` and `$last[0]`";
} else {
$message = "`$names[0]`";
}
return sprintf(self::HINT_MESSAGE, $message);
} | php | private function messages(array $exceptions)
{
$names = array_map(function ($exception) {
return $exception->children['name'];
}, $exceptions);
if (count($names) > 1) {
$last = array_slice($names, -1);
$message = implode("`, `", array_slice($names, 0, count($names) - 1));
$message = "`$message` and `$last[0]`";
} else {
$message = "`$names[0]`";
}
return sprintf(self::HINT_MESSAGE, $message);
} | [
"private",
"function",
"messages",
"(",
"array",
"$",
"exceptions",
")",
"{",
"$",
"names",
"=",
"array_map",
"(",
"function",
"(",
"$",
"exception",
")",
"{",
"return",
"$",
"exception",
"->",
"children",
"[",
"'name'",
"]",
";",
"}",
",",
"$",
"exceptions",
")",
";",
"if",
"(",
"count",
"(",
"$",
"names",
")",
">",
"1",
")",
"{",
"$",
"last",
"=",
"array_slice",
"(",
"$",
"names",
",",
"-",
"1",
")",
";",
"$",
"message",
"=",
"implode",
"(",
"\"`, `\"",
",",
"array_slice",
"(",
"$",
"names",
",",
"0",
",",
"count",
"(",
"$",
"names",
")",
"-",
"1",
")",
")",
";",
"$",
"message",
"=",
"\"`$message` and `$last[0]`\"",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"\"`$names[0]`\"",
";",
"}",
"return",
"sprintf",
"(",
"self",
"::",
"HINT_MESSAGE",
",",
"$",
"message",
")",
";",
"}"
]
| Build a hint message from exceptions.
@param Node[] $exceptions List of exceptions to specify.
@return string Hint message. | [
"Build",
"a",
"hint",
"message",
"from",
"exceptions",
"."
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Tool/MultipleCatch.php#L96-L111 | train |
wata727/pahout | src/ToolBox.php | ToolBox.create | public static function create(): array
{
$tools = [];
$config = Config::getInstance();
foreach (self::VALID_TOOLS as $tool) {
// SyntaxError is a special tool. Pahout directly generates Hint without checking AST.
if ($tool !== 'SyntaxError') {
$klass = "Pahout\\Tool\\".$tool;
$tools[] = new $klass();
}
}
return array_filter($tools, function ($tool) use ($config) {
// Activate only tools that are not included in ignore_tools, and whose PHP version is applicable.
return !in_array($tool::HINT_TYPE, $config->ignore_tools)
&& version_compare($config->php_version, $tool::PHP_VERSION, '>=');
});
} | php | public static function create(): array
{
$tools = [];
$config = Config::getInstance();
foreach (self::VALID_TOOLS as $tool) {
// SyntaxError is a special tool. Pahout directly generates Hint without checking AST.
if ($tool !== 'SyntaxError') {
$klass = "Pahout\\Tool\\".$tool;
$tools[] = new $klass();
}
}
return array_filter($tools, function ($tool) use ($config) {
// Activate only tools that are not included in ignore_tools, and whose PHP version is applicable.
return !in_array($tool::HINT_TYPE, $config->ignore_tools)
&& version_compare($config->php_version, $tool::PHP_VERSION, '>=');
});
} | [
"public",
"static",
"function",
"create",
"(",
")",
":",
"array",
"{",
"$",
"tools",
"=",
"[",
"]",
";",
"$",
"config",
"=",
"Config",
"::",
"getInstance",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"VALID_TOOLS",
"as",
"$",
"tool",
")",
"{",
"// SyntaxError is a special tool. Pahout directly generates Hint without checking AST.",
"if",
"(",
"$",
"tool",
"!==",
"'SyntaxError'",
")",
"{",
"$",
"klass",
"=",
"\"Pahout\\\\Tool\\\\\"",
".",
"$",
"tool",
";",
"$",
"tools",
"[",
"]",
"=",
"new",
"$",
"klass",
"(",
")",
";",
"}",
"}",
"return",
"array_filter",
"(",
"$",
"tools",
",",
"function",
"(",
"$",
"tool",
")",
"use",
"(",
"$",
"config",
")",
"{",
"// Activate only tools that are not included in ignore_tools, and whose PHP version is applicable.",
"return",
"!",
"in_array",
"(",
"$",
"tool",
"::",
"HINT_TYPE",
",",
"$",
"config",
"->",
"ignore_tools",
")",
"&&",
"version_compare",
"(",
"$",
"config",
"->",
"php_version",
",",
"$",
"tool",
"::",
"PHP_VERSION",
",",
"'>='",
")",
";",
"}",
")",
";",
"}"
]
| Factory method that returns list of tool instances matching PHP version.
@return Base[] List of tool instances. | [
"Factory",
"method",
"that",
"returns",
"list",
"of",
"tool",
"instances",
"matching",
"PHP",
"version",
"."
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/ToolBox.php#L40-L57 | train |
wata727/pahout | src/Loader.php | Loader.dig | public static function dig(array $files, Config $config): array
{
$list = [];
$pattern = implode("|", array_map("preg_quote", $config->extensions));
foreach ($files as $file) {
Logger::getInstance()->info('Load: '.$file);
// If a directory name received, it digs recursively under the this directory.
if (is_dir($file)) {
Logger::getInstance()->debug($file.' is directory. Recursively search the file list.');
$iterator = new \RegexIterator(
new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($file)),
"{^.+\.$pattern$}i"
);
foreach ($iterator as $file_obj) {
Logger::getInstance()->debug('Add: '.$file_obj->getPathname());
$list[] = $file_obj->getPathname();
}
// If a file name received, it adds this file to list.
} elseif (is_file($file)) {
Logger::getInstance()->debug($file.' is file. Add it to files.');
$list[] = $file;
// The vendor directory is ignored by default,
// so do not throw an exception if the vendor directory does not exist.
} elseif ($file === 'vendor') {
Logger::getInstance()->debug('vendor directory is not found.');
// If the received name is neither a file nor a directory, it throws an exception.
} else {
throw new InvalidFilePathException('`'.$file.'` is neither a file nor a directory.');
}
}
return $list;
} | php | public static function dig(array $files, Config $config): array
{
$list = [];
$pattern = implode("|", array_map("preg_quote", $config->extensions));
foreach ($files as $file) {
Logger::getInstance()->info('Load: '.$file);
// If a directory name received, it digs recursively under the this directory.
if (is_dir($file)) {
Logger::getInstance()->debug($file.' is directory. Recursively search the file list.');
$iterator = new \RegexIterator(
new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($file)),
"{^.+\.$pattern$}i"
);
foreach ($iterator as $file_obj) {
Logger::getInstance()->debug('Add: '.$file_obj->getPathname());
$list[] = $file_obj->getPathname();
}
// If a file name received, it adds this file to list.
} elseif (is_file($file)) {
Logger::getInstance()->debug($file.' is file. Add it to files.');
$list[] = $file;
// The vendor directory is ignored by default,
// so do not throw an exception if the vendor directory does not exist.
} elseif ($file === 'vendor') {
Logger::getInstance()->debug('vendor directory is not found.');
// If the received name is neither a file nor a directory, it throws an exception.
} else {
throw new InvalidFilePathException('`'.$file.'` is neither a file nor a directory.');
}
}
return $list;
} | [
"public",
"static",
"function",
"dig",
"(",
"array",
"$",
"files",
",",
"Config",
"$",
"config",
")",
":",
"array",
"{",
"$",
"list",
"=",
"[",
"]",
";",
"$",
"pattern",
"=",
"implode",
"(",
"\"|\"",
",",
"array_map",
"(",
"\"preg_quote\"",
",",
"$",
"config",
"->",
"extensions",
")",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"Logger",
"::",
"getInstance",
"(",
")",
"->",
"info",
"(",
"'Load: '",
".",
"$",
"file",
")",
";",
"// If a directory name received, it digs recursively under the this directory.",
"if",
"(",
"is_dir",
"(",
"$",
"file",
")",
")",
"{",
"Logger",
"::",
"getInstance",
"(",
")",
"->",
"debug",
"(",
"$",
"file",
".",
"' is directory. Recursively search the file list.'",
")",
";",
"$",
"iterator",
"=",
"new",
"\\",
"RegexIterator",
"(",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"file",
")",
")",
",",
"\"{^.+\\.$pattern$}i\"",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"file_obj",
")",
"{",
"Logger",
"::",
"getInstance",
"(",
")",
"->",
"debug",
"(",
"'Add: '",
".",
"$",
"file_obj",
"->",
"getPathname",
"(",
")",
")",
";",
"$",
"list",
"[",
"]",
"=",
"$",
"file_obj",
"->",
"getPathname",
"(",
")",
";",
"}",
"// If a file name received, it adds this file to list.",
"}",
"elseif",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"Logger",
"::",
"getInstance",
"(",
")",
"->",
"debug",
"(",
"$",
"file",
".",
"' is file. Add it to files.'",
")",
";",
"$",
"list",
"[",
"]",
"=",
"$",
"file",
";",
"// The vendor directory is ignored by default,",
"// so do not throw an exception if the vendor directory does not exist.",
"}",
"elseif",
"(",
"$",
"file",
"===",
"'vendor'",
")",
"{",
"Logger",
"::",
"getInstance",
"(",
")",
"->",
"debug",
"(",
"'vendor directory is not found.'",
")",
";",
"// If the received name is neither a file nor a directory, it throws an exception.",
"}",
"else",
"{",
"throw",
"new",
"InvalidFilePathException",
"(",
"'`'",
".",
"$",
"file",
".",
"'` is neither a file nor a directory.'",
")",
";",
"}",
"}",
"return",
"$",
"list",
";",
"}"
]
| Dig file paths from files or directories.
If a directory name received, it digs recursively under the directory.
@param string[] $files List of file names and directory names to load.
@param Config $config Application config.
@throws InvalidFilePathException Exception when the specified file or directory does not exist.
@return string[] List of readable file paths. | [
"Dig",
"file",
"paths",
"from",
"files",
"or",
"directories",
"."
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Loader.php#L23-L58 | train |
wata727/pahout | src/Tool/Howdah.php | Howdah.isEqualsWithoutLineno | public function isEqualsWithoutLineno($a, $b): Bool
{
if (is_array($a)) {
if (!is_array($b)) {
return false;
}
foreach ($a as $key => $value) {
if (!(array_key_exists($key, $b) && $this->isEqualsWithoutLineno($value, $b[$key]))) {
return false;
}
}
} elseif ($a instanceof Node) {
if (!$b instanceof Node) {
return false;
}
if ($a->kind !== $b->kind || $a->flags !== $b->flags) {
return false;
}
return $this->isEqualsWithoutLineno($a->children, $b->children);
} elseif ($a !== $b) {
return false;
}
return true;
} | php | public function isEqualsWithoutLineno($a, $b): Bool
{
if (is_array($a)) {
if (!is_array($b)) {
return false;
}
foreach ($a as $key => $value) {
if (!(array_key_exists($key, $b) && $this->isEqualsWithoutLineno($value, $b[$key]))) {
return false;
}
}
} elseif ($a instanceof Node) {
if (!$b instanceof Node) {
return false;
}
if ($a->kind !== $b->kind || $a->flags !== $b->flags) {
return false;
}
return $this->isEqualsWithoutLineno($a->children, $b->children);
} elseif ($a !== $b) {
return false;
}
return true;
} | [
"public",
"function",
"isEqualsWithoutLineno",
"(",
"$",
"a",
",",
"$",
"b",
")",
":",
"Bool",
"{",
"if",
"(",
"is_array",
"(",
"$",
"a",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"b",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"a",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"b",
")",
"&&",
"$",
"this",
"->",
"isEqualsWithoutLineno",
"(",
"$",
"value",
",",
"$",
"b",
"[",
"$",
"key",
"]",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"a",
"instanceof",
"Node",
")",
"{",
"if",
"(",
"!",
"$",
"b",
"instanceof",
"Node",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"a",
"->",
"kind",
"!==",
"$",
"b",
"->",
"kind",
"||",
"$",
"a",
"->",
"flags",
"!==",
"$",
"b",
"->",
"flags",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"isEqualsWithoutLineno",
"(",
"$",
"a",
"->",
"children",
",",
"$",
"b",
"->",
"children",
")",
";",
"}",
"elseif",
"(",
"$",
"a",
"!==",
"$",
"b",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Verify that it is the same except for line number of Node.
@param mixed $a Object to compare.
@param mixed $b Object to compare.
@return boolean Result. | [
"Verify",
"that",
"it",
"is",
"the",
"same",
"except",
"for",
"line",
"number",
"of",
"Node",
"."
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Tool/Howdah.php#L16-L40 | train |
wata727/pahout | src/Tool/Howdah.php | Howdah.isFunctionCall | public function isFunctionCall($node, string $function): Bool
{
if ($node instanceof Node && $node->kind === \ast\AST_CALL) {
$expr = $node->children['expr'];
if ($expr->kind === \ast\AST_NAME && $expr->children['name'] === $function) {
return true;
}
}
return false;
} | php | public function isFunctionCall($node, string $function): Bool
{
if ($node instanceof Node && $node->kind === \ast\AST_CALL) {
$expr = $node->children['expr'];
if ($expr->kind === \ast\AST_NAME && $expr->children['name'] === $function) {
return true;
}
}
return false;
} | [
"public",
"function",
"isFunctionCall",
"(",
"$",
"node",
",",
"string",
"$",
"function",
")",
":",
"Bool",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"Node",
"&&",
"$",
"node",
"->",
"kind",
"===",
"\\",
"ast",
"\\",
"AST_CALL",
")",
"{",
"$",
"expr",
"=",
"$",
"node",
"->",
"children",
"[",
"'expr'",
"]",
";",
"if",
"(",
"$",
"expr",
"->",
"kind",
"===",
"\\",
"ast",
"\\",
"AST_NAME",
"&&",
"$",
"expr",
"->",
"children",
"[",
"'name'",
"]",
"===",
"$",
"function",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Verify that node is AST_CALL of the specified function name.
@param mixed $node Node or others.
@param string $function A function name.
@return boolean Result. | [
"Verify",
"that",
"node",
"is",
"AST_CALL",
"of",
"the",
"specified",
"function",
"name",
"."
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Tool/Howdah.php#L49-L60 | train |
wata727/pahout | src/Logger.php | Logger.getInstance | public static function getInstance(OutputInterface $output = null): ConsoleLogger
{
if (!isset(self::$logger)) {
self::$logger = new ConsoleLogger($output);
}
return self::$logger;
} | php | public static function getInstance(OutputInterface $output = null): ConsoleLogger
{
if (!isset(self::$logger)) {
self::$logger = new ConsoleLogger($output);
}
return self::$logger;
} | [
"public",
"static",
"function",
"getInstance",
"(",
"OutputInterface",
"$",
"output",
"=",
"null",
")",
":",
"ConsoleLogger",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"logger",
")",
")",
"{",
"self",
"::",
"$",
"logger",
"=",
"new",
"ConsoleLogger",
"(",
"$",
"output",
")",
";",
"}",
"return",
"self",
"::",
"$",
"logger",
";",
"}"
]
| Generate or provide the single logger instance.
@param OutputInterface|null $output The output interface of symfony console. Do not be null for the first time.
@return ConsoleLogger the logger instance. | [
"Generate",
"or",
"provide",
"the",
"single",
"logger",
"instance",
"."
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Logger.php#L24-L30 | train |
wata727/pahout | src/Annotation.php | Annotation.create | public static function create(string $filename, string $source): array
{
$annotations = [];
$tokens = token_get_all($source);
$comments = array_filter($tokens, function ($token) {
return in_array($token[0], [T_COMMENT, T_DOC_COMMENT], true);
});
foreach ($comments as $comment) {
$rebel = Rebel::create($comment[1], $comment[2], $filename);
if ($rebel) {
$annotations[] = $rebel;
}
}
return $annotations;
} | php | public static function create(string $filename, string $source): array
{
$annotations = [];
$tokens = token_get_all($source);
$comments = array_filter($tokens, function ($token) {
return in_array($token[0], [T_COMMENT, T_DOC_COMMENT], true);
});
foreach ($comments as $comment) {
$rebel = Rebel::create($comment[1], $comment[2], $filename);
if ($rebel) {
$annotations[] = $rebel;
}
}
return $annotations;
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"filename",
",",
"string",
"$",
"source",
")",
":",
"array",
"{",
"$",
"annotations",
"=",
"[",
"]",
";",
"$",
"tokens",
"=",
"token_get_all",
"(",
"$",
"source",
")",
";",
"$",
"comments",
"=",
"array_filter",
"(",
"$",
"tokens",
",",
"function",
"(",
"$",
"token",
")",
"{",
"return",
"in_array",
"(",
"$",
"token",
"[",
"0",
"]",
",",
"[",
"T_COMMENT",
",",
"T_DOC_COMMENT",
"]",
",",
"true",
")",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"comments",
"as",
"$",
"comment",
")",
"{",
"$",
"rebel",
"=",
"Rebel",
"::",
"create",
"(",
"$",
"comment",
"[",
"1",
"]",
",",
"$",
"comment",
"[",
"2",
"]",
",",
"$",
"filename",
")",
";",
"if",
"(",
"$",
"rebel",
")",
"{",
"$",
"annotations",
"[",
"]",
"=",
"$",
"rebel",
";",
"}",
"}",
"return",
"$",
"annotations",
";",
"}"
]
| Annotation facotry method
Get tokens from the source code by `token_get_all`
and return an array of the obtained annotation instance.
@param string $filename A file name.
@param string $source A body of file.
@return Base[] List of annotation instance. | [
"Annotation",
"facotry",
"method"
]
| da1f41a2c560e912ed9ea1be0d7b5417275d29f1 | https://github.com/wata727/pahout/blob/da1f41a2c560e912ed9ea1be0d7b5417275d29f1/src/Annotation.php#L26-L43 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.