DirectoryTree / LdapRecord

A fully-featured LDAP framework.
https://ldaprecord.com
MIT License
500 stars 44 forks source link

Feature 632 - BASE_DN replacement everywhere #668

Closed stevebauman closed 10 months ago

stevebauman commented 10 months ago

Closes #632

This PR implements base DN substitution in more areas of LdapRecord to increase the convenience of its Active Record implementation -- namely object creation and renaming.

During Creation:

// base_dn = "dc=local,dc=com"

$user = (new User)->inside('ou=Accounting,{base}');

$user->cn = 'John Doe';

$user->save();

echo $user->getDn(); // "cn=John Doe,ou=Accounting,dc=local,dc=com"

During Rename:

// base_dn = "dc=local,dc=com"

$user = User::find('cn=John Doe,{base}');

$user->rename('Jane Doe', 'ou=Accounting,{base}');

echo $user->getDn(); // "cn=Jane Doe,ou=Accounting,dc=local,dc=com"

@lukas-staab Are there other places you would find base DN substitution useful? I thought of performing replacements inside of attributes during object creates/updates, but a bit concerned that could impact performance since we would have to cycle through all given attributes each time.

lukas-staab commented 10 months ago

Hi Steve, inside every Attribute feels a bit to much for me as well, especially with the attach() methods it should be fine without (thinking about group memberships right now).

My original use case was that I wanted a object / class which knows where its personal root is. E.g. a set of groups which live in a special OU as siblings to each other. So if I create an object, or search with the query builder, the object knows where to search or instert by default. This is probably (better) doable with a global scope to the class right now.

All in all this will be a lot easier with this change. Thanks a lot!

stevebauman commented 10 months ago

Hey Lukas, thanks for the reply! Ok great, I'm glad this will work for you. If you end up requiring it in any additional areas, drop by and give me a shout! 🙏