我是类的新手(更糟的是名称空间等等)因此,我知道必须创建主类所在的FacebookMyClass.php类(autoload.php、Facebook.php、FacebookApp.php等),然后是我的原型:
<?php
// I guess
namespace Facebook;
// Do I must 'use' or extending other class(es)?
// use ;
class FacebookMyClass extends Facebook {
// Do I have to "re-declare" parent's vars?
private $my_private_var;
public $my_public_var;
private $access_token;
// The main thing, I think, is how class is constructed
// public function __construct(array $config = []) {
public function __construct($id, $secret) {
// This will work? Need parameters?
parent::__construct();
}
public function accessParentProtectedVars($idfanpage) {
// How can I call/link to Facebook object/request/response?
$object = $this->get('/' . $idfanpage . '/albums?fields=name,id', $this->access_token);
}
private function getTokens($params = []) {
// code...
$this->access_token = '...';
}
}
?>问题是:我如何扩展Facebook\Facebook类(Es)?
发布于 2015-10-03 07:47:41
命名空间表示给定项目中的类或类组的位置。
扩展类意味着在类的范围内继承(访问)其方法。
因此,作为一个例子,请记住,您可能需要对此进行调整:
<?php
// Imports the class Facebook from the Facebook namespace eg /Facebook/Facebook.php
use Facebook\Facebook;
class MyFacebookExtension extends Facebook {
function __construct(array $config = []) {
// The base class requires an array parameter, so we accept that and forward it, and then call the parent constructor
parent::__construct($config);
}
// .. whatever methods you want to add .. You can also now access facebook() methods like $this->getclient() etc within this class.
}https://stackoverflow.com/questions/32853439
复制相似问题