1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ethna(Ethnam)に入門してみた 2026

1
Last updated at Posted at 2026-04-25

Ethnaは、いにしえのフレームワークです。使用を固く禁じます💀🦴☠️🪦

公式ドキュメントを見ても具体的な処理の流れが分からないので追ってみました http://ethna.jp/doc/tutorial/02-action-view-tpl.html

image.png

Ethnaの環境構築(GitHub Codespaces)

GitHub Codespaces

# Ethnaは$array{0}を使っておりPHP8は動かないため、PHP7をインストール
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install -y php7.4 php7.4-xdebug

# Smartyが古すぎる💀のでセキュリティを弱くする
composer config -g secure-http false
composer create-project ethna/ethna-project --no-security-blocking -s dev HelloWorld
cd HelloWorld
php7.4 \
  -d xdebug.mode=trace,profile \
  -d xdebug.start_with_request=yes \
  -d xdebug.trace_output_dir=$PWD \
  -d xdebug.trace_output_name=trace.%p \
  -d xdebug.trace_format=1 \
  -d xdebug.output_dir=$PWD \
  -d xdebug.profiler_output_name=cachegrind.out.%p \
  -S localhost:8080 -t www

Webページにアクセスすると、trace.PID.xtというトレースファイルが生成されます。

GitHub Codespacesのプロキシ対策

リクエストヘッダーから正しいURLを取得します。

vendor/ethna/ethna/Ethna/class/Config.php
<?php

$config['url'] = sprintf("%s://%s/", $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? 'http', $_SERVER['HTTP_X_FORWARDED_HOST'] ?? $_SERVER['HTTP_HOST']);
vendor/ethna/ethna/Ethna/class/Util.php
<?php

$url = $protocol . ($_SERVER['HTTP_X_FORWARDED_HOST'] ?? $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/') . '/';

www/index.phpからHTMLが出力されるまでの流れ

より詳細に分析したい方は、trace.PID.xtをxdebug-trace-viewerに読み込ませてください。

www/index.phpが実行されている。
image.png
ActionClassprepare()perform()が実行されている。
image.png
ViewClasspreforward()が実行されている。
image.png
.tplファイルから.phpファイルにコンパイルし、includeして出力している。
image.png

1. www/index.phpを実行し、Example_Controller::mainメソッドを呼ぶ(15行目)

2. Example_Controller->triggerメソッドを呼ぶ(904行目)

3. Symfony\Component\EventDispatcher\EventDispatcher->dispatchメソッドを呼ぶ(986行目)

4. Ethna_Events::CONTROLLER_TRIGGERがディスパッチされ、TriggerSubscriber::triggerWWWメソッドを呼ぶ(16行目)

5. TriggerSubscriber::triggerImplメソッドを呼ぶ(233行目)

CLI実行のときは、$event->getGateway() == GATEWAY_WWWがfalseになる

6. Ethna_Backend->performメソッドを呼ぶ(308行目)

7. Example_Action_Index->prepareメソッドとExample_Action_Index->performメソッドを呼ぶ(357と364行目)

prepareメソッドでnull以外が返ったときは、performメソッドが呼ばれない(360行目)

346行目でActionClassがインスタンス化される

8. 6に戻ってSymfony\Component\EventDispatcher\EventDispatcher->dispatchメソッドを呼ぶ(324行目)

9. Ethna_Events::CONTROLLER_FORWARDがディスパッチされ、ForwardSubscriber::forwardメソッドを呼ぶ(16行目)

10. Example_View_Index->preforwardメソッドを呼ぶ(34行目)

あんま使わんけど

11. Ethna_ViewClass->forwardメソッドを呼ぶ(36行目)

12. Ethna_ViewClass->_getRendererメソッドを呼ぶ(158行目)

13. Smartyテンプレートエンジンで使用する変数を設定する

14. 12に戻ってEthna_Renderer_Smarty->performメソッドを呼ぶ(166行目)

15. Smarty->displayメソッドを呼ぶ(101行目)

16. Smarty->fetchメソッドを呼ぶ(1107行目)

17. .tplファイルを.phpファイルにコンパイルし、includeで出力する(1257行目)

1255行目の_compile_resourceメソッドで.phpがコンパイルされます。

自動コンパイルされた.phpファイルの例

tmp/aa96c1f7f49931aff004722ba554035a^%%45^45E^45E480CD%%index.tpl.php
<?php /* Smarty version 2.6.28, created on 2026-04-25 11:34:29
         compiled from index.tpl */ ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<link rel="stylesheet" href="<?php echo $this->_tpl_vars['config']['url']; ?>
css/ethna.css" type="text/css" />
	<title>Example</title>
</head>
<body>
<div id="header">
	<h1>Example</h1>
</div>

<div id="main">
	<h2>Index Page</h2>
	<p>hello, world!</p>
</div>

<div id="footer">
	Powered By <a href="http://ethna.jp">Ethna</a>-<?php echo @ETHNA_VERSION; ?>
.
</div>
</body>
</html>
1
2
0

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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?