Esempio n. 1
0
 /**
  * Initializes the created object.
  *
  * @param object $factory  an object factory implementing "get" as described in \jackalope\Factory
  * @param TransportInterface $transport
  */
 public function __construct($factory, TransportInterface $transport)
 {
     $this->factory = $factory;
     $this->transport = $transport;
     $this->namespaceManager = $this->factory->get('NamespaceManager', array($this->defaultNamespaces));
     $namespaces = $transport->getNamespaces();
     foreach ($namespaces as $prefix => $uri) {
         if (!array_key_exists($prefix, $this->defaultNamespaces)) {
             $this->userNamespaces[$prefix] = $uri;
         }
     }
 }
Esempio n. 2
0
 /**
  * Email a message without encrypting it.
  *
  * @param Message $message The message data
  * @param bool $force      Send even if we don't have a private key?
  */
 public function sendUnencrypted(Message $message, bool $force = false)
 {
     if (!$this->serverKeyFingerprint) {
         if ($force) {
             // Unencrypted, unsigned
             $message->setBody($message->getBodyText());
         }
         return;
     }
     $this->mailer->send($this->sign($message));
 }
Esempio n. 3
0
 public function register(TransportInterface $transport)
 {
     $this->transports[$transport->getname()] = $transport;
 }
Esempio n. 4
0
 /**
  * Push all recorded changes to the backend.
  *
  * The order is important to avoid conflicts
  * 1. remove nodes
  * 2. move nodes
  * 3. add new nodes
  * 4. commit any other changes
  *
  * @return void
  */
 public function save()
 {
     // TODO: start transaction
     // remove nodes/properties
     foreach ($this->itemsRemove as $path => $dummy) {
         $this->transport->deleteNode($path);
     }
     // move nodes/properties
     foreach ($this->nodesMove as $src => $dst) {
         $this->transport->moveNode($src, $dst);
     }
     // filter out sub-nodes and sub-properties since the top-most nodes that are
     // added will create all sub-nodes and sub-properties at once
     $nodesToCreate = $this->itemsAdd;
     foreach ($nodesToCreate as $path => $dummy) {
         foreach ($nodesToCreate as $path2 => $dummy) {
             if (strpos($path2, $path . '/') === 0) {
                 unset($nodesToCreate[$path2]);
             }
         }
     }
     // create new nodes
     foreach ($nodesToCreate as $path => $dummy) {
         $item = $this->getNodeByPath($path);
         if ($item instanceof \PHPCR\NodeInterface) {
             $this->transport->storeNode($path, $item->getProperties(), $item->getNodes());
         } elseif ($item instanceof \PHPCR\PropertyInterface) {
             $this->transport->storeProperty($path, $item);
         } else {
             throw new \UnexpectedValueException('Unknown type ' . get_class($item));
         }
     }
     // loop through cached nodes and commit all dirty and set them to clean.
     if (isset($this->objectsByPath['Node'])) {
         foreach ($this->objectsByPath['Node'] as $path => $item) {
             if ($item->isModified()) {
                 if ($item instanceof \PHPCR\NodeInterface) {
                     foreach ($item->getProperties() as $propertyName => $property) {
                         if ($property->isModified()) {
                             $this->transport->storeProperty($property->getPath(), $property);
                         }
                     }
                 } elseif ($item instanceof \PHPCR\PropertyInterface) {
                     if ($item->getNativeValue() === null) {
                         $this->transport->deleteProperty($path);
                     } else {
                         $this->transport->storeProperty($path, $item);
                     }
                 } else {
                     throw new \UnexpectedValueException('Unknown type ' . get_class($item));
                 }
             }
         }
     }
     // TODO: have a davex client method to commit transaction
     // commit changes to the local state
     foreach ($this->itemsRemove as $path => $dummy) {
         unset($this->objectsByPath['Node'][$path]);
     }
     /* local state is already updated in moveNode
        foreach ($this->nodesMove as $src => $dst) {
            $this->objectsByPath[$dst] = $this->objectsByPath[$src];
            unset($this->objectsByPath[$src]);
        }
         */
     foreach ($this->itemsAdd as $path => $dummy) {
         $item = $this->getNodeByPath($path);
         $item->confirmSaved();
     }
     if (isset($this->objectsByPath['Node'])) {
         foreach ($this->objectsByPath['Node'] as $path => $item) {
             if ($item->isModified()) {
                 $item->confirmSaved();
             }
         }
     }
     $this->itemsRemove = array();
     $this->nodesMove = array();
     $this->itemsAdd = array();
 }
Esempio n. 5
0
 /**
  * Creates a socket signature.
  *
  * @param string $channel
  * @param string $socketId
  * @param array|bool  $customData
  * @return string
  */
 public function socketSignature($channel, $socketId, $customData = false)
 {
     $this->validateSocketId($socketId);
     $this->validateChannel($channel);
     return json_encode($this->transport->getSocketSignature($channel, $socketId, $customData));
 }
Esempio n. 6
0
 public function testSendReturnsFluentInterfaceOnSuccess()
 {
     $this->transport->expects($this->once())->method('write')->will($this->returnSelf());
     $this->mapper->expects($this->once())->method('mapOut')->will($this->returnValue('{"bar":1}'));
     $this->assertInstanceOf('Chippyash\\SDO\\AbstractSDO', $this->sut->send());
 }