mirror of
https://github.com/Mibew/mibew.git
synced 2025-02-12 10:31:09 +03:00
Use composer's autoloader
Funny, but it fixes #75 without classes changing
This commit is contained in:
parent
3b43090bda
commit
82a4d7a2a2
@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is a part of Mibew Messenger.
|
|
||||||
*
|
|
||||||
* Copyright 2005-2014 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Mibew;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Autoloader for classes which implements PSR-0 standard.
|
|
||||||
*/
|
|
||||||
class Autoloader
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Base path for autoloaded classes.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $basePath;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class loader.
|
|
||||||
*
|
|
||||||
* Map class name to file system using PSR-0 and base path specified via
|
|
||||||
* \Mibew\Autoloader::register().
|
|
||||||
*
|
|
||||||
* @param string $class_name Class name to load.
|
|
||||||
*/
|
|
||||||
public function autoload($class_name)
|
|
||||||
{
|
|
||||||
$class_name = ltrim($class_name, '\\');
|
|
||||||
$file_name = '';
|
|
||||||
$namespace = '';
|
|
||||||
if ($last_ns_pos = strrpos($class_name, '\\')) {
|
|
||||||
$namespace = substr($class_name, 0, $last_ns_pos);
|
|
||||||
$class_name = substr($class_name, $last_ns_pos + 1);
|
|
||||||
$file_name = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
|
||||||
}
|
|
||||||
$file_name = $this->basePath . DIRECTORY_SEPARATOR . $file_name
|
|
||||||
. str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
|
|
||||||
|
|
||||||
if (is_file($file_name)) {
|
|
||||||
include_once($file_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new instance as an SPL autoloader.
|
|
||||||
*
|
|
||||||
* @param string $base_path Base path for classes-to-files mapping.
|
|
||||||
*
|
|
||||||
* @return \Mibew\Autoloader Registered autoloader instance.
|
|
||||||
*/
|
|
||||||
public static function register($base_path)
|
|
||||||
{
|
|
||||||
$loader = new self($base_path);
|
|
||||||
spl_autoload_register(array($loader, 'autoload'));
|
|
||||||
|
|
||||||
return $loader;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param string $base_path Base path for classes-to-files mapping.
|
|
||||||
*/
|
|
||||||
protected function __construct($base_path)
|
|
||||||
{
|
|
||||||
$this->basePath = rtrim($base_path, '/\\');
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,15 +22,10 @@
|
|||||||
*/
|
*/
|
||||||
define('MIBEW_FS_ROOT', dirname(dirname(__FILE__)));
|
define('MIBEW_FS_ROOT', dirname(dirname(__FILE__)));
|
||||||
|
|
||||||
// Initialize classes autoloading
|
// Initialize autoloader for root classes and external dependecies
|
||||||
require_once(MIBEW_FS_ROOT . '/libs/classes/Mibew/Autoloader.php');
|
$loader = require_once(MIBEW_FS_ROOT . '/vendor/autoload.php');
|
||||||
Mibew\Autoloader::register(MIBEW_FS_ROOT . '/libs/classes');
|
$loader->addPsr4('', MIBEW_FS_ROOT . '/libs/classes/', true);
|
||||||
|
$loader->addPsr4('', MIBEW_FS_ROOT . '/plugins/');
|
||||||
// Automatically load plugins
|
|
||||||
Mibew\Autoloader::register(MIBEW_FS_ROOT . '/plugins');
|
|
||||||
|
|
||||||
// Initialize external dependencies
|
|
||||||
require_once(MIBEW_FS_ROOT . '/vendor/autoload.php');
|
|
||||||
|
|
||||||
// Load system configurations
|
// Load system configurations
|
||||||
require_once(MIBEW_FS_ROOT . '/libs/common/configurations.php');
|
require_once(MIBEW_FS_ROOT . '/libs/common/configurations.php');
|
||||||
|
Loading…
Reference in New Issue
Block a user