/**
* Load PdfCrypto
*
* @param string $name Classname of crypto engine without `Crypto` suffix. For example `CakePdf.Pdftk`
* @throws \Cake\Core\Exception\Exception
* @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;
}