fromNative() public static méthode

Returns a new Url object from a native url string
public static fromNative ( ) : Url
Résultat Url
 private function newActorUpdated(\DateTimeImmutable $time)
 {
     $actorId = new String('318F2ACB-F612-6F75-0037C9C29F44087A');
     $author = new String('*****@*****.**');
     $url = Url::fromNative('https://io.uitdatabank.be/event/318F2ACB-F612-6F75-0037C9C29F44087A');
     return new ActorUpdated($actorId, $time, $author, $url);
 }
 public function testWhenMechanismThrowExceptionReportIsFailed()
 {
     $mechanism_mock = \Mockery::mock('\\SimpleHealth\\EndpointMechanismInterface');
     $validator_mock = \Mockery::mock('\\SimpleHealth\\ValidatorInterface');
     $mechanism_mock->shouldReceive('request')->andThrow(new \GuzzleHttp\Exception\TransferException());
     $healthcheck = new EndpointHealthCheck(Url::fromNative('http://www.php.net'), $mechanism_mock, $validator_mock);
     $report = $healthcheck->check();
     $this->assertEquals($report->pass, false);
 }
 public function testCheckReturnsCode()
 {
     $client_mock = \Mockery::mock('\\GuzzleHttp\\Client');
     $response_mock = \Mockery::mock('\\GuzzleHttp\\Psr7\\Response');
     $url = Url::fromNative('http://www.php.net');
     $client_mock->shouldReceive('request')->andReturn($response_mock);
     $obj = new \SimpleHealth\CurlMechanism($client_mock, $url);
     $code = $obj->request();
 }
 public function build()
 {
     $endpoints = \SplFixedArray::fromArray($this->endpoints);
     for ($i = 0, $len = count($endpoints); $i < $len; $i++) {
         $endpoints[$i] = Url::fromNative($endpoints[$i]);
     }
     $endpoints = new Collection($endpoints);
     $node_healthcheck_factory = new NodeHealthCheckFactory();
     $node_healthcheck = $node_healthcheck_factory->make($endpoints);
     return new SimpleHealth($endpoints, $node_healthcheck);
 }
 public function testReturnsActorUpdated()
 {
     $actorUpdated = $this->deserializer->deserialize(new StringLiteral('{
                 "actorId": "foo",
                 "time": "2015-02-20T20:39:09+0100",
                 "author": "*****@*****.**",
                 "url": "http://foo.bar/event/foo"
             }'));
     $this->assertInstanceOf(ActorUpdated::class, $actorUpdated);
     $this->assertEquals(new StringLiteral('foo'), $actorUpdated->getactorId());
     $this->assertEquals(new StringLiteral('*****@*****.**'), $actorUpdated->getAuthor());
     $this->assertEquals(\DateTimeImmutable::createFromFormat(DateTime::ISO8601, '2015-02-20T20:39:09+0100'), $actorUpdated->getTime());
     $this->assertEquals(Url::fromNative('http://foo.bar/event/foo'), $actorUpdated->getUrl());
 }
 public function testProperties()
 {
     $id = new StringLiteral('foo');
     $time = new \DateTimeImmutable();
     $author = new StringLiteral('*****@*****.**');
     $url = Url::fromNative('http://www.some.url');
     $cdbXml = new StringLiteral(file_get_contents(__DIR__ . '/actor.xml'));
     $cdbXmlNamespaceUri = new StringLiteral('http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.2/FINAL');
     $event = new ActorCreatedEnrichedWithCdbXml($id, $time, $author, $url, $cdbXml, $cdbXmlNamespaceUri);
     $this->assertEquals($id, $event->getActorId());
     $this->assertEquals($time, $event->getTime());
     $this->assertEquals($author, $event->getAuthor());
     $this->assertEquals($url, $event->getUrl());
     $this->assertEquals($cdbXml, $event->getCdbXml());
     $this->assertEquals($cdbXmlNamespaceUri, $event->getCdbXmlNamespaceUri());
 }
 public function test()
 {
     $validator_mock = \Mockery::mock('\\SimpleHealth\\ValidatorInterface');
     $heatlhcheck_factory_mock = \Mockery::mock('\\SimpleHealth\\EndpointHealthCheckFactory');
     $healthcheck_mock = \Mockery::mock('\\SimpleHealth\\EndpointHealthCheck');
     $endpoint_report_mock = \Mockery::mock('\\SimpleHealth\\EndpointReport');
     $node_valid_mock = \Mockery::mock('\\SimpleHealth\\ValidatorResult');
     $node_valid_mock->pass = true;
     $validator_mock->shouldReceive('isValid')->andReturn($node_valid_mock);
     $heatlhcheck_factory_mock->shouldReceive('make')->andReturn($healthcheck_mock);
     $healthcheck_mock->shouldReceive('check')->andReturn($endpoint_report_mock);
     $endpoints = new Collection(SplFixedArray::fromArray([Url::fromNative('http://www.php.net/')]));
     $subject = new NodeHealthCheck($endpoints, $validator_mock, $heatlhcheck_factory_mock);
     $node_report = $subject->check();
     $this->assertEquals($node_report->pass, true);
 }
 public function connect(Application $app)
 {
     /** @var ControllerCollection $controllers */
     $controllers = $app['controllers_factory'];
     $app[self::JSONLD_CONTEXT_CONTROLLER] = $app->share(function (Application $app) {
         $contextDirectory = new StringLiteral($app['config']['jsonld']['context_directory']);
         $controller = new ContextController($contextDirectory);
         if (isset($app['config']['url']) && $app['config']['url'] !== ContextController::DEFAULT_BASE_PATH) {
             $basePath = Url::fromNative($app['config']['url']);
             return $controller->withCustomBasePath($basePath);
         } else {
             return $controller;
         }
     });
     $controllers->get('/{entityName}', self::JSONLD_CONTEXT_CONTROLLER . ':get');
     return $controllers;
 }
 /**
  * @param array $data
  * @return static
  */
 public static function deserialize(array $data)
 {
     return new static(new StringLiteral($data['actorId']), ISO8601DateTimeDeserializer::deserialize(new StringLiteral($data['time'])), new StringLiteral($data['author']), Url::fromNative($data['url']));
 }
 public function testGetUrl()
 {
     $eventCreated = $this->createEventCreated();
     $this->assertEquals(Url::fromNative('http://foo.bar/event/foo'), $eventCreated->getUrl());
 }
 public function testUrl()
 {
     $actorUpdated = $this->createActorUpdated();
     $this->assertEquals(Url::fromNative('http://foo.bar/event/foo'), $actorUpdated->getUrl());
 }
 public function testCorrespondingObjectIsReturned()
 {
     $subject = new EndpointHealthCheckFactory();
     $obj = $subject->make(Url::fromNative('http://www.php.net/'));
     $this->assertInstanceOf('\\SimpleHealth\\EndpointHealthCheck', $obj);
 }
 /**
  * @inheritdoc
  */
 public function transform(Url $url)
 {
     $lastSlashPosition = strrpos($url, '/') + 1;
     $cdbid = substr($url, $lastSlashPosition, strlen($url) - $lastSlashPosition);
     return Url::fromNative(sprintf($this->urlFormat, $cdbid));
 }
Exemple #14
0
 public function testAuthlessUrlToString()
 {
     $nativeUrlString = 'http://foo.com:80/bar?querystring#fragmentidentifier';
     $authlessUrl = new Url(new SchemeName('http'), new StringLiteral(''), new StringLiteral(''), new Hostname('foo.com'), new PortNumber(80), new Path('/bar'), new QueryString('?querystring'), new FragmentIdentifier('#fragmentidentifier'));
     $this->assertSame($nativeUrlString, $authlessUrl->__toString());
     $fromNativeUrl = Url::fromNative($nativeUrlString);
     $this->assertSame($nativeUrlString, Url::fromNative($authlessUrl)->__toString());
 }
 /**
  * @param Request $request
  * @param $cdbid
  * @return Response
  */
 public function addLink(Request $request, $cdbid)
 {
     $callback = function () use($request, $cdbid) {
         $repository = $this->eventRepository;
         if ($request->getContentType() !== 'form') {
             $rsp = rsp::error('UnexpectedFailure', 'Content-Type is not x-www-form-urlencoded.');
             return $rsp;
         }
         $required = ['lang' => 'Language code', 'subbrand' => 'Sub-brand', 'description' => 'Description', 'linktype' => 'Link type', 'plaintext' => 'Plain text'];
         foreach ($required as $requiredProperty => $humanReadable) {
             if (!$request->request->get($requiredProperty)) {
                 throw new InvalidArgumentException(sprintf('%s is required.', $humanReadable));
             }
         }
         $type = strtolower($request->request->get('linktype'));
         // At this point only collaboration "links" are supported.
         if ($type !== 'collaboration') {
             throw new InvalidArgumentException('Link type should be "collaboration". Any other type is not supported.');
         }
         $eventId = new String($cdbid);
         $language = new Language(strtolower($request->request->get('lang')));
         $collaborationData = new CollaborationData(new String($request->request->get('subbrand')), new String($request->request->get('plaintext')));
         if ($request->request->has('title')) {
             $collaborationData = $collaborationData->withTitle(new String($request->request->get('title')));
         }
         if ($request->request->has('copyright')) {
             $collaborationData = $collaborationData->withCopyright(new String($request->request->get('copyright')));
         }
         if ($request->request->has('link')) {
             $collaborationData = $collaborationData->withLink(Url::fromNative($request->request->get('link')));
         }
         $description = json_decode($request->request->get('description'));
         if (is_null($description)) {
             throw new InvalidArgumentException('Description is not a valid json string.');
         }
         if (!empty($description->text)) {
             $collaborationData = $collaborationData->withText(new String($description->text));
         }
         if (!empty($description->keyword)) {
             $collaborationData = $collaborationData->withKeyword(new String($description->keyword));
         }
         if (!empty($description->article)) {
             $collaborationData = $collaborationData->withArticle(new String($description->article));
         }
         if (!empty($description->image)) {
             $collaborationData = $collaborationData->withImage(new String($description->image));
         }
         $command = new AddCollaborationLink($eventId, $language, $collaborationData);
         $commandHandler = new EntryAPIEventCommandHandler($repository);
         $commandHandler->handle($command);
         $link = $this->entryapiLinkBaseUrl . $cdbid;
         $rsp = new Rsp('0.1', 'INFO', 'LinkCreated', $link, null);
         return $rsp;
     };
     return $this->processEventRequest($callback);
 }