상속: use trait Webiny\Component\StdLib\ComponentTrait, use trait Webiny\Component\Router\RouterTrait, use trait Webiny\Component\Http\HttpTrait, use trait Webiny\Component\StdLib\StdObjectTrait, use trait Webiny\Component\StdLib\FactoryLoaderTrait
예제 #1
0
 public function testSetGetEnv()
 {
     $rest = Rest::initRest('ExampleApi', 'http://www.example.com/services/tests/mocks/mock-api-class/test');
     $this->assertSame(Rest::ENV_PRODUCTION, $rest->getEnvironment());
     $rest->setEnvironment(Rest::ENV_DEVELOPMENT);
     $this->assertSame(Rest::ENV_DEVELOPMENT, $rest->getEnvironment());
 }
예제 #2
0
 /**
  * Get the api configuration.
  * Note: api name must already be set.
  *
  * @return ConfigObject
  */
 public function getApiConfig()
 {
     if (empty($this->apiConfig)) {
         $this->apiConfig = \Webiny\Component\Rest\Rest::getConfig()->{$this->api};
     }
     return $this->apiConfig;
 }
예제 #3
0
 public function setUp()
 {
     Annotations::setConfig(__DIR__ . '/../Mocks/MockAnnotationsConfig.yaml');
     Rest::setConfig(__DIR__ . '/../Mocks/MockRestConfig.yaml');
     // we need to create the cache files so we can test the router
     $parser = new Parser();
     $parserApi = $parser->parseApi('Webiny\\Component\\Rest\\Tests\\Mocks\\MockApiClassRouter', true);
     self::$cache = new Cache(new ArrayDriver());
     $instance = new Compiler('ExampleApi', true, self::$cache);
     $instance->writeCacheFiles($parserApi);
 }
예제 #4
0
 public function testWriteCacheFiles()
 {
     $parser = new Parser();
     $parserApi = $parser->parseApi('Webiny\\Component\\Rest\\Tests\\Mocks\\MockApiClass', true);
     $cache = new Cache(new ArrayDriver());
     $instance = new Compiler('ExampleApi', true, $cache);
     $instance->writeCacheFiles($parserApi);
     // now let's validate what was written
     $cRoot = Rest::getConfig()->ExampleApi->CompilePath;
     $cache = $cache->getCacheContent('ExampleApi', 'Webiny\\Component\\Rest\\Tests\\Mocks\\MockApiClass', 'current');
     $this->assertSame($cache['class'], 'Webiny\\Component\\Rest\\Tests\\Mocks\\MockApiClass');
     $this->assertSame($cache['version'], '1.0');
     $this->assertInternalType('array', $cache['post']);
     $this->assertCount(1, $cache['post']);
     $this->assertCount(1, $cache['get']);
     $this->assertNotFalse($cache['post']['some-method/([^/]+)/([^/]+)/([\\d]+)/']);
     $method = $cache['post']['some-method/([^/]+)/([^/]+)/([\\d]+)/'];
     $this->assertNotNull($method['default']);
     $this->assertSame('SECRET', $method['role']);
     $this->assertSame('someMethod', $method['method']);
     $this->assertSame('some-method/([^/]+)/([^/]+)/([\\d]+)/', $method['urlPattern']);
     $this->assertSame('3600', $method['cache']['ttl']);
     $this->assertSame(['expires' => '3600'], $method['header']['cache']);
     $this->assertSame('201', $method['header']['status']['success']);
     $this->assertSame('403', $method['header']['status']['error']);
     $this->assertSame('No Author for specified id.', $method['header']['status']['errorMessage']);
     $this->assertNotNull($method['rateControl']['ignore']);
     $this->assertCount(3, $method['params']);
     $param = $method['params']['param1'];
     $this->assertTrue($param['required']);
     $this->assertSame('string', $param['type']);
     $this->assertNull($param['default']);
     $param = $method['params']['param2'];
     $this->assertFalse($param['required']);
     $this->assertSame('string', $param['type']);
     $this->assertSame('default', $param['default']);
     $param = $method['params']['param3'];
     $this->assertFalse($param['required']);
     $this->assertSame('integer', $param['type']);
     $this->assertSame(22, $param['default']);
     $method = $cache['get']['simple-method/'];
     $this->assertFalse($method['default']);
     $this->assertSame(false, $method['role']);
     $this->assertSame('simpleMethod', $method['method']);
     $this->assertSame('simple-method/', $method['urlPattern']);
     $this->assertSame(0, $method['cache']['ttl']);
     $this->assertSame(['expires' => 0], $method['header']['cache']);
     $this->assertSame(200, $method['header']['status']['success']);
     $this->assertSame(404, $method['header']['status']['error']);
     $this->assertSame('', $method['header']['status']['errorMessage']);
     $this->assertFalse(isset($method['rateControl']['ignore']));
     $this->assertCount(0, $method['params']);
 }
예제 #5
0
 public function setUp()
 {
     Annotations::setConfig(__DIR__ . '/../Mocks/MockAnnotationsConfig.yaml');
     Cache::setConfig(__DIR__ . '/../Mocks/MockCacheConfig.yaml');
     Rest::setConfig(__DIR__ . '/../Mocks/MockRestConfig.yaml');
 }
예제 #6
0
 /**
  * Returns the folder where the cache files should be stored.
  *
  * @param string $api     Name of the api configuration.
  * @param string $class   Class name.
  *
  * @return string
  * @throws RestException
  * @throws \Webiny\Component\Rest\RestException
  */
 private function getCacheFolder($api, $class)
 {
     // get the api compile folder
     $compilePath = Rest::getConfig()->get($api)->CompilePath;
     if (empty($compilePath)) {
         throw new RestException('You must set CompilePath for "' . $api . '" api.');
     }
     $apiFolder = $this->str($compilePath)->trimRight('/')->append(DIRECTORY_SEPARATOR . $api);
     // get class cache folder
     $classCacheFolder = $this->str($class)->trimLeft('\\')->replace('\\', '_')->val();
     $apiFolder = $apiFolder . DIRECTORY_SEPARATOR . $classCacheFolder;
     if (!is_dir($apiFolder)) {
         mkdir($apiFolder, 0755, true);
         clearstatcache(true, realpath($apiFolder));
     }
     return $apiFolder . DIRECTORY_SEPARATOR;
 }
예제 #7
0
파일: services.php 프로젝트: Pavel910/Login
require_once './bootstrap.php';
// cors
header("Access-Control-Allow-Origin: *");
// define the login service class
class Login extends \Webiny\Login\LoginServices
{
    private static $login;
    public static function setLoginInstance(\Webiny\Login\Login $login)
    {
        self::$login = $login;
    }
    /**
     * @return \Webiny\Login\Login
     */
    protected function getLoginInstance()
    {
        return self::$login;
    }
}
Login::setLoginInstance($login);
// load rest
\Webiny\Component\Rest\Rest::setConfig('./restConfig.yaml');
try {
    $rest = \Webiny\Component\Rest\Rest::initRest('LoginApi');
    if ($rest) {
        $rest->processRequest()->sendOutput();
    }
} catch (RestException $e) {
    // handle the exception
    die(print_r($e));
}