CakePdf\Pdf\CakePdf::crypto PHP Method

crypto() public method

Load PdfCrypto
public crypto ( string $name = null ) : AbstractPdfCrypto
$name string Classname of crypto engine without `Crypto` suffix. For example `CakePdf.Pdftk`
return CakePdf\Pdf\Crypto\AbstractPdfCrypto
    public function crypto($name = null)
    {
        if ($name === null) {
            if ($this->_cryptoClass) {
                return $this->_cryptoClass;
            }
            throw new Exception(__d('cake_pdf', 'Crypto is not loaded'));
        }
        $config = [];
        if (is_array($name)) {
            $config = $name;
            $name = $name['className'];
        }
        $engineClassName = App::className($name, 'Pdf/Crypto', 'Crypto');
        if (!class_exists($engineClassName)) {
            throw new Exception(__d('cake_pdf', 'Pdf crypto "%s" not found', $name));
        }
        if (!is_subclass_of($engineClassName, 'CakePdf\\Pdf\\Crypto\\AbstractPdfCrypto')) {
            throw new Exception(__d('cake_pdf', 'Crypto engine must extend "AbstractPdfCrypto"'));
        }
        $this->_cryptoClass = new $engineClassName($this);
        $this->_cryptoClass->config($config);
        return $this->_cryptoClass;
    }