isValidOperation() public static method

Deterimine if an operation is valid
public static isValidOperation ( string $operation )
$operation string
Ejemplo n.º 1
0
 /**
  * Add an operation
  * 
  * @param string $operation
  * @param array $data
  */
 public function addOperation($operation, $property = null, $value = null)
 {
     // Make sure the operation is valid
     if (!Shanty_Mongo::isValidOperation($operation)) {
         require_once 'Shanty/Mongo/Exception.php';
         throw new Shanty_Mongo_Exception("'{$operation}' is not valid operation");
     }
     // Prime the specific operation
     if (!array_key_exists($operation, $this->_operations)) {
         $this->_operations[$operation] = array();
     }
     // Save the operation
     if (is_null($property)) {
         $path = $this->getPathToDocument();
     } else {
         $path = $this->getPathToProperty($property);
     }
     // Mix operation with existing operations if needed
     switch ($operation) {
         case '$pushAll':
         case '$pullAll':
             if (!array_key_exists($path, $this->_operations[$operation])) {
                 break;
             }
             $value = array_merge($this->_operations[$operation][$path], $value);
             break;
     }
     $this->_operations[$operation][$path] = $value;
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider validOperations
  */
 public function testValidOperation($operation)
 {
     $this->assertTrue(Shanty_Mongo::isValidOperation($operation));
     $this->assertFalse(Shanty_Mongo::isValidOperation('non valid op'));
 }