ninsuo / twigfiddle Goto Github PK
View Code? Open in Web Editor NEWtwigfiddle.com provides a small development environment to develop, run, store and access Twig code online.
Home Page: https://twigfiddle.com
License: MIT License
twigfiddle.com provides a small development environment to develop, run, store and access Twig code online.
Home Page: https://twigfiddle.com
License: MIT License
Can be useful to add a "Show HTML result" button to interpret HTML results instead of displaying text.
See: http://twigfiddle.com/e88llr
Should wrap the feature inside an iframe endpointed elsewhere than on twigfiddle.com to secure against xss using cross origin request policies.
Make sure to set the state
on all oauth providers
It is often useful to run templates with strict variables turned on to handle the case of mistakes in variables. I don't see any way to control this currently.
Consider the following template:
0
Rendering that template outputs nothing:
It should output 0
.
TwigPHP executed from the command line outputs 0
, as expected.
The following fiddle: https://twigfiddle.com/3pcjby
Makes cli crash without placing himself into the debug directory.
The current gandi certificate is going to expire, and i'm going to replace it with a let's encrypt one.
But this old and sh*tty server is under plesk so this is of course very hard to do.
Waiting for the new server to be ready, I'll try to install it anyway but you may have issues during those 2 days.
After enabling extensions v1.5.4 with Twig v3.3.7 I receive the below error message when I press Run:
#1 | Type | 1 |
---|---|---|
#2 | Message | Uncaught TypeError: Argument 2 passed to Fuz\Process\Service\TwigExtensionsManager::loadTwigExtensions() must be an instance of Twig_Environment, instance of Twig\Environment given, called in twigfiddle:cli/src/Fuz/Process/Service/ExecuteManager.php on line 62 and defined in twigfiddle:cli/src/Fuz/Process/Service/TwigExtensionsManager.php:27 Stack trace: #0 twigfiddle:cli/src/Fuz/Process/Service/ExecuteManager.php(62): Fuz\Process\Service\TwigExtensionsManager->loadTwigExtensions() #1 twigfiddle:cli/src/Fuz/Process/Command/RunCommand.php(107): Fuz\Process\Service\ExecuteManager->executeFiddle() #2 twigfiddle:cli/src/Fuz/Process/Command/RunCommand.php(141): Fuz\Process\Command\RunCommand->process() #3 twigfiddle:cli/vendor/symfony/console/Command/Command.php(245): Fuz\Process\Command\RunCommand->execute() #4 twigfiddle:cli/vendor/symfony/console/Application.php(835): Symfony\Component\Console\ |
#3 | File | twigfiddle:cli/src/Fuz/Process/Service/TwigExtensionsManager.php |
#4 | Line | 27 |
Am I doing something incorrect (I'm learning twig) or is this a bug?
This could be achieved by running processes like php -d path/to/twig.so ...
.
There are cases where a bug can be related to the usage of the C extension, and reproducing it needs to use it.
I created a new fiddle with multiple templates. Some of the templates were empty. When I tried to save the fiddle, I got this this error message:
We're sorry, but an error occurred...
I added some text to the empty templates and tried saving again, which was then successful.
Then I tried removing that text and saving again, which was also successful.
So it seems that fiddles won't save empty templates only on the first save.
The OAuthUserProvider class has its own way to manage logged-in users, but we should only rely on Symfony security component.
As a User connecting from Google and Facebook creates 2 entities (no unified accounts), username
should contain the resource_owner/resource_id couple and not user's nickname (so the user provider is able to get it back from db).
A generic implementation (to be adapted to twigfiddle specifically) could be:
<?php
namespace Fuz\AppBundle\Provider;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUserProvider as BaseUserProvider;
use Fuz\AppBundle\Entity\User;
class OAuthUserProvider extends BaseUserProvider
{
protected $em;
public function __construct($em)
{
$this->em = $em;
}
public function loadUserByUsername($username)
{
list($resourceOwner, $resourceOwnerId) = json_decode($username, true);
$user = $this->em->getRepository('FuzAppBundle:User')
->getUserByResourceOwnerId($resourceOwner, $resourceOwnerId);
if ($user) {
$user->setUsername($username);
}
return $user;
}
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$resourceOwner = $response->getResourceOwner()->getName();
$resourceOwnerId = $response->getUsername();
$name = $response->getRealName();
$json = json_encode([$resourceOwner, $resourceOwnerId]);
$user = $this->loadUserByUsername($json);
$reload = false;
if (is_null($user)) {
$user = new User();
$user->setResourceOwner($resourceOwner);
$user->setResourceOwnerId($resourceOwnerId);
$user->setUsername($json);
$user->setNickname($name);
$user->setContact($response->getEmail());
$user->setSigninCount(1);
$this->em->persist($user);
$this->em->flush($user);
$reload = true;
} else {
$user->setUsername($json);
$user->setNickname($name);
$user->setContact($response->getEmail());
$user->setSigninCount($user->getSigninCount() + 1);
$this->em->persist($user);
$this->em->flush($user);
}
if ($reload) {
return $this->loadUserByUsername($json);
}
return $user;
}
public function supportsClass($class)
{
return $class === 'Fuz\\AppBundle\\Entity\\User';
}
}
1.x is erroring for me before it gets off the ground. The code
1
gives me
Uncaught Error: Class 'Twig_Loader_Filesystem' not found in twigfiddle:cli/src/Fuz/Process/TwigEngine/V2TwigEngine.php:114 Stack trace: #0 twigfiddle:cli/src/Fuz/Process/TwigEngine/V2TwigEngine.php(35): Fuz\Process\TwigEngine\V2TwigEngine->loadBefore270('/var/www/twigfi...', '/var/www/twigfi...', '/var/www/twigfi...') #1 twigfiddle:cli/src/Fuz/Process/Service/ExecuteManager.php(58): Fuz\Process\TwigEngine\V2TwigEngine->load('/var/www/twigfi...', '/var/www/twigfi...', '/var/www/twigfi...') #2 twigfiddle:cli/src/Fuz/Process/Command/RunCommand.php(107): Fuz\Process\Service\ExecuteManager->executeFiddle(Object(Fuz\Process\Agent\FiddleAgent)) #3 twigfiddle:cli/src/Fuz/Process/Command/RunCommand.php(141): Fuz\Process\Command\RunCommand->process() #4 twigfiddle:cli/vendor/symfony/console/Command/Command.php(266): Fuz\Process\Command\RunCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfon
Same error for anything else.
Fiddle: https://twigfiddle.com/lop40u
Hi and thanks for making twigfiddle, it's very useful.
While browsing fiddle, I noticed that there is no way of viewing the most popular fiddles whereas the number of views is displayed.
I think it could be a great way to find interesting twig tricks.
Thanks again,
Paul
I'm moving twigfiddle from an old server to a brand new one.
You may experience a few issues during that night:
Thanks for understanding!
It would be great if twigfiddle.com could support HTTPS (especially when you are dealing with authentication).
Looks like there's missing index or eager/malformed query, "Browse" button ends up on "504 Gateway Time-out" when signed-in.
I feel this fiddle should support CSV format as data format. how I plan to use this feature:
I can provide an implementation, if you want.
The V1Engine passes the cache directory to the second argument of Twig_Loader_Filesystem for compat with very old versions of Twig 1.x
But recent versions of Twig 1.x use this argument in another way, which might cause issues.
Need some monitoring tools to check that the website is up and running.
In file included from /Library/WebServer/Documents/twigfiddle/cli/twig/uncompressed/Twig-1.10.0/ext/twig/twig.c:22:
In file included from /usr/local/php5/include/php/ext/standard/php_smart_str.h:24:
/usr/local/php5/include/php/ext/standard/php_smart_str_public.h:30:3: error: typedef redefinition with different types
('struct smart_str' vs 'struct smart_str')
/Library/WebServer/Documents/twigfiddle/cli/twig/uncompressed/Twig-1.10.0/ext/twig/twig.c:80:54: error: too many arguments to
function call, expected 2, have 3
return zend_symtable_exists(Z_ARRVAL_P(array), key, key_len + 1);
~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~
/Library/WebServer/Documents/twigfiddle/cli/twig/uncompressed/Twig-1.10.0/ext/twig/twig.c:97:35: error: too many arguments to
function call, expected single argument 'name', have 3 arguments
if (zend_lookup_class(interface, strlen(interface), &pce TSRMLS_CC) == FAILURE) {
~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~
/Library/WebServer/Documents/twigfiddle/cli/twig/uncompressed/Twig-1.10.0/ext/twig/twig.c:110:34: warning: incompatible pointer
types passing 'zval **' (aka 'struct _zval_struct **') to parameter of type 'zval *' (aka 'struct _zval_struct *'); remove &
[-Wincompatible-pointer-types]
zend_call_method_with_1_params(&object, ce, NULL, "offsetget", &retval, offset);
^~~~~~~ ^
/Library/WebServer/Documents/twigfiddle/cli/twig/uncompressed/Twig-1.10.0/ext/twig/twig.c:144:41: error: use of undeclared
identifier 'IS_BOOL'
return (retval && Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval));
^
etc. etc. Just a ton of errors when executing the sh prepare.sh
command
This lib looks more friendly than twigfiddle current implementation.
https://github.com/zenorocha/clipboard.js
Currently, when there is an error, the display of the compiled templates is not available.
While this makes sense for syntax errors (there is no compiled template yet), it would be great to have it in other cases (for runtime errors for instance)
All use of the C extension end up with a fatal error:
PHP Startup: Unable to load dynamic library 'twigfiddle:web/app/../../cli/twig/uncompressed/Twig-1.29.0/ext/twig/modules/twig.so' - twigfiddle:web/app/../../cli/twig/uncompressed/Twig-1.29.0/ext/twig/modules/twig.so: undefined symbol: zval_used_for_init
Sample: https://twigfiddle.com/1kmsil
A spelling error on the word 'trown' - should be 'thrown'.
It will be cleaner to use bower instead
It should be working since 2.x -> https://twig.symfony.com/doc/3.x/filters/format_currency.html
Latest Twig release breaks the V2TwigEngine's spl_autoload_register logic.
Use up to date \Twig\Loader\FilesystemLoader
instead if available.
It seems that the yesterday's Twig 3.8.0 release does not run fiddles because of php 8 requirement:
Uncaught Error: Call to undefined function Twig\Loader\str_contains() in twigfiddle:cli/twig/uncompressed/Twig-3.8.0/src/Loader/FilesystemLoader.php:253 Stack trace: #0 twigfiddle:cli/twig/uncompressed/Twig-3.8.0/src/Loader/FilesystemLoader.php(188): Twig\Loader\FilesystemLoader->validateName() #1 twigfiddle:cli/twig/uncompressed/Twig-3.8.0/src/Loader/FilesystemLoader.php(131): Twig\Loader\FilesystemLoader->findTemplate() #2 twigfiddle:cli/twig/uncompressed/Twig-3.8.0/src/Environment.php(264): Twig\Loader\FilesystemLoader->getCacheKey() #3 twigfiddle:cli/src/Fuz/Process/TwigEngine/AbstractTwigEngine.php(45): Twig\Environment->getTemplateClass() #4 twigfiddle:cli/src/Fuz/Process/Service/ExecuteManager.php(66): Fuz\Process\TwigEngine\AbstractTwigEngine->render() #5 twigfiddle:cli/src/Fuz/Process/Command/RunCommand.php(107): Fuz\Process\Service\ExecuteManager->executeFiddle() #6 /var/www/twigfid
twigfiddle runs normally in any other Twig version.
This Twig version is using symfony/polyfill-php80
, it needs to be added to the project.
When the form is kept empty or when the fiddle has just been saved without any further changes, leaving the page should not ask for confirmation.
When it asked me after I saved the fiddle, it made me wonder whether saving was done or no.
This might be useful to integrate a PHP editor so we can develop and integrate custom twig extensions to fiddles.
This has not been scheduled for the first release as this leads to lots of questions about security. If you have ideas about the way to run arbitrary PHP code safely, don't hesitate to share.
Supporting github oauth would make sense (I even think it is more relevant than facebook login for a tool aimed at devs)
At the moment, twigfiddle.com seems to send an incomplete SSL certificate chain. This causes Firefox to show a certificate error.
SSL Labs report: https://www.ssllabs.com/ssltest/analyze.html?d=twigfiddle.com
Gandi intermediate certificates: https://wiki.gandi.net/en/ssl/intermediate
The option to enable strict variables is quite hidden in the UI.
twigfiddle is often used to report reproducing test cases for Twig (it is even the official recommendation). But enabling strict variables often allows to discover the issue (as Twig fails loudly rather than returning null
for access to undefined methods or variables).
What do you think about enabling it by default for new fiddles (this is to ensure we don't change the behavior of existing fiddles), while keeping the option to disable it (in case you want to reproduce a bug happening only without strict mode) ?
For Twig 2+, it would be great to provide the extensions available in twig/*-extra
packages (I just tried using some filter from twig/intl-extra
).
Looks like an issue using the null coalescing operator.
This should work:
{{ variable ?? "Fallback" }}
But I receive an error instead:
The "defined" test only works with simple variables.
when using Twig 2.x, the option to enable the C extension should not be displayed in the options selector, as the C extension does not exist for Twig 2.
It may be interesting to access non built-in extensions.
http://twig.sensiolabs.org/doc/extensions/index.html
As we support all twig versions, we should automatically select the right supported extension accordingly.
String variables are escaped differently depending on whether they are set in Twig or YAML
This is works as expected:
{# main.twig #}
{% set str = '\-' %}
{{ str }} {# outputs `-` #}
This does not:
# yaml
str: '\-'
{# main.twig #}
{{ str }} {# outputs `\-` #}
Fiddle: https://twigfiddle.com/zeewkl
Got the following message after a composer update
Imported: ../samples/for.1.json as fiddle ID = 57
Imported: ../samples/hello-world.json as fiddle ID = 58
[InvalidArgumentException]
Entity has to be managed or scheduled for removal for single computation Fuz\AppBundle\Entity\FiddleTemplate@000000005b5904ef0000000066e7bb34
twigfiddle:import [files1] ... [filesN]
It can be useful to debug variables when using twigfiddle.
Integrate a {{ dump() }}
function, that will use the VarDumper component in order to dump variables in a new pane (below the Result pane for example).
As {{ dump() }}
can be used several times, a line above showing where it was called (file:line) should be useful.
See https://twigfiddle.com/oxixzf and https://twigfiddle.com/0nw355
Both of them are rendering an output with a leading newline. But the raw output panel strips this newline.
The panel showing the compiled template provides a proof that the newline is part of the Twig rendering.
This triggered a false bug report on Twig (the first fiddle is part of twigphp/Twig#3162, the second is my attempt at proving it is a twigfiddle issue instead).
Hi,
We can't run scripts longer than 8192 characters. Can that be changed, really inconvenient for our development.
Thanks much in advance,
Auke
Not a single fiddle works anymore. Fatal error without output.
Twig is good at reporting the usage of deprecated features. It would be great if twigfiddle could use this to report them to the user (avoid cases where people say "it works in 1.30 and not in 2.0", while 1.30 actually warned when using it).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.