0
0

[オレオレ05] 転章 vendorディレクトリ

Last updated at Posted at 2023-12-29

解説

これまでに作ってきたクラス(Request.php, View.php)はウェブアプリケーションにおける基幹部分であって、たいていのウェブアプリケーションに不可欠な処理を実行します。
このような不可欠な処理はプログラマーの脳負担を減らすためにも透過的であることが望まれます。

透過的にする(脳の意識から遠ざける)工夫のひとつとしてディレクトリを分けて管理します。

今回は supplier/ という名前のディレクトリを切ってそこで管理します。
(vendor/ にしないのは名前の重複を避けるためです)

目次

  1. ディレクトリ再構成
  2. index.php 修正

ディレクトリ再構成

現在までの構成
stampede/
    public/
        index.php
    views/
        hello.html
    Request.php
    View.php
修正後の構成
stampede/
    public/
        index.php
    views/
        hello.html
    supplier/
        stampede/
            App/
                Http/
                    Request.php
                    View.php
$ cd /opt/project/stampede/
$ mkdir -p supplier/stampede/App/Http
$ mv Request.php supplier/stampede/App/Http/
$ mv View.php supplier/stampede/App/Http/

index.php 修正

index.php
<?php

ini_set('display_errors', "On");

require_once('/opt/project/stampede/supplier/stampede/App/Http/Request.php');
require_once('/opt/project/stampede/supplier/stampede/App/Http/View.php');

$request = Request::getInstance();

$view = View::getInstance();

$view->display('hello.html', $request->all());

exit;

次の記事
[オレオレ06] 転章 オートローダー
前の記事
[オレオレ04] Viewクラスを作る

0
0
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
0
0