Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Cert Class Reference
Inheritance diagram for Cert:
AbstractModel DataObject

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 loadByWebsite ($websiteId, $strictLoad=true)
 
 getCertPath ()
 
 afterDelete ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const BASEPATH_PAYPAL_CERT = 'cert/paypal/'
 

Protected Member Functions

 _construct ()
 
 _createCertFile ($file)
 
 _removeOutdatedCertFile ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $varDirectory
 
 $encryptor
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

PayPal specific model for certificate based authentication

Definition at line 14 of file Cert.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Filesystem  $filesystem,
\Magento\Framework\Encryption\EncryptorInterface  $encryptor,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Filesystem$filesystem
\Magento\Framework\Encryption\EncryptorInterface$encryptor
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data

Definition at line 40 of file Cert.php.

48  {
49  $this->varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
50  $this->encryptor = $encryptor;
51  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
52  }
$resource
Definition: bulk.php:12
$filesystem

Member Function Documentation

◆ _construct()

_construct ( )
protected

Initialize resource model

Returns
void

Definition at line 59 of file Cert.php.

◆ _createCertFile()

_createCertFile (   $file)
protected

Create physical certificate file based on DB data

Parameters
string$file
Returns
void

Definition at line 105 of file Cert.php.

106  {
107  if ($this->varDirectory->isDirectory(self::BASEPATH_PAYPAL_CERT)) {
108  $this->_removeOutdatedCertFile();
109  }
110  $this->varDirectory->writeFile($file, $this->encryptor->decrypt($this->getContent()));
111  }

◆ _removeOutdatedCertFile()

_removeOutdatedCertFile ( )
protected

Check and remove outdated certificate file by website

Returns
void

Definition at line 118 of file Cert.php.

119  {
120  $pattern = sprintf('cert_%s*', $this->getWebsiteId());
121  $entries = $this->varDirectory->search($pattern, self::BASEPATH_PAYPAL_CERT);
122  foreach ($entries as $entry) {
123  $this->varDirectory->delete($entry);
124  }
125  }
$pattern
Definition: website.php:22

◆ afterDelete()

afterDelete ( )

Delete assigned certificate file after delete object

Returns
$this

Definition at line 132 of file Cert.php.

133  {
134  $this->_removeOutdatedCertFile();
135  return $this;
136  }

◆ getCertPath()

getCertPath ( )

Get path to PayPal certificate file, if file does not exist try to create it

Returns
string
Exceptions

Definition at line 84 of file Cert.php.

85  {
86  if (!$this->getContent()) {
87  throw new \Magento\Framework\Exception\LocalizedException(__('The PayPal certificate does not exist.'));
88  }
89 
90  $certFileName = sprintf('cert_%s_%s.pem', $this->getWebsiteId(), strtotime($this->getUpdatedAt()));
91  $certFile = self::BASEPATH_PAYPAL_CERT . $certFileName;
92 
93  if (!$this->varDirectory->isExist($certFile)) {
94  $this->_createCertFile($certFile);
95  }
96  return $this->varDirectory->getAbsolutePath($certFile);
97  }
__()
Definition: __.php:13

◆ loadByWebsite()

loadByWebsite (   $websiteId,
  $strictLoad = true 
)

Load model by website id

Parameters
int$websiteId
bool$strictLoad
Returns
$this

Definition at line 71 of file Cert.php.

72  {
73  $this->setWebsiteId($websiteId);
74  $this->_getResource()->loadByWebsite($this, $strictLoad);
75  return $this;
76  }

Field Documentation

◆ $encryptor

$encryptor
protected

Definition at line 29 of file Cert.php.

◆ $varDirectory

$varDirectory
protected

Definition at line 24 of file Cert.php.

◆ BASEPATH_PAYPAL_CERT

const BASEPATH_PAYPAL_CERT = 'cert/paypal/'

Certificate base path

Definition at line 19 of file Cert.php.


The documentation for this class was generated from the following file: