Skip to content
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

#44 Temporary directory location #45

Merged
merged 3 commits into from
Jul 27, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions twig-gettext-extractor
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ if (file_exists($a = __DIR__.'/../../autoload.php')) {
require_once __DIR__.'/vendor/autoload.php';
}

$twig = new Twig_Environment(new Twig\Gettext\Loader\Filesystem('/'), array(
'cache' => '/tmp/cache/'.uniqid(),
$tempDirectory = empty(getenv('TMPDIR')) ? DIRECTORY_SEPARATOR . 'tmp' : getenv('TMPDIR');
$cacheDirectory = implode(DIRECTORY_SEPARATOR, array($tempDirectory, 'cache', uniqid()) );

$twig = new Twig_Environment(new Twig\Gettext\Loader\Filesystem(DIRECTORY_SEPARATOR), array(
Copy link
Owner

@umpirsky umpirsky Jul 27, 2016

Choose a reason for hiding this comment

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

I would prefer something like this:

$twig = new Twig_Environment(new Twig\Gettext\Loader\Filesystem(DIRECTORY_SEPARATOR), array(
    'cache'       => sprintf('%s/cache/%s', getenv('TWIG_GETTEXT_EXTRACTOR_TMP') ? '/tmp' : getenv('TWIG_GETTEXT_EXTRACTOR_TMP'), uniqid()),
    'auto_reload' => true
));
  • Keep env vars namespaced.
  • Keep code compact.

Thanks!

'cache' => $cacheDirectory,
'auto_reload' => true
));
$twig->addExtension(new Twig_Extensions_Extension_I18n());
Expand Down