public function init()
 {
     parent::init();
     /** @var Manager $attachment */
     $attachment = Manager::getInstance();
     if (!$attachment instanceof Manager) {
         throw new InvalidConfigException('Attachment Manager component not defined');
     }
     $this->attachmentTable = $attachment->attachmentFileTable;
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     parent::attach($owner);
     if (!is_array($this->models) || empty($this->models)) {
         throw new InvalidParamException('Invalid or empty models array.');
     } else {
         foreach ($this->models as $relationName => $config) {
             Manager::getInstance()->addAttachmentModel($this->owner, $relationName, $config);
             $this->checkRelationExistence($relationName);
         }
     }
 }
예제 #3
0
 /**
  * @return AttachmentFile
  */
 public function getAttachmentModel()
 {
     return Manager::getInstance()->getAttachmentModel($this->modelClass, $this->attribute);
 }
예제 #4
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($insert) {
             $this->type = static::TYPE;
             if (!is_numeric($this->status_id)) {
                 $this->status_id = self::STATUS_TEMPORARY;
             }
             Manager::getInstance()->createDirectory($this->getDirPath());
             if (!$this->file->saveAs($this->getFilePath())) {
                 throw new ErrorException("File @storage/{$this->uri} cannot be saved.");
             }
         }
         return true;
     } else {
         return false;
     }
 }