adLDAPCollection.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * PHP LDAP CLASS FOR MANIPULATING ACTIVE DIRECTORY
  4. * Version 4.0.4
  5. *
  6. * PHP Version 5 with SSL and LDAP support
  7. *
  8. * Written by Scott Barnett, Richard Hyland
  9. * email: scott@wiggumworld.com, adldap@richardhyland.com
  10. * http://adldap.sourceforge.net/
  11. *
  12. * Copyright (c) 2006-2012 Scott Barnett, Richard Hyland
  13. *
  14. * We'd appreciate any improvements or additions to be submitted back
  15. * to benefit the entire community :)
  16. *
  17. * This library is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU Lesser General Public
  19. * License as published by the Free Software Foundation; either
  20. * version 2.1 of the License.
  21. *
  22. * This library is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. * Lesser General Public License for more details.
  26. *
  27. * @category ToolsAndUtilities
  28. * @package adLDAP
  29. * @subpackage Collection
  30. * @author Scott Barnett, Richard Hyland
  31. * @copyright (c) 2006-2012 Scott Barnett, Richard Hyland
  32. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html LGPLv2.1
  33. * @revision $Revision: 97 $
  34. * @version 4.0.4
  35. * @link http://adldap.sourceforge.net/
  36. */
  37. abstract class adLDAPCollection
  38. {
  39. /**
  40. * The current adLDAP connection via dependency injection
  41. *
  42. * @var adLDAP
  43. */
  44. protected $adldap;
  45. /**
  46. * The current object being modifed / called
  47. *
  48. * @var mixed
  49. */
  50. protected $currentObject;
  51. /**
  52. * The raw info array from Active Directory
  53. *
  54. * @var array
  55. */
  56. protected $info;
  57. public function __construct($info, adLDAP $adldap)
  58. {
  59. $this->setInfo($info);
  60. $this->adldap = $adldap;
  61. }
  62. /**
  63. * Set the raw info array from Active Directory
  64. *
  65. * @param array $info
  66. */
  67. public function setInfo(array $info)
  68. {
  69. if ($this->info && sizeof($info) >= 1) {
  70. unset($this->info);
  71. }
  72. $this->info = $info;
  73. }
  74. /**
  75. * Magic get method to retrieve data from the raw array in a formatted way
  76. *
  77. * @param string $attribute
  78. * @return mixed
  79. */
  80. public function __get($attribute)
  81. {
  82. if (isset($this->info[0]) && is_array($this->info[0])) {
  83. foreach ($this->info[0] as $keyAttr => $valueAttr) {
  84. if (strtolower($keyAttr) == strtolower($attribute)) {
  85. if ($this->info[0][strtolower($attribute)]['count'] == 1) {
  86. return $this->info[0][strtolower($attribute)][0];
  87. }
  88. else {
  89. $array = array();
  90. foreach ($this->info[0][strtolower($attribute)] as $key => $value) {
  91. if ((string)$key != 'count') {
  92. $array[$key] = $value;
  93. }
  94. }
  95. return $array;
  96. }
  97. }
  98. }
  99. }
  100. else {
  101. return NULL;
  102. }
  103. }
  104. /**
  105. * Magic set method to update an attribute
  106. *
  107. * @param string $attribute
  108. * @param string $value
  109. * @return bool
  110. */
  111. abstract public function __set($attribute, $value);
  112. /**
  113. * Magic isset method to check for the existence of an attribute
  114. *
  115. * @param string $attribute
  116. * @return bool
  117. */
  118. public function __isset($attribute) {
  119. if (isset($this->info[0]) && is_array($this->info[0])) {
  120. foreach ($this->info[0] as $keyAttr => $valueAttr) {
  121. if (strtolower($keyAttr) == strtolower($attribute)) {
  122. return true;
  123. }
  124. }
  125. }
  126. return false;
  127. }
  128. }
  129. ?>