Allow a server-wide default compile_dir and cache_dir via php.ini

Open
#1,214 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
php
Domain
backend

Research direction

Start in src/Smarty.php and review how $compile_dir and $cache_dir receive their defaults and how setCompileDir()/setCacheDir() override them. Compare the attached Smarty 3, 4, and 5 patches, then run the full test suite with and without the proposed php.ini settings. Done means configured roots work, root_strip handles the described paths, and application or subclass values and unchanged defaults still win.

Written by the indexing model from the issue text.

Description

$compile_dir and $cache_dir default to ./templates_c/ and ./cache/, which on most servers puts web-writable PHP inside the document root, even though the docs advise against it. An administrator can't change that default server-wide: each application has to call setCompileDir()/setCacheDir() (#294).

Proposal: optional php.ini settings, read with get_cfg_var():

smarty.compile_root = /var/cache/smarty_compile
smarty.cache_root   = /var/cache/smarty_cache
smarty.root_strip   = /var/www

When the application hasn't set a directory itself, the default becomes <root>/<cwd minus root_strip>/, so /var/www/example.com/app compiles to /var/cache/smarty_compile/example.com/app/. A cwd outside root_strip keeps the stock default; without root_strip the full path is mirrored (covers ~/public_html). No settings: nothing changes. An application's or subclass's own value always wins. Without these ini settings, nothing changes.

About 50 lines in src/Smarty.php; the full test suite passes with and without the settings. patches attached;

smarty3-compile-cache-root-default.patch
smarty4-compile-cache-root-default.patch
smarty5-compile-cache-root-default.patch

Dominant language
PHP
Stars
2.3k
Forks
705
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from smarty-php/smarty

All issues in smarty-php/smarty

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.