Commit Graph

82 Commits

Author SHA1 Message Date
Fabien Potencier 4ba7ae939c merged branch char101/master (PR #844)
This PR was merged into the master branch.

Commits
-------

c23ef25 Add assertEquals to NativeExtensionTest.php
9126dc6 Twig extension: fix case when accessing property of an array casted into object
34cf8e1 Fix double free
4980903 Enhancements for twig extension
db3cb80 Fix NativeExtensionTest
3485ee7 Native extension: handle dynamic properties defined in the get_properties handler in a per instance fashion.

Discussion
----------

Native extension: call get_properties in per instance manner instead of caching it.

Since dynamic properties of an object can be defined by its get_properties handler, we need to call it for each instance.

---------------------------------------------------------------------------

by char101 at 2012-09-21T10:30:37Z

PHPUnit test result

```
PHPUnit 3.7.1 by Sebastian Bergmann.

.S...........................................................   61 / 1253 (  4%)
.............................................................  122 / 1253 (  9%)
.............................................................  183 / 1253 ( 14%)
.............................................................  244 / 1253 ( 19%)
.............................................................  305 / 1253 ( 24%)
.............................................................  366 / 1253 ( 29%)
.............................................................  427 / 1253 ( 34%)
.............................................................  488 / 1253 ( 38%)
.............................................................  549 / 1253 ( 43%)
.............................................................  610 / 1253 ( 48%)
.............................................................  671 / 1253 ( 53%)
.............................................................  732 / 1253 ( 58%)
.............................................................  793 / 1253 ( 63%)
.............................................................  854 / 1253 ( 68%)
.............................................................  915 / 1253 ( 73%)
.............................................................  976 / 1253 ( 77%)
............................................................. 1037 / 1253 ( 82%)
............................................................. 1098 / 1253 ( 87%)
............................................................. 1159 / 1253 ( 92%)
............................................................. 1220 / 1253 ( 97%)
.................................

Time: 4 seconds, Memory: 13.25Mb

OK, but incomplete or skipped tests!
Tests: 1253, Assertions: 2969, Skipped: 1.
```

---------------------------------------------------------------------------

by stof at 2012-09-21T11:58:51Z

@char101 My previous comment about the way the test should be implemented is still valid. Please rewrite it to use the same way to all other integration tests in Twig

---------------------------------------------------------------------------

by char101 at 2012-09-23T04:51:36Z

@stof I don't see the reason of using a fixture. The test case works, it accomplishes its goal. It's simple. It doesn't test for a feature, it tests for a specific case where PHP crashes.

---------------------------------------------------------------------------

by stof at 2012-09-23T13:53:41Z

@char101 I see one: you are building a Twig instance and rendering a template here, which is exactely what the integration tests are doing.
Btw, your test would fail when running phpunit in strict mode as it does not assert anything

---------------------------------------------------------------------------

by char101 at 2012-09-24T02:05:58Z

@stof I don't have the desire to change what isn't broken, but you are free to change it as you see fit. As for the assert, I have added it to the test.
2012-09-28 23:45:13 +02:00
Fabien Potencier 8d14fa8290 bumped version to 1.10.1-DEV 2012-09-28 22:16:35 +02:00
Fabien Potencier 60e91ba691 prepared the 1.10.0 release 2012-09-28 22:11:39 +02:00
Charles 9126dc649c Twig extension: fix case when accessing property of an array casted into object 2012-09-21 17:29:41 +07:00
Charles 34cf8e1c6e Fix double free 2012-09-21 16:42:13 +07:00
Charles 498090364b Enhancements for twig extension
- Fix extension memory leak
- Fix gcc compile warning (cast to const char *)
- Add TWIG_HAS_DYNAMIC_PROPERTY
- Remove the previous translation of 'array_key_exists($item, $object)'
  into TWIG_ARRAY_KEY_EXISTS when checking object property because what
  it really means is property_exists which has already been handled by
  TWIG_HAS_PROPERTY and TWIG_HAS_DYNAMIC_PROPERTY
- Fix native extension spacing
2012-09-21 14:47:45 +07:00
Charles 3485ee77ea Native extension: handle dynamic properties defined in the get_properties handler in a per instance fashion. 2012-09-20 18:29:21 +07:00
Fabien Potencier c420462b5b merged branch fabpot/named-paths (PR #772)
Commits
-------

7e5acd1 fixed some possible warnings
f0d0d6d fixed typo
b7076fe added Twig_Loader_Filesystem::getNamespaces()
8f7ccd1 moved an exception
9426072 tweaked documentation
b9afa84 renamed the default filesystem namespace to __main__
c34541d changed notation of namespaced templates to @namespace/template_path
0eb4d01 added namespaced templates support in Twig_Loader_Filesystem
c24ea1b added Twig_Loader_Filesystem::prependPath()

Discussion
----------

added namespaced templates support in Twig_Loader_Filesystem

Everything is explained in the updated documentation.

Basically, it gives more flexibility when it comes to manage many templates that are not necessarily related (think frontent vs backend for instance, or templates from different Symfony bundles, ...). It is useful if, for each namespace, you need to look for templates in different directories. This implementation would probably be enough to replace the current Symfony bundle template paths, with more flexibility and less restrictions.

Feedback is more than welcome. One thing I'm not sure about is the `#` separator between the namespace and the template path. Is it the best choice? We need a character that is not used in filesystem paths, so good candidates are: `@`, `!`, `%`, `$`, `*`, `;`, `?`.

Some immediate benefits: give the same template flexibility that we have in Symfony to other frameworks using Twig like Silex. Another benefit would be the ability to share template between Symfony and other frameworks like Twig (more on a proof of concept later).

---------------------------------------------------------------------------

by alessandro1997 at 2012-07-14T16:25:42Z

This is very nice, and I think # is a great choice for the separator character. We could also use @.

---------------------------------------------------------------------------

by jjbohn at 2012-07-14T16:25:59Z

👍 for #

---------------------------------------------------------------------------

by Symfomany at 2012-07-14T16:27:45Z

Pipe character isn't candidate?

---------------------------------------------------------------------------

by inspiran at 2012-07-14T16:32:52Z

I remember from the wetter.com talk at sf live that they actually implemented a similar functionality: allow twig templates to be defined different from the default path.   So they had something like:

{% extends "cms://Home/weather/..."  ... %}
If we could make the "cms" part a configurable setting then one could use it to point to a custom folder or even to a content provider (symfony cmf?)

Maybe that would be another approach?

---------------------------------------------------------------------------

by fabpot at 2012-07-14T16:33:21Z

The other syntax possibility is something more like we have in Symfony: `@namespace/template_path`.

---------------------------------------------------------------------------

by fabpot at 2012-07-14T16:34:37Z

@inspiran: that's another possibility: use the PHP stream notation.

---------------------------------------------------------------------------

by mvrhov at 2012-07-14T16:36:18Z

I'd also prefer uri/php streams syntax...

---------------------------------------------------------------------------

by Tobion at 2012-07-14T16:41:16Z

On Windows I can create a file with `#` in it. How does it distinguish that? I don't think we will find a single seperation character that works on all file systems, do we? And `@` (e.g. namespace@file) would be semantically strange (unless you read it from right-to-left).
So I'd also prefer uri/php stream syntax.

---------------------------------------------------------------------------

by Symfomany at 2012-07-14T16:43:17Z

@fabpot  Pointer Syntax? or greater than character?

---------------------------------------------------------------------------

by markstory at 2012-07-14T16:43:48Z

I'm in favour of the `foo://` style syntax.  It is similar to other parts of PHP, and avoids overlap with filesystem characters, and doesn't introduce new unique syntax.

---------------------------------------------------------------------------

by stof at 2012-07-14T16:44:25Z

@fabpot ``@namespace/template_path`` would make it confusing in Symfony. Because locating a resource with the kernel would use ``@AcmeDemoBundle/Resources/views/layout.html.twig`` whereas Twig would find the same file as ```@AcmeDemoBundle/layout.html.twig``.

And none of ``#``, ``@``, ``!``, ``%``, ``$`` or ``;`` is forbidden in filenames on Windows.

So I think the URI/stream notation is fine

---------------------------------------------------------------------------

by maryo at 2012-07-14T16:46:44Z

On Windows @!%$; are valid. Invalid characters are \/:*?"<>|

---------------------------------------------------------------------------

by maryo at 2012-07-14T16:47:55Z

Is > allowed on Linux?

---------------------------------------------------------------------------

by jschreuder at 2012-07-14T16:49:17Z

Some thoughts from a non-Symfony user:

* Not sure about the `#`, on the one hand it is used as the comment character on the other hand I'm also familiar with it as a membership operator (which supports its usage)
* The streams/PHP syntax: I don't really like this, the syntax signifies some type of protocol to be used. Even stretched to the limits of its definition you wouldn't be able to define different namespaces as different protocols (same protocol, different location).
* `@namespace/file/path` - kind of like this one, the `@` signifies that it is followed by a special symbol (being the namespace name) and other than that a normal path.
* Another option we've used in Fuel is the double colon `::` as in `namespace::file/path` (like the `#` it signifies membership, but doesn't have another significance in Twig)

---------------------------------------------------------------------------

by gunnarlium at 2012-07-14T17:10:15Z

Does it matter what symbols are valid in filenames? Won't the separator just be used for exploding the string into namespace and path, and thus never be used to directly access a file?

---------------------------------------------------------------------------

by alessandro1997 at 2012-07-14T17:15:27Z

As @gunnarlium said, what's the problem with filenames?

```php
$path = 'namespace#new#page.html';
$parts = explode('#', $path, 2);
list($namespace, $filename) = $parts;

// "namespace and "new#page.html"
var_dump($namespace, $filename);
```

---------------------------------------------------------------------------

by stof at 2012-07-14T17:16:19Z

@gunnarlium the issue is that if you use this symbols in the filename of your template without namespace, Twig will consider it as a namespaced template for another file name

---------------------------------------------------------------------------

by stof at 2012-07-14T17:16:45Z

@alessandro1997 the issue is that namespaces are optional

---------------------------------------------------------------------------

by alessandro1997 at 2012-07-14T17:17:07Z

@stof Oh, right. I didn't get that :-)

---------------------------------------------------------------------------

by gunnarlium at 2012-07-14T17:20:32Z

@stof Ok, I see. So what we want is a symbol which is not allowed as a filename? Or (suboptimally) just add a requirement that template filenames can't contain certain reserved symbols?

---------------------------------------------------------------------------

by fabpot at 2012-07-14T17:23:37Z

But then, who is using `#` in a filename?

Anyway, I'm going to implement a version based on PHP streams to stick to the PHP way. Using a PHP stream might also allow us to get rid of the array loader.

---------------------------------------------------------------------------

by alessandro1997 at 2012-07-14T17:24:01Z

@gunnarlium But how would we check if the user is using reserved symbols in template names? Twig isn't aware of the available templates' names until the user requests them. And when he/she does it's too late because Twig doesn't know if the separator is used as namespace or if it's part of the filename.

---------------------------------------------------------------------------

by stof at 2012-07-14T17:33:38Z

@fabpot even if no sane guy would probably use ``#`` in a filename, it would mean that Twig assumes that all its userbase is sane :)

---------------------------------------------------------------------------

by lolautruche at 2012-07-14T18:51:53Z

-1 for #
+1 for php stream, though I agree with @jschreuder's arguments against it
+2 for @ syntax like in Symfony. I find it more consistent.

---------------------------------------------------------------------------

by fabpot at 2012-07-14T19:50:31Z

One problem with PHP streams is that it makes using template names quite ugly and verbose:

    {% include 'twig://namespace/index.html' %}

And for non-namespaced templates:

    {% include 'twig:///index.html' %}

for which we can provide a shortcut:

    {% include 'index.html' %}

---------------------------------------------------------------------------

by fabpot at 2012-07-14T19:54:35Z

If we are using `@` like in Symfony, it will be:

    {% include '@namespace/index.html' %}

And for non-namespaced templates:

    {% include 'index.html' %}

And for Symfony users, the notation would be the same as for resources. If we register each bundle path as a namespace, the path would even be exactly the same:

    {% include '@AcmeDemoBundle/Resources/views/layout.html.twig' %}

EDIT: that's not so simple because of the templates stored under `app/`.

---------------------------------------------------------------------------

by mahono at 2012-07-14T19:56:54Z

might not be the best idea, but what about using Backslash as namespace char?

---------------------------------------------------------------------------

by fabpot at 2012-07-14T19:57:50Z

@mahono: I have not dared to propose this alternative ;)

---------------------------------------------------------------------------

by fabpot at 2012-07-14T20:06:17Z

I've just made an additional commit that implements the `@namespace/template_path` notation.

---------------------------------------------------------------------------

by Baachi at 2012-07-14T20:32:41Z

The `@` syntax is the most consistent solution.
But the integration in symfony2 is really hard and a BC break.

The stream syntax is not a good solution.
`twig` might already be already registered as a stream.

I would suggest the `::` syntax.
2012-09-16 16:34:28 +02:00
Fabien Potencier 32c4867f68 bumped version to 1.9.3-DEV 2012-08-25 19:36:54 +02:00
Fabien Potencier f04ef7d6c1 prepared the 1.9.2 release 2012-08-25 19:32:57 +02:00
Fabien Potencier 11e91f63e9 merged branch arnaud-lb/792 (PR #814)
Commits
-------

8fa97bb php5.2 fix
d6fc86a [Tests] Test accessing a public property when \ArrayAccess is implemented
6704227 [ext] made ext consistent with 8ec73cf475
228d2b0 [ext] use only read_property handler

Discussion
----------

Alternative fix for 792

This fixes #792 as described in https://github.com/fabpot/Twig/issues/792#issuecomment-7482480

- 228d2b0 removes the *object-to-array convertion* trick, since the bug comes from there, and it doesn't appear to be needed
- 6704227 is the equivalent of aa6b835816 + 8ec73cf475 (this were not needed before because the bug was hidden by the object to array trick: numeric strings and integers are treated equally in arrays keys)

---------------------------------------------------------------------------

by stof at 2012-08-23T10:19:17Z

@arnaud-lb you need to fix the PHP 5.2 support
2012-08-23 14:18:58 +02:00
Arnaud Le Blanc 46ce33972f [ext] fixed php 5.2 ZTS builds
zend_hash_apply_with_arguments and its callback argument do not have a
TSRMLS in php 5.2.
2012-08-23 13:58:44 +02:00
Arnaud Le Blanc 8fa97bb526 php5.2 fix 2012-08-23 13:32:55 +02:00
Arnaud Le Blanc 6704227644 [ext] made ext consistent with 8ec73cf475 2012-08-23 11:54:31 +02:00
Arnaud Le Blanc 228d2b0351 [ext] use only read_property handler 2012-08-23 11:54:31 +02:00
Arnaud Le Blanc 3ca6654617 avoid crash when TWIG_GET_ARRAY_ELEMENT returns NULL
fixes #807
2012-08-20 20:28:22 +02:00
Fabien Potencier 0eb4d01d92 added namespaced templates support in Twig_Loader_Filesystem 2012-07-22 13:52:31 +02:00
Fabien Potencier 657de7bdeb bumped version to 1.9.2-DEV 2012-07-22 12:32:58 +02:00
Fabien Potencier 9228acc809 prepared the 1.9.1 release 2012-07-22 12:25:41 +02:00
Fabien Potencier 3f9f587ba7 bumped version to 1.9.1-DEV 2012-07-13 18:31:16 +02:00
Fabien Potencier 31f0592525 prepared the 1.9.0 release 2012-07-13 18:26:34 +02:00
stealth35 9229ef334d Removed useless code 2012-06-27 17:57:06 +02:00
Fabien Potencier 7657c01e65 added support for more escaping strategies (url, css, and html_attr) 2012-06-27 09:26:36 +02:00
Fabien Potencier 4679ad51c5 bumped version to 1.8.4-DEV 2012-06-17 20:52:23 +02:00
Fabien Potencier 147e5d6d60 prepared the 1.8.3 release 2012-06-17 20:48:16 +02:00
Fabien Potencier 82e73f6bf2 bumped version to 1.8.3 2012-05-30 08:18:29 +02:00
Fabien Potencier 2afc513620 prepared the 1.8.2 release 2012-05-30 08:15:36 +02:00
Fabien Potencier 875fa010ce bumped version to 1.8.2-DEV 2012-05-17 18:06:57 +02:00
Fabien Potencier 0bee037579 prepared the 1.8.1 release 2012-05-17 18:02:47 +02:00
Fabien Potencier 8ec73cf475 fixed a regression introduced by aa6b835816 2012-05-16 16:19:00 +02:00
Fabien Potencier 925254821d bumped version to 1.9.0-DEV 2012-05-08 09:06:03 +02:00
Fabien Potencier 87766410dd prepared the 1.8.0 release 2012-05-08 09:03:46 +02:00
Fabien Potencier 40c9668854 bumped version to 1.8.0-DEV 2012-04-24 07:50:52 +02:00
Fabien Potencier 6ac8791d15 prepared the 1.7.0 release 2012-04-24 07:40:10 +02:00
Fabien Potencier e2220bb282 bumped version to 1.7.0-DEV 2012-04-03 09:56:57 +02:00
Fabien Potencier 50421c8620 bumped version to 1.6.4-DEV 2012-04-02 19:45:40 +02:00
Fabien Potencier ff61094aa3 prepared the 1.6.4 release 2012-04-02 19:42:18 +02:00
Fabien Potencier ab016bd605 bumped version to 1.6.4-DEV 2012-03-22 18:31:45 +01:00
Fabien Potencier c2a53a2614 prepared the 1.6.3 release 2012-03-22 18:28:15 +01:00
Fabien Potencier 4a0773a8ad fixed usage of Z_ADDREF_P for PHP 5.2 in the C extension 2012-03-22 14:25:00 +01:00
Fabien Potencier 2ecd314dc1 bumped version to 1.7.0-DEV 2012-03-18 03:33:04 +01:00
Fabien Potencier f43cc520d6 prepared the 1.6.2 release 2012-03-18 03:23:00 +01:00
Fabien Potencier c18a0e60fe bumped Twig version 2012-02-29 22:10:49 +01:00
Fabien Potencier 30929fde86 prepared the 1.6.1 release 2012-02-29 21:46:35 +01:00
Fabien Potencier 741b11c618 fixed Twig C extension 2012-02-28 23:19:54 +01:00
Fabien Potencier 203945602b bumped version to 1.7.0-DEV 2012-02-04 08:38:29 +01:00
Fabien Potencier 9154d27622 prepared the 1.6.0 release 2012-02-04 08:34:52 +01:00
Sergey Linnik 75bfb4e1a0 Syncing Twig extension with latest changes in Twig master 2012-01-15 01:15:28 +04:00
Fabien Potencier e74205e21e bumped version to 1.6.0-DEV 2012-01-05 15:35:20 +01:00
Fabien Potencier 5bba149706 prepared the 1.5.1 release 2012-01-05 15:34:14 +01:00