Skip to content

Commit

Permalink
Merge from open-platform branch. (#651)
Browse files Browse the repository at this point in the history
* Remove stale code.

* Full namespace.

* protected vars.

* Cleanup

* Do nothing on the auth events.

* tweak.

* Remove @method announce

* rename.

* Unused code
  • Loading branch information
mingyoung authored and overtrue committed Apr 13, 2017
1 parent abd03a0 commit b605c3d
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 462 deletions.
22 changes: 12 additions & 10 deletions src/Foundation/ServiceProviders/OpenPlatformServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ public function register(Container $pimple)
};

$pimple['open_platform.access_token'] = function ($pimple) {
return new AccessToken(
$accessToken = new AccessToken(
$pimple['config']['open_platform']['app_id'],
$pimple['config']['open_platform']['secret'],
$pimple['open_platform.verify_ticket'],
$pimple['cache']
);
$accessToken->setVerifyTicket($pimple['open_platform.verify_ticket']);

return $accessToken;
};

$pimple['open_platform.encryptor'] = function ($pimple) {
Expand Down Expand Up @@ -99,14 +101,14 @@ public function register(Container $pimple)
$pimple['open_platform.pre_auth'] = $pimple['open_platform.pre_authorization'] = function ($pimple) {
return new PreAuthorization(
$pimple['open_platform.access_token'],
$pimple['config']['open_platform']
$pimple['request']
);
};

$pimple['open_platform.api'] = function ($pimple) {
return new BaseApi(
$pimple['open_platform.access_token'],
$pimple['config']['open_platform']
$pimple['request']
);
};

Expand All @@ -129,14 +131,14 @@ public function register(Container $pimple)
$pimple['open_platform.handlers.component_verify_ticket'] = function ($pimple) {
return new EventHandlers\ComponentVerifyTicket($pimple['open_platform.verify_ticket']);
};
$pimple['open_platform.handlers.authorized'] = function ($pimple) {
return new EventHandlers\Authorized($pimple['open_platform.authorization']);
$pimple['open_platform.handlers.authorized'] = function () {
return new EventHandlers\Authorized();
};
$pimple['open_platform.handlers.updateauthorized'] = function ($pimple) {
return new EventHandlers\UpdateAuthorized($pimple['open_platform.authorization']);
$pimple['open_platform.handlers.updateauthorized'] = function () {
return new EventHandlers\UpdateAuthorized();
};
$pimple['open_platform.handlers.unauthorized'] = function ($pimple) {
return new EventHandlers\Unauthorized($pimple['open_platform.authorization']);
$pimple['open_platform.handlers.unauthorized'] = function () {
return new EventHandlers\Unauthorized();
};

$pimple['open_platform.app'] = function ($pimple) {
Expand Down
16 changes: 7 additions & 9 deletions src/OpenPlatform/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

namespace EasyWeChat\OpenPlatform;

use Doctrine\Common\Cache\Cache;
use EasyWeChat\Core\AccessToken as CoreAccessToken;
use EasyWeChat\Core\Exceptions\HttpException;

Expand Down Expand Up @@ -60,18 +59,17 @@ class AccessToken extends CoreAccessToken
protected $prefix = 'easywechat.open_platform.component_access_token.';

/**
* AccessToken constructor.
* Set VerifyTicket.
*
* @param string $appId
* @param string $secret
* @param \Doctrine\Common\Cache\Cache $cache
* @param \EasyWeChat\OpenPlatform\VerifyTicket $verifyTicket
* @param EasyWeChat\OpenPlatform\VerifyTicket $verifyTicket
*
* @return $this
*/
public function __construct($appId, $secret, VerifyTicket $verifyTicket, Cache $cache = null)
public function setVerifyTicket(VerifyTicket $verifyTicket)
{
parent::__construct($appId, $secret, $cache);

$this->verifyTicket = $verifyTicket;

return $this;
}

/**
Expand Down
111 changes: 0 additions & 111 deletions src/OpenPlatform/Api/AbstractComponent.php

This file was deleted.

65 changes: 65 additions & 0 deletions src/OpenPlatform/Api/AbstractOpenPlatform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
* AbstractOpenPlatform.php.
*
* Part of Overtrue\WeChat.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author mingyoung <mingyoungcheung@gmail.com>
* @author lixiao <leonlx126@gmail.com>
* @copyright 2016
*
* @see https://github.com/overtrue
* @see http://overtrue.me
*/

namespace EasyWeChat\OpenPlatform\Api;

use EasyWeChat\Core\AbstractAPI;
use EasyWeChat\OpenPlatform\AccessToken;
use Symfony\Component\HttpFoundation\Request;

abstract class AbstractOpenPlatform extends AbstractAPI
{
/**
* Request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;

/**
* AbstractOpenPlatform constructor.
*
* @param \EasyWeChat\OpenPlatform\AccessToken $accessToken
* @param \Symfony\Component\HttpFoundation\Request $request
*/
public function __construct(AccessToken $accessToken, Request $request)
{
parent::__construct($accessToken);

$this->request = $request;
}

/**
* Get OpenPlatform AppId.
*
* @return string
*/
public function getAppId()
{
return $this->getAccessToken()->getAppId();
}
}
6 changes: 5 additions & 1 deletion src/OpenPlatform/Api/BaseApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace EasyWeChat\OpenPlatform\Api;

class BaseApi extends AbstractComponent
class BaseApi extends AbstractOpenPlatform
{
/**
* Get auth info api.
Expand Down Expand Up @@ -74,6 +74,10 @@ public function getAuthorizationInfo($authCode = null)
/**
* Get authorizer token.
*
* It doesn't cache the authorizer-access-token.
* So developers should NEVER call this method.
* It'll called by: AuthorizerAccessToken::refreshToken()
*
* @param $appId
* @param $refreshToken
*
Expand Down
2 changes: 1 addition & 1 deletion src/OpenPlatform/Api/PreAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use EasyWeChat\Core\Exceptions\InvalidArgumentException;
use Symfony\Component\HttpFoundation\RedirectResponse;

class PreAuthorization extends AbstractComponent
class PreAuthorization extends AbstractOpenPlatform
{
/**
* Create pre auth code url.
Expand Down
Loading

0 comments on commit b605c3d

Please sign in to comment.