forked from FriendsOfSymfony/FOSElasticaBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of index template support FriendsOfSymfony#916
- Loading branch information
1 parent
ff88482
commit 13617c5
Showing
21 changed files
with
644 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
/* | ||
* This file is part of the OpCart software. | ||
* | ||
* (c) 2015, OpticsPlanet, Inc | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\ElasticaBundle\Configuration; | ||
|
||
/** | ||
* Index configuration abstract class | ||
* | ||
* @author Dmitry Balabka <[email protected]> | ||
*/ | ||
class IndexConfigAbstract | ||
{ | ||
/** | ||
* The name of the index for ElasticSearch. | ||
* | ||
* @var string | ||
*/ | ||
protected $elasticSearchName; | ||
|
||
/** | ||
* The internal name of the index. May not be the same as the name used in ElasticSearch, | ||
* especially if aliases are enabled. | ||
* | ||
* @var string | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* An array of settings sent to ElasticSearch when creating the index. | ||
* | ||
* @var array | ||
*/ | ||
protected $settings; | ||
|
||
/** | ||
* All types that belong to this index. | ||
* | ||
* @var TypeConfig[] | ||
*/ | ||
protected $types; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getElasticSearchName() | ||
{ | ||
return $this->elasticSearchName; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getSettings() | ||
{ | ||
return $this->settings; | ||
} | ||
|
||
/** | ||
* @param string $typeName | ||
* | ||
* @return TypeConfig | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function getType($typeName) | ||
{ | ||
if (!array_key_exists($typeName, $this->types)) { | ||
throw new \InvalidArgumentException(sprintf('Type "%s" does not exist on index "%s"', $typeName, $this->name)); | ||
} | ||
|
||
return $this->types[$typeName]; | ||
} | ||
|
||
/** | ||
* @return \FOS\ElasticaBundle\Configuration\TypeConfig[] | ||
*/ | ||
public function getTypes() | ||
{ | ||
return $this->types; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace FOS\ElasticaBundle\Configuration; | ||
|
||
/** | ||
* Index template configuration class | ||
* | ||
* @author Dmitry Balabka <[email protected]> | ||
*/ | ||
class IndexTemplateConfig extends IndexConfigAbstract | ||
{ | ||
/** | ||
* Index name pattern | ||
* | ||
* @var string | ||
*/ | ||
private $template; | ||
|
||
/** | ||
* Constructor expects an array as generated by the Container Configuration builder. | ||
* | ||
* @param string $name | ||
* @param TypeConfig[] $types | ||
* @param array $config | ||
*/ | ||
public function __construct($name, array $types, array $config) | ||
{ | ||
$this->elasticSearchName = isset($config['elasticSearchName']) ? $config['elasticSearchName'] : $name; | ||
$this->name = $name; | ||
$this->settings = isset($config['settings']) ? $config['settings'] : array(); | ||
if (!isset($config['template'])) { | ||
throw new \InvalidArgumentException('Index template value must be set'); | ||
} | ||
$this->template = $config['template']; | ||
$this->types = $types; | ||
} | ||
|
||
/** | ||
* Gets index name pattern | ||
* | ||
* @return string | ||
*/ | ||
public function getTemplate() | ||
{ | ||
return $this->template; | ||
} | ||
} |
Oops, something went wrong.