LdapTools\Event\LdapObjectCreationEvent::setDn PHP Method

setDn() public method

Set the DN to be used for the LDAP object. This is only relevant for the 'before create' event.
public setDn ( string | null $dn )
$dn string | null
    public function setDn($dn)
    {
        $this->dn = $dn;
    }

Usage Example

 function it_should_call_creation_events_when_creating_a_ldap_object(EventDispatcherInterface $dispatcher, $connection)
 {
     $this->addOperation->setLocation('dc=foo,dc=bar');
     $connection->execute($this->addOperation)->willReturn(true);
     $beforeEvent = new LdapObjectCreationEvent(Event::LDAP_OBJECT_BEFORE_CREATE);
     $beforeEvent->setContainer('dc=foo,dc=bar');
     $beforeEvent->setData(['username' => '%foo%', 'password' => '%bar%']);
     $beforeEvent->setDn('');
     $afterEvent = new LdapObjectCreationEvent(Event::LDAP_OBJECT_AFTER_CREATE);
     $afterEvent->setContainer('dc=foo,dc=bar');
     $afterEvent->setData(['username' => 'somedude', 'password' => '12345']);
     $afterEvent->setDn('cn=somedude,dc=foo,dc=bar');
     $dispatcher->dispatch($beforeEvent)->shouldBeCalled();
     $dispatcher->dispatch($afterEvent)->shouldBeCalled();
     $this->config->setSchemaName('ad');
     $this->beConstructedWith($connection, $this->schemaFactory, $dispatcher);
     $this->createUser()->with(['username' => '%foo%', 'password' => '%bar%'])->in('dc=foo,dc=bar')->setParameter('foo', 'somedude')->setParameter('bar', '12345');
     $this->execute();
 }
All Usage Examples Of LdapTools\Event\LdapObjectCreationEvent::setDn