1. Go to this page and download the library: Download l3/ldap-user-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
l3 / ldap-user-bundle example snippets
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new OpenLdapObject\Bundle\LdapObjectBundle\OpenLdapObjectLdapObjectBundle(),
new L3\Bundle\LdapUserBundle\L3LdapUserBundle(),
);
// ...
}
// ...
}
# src/YourApplicationBundle/Entity/People.php
namespace YourApplicationBundle\Entity;
use OpenLdapObject\Entity;
use OpenLdapObject\Annotations as OLO;
/**
* @OLO\Dn(value="ou=people")
* @OLO\Entity({"inetOrgPerson"})
*/
class People extends Entity {
/**
* @OLO\Column(type="string")
* @OLO\Index
*/
protected $uid;
/**
* @OLO\Column(type="array")
*/
protected $cn;
/**
* @OLO\Column(type="array")
*/
protected $sn;
/**
* @OLO\Column(type="string")
*/
protected $givenName;
/**
* @OLO\Column(type="string")
*/
protected $mail;
/**
* @OLO\Column(type="array")
*/
protected $memberOf;
/**
* @OLO\Column(type="string")
*/
protected $eduPersonPrimaryAffiliation;
public function getFirstCn() {
return $this->cn[0];
}
public function getUid() {
return $this->uid;
}
public function setUid($value) {
$this->uid = $value;
return $this;
}
public function getCn() {
return $this->cn;
}
public function addCn($value) {
$this->cn->add($value);
return $this;
}
public function removeCn($value) {
$this->cn->removeElement($value);
return $this;
}
public function getSn() {
return $this->sn;
}
public function addSn($value) {
$this->sn->add($value);
return $this;
}
public function removeSn($value) {
$this->sn->removeElement($value);
return $this;
}
public function getGivenName() {
return $this->givenName;
}
public function setGivenName($value) {
$this->givenName = $value;
return $this;
}
public function getMail() {
return $this->mail;
}
public function setMail($value) {
$this->mail = $value;
return $this;
}
public function addMemberOf($value) {
$this->memberOf->add($value);
return $this;
}
public function removeMemberOf($value) {
$this->memberOf->removeElement($value);
return $this;
}
public function getMemberOf() {
return $this->memberOf;
}
public function getEduPersonPrimaryAffiliation() {
return $this->eduPersonPrimaryAffiliation;
}
public function setEduPersonPrimaryAffiliation($value) {
$this->eduPersonPrimaryAffiliation = $value;
return $this;
}
}
# src/YourApplicationBundle/Controller/DefaultController.php
namespace YourApplicationBundle\Controller;
...
use YourApplication\Entity\People;
...
class DefaultController extends Controller {
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
...
// type of the people (student ? employee ? ..etc)
$profil = $this->get('ldap_object.manager')->getRepository('YourApplicationBundle\Entity\People')->find($this->getUser()->getUid());
if ($profil != null){
$profil = $profil->getEduPersonPrimaryAffiliation();
}
...
}
}
# src/YourApplicationBundle/Controller/DefaultController.php
namespace YourApplicationBundle\Controller;
...
use YourApplication\Entity\People;
...
class DefaultController extends Controller {
/**
* @Route("/", name="homepage")
*/
#[Route('/', name='homepage')]
public function indexAction(Request $request)
{
...
// type of the people (student ? employee ? ..etc)
$profil = $this->get('ldap_object.manager')->getRepository('YourApplicationBundle\Entity\People')->find($this->getUser()->getUid());
if ($profil != null){
$profil = $profil->getEduPersonPrimaryAffiliation();
}
...
}
}
# src/YourApplicationBundle/Controller/DefaultController.php
namespace YourApplicationBundle\Controller;
...
use YourApplication\Entity\People;
...
class DefaultController extends Controller {
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
...
$p = new People();
$p->setUid('P7279');
$p->setGivenName('Mathieu');
$p->addSn('Hetru');
$em = $this->get('ldap_object.manager');
$em->persist($p);
$em->flush();
...
}
}
# src/YourApplicationBundle/Controller/DefaultController.php
namespace YourApplicationBundle\Controller;
...
use YourApplication\Entity\People;
...
class DefaultController extends Controller {
#[Route('/', name='homepage')]
public function indexAction(Request $request)
{
...
$a = new People();
$a->setUid('1940');
$a->setGivenName('Mathieu');
$a->addSn('Hetru');
$em = $this->get('ldap_object.manager');
$em->persist($a);
$em->flush();
...
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.