|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the LdapToolsBundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Chad Sikorra <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LdapTools\Bundle\LdapToolsBundle\CacheWarmer; |
|
12
|
|
|
|
|
13
|
|
|
use LdapTools\Configuration; |
|
14
|
|
|
use LdapTools\Factory\LdapObjectSchemaFactory; |
|
15
|
|
|
use LdapTools\LdapManager; |
|
16
|
|
|
use LdapTools\Schema\LdapObjectSchema; |
|
17
|
|
|
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* A cache warmer for the LDAP schema types. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Chad Sikorra <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class LdapToolsCacheWarmer implements CacheWarmerInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var LdapManager |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $ldap; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var Configuration |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $config; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param LdapManager $ldap |
|
38
|
|
|
* @param Configuration $config |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(LdapManager $ldap, Configuration $config) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->ldap = $ldap; |
|
43
|
|
|
$this->config = $config; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
public function warmUp($cacheDir) |
|
50
|
|
|
{ |
|
51
|
|
|
$domain = $this->ldap->getDomainContext(); |
|
52
|
|
|
foreach ($this->config->getDomainConfiguration() as $domainConfig) { |
|
|
|
|
|
|
53
|
|
|
$this->ldap->switchDomain($domainConfig->getDomainName()); |
|
54
|
|
|
$schemaFactory = $this->ldap->getSchemaFactory(); |
|
55
|
|
|
$parser = $this->ldap->getSchemaParser(); |
|
56
|
|
|
$schema = empty($domainConfig->getSchemaName()) ? $domainConfig->getLdapType() : $domainConfig->getSchemaName(); |
|
57
|
|
|
$ldapObjects = $parser->parseAll($schema); |
|
58
|
|
|
|
|
59
|
|
|
$this->cacheAllLdapSchemaObjects($schemaFactory, ...$ldapObjects); |
|
60
|
|
|
} |
|
61
|
|
|
$this->ldap->switchDomain($domain); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
|
|
public function isOptional() |
|
68
|
|
|
{ |
|
69
|
|
|
return true; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param LdapObjectSchemaFactory $schemaFactory |
|
74
|
|
|
* @param LdapObjectSchema ...$schemaObjects |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function cacheAllLdapSchemaObjects(LdapObjectSchemaFactory $schemaFactory, LdapObjectSchema ...$schemaObjects) |
|
77
|
|
|
{ |
|
78
|
|
|
/** @var LdapObjectSchema $ldapSchemaObject */ |
|
79
|
|
|
foreach ($schemaObjects as $ldapSchemaObject) { |
|
80
|
|
|
$schemaFactory->get($ldapSchemaObject->getSchemaName(), $ldapSchemaObject->getObjectType()); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.