我在heroku上使用Symfony2应用程序,但无法连接到我的API.
我向你解释一下这个场景:
所以我的问题是在第3点.我尝试使用cURL和file_get_contents来访问URL,但两者都没有用.
当我尝试访问向我提供访问API所需的OAuth令牌的URL时,它会失败.我尝试在浏览器(或邮递员)中手动访问此URL,并返回OAuth令牌.
事件监听器:
// Call of the url to deliver the token
$clientAPI = $this->em->getRepository('BgAPIBundle:Client')->findOneBy(array('providerAccess' => 'pcv'));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, urldecode($this->router->generate('fos_oauth_server_token', array('grant_type' => 'http://www.myapp/api/grants/api_key', 'client_id' => $clientAPI->getId() . '_' . $clientAPI->getRandomId(), 'client_secret' => $clientAPI->getSecret(), 'api_key' => $event->getAuthenticationToken()->getUser()->getApiKey()), true)));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$this->error = $response; // Only if there is problem
curl_close($curl);
// Write in logs
$date = new \DateTime('now');
if …Run Code Online (Sandbox Code Playgroud) 我们应该直接访问受保护的属性还是使用PHP中的getter?
我有两个班,一个是另一个班的女儿.在母亲中,我将某些属性声明为受保护,并为我的属性生成所有getter.所以,我可以直接或通过getter访问和定义这些属性,但我不知道是否有更好的解决方案.
示例:
class Mother {
private $privateProperty;
protected $protectedProperty;
public $publicProperty;
/*** Private property accessors ***/
public function setPrivateProperty($value)
{
$this->privateProperty = $value;
}
public function getPrivateProperty()
{
return $this->privateProperty;
}
/*** Protected property accessors ***/
public function setProtectedProperty($value)
{
$this->protectedProperty = $value;
}
public function getProtectedProperty()
{
return $this->protectedProperty;
}
}
class Child extends Mother {
public function showProtectedProperty() {
return $this->getProtectedProperty(); // This way ?
return $this->protectedProperty; // Or this way ?
}
public function defineProtectedProperty() { …Run Code Online (Sandbox Code Playgroud) 我想检索实体中具有注释 @Translatable 的所有字段,例如:
class WonderfulClass
{
/**
* @var string
* @Gedmo\Translatable
*/
private $aField;
/**
* @var string
* @Gedmo\Translatable
*/
private $otherField;
/**
* @var string
*/
private $lastField;
Run Code Online (Sandbox Code Playgroud)
在本例中,我想检索具有 @Gedmo\Translatable 注释的字段($aField 和 $otherField)。
有人知道该怎么做吗?