leadpages/leadboxes

一个允许您轻松将Leadpages Leadboxes集成到PHP项目的包

这个包的官方仓库似乎已经消失了,因此该包已被冻结。

1.2.2 2017-06-20 20:09 UTC

README

Build Status

摘要

Leadpages Auth旨在使您的集成快速启动变得简单。

  • 抽象出调用Leadpages以检索您的安全令牌所需的方法。
  • 内置最小存储抽象,以便Leadpages扩展遵循已知的标准集合。
  • 使用Guzzle5来允许在所有平台上保持一致的Http抽象层。选择Guzzle5以支持PHP 5.4

代码示例 - WordPress

<?php

/**
 * require composer autoload this path will probably change for your implementation
 * wordpress would suggest using plugin_dir_path
 * example require plugin_dir_path(dirname(dirname(dirname(__FILE__))))."/vendor/autoload.php";
*/

require dirname(dirname(dirname(__FILE__))) . "/vendor/autoload.php";

use GuzzleHttp\Client;
use Leadpages\Auth\LeadpagesLogin;

/**
 * Extend the Leadpages login abstract class
 * and fill out the required methods to store and retrieve your token
 * Class WordPressLeadpagesLogin
 */
class WordPressLeadpagesLogin extends LeadpagesLogin
{

    /**
     * store token in Wordpress Database
     *
     * @return mixed
     */
    public function storeToken()
    {
        update_option($this->tokenLabel, $this->token);
    }


    /**
     * get token form WordPress Database and set the $this->token
     * $this->token needs to be set on this method
     */
    public function getToken()
    {
        $this->token = get_option($this->tokenLabel);
    }

    /**
     * Delete token from WordPress Database
     * @return mixed
     */
     
    public function deleteToken()
    {
        delete_options($this->tokenLabel);
    }

    /**
     * method to check if token is empty
     *
     * @return mixed
     */
    public function checkIfTokenIsEmpty()
    {
        // TODO: Implement checkIfTokenIsEmpty() method.
    }
}

//instantiate Class
$leadpagesLogin = new WordPressLeadpagesLogin(new Client());
//call get user pipe into parseResponse
$response = $leadpagesLogin->getUser('example@example.com', 'password')->parseResponse();

if($response == 'success'){
    $this->storeToken();
}else{
    //this->response holds a json object with response codes
    return $this->response;
}

//check if a user is logged in
$isLoggedIn = $leadpagesLogin->checkIfUserIsLoggedIn();


安装

可以通过Composer安装此包

#install composer
curl -sS https://getcomposer.org/installer | php

运行Composer以要求此包

php composer.phar require leadpages/leadpages-auth

然后确保您已将Composer自动加载器包含到您的项目中。此包使用PSR-4自动加载

require 'vendor/autoload.php';

API参考

文档即将到来

测试

测试是通过PHPUnit运行的

贡献者

许可证