12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace Mall\Framework\SearchClient;
- class Mapping {
- protected $properties = array();
- protected $config = array();
-
- public function __construct(array $properties = array(), array $config = array()) {
- $this->properties = $properties;
- $this->config = $config;
- }
-
- public function export() {
- return array(
- 'properties' => $this->properties
- );
- }
-
- public function field($field, $config = array()) {
- if (is_string($config)) $config = array('type' => $config);
- $this->properties[$field] = $config;
- return $this;
- }
-
- public function config($key, $value = null) {
- if (is_array($key))
- $this->config = $key + $this->config;
- else {
- if ($value !== null) $this->config[$key] = $value;
- if (!isset($this->config[$key]))
- throw new \Exception("Configuration key `type` is not set");
- return $this->config[$key];
- }
- }
- }
|