system/application/pear
system/application/pear/PEAR.php
system/application/pear/HTTP/Request.php
system/application/pear/Net/Socket.php
system/application/pear/Net/URL.php
$config['enable_hooks'] = TRUE;
$hook['pre_controller'][] = array(
'class' => 'Pear_hook',
'function' => 'index',
'filename' => 'pear_hook.php',
'filepath' => 'hooks'
);
system/application/hooks/pear_hook.php
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Pear_hook{
function index(){
// OS independent
ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.BASEPATH.'application/pear/');
// on Apache
// ini_set('include_path',ini_get('include_path').':'.BASEPATH.'application/pear/');
// on Windows
// ini_set('include_path',ini_get('include_path').';'.BASEPATH.'application/pear/');
}
}
?>
system/application/libraries/Pearloader.php:
<?php
class Pearloader {
function load($package, $class = NULL, $options = NULL) {
if (is_null($class)) {
require_once $package . '.php';
$classname = $package;
} else {
require_once $package . '/' . $class . '.php';
$classname = $package . '_' . $class;
}
if (($count = func_num_args()) > 2) {
$params = '';
for ($i = 2; $i < $count; $i++) {
eval("\$var$i = func_get_arg($i);");
$params .= "\$var$i" . (($i + 1 == $count) ? '' : ', ');
}
eval("\$instance = new $classname($params);");
return $instance;
} else {
return new $classname();
}
}
}
?>
$this->pearloader->load('Packagename','Classname');
function example(){
$url = 'http://www.yahoo.com';
$this->load->library('pearloader');
$http_request = $this->pearloader->load('HTTP','Request');
$http_request->setURL($url);
$http_request->sendRequest();
echo $http_request->getResponseBody();
}
Source: https://habr.com/ru/post/37929/
All Articles