Exemplo n.º 1
0
 /**
  * Add a customization
  *
  * Supports a Customization instance or a config array, in that case a new
  * Customization instance wil be created based on the options.
  *
  * @param Solarium_Plugin_CustomizeRequest_Customization|array $customization
  * @return Solarium_Plugin_CustomizeRequest Provides fluent interface
  */
 public function addCustomization($customization)
 {
     if (is_array($customization)) {
         $customization = new Solarium_Plugin_CustomizeRequest_Customization($customization);
     }
     $key = $customization->getKey();
     if (0 === strlen($key)) {
         throw new Solarium_Exception('A Customization must have a key value');
     }
     if (array_key_exists($key, $this->_customizations)) {
         if ($this->_customizations[$key] === $customization) {
             //double add calls for the same customization are ignored
             //@todo add trigger_error with a notice?
         } else {
             throw new Solarium_Exception('A Customization must have a unique key value');
         }
     } else {
         $this->_customizations[$key] = $customization;
     }
     return $this;
 }
Exemplo n.º 2
0
 public function testSetAndGetKey()
 {
     $value = 'mykey';
     $this->_instance->setKey($value);
     $this->assertEquals($value, $this->_instance->getKey());
 }
 /**
  * Add a customization
  *
  * Supports a Customization instance or a config array, in that case a new
  * Customization instance wil be created based on the options.
  *
  * @param Solarium_Plugin_CustomizeRequest_Customization|array $customization
  * @return Solarium_Plugin_CustomizeRequest Provides fluent interface
  */
 public function addCustomization($customization)
 {
     if (is_array($customization)) {
         $customization = new Solarium_Plugin_CustomizeRequest_Customization($customization);
     }
     $key = $customization->getKey();
     // check for non-empty key
     if (0 === strlen($key)) {
         throw new Solarium_Exception('A Customization must have a key value');
     }
     // check for a unique key
     if (array_key_exists($key, $this->_customizations)) {
         //double add calls for the same customization are ignored, others cause an exception
         if ($this->_customizations[$key] !== $customization) {
             throw new Solarium_Exception('A Customization must have a unique key value');
         }
     }
     $this->_customizations[$key] = $customization;
     return $this;
 }