2015-09-10 47 views
0

我正在嘗試在我的symfony項目中集成WHAnonymous API。在symfony中集成Whatsapp API

我在項目中使用的作曲家包括安裝它,它現在是我的供應商的文件夾中。

但我不理解如何將其導入到我的項目!

這是我的經理級。

<?php 

namespace AppBundle\Managers; 

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 


class WhatsAppManager 
{ 

    private $test; 
    /** 
    * Constructor 
    */ 
    public function __construct() 
    { 
     $this->test =1; 
    } 

    public function sendMessage() 
    { 
    $username = ""; // Your number with country code, ie: 34123456789 
    $nickname = ""; // Your nickname, it will appear in push notifications 
    $debug = true; // Shows debug log 

    // Create a instance of WhastPort. 
    $w = new WhatsProt($username, $nickname, $debug); 
    var_dump("In send message method"); 
    } 
} 
?> 

我用

require_once 'whatsprot.class.php'; 

require_once 'Whatsapp\Bundle\Chat-api\src\whatsprot.class.php'; 

use Whatsapp\Bundle\Chat-api\Whatsprot 

但它只是不工作。 請告訴我正確的做法! 當我在symfony中使用第三方供應商時,我應該做些什麼。

我也考慮了WHanonymous的文檔,但我發現只有代碼片段使用它,而不是將其導入的方式。 Git回購WHAnonymous:https://github.com/WHAnonymous

回答

3

該類沒有名稱空間,但是由我的作曲家創建的自動加載系統正確加載。所以,你可以參考類沒有任何包括或要求指令,而只是用\爲例:

// Create a instance of WhastPort. 
    $w = new \WhatsProt($username, $nickname, $debug); 

希望這有助於

+0

Thanks.It工作! – user3425344

+0

但你能解釋我是如何工作的嗎? 作曲家的路徑是whatsapp/chat-api。 但是這個類的路徑是whatsapp/chat-api/src/whatsprot.class.php。 – user3425344

+0

hi @ user3425344該庫不尊重[標準PRS-0](http://www.php-fig.org/psr/psr-0/),但作曲家能夠正確加載類 – Matteo