Skip to content

[2.7] adds deprecation notices. #13060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 5, 2015
Prev Previous commit
Next Next commit
Fixes more deprecation notices.
  • Loading branch information
Hugo Hamon committed Jan 5, 2015
commit 97efd2cfe5775b50484c95decb49554f1aabc7d0
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(Profiler $profiler, RequestMatcherInterface $matcher
// Prevent the deprecation notice to be triggered all the time.
// The onKernelRequest() method fires some logic only when the
// RequestStack instance is not provided as a dependency.
trigger_error('The '.__CLASS__.'::onKernelRequest method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
trigger_error('Since version 2.4, the '.__METHOD__.' method must accept a RequestStack instance to get the request instead of using the '.__CLASS__.'::onKernelRequest method that will be removed in 3.0.', E_USER_DEPRECATED);
}

$this->profiler = $profiler;
Expand Down
16 changes: 13 additions & 3 deletions src/Symfony/Component/HttpKernel/EventListener/RouterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte
throw new \InvalidArgumentException('You must either pass a RequestContext or the matcher must implement RequestContextAwareInterface.');
}

if (!$requestStack instanceof RequestStack) {
trigger_error('The '.__METHOD__.' method now requires a RequestStack instance as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.');
}

$this->matcher = $matcher;
$this->context = $context ?: $matcher->getContext();
$this->requestStack = $requestStack;
Expand All @@ -88,9 +92,15 @@ public function setRequest(Request $request = null)
{
trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be made private in 3.0.', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be refactored by creating a private method already with the actual logic, so that internal usages don't trigger the warning. The deprecated method would then call this private method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done thanks. I've created a new private setCurrentRequest method and replaced all calls to the setRequest method in the class by the new private one. The setRequest method now triggers the deprecation notice and calls the private method.


$this->setCurrentRequest($request);
}

private function setCurrentRequest(Request $request = null)
{
if (null !== $request && $this->request !== $request) {
$this->context->fromRequest($request);
}

$this->request = $request;
}

Expand All @@ -100,19 +110,19 @@ public function onKernelFinishRequest(FinishRequestEvent $event)
return; // removed when requestStack is required
}

$this->setRequest($this->requestStack->getParentRequest());
$this->setCurrentRequest($this->requestStack->getParentRequest());
}

public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();

// initialize the context that is also used by the generator (assuming matcher and generator share the same context instance)
// we call setRequest even if most of the time, it has already been done to keep compatibility
// we call setCurrentRequest even if most of the time, it has already been done to keep compatibility
// with frameworks which do not use the Symfony service container
// when we have a RequestStack, no need to do it
if (null !== $this->requestStack) {
$this->setRequest($request);
$this->setCurrentRequest($request);
}

if ($request->attributes->has('_controller')) {
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Validator/Validator/LegacyValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Component\Validator\Validator;

trigger_error('The '.__NAMESPACE__.'\LegacyValidator class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Validator\RecursiveValidator class instead.', E_USER_DEPRECATED);

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Validator\Constraints\Valid;
Expand Down Expand Up @@ -54,7 +52,7 @@ public function validate($value, $groups = null, $traverse = false, $deep = fals
return parent::validate($value, $constraints, $groups);
}

trigger_error('Symfony\\Component\\Validator\\ValidatorInterface::validate() was deprecated in version 2.5 and will be removed in version 3.0. Please use Symfony\\Component\\Validator\\Validator\\ValidatorInterface::validate() instead.', E_USER_DEPRECATED);
trigger_error('The Symfony\Component\Validator\Validator\ValidatorInterface::validate method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::validate method instead.', E_USER_DEPRECATED);

$constraint = new Valid(array('traverse' => $traverse, 'deep' => $deep));

Expand All @@ -63,13 +61,15 @@ public function validate($value, $groups = null, $traverse = false, $deep = fals

public function validateValue($value, $constraints, $groups = null)
{
trigger_error('Symfony\\Component\\Validator\\ValidatorInterface::validateValue() was deprecated in version 2.5 and will be removed in version 3.0. Please use Symfony\\Component\\Validator\\Validator\\ValidatorInterface::validate() instead.', E_USER_DEPRECATED);
trigger_error('The Symfony\Component\Validator\Validator\ValidatorInterface::validateValue method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::validate method instead.', E_USER_DEPRECATED);

return parent::validate($value, $constraints, $groups);
}

public function getMetadataFactory()
{
trigger_error('The Symfony\Component\Validator\Validator\ValidatorInterface::getMetadataFactory method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::validate method instead.', E_USER_DEPRECATED);

return $this->metadataFactory;
}

Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/Yaml/Deprecated/Unescaper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Symfony\Component\Yaml\Deprecated;

trigger_error('Constant ENCODING in class Symfony\Component\Yaml\Unescaper is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);

/**
* @deprecated since version 2.7, to be removed in 3.0.
* @internal
*/
final class Unescaper
{
const ENCODING = 'UTF-8';

private function __construct()
{

}
}
18 changes: 12 additions & 6 deletions src/Symfony/Component/Yaml/Unescaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Yaml;

use Symfony\Component\Yaml\Deprecated\Unescaper as Deprecated;

/**
* Unescaper encapsulates unescaping rules for single and double-quoted
* YAML strings.
Expand All @@ -19,13 +21,17 @@
*/
class Unescaper
{
// Parser and Inline assume UTF-8 encoding, so escaped Unicode characters
// must be converted to that encoding.
// @deprecated since version 2.5, to be removed in 3.0
const ENCODING = 'UTF-8';
/**
* Parser and Inline assume UTF-8 encoding, so escaped Unicode characters
* must be converted to that encoding.
*
* @deprecated since version 2.5, to be removed in 3.0
*/
const ENCODING = Deprecated::ENCODING;

// Regex fragment that matches an escaped character in a double quoted
// string.
/**
* Regex fragment that matches an escaped character in a double quoted string.
*/
const REGEX_ESCAPED_CHARACTER = "\\\\([0abt\tnvfre \\\"\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})";

/**
Expand Down