-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Add missing deprecations #222
Changes from all commits
965706f
913cd1d
19f6516
aea3e98
32b654b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,14 @@ | |
|
||
namespace Sonata\FormatterBundle\Formatter; | ||
|
||
use Psr\Log\LoggerAwareInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\Log\NullLogger; | ||
use Twig_Environment; | ||
use Twig_Error_Syntax; | ||
use Twig_Sandbox_SecurityError; | ||
|
||
class Pool | ||
class Pool implements LoggerAwareInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is per definition a BC break IMO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. Please tell me how it would be one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am curious about the reasoning as well. 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thats why i said per definition, but if we fullfill the interface, everything is fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for the theoretical debate: how is it a BC break per definition? If you don't actually implement the interface your code will be broken. |
||
{ | ||
/** | ||
* @var array | ||
|
@@ -29,20 +31,60 @@ class Pool | |
protected $defaultFormatter; | ||
|
||
/** | ||
* NEXT_MAJOR: use LoggerAwareTrait. | ||
* | ||
* @var LoggerInterface | ||
*/ | ||
protected $logger; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you use the trait from the psr/log package you can drop this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scheduled for next major |
||
|
||
/** | ||
* @param LoggerInterface|null $logger | ||
* @param string|null $defaultFormatter | ||
* @param string|null $defaultFormatter | ||
*/ | ||
public function __construct(LoggerInterface $logger = null, $defaultFormatter = null) | ||
public function __construct($defaultFormatter = null) | ||
{ | ||
$this->logger = $logger; | ||
if (func_num_args() == 2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NEXT_MAJOR: Remove this block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the comment to line 34, to explain that line 35 must be kept, which would be harder to convey from line 45. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yoda please |
||
list($logger, $defaultFormatter) = func_get_args(); | ||
$this->logger = $logger; | ||
$this->defaultFormatter = $defaultFormatter; | ||
} elseif (func_num_args() == 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yoda please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't assign a value to a function call. So this would protect us from nothing, and make things less readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wanted to say that. Yoda for function call????? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sagikazarmark : I always said the Jedi council has too much influence :) Look how carried away they can get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, for me THIS is the point where sanity should be superior to consistency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, how you like, I really like the reading more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah but then again you guys put verbs at the end of a sentence 🇩🇪 ;) |
||
if ($defaultFormatter instanceof LoggerInterface) { | ||
$this->logger = $defaultFormatter; | ||
} else { | ||
// NEXT_MAJOR: Only keep this block | ||
$this->defaultFormatter = $defaultFormatter; | ||
} | ||
} | ||
|
||
// TODO: This should become a required first parameter when the major version is changed | ||
$this->defaultFormatter = $defaultFormatter; | ||
// NEXT_MAJOR: keep the else block only | ||
if ($this->logger) { | ||
@trigger_error(sprintf( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this error be triggered if there are two arguments too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe: if this->logger is set then trigger error else this->logger = new NullLogger(). |
||
'Providing a logger to %s through the constructor is deprecated since 3.x'. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will become "Providing a logger to Pool::__construct through the constructor...". Is this intended? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the string split kicks in as well: if you change the message, you need to rearrange the strings as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, changing it to
Yeah but if you used nowdoc it's a breeze: you join the lines together again, hit |
||
' and will no longer be possible in 4.0'. | ||
' This argument should be provided through the setLogger() method.', | ||
__CLASS__ | ||
), E_USER_DEPRECATED); | ||
} else { | ||
$this->logger = new NullLogger(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a newline here? |
||
|
||
// NEXT_MAJOR: make defaultFormatter required | ||
if (is_null($this->defaultFormatter)) { | ||
@trigger_error(sprintf( | ||
'Not providing the defaultFormatter argument to %s is deprecated since 3.x.'. | ||
' This argument will become mandatory in 4.0.', | ||
__METHOD__ | ||
), E_USER_DEPRECATED); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sagikazarmark : I'm done with the |
||
} | ||
|
||
/** | ||
* NEXT_MAJOR: use Psr\Log\LoggerAwareTrait. | ||
* | ||
* @param LoggerInterface will be used to report errors | ||
*/ | ||
public function setLogger(LoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
|
@@ -98,17 +140,23 @@ public function transform($code, $text) | |
$text = $env->render($text); | ||
} | ||
} catch (Twig_Error_Syntax $e) { | ||
if ($this->logger) { | ||
$this->logger->critical(sprintf('[FormatterBundle::transform] %s - Error while parsing twig template : %s', $code, $e->getMessage()), array( | ||
'text' => $text, | ||
)); | ||
} | ||
$this->logger->critical(sprintf( | ||
'[FormatterBundle::transform] %s - Error while parsing twig template : %s', | ||
$code, | ||
$e->getMessage() | ||
), array( | ||
'text' => $text, | ||
'exception' => $e, | ||
)); | ||
} catch (Twig_Sandbox_SecurityError $e) { | ||
if ($this->logger) { | ||
$this->logger->critical(sprintf('[FormatterBundle::transform] %s - the user try an non white-listed keyword : %s', $code, $e->getMessage()), array( | ||
'text' => $text, | ||
)); | ||
} | ||
$this->logger->critical(sprintf( | ||
'[FormatterBundle::transform] %s - the user try an non white-listed keyword : %s', | ||
$code, | ||
$e->getMessage() | ||
), array( | ||
'text' => $text, | ||
'exception' => $e, | ||
)); | ||
} | ||
|
||
return $text; | ||
|
@@ -127,7 +175,7 @@ public function getFormatters() | |
*/ | ||
public function getDefaultFormatter() | ||
{ | ||
// TODO: This should be removed when the major version is changed | ||
// NEXT_MAJOR: This should be removed | ||
if (is_null($this->defaultFormatter)) { | ||
reset($this->formatters); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't split this string in two parts just for the character limit, because searching for this particular string in the whole projects wouldn't work later.
This is a general discussion I don't want to start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So diplomatic.... 😝
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well why are you starting it then? All jokes aside, you both aprroved, so I'll just merge. But stay tuned for a real discussion about this, I'll make
a blog postan issue soon.