Ejemplo n.º 1
0
 function testGetChildForPrincipal()
 {
     $pBackend = new DAVACL\PrincipalBackend\Mock();
     $cBackend = new Backend\Mock();
     $root = new AddressBookRoot($pBackend, $cBackend);
     $children = $root->getChildren();
     $this->assertEquals(3, count($children));
     $this->assertInstanceOf('Sabre\\CardDAV\\AddressBookHome', $children[0]);
     $this->assertEquals('user1', $children[0]->getName());
 }
Ejemplo n.º 2
0
 function getName()
 {
     if ($this->principalPrefix === 'principals') {
         return parent::getName();
     }
     // Grabbing all the components of the principal path.
     $parts = explode('/', $this->principalPrefix);
     // We are only interested in the second part.
     return $parts[1];
 }
Ejemplo n.º 3
0
 /**
  * This method returns a node for a principal.
  *
  * The passed array contains principal information, and is guaranteed to
  * at least contain a uri item. Other properties may or may not be
  * supplied by the authentication backend.
  *
  * @param array $principal
  * @return \Sabre\DAV\INode
  */
 function getChildForPrincipal(array $principal)
 {
     $node = parent::getChildForPrincipal($principal);
     /*
      * Création du carnet d'adresse par défaut s'il n'existe pas
      */
     if (!$node || count($node->getChildren()) == 0) {
         //No addressBook. Create default one
         $principalUri = $principal["uri"];
         list(, $principalId) = \Sabre\HTTP\URLUtil::splitPath($principalUri);
         $name = "contacts";
         $properties = ['{DAV:}displayname' => $name, '{' . \Sabre\CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => "Contacts de " . $principalId];
         $this->carddavBackend->createAddressBook($principalUri, $name, $properties);
         $node = parent::getChildForPrincipal($principal);
     }
     return $node;
 }