Beispiel #1
0
 * Script for Google API authorization
 * @author alxmsl
 */
include __DIR__ . '/../vendor/autoload.php';
use alxmsl\Cli\CommandPosix;
use alxmsl\Cli\Exception\RequiredOptionException;
use alxmsl\Cli\Option;
use alxmsl\Google\OAuth2\Response\Token;
use alxmsl\Google\OAuth2\WebServerApplication;
$clientId = '';
$clientSecret = '';
$code = '';
$redirectUri = '';
$scopes = [];
$Command = new CommandPosix();
$Command->appendHelpParameter('show help');
$Command->appendParameter(new Option('code', 'o', 'authorization code', Option::TYPE_STRING), function ($name, $value) use(&$code) {
    $code = $value;
});
$Command->appendParameter(new Option('client', 'c', 'client id', Option::TYPE_STRING, true), function ($name, $value) use(&$clientId) {
    $clientId = $value;
});
$Command->appendParameter(new Option('redirect', 'r', 'redirect uri', Option::TYPE_STRING, true), function ($name, $value) use(&$redirectUri) {
    $redirectUri = $value;
});
$Command->appendParameter(new Option('scopes', 's', 'grant scopes', Option::TYPE_STRING, true), function ($name, $value) use(&$scopes) {
    $scopes = explode(',', $value);
});
$Command->appendParameter(new Option('secret', 'e', 'client secret', Option::TYPE_STRING, true), function ($name, $value) use(&$clientSecret) {
    $clientSecret = $value;
});
Beispiel #2
0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Usage example
 * @author alxmsl
 * @date 10/22/12
 */
// Firstly include base class
include '../source/Autoloader.php';
use alxmsl\Cli\CommandPosix;
use alxmsl\Cli\Option;
// Create command instance
$Command = new CommandPosix();
// Append created option for help to command
$Command->appendHelpParameter('show help screen option');
// Append one required option. And...
$Command->appendParameter(new Option('option', 'o', 'some option', Option::TYPE_BOOLEAN, true));
// ...just parse the command
$Command->parse();
// If will exception, when required option is not set - use string below
//$Command->parse(true);