To view this discussion on the web visit https://groups.google.com/d/msg/php-fig/-/OIKlVvaJMk0J.--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To post to this group, send email to php...@googlegroups.com.
To unsubscribe from this group, send email to php-fig+u...@googlegroups.com.
Down this road lies madness. But in all seriousness, the addition of an escape character like that makes both string replacement and simple regular expression-replacement unfeasible strategies, so I would advocate against the addition of an escape -- unless there is a simple solution that I'm missing.
Matthew
>
> Evert
>
> --
> You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
> To post to this group, send email to php...@googlegroups.com.
> To unsubscribe from this group, send email to php-fig+u...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To post to this group, send email to php...@googlegroups.com.
To unsubscribe from this group, send email to php-fig+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
On Dec 11, 2012 6:04 PM, "Evert Pot" <ever...@gmail.com> wrote:
>
> On Dec 12, 2012, at 12:00 AM, Paul Jones <pmjo...@gmail.com> wrote:
>
> >
> > On Dec 11, 2012, at 4:56 PM, Evert Pot wrote:
> >
> >> I can see that %foo%bar% could be problematic.
> >>
> >> This wouldn't be a problem if there's an escaping mechanism though. Thoughts?
> >
> > /me nods
> >
> > To be clear, you're saying we should be able to escape the delimiters so they are not interpreted as placeholders, e.g. using a backslash as part of the opening delimiter? So, {foo} would be a placeholder, and \{foo} would not be -- yes?
>
> Exactly.
>
> I feel that if I'm going to log a lot of debugging data, it would be beneficial if I can run it through an escaping function to ensure that now substitution never happens.
>
> If we're escaping with a backslash (and \\ for a 'raw' backslash), using %key% would also no longer be ambiguous.Down this road lies madness. But in all seriousness, the addition of an escape character like that makes both string replacement and simple regular expression-replacement unfeasible strategies, so I would advocate against the addition of an escape -- unless there is a simple solution that I'm missing.
A regex like this would do the trick I believe (untested):(\\ |\% |%([^%]+)%)with preg_replace_callback, this is not terribly hard to implement. I bet this can be optimized a bit though, by never calling the callback for the first two cases.
I would argue in favor of *only* named placeholders, so that we can easily throw an array of context data against a message, where the array keys do not need to be in any particular order.
I would argue also that we don't need to define the placeholder formats; anything between the delimiters should be allowed.
With that in mind, I would first argue that we need an opening and closing delimiter, not just an opening delimiter. This makes it easier to search for placeholder names in the message; you don't need to define what characters are allowed in the names, just the delimiters.
I would further argue that they should be different sets of characters; e.g., {foo} and not %foo%. I think thinks makes it easier to search for multiple tokens on the same line; you only need to define the delimiters, not the placeholder names.
Finally, I would argue that whatever we come up with should be usable in short-message contexts other than logging: things like localized message placeholders, router placeholders, validation messages, etc.
public static function format($template, array $vars=array()){return preg_replace_callback('/{{(\w+)}}/',function($match) use($vars) {return isset($vars[$match[1]]) ? $vars[$match[1]] : $match[0];}, $template);}
-- pmj
(The placeholder {{foo}} will pass, because the inner braces match the pattern, so the replacement would be surrounded by the external braces. Do we care about that?)
Thoughts?
/{([^{\w\s])?([\w]+)}/
The question is: does it matter enough to put it in the example regex, or is it enough to document that this is an expected behavior?
The question is: does it matter enough to put it in the example regex, or is it enough to document that this is an expected behavior?
I can see how documenting using regex character classes might be nice but it feels like defining "the" regex falls into the implementation detail category. In that case I do not think it needs to be defined unless the intention is to provide this functionality in the package somehow. For example, something like: Psr\Log\LogMessage::format($string, $context)
On 12/12/2012 09:16 AM, Paul Jones wrote:Ordered placeholders are useless. Full stop. And if we're adding named placeholders to sprintf(), then we're not using sprintf() anymore so there's no programmatic benefit to modeling on sprintf().
Great! Thanks!But do you agree that this is an implementation detail?
And if so suggesting strtr for parameter replacing, like the autoloader from PSR-0 is a suggestion, it should be fine. The logging components which implements this interface could be extended to use whatever they want/need for their cases but are not mandatory.If you want you can have something like this:class PrettyLogger implements LoggerInterface {}class PrettyerLogger implements LoggerInterface {setLogger(LoggerInterface $logger);function debug($msg, $params) {// take the params, prepare for strtr, call $this->logger->debug($msg, $formattedParams);}}$logger = (new PrettyerLogger())->setLogger(new PrettyLogger());
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To post to this group, send email to php...@googlegroups.com.
To unsubscribe from this group, send email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/php-fig/-/Ni-Q4B9eakYJ.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To post to this group, send email to php...@googlegroups.com.
To unsubscribe from this group, send email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/php-fig/-/YmUfoHHdnJEJ.
No, it does not seem reasonable in the slightest.
The context array is intended to carry more than just string replacement values, thus making it an ordered array rather than associative is a non-starter. The spec already says, for instance, that an exception must be passed with the key value of "exception".
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To post to this group, send email to php...@googlegroups.com.
To unsubscribe from this group, send email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/php-fig/-/HeuNPkWCVMcJ.
-- pmj
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
As with any change proposal, please think about what the benefits are
and explain them together with the change. If you can't find any, it's
probably not worth debating over. (I don't mean to pick on you, it's a
general remark)
The fact that things have to be looped over is an implementation detail,
some might loop at various places. Some implementations might look for
an exception anywhere to do fancier things if they want. The spec just
tries to nudge people towards using the same thing, but if they don't
it's still ok. It's just pointing out a sort of gentlemen's agreement
that will enable some features without resorting to over-specification.
Hi,Hi all,
What delimiters to use?
-----------------------
These are the ones I know are used by various projects, members or otherwise, whether for logging interpolation or for other string substitutions (please feel free to add to this list *from existing projects*).
Drupal:
%foo
@foo
!foo
ext/intl and possibly others:
{foo}
Lithium, Solar/Aura:
{:foo}
Twig, Mustache, et al.:
{{foo}} (no spaces allowed)
{{ foo }} (zero or more spaces allowed)
Suggested by Jordi:
%foo%
Zsh uses the “zFormat” format, which is basically:
(:subject[:options]*:). Thus we can have aVariable without option:
(:aVariable:), or we can have aVariable with some options:
(:aVariable:opt1:opt2:), or if options are represented by one
character: (:aVariable:xyz:).Let keywords $k and parameters $p:$k = array('foo' => 'bar','car' => 'DeLoReAN','power' => 2.21,'answerTo' => 'life_universe_everything_else','answerIs' => 42,'hello' => 'wor.l.d');$p = array('plpl' => '(:foo:U:)','foo' => 'ar(:%plpl:)','favoriteCar' => 'A (:car:l:)!','truth' => 'To (:answerTo:ls/_/ /U:) is (:answerIs:).','file' => '/a/file/(:_Ymd:)/(:hello:trr:).(:power:e:)','recursion' => 'oof(:%foo:s#ar#az:)');Then, after applying the zFormat, we get:• plpl: 'Bar' put the first letter in uppercase;• foo: 'arBar' call the parameter plpl;• favoriteCar: 'A delorean!' all is in lowercase;• truth: 'To Life universe everything else is 42' all is in owercase, then replace underscores by spaces, andfinally put the first letter in uppercase; and notransformation for 42;• file: '/a/file/20090505/wor.21' get date constants, thenget the tail of the path and remove extension twice,and add the extension of power;• recursion: 'oofarBaz' get 'arbar' first, and then, replace thesuffix 'ar' by 'az'.
-- Ivan Enderlin Developer of Hoa http://hoa.42/ or http://hoa-project.net/ PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis) http://disc.univ-fcomte.fr/ and http://www.inria.fr/ Member of HTML and WebApps Working Group of W3C http://w3.org/