avadaneidanut/ldapquery 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

avadaneidanut/ldapquery

Composer 安装命令:

composer require avadaneidanut/ldapquery

包简介

A light weight package for easily building LDAP advanced filter queries.

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

LDAP Query Builder is simple tool for easily generate queries for LDAP filtering. Quick example:

$query = \LdapQuery\Builder::create()->where('attrBar', 'value')
    ->where('attrFoo', '<>' 'value2')
    ->orWhere('attrBaz', [1, 2, 3, 4, 5, 6, 7, 8, 9])
    ->where(function($builder) {
        $builder->where('bla', 'bla2')
            ->orWhere('bla3', 'bla1');
    })
    ->stringify()
;

Output:

(&(|(&(attrBar=value)(!(attrFoo=value2)))(|(attrBaz=1)(attrBaz=2)(attrBaz=3)(attrBaz=4)(attrBaz=5)(attrBaz=6)(attrBaz=7)(attrBaz=8)(attrBaz=9)))(|(bla=bla2)(bla3=bla1)))

If you want to examine queries generated and don't manually separate groups just:

$builder = new \LdapQuery\Builder;
$builder->where('attrBar', 'value')
    ->where('attrFoo', '<>' 'value2')
    ->orWhere('attrBaz', [1, 2, 3, 4, 5, 6, 7, 8, 9])
    ->where(function($builder) {
        $builder->where('bla', 'bla2')
            ->orWhere('bla3', 'bla1');
    });

$builder->toArray(); # will generate a nice output

Output:

(&
   (|
      (&
         (attrBar=value)
         (!
             (attrFoo=value2)
         )
      )
      (|
         (attrBaz=1)
         (attrBaz=2)
         (attrBaz=3)
         (attrBaz=4)
         (attrBaz=5)
         (attrBaz=6)
         (attrBaz=7)
         (attrBaz=8)
         (attrBaz=9)
      )
   )
   (|
      (bla=bla2)
      (bla3=bla1)
   )
)

Usage with sympfony ldap component:

use LdapQuery\Builder;
use Symfony\Component\Ldap\LdapClient;

$client = new LdapClient('ldap.example.com');
$client->bind('uid=AB1234,ou=people,o=world', 'secretpassword');

$builder = new Builder;

$details = $client->find(
    'ou=people,o=world',
    (string)$builder->where('uid', 'AB123*')->where('cn', '~=','*Danut*'),
    ['uid','cn','mail','office','mobile']
);

Available methods on Builder class

/**
 * Add a where clause to the LDAP Query. Defaulted to & logical, acts like a andWhere.
 * 
 * @param  string|Closure    $attribute
 * @param  string|array|null $operator
 * @param  string|array|null $value
 * @param  string|null       $wildcard
 * @param  bool              $escape
 * @param  string            $logical
 *
 * @return $this
 *
 * @throws GrammarException
 */
public function where($attribute, $operator = null, $value = null, $wildcard = null, $escape = true, $negation = false, $logical = '&');
    
/**
 * Add a or where clause to the LDAP Query.
 * 
 * @param  string|Closure   $attribute
 * @param  string|array|null $operator
 * @param  string|array|null $value
 * @param  string|null       $wildcard
 * @param  bool              $escape
 *
 * @return $this
 *
 * @throws GrammarException
 */
public function orWhere($attribute, $operator = null, $value = null, $wildcard = null, $escape = true, $negation = false);

/**
 * Convert Group object to a string, LDAP valid query group.
 * 
 * @return string
 */
public function stringify();

/**
 * Convert Builder object to array.
 * 
 * @return array
 */
public function toArray();

Dynamic where clauses

LdapQuery\Builder class has plenty dynamic "where clauses" that are transformed automatically calls to "where" or "orWhere" methods with arguments translatted from method name. This can be used as any other method example:

$builder->orWhereBegins('attribute', 'value'); will be translated in
$builder->orWhere('attribute', 'value', null, 'begins', true);

Available Dynamic where clauses

// whereRaw - where attribute unescaped value
$builder->whereRaw('foo', 'bar*');
print $builder; // (foo=bar*)

// orWhereRaw - or where attribute unescaped value
$builder->where('foo', 'bar')
    ->orWhereRaw('foo', 'baz*'); 
print $builder; // (|(foo=bar)(foo=baz*))
// whereNot - where attribute not value
$builder->whereNot('foo', 'bar');
print $builder; // (!(foo=bar))

// whereNotRaw - where attribute not unescaped value
$builder->whereNotRaw('foo', 'bar*');
print $builder; // (!(foo=bar*))

// orWhereNotRaw - or where attribute not unescaped value
$builder->where('foo', 'bar')
  ->orWhereNotRaw('foo', 'baz*');
print $builder;  // (|(foo=bar)(!(foo=baz*)))
// whereBegins - where attribute begins with value
$buidler->whereBegins('foo', 'b'); 
print $builder; // (foo=b*)

// whereBeginsRaw - where attribute begins with unescaped value
$builder->whereBeginsRaw('foo', 'b)');
print $builder; // (foo=b)*)

// whereBeginsNot - where attribute not begins with value
$builder->whereNotBegins('foo', 'b');
print $builder; // (!(foo=b*))

// whereBeginsNotRaw - where attribute not begins with unescaped value
$builder->whereNotBeginsRaw('foo', 'b()');
print $builder; // (!(foo=b()*))

// orWhereBegins - or where attribute begins with value
$builder->where('foo', 'bar')
    ->orWhereBegins('foo', 'b');
print $builder; // (|(foo=bar)(foo=b*))

// orWhereBeginsRaw - or where attribute begins with unescaped value
$builder->where('foo', 'bar')
    ->orWhereBeginsRaw('foo', 'b()');
print $builder; // (|(foo=bar)(foo=b()*))

// orWhereBeginsNot - or where attribute not begins with value
$builder->where('foo', 'bar')
    ->orWhereBeginsNot('foo', 'b');
print $builder; // (|(foo=bar)(!(foo=b*)))

// orWhereBeginsNotRaw - or where attribute not begins with unescaped value
$builder->where('foo', 'bar')
    ->orWhereBeginsNotRaw('foo', 'b()');
print $builder; // (|(foo=bar)(!(foo=b()*)))
// whereEnds - where attribute ends with value
$buidler->whereEnds('foo', 'b'); 
print $builder; // (foo=*b)

// whereEndsRaw - where attribute ends with unescaped value
$builder->whereEndsRaw('foo', 'b)');
print $builder; // (foo=*b))

// whereEndsNot - where attribute not ends with value
$builder->whereNotEnds('foo', 'b');
print $builder; // (!(foo=*b))

// whereEndsNotRaw - where attribute not ends with unescaped value
$builder->whereNotEndsRaw('foo', 'b()');
print $builder; // (!(foo=*b()))

// orWhereEnds - or where attribute ends with value
$builder->where('foo', 'bar')
    ->orWhereEnds('foo', 'b');
print $builder; // (|(foo=bar)(foo=*b))

// orWhereEndsRaw - or where attribute ends with unescaped value
$builder->where('foo', 'bar')
    ->orWhereEndsRaw('foo', 'b()');
print $builder; // (|(foo=bar)(foo=*b()))

// orWhereEndsNot - or where attribute not ends with value
$builder->where('foo', 'bar')
    ->orWhereEndsNot('foo', 'b');
print $builder; // (|(foo=bar)(!(foo=*b)))

// orWhereEndsNotRaw - or where attribute not ends with unescaped value
$builder->where('foo', 'bar')
    ->orWhereEndsNotRaw('foo', 'b()');
print $builder; // (|(foo=bar)(!(foo=*b())))
// whereLike - where attribute like value
$buidler->whereLike('foo', 'b'); 
print $builder; // (foo=*b*)

// whereLikeRaw - where attribute like unescaped value
$builder->whereLikeRaw('foo', 'b)');
print $builder; // (foo=*b)*)

// whereLikeNot - where attribute not like value
$builder->whereNotLike('foo', 'b');
print $builder; // (!(foo=*b*))

// whereLikeNotRaw - where attribute not like unescaped value
$builder->whereNotLikeRaw('foo', 'b()');
print $builder; // (!(foo=*b()*))

// orWhereLike - or where attribute like value
$builder->where('foo', 'bar')
    ->orWhereLike('foo', 'b');
print $builder; // (|(foo=bar)(foo=*b*))

// orWhereLikeRaw - or where attribute like unescaped value
$builder->where('foo', 'bar')
    ->orWhereLikeRaw('foo', 'b()');
print $builder; // (|(foo=bar)(foo=*b()*))

// orWhereLikeNot - or where attribute not like value
$builder->where('foo', 'bar')
    ->orWhereLikeNot('foo', 'b');
print $builder; // (|(foo=bar)(!(foo=*b*)))

// orWhereLikeNotRaw - or where attribute not like unescaped value
$builder->where('foo', 'bar')
    ->orWhereLikeNotRaw('foo', 'b()');
print $builder; // (|(foo=bar)(!(foo=*b()*)))

Installation

LdapQuery requires composer to install

$ composer require avadaneidanut/ldapquery

Development

Want to contribute? Great! Can't wait to hear from you!

License

MIT

avadaneidanut/ldapquery 适用场景与选型建议

avadaneidanut/ldapquery 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.39k 次下载、GitHub Stars 达 47, 最近一次更新时间为 2016 年 05 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「ldap」 「windows」 「active directory」 「ldapquery」 「ldap query」 「windows server」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 avadaneidanut/ldapquery 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 avadaneidanut/ldapquery 我们能提供哪些服务?
定制开发 / 二次开发

基于 avadaneidanut/ldapquery 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 18.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 47
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 47
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-12