8000 Ensure BC · symfony/symfony@861503b · GitHub
[go: up one dir, main page]

Skip to content

Commit 861503b

Browse files
author
Dominic Tubach
committed
Ensure BC
Style fixes
1 parent 080c045 commit 861503b

File tree

7 files changed

+46
-13
lines changed

7 files changed

+46
-13
lines changed

src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function rename(Entry $entry, $newRdn, $removeOldRdn = true)
116116
*
117117
* @throws NotBoundException if the connection has not been previously bound
118118
* @throws LdapException if an error is thrown during the rename operation
119-
* @throws MalformedDistinguishedNameException if entry contains a malformed DN.
119+
* @throws MalformedDistinguishedNameException if entry contains a malformed DN
120120
*/
121121
public function move(Entry $entry, string $newParent)
122122
{

src/Symfony/Component/Ldap/Exception/ExtensionNotLoadedException.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@
1212
namespace Symfony\Component\Ldap\Exception;
1313

1414
/**
15-
* ExtensionNotLoadedException is thrown is a required PHP extension is not loaded.
15+
* ExtensionNotLoadedException is thrown if a required PHP extension is not loaded.
16+
*
17+
* This class should extend \RuntimeException, but extends LdapException for BC
18+
* compatibility.
1619
*
1720
* @author Dominic Tubach <dominic.tubach@to.com>
1821
*/
19-
class ExtensionNotLoadedException extends \RuntimeException implements ExceptionInterface
22+
class ExtensionNotLoadedException extends LdapException implements ExceptionInterface
2023
{
24+
public function __construct(string $message = '', int $code = 0, \Throwable $previous = null)
25+
{
26+
// avoid deprecation error
27+
parent::__construct($message, $code, $previous);
28+
}
2129
}

src/Symfony/Component/Ldap/Exception/LdapException.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
1212
namespace Symfony\Component\Ldap\Exception;
1313

1414
/**
15-
* LdapException is thrown if an LDAP operation fails.
15+
* LdapException is thrown if an LDAP operation fails. For BC compatibility
16+
* the classes ExtensionNotLoadedException, MalformedDistinguishedNameException,
17+
* and UnexpectedValueException extend this class, though they are not thrown
18+
* because of a failed LDAP operation.
1619
*
1720
* @author Grégoire Pineau <lyrixx@lyrixx.info>
1821
* @author Dominic Tubach <dominic.tubach@to.com>
@@ -22,12 +25,15 @@ class LdapException extends \RuntimeException implements ExceptionInterface
2225
/**
2326
* This constructor ensures that an error code is specified.
2427
*
25-
* @param string $message
26-
* @param int $code The LDAP error code.
28+
* @param int $code the LDAP error code
2729
* @param \Throwable $previous
2830
*/
29-
public function __construct(string $message, int $code, \Throwable $previous = null)
31+
public function __construct(string $message = '', int $code = 0, \Throwable $previous = null)
3032
{
33+
if (2 > func_num_args()) {
34+
@trigger_error(sprintf('Not specifying the LDAP error code in "%s::__construct()" is deprecated since Symfony 4.4.', __CLASS__), E_USER_DEPRECATED);
35+
}
36+
3137
parent::__construct($message, $code, $previous);
3238
}
3339

@@ -36,15 +42,15 @@ public function __construct(string $message, int $code, \Throwable $previous = n
3642
* are {errorCode} and {errorMsg} that will be
3743
* replaced by the LDAP error code and the LDAP
3844
* error message, respectively.
39-
* @param int $errorCode The LDAP error code.
45+
* @param int $errorCode the LDAP error code
4046
*
4147
* @return static
4248
*/
4349
public static function create(string $messageFormat, int $errorCode)
4450
{
4551
$message = strtr($messageFormat, [
4652
'{errorCode}' => $errorCode,
47-
'{errorMsg}' => ldap_err2str($errorCode),
53+
'{errorMsg}' => ldap_err2str($errorCode),
4854
]);
4955

5056
return new static($message, $errorCode);

src/Symfony/Component/Ldap/Exception/MalformedDistinguishedNameException.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@
1414
/**
1515
* MalformedDistinguishedNameException is thrown in case of an malformed DN.
1616
*
17+
* This class should extend \RuntimeException, but extends LdapException for BC
18+
* compatibility.
19+
*
1720
* @author Dominic Tubach <dominic.tubach@to.com>
1821
*/
19-
class MalformedDistinguishedNameException extends \RuntimeException implements ExceptionInterface
22+
class MalformedDistinguishedNameException extends LdapException implements ExceptionInterface
2023
{
24+
public function __construct(string $message = '', int $code = 0, \Throwable $previous = null)
25+
{
26+
// avoid deprecation error
27+
parent::__construct($message, $code, $previous);
28+
}
2129
}

src/Symfony/Component/Ldap/Exception/UnexpectedValueException.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111

1212
namespace Symfony\Component\Ldap\Exception;
1313

14-
class UnexpectedValueException extends \UnexpectedValueException implements ExceptionInterface
14+
/**
15+
* This class should extend \UnexpectedValueException, but extends LdapException
16+
* for BC compatibility.
17+
*
18+
* @author Dominic Tubach <dominic.tubach@to.com>
19+
*/
20+
class UnexpectedValueException extends LdapException implements ExceptionInterface
1521
{
22+
public function __construct(string $message = '', int $code = 0, \Throwable $previous = null)
23+
{
24+
// avoid deprecation error
25+
parent::__construct($message, $code, $previous);
26+
}
1627
}

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testBindFailureShouldThrowAnException()
6767
$ldap
6868
->expects($this->once())
6969
->method('bind')
70-
->willThrowException(new ConnectionException())
70+
->willThrowException(new ConnectionException('Test', 80))
7171
;
7272
$userChecker = $this->getMockBuilder(UserCheckerInterface::class)->getMock();
7373

src/Symfony/Component/Security/Core/Tests/User/LdapUserProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testLoadUserByUsernameFailsIfCantConnectToLdap()
3232
$ldap
3333
->expects($this->once())
3434
->method('bind')
35-
->willThrowException(new ConnectionException())
35+
->willThrowException(new ConnectionException('Test', 80))
3636
;
3737

3838
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');

0 commit comments

Comments
 (0)
0