小编Max*_*ard的帖子

heroku上的cURL超时

我在heroku上使用Symfony2应用程序,但无法连接到我的API.

我向你解释一下这个场景:

  1. 我通过表单在我的应用程序中连接我
  2. 当我正确登录我的应用程序时,会触发一个事件监听器
  3. 我访问了向我提供API令牌的URL,并将这些凭据保存在用户会话中
  4. 我将连接(到应用程序和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 curl heroku symfony

8
推荐指数
1
解决办法
557
查看次数

我们应该直接访问受保护的属性还是使用getter?

我们应该直接访问受保护的属性还是使用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)

php

6
推荐指数
1
解决办法
1047
查看次数

查找具有特定@Annotation的所有实体字段

我想检索实体中具有注释 @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)。

有人知道该怎么做吗?

php annotations symfony doctrine-orm

5
推荐指数
1
解决办法
3173
查看次数

标签 统计

php ×3

symfony ×2

annotations ×1

curl ×1

doctrine-orm ×1

heroku ×1