我有一些旧代码,这些旧代码在使用作曲器更新了我前同事的Cosenary Instagram类的Handler类的依赖关系类后破裂。
在处理程序类中包含该类的先前引用是这样的:
namespace Acme\Instagram;
class Handler
{
/* GOT SOME USEFUL VARS HERE */
const API_URL = 'https://api.instagram.com/v1';
/**
* Initialize the library
*
* @param array $settings Contains our ClientId and upload dir
* @param string $root_dir The root of our application
*/
public function __construct( $settings, $root_dir = __DIR__ )
{
include_once $root_dir . '/vendor/cosenary/instagram/instagram.class.php'; //HERE WAS THE INCLUDE BEFORE
// THROW SOME EXCEPTIONS HERE IF SETTINGS MISSING ETC...
// New instance of the instagram class
$this->_instagram = new \Instagram($this->_clientId);
}
/* HANDLE SOM FUNCTIONS HERE */
}
如果我将include_once更改为:
require_once $root_dir . '/vendor/cosenary/instagram/src/Instagram.php';
然后我得到:
Fatal error: Class 'Acme\Instagram\Instagram' not found in
我想我需要将其作为构造函数中的引用传递,但这意味着我需要重写很多代码,并且可能还有5-10个其他项目依赖于此Hanlder类。有没有办法在其他课程中使用instagram课程?
尝试移出include_once和:
use MetzWeb\Instagram\Instagram;
但是,没有运气,没有任何帮助或指示,我非常感谢。
我不确定您的应用程序的结构如何。但是尝试一下:
namespace Acme\Instagram;
require_once $root_dir.'/vendor/autoload.php';
use MetzWeb\Instagram\Instagram AS InstagramClient;
class Handler
{
/* GOT SOME USEFUL VARS HERE */
const API_URL = 'https://api.instagram.com/v1';
/**
* Initialize the library
*
* @param array $settings Contains our ClientId and upload dir
* @param string $root_dir The root of our application
*/
public function __construct( $settings, $root_dir = __DIR__ )
{
// New instance of the instagram class
$this->_instagram = new InstagramClient($this->_clientId);
}
/* HANDLE SOM FUNCTIONS HERE */
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句