LoginSignup
20

More than 5 years have passed since last update.

SmartyをComposerでインストールする

Last updated at Posted at 2013-06-22

開発速度が心配されるSmartyですが、密かにComposerでセットアップする事ができる。展開したファイルからlibをコピーしてrequireという手順は実は必要なかった。
通常どおりcomposer.jsonを記述してcomposer installでセットアップされる。

composer.json
{
 "require": {
   "smarty/smarty": "dev-trunk"
 }
}

あとはComposerコマンドを起動する事で自動的にライブラリのセットアップを行う。

結果
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install
$ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing smarty/smarty (dev-trunk)
    Checking out /trunk/@4746
Writing lock file
Generating autoload files

$ ls -l vendor/
total 4
-rw-r--r-- 1 vagrant vagrant 182 Jun 22 07:53 autoload.php
drwxr-xr-x 1 vagrant vagrant 238 Jun 22 07:53 composer
drwxr-xr-x 1 vagrant vagrant 102 Jun 22 07:50 smarty

これでSmartyクラスをオートロードして利用する事ができる。

index.php
<?php
require './vendor/autoload.php';
$smarty = new Smarty();
$smarty->display('hoge.tpl');
templates/hoge.tpl
This is rendered by {$smarty.version}

実行してみると無事にテンプレートがレンダリングされた。


This is rendered by Smarty-3.1-DEV

Smartyをまだ使っているにせよ、レガシーなrequireを一つ減らす事ができるのでComposerでインストールする事が望ましい。

参考
https://packagist.org/packages/smarty/smarty

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20