Create new AttachmentLink object for the given parameters.

@param File $file
@param AttachableObjectInterface $object
@param string $fieldName
@param Attachment $attachment

@return AttachmentLink
501057
protected function createAttachmentLink(File $file, AttachableObjectInterface $object, $fieldName, Attachment $attachment, $customFilename = null)
    {
        if ($file instanceof UploadedFile)
        {
            $extension = $file->getClientOriginalExtension();
            $filename = $file->getClientOriginalName();
            $basename = basename($filename, '.'.$extension);
        }
        else
        {
            $extension = $file->getExtension();
            $filename = $file->getFilename();
            $basename = $file->getBasename('.'.$extension);
        }
        
        if (null !== $customFilename)
        {
            $filename = $customFilename;
            $basename = basename($filename, '.'.$extension);
        }
        
        $link = new AttachmentLink();
        $link
            ->setAttachment($attachment)
            ->setModelName($object->getAttachableClassName())
            ->setModelId($object->getAttachableId())
            ->setModelField($fieldName)
            ->setFileName($filename)
            ->setFileExtension($extension)
            ->setCustomName($basename)
        ;
        
        return $link;
    }
889164
public function getAttachedFile($file, $attachment_id) {
	    $shouldOverride = apply_filters('ilab_should_override_attached_file', true, $attachment_id);

		if(!file_exists($file) && $shouldOverride) {
			$meta = wp_get_attachment_metadata($attachment_id);

			$new_url = null;
			if($meta) {
				$new_url = $this->getAttachmentURLFromMeta($meta);
			}

			if(!$new_url) {
				$meta = get_post_meta($attachment_id, 'ilab_s3_info', true);
				if($meta) {
					$new_url = $this->getAttachmentURLFromMeta($meta);
				} else if(!$meta && StorageSettings::docCdn()) {
					$post = \WP_Post::get_instance($attachment_id);
					if($post && (strpos($post->guid, StorageSettings::docCdn()) === 0)) {
						$new_url = $post->guid;
					}
				}
			}

			if($new_url) {
				return $new_url;
			}
		}

		return $file;
	}
102509
protected function generateKey(File $file, AttachableObjectInterface $object, $fieldName)
    {
        $schema = $this->getSchemaForObject($object, $fieldName);
        
        if ($file instanceof UploadedFile)
        {
            $extension = $file->getClientOriginalExtension();
        }
        else
        {
            $extension = $file->getExtension();
        }
        
        $hash = $this->generateFileHash($file, $schema);
        
        $fileKey = new $this->fileKeyClass();
        $fileKey
            ->setHash($hash)
            ->setExtension($extension)
            ->setDepth($schema->getStorageDepth())
            ->setClassName($object->getAttachableClassName())
            ->setFieldName($fieldName)
            ->setStorageName($schema->getStorage()->getName())
        ;
        
        // This triggers the generation inside the key. If there are any exceptions, we want them here for clarity.
        $fileKey->getKey();
        
        return $fileKey;
    }
880771
public function fromFile($filename, $object = true)
    {
        $pathinfo = pathinfo($filename);

        if (!isset($pathinfo['extension']))
        {
            throw new \RuntimeException(sprintf(
                'Filename "%s" is missing an extension and cannot be auto-detected', $filename
            ));
        }

        $config = $this->createFormat($pathinfo['extension'])->fromFile($filename, $object);
        return $config;
    }
266469
public static function file(File $file, $filename = null, $mime = null) {

		if(null !== $filename && false === is_string($filename)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($filename)), E_USER_ERROR);
		}

		if(null !== $mime && false === is_string($mime)) {
			return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($mime)), E_USER_ERROR);
		}

		if(null !== $file -> entity()) {

			//Determine file name
			$filename = null !== $filename ? $filename : $file -> entity() -> getBasename();

			//Add mime if known
			$mime = null !== $mime ? $mime : $file -> getMime();

			if(null !== $mime) {
				static :: addHeader('Content-Type', $mime);
			}

			static :: addHeader('Content-Transfer-Encoding', 'binary');
			static :: addHeader('Expires', '0');
			static :: addHeader('Pragma', 'public');
			static :: addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
			static :: addHeader('Content-Length', $file -> entity() -> getFilesize());
			static :: addHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate');
			static :: addHeader('Expires', 'Tue, 25 Oct '. (date('Y') - 10) .' 05:00:00 GMT');
			static :: addHeader('Pragma', 'no-cache');

			if($fd = @fopen($file -> entity() -> getBasepath(), 'r')) {

				ob_clean();
				flush();

				while(!feof($fd)) {
					echo fread($fd, 2048);
				}
				
				fclose($fd);
			}
		}
	}
724768
public function addBlobAttachment($content, $filename, $mimeType = null, $fileInfo = []) {
		if ($mimeType === null) {
			$ext = pathinfo($filename, PATHINFO_EXTENSION);
			$mimeType = $this->_getMimeByExtension($ext);
		}
		$fileInfo['data'] = $content;
		$fileInfo['mimetype'] = $mimeType;
		$file = [$filename => $fileInfo];
		return $this->addAttachments($file);
	}
820174
public function attachFile($file, $fileName = null)
    {
        if (gettype($file) == 'resource') {
            $this->file = ['fileName' => $fileName, 'fileContent' => $file];
        } else {
            $this->file = ['fileName' => $fileName, 'fileContent' => fopen($file, 'r')];
        }
    }
814440
public function addField($field)
    {
        if (! is_array($field) && ! $field instanceof AttachmentField) {
            throw FieldCannotBeAdded::invalidType();
        }

        if (is_array($field)) {
            $title = array_keys($field)[0];
            $value = $field[$title];

            $field = AttachmentField::create($title, $value);
        }

        $this->fields->push($field);

        return $this;
    }
366948
public static function serialize( $object, $fileName )
	{
		$serial	= parent::serialize( $object );
		$file	= new FS_File_Writer( $fileName );
		return $file->writeString( $serial );
	}
860925
protected function createFileProperty(IObject $object, FileField $field)
    {
        $property = $this->getPrototype(
            $this->defaultFilePropertyClass,
            ['umi\orm\object\property\file\IFileProperty']
        )
            ->createInstance([$object, $field]);

        return $property;
    }
674560
public function withFileToSend($filePath, $attachmentName = null, $attachment = false)
    {
        if (!is_string($attachmentName)) {
            $basePath = basename($filePath);
        } else {
            $basePath = $attachmentName;
        }

        $this->file = $filePath;

        if ($attachment) {
            return $this->withHeader('Content-Description', 'File Transfer')
                ->withHeader('Content-Disposition', 'attachment; filename="' . $basePath . '"')
                ->withHeader('Content-Transfer-Encoding', 'binary');
        }

        return $this;
    }
178993
public function addAttachment($file, $name = false)
    {
        if (file_exists($file)) {
            $this->attachemnts[] = array(
                $file => $name
            );
        }
        
        return $this;
    }
1332597
public function addAttachment($path, $filename = null, $data = null)
    {
        $filename = empty($filename) ? basename($path) : $filename;
        $filename = $this->encodeUtf8($this->filterOther((string) $filename));
        $data = empty($data) ? $this->getAttachmentData($path) : $data;
        $this->_attachments[] = array(
            'path' => $path,
            'file' => $filename,
            'data' => chunk_split(base64_encode($data))
        );
        return $this;
    }
486263
public function attach($field, $path)
    {
        $element = $this->resolver->resolveForAttachment($field);

        $element->setFileDetector(new LocalFileDetector)->sendKeys($path);

        return $this;
    }
227057
public function addAttachment($filePath) {
        if (!$file = fopen($filePath, 'r')) {
            throw new Exception('Cannot open file "' . $filePath . '"');
        }

        $this->attachments[$filePath] = chunk_split(base64_encode(fread($file, filesize($filePath))));
        return $this;
    }
644571
def _create_related_attachment(self, filename, content, mimetype=None):
        
        attachment = super(EmailMultiRelated, self)._create_attachment(filename, content, mimetype)
        if filename:
            mimetype = attachment['Content-Type']
            del(attachment['Content-Type'])
            del(attachment['Content-Disposition'])
            attachment.add_header('Content-Disposition', 'inline', filename=filename)
            attachment.add_header('Content-Type', mimetype, name=filename)
            attachment.add_header('Content-ID', '<%s>' % filename)
        return attachment
466191
public function addAttachment($attachment): Letter
    {
        if (!is_file($attachment)) {
            throw new InvalidArgumentException('"%s" can not be found or is not a file');
        }

        $this->attachments[] = $attachment;

        return $this;
    }