public function testSerializeJson()
 {
     $team = new Team('Dream Team');
     $team->setPlayers([new Player('Player 1', 1)]);
     $array = Object2ArrayBuilder::create()->build()->createArray($team);
     static::assertEquals('{"name":"Dream Team","manager":[],"players":[{"name":"Player 1","number":1}]}', json_encode($array));
 }
 public function testPopulate()
 {
     $game = new Game();
     $game->setStadiumName('National');
     $game->setDate(new \DateTime('2016-01-01'));
     $game->setHomeClub(new Team('Team 1'));
     $game->setVisitor(new Team('Team 2'));
     $objectToArray = Object2ArrayBuilder::create()->build();
     $array = $objectToArray->createArray($game);
     static::assertEquals($game->getStadiumName(), $array['stadium']);
     static::assertEquals('2016-01-01', $array['date']);
     static::assertEquals('Team 1', $array['homeClub']['name']);
     static::assertEquals('Team 2', $array['visitor']['name']);
 }
 /**
  * @inheritdoc
  */
 public function buildRequest(ApiRequestBuilder $requestBuilder, ApiInterface $api)
 {
     /** @var QPayApi $api */
     $data = Object2ArrayBuilder::create()->build()->createArray($this);
     if (array_key_exists('urn:Header', $data)) {
         $data['urn:Header'] = ['urn1:CertPublicKey' => $api->getCredentials()->getCertificateSerialNumber(), 'urn1:UIID' => $api->getCredentials()->getUuid(), 'urn1:User' => 'system'];
     }
     if (array_key_exists('urn:RequestToken', $data)) {
         $data['urn:RequestToken'] = Object2ArrayBuilder::create()->build()->createArray($api->getRequestToken());
     }
     //build the request url
     $uri = sprintf('https://pos.qpay123.biz/%s/Gateway.svc', $api->getCredentials()->getMerchantName());
     $xml = QPayXMLParser::createRequest($this->getActionName(), $data);
     $requestBuilder->withUri($uri)->withMethod('POST')->withXMLBody($xml)->options()->setCurlOption(CURLOPT_CAINFO, $api->getCredentials()->getAuthorityCertificateFile())->setCurlOption(CURLOPT_SSLCERT, $api->getCredentials()->getClientCertificateFile())->setCurlOption(CURLOPT_SSLKEY, $api->getCredentials()->getCertificateKeyFile())->setCurlOption(CURLOPT_SSLCERTPASSWD, $api->getCredentials()->getCertificatePassword())->SSLVerification(false);
 }
 /**
  * Get array in sonata format.
  *
  * @return array
  */
 public function __toArray()
 {
     $batchActionsArray = [];
     foreach ($this->getAll() as $action) {
         $batchActionsArray[$action->getName()] = $action;
         //SonataAdmin require all actions in the root
         //mark each shild is a way to hide in the template
         if (!$action->getDropDown()->isEmpty()) {
             $childArray = $action->getDropDown();
             foreach ($childArray as $childAction => $childSettings) {
                 $childSettings = Object2ArrayBuilder::create()->build()->createArray($childSettings);
                 $childSettings['visible'] = false;
                 $batchActionsArray[$childAction] = $childSettings;
             }
         }
     }
     return $batchActionsArray;
 }
示例#5
0
 /**
  * @param Modal $modal
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(Modal $modal)
 {
     $modalJson = json_encode(Object2ArrayBuilder::create()->build()->createArray($modal));
     parent::__construct($modalJson, 200, ['X-Modal' => true, 'Content-Type' => 'application/json']);
 }
示例#6
0
 /**
  * NOTE: use configureBatchActionsUsingMapper to customize batch actions.
  *
  * {@inheritdoc}
  *
  * @internal
  *
  * Override to call configureBatchActionsUsingMapper with mapper instance with current actions
  */
 protected function configureBatchActions($actions)
 {
     $mapper = new BatchActionMapper();
     foreach ($actions as $action => $options) {
         $mapper[$action] = $options;
     }
     $this->configureBatchActionsUsingMapper($mapper);
     //customize delete action
     if ($mapper->has('delete')) {
         $mapper->get('delete')->setIcon('fa fa-trash')->addAttributes(['class' => 'btn btn-danger']);
     }
     //this return a array in the format expected by sonata
     //sonata don`t allow dropdowns, for that reason some child elements
     //appear as duplicated in the array, but note the key visible is false to hide duplicate
     //actions in the template
     return Object2ArrayBuilder::create()->build()->createArray($mapper);
 }