forked from ldaptools/ldaptools-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 01cfe46
Showing
56 changed files
with
6,276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
composer.lock | ||
composer.phar | ||
.idea | ||
vendor/ | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
$finder = Symfony\CS\Finder\DefaultFinder::create() | ||
->exclude('spec') | ||
->in(__DIR__) | ||
; | ||
|
||
return Symfony\CS\Config\Config::create() | ||
->finder($finder) | ||
->level(Symfony\CS\FixerInterface::PSR2_LEVEL) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
imports: | ||
- php | ||
|
||
filter: | ||
excluded_paths: | ||
- spec/* | ||
- Resources/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
language: php | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache/files | ||
|
||
matrix: | ||
fast_finish: true | ||
include: | ||
- php: 5.6 | ||
env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_DEPRECATIONS_HELPER=weak | ||
- php: 7.0 | ||
env: SYMFONY_VERSION='2.8.*' | ||
- php: 7.0 | ||
env: SYMFONY_VERSION='3.0.*' | ||
allow_failures: | ||
- php: 7.0 | ||
|
||
before_install: | ||
- echo "extension=ldap.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` | ||
- composer self-update | ||
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --dev --no-update symfony/symfony=$SYMFONY_VERSION; fi | ||
|
||
install: composer update $COMPOSER_FLAGS --prefer-dist | ||
|
||
script: | ||
- bin/phpspec run --format=pretty --no-interaction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* This file is part of the LdapToolsBundle package. | ||
* | ||
* (c) Chad Sikorra <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace LdapTools\Bundle\LdapToolsBundle\Annotation; | ||
|
||
/** | ||
* @Annotation | ||
* @Target("PROPERTY") | ||
*/ | ||
class LdapObject | ||
{ | ||
/** | ||
* @Required | ||
* @var string | ||
*/ | ||
public $type; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $domain; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $id = 'guid'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $collection = false; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $attributes = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/** | ||
* This file is part of the LdapToolsBundle package. | ||
* | ||
* (c) Chad Sikorra <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace LdapTools\Bundle\LdapToolsBundle\CacheWarmer; | ||
|
||
use LdapTools\Configuration; | ||
use LdapTools\Factory\LdapObjectSchemaFactory; | ||
use LdapTools\LdapManager; | ||
use LdapTools\Schema\LdapObjectSchema; | ||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; | ||
|
||
/** | ||
* A cache warmer for the LDAP schema types. | ||
* | ||
* @author Chad Sikorra <[email protected]> | ||
*/ | ||
class LdapToolsCacheWarmer implements CacheWarmerInterface | ||
{ | ||
/** | ||
* @var LdapManager | ||
*/ | ||
protected $ldap; | ||
|
||
/** | ||
* @var Configuration | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* @param LdapManager $ldap | ||
* @param Configuration $config | ||
*/ | ||
public function __construct(LdapManager $ldap, Configuration $config) | ||
{ | ||
$this->ldap = $ldap; | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function warmUp($cacheDir) | ||
{ | ||
$domain = $this->ldap->getDomainContext(); | ||
foreach ($this->config->getDomainConfiguration() as $domainConfig) { | ||
$this->ldap->switchDomain($domainConfig->getDomainName()); | ||
$schemaFactory = $this->ldap->getSchemaFactory(); | ||
$parser = $this->ldap->getSchemaParser(); | ||
$schema = empty($domainConfig->getSchemaName()) ? $domainConfig->getLdapType() : $domainConfig->getSchemaName(); | ||
$ldapObjects = $parser->parseAll($schema); | ||
|
||
$this->cacheAllLdapSchemaObjects($schemaFactory, ...$ldapObjects); | ||
} | ||
$this->ldap->switchDomain($domain); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isOptional() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @param LdapObjectSchemaFactory $schemaFactory | ||
* @param LdapObjectSchema ...$schemaObjects | ||
*/ | ||
protected function cacheAllLdapSchemaObjects(LdapObjectSchemaFactory $schemaFactory, LdapObjectSchema ...$schemaObjects) | ||
{ | ||
/** @var LdapObjectSchema $ldapSchemaObject */ | ||
foreach ($schemaObjects as $ldapSchemaObject) { | ||
$schemaFactory->get($ldapSchemaObject->getSchemaName(), $ldapSchemaObject->getObjectType()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
/** | ||
* This file is part of the LdapToolsBundle package. | ||
* | ||
* (c) Chad Sikorra <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace LdapTools\Bundle\LdapToolsBundle\DataCollector; | ||
|
||
use LdapTools\Bundle\LdapToolsBundle\Log\LdapProfilerLogger; | ||
use LdapTools\LdapManager; | ||
use LdapTools\Log\LogOperation; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\DataCollector\DataCollector; | ||
|
||
/** | ||
* Data Collector for LdapTools. | ||
* | ||
* @author Chad Sikorra <[email protected]> | ||
*/ | ||
class LdapToolsDataCollector extends DataCollector | ||
{ | ||
/** | ||
* @var LdapManager | ||
*/ | ||
protected $ldap; | ||
|
||
/** | ||
* @var LdapProfilerLogger | ||
*/ | ||
protected $logger; | ||
|
||
/** | ||
* LdapToolsDataCollector constructor. | ||
* @param LdapProfilerLogger $logger | ||
* @param LdapManager|null $ldap | ||
*/ | ||
public function __construct(LdapProfilerLogger $logger, LdapManager $ldap = null) | ||
{ | ||
$this->ldap = $ldap; | ||
$this->logger = $logger; | ||
|
||
$this->data['domains'] = []; | ||
$this->data['errors'] = []; | ||
$this->data['operations'] = []; | ||
$this->data['operations_by_domain'] = []; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'ldaptools'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function collect(Request $request, Response $response, \Exception $exception = null) | ||
{ | ||
if (!$this->ldap) { | ||
return; | ||
} | ||
$this->data['domains'] = $this->ldap->getDomains(); | ||
|
||
$this->data['operations_by_domain'] = []; | ||
foreach ($this->data['domains'] as $domain) { | ||
$this->data['operations_by_domain'][$domain] = $this->addOperationToData(...$this->logger->getOperations($domain)); | ||
} | ||
$this->data['operations'] = $this->addOperationToData(...$this->logger->getOperations()); | ||
$this->data['errors'] = $this->addOperationToData(...$this->logger->getErrors()); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getOperationsByDomain() | ||
{ | ||
return $this->data['operations_by_domain']; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getTime() | ||
{ | ||
$time = 0; | ||
|
||
foreach ($this->data['operations'] as $operation) { | ||
$time += $operation['duration']; | ||
} | ||
|
||
return $time; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getOperations() | ||
{ | ||
return $this->data['operations']; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getErrors() | ||
{ | ||
return $this->data['errors']; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getDomains() | ||
{ | ||
return $this->data['domains']; | ||
} | ||
|
||
/** | ||
* @param \LdapTools\Log\LogOperation[] ...$logs | ||
* @return array | ||
*/ | ||
protected function addOperationToData(LogOperation ...$logs) | ||
{ | ||
$logData = []; | ||
|
||
foreach ($logs as $log) { | ||
$data = []; | ||
|
||
$data['data'] = $log->getOperation()->getLogArray(); | ||
$data['startTime'] = $log->getStartTime(); | ||
$data['stopTime'] = $log->getStopTime(); | ||
$data['domain'] = $log->getDomain(); | ||
$data['error'] = $log->getError(); | ||
$data['name'] = $log->getOperation()->getName(); | ||
$data['duration'] = ($data['stopTime'] - $data['startTime']) * 1000; | ||
|
||
$logData[] = $data; | ||
} | ||
|
||
return $logData; | ||
} | ||
} |
Oops, something went wrong.