Wrep\Notificato\Apns\Certificate::__construct PHP Method

__construct() public method

APNS Certificate constructor
public __construct ( $pemFile, $passphrase = null, $validate = true, $endpointEnv = null )
    public function __construct($pemFile, $passphrase = null, $validate = true, $endpointEnv = null)
    {
        // Check if the given PEM file does exists and expand the path
        $absolutePemFilePath = realpath($pemFile);
        if (!is_file($absolutePemFilePath)) {
            throw new InvalidCertificateException('Could not find the given PEM file "' . $pemFile . '".');
        }
        // Save the given parameters
        $this->pemFile = $absolutePemFilePath;
        $this->passphrase = $passphrase;
        $this->endpointEnv = $endpointEnv;
        $this->fingerprint = null;
        $this->isValidated = false;
        // Parse (and validate) the certificate
        if ($validate) {
            $this->parseCertificate();
            $this->isValidated = true;
        }
        // A valid endpoint is required by now
        if (null == $this->endpointEnv) {
            throw new InvalidCertificateException('No endpoint given and/or detected from certificate.');
        } else {
            if (self::ENDPOINT_ENV_PRODUCTION !== $this->endpointEnv && self::ENDPOINT_ENV_SANDBOX !== $this->endpointEnv) {
                throw new \InvalidArgumentException('Invalid endpoint given: ' . $endpointEnv);
            }
        }
    }