Last active
April 7, 2020 12:50
-
-
Save ptsakyrellis/c81538755ec178736c1e277a7c50deb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyApp\DataFixtures; | |
use Doctrine\Bundle\FixturesBundle\Fixture; | |
use Doctrine\Persistence\ObjectManager; | |
use Symfony\Component\Ldap\Entry; | |
use Symfony\Component\Ldap\Ldap; | |
class LdapUserFixtures extends Fixture | |
{ | |
public function load(ObjectManager $manager) | |
{ | |
$ldap = Ldap::create('ext_ldap', ['connection_string' => 'ldap://sf4ldap:389']); | |
$ldap->bind('cn=admin,dc=sf4app,dc=org', 'myadminpasswd'); | |
$entryManager = $ldap->getEntryManager(); | |
// Adding Organizational Unit | |
$ou = new Entry('ou=People,dc=sf4app,dc=org', ['objectClass' => ['organizationalUnit'], 'ou' => ['People']]); | |
$entryManager->add($ou); | |
$entries = [ | |
new Entry( | |
'cn=user1,ou=People,dc=sf4app,dc=org', | |
[ | |
'objectClass' => ['personnel'], | |
'sn' => ['My User1'], | |
'cn' => ['user1'], | |
'mail' => ['[email protected]'], | |
'myadditionnalAttr' => ['Value1'], | |
'myadditionnalAttr2' => ['Value2'] | |
] | |
), | |
new Entry( | |
'cn=user2,ou=People,dc=sf4app,dc=org', | |
[ | |
'objectClass' => ['personnel'], | |
'sn' => ['My User2'], | |
'cn' => ['user2'], | |
'mail' => ['[email protected]'], | |
'myadditionnalAttr' => ['Value1'], | |
'myadditionnalAttr2' => ['Value2'] | |
] | |
) | |
]; | |
foreach ($entries as $entry) { | |
$entryManager->add($entry); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment