repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
ongr-io/ElasticsearchBundle | Service/ExportService.php | ExportService.getFileCount | protected function getFileCount($resultsCount, $maxLinesInFile, $fileCounter)
{
$leftToInsert = $resultsCount - ($fileCounter * $maxLinesInFile);
if ($leftToInsert <= $maxLinesInFile) {
$count = $leftToInsert;
} else {
$count = $maxLinesInFile;
}
return $count;
} | php | protected function getFileCount($resultsCount, $maxLinesInFile, $fileCounter)
{
$leftToInsert = $resultsCount - ($fileCounter * $maxLinesInFile);
if ($leftToInsert <= $maxLinesInFile) {
$count = $leftToInsert;
} else {
$count = $maxLinesInFile;
}
return $count;
} | [
"protected",
"function",
"getFileCount",
"(",
"$",
"resultsCount",
",",
"$",
"maxLinesInFile",
",",
"$",
"fileCounter",
")",
"{",
"$",
"leftToInsert",
"=",
"$",
"resultsCount",
"-",
"(",
"$",
"fileCounter",
"*",
"$",
"maxLinesInFile",
")",
";",
"if",
"(",
"$",
"leftToInsert",
"<=",
"$",
"maxLinesInFile",
")",
"{",
"$",
"count",
"=",
"$",
"leftToInsert",
";",
"}",
"else",
"{",
"$",
"count",
"=",
"$",
"maxLinesInFile",
";",
"}",
"return",
"$",
"count",
";",
"}"
] | @param int $resultsCount
@param int $maxLinesInFile
@param int $fileCounter
@return int | [
"@param",
"int",
"$resultsCount",
"@param",
"int",
"$maxLinesInFile",
"@param",
"int",
"$fileCounter"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/ExportService.php#L148-L158 |
ongr-io/ElasticsearchBundle | DependencyInjection/Compiler/MappingPass.php | MappingPass.process | public function process(ContainerBuilder $container)
{
$analysis = $container->getParameter('es.analysis');
$managers = $container->getParameter('es.managers');
$collector = $container->get('es.metadata_collector');
foreach ($managers as $managerName => $manager) {
$connection = $manager['index'];
$managerName = strtolower($managerName);
$managerDefinition = new Definition(
'ONGR\ElasticsearchBundle\Service\Manager',
[
$managerName,
$connection,
$analysis,
$manager,
]
);
$managerDefinition->setPublic(true);
$managerDefinition->setFactory(
[
new Reference('es.manager_factory'),
'createManager',
]
);
$container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition);
// Make es.manager.default as es.manager service.
if ($managerName === 'default') {
$container->setAlias('es.manager', 'es.manager.default');
if (Kernel::MAJOR_VERSION >= 4) {
$container->getAlias('es.manager')
->setPublic(true)
;
}
}
$mappings = $collector->getMappings($manager['mappings']);
// Building repository services.
foreach ($mappings as $repositoryType => $repositoryDetails) {
$repositoryDefinition = new Definition(
'ONGR\ElasticsearchBundle\Service\Repository',
[$repositoryDetails['namespace']]
);
$repositoryDefinition->setPublic(true);
if (isset($repositoryDetails['directory_name']) && $managerName == 'default') {
$container->get('es.document_finder')->setDocumentDir($repositoryDetails['directory_name']);
}
$repositoryDefinition->setFactory(
[
new Reference(sprintf('es.manager.%s', $managerName)),
'getRepository',
]
);
$repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType);
$container->setDefinition($repositoryId, $repositoryDefinition);
}
}
} | php | public function process(ContainerBuilder $container)
{
$analysis = $container->getParameter('es.analysis');
$managers = $container->getParameter('es.managers');
$collector = $container->get('es.metadata_collector');
foreach ($managers as $managerName => $manager) {
$connection = $manager['index'];
$managerName = strtolower($managerName);
$managerDefinition = new Definition(
'ONGR\ElasticsearchBundle\Service\Manager',
[
$managerName,
$connection,
$analysis,
$manager,
]
);
$managerDefinition->setPublic(true);
$managerDefinition->setFactory(
[
new Reference('es.manager_factory'),
'createManager',
]
);
$container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition);
// Make es.manager.default as es.manager service.
if ($managerName === 'default') {
$container->setAlias('es.manager', 'es.manager.default');
if (Kernel::MAJOR_VERSION >= 4) {
$container->getAlias('es.manager')
->setPublic(true)
;
}
}
$mappings = $collector->getMappings($manager['mappings']);
// Building repository services.
foreach ($mappings as $repositoryType => $repositoryDetails) {
$repositoryDefinition = new Definition(
'ONGR\ElasticsearchBundle\Service\Repository',
[$repositoryDetails['namespace']]
);
$repositoryDefinition->setPublic(true);
if (isset($repositoryDetails['directory_name']) && $managerName == 'default') {
$container->get('es.document_finder')->setDocumentDir($repositoryDetails['directory_name']);
}
$repositoryDefinition->setFactory(
[
new Reference(sprintf('es.manager.%s', $managerName)),
'getRepository',
]
);
$repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType);
$container->setDefinition($repositoryId, $repositoryDefinition);
}
}
} | [
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"analysis",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'es.analysis'",
")",
";",
"$",
"managers",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'es.managers'",
")",
";",
"$",
"collector",
"=",
"$",
"container",
"->",
"get",
"(",
"'es.metadata_collector'",
")",
";",
"foreach",
"(",
"$",
"managers",
"as",
"$",
"managerName",
"=>",
"$",
"manager",
")",
"{",
"$",
"connection",
"=",
"$",
"manager",
"[",
"'index'",
"]",
";",
"$",
"managerName",
"=",
"strtolower",
"(",
"$",
"managerName",
")",
";",
"$",
"managerDefinition",
"=",
"new",
"Definition",
"(",
"'ONGR\\ElasticsearchBundle\\Service\\Manager'",
",",
"[",
"$",
"managerName",
",",
"$",
"connection",
",",
"$",
"analysis",
",",
"$",
"manager",
",",
"]",
")",
";",
"$",
"managerDefinition",
"->",
"setPublic",
"(",
"true",
")",
";",
"$",
"managerDefinition",
"->",
"setFactory",
"(",
"[",
"new",
"Reference",
"(",
"'es.manager_factory'",
")",
",",
"'createManager'",
",",
"]",
")",
";",
"$",
"container",
"->",
"setDefinition",
"(",
"sprintf",
"(",
"'es.manager.%s'",
",",
"$",
"managerName",
")",
",",
"$",
"managerDefinition",
")",
";",
"// Make es.manager.default as es.manager service.",
"if",
"(",
"$",
"managerName",
"===",
"'default'",
")",
"{",
"$",
"container",
"->",
"setAlias",
"(",
"'es.manager'",
",",
"'es.manager.default'",
")",
";",
"if",
"(",
"Kernel",
"::",
"MAJOR_VERSION",
">=",
"4",
")",
"{",
"$",
"container",
"->",
"getAlias",
"(",
"'es.manager'",
")",
"->",
"setPublic",
"(",
"true",
")",
";",
"}",
"}",
"$",
"mappings",
"=",
"$",
"collector",
"->",
"getMappings",
"(",
"$",
"manager",
"[",
"'mappings'",
"]",
")",
";",
"// Building repository services.",
"foreach",
"(",
"$",
"mappings",
"as",
"$",
"repositoryType",
"=>",
"$",
"repositoryDetails",
")",
"{",
"$",
"repositoryDefinition",
"=",
"new",
"Definition",
"(",
"'ONGR\\ElasticsearchBundle\\Service\\Repository'",
",",
"[",
"$",
"repositoryDetails",
"[",
"'namespace'",
"]",
"]",
")",
";",
"$",
"repositoryDefinition",
"->",
"setPublic",
"(",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"repositoryDetails",
"[",
"'directory_name'",
"]",
")",
"&&",
"$",
"managerName",
"==",
"'default'",
")",
"{",
"$",
"container",
"->",
"get",
"(",
"'es.document_finder'",
")",
"->",
"setDocumentDir",
"(",
"$",
"repositoryDetails",
"[",
"'directory_name'",
"]",
")",
";",
"}",
"$",
"repositoryDefinition",
"->",
"setFactory",
"(",
"[",
"new",
"Reference",
"(",
"sprintf",
"(",
"'es.manager.%s'",
",",
"$",
"managerName",
")",
")",
",",
"'getRepository'",
",",
"]",
")",
";",
"$",
"repositoryId",
"=",
"sprintf",
"(",
"'es.manager.%s.%s'",
",",
"$",
"managerName",
",",
"$",
"repositoryType",
")",
";",
"$",
"container",
"->",
"setDefinition",
"(",
"$",
"repositoryId",
",",
"$",
"repositoryDefinition",
")",
";",
"}",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/DependencyInjection/Compiler/MappingPass.php#L28-L94 |
ongr-io/ElasticsearchBundle | Command/CacheClearCommand.php | CacheClearCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$this
->getManager($input->getOption('manager'))
->clearCache();
$io->success(
sprintf(
'Elasticsearch index cache has been cleared for manager named `%s`',
$input->getOption('manager')
)
);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$this
->getManager($input->getOption('manager'))
->clearCache();
$io->success(
sprintf(
'Elasticsearch index cache has been cleared for manager named `%s`',
$input->getOption('manager')
)
);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"io",
"=",
"new",
"SymfonyStyle",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"$",
"this",
"->",
"getManager",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'manager'",
")",
")",
"->",
"clearCache",
"(",
")",
";",
"$",
"io",
"->",
"success",
"(",
"sprintf",
"(",
"'Elasticsearch index cache has been cleared for manager named `%s`'",
",",
"$",
"input",
"->",
"getOption",
"(",
"'manager'",
")",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/CacheClearCommand.php#L40-L52 |
ongr-io/ElasticsearchBundle | Mapping/MetadataCollector.php | MetadataCollector.getMappings | public function getMappings(array $bundles)
{
$output = [];
foreach ($bundles as $name => $bundleConfig) {
// Backward compatibility hack for support.
if (!is_array($bundleConfig)) {
$name = $bundleConfig;
$bundleConfig = [];
}
$mappings = $this->getBundleMapping($name, $bundleConfig);
$alreadyDefinedTypes = array_intersect_key($mappings, $output);
if (count($alreadyDefinedTypes)) {
throw new \LogicException(
implode(',', array_keys($alreadyDefinedTypes)) .
' type(s) already defined in other document, you can use the same ' .
'type only once in a manager definition.'
);
}
$output = array_merge($output, $mappings);
}
return $output;
} | php | public function getMappings(array $bundles)
{
$output = [];
foreach ($bundles as $name => $bundleConfig) {
// Backward compatibility hack for support.
if (!is_array($bundleConfig)) {
$name = $bundleConfig;
$bundleConfig = [];
}
$mappings = $this->getBundleMapping($name, $bundleConfig);
$alreadyDefinedTypes = array_intersect_key($mappings, $output);
if (count($alreadyDefinedTypes)) {
throw new \LogicException(
implode(',', array_keys($alreadyDefinedTypes)) .
' type(s) already defined in other document, you can use the same ' .
'type only once in a manager definition.'
);
}
$output = array_merge($output, $mappings);
}
return $output;
} | [
"public",
"function",
"getMappings",
"(",
"array",
"$",
"bundles",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"bundles",
"as",
"$",
"name",
"=>",
"$",
"bundleConfig",
")",
"{",
"// Backward compatibility hack for support.",
"if",
"(",
"!",
"is_array",
"(",
"$",
"bundleConfig",
")",
")",
"{",
"$",
"name",
"=",
"$",
"bundleConfig",
";",
"$",
"bundleConfig",
"=",
"[",
"]",
";",
"}",
"$",
"mappings",
"=",
"$",
"this",
"->",
"getBundleMapping",
"(",
"$",
"name",
",",
"$",
"bundleConfig",
")",
";",
"$",
"alreadyDefinedTypes",
"=",
"array_intersect_key",
"(",
"$",
"mappings",
",",
"$",
"output",
")",
";",
"if",
"(",
"count",
"(",
"$",
"alreadyDefinedTypes",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"implode",
"(",
"','",
",",
"array_keys",
"(",
"$",
"alreadyDefinedTypes",
")",
")",
".",
"' type(s) already defined in other document, you can use the same '",
".",
"'type only once in a manager definition.'",
")",
";",
"}",
"$",
"output",
"=",
"array_merge",
"(",
"$",
"output",
",",
"$",
"mappings",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Fetches bundles mapping from documents.
@param string[] $bundles Elasticsearch manager config. You can get bundles list from 'mappings' node.
@return array | [
"Fetches",
"bundles",
"mapping",
"from",
"documents",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Mapping/MetadataCollector.php#L71-L95 |
ongr-io/ElasticsearchBundle | Mapping/MetadataCollector.php | MetadataCollector.getBundleMapping | public function getBundleMapping($name, $config = [])
{
if (!is_string($name)) {
throw new \LogicException('getBundleMapping() in the Metadata collector expects a string argument only!');
}
$cacheName = 'ongr.metadata.mapping.' . md5($name.serialize($config));
$this->enableCache && $mappings = $this->cache->fetch($cacheName);
if (isset($mappings) && false !== $mappings) {
return $mappings;
}
$mappings = [];
$documentDir = isset($config['document_dir']) ? $config['document_dir'] : $this->finder->getDocumentDir();
// Handle the case when single document mapping requested
// Usage od ":" in name is deprecated. This if is only for BC.
if (strpos($name, ':') !== false) {
list($bundle, $documentClass) = explode(':', $name);
$documents = $this->finder->getBundleDocumentClasses($bundle);
$documents = in_array($documentClass, $documents) ? [$documentClass] : [];
} else {
$documents = $this->finder->getBundleDocumentClasses($name, $documentDir);
$bundle = $name;
}
$bundleNamespace = $this->finder->getBundleClass($bundle);
$bundleNamespace = substr($bundleNamespace, 0, strrpos($bundleNamespace, '\\'));
if (!count($documents)) {
return [];
}
// Loop through documents found in bundle.
foreach ($documents as $document) {
$documentReflection = new \ReflectionClass(
$bundleNamespace .
'\\' . str_replace('/', '\\', $documentDir) .
'\\' . $document
);
try {
$documentMapping = $this->getDocumentReflectionMapping($documentReflection);
if (!$documentMapping) {
continue;
}
} catch (MissingDocumentAnnotationException $exception) {
// Not a document, just ignore
continue;
}
if (!array_key_exists($documentMapping['type'], $mappings)) {
$documentMapping['bundle'] = $bundle;
$mappings = array_merge($mappings, [$documentMapping['type'] => $documentMapping]);
} else {
throw new \LogicException(
$bundle . ' has 2 same type names defined in the documents. ' .
'Type names must be unique!'
);
}
}
$this->enableCache && $this->cache->save($cacheName, $mappings);
return $mappings;
} | php | public function getBundleMapping($name, $config = [])
{
if (!is_string($name)) {
throw new \LogicException('getBundleMapping() in the Metadata collector expects a string argument only!');
}
$cacheName = 'ongr.metadata.mapping.' . md5($name.serialize($config));
$this->enableCache && $mappings = $this->cache->fetch($cacheName);
if (isset($mappings) && false !== $mappings) {
return $mappings;
}
$mappings = [];
$documentDir = isset($config['document_dir']) ? $config['document_dir'] : $this->finder->getDocumentDir();
// Handle the case when single document mapping requested
// Usage od ":" in name is deprecated. This if is only for BC.
if (strpos($name, ':') !== false) {
list($bundle, $documentClass) = explode(':', $name);
$documents = $this->finder->getBundleDocumentClasses($bundle);
$documents = in_array($documentClass, $documents) ? [$documentClass] : [];
} else {
$documents = $this->finder->getBundleDocumentClasses($name, $documentDir);
$bundle = $name;
}
$bundleNamespace = $this->finder->getBundleClass($bundle);
$bundleNamespace = substr($bundleNamespace, 0, strrpos($bundleNamespace, '\\'));
if (!count($documents)) {
return [];
}
// Loop through documents found in bundle.
foreach ($documents as $document) {
$documentReflection = new \ReflectionClass(
$bundleNamespace .
'\\' . str_replace('/', '\\', $documentDir) .
'\\' . $document
);
try {
$documentMapping = $this->getDocumentReflectionMapping($documentReflection);
if (!$documentMapping) {
continue;
}
} catch (MissingDocumentAnnotationException $exception) {
// Not a document, just ignore
continue;
}
if (!array_key_exists($documentMapping['type'], $mappings)) {
$documentMapping['bundle'] = $bundle;
$mappings = array_merge($mappings, [$documentMapping['type'] => $documentMapping]);
} else {
throw new \LogicException(
$bundle . ' has 2 same type names defined in the documents. ' .
'Type names must be unique!'
);
}
}
$this->enableCache && $this->cache->save($cacheName, $mappings);
return $mappings;
} | [
"public",
"function",
"getBundleMapping",
"(",
"$",
"name",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'getBundleMapping() in the Metadata collector expects a string argument only!'",
")",
";",
"}",
"$",
"cacheName",
"=",
"'ongr.metadata.mapping.'",
".",
"md5",
"(",
"$",
"name",
".",
"serialize",
"(",
"$",
"config",
")",
")",
";",
"$",
"this",
"->",
"enableCache",
"&&",
"$",
"mappings",
"=",
"$",
"this",
"->",
"cache",
"->",
"fetch",
"(",
"$",
"cacheName",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"mappings",
")",
"&&",
"false",
"!==",
"$",
"mappings",
")",
"{",
"return",
"$",
"mappings",
";",
"}",
"$",
"mappings",
"=",
"[",
"]",
";",
"$",
"documentDir",
"=",
"isset",
"(",
"$",
"config",
"[",
"'document_dir'",
"]",
")",
"?",
"$",
"config",
"[",
"'document_dir'",
"]",
":",
"$",
"this",
"->",
"finder",
"->",
"getDocumentDir",
"(",
")",
";",
"// Handle the case when single document mapping requested",
"// Usage od \":\" in name is deprecated. This if is only for BC.",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"bundle",
",",
"$",
"documentClass",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"name",
")",
";",
"$",
"documents",
"=",
"$",
"this",
"->",
"finder",
"->",
"getBundleDocumentClasses",
"(",
"$",
"bundle",
")",
";",
"$",
"documents",
"=",
"in_array",
"(",
"$",
"documentClass",
",",
"$",
"documents",
")",
"?",
"[",
"$",
"documentClass",
"]",
":",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"documents",
"=",
"$",
"this",
"->",
"finder",
"->",
"getBundleDocumentClasses",
"(",
"$",
"name",
",",
"$",
"documentDir",
")",
";",
"$",
"bundle",
"=",
"$",
"name",
";",
"}",
"$",
"bundleNamespace",
"=",
"$",
"this",
"->",
"finder",
"->",
"getBundleClass",
"(",
"$",
"bundle",
")",
";",
"$",
"bundleNamespace",
"=",
"substr",
"(",
"$",
"bundleNamespace",
",",
"0",
",",
"strrpos",
"(",
"$",
"bundleNamespace",
",",
"'\\\\'",
")",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"documents",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"// Loop through documents found in bundle.",
"foreach",
"(",
"$",
"documents",
"as",
"$",
"document",
")",
"{",
"$",
"documentReflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"bundleNamespace",
".",
"'\\\\'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"documentDir",
")",
".",
"'\\\\'",
".",
"$",
"document",
")",
";",
"try",
"{",
"$",
"documentMapping",
"=",
"$",
"this",
"->",
"getDocumentReflectionMapping",
"(",
"$",
"documentReflection",
")",
";",
"if",
"(",
"!",
"$",
"documentMapping",
")",
"{",
"continue",
";",
"}",
"}",
"catch",
"(",
"MissingDocumentAnnotationException",
"$",
"exception",
")",
"{",
"// Not a document, just ignore",
"continue",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"documentMapping",
"[",
"'type'",
"]",
",",
"$",
"mappings",
")",
")",
"{",
"$",
"documentMapping",
"[",
"'bundle'",
"]",
"=",
"$",
"bundle",
";",
"$",
"mappings",
"=",
"array_merge",
"(",
"$",
"mappings",
",",
"[",
"$",
"documentMapping",
"[",
"'type'",
"]",
"=>",
"$",
"documentMapping",
"]",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"$",
"bundle",
".",
"' has 2 same type names defined in the documents. '",
".",
"'Type names must be unique!'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"enableCache",
"&&",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"$",
"cacheName",
",",
"$",
"mappings",
")",
";",
"return",
"$",
"mappings",
";",
"}"
] | Searches for documents in the bundle and tries to read them.
@param string $name
@param array $config Bundle configuration
@return array Empty array on containing zero documents. | [
"Searches",
"for",
"documents",
"in",
"the",
"bundle",
"and",
"tries",
"to",
"read",
"them",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Mapping/MetadataCollector.php#L105-L172 |
ongr-io/ElasticsearchBundle | Mapping/MetadataCollector.php | MetadataCollector.getClientMapping | public function getClientMapping(array $bundles)
{
/** @var array $typesMapping Array of filtered mappings for the elasticsearch client*/
$typesMapping = null;
/** @var array $mappings All mapping info */
$mappings = $this->getMappings($bundles);
foreach ($mappings as $type => $mapping) {
if (!empty($mapping['properties'])) {
$typesMapping[$type] = array_filter(
array_merge(
['properties' => $mapping['properties']],
$mapping['fields']
),
function ($value) {
return (bool)$value || is_bool($value);
}
);
}
}
return $typesMapping;
} | php | public function getClientMapping(array $bundles)
{
/** @var array $typesMapping Array of filtered mappings for the elasticsearch client*/
$typesMapping = null;
/** @var array $mappings All mapping info */
$mappings = $this->getMappings($bundles);
foreach ($mappings as $type => $mapping) {
if (!empty($mapping['properties'])) {
$typesMapping[$type] = array_filter(
array_merge(
['properties' => $mapping['properties']],
$mapping['fields']
),
function ($value) {
return (bool)$value || is_bool($value);
}
);
}
}
return $typesMapping;
} | [
"public",
"function",
"getClientMapping",
"(",
"array",
"$",
"bundles",
")",
"{",
"/** @var array $typesMapping Array of filtered mappings for the elasticsearch client*/",
"$",
"typesMapping",
"=",
"null",
";",
"/** @var array $mappings All mapping info */",
"$",
"mappings",
"=",
"$",
"this",
"->",
"getMappings",
"(",
"$",
"bundles",
")",
";",
"foreach",
"(",
"$",
"mappings",
"as",
"$",
"type",
"=>",
"$",
"mapping",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"mapping",
"[",
"'properties'",
"]",
")",
")",
"{",
"$",
"typesMapping",
"[",
"$",
"type",
"]",
"=",
"array_filter",
"(",
"array_merge",
"(",
"[",
"'properties'",
"=>",
"$",
"mapping",
"[",
"'properties'",
"]",
"]",
",",
"$",
"mapping",
"[",
"'fields'",
"]",
")",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"value",
"||",
"is_bool",
"(",
"$",
"value",
")",
";",
"}",
")",
";",
"}",
"}",
"return",
"$",
"typesMapping",
";",
"}"
] | Retrieves prepared mapping to sent to the elasticsearch client.
@param array $bundles Manager config.
@return array|null | [
"Retrieves",
"prepared",
"mapping",
"to",
"sent",
"to",
"the",
"elasticsearch",
"client",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Mapping/MetadataCollector.php#L207-L230 |
ongr-io/ElasticsearchBundle | Mapping/MetadataCollector.php | MetadataCollector.getClientAnalysis | public function getClientAnalysis(array $bundles, $analysisConfig = [])
{
$cacheName = 'ongr.metadata.analysis.'.md5(serialize($bundles));
$this->enableCache && $typesAnalysis = $this->cache->fetch($cacheName);
if (isset($typesAnalysis) && false !== $typesAnalysis) {
return $typesAnalysis;
}
$typesAnalysis = [
'analyzer' => [],
'filter' => [],
'tokenizer' => [],
'char_filter' => [],
'normalizer' => [],
];
/** @var array $mappings All mapping info */
$mappings = $this->getMappings($bundles);
foreach ($mappings as $type => $metadata) {
foreach ($metadata['analyzers'] as $analyzerName) {
if (isset($analysisConfig['analyzer'][$analyzerName])) {
$analyzer = $analysisConfig['analyzer'][$analyzerName];
$typesAnalysis['analyzer'][$analyzerName] = $analyzer;
$typesAnalysis['filter'] = $this->getAnalysisNodeConfiguration(
'filter',
$analyzer,
$analysisConfig,
$typesAnalysis['filter']
);
$typesAnalysis['tokenizer'] = $this->getAnalysisNodeConfiguration(
'tokenizer',
$analyzer,
$analysisConfig,
$typesAnalysis['tokenizer']
);
$typesAnalysis['char_filter'] = $this->getAnalysisNodeConfiguration(
'char_filter',
$analyzer,
$analysisConfig,
$typesAnalysis['char_filter']
);
}
}
}
if (isset($analysisConfig['normalizer'])) {
$typesAnalysis['normalizer'] = $analysisConfig['normalizer'];
}
$this->enableCache && $this->cache->save($cacheName, $typesAnalysis);
return $typesAnalysis;
} | php | public function getClientAnalysis(array $bundles, $analysisConfig = [])
{
$cacheName = 'ongr.metadata.analysis.'.md5(serialize($bundles));
$this->enableCache && $typesAnalysis = $this->cache->fetch($cacheName);
if (isset($typesAnalysis) && false !== $typesAnalysis) {
return $typesAnalysis;
}
$typesAnalysis = [
'analyzer' => [],
'filter' => [],
'tokenizer' => [],
'char_filter' => [],
'normalizer' => [],
];
/** @var array $mappings All mapping info */
$mappings = $this->getMappings($bundles);
foreach ($mappings as $type => $metadata) {
foreach ($metadata['analyzers'] as $analyzerName) {
if (isset($analysisConfig['analyzer'][$analyzerName])) {
$analyzer = $analysisConfig['analyzer'][$analyzerName];
$typesAnalysis['analyzer'][$analyzerName] = $analyzer;
$typesAnalysis['filter'] = $this->getAnalysisNodeConfiguration(
'filter',
$analyzer,
$analysisConfig,
$typesAnalysis['filter']
);
$typesAnalysis['tokenizer'] = $this->getAnalysisNodeConfiguration(
'tokenizer',
$analyzer,
$analysisConfig,
$typesAnalysis['tokenizer']
);
$typesAnalysis['char_filter'] = $this->getAnalysisNodeConfiguration(
'char_filter',
$analyzer,
$analysisConfig,
$typesAnalysis['char_filter']
);
}
}
}
if (isset($analysisConfig['normalizer'])) {
$typesAnalysis['normalizer'] = $analysisConfig['normalizer'];
}
$this->enableCache && $this->cache->save($cacheName, $typesAnalysis);
return $typesAnalysis;
} | [
"public",
"function",
"getClientAnalysis",
"(",
"array",
"$",
"bundles",
",",
"$",
"analysisConfig",
"=",
"[",
"]",
")",
"{",
"$",
"cacheName",
"=",
"'ongr.metadata.analysis.'",
".",
"md5",
"(",
"serialize",
"(",
"$",
"bundles",
")",
")",
";",
"$",
"this",
"->",
"enableCache",
"&&",
"$",
"typesAnalysis",
"=",
"$",
"this",
"->",
"cache",
"->",
"fetch",
"(",
"$",
"cacheName",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"typesAnalysis",
")",
"&&",
"false",
"!==",
"$",
"typesAnalysis",
")",
"{",
"return",
"$",
"typesAnalysis",
";",
"}",
"$",
"typesAnalysis",
"=",
"[",
"'analyzer'",
"=>",
"[",
"]",
",",
"'filter'",
"=>",
"[",
"]",
",",
"'tokenizer'",
"=>",
"[",
"]",
",",
"'char_filter'",
"=>",
"[",
"]",
",",
"'normalizer'",
"=>",
"[",
"]",
",",
"]",
";",
"/** @var array $mappings All mapping info */",
"$",
"mappings",
"=",
"$",
"this",
"->",
"getMappings",
"(",
"$",
"bundles",
")",
";",
"foreach",
"(",
"$",
"mappings",
"as",
"$",
"type",
"=>",
"$",
"metadata",
")",
"{",
"foreach",
"(",
"$",
"metadata",
"[",
"'analyzers'",
"]",
"as",
"$",
"analyzerName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"analysisConfig",
"[",
"'analyzer'",
"]",
"[",
"$",
"analyzerName",
"]",
")",
")",
"{",
"$",
"analyzer",
"=",
"$",
"analysisConfig",
"[",
"'analyzer'",
"]",
"[",
"$",
"analyzerName",
"]",
";",
"$",
"typesAnalysis",
"[",
"'analyzer'",
"]",
"[",
"$",
"analyzerName",
"]",
"=",
"$",
"analyzer",
";",
"$",
"typesAnalysis",
"[",
"'filter'",
"]",
"=",
"$",
"this",
"->",
"getAnalysisNodeConfiguration",
"(",
"'filter'",
",",
"$",
"analyzer",
",",
"$",
"analysisConfig",
",",
"$",
"typesAnalysis",
"[",
"'filter'",
"]",
")",
";",
"$",
"typesAnalysis",
"[",
"'tokenizer'",
"]",
"=",
"$",
"this",
"->",
"getAnalysisNodeConfiguration",
"(",
"'tokenizer'",
",",
"$",
"analyzer",
",",
"$",
"analysisConfig",
",",
"$",
"typesAnalysis",
"[",
"'tokenizer'",
"]",
")",
";",
"$",
"typesAnalysis",
"[",
"'char_filter'",
"]",
"=",
"$",
"this",
"->",
"getAnalysisNodeConfiguration",
"(",
"'char_filter'",
",",
"$",
"analyzer",
",",
"$",
"analysisConfig",
",",
"$",
"typesAnalysis",
"[",
"'char_filter'",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"analysisConfig",
"[",
"'normalizer'",
"]",
")",
")",
"{",
"$",
"typesAnalysis",
"[",
"'normalizer'",
"]",
"=",
"$",
"analysisConfig",
"[",
"'normalizer'",
"]",
";",
"}",
"$",
"this",
"->",
"enableCache",
"&&",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"$",
"cacheName",
",",
"$",
"typesAnalysis",
")",
";",
"return",
"$",
"typesAnalysis",
";",
"}"
] | Prepares analysis node for Elasticsearch client.
@param array $bundles
@param array $analysisConfig
@return array | [
"Prepares",
"analysis",
"node",
"for",
"Elasticsearch",
"client",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Mapping/MetadataCollector.php#L240-L294 |
ongr-io/ElasticsearchBundle | Mapping/MetadataCollector.php | MetadataCollector.getAnalysisNodeConfiguration | private function getAnalysisNodeConfiguration($type, $analyzer, $analysisConfig, $container = [])
{
if (isset($analyzer[$type])) {
if (is_array($analyzer[$type])) {
foreach ($analyzer[$type] as $filter) {
if (isset($analysisConfig[$type][$filter])) {
$container[$filter] = $analysisConfig[$type][$filter];
}
}
} else {
if (isset($analysisConfig[$type][$analyzer[$type]])) {
$container[$analyzer[$type]] = $analysisConfig[$type][$analyzer[$type]];
}
}
}
return $container;
} | php | private function getAnalysisNodeConfiguration($type, $analyzer, $analysisConfig, $container = [])
{
if (isset($analyzer[$type])) {
if (is_array($analyzer[$type])) {
foreach ($analyzer[$type] as $filter) {
if (isset($analysisConfig[$type][$filter])) {
$container[$filter] = $analysisConfig[$type][$filter];
}
}
} else {
if (isset($analysisConfig[$type][$analyzer[$type]])) {
$container[$analyzer[$type]] = $analysisConfig[$type][$analyzer[$type]];
}
}
}
return $container;
} | [
"private",
"function",
"getAnalysisNodeConfiguration",
"(",
"$",
"type",
",",
"$",
"analyzer",
",",
"$",
"analysisConfig",
",",
"$",
"container",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"analyzer",
"[",
"$",
"type",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"analyzer",
"[",
"$",
"type",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"analyzer",
"[",
"$",
"type",
"]",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"analysisConfig",
"[",
"$",
"type",
"]",
"[",
"$",
"filter",
"]",
")",
")",
"{",
"$",
"container",
"[",
"$",
"filter",
"]",
"=",
"$",
"analysisConfig",
"[",
"$",
"type",
"]",
"[",
"$",
"filter",
"]",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"analysisConfig",
"[",
"$",
"type",
"]",
"[",
"$",
"analyzer",
"[",
"$",
"type",
"]",
"]",
")",
")",
"{",
"$",
"container",
"[",
"$",
"analyzer",
"[",
"$",
"type",
"]",
"]",
"=",
"$",
"analysisConfig",
"[",
"$",
"type",
"]",
"[",
"$",
"analyzer",
"[",
"$",
"type",
"]",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"container",
";",
"}"
] | Prepares analysis node content for Elasticsearch client.
@param string $type Node type: filter, tokenizer or char_filter
@param array $analyzer Analyzer from which used helpers will be extracted.
@param array $analysisConfig Pre configured analyzers container
@param array $container Current analysis container where prepared helpers will be appended.
@return array | [
"Prepares",
"analysis",
"node",
"content",
"for",
"Elasticsearch",
"client",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Mapping/MetadataCollector.php#L306-L322 |
ongr-io/ElasticsearchBundle | Mapping/MetadataCollector.php | MetadataCollector.getMapping | public function getMapping($namespace)
{
$cacheName = 'ongr.metadata.document.'.md5($namespace);
$namespace = $this->getClassName($namespace);
$this->enableCache && $mapping = $this->cache->fetch($cacheName);
if (isset($mapping) && false !== $mapping) {
return $mapping;
}
$mapping = $this->getDocumentReflectionMapping(new \ReflectionClass($namespace));
$this->enableCache && $this->cache->save($cacheName, $mapping);
return $mapping;
} | php | public function getMapping($namespace)
{
$cacheName = 'ongr.metadata.document.'.md5($namespace);
$namespace = $this->getClassName($namespace);
$this->enableCache && $mapping = $this->cache->fetch($cacheName);
if (isset($mapping) && false !== $mapping) {
return $mapping;
}
$mapping = $this->getDocumentReflectionMapping(new \ReflectionClass($namespace));
$this->enableCache && $this->cache->save($cacheName, $mapping);
return $mapping;
} | [
"public",
"function",
"getMapping",
"(",
"$",
"namespace",
")",
"{",
"$",
"cacheName",
"=",
"'ongr.metadata.document.'",
".",
"md5",
"(",
"$",
"namespace",
")",
";",
"$",
"namespace",
"=",
"$",
"this",
"->",
"getClassName",
"(",
"$",
"namespace",
")",
";",
"$",
"this",
"->",
"enableCache",
"&&",
"$",
"mapping",
"=",
"$",
"this",
"->",
"cache",
"->",
"fetch",
"(",
"$",
"cacheName",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"mapping",
")",
"&&",
"false",
"!==",
"$",
"mapping",
")",
"{",
"return",
"$",
"mapping",
";",
"}",
"$",
"mapping",
"=",
"$",
"this",
"->",
"getDocumentReflectionMapping",
"(",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"namespace",
")",
")",
";",
"$",
"this",
"->",
"enableCache",
"&&",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"$",
"cacheName",
",",
"$",
"mapping",
")",
";",
"return",
"$",
"mapping",
";",
"}"
] | Returns single document mapping metadata.
@param string $namespace Document namespace
@return array
@throws DocumentParserException | [
"Returns",
"single",
"document",
"mapping",
"metadata",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Mapping/MetadataCollector.php#L345-L361 |
ongr-io/ElasticsearchBundle | Result/Converter.php | Converter.convertToDocument | public function convertToDocument($rawData, Manager $manager)
{
$types = $this->metadataCollector->getMappings($manager->getConfig()['mappings']);
if (isset($types[$rawData['_type']])) {
$metadata = $types[$rawData['_type']];
} else {
throw new \LogicException("Got document of unknown type '{$rawData['_type']}'.");
}
switch (true) {
case isset($rawData['_source']):
$rawData = array_merge($rawData, $rawData['_source']);
break;
case isset($rawData['fields']):
$rawData = array_merge($rawData, $rawData['fields']);
break;
default:
// Do nothing.
break;
}
$object = $this->assignArrayToObject($rawData, new $metadata['namespace'](), $metadata['aliases']);
return $object;
} | php | public function convertToDocument($rawData, Manager $manager)
{
$types = $this->metadataCollector->getMappings($manager->getConfig()['mappings']);
if (isset($types[$rawData['_type']])) {
$metadata = $types[$rawData['_type']];
} else {
throw new \LogicException("Got document of unknown type '{$rawData['_type']}'.");
}
switch (true) {
case isset($rawData['_source']):
$rawData = array_merge($rawData, $rawData['_source']);
break;
case isset($rawData['fields']):
$rawData = array_merge($rawData, $rawData['fields']);
break;
default:
// Do nothing.
break;
}
$object = $this->assignArrayToObject($rawData, new $metadata['namespace'](), $metadata['aliases']);
return $object;
} | [
"public",
"function",
"convertToDocument",
"(",
"$",
"rawData",
",",
"Manager",
"$",
"manager",
")",
"{",
"$",
"types",
"=",
"$",
"this",
"->",
"metadataCollector",
"->",
"getMappings",
"(",
"$",
"manager",
"->",
"getConfig",
"(",
")",
"[",
"'mappings'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"types",
"[",
"$",
"rawData",
"[",
"'_type'",
"]",
"]",
")",
")",
"{",
"$",
"metadata",
"=",
"$",
"types",
"[",
"$",
"rawData",
"[",
"'_type'",
"]",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"Got document of unknown type '{$rawData['_type']}'.\"",
")",
";",
"}",
"switch",
"(",
"true",
")",
"{",
"case",
"isset",
"(",
"$",
"rawData",
"[",
"'_source'",
"]",
")",
":",
"$",
"rawData",
"=",
"array_merge",
"(",
"$",
"rawData",
",",
"$",
"rawData",
"[",
"'_source'",
"]",
")",
";",
"break",
";",
"case",
"isset",
"(",
"$",
"rawData",
"[",
"'fields'",
"]",
")",
":",
"$",
"rawData",
"=",
"array_merge",
"(",
"$",
"rawData",
",",
"$",
"rawData",
"[",
"'fields'",
"]",
")",
";",
"break",
";",
"default",
":",
"// Do nothing.",
"break",
";",
"}",
"$",
"object",
"=",
"$",
"this",
"->",
"assignArrayToObject",
"(",
"$",
"rawData",
",",
"new",
"$",
"metadata",
"[",
"'namespace'",
"]",
"(",
")",
",",
"$",
"metadata",
"[",
"'aliases'",
"]",
")",
";",
"return",
"$",
"object",
";",
"}"
] | Converts raw array to document.
@param array $rawData
@param Manager $manager
@return object
@throws \LogicException | [
"Converts",
"raw",
"array",
"to",
"document",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/Converter.php#L50-L75 |
ongr-io/ElasticsearchBundle | Result/Converter.php | Converter.assignArrayToObject | public function assignArrayToObject(array $array, $object, array $aliases)
{
foreach ($array as $name => $value) {
if (!isset($aliases[$name])) {
continue;
}
if (isset($aliases[$name]['type'])) {
switch ($aliases[$name]['type']) {
case 'date':
if (is_null($value) || (is_object($value) && $value instanceof \DateTimeInterface)) {
continue;
}
if (is_numeric($value) && (int)$value == $value) {
$time = $value;
$value = new \DateTime();
$value->setTimestamp($time);
} else {
$value = new \DateTime($value);
}
break;
case ObjectType::NAME:
case Nested::NAME:
if ($aliases[$name]['multiple']) {
$value = new ObjectIterator($this, $value, $aliases[$name]);
} else {
if (!isset($value)) {
break;
}
$value = $this->assignArrayToObject(
$value,
new $aliases[$name]['namespace'](),
$aliases[$name]['aliases']
);
}
break;
case 'boolean':
if (!is_bool($value)) {
$value = (bool)$value;
}
break;
default:
// Do nothing here. Default cas is required by our code style standard.
break;
}
}
if ($aliases[$name]['propertyType'] == 'private') {
$object->{$aliases[$name]['methods']['setter']}($value);
} else {
$object->{$aliases[$name]['propertyName']} = $value;
}
}
return $object;
} | php | public function assignArrayToObject(array $array, $object, array $aliases)
{
foreach ($array as $name => $value) {
if (!isset($aliases[$name])) {
continue;
}
if (isset($aliases[$name]['type'])) {
switch ($aliases[$name]['type']) {
case 'date':
if (is_null($value) || (is_object($value) && $value instanceof \DateTimeInterface)) {
continue;
}
if (is_numeric($value) && (int)$value == $value) {
$time = $value;
$value = new \DateTime();
$value->setTimestamp($time);
} else {
$value = new \DateTime($value);
}
break;
case ObjectType::NAME:
case Nested::NAME:
if ($aliases[$name]['multiple']) {
$value = new ObjectIterator($this, $value, $aliases[$name]);
} else {
if (!isset($value)) {
break;
}
$value = $this->assignArrayToObject(
$value,
new $aliases[$name]['namespace'](),
$aliases[$name]['aliases']
);
}
break;
case 'boolean':
if (!is_bool($value)) {
$value = (bool)$value;
}
break;
default:
// Do nothing here. Default cas is required by our code style standard.
break;
}
}
if ($aliases[$name]['propertyType'] == 'private') {
$object->{$aliases[$name]['methods']['setter']}($value);
} else {
$object->{$aliases[$name]['propertyName']} = $value;
}
}
return $object;
} | [
"public",
"function",
"assignArrayToObject",
"(",
"array",
"$",
"array",
",",
"$",
"object",
",",
"array",
"$",
"aliases",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"aliases",
"[",
"$",
"name",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'type'",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'type'",
"]",
")",
"{",
"case",
"'date'",
":",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
"||",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"instanceof",
"\\",
"DateTimeInterface",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"(",
"int",
")",
"$",
"value",
"==",
"$",
"value",
")",
"{",
"$",
"time",
"=",
"$",
"value",
";",
"$",
"value",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"value",
"->",
"setTimestamp",
"(",
"$",
"time",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"value",
")",
";",
"}",
"break",
";",
"case",
"ObjectType",
"::",
"NAME",
":",
"case",
"Nested",
"::",
"NAME",
":",
"if",
"(",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'multiple'",
"]",
")",
"{",
"$",
"value",
"=",
"new",
"ObjectIterator",
"(",
"$",
"this",
",",
"$",
"value",
",",
"$",
"aliases",
"[",
"$",
"name",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
")",
")",
"{",
"break",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"assignArrayToObject",
"(",
"$",
"value",
",",
"new",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'namespace'",
"]",
"(",
")",
",",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'aliases'",
"]",
")",
";",
"}",
"break",
";",
"case",
"'boolean'",
":",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"bool",
")",
"$",
"value",
";",
"}",
"break",
";",
"default",
":",
"// Do nothing here. Default cas is required by our code style standard.",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'propertyType'",
"]",
"==",
"'private'",
")",
"{",
"$",
"object",
"->",
"{",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'methods'",
"]",
"[",
"'setter'",
"]",
"}",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"object",
"->",
"{",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'propertyName'",
"]",
"}",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"object",
";",
"}"
] | Assigns all properties to object.
@param array $array
@param object $object
@param array $aliases
@return object | [
"Assigns",
"all",
"properties",
"to",
"object",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/Converter.php#L86-L141 |
ongr-io/ElasticsearchBundle | Result/Converter.php | Converter.convertToArray | public function convertToArray($object, $aliases = [], $fields = [])
{
if (empty($aliases)) {
$aliases = $this->getAlias($object);
if (count($fields) > 0) {
$aliases = array_intersect_key($aliases, array_flip($fields));
}
}
$array = [];
// Variable $name defined in client.
foreach ($aliases as $name => $alias) {
if ($aliases[$name]['propertyType'] == 'private') {
$value = $object->{$aliases[$name]['methods']['getter']}();
} else {
$value = $object->{$aliases[$name]['propertyName']};
}
if (isset($value)) {
if (array_key_exists('aliases', $alias)) {
$new = [];
if ($alias['multiple']) {
$this->isCollection($aliases[$name]['propertyName'], $value);
foreach ($value as $item) {
$this->checkVariableType($item, [$alias['namespace']]);
$new[] = $this->convertToArray($item, $alias['aliases']);
}
} else {
$this->checkVariableType($value, [$alias['namespace']]);
$new = $this->convertToArray($value, $alias['aliases']);
}
$value = $new;
}
if ($value instanceof \DateTime) {
$value = $value->format(isset($alias['format']) ? $alias['format'] : \DateTime::ISO8601);
}
if (isset($alias['type'])) {
switch ($alias['type']) {
case 'float':
if (is_array($value)) {
foreach ($value as $key => $item) {
$value[$key] = (float)$item;
}
} else {
$value = (float)$value;
}
break;
case 'integer':
if (is_array($value)) {
foreach ($value as $key => $item) {
$value[$key] = (int)$item;
}
} else {
$value = (int)$value;
}
break;
default:
break;
}
}
$array[$name] = $value;
}
}
return $array;
} | php | public function convertToArray($object, $aliases = [], $fields = [])
{
if (empty($aliases)) {
$aliases = $this->getAlias($object);
if (count($fields) > 0) {
$aliases = array_intersect_key($aliases, array_flip($fields));
}
}
$array = [];
// Variable $name defined in client.
foreach ($aliases as $name => $alias) {
if ($aliases[$name]['propertyType'] == 'private') {
$value = $object->{$aliases[$name]['methods']['getter']}();
} else {
$value = $object->{$aliases[$name]['propertyName']};
}
if (isset($value)) {
if (array_key_exists('aliases', $alias)) {
$new = [];
if ($alias['multiple']) {
$this->isCollection($aliases[$name]['propertyName'], $value);
foreach ($value as $item) {
$this->checkVariableType($item, [$alias['namespace']]);
$new[] = $this->convertToArray($item, $alias['aliases']);
}
} else {
$this->checkVariableType($value, [$alias['namespace']]);
$new = $this->convertToArray($value, $alias['aliases']);
}
$value = $new;
}
if ($value instanceof \DateTime) {
$value = $value->format(isset($alias['format']) ? $alias['format'] : \DateTime::ISO8601);
}
if (isset($alias['type'])) {
switch ($alias['type']) {
case 'float':
if (is_array($value)) {
foreach ($value as $key => $item) {
$value[$key] = (float)$item;
}
} else {
$value = (float)$value;
}
break;
case 'integer':
if (is_array($value)) {
foreach ($value as $key => $item) {
$value[$key] = (int)$item;
}
} else {
$value = (int)$value;
}
break;
default:
break;
}
}
$array[$name] = $value;
}
}
return $array;
} | [
"public",
"function",
"convertToArray",
"(",
"$",
"object",
",",
"$",
"aliases",
"=",
"[",
"]",
",",
"$",
"fields",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"aliases",
")",
")",
"{",
"$",
"aliases",
"=",
"$",
"this",
"->",
"getAlias",
"(",
"$",
"object",
")",
";",
"if",
"(",
"count",
"(",
"$",
"fields",
")",
">",
"0",
")",
"{",
"$",
"aliases",
"=",
"array_intersect_key",
"(",
"$",
"aliases",
",",
"array_flip",
"(",
"$",
"fields",
")",
")",
";",
"}",
"}",
"$",
"array",
"=",
"[",
"]",
";",
"// Variable $name defined in client.",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"name",
"=>",
"$",
"alias",
")",
"{",
"if",
"(",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'propertyType'",
"]",
"==",
"'private'",
")",
"{",
"$",
"value",
"=",
"$",
"object",
"->",
"{",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'methods'",
"]",
"[",
"'getter'",
"]",
"}",
"(",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"object",
"->",
"{",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'propertyName'",
"]",
"}",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'aliases'",
",",
"$",
"alias",
")",
")",
"{",
"$",
"new",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"alias",
"[",
"'multiple'",
"]",
")",
"{",
"$",
"this",
"->",
"isCollection",
"(",
"$",
"aliases",
"[",
"$",
"name",
"]",
"[",
"'propertyName'",
"]",
",",
"$",
"value",
")",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"checkVariableType",
"(",
"$",
"item",
",",
"[",
"$",
"alias",
"[",
"'namespace'",
"]",
"]",
")",
";",
"$",
"new",
"[",
"]",
"=",
"$",
"this",
"->",
"convertToArray",
"(",
"$",
"item",
",",
"$",
"alias",
"[",
"'aliases'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"checkVariableType",
"(",
"$",
"value",
",",
"[",
"$",
"alias",
"[",
"'namespace'",
"]",
"]",
")",
";",
"$",
"new",
"=",
"$",
"this",
"->",
"convertToArray",
"(",
"$",
"value",
",",
"$",
"alias",
"[",
"'aliases'",
"]",
")",
";",
"}",
"$",
"value",
"=",
"$",
"new",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"->",
"format",
"(",
"isset",
"(",
"$",
"alias",
"[",
"'format'",
"]",
")",
"?",
"$",
"alias",
"[",
"'format'",
"]",
":",
"\\",
"DateTime",
"::",
"ISO8601",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"alias",
"[",
"'type'",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"alias",
"[",
"'type'",
"]",
")",
"{",
"case",
"'float'",
":",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"value",
"[",
"$",
"key",
"]",
"=",
"(",
"float",
")",
"$",
"item",
";",
"}",
"}",
"else",
"{",
"$",
"value",
"=",
"(",
"float",
")",
"$",
"value",
";",
"}",
"break",
";",
"case",
"'integer'",
":",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"value",
"[",
"$",
"key",
"]",
"=",
"(",
"int",
")",
"$",
"item",
";",
"}",
"}",
"else",
"{",
"$",
"value",
"=",
"(",
"int",
")",
"$",
"value",
";",
"}",
"break",
";",
"default",
":",
"break",
";",
"}",
"}",
"$",
"array",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] | Converts object to an array.
@param mixed $object
@param array $aliases
@param array $fields
@return array | [
"Converts",
"object",
"to",
"an",
"array",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/Converter.php#L152-L221 |
ongr-io/ElasticsearchBundle | Result/Converter.php | Converter.checkVariableType | private function checkVariableType($object, array $expectedClasses)
{
if (!is_object($object)) {
$msg = 'Expected variable of type object, got ' . gettype($object) . ". (field isn't multiple)";
throw new \InvalidArgumentException($msg);
}
$classes = class_parents($object);
$classes[] = $class = get_class($object);
if (empty(array_intersect($classes, $expectedClasses))) {
throw new \InvalidArgumentException("Expected object of type {$expectedClasses[0]}, got {$class}.");
}
} | php | private function checkVariableType($object, array $expectedClasses)
{
if (!is_object($object)) {
$msg = 'Expected variable of type object, got ' . gettype($object) . ". (field isn't multiple)";
throw new \InvalidArgumentException($msg);
}
$classes = class_parents($object);
$classes[] = $class = get_class($object);
if (empty(array_intersect($classes, $expectedClasses))) {
throw new \InvalidArgumentException("Expected object of type {$expectedClasses[0]}, got {$class}.");
}
} | [
"private",
"function",
"checkVariableType",
"(",
"$",
"object",
",",
"array",
"$",
"expectedClasses",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"$",
"msg",
"=",
"'Expected variable of type object, got '",
".",
"gettype",
"(",
"$",
"object",
")",
".",
"\". (field isn't multiple)\"",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"classes",
"=",
"class_parents",
"(",
"$",
"object",
")",
";",
"$",
"classes",
"[",
"]",
"=",
"$",
"class",
"=",
"get_class",
"(",
"$",
"object",
")",
";",
"if",
"(",
"empty",
"(",
"array_intersect",
"(",
"$",
"classes",
",",
"$",
"expectedClasses",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Expected object of type {$expectedClasses[0]}, got {$class}.\"",
")",
";",
"}",
"}"
] | Check if class matches the expected one.
@param object $object
@param array $expectedClasses
@throws \InvalidArgumentException | [
"Check",
"if",
"class",
"matches",
"the",
"expected",
"one",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/Converter.php#L231-L243 |
ongr-io/ElasticsearchBundle | Result/Converter.php | Converter.isCollection | private function isCollection($property, $value)
{
if (!$value instanceof Collection) {
$got = is_object($value) ? get_class($value) : gettype($value);
throw new \InvalidArgumentException(
sprintf('Value of "%s" property must be an instance of Collection, got %s.', $property, $got)
);
}
} | php | private function isCollection($property, $value)
{
if (!$value instanceof Collection) {
$got = is_object($value) ? get_class($value) : gettype($value);
throw new \InvalidArgumentException(
sprintf('Value of "%s" property must be an instance of Collection, got %s.', $property, $got)
);
}
} | [
"private",
"function",
"isCollection",
"(",
"$",
"property",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"value",
"instanceof",
"Collection",
")",
"{",
"$",
"got",
"=",
"is_object",
"(",
"$",
"value",
")",
"?",
"get_class",
"(",
"$",
"value",
")",
":",
"gettype",
"(",
"$",
"value",
")",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Value of \"%s\" property must be an instance of Collection, got %s.'",
",",
"$",
"property",
",",
"$",
"got",
")",
")",
";",
"}",
"}"
] | Check if value is instance of Collection.
@param string $property
@param mixed $value
@throws \InvalidArgumentException | [
"Check",
"if",
"value",
"is",
"instance",
"of",
"Collection",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/Converter.php#L253-L262 |
ongr-io/ElasticsearchBundle | Command/IndexImportCommand.php | IndexImportCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$manager = $this->getManager($input->getOption('manager'));
// Initialize options array
$options = [];
if ($input->getOption('gzip')) {
$options['gzip'] = null;
}
$options['bulk-size'] = $input->getOption('bulk-size');
/** @var ImportService $importService */
$importService = $this->getContainer()->get('es.import');
$importService->importIndex(
$manager,
$input->getArgument('filename'),
$output,
$options
);
$io->success('Data import completed!');
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$manager = $this->getManager($input->getOption('manager'));
// Initialize options array
$options = [];
if ($input->getOption('gzip')) {
$options['gzip'] = null;
}
$options['bulk-size'] = $input->getOption('bulk-size');
/** @var ImportService $importService */
$importService = $this->getContainer()->get('es.import');
$importService->importIndex(
$manager,
$input->getArgument('filename'),
$output,
$options
);
$io->success('Data import completed!');
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"io",
"=",
"new",
"SymfonyStyle",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"getManager",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'manager'",
")",
")",
";",
"// Initialize options array",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'gzip'",
")",
")",
"{",
"$",
"options",
"[",
"'gzip'",
"]",
"=",
"null",
";",
"}",
"$",
"options",
"[",
"'bulk-size'",
"]",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'bulk-size'",
")",
";",
"/** @var ImportService $importService */",
"$",
"importService",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'es.import'",
")",
";",
"$",
"importService",
"->",
"importIndex",
"(",
"$",
"manager",
",",
"$",
"input",
"->",
"getArgument",
"(",
"'filename'",
")",
",",
"$",
"output",
",",
"$",
"options",
")",
";",
"$",
"io",
"->",
"success",
"(",
"'Data import completed!'",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/IndexImportCommand.php#L61-L83 |
ongr-io/ElasticsearchBundle | Service/ManagerFactory.php | ManagerFactory.createManager | public function createManager($managerName, $connection, $analysis, $managerConfig)
{
$mappings = $this->metadataCollector->getClientMapping($managerConfig['mappings']);
$client = ClientBuilder::create();
$client->setHosts($connection['hosts']);
$client->setTracer($this->tracer);
if ($this->logger && $managerConfig['logger']['enabled']) {
$client->setLogger($this->logger);
}
$indexSettings = [
'index' => $connection['index_name'],
'body' => array_filter(
[
'settings' => array_merge(
$connection['settings'],
[
'analysis' =>
$this->metadataCollector->getClientAnalysis($managerConfig['mappings'], $analysis),
]
),
'mappings' => $mappings,
]
),
];
$this->eventDispatcher &&
$this->eventDispatcher->dispatch(
Events::PRE_MANAGER_CREATE,
new PreCreateManagerEvent($client, $indexSettings)
);
$manager = new Manager(
$managerName,
$managerConfig,
$client->build(),
$indexSettings,
$this->metadataCollector,
$this->converter
);
if (isset($this->stopwatch)) {
$manager->setStopwatch($this->stopwatch);
}
$manager->setCommitMode($managerConfig['commit_mode']);
$manager->setEventDispatcher($this->eventDispatcher);
$manager->setCommitMode($managerConfig['commit_mode']);
$manager->setBulkCommitSize($managerConfig['bulk_size']);
$this->eventDispatcher &&
$this->eventDispatcher->dispatch(Events::POST_MANAGER_CREATE, new PostCreateManagerEvent($manager));
return $manager;
} | php | public function createManager($managerName, $connection, $analysis, $managerConfig)
{
$mappings = $this->metadataCollector->getClientMapping($managerConfig['mappings']);
$client = ClientBuilder::create();
$client->setHosts($connection['hosts']);
$client->setTracer($this->tracer);
if ($this->logger && $managerConfig['logger']['enabled']) {
$client->setLogger($this->logger);
}
$indexSettings = [
'index' => $connection['index_name'],
'body' => array_filter(
[
'settings' => array_merge(
$connection['settings'],
[
'analysis' =>
$this->metadataCollector->getClientAnalysis($managerConfig['mappings'], $analysis),
]
),
'mappings' => $mappings,
]
),
];
$this->eventDispatcher &&
$this->eventDispatcher->dispatch(
Events::PRE_MANAGER_CREATE,
new PreCreateManagerEvent($client, $indexSettings)
);
$manager = new Manager(
$managerName,
$managerConfig,
$client->build(),
$indexSettings,
$this->metadataCollector,
$this->converter
);
if (isset($this->stopwatch)) {
$manager->setStopwatch($this->stopwatch);
}
$manager->setCommitMode($managerConfig['commit_mode']);
$manager->setEventDispatcher($this->eventDispatcher);
$manager->setCommitMode($managerConfig['commit_mode']);
$manager->setBulkCommitSize($managerConfig['bulk_size']);
$this->eventDispatcher &&
$this->eventDispatcher->dispatch(Events::POST_MANAGER_CREATE, new PostCreateManagerEvent($manager));
return $manager;
} | [
"public",
"function",
"createManager",
"(",
"$",
"managerName",
",",
"$",
"connection",
",",
"$",
"analysis",
",",
"$",
"managerConfig",
")",
"{",
"$",
"mappings",
"=",
"$",
"this",
"->",
"metadataCollector",
"->",
"getClientMapping",
"(",
"$",
"managerConfig",
"[",
"'mappings'",
"]",
")",
";",
"$",
"client",
"=",
"ClientBuilder",
"::",
"create",
"(",
")",
";",
"$",
"client",
"->",
"setHosts",
"(",
"$",
"connection",
"[",
"'hosts'",
"]",
")",
";",
"$",
"client",
"->",
"setTracer",
"(",
"$",
"this",
"->",
"tracer",
")",
";",
"if",
"(",
"$",
"this",
"->",
"logger",
"&&",
"$",
"managerConfig",
"[",
"'logger'",
"]",
"[",
"'enabled'",
"]",
")",
"{",
"$",
"client",
"->",
"setLogger",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"$",
"indexSettings",
"=",
"[",
"'index'",
"=>",
"$",
"connection",
"[",
"'index_name'",
"]",
",",
"'body'",
"=>",
"array_filter",
"(",
"[",
"'settings'",
"=>",
"array_merge",
"(",
"$",
"connection",
"[",
"'settings'",
"]",
",",
"[",
"'analysis'",
"=>",
"$",
"this",
"->",
"metadataCollector",
"->",
"getClientAnalysis",
"(",
"$",
"managerConfig",
"[",
"'mappings'",
"]",
",",
"$",
"analysis",
")",
",",
"]",
")",
",",
"'mappings'",
"=>",
"$",
"mappings",
",",
"]",
")",
",",
"]",
";",
"$",
"this",
"->",
"eventDispatcher",
"&&",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"Events",
"::",
"PRE_MANAGER_CREATE",
",",
"new",
"PreCreateManagerEvent",
"(",
"$",
"client",
",",
"$",
"indexSettings",
")",
")",
";",
"$",
"manager",
"=",
"new",
"Manager",
"(",
"$",
"managerName",
",",
"$",
"managerConfig",
",",
"$",
"client",
"->",
"build",
"(",
")",
",",
"$",
"indexSettings",
",",
"$",
"this",
"->",
"metadataCollector",
",",
"$",
"this",
"->",
"converter",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"stopwatch",
")",
")",
"{",
"$",
"manager",
"->",
"setStopwatch",
"(",
"$",
"this",
"->",
"stopwatch",
")",
";",
"}",
"$",
"manager",
"->",
"setCommitMode",
"(",
"$",
"managerConfig",
"[",
"'commit_mode'",
"]",
")",
";",
"$",
"manager",
"->",
"setEventDispatcher",
"(",
"$",
"this",
"->",
"eventDispatcher",
")",
";",
"$",
"manager",
"->",
"setCommitMode",
"(",
"$",
"managerConfig",
"[",
"'commit_mode'",
"]",
")",
";",
"$",
"manager",
"->",
"setBulkCommitSize",
"(",
"$",
"managerConfig",
"[",
"'bulk_size'",
"]",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"&&",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"Events",
"::",
"POST_MANAGER_CREATE",
",",
"new",
"PostCreateManagerEvent",
"(",
"$",
"manager",
")",
")",
";",
"return",
"$",
"manager",
";",
"}"
] | Factory function to create a manager instance.
@param string $managerName Manager name.
@param array $connection Connection configuration.
@param array $analysis Analyzers, filters and tokenizers config.
@param array $managerConfig Manager configuration.
@return Manager | [
"Factory",
"function",
"to",
"create",
"a",
"manager",
"instance",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/ManagerFactory.php#L99-L155 |
ongr-io/ElasticsearchBundle | Profiler/ElasticsearchProfiler.php | ElasticsearchProfiler.collect | public function collect(Request $request, Response $response, \Exception $exception = null)
{
/** @var Logger $logger */
foreach ($this->loggers as $logger) {
foreach ($logger->getHandlers() as $handler) {
if ($handler instanceof CollectionHandler) {
$this->handleRecords($this->getRoute($request), $handler->getRecords());
$handler->clearRecords();
}
}
}
} | php | public function collect(Request $request, Response $response, \Exception $exception = null)
{
/** @var Logger $logger */
foreach ($this->loggers as $logger) {
foreach ($logger->getHandlers() as $handler) {
if ($handler instanceof CollectionHandler) {
$this->handleRecords($this->getRoute($request), $handler->getRecords());
$handler->clearRecords();
}
}
}
} | [
"public",
"function",
"collect",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
",",
"\\",
"Exception",
"$",
"exception",
"=",
"null",
")",
"{",
"/** @var Logger $logger */",
"foreach",
"(",
"$",
"this",
"->",
"loggers",
"as",
"$",
"logger",
")",
"{",
"foreach",
"(",
"$",
"logger",
"->",
"getHandlers",
"(",
")",
"as",
"$",
"handler",
")",
"{",
"if",
"(",
"$",
"handler",
"instanceof",
"CollectionHandler",
")",
"{",
"$",
"this",
"->",
"handleRecords",
"(",
"$",
"this",
"->",
"getRoute",
"(",
"$",
"request",
")",
",",
"$",
"handler",
"->",
"getRecords",
"(",
")",
")",
";",
"$",
"handler",
"->",
"clearRecords",
"(",
")",
";",
"}",
"}",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Profiler/ElasticsearchProfiler.php#L65-L76 |
ongr-io/ElasticsearchBundle | Profiler/ElasticsearchProfiler.php | ElasticsearchProfiler.handleRecords | private function handleRecords($route, $records)
{
$this->count += count($records) / 2;
$queryBody = '';
foreach ($records as $record) {
// First record will never have context.
if (!empty($record['context'])) {
$this->time += $record['context']['duration'];
$this->addQuery($route, $record, $queryBody);
} else {
$position = strpos($record['message'], ' -d');
$queryBody = $position !== false ? substr($record['message'], $position + 3) : '';
}
}
} | php | private function handleRecords($route, $records)
{
$this->count += count($records) / 2;
$queryBody = '';
foreach ($records as $record) {
// First record will never have context.
if (!empty($record['context'])) {
$this->time += $record['context']['duration'];
$this->addQuery($route, $record, $queryBody);
} else {
$position = strpos($record['message'], ' -d');
$queryBody = $position !== false ? substr($record['message'], $position + 3) : '';
}
}
} | [
"private",
"function",
"handleRecords",
"(",
"$",
"route",
",",
"$",
"records",
")",
"{",
"$",
"this",
"->",
"count",
"+=",
"count",
"(",
"$",
"records",
")",
"/",
"2",
";",
"$",
"queryBody",
"=",
"''",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"// First record will never have context.",
"if",
"(",
"!",
"empty",
"(",
"$",
"record",
"[",
"'context'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"time",
"+=",
"$",
"record",
"[",
"'context'",
"]",
"[",
"'duration'",
"]",
";",
"$",
"this",
"->",
"addQuery",
"(",
"$",
"route",
",",
"$",
"record",
",",
"$",
"queryBody",
")",
";",
"}",
"else",
"{",
"$",
"position",
"=",
"strpos",
"(",
"$",
"record",
"[",
"'message'",
"]",
",",
"' -d'",
")",
";",
"$",
"queryBody",
"=",
"$",
"position",
"!==",
"false",
"?",
"substr",
"(",
"$",
"record",
"[",
"'message'",
"]",
",",
"$",
"position",
"+",
"3",
")",
":",
"''",
";",
"}",
"}",
"}"
] | Handles passed records.
@param string $route
@param array $records | [
"Handles",
"passed",
"records",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Profiler/ElasticsearchProfiler.php#L160-L174 |
ongr-io/ElasticsearchBundle | Profiler/ElasticsearchProfiler.php | ElasticsearchProfiler.addQuery | private function addQuery($route, $record, $queryBody)
{
parse_str(parse_url($record['context']['uri'], PHP_URL_QUERY), $httpParameters);
$body = json_decode(trim($queryBody, " '\r\t\n"));
$this->queries[$route][] = array_merge(
[
'body' => $body !== null ? json_encode($body, JSON_PRETTY_PRINT) : '',
'method' => $record['context']['method'],
'httpParameters' => $httpParameters,
'time' => $record['context']['duration'] * 1000,
],
array_diff_key(parse_url($record['context']['uri']), array_flip(['query']))
);
} | php | private function addQuery($route, $record, $queryBody)
{
parse_str(parse_url($record['context']['uri'], PHP_URL_QUERY), $httpParameters);
$body = json_decode(trim($queryBody, " '\r\t\n"));
$this->queries[$route][] = array_merge(
[
'body' => $body !== null ? json_encode($body, JSON_PRETTY_PRINT) : '',
'method' => $record['context']['method'],
'httpParameters' => $httpParameters,
'time' => $record['context']['duration'] * 1000,
],
array_diff_key(parse_url($record['context']['uri']), array_flip(['query']))
);
} | [
"private",
"function",
"addQuery",
"(",
"$",
"route",
",",
"$",
"record",
",",
"$",
"queryBody",
")",
"{",
"parse_str",
"(",
"parse_url",
"(",
"$",
"record",
"[",
"'context'",
"]",
"[",
"'uri'",
"]",
",",
"PHP_URL_QUERY",
")",
",",
"$",
"httpParameters",
")",
";",
"$",
"body",
"=",
"json_decode",
"(",
"trim",
"(",
"$",
"queryBody",
",",
"\" '\\r\\t\\n\"",
")",
")",
";",
"$",
"this",
"->",
"queries",
"[",
"$",
"route",
"]",
"[",
"]",
"=",
"array_merge",
"(",
"[",
"'body'",
"=>",
"$",
"body",
"!==",
"null",
"?",
"json_encode",
"(",
"$",
"body",
",",
"JSON_PRETTY_PRINT",
")",
":",
"''",
",",
"'method'",
"=>",
"$",
"record",
"[",
"'context'",
"]",
"[",
"'method'",
"]",
",",
"'httpParameters'",
"=>",
"$",
"httpParameters",
",",
"'time'",
"=>",
"$",
"record",
"[",
"'context'",
"]",
"[",
"'duration'",
"]",
"*",
"1000",
",",
"]",
",",
"array_diff_key",
"(",
"parse_url",
"(",
"$",
"record",
"[",
"'context'",
"]",
"[",
"'uri'",
"]",
")",
",",
"array_flip",
"(",
"[",
"'query'",
"]",
")",
")",
")",
";",
"}"
] | Adds query to collected data array.
@param string $route
@param array $record
@param string $queryBody | [
"Adds",
"query",
"to",
"collected",
"data",
"array",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Profiler/ElasticsearchProfiler.php#L183-L196 |
ongr-io/ElasticsearchBundle | Profiler/ElasticsearchProfiler.php | ElasticsearchProfiler.getRoute | private function getRoute(Request $request)
{
$route = $request->attributes->get('_route');
return empty($route) ? self::UNDEFINED_ROUTE : $route;
} | php | private function getRoute(Request $request)
{
$route = $request->attributes->get('_route');
return empty($route) ? self::UNDEFINED_ROUTE : $route;
} | [
"private",
"function",
"getRoute",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"route",
"=",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_route'",
")",
";",
"return",
"empty",
"(",
"$",
"route",
")",
"?",
"self",
"::",
"UNDEFINED_ROUTE",
":",
"$",
"route",
";",
"}"
] | Returns route name from request.
@param Request $request
@return string | [
"Returns",
"route",
"name",
"from",
"request",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Profiler/ElasticsearchProfiler.php#L205-L210 |
ongr-io/ElasticsearchBundle | Result/AbstractResultsIterator.php | AbstractResultsIterator.getAggregation | public function getAggregation($name)
{
if (isset($this->aggregations[$name])) {
return $this->aggregations[$name];
}
return null;
} | php | public function getAggregation($name)
{
if (isset($this->aggregations[$name])) {
return $this->aggregations[$name];
}
return null;
} | [
"public",
"function",
"getAggregation",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aggregations",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aggregations",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Returns specific aggregation by name.
@param string $name
@return array | [
"Returns",
"specific",
"aggregation",
"by",
"name",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/AbstractResultsIterator.php#L143-L149 |
ongr-io/ElasticsearchBundle | Result/AbstractResultsIterator.php | AbstractResultsIterator.valid | public function valid()
{
if (!isset($this->documents)) {
return false;
}
$valid = $this->documentExists($this->key());
if ($valid) {
return true;
}
$this->page();
return $this->documentExists($this->key());
} | php | public function valid()
{
if (!isset($this->documents)) {
return false;
}
$valid = $this->documentExists($this->key());
if ($valid) {
return true;
}
$this->page();
return $this->documentExists($this->key());
} | [
"public",
"function",
"valid",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"documents",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"valid",
"=",
"$",
"this",
"->",
"documentExists",
"(",
"$",
"this",
"->",
"key",
"(",
")",
")",
";",
"if",
"(",
"$",
"valid",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"page",
"(",
")",
";",
"return",
"$",
"this",
"->",
"documentExists",
"(",
"$",
"this",
"->",
"key",
"(",
")",
")",
";",
"}"
] | Checks if current position is valid.
@return bool | [
"Checks",
"if",
"current",
"position",
"is",
"valid",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/AbstractResultsIterator.php#L202-L216 |
ongr-io/ElasticsearchBundle | Result/AbstractResultsIterator.php | AbstractResultsIterator.getDocument | protected function getDocument($key)
{
if (!$this->documentExists($key)) {
return null;
}
return $this->convertDocument($this->documents[$key]);
} | php | protected function getDocument($key)
{
if (!$this->documentExists($key)) {
return null;
}
return $this->convertDocument($this->documents[$key]);
} | [
"protected",
"function",
"getDocument",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"documentExists",
"(",
"$",
"key",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"convertDocument",
"(",
"$",
"this",
"->",
"documents",
"[",
"$",
"key",
"]",
")",
";",
"}"
] | Gets document array from the container.
@param mixed $key
@return mixed | [
"Gets",
"document",
"array",
"from",
"the",
"container",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/AbstractResultsIterator.php#L257-L264 |
ongr-io/ElasticsearchBundle | Result/AbstractResultsIterator.php | AbstractResultsIterator.advanceKey | protected function advanceKey()
{
if ($this->isScrollable() && ($this->documents[$this->key()] == end($this->documents))) {
$this->page();
} else {
$this->key++;
}
return $this;
} | php | protected function advanceKey()
{
if ($this->isScrollable() && ($this->documents[$this->key()] == end($this->documents))) {
$this->page();
} else {
$this->key++;
}
return $this;
} | [
"protected",
"function",
"advanceKey",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isScrollable",
"(",
")",
"&&",
"(",
"$",
"this",
"->",
"documents",
"[",
"$",
"this",
"->",
"key",
"(",
")",
"]",
"==",
"end",
"(",
"$",
"this",
"->",
"documents",
")",
")",
")",
"{",
"$",
"this",
"->",
"page",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"key",
"++",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Advances key.
@return $this | [
"Advances",
"key",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/AbstractResultsIterator.php#L283-L292 |
ongr-io/ElasticsearchBundle | Result/AbstractResultsIterator.php | AbstractResultsIterator.page | protected function page()
{
if ($this->key() == $this->count() || !$this->isScrollable()) {
return $this;
}
// $raw = $this->manager->scroll($this->scrollId, $this->scrollDuration, Result::RESULTS_RAW);
$raw = $this->manager->getClient()->scroll(
[
'scroll' => $this->scrollDuration,
'scroll_id' => $this->scrollId,
]
);
$this->rewind();
$this->scrollId = $raw['_scroll_id'];
$this->documents = $raw['hits']['hits'];
return $this;
} | php | protected function page()
{
if ($this->key() == $this->count() || !$this->isScrollable()) {
return $this;
}
// $raw = $this->manager->scroll($this->scrollId, $this->scrollDuration, Result::RESULTS_RAW);
$raw = $this->manager->getClient()->scroll(
[
'scroll' => $this->scrollDuration,
'scroll_id' => $this->scrollId,
]
);
$this->rewind();
$this->scrollId = $raw['_scroll_id'];
$this->documents = $raw['hits']['hits'];
return $this;
} | [
"protected",
"function",
"page",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"key",
"(",
")",
"==",
"$",
"this",
"->",
"count",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"isScrollable",
"(",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"// $raw = $this->manager->scroll($this->scrollId, $this->scrollDuration, Result::RESULTS_RAW);",
"$",
"raw",
"=",
"$",
"this",
"->",
"manager",
"->",
"getClient",
"(",
")",
"->",
"scroll",
"(",
"[",
"'scroll'",
"=>",
"$",
"this",
"->",
"scrollDuration",
",",
"'scroll_id'",
"=>",
"$",
"this",
"->",
"scrollId",
",",
"]",
")",
";",
"$",
"this",
"->",
"rewind",
"(",
")",
";",
"$",
"this",
"->",
"scrollId",
"=",
"$",
"raw",
"[",
"'_scroll_id'",
"]",
";",
"$",
"this",
"->",
"documents",
"=",
"$",
"raw",
"[",
"'hits'",
"]",
"[",
"'hits'",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Advances scan page.
@return $this | [
"Advances",
"scan",
"page",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/AbstractResultsIterator.php#L311-L329 |
ongr-io/ElasticsearchBundle | Result/AbstractResultsIterator.php | AbstractResultsIterator.getDocumentScore | public function getDocumentScore()
{
if (!$this->valid()) {
throw new \LogicException('Document score is available only while iterating over results.');
}
if (!isset($this->documents[$this->key]['_score'])) {
return null;
}
return $this->documents[$this->key]['_score'];
} | php | public function getDocumentScore()
{
if (!$this->valid()) {
throw new \LogicException('Document score is available only while iterating over results.');
}
if (!isset($this->documents[$this->key]['_score'])) {
return null;
}
return $this->documents[$this->key]['_score'];
} | [
"public",
"function",
"getDocumentScore",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"valid",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Document score is available only while iterating over results.'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"documents",
"[",
"$",
"this",
"->",
"key",
"]",
"[",
"'_score'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"documents",
"[",
"$",
"this",
"->",
"key",
"]",
"[",
"'_score'",
"]",
";",
"}"
] | Returns score of current hit.
@return int | [
"Returns",
"score",
"of",
"current",
"hit",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/AbstractResultsIterator.php#L336-L347 |
ongr-io/ElasticsearchBundle | Result/AbstractResultsIterator.php | AbstractResultsIterator.getDocumentSort | public function getDocumentSort()
{
if (!$this->valid()) {
throw new \LogicException('Document sort is available only while iterating over results.');
}
if (!isset($this->documents[$this->key]['sort'])) {
return null;
}
return $this->documents[$this->key]['sort'][0];
} | php | public function getDocumentSort()
{
if (!$this->valid()) {
throw new \LogicException('Document sort is available only while iterating over results.');
}
if (!isset($this->documents[$this->key]['sort'])) {
return null;
}
return $this->documents[$this->key]['sort'][0];
} | [
"public",
"function",
"getDocumentSort",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"valid",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Document sort is available only while iterating over results.'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"documents",
"[",
"$",
"this",
"->",
"key",
"]",
"[",
"'sort'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"documents",
"[",
"$",
"this",
"->",
"key",
"]",
"[",
"'sort'",
"]",
"[",
"0",
"]",
";",
"}"
] | Returns sort of current hit.
@return mixed | [
"Returns",
"sort",
"of",
"current",
"hit",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/AbstractResultsIterator.php#L354-L365 |
ongr-io/ElasticsearchBundle | Mapping/Caser.php | Caser.snake | public static function snake($string)
{
$string = preg_replace('#([A-Z\d]+)([A-Z][a-z])#', '\1_\2', self::camel($string));
$string = preg_replace('#([a-z\d])([A-Z])#', '\1_\2', $string);
return strtolower(strtr($string, '-', '_'));
} | php | public static function snake($string)
{
$string = preg_replace('#([A-Z\d]+)([A-Z][a-z])#', '\1_\2', self::camel($string));
$string = preg_replace('#([a-z\d])([A-Z])#', '\1_\2', $string);
return strtolower(strtr($string, '-', '_'));
} | [
"public",
"static",
"function",
"snake",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"preg_replace",
"(",
"'#([A-Z\\d]+)([A-Z][a-z])#'",
",",
"'\\1_\\2'",
",",
"self",
"::",
"camel",
"(",
"$",
"string",
")",
")",
";",
"$",
"string",
"=",
"preg_replace",
"(",
"'#([a-z\\d])([A-Z])#'",
",",
"'\\1_\\2'",
",",
"$",
"string",
")",
";",
"return",
"strtolower",
"(",
"strtr",
"(",
"$",
"string",
",",
"'-'",
",",
"'_'",
")",
")",
";",
"}"
] | Transforms string to snake case (e.g., result_string).
@param string $string Text to transform.
@return string | [
"Transforms",
"string",
"to",
"snake",
"case",
"(",
"e",
".",
"g",
".",
"result_string",
")",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Mapping/Caser.php#L40-L46 |
ongr-io/ElasticsearchBundle | Result/Aggregation/AggregationValue.php | AggregationValue.getValue | public function getValue($name = 'key')
{
if (!isset($this->rawData[$name])) {
return null;
}
return $this->rawData[$name];
} | php | public function getValue($name = 'key')
{
if (!isset($this->rawData[$name])) {
return null;
}
return $this->rawData[$name];
} | [
"public",
"function",
"getValue",
"(",
"$",
"name",
"=",
"'key'",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"rawData",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"rawData",
"[",
"$",
"name",
"]",
";",
"}"
] | Returns aggregation value by name.
@param string $name
@return array | [
"Returns",
"aggregation",
"value",
"by",
"name",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/Aggregation/AggregationValue.php#L41-L48 |
ongr-io/ElasticsearchBundle | Result/Aggregation/AggregationValue.php | AggregationValue.getBuckets | public function getBuckets()
{
if (!isset($this->rawData['buckets'])) {
return null;
}
$buckets = [];
foreach ($this->rawData['buckets'] as $bucket) {
$buckets[] = new self($bucket);
}
return $buckets;
} | php | public function getBuckets()
{
if (!isset($this->rawData['buckets'])) {
return null;
}
$buckets = [];
foreach ($this->rawData['buckets'] as $bucket) {
$buckets[] = new self($bucket);
}
return $buckets;
} | [
"public",
"function",
"getBuckets",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"rawData",
"[",
"'buckets'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"buckets",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"rawData",
"[",
"'buckets'",
"]",
"as",
"$",
"bucket",
")",
"{",
"$",
"buckets",
"[",
"]",
"=",
"new",
"self",
"(",
"$",
"bucket",
")",
";",
"}",
"return",
"$",
"buckets",
";",
"}"
] | Returns array of bucket values.
@return AggregationValue[]|null | [
"Returns",
"array",
"of",
"bucket",
"values",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/Aggregation/AggregationValue.php#L65-L78 |
ongr-io/ElasticsearchBundle | Result/Aggregation/AggregationValue.php | AggregationValue.getAggregation | public function getAggregation($name)
{
if (!isset($this->rawData[$name])) {
return null;
}
return new self($this->rawData[$name]);
} | php | public function getAggregation($name)
{
if (!isset($this->rawData[$name])) {
return null;
}
return new self($this->rawData[$name]);
} | [
"public",
"function",
"getAggregation",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"rawData",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"this",
"->",
"rawData",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Returns sub-aggregation.
@param string $name
@return AggregationValue|null | [
"Returns",
"sub",
"-",
"aggregation",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/Aggregation/AggregationValue.php#L87-L94 |
ongr-io/ElasticsearchBundle | Result/Aggregation/AggregationValue.php | AggregationValue.find | public function find($path)
{
$name = explode('.', $path, 2);
$aggregation = $this->getAggregation($name[0]);
if ($aggregation === null || !isset($name[1])) {
return $aggregation;
}
return $aggregation->find($name[1]);
} | php | public function find($path)
{
$name = explode('.', $path, 2);
$aggregation = $this->getAggregation($name[0]);
if ($aggregation === null || !isset($name[1])) {
return $aggregation;
}
return $aggregation->find($name[1]);
} | [
"public",
"function",
"find",
"(",
"$",
"path",
")",
"{",
"$",
"name",
"=",
"explode",
"(",
"'.'",
",",
"$",
"path",
",",
"2",
")",
";",
"$",
"aggregation",
"=",
"$",
"this",
"->",
"getAggregation",
"(",
"$",
"name",
"[",
"0",
"]",
")",
";",
"if",
"(",
"$",
"aggregation",
"===",
"null",
"||",
"!",
"isset",
"(",
"$",
"name",
"[",
"1",
"]",
")",
")",
"{",
"return",
"$",
"aggregation",
";",
"}",
"return",
"$",
"aggregation",
"->",
"find",
"(",
"$",
"name",
"[",
"1",
"]",
")",
";",
"}"
] | Applies path method to aggregations.
@param string $path
@return AggregationValue|null | [
"Applies",
"path",
"method",
"to",
"aggregations",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/Aggregation/AggregationValue.php#L103-L113 |
ongr-io/ElasticsearchBundle | Result/Aggregation/AggregationValue.php | AggregationValue.offsetGet | public function offsetGet($offset)
{
if (!isset($this->rawData[$offset])) {
return null;
}
return $this->rawData[$offset];
} | php | public function offsetGet($offset)
{
if (!isset($this->rawData[$offset])) {
return null;
}
return $this->rawData[$offset];
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"rawData",
"[",
"$",
"offset",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"rawData",
"[",
"$",
"offset",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/Aggregation/AggregationValue.php#L126-L133 |
ongr-io/ElasticsearchBundle | Result/Aggregation/AggregationValue.php | AggregationValue.getIterator | public function getIterator()
{
$buckets = $this->getBuckets();
if ($buckets === null) {
throw new \LogicException('Can not iterate over aggregation without buckets!');
}
return new \ArrayIterator($this->getBuckets());
} | php | public function getIterator()
{
$buckets = $this->getBuckets();
if ($buckets === null) {
throw new \LogicException('Can not iterate over aggregation without buckets!');
}
return new \ArrayIterator($this->getBuckets());
} | [
"public",
"function",
"getIterator",
"(",
")",
"{",
"$",
"buckets",
"=",
"$",
"this",
"->",
"getBuckets",
"(",
")",
";",
"if",
"(",
"$",
"buckets",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Can not iterate over aggregation without buckets!'",
")",
";",
"}",
"return",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"this",
"->",
"getBuckets",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/Aggregation/AggregationValue.php#L154-L163 |
ongr-io/ElasticsearchBundle | Result/ArrayIterator.php | ArrayIterator.convertDocument | protected function convertDocument(array $document)
{
if (array_key_exists('_source', $document)) {
return $document['_source'];
} elseif (array_key_exists('fields', $document)) {
return array_map('reset', $document['fields']);
}
return $document;
} | php | protected function convertDocument(array $document)
{
if (array_key_exists('_source', $document)) {
return $document['_source'];
} elseif (array_key_exists('fields', $document)) {
return array_map('reset', $document['fields']);
}
return $document;
} | [
"protected",
"function",
"convertDocument",
"(",
"array",
"$",
"document",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'_source'",
",",
"$",
"document",
")",
")",
"{",
"return",
"$",
"document",
"[",
"'_source'",
"]",
";",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"'fields'",
",",
"$",
"document",
")",
")",
"{",
"return",
"array_map",
"(",
"'reset'",
",",
"$",
"document",
"[",
"'fields'",
"]",
")",
";",
"}",
"return",
"$",
"document",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/ArrayIterator.php#L54-L63 |
ongr-io/ElasticsearchBundle | Service/ImportService.php | ImportService.importIndex | public function importIndex(
Manager $manager,
$filename,
OutputInterface $output,
$options
) {
$reader = $this->getReader($manager, $this->getFilePath($filename), $options);
$progress = new ProgressBar($output, $reader->count());
$progress->setRedrawFrequency(100);
$progress->start();
$bulkSize = $options['bulk-size'];
foreach ($reader as $key => $document) {
$data = $document['_source'];
$data['_id'] = $document['_id'];
if (array_key_exists('fields', $document)) {
$data = array_merge($document['fields'], $data);
}
$manager->bulk('index', $document['_type'], $data);
if (($key + 1) % $bulkSize == 0) {
$manager->commit();
}
$progress->advance();
}
$manager->commit();
$progress->finish();
$output->writeln('');
} | php | public function importIndex(
Manager $manager,
$filename,
OutputInterface $output,
$options
) {
$reader = $this->getReader($manager, $this->getFilePath($filename), $options);
$progress = new ProgressBar($output, $reader->count());
$progress->setRedrawFrequency(100);
$progress->start();
$bulkSize = $options['bulk-size'];
foreach ($reader as $key => $document) {
$data = $document['_source'];
$data['_id'] = $document['_id'];
if (array_key_exists('fields', $document)) {
$data = array_merge($document['fields'], $data);
}
$manager->bulk('index', $document['_type'], $data);
if (($key + 1) % $bulkSize == 0) {
$manager->commit();
}
$progress->advance();
}
$manager->commit();
$progress->finish();
$output->writeln('');
} | [
"public",
"function",
"importIndex",
"(",
"Manager",
"$",
"manager",
",",
"$",
"filename",
",",
"OutputInterface",
"$",
"output",
",",
"$",
"options",
")",
"{",
"$",
"reader",
"=",
"$",
"this",
"->",
"getReader",
"(",
"$",
"manager",
",",
"$",
"this",
"->",
"getFilePath",
"(",
"$",
"filename",
")",
",",
"$",
"options",
")",
";",
"$",
"progress",
"=",
"new",
"ProgressBar",
"(",
"$",
"output",
",",
"$",
"reader",
"->",
"count",
"(",
")",
")",
";",
"$",
"progress",
"->",
"setRedrawFrequency",
"(",
"100",
")",
";",
"$",
"progress",
"->",
"start",
"(",
")",
";",
"$",
"bulkSize",
"=",
"$",
"options",
"[",
"'bulk-size'",
"]",
";",
"foreach",
"(",
"$",
"reader",
"as",
"$",
"key",
"=>",
"$",
"document",
")",
"{",
"$",
"data",
"=",
"$",
"document",
"[",
"'_source'",
"]",
";",
"$",
"data",
"[",
"'_id'",
"]",
"=",
"$",
"document",
"[",
"'_id'",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"'fields'",
",",
"$",
"document",
")",
")",
"{",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"document",
"[",
"'fields'",
"]",
",",
"$",
"data",
")",
";",
"}",
"$",
"manager",
"->",
"bulk",
"(",
"'index'",
",",
"$",
"document",
"[",
"'_type'",
"]",
",",
"$",
"data",
")",
";",
"if",
"(",
"(",
"$",
"key",
"+",
"1",
")",
"%",
"$",
"bulkSize",
"==",
"0",
")",
"{",
"$",
"manager",
"->",
"commit",
"(",
")",
";",
"}",
"$",
"progress",
"->",
"advance",
"(",
")",
";",
"}",
"$",
"manager",
"->",
"commit",
"(",
")",
";",
"$",
"progress",
"->",
"finish",
"(",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"}"
] | Imports Elasticsearch index data.
@param Manager $manager
@param string $filename
@param OutputInterface $output
@param array $options | [
"Imports",
"Elasticsearch",
"index",
"data",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/ImportService.php#L31-L65 |
ongr-io/ElasticsearchBundle | Service/ImportService.php | ImportService.getFilePath | protected function getFilePath($filename)
{
if ($filename{0} == '/' || strstr($filename, ':') !== false) {
return $filename;
}
return realpath(getcwd() . '/' . $filename);
} | php | protected function getFilePath($filename)
{
if ($filename{0} == '/' || strstr($filename, ':') !== false) {
return $filename;
}
return realpath(getcwd() . '/' . $filename);
} | [
"protected",
"function",
"getFilePath",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"$",
"filename",
"{",
"0",
"}",
"==",
"'/'",
"||",
"strstr",
"(",
"$",
"filename",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"filename",
";",
"}",
"return",
"realpath",
"(",
"getcwd",
"(",
")",
".",
"'/'",
".",
"$",
"filename",
")",
";",
"}"
] | Returns a real file path.
@param string $filename
@return string | [
"Returns",
"a",
"real",
"file",
"path",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/ImportService.php#L74-L81 |
ongr-io/ElasticsearchBundle | Command/IndexDropCommand.php | IndexDropCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
if ($input->getOption('force')) {
$this->getManager($input->getOption('manager'))->dropIndex();
$io->text(
sprintf(
'Dropped index for the <comment>`%s`</comment> manager',
$input->getOption('manager')
)
);
} else {
$io->error('ATTENTION:');
$io->text('This action should not be used in the production environment.');
$io->error('Option --force is mandatory to drop type(s).');
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
if ($input->getOption('force')) {
$this->getManager($input->getOption('manager'))->dropIndex();
$io->text(
sprintf(
'Dropped index for the <comment>`%s`</comment> manager',
$input->getOption('manager')
)
);
} else {
$io->error('ATTENTION:');
$io->text('This action should not be used in the production environment.');
$io->error('Option --force is mandatory to drop type(s).');
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"io",
"=",
"new",
"SymfonyStyle",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'force'",
")",
")",
"{",
"$",
"this",
"->",
"getManager",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'manager'",
")",
")",
"->",
"dropIndex",
"(",
")",
";",
"$",
"io",
"->",
"text",
"(",
"sprintf",
"(",
"'Dropped index for the <comment>`%s`</comment> manager'",
",",
"$",
"input",
"->",
"getOption",
"(",
"'manager'",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"io",
"->",
"error",
"(",
"'ATTENTION:'",
")",
";",
"$",
"io",
"->",
"text",
"(",
"'This action should not be used in the production environment.'",
")",
";",
"$",
"io",
"->",
"error",
"(",
"'Option --force is mandatory to drop type(s).'",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/IndexDropCommand.php#L48-L65 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.interact | protected function interact(InputInterface $input, OutputInterface $output)
{
/** @var FormatterHelper $formatter */
$formatter = $this->getHelperSet()->get('formatter');
$this->questionHelper = new QuestionHelper();
$output->writeln(
[
'',
$formatter->formatBlock('Welcome to the Elasticsearch Bundle document generator', 'bg=blue', true),
'',
'This command helps you generate ONGRElasticsearchBundle documents.',
'',
'First, you need to give the document name you want to generate.',
'You must use the shortcut notation like <comment>AcmeDemoBundle:Post</comment>.',
'',
]
);
/** @var Kernel $kernel */
$kernel = $this->getContainer()->get('kernel');
$bundleNames = array_keys($kernel->getBundles());
while (true) {
$document = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion('The Document shortcut name', null, [$this, 'validateDocumentName'], $bundleNames)
);
list($bundle, $document) = $this->parseShortcutNotation($document);
if (in_array(strtolower($document), $this->getReservedKeywords())) {
$output->writeln($this->getException('"%s" is a reserved word.', [$document])->getMessage());
continue;
}
try {
if (!file_exists(
$kernel->getBundle($bundle)->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php'
)) {
break;
}
$output->writeln(
$this->getException('Document "%s:%s" already exists.', [$bundle, $document])->getMessage()
);
} catch (\Exception $e) {
$output->writeln($this->getException('Bundle "%s" does not exist.', [$bundle])->getMessage());
}
}
$output->writeln($this->getOptionsLabel($this->getDocumentAnnotations(), 'Available types'));
$annotation = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
'Document type',
'document',
[$this, 'validateDocumentAnnotation'],
$this->getDocumentAnnotations()
)
);
$this->propertyAnnotations = ['embedded', 'property'];
$documentType = lcfirst($document);
if ($annotation == 'document') {
$this->propertyAnnotations = ['embedded', 'id', 'parentDocument', 'property', 'ttl'];
$documentType = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
"\n" . 'Elasticsearch Document name',
lcfirst($document),
[$this, 'validateFieldName']
)
);
}
$properties = [];
$output->writeln(['', $formatter->formatBlock('New Document Property?', 'bg=blue;fg=white', true)]);
while (true) {
$property = [];
$question = $this->getQuestion(
'Property name [<comment>press <info><return></info> to stop</comment>]',
false
);
if (!$field = $this->questionHelper->ask($input, $output, $question)) {
break;
}
foreach ($properties as $previousProperty) {
if ($previousProperty['field_name'] == $field) {
$output->writeln($this->getException('Duplicate field name "%s"', [$field])->getMessage());
continue(2);
}
}
try {
$this->validateFieldName($field);
} catch (\InvalidArgumentException $e) {
$output->writeln($e->getMessage());
continue;
}
$this->propertyVisibilities = ['private', 'protected', 'public'];
$output->writeln($this->getOptionsLabel($this->propertyVisibilities, 'Available visibilities'));
$property['visibility'] = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
'Property visibility',
'private',
[$this, 'validatePropertyVisibility'],
$this->propertyVisibilities
)
);
$output->writeln($this->getOptionsLabel($this->propertyAnnotations, 'Available annotations'));
$property['annotation'] = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
'Property meta field',
'property',
[$this, 'validatePropertyAnnotation'],
$this->propertyAnnotations
)
);
$property['field_name'] = $property['property_name'] = $field;
switch ($property['annotation']) {
case 'embedded':
$property['property_name'] = $this->askForPropertyName($input, $output, $property['field_name']);
$property['property_class'] = $this->askForPropertyClass($input, $output);
$question = new ConfirmationQuestion("\n<info>Multiple</info> [<comment>no</comment>]: ", false);
$question->setAutocompleterValues(['yes', 'no']);
$property['property_multiple'] = $this->questionHelper->ask($input, $output, $question);
$property['property_options'] = $this->askForPropertyOptions($input, $output);
break;
case 'parentDocument':
if (!$this->isUniqueAnnotation($properties, $property['annotation'])) {
$output->writeln(
$this
->getException('Only one "%s" field can be added', [$property['annotation']])
->getMessage()
);
continue(2);
}
$property['property_class'] = $this->askForPropertyClass($input, $output);
break;
case 'property':
$property['property_name'] = $this->askForPropertyName($input, $output, $property['field_name']);
$output->writeln($this->getOptionsLabel($this->getPropertyTypes(), 'Available types'));
$property['property_type'] = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
'Property type',
'text',
[$this, 'validatePropertyType'],
$this->getPropertyTypes()
)
);
$property['property_options'] = $this->askForPropertyOptions($input, $output);
break;
case 'ttl':
if (!$this->isUniqueAnnotation($properties, $property['annotation'])) {
$output->writeln(
$this
->getException('Only one "%s" field can be added', [$property['annotation']])
->getMessage()
);
continue(2);
}
$property['property_default'] = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion("\n" . 'Default time to live')
);
break;
case 'id':
if (!$this->isUniqueAnnotation($properties, $property['annotation'])) {
$output->writeln(
$this
->getException('Only one "%s" field can be added', [$property['annotation']])
->getMessage()
);
continue(2);
}
break;
}
$properties[] = $property;
$output->writeln(['', $formatter->formatBlock('New Document Property', 'bg=blue;fg=white', true)]);
}
$this->getContainer()->get('es.generate')->generate(
$this->getContainer()->get('kernel')->getBundle($bundle),
$document,
$annotation,
$documentType,
$properties
);
} | php | protected function interact(InputInterface $input, OutputInterface $output)
{
/** @var FormatterHelper $formatter */
$formatter = $this->getHelperSet()->get('formatter');
$this->questionHelper = new QuestionHelper();
$output->writeln(
[
'',
$formatter->formatBlock('Welcome to the Elasticsearch Bundle document generator', 'bg=blue', true),
'',
'This command helps you generate ONGRElasticsearchBundle documents.',
'',
'First, you need to give the document name you want to generate.',
'You must use the shortcut notation like <comment>AcmeDemoBundle:Post</comment>.',
'',
]
);
/** @var Kernel $kernel */
$kernel = $this->getContainer()->get('kernel');
$bundleNames = array_keys($kernel->getBundles());
while (true) {
$document = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion('The Document shortcut name', null, [$this, 'validateDocumentName'], $bundleNames)
);
list($bundle, $document) = $this->parseShortcutNotation($document);
if (in_array(strtolower($document), $this->getReservedKeywords())) {
$output->writeln($this->getException('"%s" is a reserved word.', [$document])->getMessage());
continue;
}
try {
if (!file_exists(
$kernel->getBundle($bundle)->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php'
)) {
break;
}
$output->writeln(
$this->getException('Document "%s:%s" already exists.', [$bundle, $document])->getMessage()
);
} catch (\Exception $e) {
$output->writeln($this->getException('Bundle "%s" does not exist.', [$bundle])->getMessage());
}
}
$output->writeln($this->getOptionsLabel($this->getDocumentAnnotations(), 'Available types'));
$annotation = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
'Document type',
'document',
[$this, 'validateDocumentAnnotation'],
$this->getDocumentAnnotations()
)
);
$this->propertyAnnotations = ['embedded', 'property'];
$documentType = lcfirst($document);
if ($annotation == 'document') {
$this->propertyAnnotations = ['embedded', 'id', 'parentDocument', 'property', 'ttl'];
$documentType = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
"\n" . 'Elasticsearch Document name',
lcfirst($document),
[$this, 'validateFieldName']
)
);
}
$properties = [];
$output->writeln(['', $formatter->formatBlock('New Document Property?', 'bg=blue;fg=white', true)]);
while (true) {
$property = [];
$question = $this->getQuestion(
'Property name [<comment>press <info><return></info> to stop</comment>]',
false
);
if (!$field = $this->questionHelper->ask($input, $output, $question)) {
break;
}
foreach ($properties as $previousProperty) {
if ($previousProperty['field_name'] == $field) {
$output->writeln($this->getException('Duplicate field name "%s"', [$field])->getMessage());
continue(2);
}
}
try {
$this->validateFieldName($field);
} catch (\InvalidArgumentException $e) {
$output->writeln($e->getMessage());
continue;
}
$this->propertyVisibilities = ['private', 'protected', 'public'];
$output->writeln($this->getOptionsLabel($this->propertyVisibilities, 'Available visibilities'));
$property['visibility'] = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
'Property visibility',
'private',
[$this, 'validatePropertyVisibility'],
$this->propertyVisibilities
)
);
$output->writeln($this->getOptionsLabel($this->propertyAnnotations, 'Available annotations'));
$property['annotation'] = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
'Property meta field',
'property',
[$this, 'validatePropertyAnnotation'],
$this->propertyAnnotations
)
);
$property['field_name'] = $property['property_name'] = $field;
switch ($property['annotation']) {
case 'embedded':
$property['property_name'] = $this->askForPropertyName($input, $output, $property['field_name']);
$property['property_class'] = $this->askForPropertyClass($input, $output);
$question = new ConfirmationQuestion("\n<info>Multiple</info> [<comment>no</comment>]: ", false);
$question->setAutocompleterValues(['yes', 'no']);
$property['property_multiple'] = $this->questionHelper->ask($input, $output, $question);
$property['property_options'] = $this->askForPropertyOptions($input, $output);
break;
case 'parentDocument':
if (!$this->isUniqueAnnotation($properties, $property['annotation'])) {
$output->writeln(
$this
->getException('Only one "%s" field can be added', [$property['annotation']])
->getMessage()
);
continue(2);
}
$property['property_class'] = $this->askForPropertyClass($input, $output);
break;
case 'property':
$property['property_name'] = $this->askForPropertyName($input, $output, $property['field_name']);
$output->writeln($this->getOptionsLabel($this->getPropertyTypes(), 'Available types'));
$property['property_type'] = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
'Property type',
'text',
[$this, 'validatePropertyType'],
$this->getPropertyTypes()
)
);
$property['property_options'] = $this->askForPropertyOptions($input, $output);
break;
case 'ttl':
if (!$this->isUniqueAnnotation($properties, $property['annotation'])) {
$output->writeln(
$this
->getException('Only one "%s" field can be added', [$property['annotation']])
->getMessage()
);
continue(2);
}
$property['property_default'] = $this->questionHelper->ask(
$input,
$output,
$this->getQuestion("\n" . 'Default time to live')
);
break;
case 'id':
if (!$this->isUniqueAnnotation($properties, $property['annotation'])) {
$output->writeln(
$this
->getException('Only one "%s" field can be added', [$property['annotation']])
->getMessage()
);
continue(2);
}
break;
}
$properties[] = $property;
$output->writeln(['', $formatter->formatBlock('New Document Property', 'bg=blue;fg=white', true)]);
}
$this->getContainer()->get('es.generate')->generate(
$this->getContainer()->get('kernel')->getBundle($bundle),
$document,
$annotation,
$documentType,
$properties
);
} | [
"protected",
"function",
"interact",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"/** @var FormatterHelper $formatter */",
"$",
"formatter",
"=",
"$",
"this",
"->",
"getHelperSet",
"(",
")",
"->",
"get",
"(",
"'formatter'",
")",
";",
"$",
"this",
"->",
"questionHelper",
"=",
"new",
"QuestionHelper",
"(",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"[",
"''",
",",
"$",
"formatter",
"->",
"formatBlock",
"(",
"'Welcome to the Elasticsearch Bundle document generator'",
",",
"'bg=blue'",
",",
"true",
")",
",",
"''",
",",
"'This command helps you generate ONGRElasticsearchBundle documents.'",
",",
"''",
",",
"'First, you need to give the document name you want to generate.'",
",",
"'You must use the shortcut notation like <comment>AcmeDemoBundle:Post</comment>.'",
",",
"''",
",",
"]",
")",
";",
"/** @var Kernel $kernel */",
"$",
"kernel",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'kernel'",
")",
";",
"$",
"bundleNames",
"=",
"array_keys",
"(",
"$",
"kernel",
"->",
"getBundles",
"(",
")",
")",
";",
"while",
"(",
"true",
")",
"{",
"$",
"document",
"=",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"this",
"->",
"getQuestion",
"(",
"'The Document shortcut name'",
",",
"null",
",",
"[",
"$",
"this",
",",
"'validateDocumentName'",
"]",
",",
"$",
"bundleNames",
")",
")",
";",
"list",
"(",
"$",
"bundle",
",",
"$",
"document",
")",
"=",
"$",
"this",
"->",
"parseShortcutNotation",
"(",
"$",
"document",
")",
";",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"document",
")",
",",
"$",
"this",
"->",
"getReservedKeywords",
"(",
")",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getException",
"(",
"'\"%s\" is a reserved word.'",
",",
"[",
"$",
"document",
"]",
")",
"->",
"getMessage",
"(",
")",
")",
";",
"continue",
";",
"}",
"try",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"kernel",
"->",
"getBundle",
"(",
"$",
"bundle",
")",
"->",
"getPath",
"(",
")",
".",
"'/Document/'",
".",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"document",
")",
".",
"'.php'",
")",
")",
"{",
"break",
";",
"}",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getException",
"(",
"'Document \"%s:%s\" already exists.'",
",",
"[",
"$",
"bundle",
",",
"$",
"document",
"]",
")",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getException",
"(",
"'Bundle \"%s\" does not exist.'",
",",
"[",
"$",
"bundle",
"]",
")",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getOptionsLabel",
"(",
"$",
"this",
"->",
"getDocumentAnnotations",
"(",
")",
",",
"'Available types'",
")",
")",
";",
"$",
"annotation",
"=",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"this",
"->",
"getQuestion",
"(",
"'Document type'",
",",
"'document'",
",",
"[",
"$",
"this",
",",
"'validateDocumentAnnotation'",
"]",
",",
"$",
"this",
"->",
"getDocumentAnnotations",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"propertyAnnotations",
"=",
"[",
"'embedded'",
",",
"'property'",
"]",
";",
"$",
"documentType",
"=",
"lcfirst",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"annotation",
"==",
"'document'",
")",
"{",
"$",
"this",
"->",
"propertyAnnotations",
"=",
"[",
"'embedded'",
",",
"'id'",
",",
"'parentDocument'",
",",
"'property'",
",",
"'ttl'",
"]",
";",
"$",
"documentType",
"=",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"this",
"->",
"getQuestion",
"(",
"\"\\n\"",
".",
"'Elasticsearch Document name'",
",",
"lcfirst",
"(",
"$",
"document",
")",
",",
"[",
"$",
"this",
",",
"'validateFieldName'",
"]",
")",
")",
";",
"}",
"$",
"properties",
"=",
"[",
"]",
";",
"$",
"output",
"->",
"writeln",
"(",
"[",
"''",
",",
"$",
"formatter",
"->",
"formatBlock",
"(",
"'New Document Property?'",
",",
"'bg=blue;fg=white'",
",",
"true",
")",
"]",
")",
";",
"while",
"(",
"true",
")",
"{",
"$",
"property",
"=",
"[",
"]",
";",
"$",
"question",
"=",
"$",
"this",
"->",
"getQuestion",
"(",
"'Property name [<comment>press <info><return></info> to stop</comment>]'",
",",
"false",
")",
";",
"if",
"(",
"!",
"$",
"field",
"=",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"question",
")",
")",
"{",
"break",
";",
"}",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"previousProperty",
")",
"{",
"if",
"(",
"$",
"previousProperty",
"[",
"'field_name'",
"]",
"==",
"$",
"field",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getException",
"(",
"'Duplicate field name \"%s\"'",
",",
"[",
"$",
"field",
"]",
")",
"->",
"getMessage",
"(",
")",
")",
";",
"continue",
"(",
"2",
")",
";",
"}",
"}",
"try",
"{",
"$",
"this",
"->",
"validateFieldName",
"(",
"$",
"field",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"propertyVisibilities",
"=",
"[",
"'private'",
",",
"'protected'",
",",
"'public'",
"]",
";",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getOptionsLabel",
"(",
"$",
"this",
"->",
"propertyVisibilities",
",",
"'Available visibilities'",
")",
")",
";",
"$",
"property",
"[",
"'visibility'",
"]",
"=",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"this",
"->",
"getQuestion",
"(",
"'Property visibility'",
",",
"'private'",
",",
"[",
"$",
"this",
",",
"'validatePropertyVisibility'",
"]",
",",
"$",
"this",
"->",
"propertyVisibilities",
")",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getOptionsLabel",
"(",
"$",
"this",
"->",
"propertyAnnotations",
",",
"'Available annotations'",
")",
")",
";",
"$",
"property",
"[",
"'annotation'",
"]",
"=",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"this",
"->",
"getQuestion",
"(",
"'Property meta field'",
",",
"'property'",
",",
"[",
"$",
"this",
",",
"'validatePropertyAnnotation'",
"]",
",",
"$",
"this",
"->",
"propertyAnnotations",
")",
")",
";",
"$",
"property",
"[",
"'field_name'",
"]",
"=",
"$",
"property",
"[",
"'property_name'",
"]",
"=",
"$",
"field",
";",
"switch",
"(",
"$",
"property",
"[",
"'annotation'",
"]",
")",
"{",
"case",
"'embedded'",
":",
"$",
"property",
"[",
"'property_name'",
"]",
"=",
"$",
"this",
"->",
"askForPropertyName",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"property",
"[",
"'field_name'",
"]",
")",
";",
"$",
"property",
"[",
"'property_class'",
"]",
"=",
"$",
"this",
"->",
"askForPropertyClass",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"$",
"question",
"=",
"new",
"ConfirmationQuestion",
"(",
"\"\\n<info>Multiple</info> [<comment>no</comment>]: \"",
",",
"false",
")",
";",
"$",
"question",
"->",
"setAutocompleterValues",
"(",
"[",
"'yes'",
",",
"'no'",
"]",
")",
";",
"$",
"property",
"[",
"'property_multiple'",
"]",
"=",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"question",
")",
";",
"$",
"property",
"[",
"'property_options'",
"]",
"=",
"$",
"this",
"->",
"askForPropertyOptions",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"break",
";",
"case",
"'parentDocument'",
":",
"if",
"(",
"!",
"$",
"this",
"->",
"isUniqueAnnotation",
"(",
"$",
"properties",
",",
"$",
"property",
"[",
"'annotation'",
"]",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getException",
"(",
"'Only one \"%s\" field can be added'",
",",
"[",
"$",
"property",
"[",
"'annotation'",
"]",
"]",
")",
"->",
"getMessage",
"(",
")",
")",
";",
"continue",
"(",
"2",
")",
";",
"}",
"$",
"property",
"[",
"'property_class'",
"]",
"=",
"$",
"this",
"->",
"askForPropertyClass",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"break",
";",
"case",
"'property'",
":",
"$",
"property",
"[",
"'property_name'",
"]",
"=",
"$",
"this",
"->",
"askForPropertyName",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"property",
"[",
"'field_name'",
"]",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getOptionsLabel",
"(",
"$",
"this",
"->",
"getPropertyTypes",
"(",
")",
",",
"'Available types'",
")",
")",
";",
"$",
"property",
"[",
"'property_type'",
"]",
"=",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"this",
"->",
"getQuestion",
"(",
"'Property type'",
",",
"'text'",
",",
"[",
"$",
"this",
",",
"'validatePropertyType'",
"]",
",",
"$",
"this",
"->",
"getPropertyTypes",
"(",
")",
")",
")",
";",
"$",
"property",
"[",
"'property_options'",
"]",
"=",
"$",
"this",
"->",
"askForPropertyOptions",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"break",
";",
"case",
"'ttl'",
":",
"if",
"(",
"!",
"$",
"this",
"->",
"isUniqueAnnotation",
"(",
"$",
"properties",
",",
"$",
"property",
"[",
"'annotation'",
"]",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getException",
"(",
"'Only one \"%s\" field can be added'",
",",
"[",
"$",
"property",
"[",
"'annotation'",
"]",
"]",
")",
"->",
"getMessage",
"(",
")",
")",
";",
"continue",
"(",
"2",
")",
";",
"}",
"$",
"property",
"[",
"'property_default'",
"]",
"=",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"this",
"->",
"getQuestion",
"(",
"\"\\n\"",
".",
"'Default time to live'",
")",
")",
";",
"break",
";",
"case",
"'id'",
":",
"if",
"(",
"!",
"$",
"this",
"->",
"isUniqueAnnotation",
"(",
"$",
"properties",
",",
"$",
"property",
"[",
"'annotation'",
"]",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getException",
"(",
"'Only one \"%s\" field can be added'",
",",
"[",
"$",
"property",
"[",
"'annotation'",
"]",
"]",
")",
"->",
"getMessage",
"(",
")",
")",
";",
"continue",
"(",
"2",
")",
";",
"}",
"break",
";",
"}",
"$",
"properties",
"[",
"]",
"=",
"$",
"property",
";",
"$",
"output",
"->",
"writeln",
"(",
"[",
"''",
",",
"$",
"formatter",
"->",
"formatBlock",
"(",
"'New Document Property'",
",",
"'bg=blue;fg=white'",
",",
"true",
")",
"]",
")",
";",
"}",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'es.generate'",
")",
"->",
"generate",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'kernel'",
")",
"->",
"getBundle",
"(",
"$",
"bundle",
")",
",",
"$",
"document",
",",
"$",
"annotation",
",",
"$",
"documentType",
",",
"$",
"properties",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L67-L279 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.isUniqueAnnotation | private function isUniqueAnnotation($properties, $annotation)
{
foreach ($properties as $property) {
if ($property['annotation'] == $annotation) {
return false;
}
}
return true;
} | php | private function isUniqueAnnotation($properties, $annotation)
{
foreach ($properties as $property) {
if ($property['annotation'] == $annotation) {
return false;
}
}
return true;
} | [
"private",
"function",
"isUniqueAnnotation",
"(",
"$",
"properties",
",",
"$",
"annotation",
")",
"{",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"property",
"[",
"'annotation'",
"]",
"==",
"$",
"annotation",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | @param array $properties
@param string $annotation
@return string | [
"@param",
"array",
"$properties",
"@param",
"string",
"$annotation"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L287-L296 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.askForPropertyName | private function askForPropertyName(InputInterface $input, OutputInterface $output, $default = null)
{
return $this->questionHelper->ask(
$input,
$output,
$this->getQuestion("\n" . 'Property name in Elasticsearch', $default, [$this, 'validateFieldName'])
);
} | php | private function askForPropertyName(InputInterface $input, OutputInterface $output, $default = null)
{
return $this->questionHelper->ask(
$input,
$output,
$this->getQuestion("\n" . 'Property name in Elasticsearch', $default, [$this, 'validateFieldName'])
);
} | [
"private",
"function",
"askForPropertyName",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"$",
"default",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"this",
"->",
"getQuestion",
"(",
"\"\\n\"",
".",
"'Property name in Elasticsearch'",
",",
"$",
"default",
",",
"[",
"$",
"this",
",",
"'validateFieldName'",
"]",
")",
")",
";",
"}"
] | Asks for property name
@param InputInterface $input
@param OutputInterface $output
@param string $default
@return string | [
"Asks",
"for",
"property",
"name"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L307-L314 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.askForPropertyOptions | private function askForPropertyOptions(InputInterface $input, OutputInterface $output)
{
$output->writeln(
"\n"
. '<info>Enter property options, for example <comment>"index"="not_analyzed"</comment>'
. ' allows mapper to index this field, so it is searchable, but value will be not analyzed.</info>'
);
return $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
'Property options [<comment>press <info><return></info> to stop</comment>]',
false,
null,
['"index"="not_analyzed"', '"analyzer"="standard"']
)
);
} | php | private function askForPropertyOptions(InputInterface $input, OutputInterface $output)
{
$output->writeln(
"\n"
. '<info>Enter property options, for example <comment>"index"="not_analyzed"</comment>'
. ' allows mapper to index this field, so it is searchable, but value will be not analyzed.</info>'
);
return $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
'Property options [<comment>press <info><return></info> to stop</comment>]',
false,
null,
['"index"="not_analyzed"', '"analyzer"="standard"']
)
);
} | [
"private",
"function",
"askForPropertyOptions",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"\"\\n\"",
".",
"'<info>Enter property options, for example <comment>\"index\"=\"not_analyzed\"</comment>'",
".",
"' allows mapper to index this field, so it is searchable, but value will be not analyzed.</info>'",
")",
";",
"return",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"this",
"->",
"getQuestion",
"(",
"'Property options [<comment>press <info><return></info> to stop</comment>]'",
",",
"false",
",",
"null",
",",
"[",
"'\"index\"=\"not_analyzed\"'",
",",
"'\"analyzer\"=\"standard\"'",
"]",
")",
")",
";",
"}"
] | Asks for property options
@param InputInterface $input
@param OutputInterface $output
@return string | [
"Asks",
"for",
"property",
"options"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L324-L342 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.askForPropertyClass | private function askForPropertyClass(InputInterface $input, OutputInterface $output)
{
return $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
"\n" . 'Property class',
null,
[$this, 'validatePropertyClass'],
array_merge($this->getDocumentClasses(), array_keys($this->getContainer()->get('kernel')->getBundles()))
)
);
} | php | private function askForPropertyClass(InputInterface $input, OutputInterface $output)
{
return $this->questionHelper->ask(
$input,
$output,
$this->getQuestion(
"\n" . 'Property class',
null,
[$this, 'validatePropertyClass'],
array_merge($this->getDocumentClasses(), array_keys($this->getContainer()->get('kernel')->getBundles()))
)
);
} | [
"private",
"function",
"askForPropertyClass",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"return",
"$",
"this",
"->",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"this",
"->",
"getQuestion",
"(",
"\"\\n\"",
".",
"'Property class'",
",",
"null",
",",
"[",
"$",
"this",
",",
"'validatePropertyClass'",
"]",
",",
"array_merge",
"(",
"$",
"this",
"->",
"getDocumentClasses",
"(",
")",
",",
"array_keys",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'kernel'",
")",
"->",
"getBundles",
"(",
")",
")",
")",
")",
")",
";",
"}"
] | Asks for property class
@param InputInterface $input
@param OutputInterface $output
@return string | [
"Asks",
"for",
"property",
"class"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L352-L364 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.getDocumentClasses | private function getDocumentClasses()
{
/** @var MetadataCollector $metadataCollector */
$metadataCollector = $this->getContainer()->get('es.metadata_collector');
$classes = [];
foreach ($this->getContainer()->getParameter('es.managers') as $manager) {
$documents = $metadataCollector->getMappings($manager['mappings']);
foreach ($documents as $document) {
$classes[] = sprintf('%s:%s', $document['bundle'], $document['class']);
}
}
return $classes;
} | php | private function getDocumentClasses()
{
/** @var MetadataCollector $metadataCollector */
$metadataCollector = $this->getContainer()->get('es.metadata_collector');
$classes = [];
foreach ($this->getContainer()->getParameter('es.managers') as $manager) {
$documents = $metadataCollector->getMappings($manager['mappings']);
foreach ($documents as $document) {
$classes[] = sprintf('%s:%s', $document['bundle'], $document['class']);
}
}
return $classes;
} | [
"private",
"function",
"getDocumentClasses",
"(",
")",
"{",
"/** @var MetadataCollector $metadataCollector */",
"$",
"metadataCollector",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'es.metadata_collector'",
")",
";",
"$",
"classes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"getParameter",
"(",
"'es.managers'",
")",
"as",
"$",
"manager",
")",
"{",
"$",
"documents",
"=",
"$",
"metadataCollector",
"->",
"getMappings",
"(",
"$",
"manager",
"[",
"'mappings'",
"]",
")",
";",
"foreach",
"(",
"$",
"documents",
"as",
"$",
"document",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"sprintf",
"(",
"'%s:%s'",
",",
"$",
"document",
"[",
"'bundle'",
"]",
",",
"$",
"document",
"[",
"'class'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"classes",
";",
"}"
] | Returns available document classes
@return array | [
"Returns",
"available",
"document",
"classes"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L371-L385 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.parseShortcutNotation | private function parseShortcutNotation($shortcut)
{
$shortcut = str_replace('/', '\\', $shortcut);
if (false === $pos = strpos($shortcut, ':')) {
throw $this->getException(
'The document name isn\'t valid ("%s" given, expecting something like AcmeBundle:Post)',
[$shortcut]
);
}
return [substr($shortcut, 0, $pos), substr($shortcut, $pos + 1)];
} | php | private function parseShortcutNotation($shortcut)
{
$shortcut = str_replace('/', '\\', $shortcut);
if (false === $pos = strpos($shortcut, ':')) {
throw $this->getException(
'The document name isn\'t valid ("%s" given, expecting something like AcmeBundle:Post)',
[$shortcut]
);
}
return [substr($shortcut, 0, $pos), substr($shortcut, $pos + 1)];
} | [
"private",
"function",
"parseShortcutNotation",
"(",
"$",
"shortcut",
")",
"{",
"$",
"shortcut",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"shortcut",
")",
";",
"if",
"(",
"false",
"===",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"shortcut",
",",
"':'",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"getException",
"(",
"'The document name isn\\'t valid (\"%s\" given, expecting something like AcmeBundle:Post)'",
",",
"[",
"$",
"shortcut",
"]",
")",
";",
"}",
"return",
"[",
"substr",
"(",
"$",
"shortcut",
",",
"0",
",",
"$",
"pos",
")",
",",
"substr",
"(",
"$",
"shortcut",
",",
"$",
"pos",
"+",
"1",
")",
"]",
";",
"}"
] | Parses shortcut notation
@param string $shortcut
@return string[]
@throws \InvalidArgumentException | [
"Parses",
"shortcut",
"notation"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L395-L407 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.validatePropertyClass | public function validatePropertyClass($input)
{
list($bundle, $document) = $this->parseShortcutNotation($input);
try {
$bundlePath = $this->getContainer()->get('kernel')->getBundle($bundle)->getPath();
} catch (\Exception $e) {
throw $this->getException('Bundle "%s" does not exist.', [$bundle]);
}
if (!file_exists($bundlePath . '/Document/' . str_replace('\\', '/', $document) . '.php')) {
throw $this->getException('Document "%s:%s" does not exist.', [$bundle, $document]);
}
return $input;
} | php | public function validatePropertyClass($input)
{
list($bundle, $document) = $this->parseShortcutNotation($input);
try {
$bundlePath = $this->getContainer()->get('kernel')->getBundle($bundle)->getPath();
} catch (\Exception $e) {
throw $this->getException('Bundle "%s" does not exist.', [$bundle]);
}
if (!file_exists($bundlePath . '/Document/' . str_replace('\\', '/', $document) . '.php')) {
throw $this->getException('Document "%s:%s" does not exist.', [$bundle, $document]);
}
return $input;
} | [
"public",
"function",
"validatePropertyClass",
"(",
"$",
"input",
")",
"{",
"list",
"(",
"$",
"bundle",
",",
"$",
"document",
")",
"=",
"$",
"this",
"->",
"parseShortcutNotation",
"(",
"$",
"input",
")",
";",
"try",
"{",
"$",
"bundlePath",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'kernel'",
")",
"->",
"getBundle",
"(",
"$",
"bundle",
")",
"->",
"getPath",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"this",
"->",
"getException",
"(",
"'Bundle \"%s\" does not exist.'",
",",
"[",
"$",
"bundle",
"]",
")",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"bundlePath",
".",
"'/Document/'",
".",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"document",
")",
".",
"'.php'",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"getException",
"(",
"'Document \"%s:%s\" does not exist.'",
",",
"[",
"$",
"bundle",
",",
"$",
"document",
"]",
")",
";",
"}",
"return",
"$",
"input",
";",
"}"
] | Validates property class
@param string $input
@return string
@throws \InvalidArgumentException | [
"Validates",
"property",
"class"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L417-L432 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.validateFieldName | public function validateFieldName($field)
{
if (!$field || $field != lcfirst(preg_replace('/[^a-zA-Z]+/', '', $field))) {
throw $this->getException(
'The parameter isn\'t valid ("%s" given, expecting camelcase separated words)',
[$field]
);
}
if (in_array(strtolower($field), $this->getReservedKeywords())) {
throw $this->getException('"%s" is a reserved word.', [$field]);
}
return $field;
} | php | public function validateFieldName($field)
{
if (!$field || $field != lcfirst(preg_replace('/[^a-zA-Z]+/', '', $field))) {
throw $this->getException(
'The parameter isn\'t valid ("%s" given, expecting camelcase separated words)',
[$field]
);
}
if (in_array(strtolower($field), $this->getReservedKeywords())) {
throw $this->getException('"%s" is a reserved word.', [$field]);
}
return $field;
} | [
"public",
"function",
"validateFieldName",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"$",
"field",
"||",
"$",
"field",
"!=",
"lcfirst",
"(",
"preg_replace",
"(",
"'/[^a-zA-Z]+/'",
",",
"''",
",",
"$",
"field",
")",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"getException",
"(",
"'The parameter isn\\'t valid (\"%s\" given, expecting camelcase separated words)'",
",",
"[",
"$",
"field",
"]",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"field",
")",
",",
"$",
"this",
"->",
"getReservedKeywords",
"(",
")",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"getException",
"(",
"'\"%s\" is a reserved word.'",
",",
"[",
"$",
"field",
"]",
")",
";",
"}",
"return",
"$",
"field",
";",
"}"
] | Validates field name
@param string $field
@return string
@throws \InvalidArgumentException | [
"Validates",
"field",
"name"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L462-L476 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.validatePropertyType | public function validatePropertyType($type)
{
if (!in_array($type, $this->getPropertyTypes())) {
throw $this->getException(
'The property type isn\'t valid ("%s" given, expecting one of following: %s)',
[$type, implode(', ', $this->getPropertyTypes())]
);
}
return $type;
} | php | public function validatePropertyType($type)
{
if (!in_array($type, $this->getPropertyTypes())) {
throw $this->getException(
'The property type isn\'t valid ("%s" given, expecting one of following: %s)',
[$type, implode(', ', $this->getPropertyTypes())]
);
}
return $type;
} | [
"public",
"function",
"validatePropertyType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"getPropertyTypes",
"(",
")",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"getException",
"(",
"'The property type isn\\'t valid (\"%s\" given, expecting one of following: %s)'",
",",
"[",
"$",
"type",
",",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"getPropertyTypes",
"(",
")",
")",
"]",
")",
";",
"}",
"return",
"$",
"type",
";",
"}"
] | Validates property type
@param string $type
@return string
@throws \InvalidArgumentException | [
"Validates",
"property",
"type"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L486-L496 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.validateDocumentAnnotation | public function validateDocumentAnnotation($annotation)
{
if (!in_array($annotation, $this->getDocumentAnnotations())) {
throw $this->getException(
'The document annotation isn\'t valid ("%s" given, expecting one of following: %s)',
[$annotation, implode(', ', $this->getDocumentAnnotations())]
);
}
return $annotation;
} | php | public function validateDocumentAnnotation($annotation)
{
if (!in_array($annotation, $this->getDocumentAnnotations())) {
throw $this->getException(
'The document annotation isn\'t valid ("%s" given, expecting one of following: %s)',
[$annotation, implode(', ', $this->getDocumentAnnotations())]
);
}
return $annotation;
} | [
"public",
"function",
"validateDocumentAnnotation",
"(",
"$",
"annotation",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"annotation",
",",
"$",
"this",
"->",
"getDocumentAnnotations",
"(",
")",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"getException",
"(",
"'The document annotation isn\\'t valid (\"%s\" given, expecting one of following: %s)'",
",",
"[",
"$",
"annotation",
",",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"getDocumentAnnotations",
"(",
")",
")",
"]",
")",
";",
"}",
"return",
"$",
"annotation",
";",
"}"
] | Validates document annotation
@param string $annotation
@return string
@throws \InvalidArgumentException | [
"Validates",
"document",
"annotation"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L506-L516 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.validatePropertyAnnotation | public function validatePropertyAnnotation($annotation)
{
if (!in_array($annotation, $this->propertyAnnotations)) {
throw $this->getException(
'The property annotation isn\'t valid ("%s" given, expecting one of following: %s)',
[$annotation, implode(', ', $this->propertyAnnotations)]
);
}
return $annotation;
} | php | public function validatePropertyAnnotation($annotation)
{
if (!in_array($annotation, $this->propertyAnnotations)) {
throw $this->getException(
'The property annotation isn\'t valid ("%s" given, expecting one of following: %s)',
[$annotation, implode(', ', $this->propertyAnnotations)]
);
}
return $annotation;
} | [
"public",
"function",
"validatePropertyAnnotation",
"(",
"$",
"annotation",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"annotation",
",",
"$",
"this",
"->",
"propertyAnnotations",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"getException",
"(",
"'The property annotation isn\\'t valid (\"%s\" given, expecting one of following: %s)'",
",",
"[",
"$",
"annotation",
",",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"propertyAnnotations",
")",
"]",
")",
";",
"}",
"return",
"$",
"annotation",
";",
"}"
] | Validates property annotation
@param string $annotation
@return string
@throws \InvalidArgumentException | [
"Validates",
"property",
"annotation"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L526-L536 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.validatePropertyVisibility | public function validatePropertyVisibility($visibility)
{
if (!in_array($visibility, $this->propertyVisibilities)) {
throw $this->getException(
'The property visibility isn\'t valid ("%s" given, expecting one of following: %s)',
[$visibility, implode(', ', $this->propertyVisibilities)]
);
}
return $visibility;
} | php | public function validatePropertyVisibility($visibility)
{
if (!in_array($visibility, $this->propertyVisibilities)) {
throw $this->getException(
'The property visibility isn\'t valid ("%s" given, expecting one of following: %s)',
[$visibility, implode(', ', $this->propertyVisibilities)]
);
}
return $visibility;
} | [
"public",
"function",
"validatePropertyVisibility",
"(",
"$",
"visibility",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"visibility",
",",
"$",
"this",
"->",
"propertyVisibilities",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"getException",
"(",
"'The property visibility isn\\'t valid (\"%s\" given, expecting one of following: %s)'",
",",
"[",
"$",
"visibility",
",",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"propertyVisibilities",
")",
"]",
")",
";",
"}",
"return",
"$",
"visibility",
";",
"}"
] | Validates property visibility
@param string $visibility
@return string
@throws \InvalidArgumentException When the visibility is not found in the list of allowed ones. | [
"Validates",
"property",
"visibility"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L546-L556 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.getQuestion | private function getQuestion($question, $default = null, callable $validator = null, array $values = null)
{
$question = new Question(
sprintf('<info>%s</info>%s: ', $question, $default ? sprintf(' [<comment>%s</comment>]', $default) : ''),
$default
);
$question
->setValidator($validator)
->setAutocompleterValues($values);
return $question;
} | php | private function getQuestion($question, $default = null, callable $validator = null, array $values = null)
{
$question = new Question(
sprintf('<info>%s</info>%s: ', $question, $default ? sprintf(' [<comment>%s</comment>]', $default) : ''),
$default
);
$question
->setValidator($validator)
->setAutocompleterValues($values);
return $question;
} | [
"private",
"function",
"getQuestion",
"(",
"$",
"question",
",",
"$",
"default",
"=",
"null",
",",
"callable",
"$",
"validator",
"=",
"null",
",",
"array",
"$",
"values",
"=",
"null",
")",
"{",
"$",
"question",
"=",
"new",
"Question",
"(",
"sprintf",
"(",
"'<info>%s</info>%s: '",
",",
"$",
"question",
",",
"$",
"default",
"?",
"sprintf",
"(",
"' [<comment>%s</comment>]'",
",",
"$",
"default",
")",
":",
"''",
")",
",",
"$",
"default",
")",
";",
"$",
"question",
"->",
"setValidator",
"(",
"$",
"validator",
")",
"->",
"setAutocompleterValues",
"(",
"$",
"values",
")",
";",
"return",
"$",
"question",
";",
"}"
] | Returns formatted question
@param string $question
@param mixed $default
@param callable|null $validator
@param array|null $values
@return Question | [
"Returns",
"formatted",
"question"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L568-L580 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.getOptionsLabel | private function getOptionsLabel(array $options, $suffix)
{
$label = sprintf('<info>%s:</info> ', $suffix);
foreach ($options as &$option) {
$option = sprintf('<comment>%s</comment>', $option);
}
return ['', $label . implode(', ', $options) . '.'];
} | php | private function getOptionsLabel(array $options, $suffix)
{
$label = sprintf('<info>%s:</info> ', $suffix);
foreach ($options as &$option) {
$option = sprintf('<comment>%s</comment>', $option);
}
return ['', $label . implode(', ', $options) . '.'];
} | [
"private",
"function",
"getOptionsLabel",
"(",
"array",
"$",
"options",
",",
"$",
"suffix",
")",
"{",
"$",
"label",
"=",
"sprintf",
"(",
"'<info>%s:</info> '",
",",
"$",
"suffix",
")",
";",
"foreach",
"(",
"$",
"options",
"as",
"&",
"$",
"option",
")",
"{",
"$",
"option",
"=",
"sprintf",
"(",
"'<comment>%s</comment>'",
",",
"$",
"option",
")",
";",
"}",
"return",
"[",
"''",
",",
"$",
"label",
".",
"implode",
"(",
"', '",
",",
"$",
"options",
")",
".",
"'.'",
"]",
";",
"}"
] | Returns options label
@param array $options
@param string $suffix
@return string[] | [
"Returns",
"options",
"label"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L590-L599 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.getException | private function getException($format, $args = [])
{
/** @var FormatterHelper $formatter */
$formatter = $this->getHelperSet()->get('formatter');
return new \InvalidArgumentException($formatter->formatBlock(vsprintf($format, $args), 'bg=red', true));
} | php | private function getException($format, $args = [])
{
/** @var FormatterHelper $formatter */
$formatter = $this->getHelperSet()->get('formatter');
return new \InvalidArgumentException($formatter->formatBlock(vsprintf($format, $args), 'bg=red', true));
} | [
"private",
"function",
"getException",
"(",
"$",
"format",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"/** @var FormatterHelper $formatter */",
"$",
"formatter",
"=",
"$",
"this",
"->",
"getHelperSet",
"(",
")",
"->",
"get",
"(",
"'formatter'",
")",
";",
"return",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"formatter",
"->",
"formatBlock",
"(",
"vsprintf",
"(",
"$",
"format",
",",
"$",
"args",
")",
",",
"'bg=red'",
",",
"true",
")",
")",
";",
"}"
] | Returns formatted exception
@param string $format
@param array $args
@return \InvalidArgumentException | [
"Returns",
"formatted",
"exception"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L609-L614 |
ongr-io/ElasticsearchBundle | Command/DocumentGenerateCommand.php | DocumentGenerateCommand.getPropertyTypes | private function getPropertyTypes()
{
$reflection = new \ReflectionClass('ONGR\ElasticsearchBundle\Annotation\Property');
return $this
->getContainer()
->get('es.annotations.cached_reader')
->getPropertyAnnotation($reflection->getProperty('type'), 'Doctrine\Common\Annotations\Annotation\Enum')
->value;
} | php | private function getPropertyTypes()
{
$reflection = new \ReflectionClass('ONGR\ElasticsearchBundle\Annotation\Property');
return $this
->getContainer()
->get('es.annotations.cached_reader')
->getPropertyAnnotation($reflection->getProperty('type'), 'Doctrine\Common\Annotations\Annotation\Enum')
->value;
} | [
"private",
"function",
"getPropertyTypes",
"(",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"'ONGR\\ElasticsearchBundle\\Annotation\\Property'",
")",
";",
"return",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'es.annotations.cached_reader'",
")",
"->",
"getPropertyAnnotation",
"(",
"$",
"reflection",
"->",
"getProperty",
"(",
"'type'",
")",
",",
"'Doctrine\\Common\\Annotations\\Annotation\\Enum'",
")",
"->",
"value",
";",
"}"
] | Returns available property types
@return array | [
"Returns",
"available",
"property",
"types"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/DocumentGenerateCommand.php#L621-L630 |
ongr-io/ElasticsearchBundle | Mapping/DocumentFinder.php | DocumentFinder.getNamespace | public function getNamespace($namespace, $documentsDirectory = null)
{
if (!$documentsDirectory) {
$documentsDirectory = $this->documentDir;
}
if (strpos($namespace, ':') !== false) {
list($bundle, $document) = explode(':', $namespace);
$bundle = $this->getBundleClass($bundle);
// If bundle has a sub-namespace it needs to be replaced
if (strpos($documentsDirectory, '\\')) {
$bundleSubNamespace = substr(
$bundle,
$start = strpos($bundle, '\\') + 1,
strrpos($bundle, '\\') - $start + 1
);
$documentsDirectory = str_replace(
$bundleSubNamespace,
'',
$documentsDirectory
);
}
$namespace = substr($bundle, 0, strrpos($bundle, '\\')) . '\\' .
$documentsDirectory . '\\' . $document;
}
return $namespace;
} | php | public function getNamespace($namespace, $documentsDirectory = null)
{
if (!$documentsDirectory) {
$documentsDirectory = $this->documentDir;
}
if (strpos($namespace, ':') !== false) {
list($bundle, $document) = explode(':', $namespace);
$bundle = $this->getBundleClass($bundle);
// If bundle has a sub-namespace it needs to be replaced
if (strpos($documentsDirectory, '\\')) {
$bundleSubNamespace = substr(
$bundle,
$start = strpos($bundle, '\\') + 1,
strrpos($bundle, '\\') - $start + 1
);
$documentsDirectory = str_replace(
$bundleSubNamespace,
'',
$documentsDirectory
);
}
$namespace = substr($bundle, 0, strrpos($bundle, '\\')) . '\\' .
$documentsDirectory . '\\' . $document;
}
return $namespace;
} | [
"public",
"function",
"getNamespace",
"(",
"$",
"namespace",
",",
"$",
"documentsDirectory",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"documentsDirectory",
")",
"{",
"$",
"documentsDirectory",
"=",
"$",
"this",
"->",
"documentDir",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"namespace",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"bundle",
",",
"$",
"document",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"namespace",
")",
";",
"$",
"bundle",
"=",
"$",
"this",
"->",
"getBundleClass",
"(",
"$",
"bundle",
")",
";",
"// If bundle has a sub-namespace it needs to be replaced",
"if",
"(",
"strpos",
"(",
"$",
"documentsDirectory",
",",
"'\\\\'",
")",
")",
"{",
"$",
"bundleSubNamespace",
"=",
"substr",
"(",
"$",
"bundle",
",",
"$",
"start",
"=",
"strpos",
"(",
"$",
"bundle",
",",
"'\\\\'",
")",
"+",
"1",
",",
"strrpos",
"(",
"$",
"bundle",
",",
"'\\\\'",
")",
"-",
"$",
"start",
"+",
"1",
")",
";",
"$",
"documentsDirectory",
"=",
"str_replace",
"(",
"$",
"bundleSubNamespace",
",",
"''",
",",
"$",
"documentsDirectory",
")",
";",
"}",
"$",
"namespace",
"=",
"substr",
"(",
"$",
"bundle",
",",
"0",
",",
"strrpos",
"(",
"$",
"bundle",
",",
"'\\\\'",
")",
")",
".",
"'\\\\'",
".",
"$",
"documentsDirectory",
".",
"'\\\\'",
".",
"$",
"document",
";",
"}",
"return",
"$",
"namespace",
";",
"}"
] | Formats namespace from short syntax.
@param string $namespace
@param string $documentsDirectory Directory name where documents are stored in the bundle.
@return string | [
"Formats",
"namespace",
"from",
"short",
"syntax",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Mapping/DocumentFinder.php#L64-L94 |
ongr-io/ElasticsearchBundle | Mapping/DocumentFinder.php | DocumentFinder.getBundleClass | public function getBundleClass($name)
{
if (array_key_exists($name, $this->bundles)) {
return $this->bundles[$name];
}
throw new \LogicException(sprintf('Bundle \'%s\' does not exist.', $name));
} | php | public function getBundleClass($name)
{
if (array_key_exists($name, $this->bundles)) {
return $this->bundles[$name];
}
throw new \LogicException(sprintf('Bundle \'%s\' does not exist.', $name));
} | [
"public",
"function",
"getBundleClass",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"bundles",
")",
")",
"{",
"return",
"$",
"this",
"->",
"bundles",
"[",
"$",
"name",
"]",
";",
"}",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'Bundle \\'%s\\' does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}"
] | Returns bundle class namespace else throws an exception.
@param string $name
@return string
@throws \LogicException | [
"Returns",
"bundle",
"class",
"namespace",
"else",
"throws",
"an",
"exception",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Mapping/DocumentFinder.php#L105-L112 |
ongr-io/ElasticsearchBundle | Mapping/DocumentFinder.php | DocumentFinder.getBundleDocumentClasses | public function getBundleDocumentClasses($bundle, $documentsDirectory = null)
{
if (!$documentsDirectory) {
$documentsDirectory = $this->documentDir;
}
$bundleReflection = new \ReflectionClass($this->getBundleClass($bundle));
$documentsDirectory = DIRECTORY_SEPARATOR . str_replace('\\', '/', $documentsDirectory) . DIRECTORY_SEPARATOR;
$directory = dirname($bundleReflection->getFileName()) . $documentsDirectory;
if (!is_dir($directory)) {
return [];
}
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory));
$files = new \RegexIterator($iterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH);
$documents = [];
foreach ($files as $file => $v) {
$documents[] = str_replace(
DIRECTORY_SEPARATOR,
'\\',
substr(strstr($file, $documentsDirectory), strlen($documentsDirectory), -4)
);
}
return $documents;
} | php | public function getBundleDocumentClasses($bundle, $documentsDirectory = null)
{
if (!$documentsDirectory) {
$documentsDirectory = $this->documentDir;
}
$bundleReflection = new \ReflectionClass($this->getBundleClass($bundle));
$documentsDirectory = DIRECTORY_SEPARATOR . str_replace('\\', '/', $documentsDirectory) . DIRECTORY_SEPARATOR;
$directory = dirname($bundleReflection->getFileName()) . $documentsDirectory;
if (!is_dir($directory)) {
return [];
}
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory));
$files = new \RegexIterator($iterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH);
$documents = [];
foreach ($files as $file => $v) {
$documents[] = str_replace(
DIRECTORY_SEPARATOR,
'\\',
substr(strstr($file, $documentsDirectory), strlen($documentsDirectory), -4)
);
}
return $documents;
} | [
"public",
"function",
"getBundleDocumentClasses",
"(",
"$",
"bundle",
",",
"$",
"documentsDirectory",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"documentsDirectory",
")",
"{",
"$",
"documentsDirectory",
"=",
"$",
"this",
"->",
"documentDir",
";",
"}",
"$",
"bundleReflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"getBundleClass",
"(",
"$",
"bundle",
")",
")",
";",
"$",
"documentsDirectory",
"=",
"DIRECTORY_SEPARATOR",
".",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"documentsDirectory",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"directory",
"=",
"dirname",
"(",
"$",
"bundleReflection",
"->",
"getFileName",
"(",
")",
")",
".",
"$",
"documentsDirectory",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"directory",
")",
")",
";",
"$",
"files",
"=",
"new",
"\\",
"RegexIterator",
"(",
"$",
"iterator",
",",
"'/^.+\\.php$/i'",
",",
"\\",
"RecursiveRegexIterator",
"::",
"GET_MATCH",
")",
";",
"$",
"documents",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
"=>",
"$",
"v",
")",
"{",
"$",
"documents",
"[",
"]",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'\\\\'",
",",
"substr",
"(",
"strstr",
"(",
"$",
"file",
",",
"$",
"documentsDirectory",
")",
",",
"strlen",
"(",
"$",
"documentsDirectory",
")",
",",
"-",
"4",
")",
")",
";",
"}",
"return",
"$",
"documents",
";",
"}"
] | Returns a list of bundle document classes.
Example output:
[
'Category',
'Product',
'SubDir\SomeObject'
]
@param string $bundle Bundle name. E.g. AppBundle
@param string $documentsDirectory Directory name where documents are stored in the bundle.
@return array | [
"Returns",
"a",
"list",
"of",
"bundle",
"document",
"classes",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Mapping/DocumentFinder.php#L130-L159 |
ongr-io/ElasticsearchBundle | Service/IndexSuffixFinder.php | IndexSuffixFinder.setNextFreeIndex | public function setNextFreeIndex(Manager $manager, \DateTime $time = null)
{
if ($time === null) {
$time = new \DateTime();
}
$date = $time->format('Y.m.d');
$indexName = $manager->getIndexName();
$nameBase = $indexName . '-' . $date;
$name = $nameBase;
$i = 0;
$manager->setIndexName($name);
while ($manager->indexExists()) {
$i++;
$name = "{$nameBase}-{$i}";
$manager->setIndexName($name);
}
return $name;
} | php | public function setNextFreeIndex(Manager $manager, \DateTime $time = null)
{
if ($time === null) {
$time = new \DateTime();
}
$date = $time->format('Y.m.d');
$indexName = $manager->getIndexName();
$nameBase = $indexName . '-' . $date;
$name = $nameBase;
$i = 0;
$manager->setIndexName($name);
while ($manager->indexExists()) {
$i++;
$name = "{$nameBase}-{$i}";
$manager->setIndexName($name);
}
return $name;
} | [
"public",
"function",
"setNextFreeIndex",
"(",
"Manager",
"$",
"manager",
",",
"\\",
"DateTime",
"$",
"time",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"time",
"===",
"null",
")",
"{",
"$",
"time",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"}",
"$",
"date",
"=",
"$",
"time",
"->",
"format",
"(",
"'Y.m.d'",
")",
";",
"$",
"indexName",
"=",
"$",
"manager",
"->",
"getIndexName",
"(",
")",
";",
"$",
"nameBase",
"=",
"$",
"indexName",
".",
"'-'",
".",
"$",
"date",
";",
"$",
"name",
"=",
"$",
"nameBase",
";",
"$",
"i",
"=",
"0",
";",
"$",
"manager",
"->",
"setIndexName",
"(",
"$",
"name",
")",
";",
"while",
"(",
"$",
"manager",
"->",
"indexExists",
"(",
")",
")",
"{",
"$",
"i",
"++",
";",
"$",
"name",
"=",
"\"{$nameBase}-{$i}\"",
";",
"$",
"manager",
"->",
"setIndexName",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Constructs index name with date suffix. Sets name in the connection.
E.g. 2022.03.22-5 (if 4 indexes exists already for given date)
@param Manager $manager Connection to act upon.
@param null|\DateTime $time Date for which the suffix will be based on.
Current date if null.
@return string | [
"Constructs",
"index",
"name",
"with",
"date",
"suffix",
".",
"Sets",
"name",
"in",
"the",
"connection",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/IndexSuffixFinder.php#L30-L51 |
ongr-io/ElasticsearchBundle | Service/Json/JsonWriter.php | JsonWriter.initialize | protected function initialize()
{
if ($this->handle !== null) {
return;
}
$this->handle = fopen($this->filename, 'w');
fwrite($this->handle, "[\n");
fwrite($this->handle, json_encode($this->metadata));
} | php | protected function initialize()
{
if ($this->handle !== null) {
return;
}
$this->handle = fopen($this->filename, 'w');
fwrite($this->handle, "[\n");
fwrite($this->handle, json_encode($this->metadata));
} | [
"protected",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"handle",
"!==",
"null",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"handle",
"=",
"fopen",
"(",
"$",
"this",
"->",
"filename",
",",
"'w'",
")",
";",
"fwrite",
"(",
"$",
"this",
"->",
"handle",
",",
"\"[\\n\"",
")",
";",
"fwrite",
"(",
"$",
"this",
"->",
"handle",
",",
"json_encode",
"(",
"$",
"this",
"->",
"metadata",
")",
")",
";",
"}"
] | Performs initialization. | [
"Performs",
"initialization",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Json/JsonWriter.php#L75-L84 |
ongr-io/ElasticsearchBundle | Service/Json/JsonWriter.php | JsonWriter.finalize | public function finalize()
{
$this->initialize();
if (is_resource($this->handle)) {
fwrite($this->handle, "\n]");
fclose($this->handle);
}
} | php | public function finalize()
{
$this->initialize();
if (is_resource($this->handle)) {
fwrite($this->handle, "\n]");
fclose($this->handle);
}
} | [
"public",
"function",
"finalize",
"(",
")",
"{",
"$",
"this",
"->",
"initialize",
"(",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"this",
"->",
"handle",
")",
")",
"{",
"fwrite",
"(",
"$",
"this",
"->",
"handle",
",",
"\"\\n]\"",
")",
";",
"fclose",
"(",
"$",
"this",
"->",
"handle",
")",
";",
"}",
"}"
] | Performs finalization. | [
"Performs",
"finalization",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Json/JsonWriter.php#L89-L97 |
ongr-io/ElasticsearchBundle | Service/Json/JsonWriter.php | JsonWriter.push | public function push($document)
{
$this->initialize();
$this->currentPosition++;
if (isset($this->metadata['count']) && $this->currentPosition > $this->metadata['count']) {
throw new \OverflowException(
sprintf('This writer was set up to write %d documents, got more.', $this->metadata['count'])
);
}
fwrite($this->handle, ",\n");
fwrite($this->handle, json_encode($document));
if (isset($this->metadata['count']) && $this->currentPosition == $this->metadata['count']) {
$this->finalize();
}
} | php | public function push($document)
{
$this->initialize();
$this->currentPosition++;
if (isset($this->metadata['count']) && $this->currentPosition > $this->metadata['count']) {
throw new \OverflowException(
sprintf('This writer was set up to write %d documents, got more.', $this->metadata['count'])
);
}
fwrite($this->handle, ",\n");
fwrite($this->handle, json_encode($document));
if (isset($this->metadata['count']) && $this->currentPosition == $this->metadata['count']) {
$this->finalize();
}
} | [
"public",
"function",
"push",
"(",
"$",
"document",
")",
"{",
"$",
"this",
"->",
"initialize",
"(",
")",
";",
"$",
"this",
"->",
"currentPosition",
"++",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"metadata",
"[",
"'count'",
"]",
")",
"&&",
"$",
"this",
"->",
"currentPosition",
">",
"$",
"this",
"->",
"metadata",
"[",
"'count'",
"]",
")",
"{",
"throw",
"new",
"\\",
"OverflowException",
"(",
"sprintf",
"(",
"'This writer was set up to write %d documents, got more.'",
",",
"$",
"this",
"->",
"metadata",
"[",
"'count'",
"]",
")",
")",
";",
"}",
"fwrite",
"(",
"$",
"this",
"->",
"handle",
",",
"\",\\n\"",
")",
";",
"fwrite",
"(",
"$",
"this",
"->",
"handle",
",",
"json_encode",
"(",
"$",
"document",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"metadata",
"[",
"'count'",
"]",
")",
"&&",
"$",
"this",
"->",
"currentPosition",
"==",
"$",
"this",
"->",
"metadata",
"[",
"'count'",
"]",
")",
"{",
"$",
"this",
"->",
"finalize",
"(",
")",
";",
"}",
"}"
] | Writes single document to stream.
@param mixed $document Object to insert into stream.
@throws \OverflowException | [
"Writes",
"single",
"document",
"to",
"stream",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Json/JsonWriter.php#L106-L123 |
ongr-io/ElasticsearchBundle | Service/GenerateService.php | GenerateService.generate | public function generate(
BundleInterface $bundle,
$document,
$annotation,
$type,
array $properties
) {
$documentPath = $bundle->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php';
$class = [
'name' => $bundle->getNamespace() . '\\Document\\' . $document,
'annotation' => $annotation,
'type' => $type,
'properties' => $properties,
];
$documentCode = $this->generator->generateDocumentClass($class);
$this->filesystem->mkdir(dirname($documentPath));
file_put_contents($documentPath, $documentCode);
} | php | public function generate(
BundleInterface $bundle,
$document,
$annotation,
$type,
array $properties
) {
$documentPath = $bundle->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php';
$class = [
'name' => $bundle->getNamespace() . '\\Document\\' . $document,
'annotation' => $annotation,
'type' => $type,
'properties' => $properties,
];
$documentCode = $this->generator->generateDocumentClass($class);
$this->filesystem->mkdir(dirname($documentPath));
file_put_contents($documentPath, $documentCode);
} | [
"public",
"function",
"generate",
"(",
"BundleInterface",
"$",
"bundle",
",",
"$",
"document",
",",
"$",
"annotation",
",",
"$",
"type",
",",
"array",
"$",
"properties",
")",
"{",
"$",
"documentPath",
"=",
"$",
"bundle",
"->",
"getPath",
"(",
")",
".",
"'/Document/'",
".",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"document",
")",
".",
"'.php'",
";",
"$",
"class",
"=",
"[",
"'name'",
"=>",
"$",
"bundle",
"->",
"getNamespace",
"(",
")",
".",
"'\\\\Document\\\\'",
".",
"$",
"document",
",",
"'annotation'",
"=>",
"$",
"annotation",
",",
"'type'",
"=>",
"$",
"type",
",",
"'properties'",
"=>",
"$",
"properties",
",",
"]",
";",
"$",
"documentCode",
"=",
"$",
"this",
"->",
"generator",
"->",
"generateDocumentClass",
"(",
"$",
"class",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"mkdir",
"(",
"dirname",
"(",
"$",
"documentPath",
")",
")",
";",
"file_put_contents",
"(",
"$",
"documentPath",
",",
"$",
"documentCode",
")",
";",
"}"
] | Generates document class
@param BundleInterface $bundle
@param string $document
@param string $annotation
@param string $type
@param array $properties | [
"Generates",
"document",
"class"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/GenerateService.php#L54-L73 |
ongr-io/ElasticsearchBundle | Result/DocumentIterator.php | DocumentIterator.getAggregations | public function getAggregations()
{
$aggregations = [];
foreach (parent::getAggregations() as $key => $aggregation) {
$aggregations[$key] = $this->getAggregation($key);
}
return $aggregations;
} | php | public function getAggregations()
{
$aggregations = [];
foreach (parent::getAggregations() as $key => $aggregation) {
$aggregations[$key] = $this->getAggregation($key);
}
return $aggregations;
} | [
"public",
"function",
"getAggregations",
"(",
")",
"{",
"$",
"aggregations",
"=",
"[",
"]",
";",
"foreach",
"(",
"parent",
"::",
"getAggregations",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"aggregation",
")",
"{",
"$",
"aggregations",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getAggregation",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"aggregations",
";",
"}"
] | Returns aggregations.
@return array | [
"Returns",
"aggregations",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/DocumentIterator.php#L26-L35 |
ongr-io/ElasticsearchBundle | Result/DocumentIterator.php | DocumentIterator.getAggregation | public function getAggregation($name)
{
$aggregations = parent::getAggregations();
if (!array_key_exists($name, $aggregations)) {
return null;
}
return new AggregationValue($aggregations[$name]);
} | php | public function getAggregation($name)
{
$aggregations = parent::getAggregations();
if (!array_key_exists($name, $aggregations)) {
return null;
}
return new AggregationValue($aggregations[$name]);
} | [
"public",
"function",
"getAggregation",
"(",
"$",
"name",
")",
"{",
"$",
"aggregations",
"=",
"parent",
"::",
"getAggregations",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"aggregations",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"AggregationValue",
"(",
"$",
"aggregations",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Get a specific aggregation by name. It fetches from the top level only.
@param string $name
@return AggregationValue|null | [
"Get",
"a",
"specific",
"aggregation",
"by",
"name",
".",
"It",
"fetches",
"from",
"the",
"top",
"level",
"only",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/DocumentIterator.php#L44-L52 |
ongr-io/ElasticsearchBundle | EventListener/TerminateListener.php | TerminateListener.onKernelTerminate | public function onKernelTerminate()
{
foreach ($this->managers as $key => $value) {
if ($value['force_commit']) {
try {
/** @var Manager $manager */
$manager = $this->container->get(sprintf('es.manager.%s', $key));
} catch (\Exception $e) {
continue;
}
$manager->commit();
}
}
} | php | public function onKernelTerminate()
{
foreach ($this->managers as $key => $value) {
if ($value['force_commit']) {
try {
/** @var Manager $manager */
$manager = $this->container->get(sprintf('es.manager.%s', $key));
} catch (\Exception $e) {
continue;
}
$manager->commit();
}
}
} | [
"public",
"function",
"onKernelTerminate",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"managers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"[",
"'force_commit'",
"]",
")",
"{",
"try",
"{",
"/** @var Manager $manager */",
"$",
"manager",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"sprintf",
"(",
"'es.manager.%s'",
",",
"$",
"key",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"continue",
";",
"}",
"$",
"manager",
"->",
"commit",
"(",
")",
";",
"}",
"}",
"}"
] | Forces commit to elasticsearch on kernel terminate | [
"Forces",
"commit",
"to",
"elasticsearch",
"on",
"kernel",
"terminate"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/EventListener/TerminateListener.php#L44-L57 |
ongr-io/ElasticsearchBundle | Service/Repository.php | Repository.find | public function find($id, $routing = null)
{
return $this->manager->find($this->type, $id, $routing);
} | php | public function find($id, $routing = null)
{
return $this->manager->find($this->type, $id, $routing);
} | [
"public",
"function",
"find",
"(",
"$",
"id",
",",
"$",
"routing",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"manager",
"->",
"find",
"(",
"$",
"this",
"->",
"type",
",",
"$",
"id",
",",
"$",
"routing",
")",
";",
"}"
] | Returns a single document data by ID or null if document is not found.
@param string $id Document ID to find
@param string $routing Custom routing for the document
@return object | [
"Returns",
"a",
"single",
"document",
"data",
"by",
"ID",
"or",
"null",
"if",
"document",
"is",
"not",
"found",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Repository.php#L91-L94 |
ongr-io/ElasticsearchBundle | Service/Repository.php | Repository.findByIds | public function findByIds(array $ids)
{
$args = [];
$manager = $this->getManager();
$args['body']['docs'] = [];
$args['index'] = $manager->getIndexName();
$args['type'] = $this->getType();
foreach ($ids as $id) {
$args['body']['docs'][] = [
'_id' => $id
];
}
$mgetResponse = $manager->getClient()->mget($args);
$return = [
'hits' => [
'hits' => [],
'total' => 0,
]
];
foreach ($mgetResponse['docs'] as $item) {
if ($item['found']) {
$return['hits']['hits'][] = $item;
}
}
$return['hits']['total'] = count($return['hits']['hits']);
return new DocumentIterator($return, $manager);
} | php | public function findByIds(array $ids)
{
$args = [];
$manager = $this->getManager();
$args['body']['docs'] = [];
$args['index'] = $manager->getIndexName();
$args['type'] = $this->getType();
foreach ($ids as $id) {
$args['body']['docs'][] = [
'_id' => $id
];
}
$mgetResponse = $manager->getClient()->mget($args);
$return = [
'hits' => [
'hits' => [],
'total' => 0,
]
];
foreach ($mgetResponse['docs'] as $item) {
if ($item['found']) {
$return['hits']['hits'][] = $item;
}
}
$return['hits']['total'] = count($return['hits']['hits']);
return new DocumentIterator($return, $manager);
} | [
"public",
"function",
"findByIds",
"(",
"array",
"$",
"ids",
")",
"{",
"$",
"args",
"=",
"[",
"]",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
";",
"$",
"args",
"[",
"'body'",
"]",
"[",
"'docs'",
"]",
"=",
"[",
"]",
";",
"$",
"args",
"[",
"'index'",
"]",
"=",
"$",
"manager",
"->",
"getIndexName",
"(",
")",
";",
"$",
"args",
"[",
"'type'",
"]",
"=",
"$",
"this",
"->",
"getType",
"(",
")",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
")",
"{",
"$",
"args",
"[",
"'body'",
"]",
"[",
"'docs'",
"]",
"[",
"]",
"=",
"[",
"'_id'",
"=>",
"$",
"id",
"]",
";",
"}",
"$",
"mgetResponse",
"=",
"$",
"manager",
"->",
"getClient",
"(",
")",
"->",
"mget",
"(",
"$",
"args",
")",
";",
"$",
"return",
"=",
"[",
"'hits'",
"=>",
"[",
"'hits'",
"=>",
"[",
"]",
",",
"'total'",
"=>",
"0",
",",
"]",
"]",
";",
"foreach",
"(",
"$",
"mgetResponse",
"[",
"'docs'",
"]",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'found'",
"]",
")",
"{",
"$",
"return",
"[",
"'hits'",
"]",
"[",
"'hits'",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"$",
"return",
"[",
"'hits'",
"]",
"[",
"'total'",
"]",
"=",
"count",
"(",
"$",
"return",
"[",
"'hits'",
"]",
"[",
"'hits'",
"]",
")",
";",
"return",
"new",
"DocumentIterator",
"(",
"$",
"return",
",",
"$",
"manager",
")",
";",
"}"
] | Returns documents by a set of ids
@param array $ids
@return DocumentIterator The objects. | [
"Returns",
"documents",
"by",
"a",
"set",
"of",
"ids"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Repository.php#L103-L135 |
ongr-io/ElasticsearchBundle | Service/Repository.php | Repository.findBy | public function findBy(
array $criteria,
array $orderBy = [],
$limit = null,
$offset = null
) {
$search = $this->createSearch();
if ($limit !== null) {
$search->setSize($limit);
}
if ($offset !== null) {
$search->setFrom($offset);
}
foreach ($criteria as $field => $value) {
if (preg_match('/^!(.+)$/', $field)) {
$boolType = BoolQuery::MUST_NOT;
$field = preg_replace('/^!/', '', $field);
} else {
$boolType = BoolQuery::MUST;
}
$search->addQuery(
new QueryStringQuery(is_array($value) ? implode(' OR ', $value) : $value, ['default_field' => $field]),
$boolType
);
}
foreach ($orderBy as $field => $direction) {
$search->addSort(new FieldSort($field, $direction));
}
return $this->findDocuments($search);
} | php | public function findBy(
array $criteria,
array $orderBy = [],
$limit = null,
$offset = null
) {
$search = $this->createSearch();
if ($limit !== null) {
$search->setSize($limit);
}
if ($offset !== null) {
$search->setFrom($offset);
}
foreach ($criteria as $field => $value) {
if (preg_match('/^!(.+)$/', $field)) {
$boolType = BoolQuery::MUST_NOT;
$field = preg_replace('/^!/', '', $field);
} else {
$boolType = BoolQuery::MUST;
}
$search->addQuery(
new QueryStringQuery(is_array($value) ? implode(' OR ', $value) : $value, ['default_field' => $field]),
$boolType
);
}
foreach ($orderBy as $field => $direction) {
$search->addSort(new FieldSort($field, $direction));
}
return $this->findDocuments($search);
} | [
"public",
"function",
"findBy",
"(",
"array",
"$",
"criteria",
",",
"array",
"$",
"orderBy",
"=",
"[",
"]",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"createSearch",
"(",
")",
";",
"if",
"(",
"$",
"limit",
"!==",
"null",
")",
"{",
"$",
"search",
"->",
"setSize",
"(",
"$",
"limit",
")",
";",
"}",
"if",
"(",
"$",
"offset",
"!==",
"null",
")",
"{",
"$",
"search",
"->",
"setFrom",
"(",
"$",
"offset",
")",
";",
"}",
"foreach",
"(",
"$",
"criteria",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^!(.+)$/'",
",",
"$",
"field",
")",
")",
"{",
"$",
"boolType",
"=",
"BoolQuery",
"::",
"MUST_NOT",
";",
"$",
"field",
"=",
"preg_replace",
"(",
"'/^!/'",
",",
"''",
",",
"$",
"field",
")",
";",
"}",
"else",
"{",
"$",
"boolType",
"=",
"BoolQuery",
"::",
"MUST",
";",
"}",
"$",
"search",
"->",
"addQuery",
"(",
"new",
"QueryStringQuery",
"(",
"is_array",
"(",
"$",
"value",
")",
"?",
"implode",
"(",
"' OR '",
",",
"$",
"value",
")",
":",
"$",
"value",
",",
"[",
"'default_field'",
"=>",
"$",
"field",
"]",
")",
",",
"$",
"boolType",
")",
";",
"}",
"foreach",
"(",
"$",
"orderBy",
"as",
"$",
"field",
"=>",
"$",
"direction",
")",
"{",
"$",
"search",
"->",
"addSort",
"(",
"new",
"FieldSort",
"(",
"$",
"field",
",",
"$",
"direction",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"findDocuments",
"(",
"$",
"search",
")",
";",
"}"
] | Finds documents by a set of criteria.
@param array $criteria Example: ['group' => ['best', 'worst'], 'job' => 'medic'].
@param array|null $orderBy Example: ['name' => 'ASC', 'surname' => 'DESC'].
@param int|null $limit Example: 5.
@param int|null $offset Example: 30.
@return array|DocumentIterator The objects. | [
"Finds",
"documents",
"by",
"a",
"set",
"of",
"criteria",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Repository.php#L147-L181 |
ongr-io/ElasticsearchBundle | Service/Repository.php | Repository.getScrollConfiguration | public function getScrollConfiguration($raw, $scrollDuration)
{
$scrollConfig = [];
if (isset($raw['_scroll_id'])) {
$scrollConfig['_scroll_id'] = $raw['_scroll_id'];
$scrollConfig['duration'] = $scrollDuration;
}
return $scrollConfig;
} | php | public function getScrollConfiguration($raw, $scrollDuration)
{
$scrollConfig = [];
if (isset($raw['_scroll_id'])) {
$scrollConfig['_scroll_id'] = $raw['_scroll_id'];
$scrollConfig['duration'] = $scrollDuration;
}
return $scrollConfig;
} | [
"public",
"function",
"getScrollConfiguration",
"(",
"$",
"raw",
",",
"$",
"scrollDuration",
")",
"{",
"$",
"scrollConfig",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"raw",
"[",
"'_scroll_id'",
"]",
")",
")",
"{",
"$",
"scrollConfig",
"[",
"'_scroll_id'",
"]",
"=",
"$",
"raw",
"[",
"'_scroll_id'",
"]",
";",
"$",
"scrollConfig",
"[",
"'duration'",
"]",
"=",
"$",
"scrollDuration",
";",
"}",
"return",
"$",
"scrollConfig",
";",
"}"
] | Parses scroll configuration from raw response.
@param array $raw
@param string $scrollDuration
@return array | [
"Parses",
"scroll",
"configuration",
"from",
"raw",
"response",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Repository.php#L214-L223 |
ongr-io/ElasticsearchBundle | Service/Repository.php | Repository.findDocuments | public function findDocuments(Search $search)
{
$results = $this->executeSearch($search);
return new DocumentIterator(
$results,
$this->getManager(),
$this->getScrollConfiguration($results, $search->getScroll())
);
} | php | public function findDocuments(Search $search)
{
$results = $this->executeSearch($search);
return new DocumentIterator(
$results,
$this->getManager(),
$this->getScrollConfiguration($results, $search->getScroll())
);
} | [
"public",
"function",
"findDocuments",
"(",
"Search",
"$",
"search",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"executeSearch",
"(",
"$",
"search",
")",
";",
"return",
"new",
"DocumentIterator",
"(",
"$",
"results",
",",
"$",
"this",
"->",
"getManager",
"(",
")",
",",
"$",
"this",
"->",
"getScrollConfiguration",
"(",
"$",
"results",
",",
"$",
"search",
"->",
"getScroll",
"(",
")",
")",
")",
";",
"}"
] | Returns DocumentIterator with composed Document objects from array response.
@param Search $search
@return DocumentIterator | [
"Returns",
"DocumentIterator",
"with",
"composed",
"Document",
"objects",
"from",
"array",
"response",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Repository.php#L232-L241 |
ongr-io/ElasticsearchBundle | Service/Repository.php | Repository.findArray | public function findArray(Search $search)
{
$results = $this->executeSearch($search);
return new ArrayIterator(
$results,
$this->getManager(),
$this->getScrollConfiguration($results, $search->getScroll())
);
} | php | public function findArray(Search $search)
{
$results = $this->executeSearch($search);
return new ArrayIterator(
$results,
$this->getManager(),
$this->getScrollConfiguration($results, $search->getScroll())
);
} | [
"public",
"function",
"findArray",
"(",
"Search",
"$",
"search",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"executeSearch",
"(",
"$",
"search",
")",
";",
"return",
"new",
"ArrayIterator",
"(",
"$",
"results",
",",
"$",
"this",
"->",
"getManager",
"(",
")",
",",
"$",
"this",
"->",
"getScrollConfiguration",
"(",
"$",
"results",
",",
"$",
"search",
"->",
"getScroll",
"(",
")",
")",
")",
";",
"}"
] | Returns ArrayIterator with access to unmodified documents directly.
@param Search $search
@return ArrayIterator | [
"Returns",
"ArrayIterator",
"with",
"access",
"to",
"unmodified",
"documents",
"directly",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Repository.php#L251-L260 |
ongr-io/ElasticsearchBundle | Service/Repository.php | Repository.findRaw | public function findRaw(Search $search)
{
$results = $this->executeSearch($search);
return new RawIterator(
$results,
$this->getManager(),
$this->getScrollConfiguration($results, $search->getScroll())
);
} | php | public function findRaw(Search $search)
{
$results = $this->executeSearch($search);
return new RawIterator(
$results,
$this->getManager(),
$this->getScrollConfiguration($results, $search->getScroll())
);
} | [
"public",
"function",
"findRaw",
"(",
"Search",
"$",
"search",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"executeSearch",
"(",
"$",
"search",
")",
";",
"return",
"new",
"RawIterator",
"(",
"$",
"results",
",",
"$",
"this",
"->",
"getManager",
"(",
")",
",",
"$",
"this",
"->",
"getScrollConfiguration",
"(",
"$",
"results",
",",
"$",
"search",
"->",
"getScroll",
"(",
")",
")",
")",
";",
"}"
] | Returns RawIterator with access to node with all returned values included.
@param Search $search
@return RawIterator | [
"Returns",
"RawIterator",
"with",
"access",
"to",
"node",
"with",
"all",
"returned",
"values",
"included",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Repository.php#L269-L278 |
ongr-io/ElasticsearchBundle | Service/Repository.php | Repository.executeSearch | private function executeSearch(Search $search)
{
return $this->getManager()->search([$this->getType()], $search->toArray(), $search->getUriParams());
} | php | private function executeSearch(Search $search)
{
return $this->getManager()->search([$this->getType()], $search->toArray(), $search->getUriParams());
} | [
"private",
"function",
"executeSearch",
"(",
"Search",
"$",
"search",
")",
"{",
"return",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"search",
"(",
"[",
"$",
"this",
"->",
"getType",
"(",
")",
"]",
",",
"$",
"search",
"->",
"toArray",
"(",
")",
",",
"$",
"search",
"->",
"getUriParams",
"(",
")",
")",
";",
"}"
] | Executes search to the elasticsearch and returns raw response.
@param Search $search
@return array | [
"Executes",
"search",
"to",
"the",
"elasticsearch",
"and",
"returns",
"raw",
"response",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Repository.php#L287-L290 |
ongr-io/ElasticsearchBundle | Service/Repository.php | Repository.count | public function count(Search $search, array $params = [], $returnRaw = false)
{
$body = array_merge(
[
'index' => $this->getManager()->getIndexName(),
'type' => $this->type,
'body' => $search->toArray(),
],
$params
);
$results = $this
->getManager()
->getClient()->count($body);
if ($returnRaw) {
return $results;
} else {
return $results['count'];
}
} | php | public function count(Search $search, array $params = [], $returnRaw = false)
{
$body = array_merge(
[
'index' => $this->getManager()->getIndexName(),
'type' => $this->type,
'body' => $search->toArray(),
],
$params
);
$results = $this
->getManager()
->getClient()->count($body);
if ($returnRaw) {
return $results;
} else {
return $results['count'];
}
} | [
"public",
"function",
"count",
"(",
"Search",
"$",
"search",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"returnRaw",
"=",
"false",
")",
"{",
"$",
"body",
"=",
"array_merge",
"(",
"[",
"'index'",
"=>",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getIndexName",
"(",
")",
",",
"'type'",
"=>",
"$",
"this",
"->",
"type",
",",
"'body'",
"=>",
"$",
"search",
"->",
"toArray",
"(",
")",
",",
"]",
",",
"$",
"params",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getClient",
"(",
")",
"->",
"count",
"(",
"$",
"body",
")",
";",
"if",
"(",
"$",
"returnRaw",
")",
"{",
"return",
"$",
"results",
";",
"}",
"else",
"{",
"return",
"$",
"results",
"[",
"'count'",
"]",
";",
"}",
"}"
] | Counts documents by given search.
@param Search $search
@param array $params
@param bool $returnRaw If set true returns raw response gotten from client.
@return int|array | [
"Counts",
"documents",
"by",
"given",
"search",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Repository.php#L301-L321 |
ongr-io/ElasticsearchBundle | Service/Repository.php | Repository.remove | public function remove($id, $routing = null)
{
$params = [
'index' => $this->getManager()->getIndexName(),
'type' => $this->type,
'id' => $id,
];
if ($routing) {
$params['routing'] = $routing;
}
$response = $this->getManager()->getClient()->delete($params);
return $response;
} | php | public function remove($id, $routing = null)
{
$params = [
'index' => $this->getManager()->getIndexName(),
'type' => $this->type,
'id' => $id,
];
if ($routing) {
$params['routing'] = $routing;
}
$response = $this->getManager()->getClient()->delete($params);
return $response;
} | [
"public",
"function",
"remove",
"(",
"$",
"id",
",",
"$",
"routing",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"[",
"'index'",
"=>",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getIndexName",
"(",
")",
",",
"'type'",
"=>",
"$",
"this",
"->",
"type",
",",
"'id'",
"=>",
"$",
"id",
",",
"]",
";",
"if",
"(",
"$",
"routing",
")",
"{",
"$",
"params",
"[",
"'routing'",
"]",
"=",
"$",
"routing",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getClient",
"(",
")",
"->",
"delete",
"(",
"$",
"params",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Removes a single document data by ID.
@param string $id Document ID to remove
@param string $routing Custom routing for the document
@return array
@throws \LogicException | [
"Removes",
"a",
"single",
"document",
"data",
"by",
"ID",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Repository.php#L333-L348 |
ongr-io/ElasticsearchBundle | Service/Repository.php | Repository.update | public function update($id, array $fields = [], $script = null, array $params = [])
{
$body = array_filter(
[
'doc' => $fields,
'script' => $script,
]
);
$params = array_merge(
[
'id' => $id,
'index' => $this->getManager()->getIndexName(),
'type' => $this->type,
'body' => $body,
],
$params
);
return $this->getManager()->getClient()->update($params);
} | php | public function update($id, array $fields = [], $script = null, array $params = [])
{
$body = array_filter(
[
'doc' => $fields,
'script' => $script,
]
);
$params = array_merge(
[
'id' => $id,
'index' => $this->getManager()->getIndexName(),
'type' => $this->type,
'body' => $body,
],
$params
);
return $this->getManager()->getClient()->update($params);
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"array",
"$",
"fields",
"=",
"[",
"]",
",",
"$",
"script",
"=",
"null",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"body",
"=",
"array_filter",
"(",
"[",
"'doc'",
"=>",
"$",
"fields",
",",
"'script'",
"=>",
"$",
"script",
",",
"]",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"[",
"'id'",
"=>",
"$",
"id",
",",
"'index'",
"=>",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getIndexName",
"(",
")",
",",
"'type'",
"=>",
"$",
"this",
"->",
"type",
",",
"'body'",
"=>",
"$",
"body",
",",
"]",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getClient",
"(",
")",
"->",
"update",
"(",
"$",
"params",
")",
";",
"}"
] | Partial document update.
@param string $id Document id to update.
@param array $fields Fields array to update.
@param string $script Groovy script to update fields.
@param array $params Additional parameters to pass to the client.
@return array | [
"Partial",
"document",
"update",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Repository.php#L360-L380 |
ongr-io/ElasticsearchBundle | Command/AbstractManagerAwareCommand.php | AbstractManagerAwareCommand.getManager | protected function getManager($name)
{
$id = $this->getManagerId($name);
if ($this->getContainer()->has($id)) {
return $this->getContainer()->get($id);
}
throw new \RuntimeException(
sprintf(
'Manager named `%s` not found. Available: `%s`.',
$name,
implode('`, `', array_keys($this->getContainer()->getParameter('es.managers')))
)
);
} | php | protected function getManager($name)
{
$id = $this->getManagerId($name);
if ($this->getContainer()->has($id)) {
return $this->getContainer()->get($id);
}
throw new \RuntimeException(
sprintf(
'Manager named `%s` not found. Available: `%s`.',
$name,
implode('`, `', array_keys($this->getContainer()->getParameter('es.managers')))
)
);
} | [
"protected",
"function",
"getManager",
"(",
"$",
"name",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getManagerId",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"$",
"id",
")",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Manager named `%s` not found. Available: `%s`.'",
",",
"$",
"name",
",",
"implode",
"(",
"'`, `'",
",",
"array_keys",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"getParameter",
"(",
"'es.managers'",
")",
")",
")",
")",
")",
";",
"}"
] | Returns elasticsearch manager by name from service container.
@param string $name Manager name defined in configuration.
@return Manager
@throws \RuntimeException If manager was not found. | [
"Returns",
"elasticsearch",
"manager",
"by",
"name",
"from",
"service",
"container",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/AbstractManagerAwareCommand.php#L46-L61 |
ongr-io/ElasticsearchBundle | Result/ObjectIterator.php | ObjectIterator.convertDocument | protected function convertDocument(array $document)
{
return $this->converter->assignArrayToObject(
$document,
new $this->alias['namespace'](),
$this->alias['aliases']
);
} | php | protected function convertDocument(array $document)
{
return $this->converter->assignArrayToObject(
$document,
new $this->alias['namespace'](),
$this->alias['aliases']
);
} | [
"protected",
"function",
"convertDocument",
"(",
"array",
"$",
"document",
")",
"{",
"return",
"$",
"this",
"->",
"converter",
"->",
"assignArrayToObject",
"(",
"$",
"document",
",",
"new",
"$",
"this",
"->",
"alias",
"[",
"'namespace'",
"]",
"(",
")",
",",
"$",
"this",
"->",
"alias",
"[",
"'aliases'",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Result/ObjectIterator.php#L49-L56 |
ongr-io/ElasticsearchBundle | Command/IndexExportCommand.php | IndexExportCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$manager = $this->getManager($input->getOption('manager'));
/** @var ExportService $exportService */
$exportService = $this->getContainer()->get('es.export');
$exportService->exportIndex(
$manager,
$input->getArgument('filename'),
$input->getOption('types'),
$input->getOption('chunk'),
$output,
$input->getOption('split')
);
$io->success('Data export completed!');
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$manager = $this->getManager($input->getOption('manager'));
/** @var ExportService $exportService */
$exportService = $this->getContainer()->get('es.export');
$exportService->exportIndex(
$manager,
$input->getArgument('filename'),
$input->getOption('types'),
$input->getOption('chunk'),
$output,
$input->getOption('split')
);
$io->success('Data export completed!');
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"io",
"=",
"new",
"SymfonyStyle",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"getManager",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'manager'",
")",
")",
";",
"/** @var ExportService $exportService */",
"$",
"exportService",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'es.export'",
")",
";",
"$",
"exportService",
"->",
"exportIndex",
"(",
"$",
"manager",
",",
"$",
"input",
"->",
"getArgument",
"(",
"'filename'",
")",
",",
"$",
"input",
"->",
"getOption",
"(",
"'types'",
")",
",",
"$",
"input",
"->",
"getOption",
"(",
"'chunk'",
")",
",",
"$",
"output",
",",
"$",
"input",
"->",
"getOption",
"(",
"'split'",
")",
")",
";",
"$",
"io",
"->",
"success",
"(",
"'Data export completed!'",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/IndexExportCommand.php#L65-L82 |
ongr-io/ElasticsearchBundle | Service/Json/JsonReader.php | JsonReader.getFileHandler | protected function getFileHandler()
{
if ($this->handle === null) {
$isGzip = array_key_exists('gzip', $this->options);
$filename = !$isGzip?
$this->filename:
sprintf('compress.zlib://%s', $this->filename);
$fileHandler = @fopen($filename, 'r');
if ($fileHandler === false) {
throw new \LogicException('Can not open file.');
}
$this->handle = $fileHandler;
}
return $this->handle;
} | php | protected function getFileHandler()
{
if ($this->handle === null) {
$isGzip = array_key_exists('gzip', $this->options);
$filename = !$isGzip?
$this->filename:
sprintf('compress.zlib://%s', $this->filename);
$fileHandler = @fopen($filename, 'r');
if ($fileHandler === false) {
throw new \LogicException('Can not open file.');
}
$this->handle = $fileHandler;
}
return $this->handle;
} | [
"protected",
"function",
"getFileHandler",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"handle",
"===",
"null",
")",
"{",
"$",
"isGzip",
"=",
"array_key_exists",
"(",
"'gzip'",
",",
"$",
"this",
"->",
"options",
")",
";",
"$",
"filename",
"=",
"!",
"$",
"isGzip",
"?",
"$",
"this",
"->",
"filename",
":",
"sprintf",
"(",
"'compress.zlib://%s'",
",",
"$",
"this",
"->",
"filename",
")",
";",
"$",
"fileHandler",
"=",
"@",
"fopen",
"(",
"$",
"filename",
",",
"'r'",
")",
";",
"if",
"(",
"$",
"fileHandler",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Can not open file.'",
")",
";",
"}",
"$",
"this",
"->",
"handle",
"=",
"$",
"fileHandler",
";",
"}",
"return",
"$",
"this",
"->",
"handle",
";",
"}"
] | Returns file handler.
@return resource
@throws \LogicException | [
"Returns",
"file",
"handler",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Json/JsonReader.php#L102-L120 |
ongr-io/ElasticsearchBundle | Service/Json/JsonReader.php | JsonReader.readMetadata | protected function readMetadata()
{
if ($this->metadata !== null) {
return;
}
$line = fgets($this->getFileHandler());
if (trim($line) !== '[') {
throw new \InvalidArgumentException('Given file does not match expected pattern.');
}
$line = trim(fgets($this->getFileHandler()));
$this->metadata = json_decode(rtrim($line, ','), true);
} | php | protected function readMetadata()
{
if ($this->metadata !== null) {
return;
}
$line = fgets($this->getFileHandler());
if (trim($line) !== '[') {
throw new \InvalidArgumentException('Given file does not match expected pattern.');
}
$line = trim(fgets($this->getFileHandler()));
$this->metadata = json_decode(rtrim($line, ','), true);
} | [
"protected",
"function",
"readMetadata",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"metadata",
"!==",
"null",
")",
"{",
"return",
";",
"}",
"$",
"line",
"=",
"fgets",
"(",
"$",
"this",
"->",
"getFileHandler",
"(",
")",
")",
";",
"if",
"(",
"trim",
"(",
"$",
"line",
")",
"!==",
"'['",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Given file does not match expected pattern.'",
")",
";",
"}",
"$",
"line",
"=",
"trim",
"(",
"fgets",
"(",
"$",
"this",
"->",
"getFileHandler",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"metadata",
"=",
"json_decode",
"(",
"rtrim",
"(",
"$",
"line",
",",
"','",
")",
",",
"true",
")",
";",
"}"
] | Reads metadata from file.
@throws \InvalidArgumentException | [
"Reads",
"metadata",
"from",
"file",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Json/JsonReader.php#L127-L141 |
ongr-io/ElasticsearchBundle | Service/Json/JsonReader.php | JsonReader.readLine | protected function readLine()
{
$buffer = '';
while ($buffer === '') {
$buffer = fgets($this->getFileHandler());
if ($buffer === false) {
$this->currentLine = null;
return;
}
$buffer = trim($buffer);
}
if ($buffer === ']') {
$this->currentLine = null;
return;
}
$data = json_decode(rtrim($buffer, ','), true);
$this->currentLine = $this->getOptionsResolver()->resolve($data);
} | php | protected function readLine()
{
$buffer = '';
while ($buffer === '') {
$buffer = fgets($this->getFileHandler());
if ($buffer === false) {
$this->currentLine = null;
return;
}
$buffer = trim($buffer);
}
if ($buffer === ']') {
$this->currentLine = null;
return;
}
$data = json_decode(rtrim($buffer, ','), true);
$this->currentLine = $this->getOptionsResolver()->resolve($data);
} | [
"protected",
"function",
"readLine",
"(",
")",
"{",
"$",
"buffer",
"=",
"''",
";",
"while",
"(",
"$",
"buffer",
"===",
"''",
")",
"{",
"$",
"buffer",
"=",
"fgets",
"(",
"$",
"this",
"->",
"getFileHandler",
"(",
")",
")",
";",
"if",
"(",
"$",
"buffer",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"currentLine",
"=",
"null",
";",
"return",
";",
"}",
"$",
"buffer",
"=",
"trim",
"(",
"$",
"buffer",
")",
";",
"}",
"if",
"(",
"$",
"buffer",
"===",
"']'",
")",
"{",
"$",
"this",
"->",
"currentLine",
"=",
"null",
";",
"return",
";",
"}",
"$",
"data",
"=",
"json_decode",
"(",
"rtrim",
"(",
"$",
"buffer",
",",
"','",
")",
",",
"true",
")",
";",
"$",
"this",
"->",
"currentLine",
"=",
"$",
"this",
"->",
"getOptionsResolver",
"(",
")",
"->",
"resolve",
"(",
"$",
"data",
")",
";",
"}"
] | Reads single line from file. | [
"Reads",
"single",
"line",
"from",
"file",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Json/JsonReader.php#L146-L170 |
ongr-io/ElasticsearchBundle | Service/Json/JsonReader.php | JsonReader.configureResolver | protected function configureResolver(OptionsResolver $resolver)
{
$resolver
->setRequired(['_id', '_type', '_source'])
->setDefaults(['_score' => null, 'fields' => []])
->addAllowedTypes('_id', ['integer', 'string'])
->addAllowedTypes('_type', 'string')
->addAllowedTypes('_source', 'array')
->addAllowedTypes('fields', 'array');
} | php | protected function configureResolver(OptionsResolver $resolver)
{
$resolver
->setRequired(['_id', '_type', '_source'])
->setDefaults(['_score' => null, 'fields' => []])
->addAllowedTypes('_id', ['integer', 'string'])
->addAllowedTypes('_type', 'string')
->addAllowedTypes('_source', 'array')
->addAllowedTypes('fields', 'array');
} | [
"protected",
"function",
"configureResolver",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"resolver",
"->",
"setRequired",
"(",
"[",
"'_id'",
",",
"'_type'",
",",
"'_source'",
"]",
")",
"->",
"setDefaults",
"(",
"[",
"'_score'",
"=>",
"null",
",",
"'fields'",
"=>",
"[",
"]",
"]",
")",
"->",
"addAllowedTypes",
"(",
"'_id'",
",",
"[",
"'integer'",
",",
"'string'",
"]",
")",
"->",
"addAllowedTypes",
"(",
"'_type'",
",",
"'string'",
")",
"->",
"addAllowedTypes",
"(",
"'_source'",
",",
"'array'",
")",
"->",
"addAllowedTypes",
"(",
"'fields'",
",",
"'array'",
")",
";",
"}"
] | Configures OptionResolver for resolving document metadata fields.
@param OptionsResolver $resolver | [
"Configures",
"OptionResolver",
"for",
"resolving",
"document",
"metadata",
"fields",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Json/JsonReader.php#L177-L186 |
ongr-io/ElasticsearchBundle | Service/Json/JsonReader.php | JsonReader.rewind | public function rewind()
{
rewind($this->getFileHandler());
$this->metadata = null;
$this->readMetadata();
$this->readLine();
} | php | public function rewind()
{
rewind($this->getFileHandler());
$this->metadata = null;
$this->readMetadata();
$this->readLine();
} | [
"public",
"function",
"rewind",
"(",
")",
"{",
"rewind",
"(",
"$",
"this",
"->",
"getFileHandler",
"(",
")",
")",
";",
"$",
"this",
"->",
"metadata",
"=",
"null",
";",
"$",
"this",
"->",
"readMetadata",
"(",
")",
";",
"$",
"this",
"->",
"readLine",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Json/JsonReader.php#L231-L237 |
ongr-io/ElasticsearchBundle | Service/Json/JsonReader.php | JsonReader.getOptionsResolver | private function getOptionsResolver()
{
if (!$this->optionsResolver) {
$this->optionsResolver = new OptionsResolver();
$this->configureResolver($this->optionsResolver);
}
return $this->optionsResolver;
} | php | private function getOptionsResolver()
{
if (!$this->optionsResolver) {
$this->optionsResolver = new OptionsResolver();
$this->configureResolver($this->optionsResolver);
}
return $this->optionsResolver;
} | [
"private",
"function",
"getOptionsResolver",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"optionsResolver",
")",
"{",
"$",
"this",
"->",
"optionsResolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"$",
"this",
"->",
"configureResolver",
"(",
"$",
"this",
"->",
"optionsResolver",
")",
";",
"}",
"return",
"$",
"this",
"->",
"optionsResolver",
";",
"}"
] | Returns configured options resolver instance.
@return OptionsResolver | [
"Returns",
"configured",
"options",
"resolver",
"instance",
"."
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Service/Json/JsonReader.php#L270-L278 |
ongr-io/ElasticsearchBundle | Generator/DocumentGenerator.php | DocumentGenerator.generateDocumentClass | public function generateDocumentClass(array $metadata)
{
return implode(
"\n",
[
"<?php\n",
sprintf('namespace %s;', substr($metadata['name'], 0, strrpos($metadata['name'], '\\'))) . "\n",
$this->generateDocumentUse($metadata),
$this->generateDocumentDocBlock($metadata),
'class ' . $this->getClassName($metadata),
"{",
str_replace('<spaces>', $this->spaces, $this->generateDocumentBody($metadata)),
"}\n"
]
);
} | php | public function generateDocumentClass(array $metadata)
{
return implode(
"\n",
[
"<?php\n",
sprintf('namespace %s;', substr($metadata['name'], 0, strrpos($metadata['name'], '\\'))) . "\n",
$this->generateDocumentUse($metadata),
$this->generateDocumentDocBlock($metadata),
'class ' . $this->getClassName($metadata),
"{",
str_replace('<spaces>', $this->spaces, $this->generateDocumentBody($metadata)),
"}\n"
]
);
} | [
"public",
"function",
"generateDocumentClass",
"(",
"array",
"$",
"metadata",
")",
"{",
"return",
"implode",
"(",
"\"\\n\"",
",",
"[",
"\"<?php\\n\"",
",",
"sprintf",
"(",
"'namespace %s;'",
",",
"substr",
"(",
"$",
"metadata",
"[",
"'name'",
"]",
",",
"0",
",",
"strrpos",
"(",
"$",
"metadata",
"[",
"'name'",
"]",
",",
"'\\\\'",
")",
")",
")",
".",
"\"\\n\"",
",",
"$",
"this",
"->",
"generateDocumentUse",
"(",
"$",
"metadata",
")",
",",
"$",
"this",
"->",
"generateDocumentDocBlock",
"(",
"$",
"metadata",
")",
",",
"'class '",
".",
"$",
"this",
"->",
"getClassName",
"(",
"$",
"metadata",
")",
",",
"\"{\"",
",",
"str_replace",
"(",
"'<spaces>'",
",",
"$",
"this",
"->",
"spaces",
",",
"$",
"this",
"->",
"generateDocumentBody",
"(",
"$",
"metadata",
")",
")",
",",
"\"}\\n\"",
"]",
")",
";",
"}"
] | @param array $metadata
@return string | [
"@param",
"array",
"$metadata"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Generator/DocumentGenerator.php#L89-L104 |
ongr-io/ElasticsearchBundle | Generator/DocumentGenerator.php | DocumentGenerator.generateDocumentBody | private function generateDocumentBody(array $metadata)
{
$lines = [];
if ($properties = $this->generateDocumentProperties($metadata)) {
$lines[] = $properties;
}
if ($this->hasMultipleEmbedded($metadata)) {
$lines[] = $this->generateDocumentConstructor($metadata);
}
if ($methods = $this->generateDocumentMethods($metadata)) {
$lines[] = $methods;
}
return rtrim(implode("\n", $lines));
} | php | private function generateDocumentBody(array $metadata)
{
$lines = [];
if ($properties = $this->generateDocumentProperties($metadata)) {
$lines[] = $properties;
}
if ($this->hasMultipleEmbedded($metadata)) {
$lines[] = $this->generateDocumentConstructor($metadata);
}
if ($methods = $this->generateDocumentMethods($metadata)) {
$lines[] = $methods;
}
return rtrim(implode("\n", $lines));
} | [
"private",
"function",
"generateDocumentBody",
"(",
"array",
"$",
"metadata",
")",
"{",
"$",
"lines",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"properties",
"=",
"$",
"this",
"->",
"generateDocumentProperties",
"(",
"$",
"metadata",
")",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"$",
"properties",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasMultipleEmbedded",
"(",
"$",
"metadata",
")",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"$",
"this",
"->",
"generateDocumentConstructor",
"(",
"$",
"metadata",
")",
";",
"}",
"if",
"(",
"$",
"methods",
"=",
"$",
"this",
"->",
"generateDocumentMethods",
"(",
"$",
"metadata",
")",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"$",
"methods",
";",
"}",
"return",
"rtrim",
"(",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
")",
";",
"}"
] | Generates document body
@param array $metadata
@return string | [
"Generates",
"document",
"body"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Generator/DocumentGenerator.php#L113-L130 |
ongr-io/ElasticsearchBundle | Generator/DocumentGenerator.php | DocumentGenerator.generateDocumentProperties | private function generateDocumentProperties(array $metadata)
{
$lines = [];
foreach ($metadata['properties'] as $property) {
$lines[] = $this->generatePropertyDocBlock($property);
$lines[] = $this->spaces . $property['visibility'] . ' $' . $property['field_name'] . ";\n";
}
return implode("\n", $lines);
} | php | private function generateDocumentProperties(array $metadata)
{
$lines = [];
foreach ($metadata['properties'] as $property) {
$lines[] = $this->generatePropertyDocBlock($property);
$lines[] = $this->spaces . $property['visibility'] . ' $' . $property['field_name'] . ";\n";
}
return implode("\n", $lines);
} | [
"private",
"function",
"generateDocumentProperties",
"(",
"array",
"$",
"metadata",
")",
"{",
"$",
"lines",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"metadata",
"[",
"'properties'",
"]",
"as",
"$",
"property",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"$",
"this",
"->",
"generatePropertyDocBlock",
"(",
"$",
"property",
")",
";",
"$",
"lines",
"[",
"]",
"=",
"$",
"this",
"->",
"spaces",
".",
"$",
"property",
"[",
"'visibility'",
"]",
".",
"' $'",
".",
"$",
"property",
"[",
"'field_name'",
"]",
".",
"\";\\n\"",
";",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"}"
] | Generates document properties
@param array $metadata
@return string | [
"Generates",
"document",
"properties"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Generator/DocumentGenerator.php#L139-L149 |
ongr-io/ElasticsearchBundle | Generator/DocumentGenerator.php | DocumentGenerator.generateDocumentMethods | private function generateDocumentMethods(array $metadata)
{
$lines = [];
foreach ($metadata['properties'] as $property) {
if (isset($property['visibility']) && $property['visibility'] === 'public') {
continue;
}
$lines[] = $this->generateDocumentMethod($property, $this->setMethodTemplate) . "\n";
if (isset($property['property_type']) && $property['property_type'] === 'boolean') {
$lines[] = $this->generateDocumentMethod($property, $this->isMethodTemplate) . "\n";
}
$lines[] = $this->generateDocumentMethod($property, $this->getMethodTemplate) . "\n";
}
return implode("\n", $lines);
} | php | private function generateDocumentMethods(array $metadata)
{
$lines = [];
foreach ($metadata['properties'] as $property) {
if (isset($property['visibility']) && $property['visibility'] === 'public') {
continue;
}
$lines[] = $this->generateDocumentMethod($property, $this->setMethodTemplate) . "\n";
if (isset($property['property_type']) && $property['property_type'] === 'boolean') {
$lines[] = $this->generateDocumentMethod($property, $this->isMethodTemplate) . "\n";
}
$lines[] = $this->generateDocumentMethod($property, $this->getMethodTemplate) . "\n";
}
return implode("\n", $lines);
} | [
"private",
"function",
"generateDocumentMethods",
"(",
"array",
"$",
"metadata",
")",
"{",
"$",
"lines",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"metadata",
"[",
"'properties'",
"]",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"property",
"[",
"'visibility'",
"]",
")",
"&&",
"$",
"property",
"[",
"'visibility'",
"]",
"===",
"'public'",
")",
"{",
"continue",
";",
"}",
"$",
"lines",
"[",
"]",
"=",
"$",
"this",
"->",
"generateDocumentMethod",
"(",
"$",
"property",
",",
"$",
"this",
"->",
"setMethodTemplate",
")",
".",
"\"\\n\"",
";",
"if",
"(",
"isset",
"(",
"$",
"property",
"[",
"'property_type'",
"]",
")",
"&&",
"$",
"property",
"[",
"'property_type'",
"]",
"===",
"'boolean'",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"$",
"this",
"->",
"generateDocumentMethod",
"(",
"$",
"property",
",",
"$",
"this",
"->",
"isMethodTemplate",
")",
".",
"\"\\n\"",
";",
"}",
"$",
"lines",
"[",
"]",
"=",
"$",
"this",
"->",
"generateDocumentMethod",
"(",
"$",
"property",
",",
"$",
"this",
"->",
"getMethodTemplate",
")",
".",
"\"\\n\"",
";",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"}"
] | Generates document methods
@param array $metadata
@return string | [
"Generates",
"document",
"methods"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Generator/DocumentGenerator.php#L158-L175 |
ongr-io/ElasticsearchBundle | Generator/DocumentGenerator.php | DocumentGenerator.generateDocumentConstructor | private function generateDocumentConstructor(array $metadata)
{
$fields = [];
foreach ($metadata['properties'] as $prop) {
if ($prop['annotation'] == 'embedded' && isset($prop['property_multiple']) && $prop['property_multiple']) {
$fields[] = sprintf('%s$this->%s = new Collection();', $this->spaces, $prop['field_name']);
}
}
return $this->prefixWithSpaces(
str_replace('<fields>', implode("\n", $fields), $this->constructorTemplate)
) . "\n";
} | php | private function generateDocumentConstructor(array $metadata)
{
$fields = [];
foreach ($metadata['properties'] as $prop) {
if ($prop['annotation'] == 'embedded' && isset($prop['property_multiple']) && $prop['property_multiple']) {
$fields[] = sprintf('%s$this->%s = new Collection();', $this->spaces, $prop['field_name']);
}
}
return $this->prefixWithSpaces(
str_replace('<fields>', implode("\n", $fields), $this->constructorTemplate)
) . "\n";
} | [
"private",
"function",
"generateDocumentConstructor",
"(",
"array",
"$",
"metadata",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"metadata",
"[",
"'properties'",
"]",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"$",
"prop",
"[",
"'annotation'",
"]",
"==",
"'embedded'",
"&&",
"isset",
"(",
"$",
"prop",
"[",
"'property_multiple'",
"]",
")",
"&&",
"$",
"prop",
"[",
"'property_multiple'",
"]",
")",
"{",
"$",
"fields",
"[",
"]",
"=",
"sprintf",
"(",
"'%s$this->%s = new Collection();'",
",",
"$",
"this",
"->",
"spaces",
",",
"$",
"prop",
"[",
"'field_name'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"prefixWithSpaces",
"(",
"str_replace",
"(",
"'<fields>'",
",",
"implode",
"(",
"\"\\n\"",
",",
"$",
"fields",
")",
",",
"$",
"this",
"->",
"constructorTemplate",
")",
")",
".",
"\"\\n\"",
";",
"}"
] | Generates document constructor
@param array $metadata
@return string | [
"Generates",
"document",
"constructor"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Generator/DocumentGenerator.php#L184-L197 |
ongr-io/ElasticsearchBundle | Generator/DocumentGenerator.php | DocumentGenerator.generateDocumentMethod | private function generateDocumentMethod(array $metadata, $template)
{
return $this->prefixWithSpaces(
str_replace(
['<methodName>', '<fieldName>'],
[ucfirst($metadata['field_name']), $metadata['field_name']],
$template
)
);
} | php | private function generateDocumentMethod(array $metadata, $template)
{
return $this->prefixWithSpaces(
str_replace(
['<methodName>', '<fieldName>'],
[ucfirst($metadata['field_name']), $metadata['field_name']],
$template
)
);
} | [
"private",
"function",
"generateDocumentMethod",
"(",
"array",
"$",
"metadata",
",",
"$",
"template",
")",
"{",
"return",
"$",
"this",
"->",
"prefixWithSpaces",
"(",
"str_replace",
"(",
"[",
"'<methodName>'",
",",
"'<fieldName>'",
"]",
",",
"[",
"ucfirst",
"(",
"$",
"metadata",
"[",
"'field_name'",
"]",
")",
",",
"$",
"metadata",
"[",
"'field_name'",
"]",
"]",
",",
"$",
"template",
")",
")",
";",
"}"
] | Generates document method
@param array $metadata
@param string $template
@return string | [
"Generates",
"document",
"method"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Generator/DocumentGenerator.php#L207-L216 |
ongr-io/ElasticsearchBundle | Generator/DocumentGenerator.php | DocumentGenerator.generatePropertyDocBlock | private function generatePropertyDocBlock(array $metadata)
{
$lines = [
$this->spaces . '/**',
$this->spaces . ' * @var string',
$this->spaces . ' *',
];
$column = [];
if (isset($metadata['property_name']) && $metadata['property_name'] != $metadata['field_name']) {
$column[] = 'name="' . $metadata['property_name'] . '"';
}
if (isset($metadata['property_class'])) {
$column[] = 'class="' . $metadata['property_class'] . '"';
}
if (isset($metadata['property_multiple']) && $metadata['property_multiple']) {
$column[] = 'multiple=true';
}
if (isset($metadata['property_type']) && $metadata['annotation'] == 'property') {
$column[] = 'type="' . $metadata['property_type'] . '"';
}
if (isset($metadata['property_default'])) {
$column[] = 'default="' . $metadata['property_default'] . '"';
}
if (isset($metadata['property_options']) && $metadata['property_options']) {
$column[] = 'options={' . $metadata['property_options'] . '}';
}
$lines[] = $this->spaces . ' * @ES\\' . ucfirst($metadata['annotation']) . '(' . implode(', ', $column) . ')';
$lines[] = $this->spaces . ' */';
return implode("\n", $lines);
} | php | private function generatePropertyDocBlock(array $metadata)
{
$lines = [
$this->spaces . '/**',
$this->spaces . ' * @var string',
$this->spaces . ' *',
];
$column = [];
if (isset($metadata['property_name']) && $metadata['property_name'] != $metadata['field_name']) {
$column[] = 'name="' . $metadata['property_name'] . '"';
}
if (isset($metadata['property_class'])) {
$column[] = 'class="' . $metadata['property_class'] . '"';
}
if (isset($metadata['property_multiple']) && $metadata['property_multiple']) {
$column[] = 'multiple=true';
}
if (isset($metadata['property_type']) && $metadata['annotation'] == 'property') {
$column[] = 'type="' . $metadata['property_type'] . '"';
}
if (isset($metadata['property_default'])) {
$column[] = 'default="' . $metadata['property_default'] . '"';
}
if (isset($metadata['property_options']) && $metadata['property_options']) {
$column[] = 'options={' . $metadata['property_options'] . '}';
}
$lines[] = $this->spaces . ' * @ES\\' . ucfirst($metadata['annotation']) . '(' . implode(', ', $column) . ')';
$lines[] = $this->spaces . ' */';
return implode("\n", $lines);
} | [
"private",
"function",
"generatePropertyDocBlock",
"(",
"array",
"$",
"metadata",
")",
"{",
"$",
"lines",
"=",
"[",
"$",
"this",
"->",
"spaces",
".",
"'/**'",
",",
"$",
"this",
"->",
"spaces",
".",
"' * @var string'",
",",
"$",
"this",
"->",
"spaces",
".",
"' *'",
",",
"]",
";",
"$",
"column",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'property_name'",
"]",
")",
"&&",
"$",
"metadata",
"[",
"'property_name'",
"]",
"!=",
"$",
"metadata",
"[",
"'field_name'",
"]",
")",
"{",
"$",
"column",
"[",
"]",
"=",
"'name=\"'",
".",
"$",
"metadata",
"[",
"'property_name'",
"]",
".",
"'\"'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'property_class'",
"]",
")",
")",
"{",
"$",
"column",
"[",
"]",
"=",
"'class=\"'",
".",
"$",
"metadata",
"[",
"'property_class'",
"]",
".",
"'\"'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'property_multiple'",
"]",
")",
"&&",
"$",
"metadata",
"[",
"'property_multiple'",
"]",
")",
"{",
"$",
"column",
"[",
"]",
"=",
"'multiple=true'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'property_type'",
"]",
")",
"&&",
"$",
"metadata",
"[",
"'annotation'",
"]",
"==",
"'property'",
")",
"{",
"$",
"column",
"[",
"]",
"=",
"'type=\"'",
".",
"$",
"metadata",
"[",
"'property_type'",
"]",
".",
"'\"'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'property_default'",
"]",
")",
")",
"{",
"$",
"column",
"[",
"]",
"=",
"'default=\"'",
".",
"$",
"metadata",
"[",
"'property_default'",
"]",
".",
"'\"'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'property_options'",
"]",
")",
"&&",
"$",
"metadata",
"[",
"'property_options'",
"]",
")",
"{",
"$",
"column",
"[",
"]",
"=",
"'options={'",
".",
"$",
"metadata",
"[",
"'property_options'",
"]",
".",
"'}'",
";",
"}",
"$",
"lines",
"[",
"]",
"=",
"$",
"this",
"->",
"spaces",
".",
"' * @ES\\\\'",
".",
"ucfirst",
"(",
"$",
"metadata",
"[",
"'annotation'",
"]",
")",
".",
"'('",
".",
"implode",
"(",
"', '",
",",
"$",
"column",
")",
".",
"')'",
";",
"$",
"lines",
"[",
"]",
"=",
"$",
"this",
"->",
"spaces",
".",
"' */'",
";",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"}"
] | Returns property doc block
@param array $metadata
@return string | [
"Returns",
"property",
"doc",
"block"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Generator/DocumentGenerator.php#L225-L263 |
ongr-io/ElasticsearchBundle | Generator/DocumentGenerator.php | DocumentGenerator.generateDocumentDocBlock | private function generateDocumentDocBlock(array $metadata)
{
return str_replace(
['<className>', '<annotation>', '<options>'],
[
$this->getClassName($metadata),
ucfirst($metadata['annotation']),
$metadata['annotation'] != 'object' ? ($metadata['type'] != lcfirst($this->getClassName($metadata))
? sprintf('type="%s"', $metadata['type']) : '') : '',
],
'/**
* <className>
*
* @ES\<annotation>(<options>)
*/'
);
} | php | private function generateDocumentDocBlock(array $metadata)
{
return str_replace(
['<className>', '<annotation>', '<options>'],
[
$this->getClassName($metadata),
ucfirst($metadata['annotation']),
$metadata['annotation'] != 'object' ? ($metadata['type'] != lcfirst($this->getClassName($metadata))
? sprintf('type="%s"', $metadata['type']) : '') : '',
],
'/**
* <className>
*
* @ES\<annotation>(<options>)
*/'
);
} | [
"private",
"function",
"generateDocumentDocBlock",
"(",
"array",
"$",
"metadata",
")",
"{",
"return",
"str_replace",
"(",
"[",
"'<className>'",
",",
"'<annotation>'",
",",
"'<options>'",
"]",
",",
"[",
"$",
"this",
"->",
"getClassName",
"(",
"$",
"metadata",
")",
",",
"ucfirst",
"(",
"$",
"metadata",
"[",
"'annotation'",
"]",
")",
",",
"$",
"metadata",
"[",
"'annotation'",
"]",
"!=",
"'object'",
"?",
"(",
"$",
"metadata",
"[",
"'type'",
"]",
"!=",
"lcfirst",
"(",
"$",
"this",
"->",
"getClassName",
"(",
"$",
"metadata",
")",
")",
"?",
"sprintf",
"(",
"'type=\"%s\"'",
",",
"$",
"metadata",
"[",
"'type'",
"]",
")",
":",
"''",
")",
":",
"''",
",",
"]",
",",
"'/**\n * <className>\n *\n * @ES\\<annotation>(<options>)\n */'",
")",
";",
"}"
] | Generates document doc block
@param array $metadata
@return string | [
"Generates",
"document",
"doc",
"block"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Generator/DocumentGenerator.php#L272-L288 |
ongr-io/ElasticsearchBundle | Generator/DocumentGenerator.php | DocumentGenerator.prefixWithSpaces | private function prefixWithSpaces($code)
{
$lines = explode("\n", $code);
foreach ($lines as $key => $value) {
if ($value) {
$lines[$key] = $this->spaces . $lines[$key];
}
}
return implode("\n", $lines);
} | php | private function prefixWithSpaces($code)
{
$lines = explode("\n", $code);
foreach ($lines as $key => $value) {
if ($value) {
$lines[$key] = $this->spaces . $lines[$key];
}
}
return implode("\n", $lines);
} | [
"private",
"function",
"prefixWithSpaces",
"(",
"$",
"code",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"code",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"lines",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"spaces",
".",
"$",
"lines",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"}"
] | @param string $code
@return string | [
"@param",
"string",
"$code"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Generator/DocumentGenerator.php#L295-L306 |
ongr-io/ElasticsearchBundle | Generator/DocumentGenerator.php | DocumentGenerator.getClassName | private function getClassName(array $metadata)
{
return ($pos = strrpos($metadata['name'], '\\'))
? substr($metadata['name'], $pos + 1, strlen($metadata['name'])) : $metadata['name'];
} | php | private function getClassName(array $metadata)
{
return ($pos = strrpos($metadata['name'], '\\'))
? substr($metadata['name'], $pos + 1, strlen($metadata['name'])) : $metadata['name'];
} | [
"private",
"function",
"getClassName",
"(",
"array",
"$",
"metadata",
")",
"{",
"return",
"(",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"metadata",
"[",
"'name'",
"]",
",",
"'\\\\'",
")",
")",
"?",
"substr",
"(",
"$",
"metadata",
"[",
"'name'",
"]",
",",
"$",
"pos",
"+",
"1",
",",
"strlen",
"(",
"$",
"metadata",
"[",
"'name'",
"]",
")",
")",
":",
"$",
"metadata",
"[",
"'name'",
"]",
";",
"}"
] | Returns class name
@param array $metadata
@return string | [
"Returns",
"class",
"name"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Generator/DocumentGenerator.php#L315-L319 |
ongr-io/ElasticsearchBundle | Generator/DocumentGenerator.php | DocumentGenerator.hasMultipleEmbedded | private function hasMultipleEmbedded(array $metadata)
{
foreach ($metadata['properties'] as $prop) {
if ($prop['annotation'] == 'embedded' && isset($prop['property_multiple']) && $prop['property_multiple']) {
return true;
}
}
return false;
} | php | private function hasMultipleEmbedded(array $metadata)
{
foreach ($metadata['properties'] as $prop) {
if ($prop['annotation'] == 'embedded' && isset($prop['property_multiple']) && $prop['property_multiple']) {
return true;
}
}
return false;
} | [
"private",
"function",
"hasMultipleEmbedded",
"(",
"array",
"$",
"metadata",
")",
"{",
"foreach",
"(",
"$",
"metadata",
"[",
"'properties'",
"]",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"$",
"prop",
"[",
"'annotation'",
"]",
"==",
"'embedded'",
"&&",
"isset",
"(",
"$",
"prop",
"[",
"'property_multiple'",
"]",
")",
"&&",
"$",
"prop",
"[",
"'property_multiple'",
"]",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | @param array $metadata
@return bool | [
"@param",
"array",
"$metadata"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Generator/DocumentGenerator.php#L344-L353 |
ongr-io/ElasticsearchBundle | Annotation/Embedded.php | Embedded.dump | public function dump(array $exclude = [])
{
$array = array_diff_key(
array_filter(
get_object_vars($this),
function ($value) {
return $value || is_bool($value);
}
),
array_flip(array_merge(['class', 'name', 'multiple'], $exclude))
);
return array_combine(
array_map(
function ($key) {
return Caser::snake($key);
},
array_keys($array)
),
array_values($array)
);
} | php | public function dump(array $exclude = [])
{
$array = array_diff_key(
array_filter(
get_object_vars($this),
function ($value) {
return $value || is_bool($value);
}
),
array_flip(array_merge(['class', 'name', 'multiple'], $exclude))
);
return array_combine(
array_map(
function ($key) {
return Caser::snake($key);
},
array_keys($array)
),
array_values($array)
);
} | [
"public",
"function",
"dump",
"(",
"array",
"$",
"exclude",
"=",
"[",
"]",
")",
"{",
"$",
"array",
"=",
"array_diff_key",
"(",
"array_filter",
"(",
"get_object_vars",
"(",
"$",
"this",
")",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"||",
"is_bool",
"(",
"$",
"value",
")",
";",
"}",
")",
",",
"array_flip",
"(",
"array_merge",
"(",
"[",
"'class'",
",",
"'name'",
",",
"'multiple'",
"]",
",",
"$",
"exclude",
")",
")",
")",
";",
"return",
"array_combine",
"(",
"array_map",
"(",
"function",
"(",
"$",
"key",
")",
"{",
"return",
"Caser",
"::",
"snake",
"(",
"$",
"key",
")",
";",
"}",
",",
"array_keys",
"(",
"$",
"array",
")",
")",
",",
"array_values",
"(",
"$",
"array",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Annotation/Embedded.php#L60-L81 |
ongr-io/ElasticsearchBundle | Command/IndexCreateCommand.php | IndexCreateCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$manager = $this->getManager($input->getOption('manager'));
$originalIndexName = $manager->getIndexName();
if ($input->getOption('dump')) {
$io->note("Index mappings:");
$io->text(
json_encode(
$manager->getIndexMappings(),
JSON_PRETTY_PRINT
)
);
return 0;
}
if ($input->getOption('time')) {
/** @var IndexSuffixFinder $finder */
$finder = $this->getContainer()->get('es.client.index_suffix_finder');
$finder->setNextFreeIndex($manager);
}
if ($input->getOption('if-not-exists') && $manager->indexExists()) {
$io->note(
sprintf(
'Index `%s` already exists in `%s` manager.',
$manager->getIndexName(),
$input->getOption('manager')
)
);
return 0;
}
$manager->createIndex($input->getOption('no-mapping'));
$io->text(
sprintf(
'Created `<comment>%s</comment>` index for the `<comment>%s</comment>` manager. ',
$manager->getIndexName(),
$input->getOption('manager')
)
);
if ($input->getOption('alias') && $originalIndexName != $manager->getIndexName()) {
$params['body'] = [
'actions' => [
[
'add' => [
'index' => $manager->getIndexName(),
'alias' => $originalIndexName,
]
]
]
];
$message = 'Created an alias `<comment>'.$originalIndexName.'</comment>` for the `<comment>'.
$manager->getIndexName().'</comment>` index. ';
if ($manager->getClient()->indices()->existsAlias(['name' => $originalIndexName])) {
$currentAlias = $manager->getClient()->indices()->getAlias(
[
'name' => $originalIndexName,
]
);
$indexesToRemoveAliases = implode(',', array_keys($currentAlias));
if (!empty($indexesToRemoveAliases)) {
$params['body']['actions'][]['remove'] = [
'index' => $indexesToRemoveAliases,
'alias' => $originalIndexName,
];
$message .= 'Removed `<comment>'.$originalIndexName.'</comment>` alias from `<comment>'.
$indexesToRemoveAliases.'</comment>` index(es).';
}
}
$manager->getClient()->indices()->updateAliases($params);
$io->text($message);
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$manager = $this->getManager($input->getOption('manager'));
$originalIndexName = $manager->getIndexName();
if ($input->getOption('dump')) {
$io->note("Index mappings:");
$io->text(
json_encode(
$manager->getIndexMappings(),
JSON_PRETTY_PRINT
)
);
return 0;
}
if ($input->getOption('time')) {
/** @var IndexSuffixFinder $finder */
$finder = $this->getContainer()->get('es.client.index_suffix_finder');
$finder->setNextFreeIndex($manager);
}
if ($input->getOption('if-not-exists') && $manager->indexExists()) {
$io->note(
sprintf(
'Index `%s` already exists in `%s` manager.',
$manager->getIndexName(),
$input->getOption('manager')
)
);
return 0;
}
$manager->createIndex($input->getOption('no-mapping'));
$io->text(
sprintf(
'Created `<comment>%s</comment>` index for the `<comment>%s</comment>` manager. ',
$manager->getIndexName(),
$input->getOption('manager')
)
);
if ($input->getOption('alias') && $originalIndexName != $manager->getIndexName()) {
$params['body'] = [
'actions' => [
[
'add' => [
'index' => $manager->getIndexName(),
'alias' => $originalIndexName,
]
]
]
];
$message = 'Created an alias `<comment>'.$originalIndexName.'</comment>` for the `<comment>'.
$manager->getIndexName().'</comment>` index. ';
if ($manager->getClient()->indices()->existsAlias(['name' => $originalIndexName])) {
$currentAlias = $manager->getClient()->indices()->getAlias(
[
'name' => $originalIndexName,
]
);
$indexesToRemoveAliases = implode(',', array_keys($currentAlias));
if (!empty($indexesToRemoveAliases)) {
$params['body']['actions'][]['remove'] = [
'index' => $indexesToRemoveAliases,
'alias' => $originalIndexName,
];
$message .= 'Removed `<comment>'.$originalIndexName.'</comment>` alias from `<comment>'.
$indexesToRemoveAliases.'</comment>` index(es).';
}
}
$manager->getClient()->indices()->updateAliases($params);
$io->text($message);
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"io",
"=",
"new",
"SymfonyStyle",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"getManager",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'manager'",
")",
")",
";",
"$",
"originalIndexName",
"=",
"$",
"manager",
"->",
"getIndexName",
"(",
")",
";",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'dump'",
")",
")",
"{",
"$",
"io",
"->",
"note",
"(",
"\"Index mappings:\"",
")",
";",
"$",
"io",
"->",
"text",
"(",
"json_encode",
"(",
"$",
"manager",
"->",
"getIndexMappings",
"(",
")",
",",
"JSON_PRETTY_PRINT",
")",
")",
";",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'time'",
")",
")",
"{",
"/** @var IndexSuffixFinder $finder */",
"$",
"finder",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'es.client.index_suffix_finder'",
")",
";",
"$",
"finder",
"->",
"setNextFreeIndex",
"(",
"$",
"manager",
")",
";",
"}",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'if-not-exists'",
")",
"&&",
"$",
"manager",
"->",
"indexExists",
"(",
")",
")",
"{",
"$",
"io",
"->",
"note",
"(",
"sprintf",
"(",
"'Index `%s` already exists in `%s` manager.'",
",",
"$",
"manager",
"->",
"getIndexName",
"(",
")",
",",
"$",
"input",
"->",
"getOption",
"(",
"'manager'",
")",
")",
")",
";",
"return",
"0",
";",
"}",
"$",
"manager",
"->",
"createIndex",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'no-mapping'",
")",
")",
";",
"$",
"io",
"->",
"text",
"(",
"sprintf",
"(",
"'Created `<comment>%s</comment>` index for the `<comment>%s</comment>` manager. '",
",",
"$",
"manager",
"->",
"getIndexName",
"(",
")",
",",
"$",
"input",
"->",
"getOption",
"(",
"'manager'",
")",
")",
")",
";",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'alias'",
")",
"&&",
"$",
"originalIndexName",
"!=",
"$",
"manager",
"->",
"getIndexName",
"(",
")",
")",
"{",
"$",
"params",
"[",
"'body'",
"]",
"=",
"[",
"'actions'",
"=>",
"[",
"[",
"'add'",
"=>",
"[",
"'index'",
"=>",
"$",
"manager",
"->",
"getIndexName",
"(",
")",
",",
"'alias'",
"=>",
"$",
"originalIndexName",
",",
"]",
"]",
"]",
"]",
";",
"$",
"message",
"=",
"'Created an alias `<comment>'",
".",
"$",
"originalIndexName",
".",
"'</comment>` for the `<comment>'",
".",
"$",
"manager",
"->",
"getIndexName",
"(",
")",
".",
"'</comment>` index. '",
";",
"if",
"(",
"$",
"manager",
"->",
"getClient",
"(",
")",
"->",
"indices",
"(",
")",
"->",
"existsAlias",
"(",
"[",
"'name'",
"=>",
"$",
"originalIndexName",
"]",
")",
")",
"{",
"$",
"currentAlias",
"=",
"$",
"manager",
"->",
"getClient",
"(",
")",
"->",
"indices",
"(",
")",
"->",
"getAlias",
"(",
"[",
"'name'",
"=>",
"$",
"originalIndexName",
",",
"]",
")",
";",
"$",
"indexesToRemoveAliases",
"=",
"implode",
"(",
"','",
",",
"array_keys",
"(",
"$",
"currentAlias",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"indexesToRemoveAliases",
")",
")",
"{",
"$",
"params",
"[",
"'body'",
"]",
"[",
"'actions'",
"]",
"[",
"]",
"[",
"'remove'",
"]",
"=",
"[",
"'index'",
"=>",
"$",
"indexesToRemoveAliases",
",",
"'alias'",
"=>",
"$",
"originalIndexName",
",",
"]",
";",
"$",
"message",
".=",
"'Removed `<comment>'",
".",
"$",
"originalIndexName",
".",
"'</comment>` alias from `<comment>'",
".",
"$",
"indexesToRemoveAliases",
".",
"'</comment>` index(es).'",
";",
"}",
"}",
"$",
"manager",
"->",
"getClient",
"(",
")",
"->",
"indices",
"(",
")",
"->",
"updateAliases",
"(",
"$",
"params",
")",
";",
"$",
"io",
"->",
"text",
"(",
"$",
"message",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/Command/IndexCreateCommand.php#L57-L137 |
ongr-io/ElasticsearchBundle | DependencyInjection/Configuration.php | Configuration.getConfigTreeBuilder | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('ongr_elasticsearch');
$rootNode
->children()
->booleanNode('cache')
->info(
'Enables cache handler to store metadata and other data to the cache. '.
'By default it is enabled in prod environment and disabled in dev.'
)
->end()
->booleanNode('profiler')
->info(
'Enables ElasticsearchBundle query profiler. Default value is kernel.debug parameter. '.
'If profiler is disabled the tracer service will be disabled as well.'
)
->end()
->append($this->getAnalysisNode())
->append($this->getManagersNode())
->end();
return $treeBuilder;
} | php | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('ongr_elasticsearch');
$rootNode
->children()
->booleanNode('cache')
->info(
'Enables cache handler to store metadata and other data to the cache. '.
'By default it is enabled in prod environment and disabled in dev.'
)
->end()
->booleanNode('profiler')
->info(
'Enables ElasticsearchBundle query profiler. Default value is kernel.debug parameter. '.
'If profiler is disabled the tracer service will be disabled as well.'
)
->end()
->append($this->getAnalysisNode())
->append($this->getManagersNode())
->end();
return $treeBuilder;
} | [
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
")",
";",
"$",
"rootNode",
"=",
"$",
"treeBuilder",
"->",
"root",
"(",
"'ongr_elasticsearch'",
")",
";",
"$",
"rootNode",
"->",
"children",
"(",
")",
"->",
"booleanNode",
"(",
"'cache'",
")",
"->",
"info",
"(",
"'Enables cache handler to store metadata and other data to the cache. '",
".",
"'By default it is enabled in prod environment and disabled in dev.'",
")",
"->",
"end",
"(",
")",
"->",
"booleanNode",
"(",
"'profiler'",
")",
"->",
"info",
"(",
"'Enables ElasticsearchBundle query profiler. Default value is kernel.debug parameter. '",
".",
"'If profiler is disabled the tracer service will be disabled as well.'",
")",
"->",
"end",
"(",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"getAnalysisNode",
"(",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"getManagersNode",
"(",
")",
")",
"->",
"end",
"(",
")",
";",
"return",
"$",
"treeBuilder",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ongr-io/ElasticsearchBundle/blob/c817dc53d3b93129e8575a740e11484c67f79a87/DependencyInjection/Configuration.php#L26-L50 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.