Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@..

Decoded Output download

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Ldap\Adapter\ExtLdap;

use Symfony\Component\Ldap\Adapter\AdapterInterface;
use Symfony\Component\Ldap\Adapter\ConnectionInterface;
use Symfony\Component\Ldap\Adapter\EntryManagerInterface;
use Symfony\Component\Ldap\Adapter\QueryInterface;
use Symfony\Component\Ldap\Exception\LdapException;

/**
 * @author Charles Sarrazin <[email protected]>
 */
class Adapter implements AdapterInterface
{
    private ConnectionInterface $connection;
    private EntryManagerInterface $entryManager;

    public function __construct(
        private array $config = [],
    ) {
        if (!\extension_loaded('ldap')) {
            throw new LdapException('The LDAP PHP extension is not enabled.');
        }
    }

    public function getConnection(): ConnectionInterface
    {
        return $this->connection ??= new Connection($this->config);
    }

    public function getEntryManager(): EntryManagerInterface
    {
        return $this->entryManager ??= new EntryManager($this->getConnection());
    }

    public function createQuery(string $dn, string $query, array $options = []): QueryInterface
    {
        return new Query($this->getConnection(), $dn, $query, $options);
    }

    public function escape(string $subject, string $ignore = '', int $flags = 0): string
    {
        $value = ldap_escape($subject, $ignore, $flags);

        // Per RFC 4514, leading/trailing spaces should be encoded in DNs, as well as carriage returns.
        if ($flags & \LDAP_ESCAPE_DN) {
            if ($value && ' ' === $value[0]) {
                $value = '\20'.substr($value, 1);
            }
            if ($value && ' ' === $value[\strlen($value) - 1]) {
                $value = substr($value, 0, -1).'\20';
            }
            $value = str_replace("
", 'd', $value);
        }

        return $value;
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Ldap\Adapter\ExtLdap;

use Symfony\Component\Ldap\Adapter\AdapterInterface;
use Symfony\Component\Ldap\Adapter\ConnectionInterface;
use Symfony\Component\Ldap\Adapter\EntryManagerInterface;
use Symfony\Component\Ldap\Adapter\QueryInterface;
use Symfony\Component\Ldap\Exception\LdapException;

/**
 * @author Charles Sarrazin <[email protected]>
 */
class Adapter implements AdapterInterface
{
    private ConnectionInterface $connection;
    private EntryManagerInterface $entryManager;

    public function __construct(
        private array $config = [],
    ) {
        if (!\extension_loaded('ldap')) {
            throw new LdapException('The LDAP PHP extension is not enabled.');
        }
    }

    public function getConnection(): ConnectionInterface
    {
        return $this->connection ??= new Connection($this->config);
    }

    public function getEntryManager(): EntryManagerInterface
    {
        return $this->entryManager ??= new EntryManager($this->getConnection());
    }

    public function createQuery(string $dn, string $query, array $options = []): QueryInterface
    {
        return new Query($this->getConnection(), $dn, $query, $options);
    }

    public function escape(string $subject, string $ignore = '', int $flags = 0): string
    {
        $value = ldap_escape($subject, $ignore, $flags);

        // Per RFC 4514, leading/trailing spaces should be encoded in DNs, as well as carriage returns.
        if ($flags & \LDAP_ESCAPE_DN) {
            if ($value && ' ' === $value[0]) {
                $value = '\\20'.substr($value, 1);
            }
            if ($value && ' ' === $value[\strlen($value) - 1]) {
                $value = substr($value, 0, -1).'\\20';
            }
            $value = str_replace("\r", '\0d', $value);
        }

        return $value;
    }
}

Function Calls

None

Variables

None

Stats

MD5 60d883f0378507e60db0fa81e95a071a
Eval Count 0
Decode Time 75 ms