この記事は2年以上前に書かれたものです。
情報が古い可能性があります。
情報が古い可能性があります。
fuel/app/classes/file.php を作成
Fuel\Core\File クラスを継承し、Fuel\Core\File で定義されている create_dir メソッドを新たに定義し、オーバーライドします。
create_dir メソッドはバージョン1.7 のものを使用するので、create_dir は FuelPHP 1.8 → Fuel PHP1.7 の動作をするようになります。
<?php
/**
* ディレクトリ作成メソッド不具合のため、オーバーライド
* 読み込みは bootstrap.php にて設定
*
* @extends Fuel\Core\File
*/
class File extends Fuel\Core\File
{
/**
* Create an empty directory
*
* FuelPHP 1.7 のメソッドを使用
*
* @param string directory where to create new dir
* @param string dirname
* @param int (octal) file permissions
* @param string|File_Area|null file area name, object or null for non-specific
* @return bool
*/
public static function create_dir($basepath, $name, $chmod = null, $area = null)
{
$basepath = rtrim(static::instance($area)->get_path($basepath), '\\/').DS;
$new_dir = static::instance($area)->get_path($basepath.trim($name,'\\/'));
is_null($chmod) and $chmod = \Config::get('file.chmod.folders', 0777);
if ( ! is_dir($basepath) or ! is_writable($basepath))
{
throw new \InvalidPathException('Invalid basepath: "'.$basepath.'", cannot create directory at this location.');
}
elseif (is_dir($new_dir))
{
throw new \FileAccessException('Directory: "'.$new_dir.'" exists already, cannot be created.');
}
// unify the path separators, and get the part we need to add to the basepath
$new_dir = substr(str_replace(array('\\', '/'), DS, $new_dir), strlen($basepath));
// recursively create the directory. we can't use mkdir permissions or recursive
// due to the fact that mkdir is restricted by the current users umask
$basepath = rtrim($basepath, DS);
foreach (explode(DS, $new_dir) as $dir)
{
$basepath .= DS.$dir;
if ( ! is_dir($basepath))
{
try
{
if ( ! mkdir($basepath))
{
return false;
}
chmod($basepath, $chmod);
}
catch (\PHPErrorException $e)
{
return false;
}
}
}
return true;
}
}
fuel/app/bootstrap.php を編集
クラスをオーバーロードするため、作成したファイルを読み込むように記述します。
<?php
// Bootstrap the framework DO NOT edit this
require COREPATH.'bootstrap.php';
\Autoloader::add_classes(array(
// Add classes you want to override here
// Example: 'View' => APPPATH.'classes/view.php',
// Fuel\Core\File クラスのオーバーライド
'File' => APPPATH . 'classes/file.php',
));
// Register the autoloader
\Autoloader::register();
/**
* Your environment. Can be set to any of the following:
*
* Fuel::DEVELOPMENT
* Fuel::TEST
* Fuel::STAGING
* Fuel::PRODUCTION
*/
\Fuel::$env = \Arr::get($_SERVER, 'FUEL_ENV', \Arr::get($_ENV, 'FUEL_ENV', \Fuel::DEVELOPMENT));
// Initialize the framework with the config file.
\Fuel::init('config.php');
追加したのはこの部分です。
// Fuel\Core\File クラスのオーバーライド 'File' => APPPATH . 'classes/file.php',