@param string $eventName
@param object $fileReference
@param FileMetadata $metadata

@return IUploadEvent
1646
public function dispatch($eventName, $fileReference, FileMetadata $metadata)
    {
        $event = new UploadEvent($fileReference, $metadata);

        foreach ($this->listeners[$eventName] as $listener) {
            call_user_func($listener, $event);
        }

        foreach ($this->subscribers as $subscriber) {
            $events = $subscriber->getSubscribedEvents();

            if (!isset($events[$eventName])) {
                continue;
            }

            call_user_func([$subscriber, $events[$eventName]], $event);
        }

        return $event;
    }
1070169
protected function registerEvent($eventName, $funcName)
    {
        \OWeb\manage\events::getInstance()->registerEvent($eventName, $this, $funcName);
    }
158545
public static function create( $eventName, $eventArgs = null ) {
			
			if ( !is_string( $eventName ) ) {
				throw new \browserfs\Exception('Invalid argument $eventName: string expected!');
			}
			
			if ( null !== $eventArgs && !is_array( $eventArgs ) ) {
				throw new \browserfs\Exception('Invalid argument $eventArgs: any[] | null expected');
			}

			return new static( $eventName, null === $eventArgs ? [] : array_values( $eventArgs ) );
		}
817454
public function addAttachment($attachment, $filename=null)
	{
		if (!($attachment instanceof Swift_Mime_MimeEntity))
		{
			$attachment = \Swift_Attachment::fromPath($attachment);
		}

		if ($filename && is_string($filename))
		{
			$attachment->setFilename($filename);
		}

		return $this->attach($attachment);
	}
669704
public function performEvent($eventName, $eventData = null)
    {
        $url = $this->url() . '/command/' . $eventName;
        $response = $this->api->post($url, $eventData);
        $this->data = (array) $response->data;

        return $this;
    }
804009
public function get_file($reference, $filename = '') {
        global $CFG;

        if (!$this->issuer->get('enabled')) {
            throw new repository_exception('cannotdownload', 'repository');
        }

        $source = json_decode($reference);

        $client = null;
        if (!empty($source->usesystem)) {
            $client = \core\oauth2\api::get_system_oauth_client($this->issuer);
        } else {
            $client = $this->get_user_oauth_client();
        }

        $base = 'https://www.googleapis.com/drive/v3';

        $newfilename = false;
        if ($source->exportformat == 'download') {
            $params = ['alt' => 'media'];
            $sourceurl = new moodle_url($base . '/files/' . $source->id, $params);
            $source = $sourceurl->out(false);
        } else {
            $params = ['mimeType' => $source->exportformat];
            $sourceurl = new moodle_url($base . '/files/' . $source->id . '/export', $params);
            $types = get_mimetypes_array();
            $checktype = $source->exportformat;
            if ($checktype == 'application/rtf') {
                $checktype = 'text/rtf';
            }
            foreach ($types as $extension => $info) {
                if ($info['type'] == $checktype) {
                    $newfilename = $source->name . '.' . $extension;
                    break;
                }
            }
            $source = $sourceurl->out(false);
        }

        // We use download_one and not the rest API because it has special timeouts etc.
        $path = $this->prepare_file($filename);
        $options = ['filepath' => $path, 'timeout' => 15, 'followlocation' => true, 'maxredirs' => 5];
        $success = $client->download_one($source, null, $options);

        if ($success) {
            @chmod($path, $CFG->filepermissions);

            $result = [
                'path' => $path,
                'url' => $reference,
            ];
            if (!empty($newfilename)) {
                $result['newfilename'] = $newfilename;
            }
            return $result;
        }
        throw new repository_exception('cannotdownload', 'repository');
    }
599396
public function storeFile($filename, $metadata = [], $options = [])
    {
        return $this->collection->storeFile($filename, $metadata, $options);
    }
28685
public function writeFile($filename)
    {
        $file = $this->getAttribute('file');
        if (empty($file) && !$this->getIsNewRecord()) {
            $file = $this->refreshFile();
        }

        if (empty($file)) {
            throw new InvalidParamException('There is no file associated with this object.');
        } elseif ($file instanceof Download) {
            return ($file->toFile($filename) == $file->getSize());
        } elseif ($file instanceof UploadedFile) {
            return copy($file->tempName, $filename);
        } elseif (is_string($file)) {
            if (file_exists($file)) {
                return copy($file, $filename);
            }
            throw new InvalidParamException("File '{$file}' does not exist.");
        }

        throw new InvalidParamException('Unsupported type of "file" attribute.');
    }
950414
protected function performAdditionalUpdateAction($updateEvent)
    {
        // Associate the file if it's a virtual product
        // and with only 1 PSE
        $virtualDocumentId = \intval($updateEvent->getVirtualDocumentId());

        if ($virtualDocumentId >= 0) {
            $defaultPSE = ProductSaleElementsQuery::create()
                ->filterByProductId($updateEvent->getProductId())
                ->filterByIsDefault(true)
                ->findOne();

            if (null !== $defaultPSE) {
                if ($virtualDocumentId !== 0) {
                    $assocEvent = new MetaDataCreateOrUpdateEvent('virtual', MetaData::PSE_KEY, $defaultPSE->getId(), $virtualDocumentId);
                    $this->dispatch(TheliaEvents::META_DATA_UPDATE, $assocEvent);
                } else {
                    $assocEvent = new MetaDataDeleteEvent('virtual', MetaData::PSE_KEY, $defaultPSE->getId());
                    $this->dispatch(TheliaEvents::META_DATA_DELETE, $assocEvent);
                }
            }
        }

        return null;
    }
579401
public function getSnippet($filename, array $extraSourceParameters = null)
    {
        try {
            $this->addRegistryContainer($extraSourceParameters, 'tmpContainer');
            $snippet = $this->_loadClass($filename, true);
            $this->removeRegistryContainer('tmpContainer');
            if (self::$verbose) {
                \MUtil_Echo::r('Loading snippet ' . $filename . '<br/>' . 'Using snippet: ' . get_class($snippet));
               }
        } catch (\Exception $exc) {
            if (self::$verbose) {
                \MUtil_Echo::r($exc->getMessage(), __CLASS__ . '->' .  __FUNCTION__ . '(' . $filename . ')');
            }
            throw $exc;
        }

        return $snippet;
    }
1131510
private function openDestinationStream(string $filename)
    {
        $inputStream = @fopen($filename, 'wb');

        if ($inputStream === false) {
            throw new UploadException("Could not open Stream to write upload data: ${filename}");
        }

        return $inputStream;
    }
978970
protected function handlePublication(PublishableInterface $entity, $eventName)
    {
        if (!$this->enabled) {
            return;
        }
        $class = $this->publicationEventClass;
        $event = new $class($entity, $eventName);

        $serialized = $this->getSerializer()->serialize($event, $this->getFormat());
        $f = $this->getFileName($eventName, $entity->getPublicationUuid());
        if (false === file_put_contents($f, $serialized)) {
            throw new FileException("Unable to write to file {$f}");
        }
    }
655548
public static function addAttachmentFromFile($object, $filename)
    {
        return self::addAttachment($object, basename($filename),
                file_get_contents($filename), mime_content_type($filename));
    }
830850
public function toWbmp(String $fileName = NULL, Int $threshold = NULL) : GD
    {
        image2wbmp($this->canvas, $fileName, $threshold);

        return $this;
    }
200710
protected function getJoinName(ClassMetadata $metadata, $tableName, $entityName)
    {
        $joinName = $tableName;

        // If it is self-referencing then we must avoid collisions
        if ($metadata->getName() == $this->metadata->getName()) {
            $joinName .= "_$entityName";   
        }

        return $joinName;
    }
359908
public function photoExistsInEvent($eventId, $photoFileName)
    {
        if (is_null($eventId) || $eventId == '') {
            throw new Exception('The eventId is required to check if a photo exists.');
        }

        if (is_null($photoFileName) || $photoFileName == '') {
            throw new Exception('The photoFileName is required to check if a photo exists.');
        }

        $params = array(
            'method' => 'sp.event.photo_exists',
            'event_id' => $eventId,
            'photo_name' => $photoFileName
        );

        return $this->_makeApiRequest($params);
    }
649596
public function setFileName($fileName)
	{
		$hasFilename = ($this->fileName !== null);
		
		if ($hasFilename) {
			$previousName = $this->fileName;
			$previousExtension = $this->getExtension();
		}
		
		parent::setFileName($fileName);
		
		if ($hasFilename) {
			
			$newExtension = $this->getExtension();

			if (strcasecmp($previousExtension, $newExtension) !== 0) {

				// restore name back to previous one. Because that's safer.
				parent::setFileName($previousName);

				throw new \RuntimeException('Extension change is not allowed');
			}
		}
	}