PHP code example of awaitcz / smartform

1. Go to this page and download the library: Download awaitcz/smartform library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

awaitcz / smartform example snippets




namespace App;

use Awaitcz\SmartForm\Client\AddressClient;
use Awaitcz\SmartForm\Client\CompanyClient;
use Awaitcz\SmartForm\Client\EmailClient;
use Awaitcz\SmartForm\Entity\Address\Validate\ValidateAddress;
use Awaitcz\SmartForm\Entity\Address\Whisper\Query\WhisperAddressByMunicipalityAndDistrict;
use Awaitcz\SmartForm\Entity\Address\Whisper\Query\WhisperAddressByStreetAndNumberMunicipalityPostCode;
use Awaitcz\SmartForm\Entity\Address\Whisper\Query\WhisperAddressByStreetNumberMunicipalityPostCode;
use Awaitcz\SmartForm\Entity\Address\Whisper\Query\WhisperAddressByWholeAddress;
use Awaitcz\SmartForm\Entity\Address\Whisper\WhisperAddress;
use Awaitcz\SmartForm\Entity\Company\Validate\ValidateCompany;
use Awaitcz\SmartForm\Entity\Company\Whisper\Query\WhisperCompanyByNameQuery;
use Awaitcz\SmartForm\Entity\Company\Whisper\WhisperCompany;
use Awaitcz\SmartForm\Entity\Country;
use Awaitcz\SmartForm\Entity\Email\Validate\ValidateEmail;
use Awaitcz\SmartForm\Exception\ClientException;


final class ExampleService
{

	public function __construct(
		private readonly AddressClient $addressClient,
		private readonly CompanyClient $companyClient,
		private readonly EmailClient $emailClient,
	)
	{
	}

	public function tryWhisperAddress(): void
	{

		try {

			$whisperedAddressResponse = $this->addressClient->whisper(new WhisperAddress(
				new WhisperAddressByWholeAddress('Na Pavím vrchu 1949/2'),
				country: Country::CzechRepublic,
			));

			$addresses = $whisperedAddressResponse->getResult();

			foreach($addresses as $address) {
				dump([
					$address->wholeAddress, // Na Pavím vrchu 1949/2, 15000 Praha 5 - Smíchov
				]);
				break;
			}

		} catch (ClientException $e) {
			dump($e->getCode());
			dump($e->getMessage());
		}

	}

	public function tryValidateCompany(): void
	{

		try {

			$validatedCompanyResponse = $this->companyClient->validate(
			  new ValidateCompany(registrationNumber: '75848015')
			);

			$companies = $whisperedAddressResponse->getResult();

			foreach($companies as $company) {
				dump([
					$company->registrationNumber, // 75848015
					$company->naceCodes, // 27900, 620
				]);
				break;
			}

		} catch (ClientException $e) {
			dump($e->getCode());
			dump($e->getMessage());
		}

	}

}