Makes a normalized storable file instance from a data URI.

@param string|RawContentInterface $data
@param string|null                $name
@param string|null                $mimeType
@return StorableFileInterface
@throws CouldNotReadDataException
778816
public function makeFromDataUri($data, $name = null, $mimeType = null)
    {
        if ($data instanceof RawContentInterface) {
            $data = $data->content();
        }

        $resource = @fopen($data, 'r');

        if ( ! $resource) {
            throw new CouldNotReadDataException('Invalid data URI');
        }

        try {
            $meta = stream_get_meta_data($resource);
            // @codeCoverageIgnoreStart
        } catch (Exception $e) {
            throw new CouldNotReadDataException('Failed to interpret Data URI as stream', $e->getCode(), $e);
            // @codeCoverageIgnoreEnd
        }

        if (null === $mimeType) {
            $mimeType = $meta['mediatype'];
        }

        $extension = $this->mimeTypeHelper->guessExtensionForMimeType($mimeType);
        $localPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5($meta['uri']) . '.' . $extension;

        if (null === $name) {
            $name = pathinfo($localPath, PATHINFO_BASENAME);
        }

        try {
            file_put_contents($localPath, stream_get_contents($resource));
            // @codeCoverageIgnoreStart
        } catch (Exception $e) {
            throw new CouldNotReadDataException('Failed to make local file from Data URI', $e->getCode(), $e);
            // @codeCoverageIgnoreEnd
        }

        // Always flag as uploaded, since a temp file was created
        return $this->uploaded()->makeFromLocalPath($localPath, $name);
    }
1180605
public function read($uri, $mimeType = null)
    {
        if (!$uri instanceof UriInterface) {
            $uri = $this->uriFactory()->create($uri);
        }

        $content = $this->loader()->load($uri);
        if (null === $mimeType) {
            $mimeType = $content->mimeType();
        }

        $value = $this->protocolMap()->get($mimeType)->thaw($content->data());

        return $this->valueFactory()->create($value);
    }
281090
public static ContentData create(byte[] data, String type, @Nullable String name) {
        return new ContentData(RequestBody.create(MediaType.parse(type), data), name);
    }
1353740
protected function createChunkFile($name, $uuid = null, $mimeType = null)
    {
        return $this->chunkFileFactory->create(
            $name, $this->chunkPath(), $this->storagePath(), $uuid, $mimeType
        );
    }
1075768
public function addAttachmentFromFile($name, $path, $mimeType = 'application/octet-stream', $contentId = null)
    {
        if (file_exists($path) && is_file($path) && is_readable($path)) {
            $this->addAttachmentFromData($name, file_get_contents($path), $mimeType, $contentId);
        }
    }
534169
private function readMetaData($name) {
        $refData = [
            'ID' => '',
            'Size' => 0,
            'Offset' => 0,
            'Extension' => '',
            'FileName' => '',
            'MimeType' => '',
            'IsPartial' => true,
            'IsFinal' => false,
            'PartialUploads' => null, // unused
        ];

        $storageFileName = $this->directory . $name . '.info';
        if (file_exists($storageFileName)) {
            $json = file_get_contents($storageFileName);
            $data = Json::decode($json, Json::TYPE_ARRAY);
            if (is_array($data)) {
                return array_merge($refData, $data);
            }
        }
        return $refData;
    }
405709
public function createLink(string $name, array $data): Link
    {
        if (! preg_match(self::RESOURCE_PATTERN, $data['resource'], $matches)) {
            throw new \LogicException(sprintf('Invalid resource definition: "%s"', $data['resource']));
        }

        $link = new Link(
            $name,
            $matches['repository'],
            $matches['link']
        );

        $link->setParameters($data['parameters']);
        $link->setMetadata($data['metadata']);

        return $link;
    }
360861
private function _validateDataType($data)
  {
    if(empty($this->allowed_file_types))
      return true;

    $finfo = new \finfo(FILEINFO_MIME_TYPE);

    if(!in_array($finfo->file($data['tmp_name']), $this->allowed_file_types))
      throw new FileTypeNotAllowedException();

    return true;
  }
1359429
public function denormalize($data, $class, $format = null, array $context = [])
    {
        if (!preg_match('/^data:([a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}\/[a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}(;[a-z0-9\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\\\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i', $data)) {
            throw new NotNormalizableValueException('The provided "data:" URI is not valid.');
        }

        try {
            switch ($class) {
                case 'Symfony\Component\HttpFoundation\File\File':
                    return new File($data, false);

                case 'SplFileObject':
                case 'SplFileInfo':
                    return new \SplFileObject($data);
            }
        } catch (\RuntimeException $exception) {
            throw new NotNormalizableValueException($exception->getMessage(), $exception->getCode(), $exception);
        }

        throw new InvalidArgumentException(sprintf('The class parameter "%s" is not supported. It must be one of "SplFileInfo", "SplFileObject" or "Symfony\Component\HttpFoundation\File\File".', $class));
    }
823438
public static function createFromArray($name, array $data = [])
    {
        $class = new static($name);

        $class->setType($data['type']);
        if (isset($data['usage'])) {
            \assert($class instanceof TraitDefinition);
            $class->setUsage($data['usage']);
        }
        if (isset($data['required'])) {
            $class->setRequired($data['required']);
        }
        if (isset($data['enum'])) {
            $class->setEnum($data['enum']);
        }
        if (\substr($name, -1) === '?') {
            $class->setRequired(false);
            $class->setName(\substr($name, 0, -1));
        }
        $class->setDefinition($data);

        return $class;
    }
344323
protected function recurse(&$data, $name = null, $type = null)
    {
        if (is_scalar($data)) {
            $this->makeScalarDefinition($data, $name, $type);

            return;
        }

        if ($this->maxDepth > 0 && $this->depth >= $this->maxDepth) {
            $this->out[] = "{$this->makeDefinition($type, null, $name)} " .
            "<em style='color:#999;'>... depth limit reached</em>";

            return;
        }

        if ($this->isCircularReference($data)) {
            $this->out[] = "{$this->makeDefinition($type, null, $name)} " .
            "<em style='color:#999;'>... cirular reference omitted</em>";

            return;
        }

        $this->registerObject($data);

        $iterable = $data;
        $lpad     = str_repeat($this->indentWith, $this->depth);

        if (is_array($iterable)) {
            $len  = count($iterable);
            $type = $type ? : 'array';

            $this->out[] = "{$this->makeDefinition($type, $len, $name)} {";

            $this->depth++;

            foreach ($iterable as $key => $val) {
                $valType = gettype($val);
                if ($val instanceof EntityInterface) {
                    $valType = $val->calledClassName();
                }
                elseif (is_object($val)) {
                    $valType = get_class($val);
                }

                $this->recurse($val, $key, $valType);
            }

            $this->depth--;

            $this->out[] = "{$lpad}}";
        }
        elseif (is_object($iterable)) {
            $len  = count($iterable);
            $type = $type ? : get_class($iterable);
            
            if (!($iterable instanceof Traversable)) {
                $iterable = get_object_vars($data);
            }

            $this->out[] = "{$this->makeDefinition($type, $len, $name)} {";

            $this->depth++;

            foreach ($iterable as $key => $val) {
                if (!isset($iterable->$key) && !isset($iterable[$key])) {
                    continue;
                }

                $valType = $iterable instanceof EntityInterface ? $iterable->typeof($key) : null;
                $this->recurse($val, $key, $valType);
            }

            $this->depth--;

            $this->out[] = "{$lpad}}";
        }

        $this->deregisterObject($data);
    }
1279266
public function updateContentTypeGroup(
        ContentTypeGroupUpdateData $data = null,
        ?string $name = null
    ): FormInterface {
        $name = $name ?: sprintf('update-content-type-group-%d', $data->getContentTypeGroup()->id);

        return $this->formFactory->createNamed($name, ContentTypeGroupUpdateType::class, $data);
    }
1141994
public function updateContentMainLocation(
        ?ContentMainLocationUpdateData $data = null,
        ?string $name = null
    ): FormInterface {
        $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentMainLocationUpdateType::class);
        $data = $data ?? new ContentMainLocationUpdateData();

        return $this->formFactory->createNamed(
            $name,
            ContentMainLocationUpdateType::class,
            $data
        );
    }
1209709
public static function is_convertable($mimetype = null)
    {
        $rcube = rcube::get_instance();

        // @TODO: check if specified mimetype is really supported
        return class_exists('Imagick', false) || $rcube->config->get('im_convert_path');
    }
327360
public function template($name, $data = null)
  {
    $t = $this->getTemplatesEngine()->make($name);

    if ($data) {
      $t->data($data);
    }

    return $t;
  }
421857
public function resolveFileUrl($data, string $name)
    {
        $value = '';
        if (null !== $data) {
            if (is_array($data) && isset($data[$name])) {
                $value = $data[$name];
            } elseif (is_object($data) && property_exists($data, $name)) {
                $value = $data->{$name};
            }

            return is_string($value) ? $value : '';
        }

        return $value;
    }
311514
public function removeContentTypeTranslation(
        TranslationRemoveData $data = null,
        ?string $name = null
    ): FormInterface {
        $name = $name ?: 'delete-translations';

        return $this->formFactory->createNamed($name, TranslationRemoveType::class, $data);
    }