倒回文件指针的位置

@param resource $resource

@throws \InvalidArgumentException
776679
protected function rewindStream($resource)
    {
        if (! Assert::resource($resource)) {
            throw new InvalidArgumentException(
                sprintf(
                    '%s::%s() parameter 1 must be "resource"',
                    __CLASS__,
                    __METHOD__
                )
            );
        }

        if (ftell($resource) !== 0 && $this->isSeekableStream($resource)) {
            rewind($resource);
        }
    }
261590
public function delete(Resource $resource)
    {
        $data = $resource->toArray();

        $user = $this->userManager->findUserByUsername($data['username']);
        if (!$user) {
            $errorMessage = $this->translator->trans('error.user_not_found', array('%username%' => $data['username']));
            throw new NotFoundHttpException($errorMessage);
        }

        $this->userManager->deleteUser($user);
    }
498896
public function swapResource($resource)
    {
        if (!is_resource($resource) or 'gd' !== get_resource_type($resource)) {
            throw new \InvalidArgumentException('No resource given or wrong resource type');
        }

        $this->resource = $resource;
    }
1253038
protected function attachResource($stream) : void
    {
        if (is_resource($stream) === false) {
            throw new \InvalidArgumentException("Argument must be a valid resource type.");
        }

        $this->stream = $stream;
        $stats = fstat($this->stream);


        // Identifica se o "Stream" é "pipe"
        $bitMask = 0010000;
        $this->isPipe = (($stats["mode"] & $bitMask) !== 0);

        // Identifica o tamanho do "Stream" (se possível).
        $this->size = ((isset($stats["size"]) && $this->isPipe === false) ? $stats["size"] : null);

        // Resgata os metadados do "Stream"
        $this->metaData = stream_get_meta_data($this->stream);

        // Verifica se o "Stream" é "pesquisável"
        $this->seekable = ($this->isPipe === false && $this->metaData["seekable"]);



        $streamModes = [
            "readable" => ["r", "r+", "w+", "a+", "x+", "c+"],
            "writable" => ["r+", "w", "w+", "a", "a+", "x", "x+", "c", "c+"]
        ];

        // Verifica se é possível alterar o "Stream"
        foreach ($streamModes["writable"] as $mode) {
            if (strpos($this->metaData["mode"], $mode) === 0) {
                $this->writable = true;
                break;
            }
        }

        
        // Verifica se é possível ler o "Stream"
        foreach ($streamModes["readable"] as $mode) {
            if (strpos($this->metaData["mode"], $mode) === 0) {
                $this->readable = true;
                break;
            }
        }
    }
618873
public function deserialize($data, Resource $resource = null)
    {
        if (empty($resource)) {
            $resource = new Resource();
        }
        if (isset($data['resourceType']) && isset($data['resourceType']['name'])) {
            $resourceType = $this->resourceTypeRepo->findOneBy(['name' => $data['resourceType']['name']]);
            $resource->setResourceType($resourceType);
        }
        if (isset($data['name'])) {
            $resource->setName($data['name']);
        }
        if (isset($data['maxTimeReservation'])) {
            $resource->setMaxTimeReservation($data['maxTimeReservation']);
        }
        if (isset($data['description'])) {
            $resource->setDescription($data['description']);
        }
        if (isset($data['localization'])) {
            $resource->setLocalisation($data['localization']);
        }
        if (isset($data['quantity'])) {
            $resource->setQuantity($data['quantity']);
        }
        if (isset($data['color'])) {
            $resource->setColor($data['color']);
        }
        if (isset($data['organizations'])) {
            $this->deserializeOrganizations($resource, $data['organizations']);
        }

        return $resource;
    }
107077
public function supports($resource, $type = null)
    {
        if (is_string($resource)) {
            if ($this->isFile($resource)) {
                return $this->validateExtension($resource);
            } else {
                return $this->isJson($resource);
            }
        }

        return false;
    }
22465
public static function create($resource)
    {
        $type = gettype($resource);

        if ($type == 'string') {
            $stream = fopen('php://temp', 'r+');

            if ($resource !== '') {
                fwrite($stream, $resource);
                fseek($stream, 0);
            }

            return new self($stream);
        }

        if ($type == 'resource') {
            return new self($resource);
        }

        if ($resource instanceof StreamableInterface) {
            return $resource;
        }

        throw new \InvalidArgumentException('Invalid resource type: ' . $type);
    }
62044
public function setResource($rel, $resource)
    {
        if (is_array($resource)) {
            foreach ($resource as $r) {
                $this->addResource($rel, $r);
            }

            return $this;
        }

        if (!($resource instanceof Hal)) {
            throw new \InvalidArgumentException('$resource should be of type array or Nocarrier\Hal');
        }

        $this->resources[$rel][] = $resource;

        return $this;
    }
64878
public function load($source)
    {
        if ($source instanceof File) {
            $resource = $source->readStream();
        } else {
            if (!is_file($source)) {
                throw new InvalidArgumentException("Expected CSV file '" . $source . "' could not be open.");
            }
            if (!is_readable($source)) {
                throw new InvalidArgumentException("CSV file '" . $source . "' is not readable.");
            }
            $resource = fopen($source, 'r');
        }

        // More readable variables
        $enclosure = preg_quote($this->options['field_encloser'], '/');
        $delimiter = $this->options['field_delimiter'];
        $multiValueSeparator = $this->options['multi_values_delimiter'];

        $adle = ini_get('auto_detect_line_endings');
        ini_set('auto_detect_line_endings', true);

        if ($this->options['first_row_column_names']) {
            $fields = fgetcsv($resource, 0, $delimiter, $enclosure);
            $this->setColumnMapping($fields);
        }

        $data = array();
        while (($rowFields = fgetcsv($resource, 0, $delimiter, $enclosure)) !== false) {
            $lineData = [];
            foreach ($rowFields as $fieldData) {
                // If there is nothing in the cell, replace by null for abstraction consistency.
                if ($fieldData == '') {
                    $fieldData = null;
                } elseif (!empty($multiValueSeparator) && mb_strpos($fieldData, $multiValueSeparator) !== false) {
                    // try to split by multi_value_delimiter
                    $multiField = [];
                    foreach (explode($multiValueSeparator, $fieldData) as $item) {
                        if (!empty($item)) {
                            $multiField[] = $item;
                        }
                    }
                    $fieldData = $multiField;
                }
                $lineData[] = $fieldData;
            }
            $data[] = $lineData;

            // Update the column count.
            $currentRowColumnCount = count($rowFields);
            if ($this->getColumnCount() < $currentRowColumnCount) {
                $this->setColumnCount($currentRowColumnCount);
            }

        }
        ini_set('auto_detect_line_endings', $adle);
        fclose($resource);
        $this->setData($data);
    }
921109
public function load($resource, $type = null)
    {
        $path = $this->locator->locate($resource);
        $this->container->addResource(new FileResource($path));

        $file = new JsonFile($path);
        $content = $file->read();
        $extension = pathinfo($resource, PATHINFO_FILENAME);

        if (array_key_exists('parameters', $content)) {
            foreach ($content['parameters'] as $name => $parameter) {
                $this->container->setParameter($name, $parameter);
            }

            unset($content['parameters']);
        }

        if (array_key_exists('imports', $content)) {
            foreach ($content['imports'] as $import) {
                $importFilename = $import;
                if (!Path::isAbsolute($importFilename)) {
                    $importFilename = Path::join([dirname($path), $import]);
                }

                $this->import($importFilename, null, false, $file);
            }

            unset($content['imports']);
        }

        $this->container->loadFromExtension($extension, $content);
    }
657761
protected function filterFile($file)
    {
        if (is_string($file)) {
            $this->file = $file;
        } elseif (is_resource($file)) {
            $this->stream = new Stream($file);
        } elseif ($file instanceof StreamInterface) {
            $this->stream = $file;
        } else {
            throw new \InvalidArgumentException('The file resource is not readable.');
        }
    }
414555
public function addResource(string ...$resource)
    {
        foreach ($resource as $_resource)
        {
            $this->resourceRegistry->save($_resource);
        }
    }
415098
public function load($resource, $type = null) 
    {
        $path = $this->locator->locate($resource);
        
        if (!stream_is_local($path)) {
            throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path));
        }

        if (!file_exists($path)) {
            throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path));
        }
        
        $this->loaded[$resource] = $path;

        return Yaml::parse(file_get_contents($path));
    }
399234
public function load($resource, $type = null) 
    {
        $path = $this->locator->locate($resource);
        
        if (!stream_is_local($path)) {
            throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path));
        }

        if (!file_exists($path)) {
            throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path));
        }

        $returnArray = include $path;
        
        if(false === is_array($returnArray)) {
            throw ConfigException::configNotArray($path);
        }
        
        $this->loaded[$resource] = $path;
        
        return $returnArray;
    }
1047908
public function moveResource()
    {
        try {
            if (!$this->hasRequestParameter('uri')) {
                throw new InvalidArgumentException('Resource uri must be specified.');
            }

            $data = $this->getRequestParameter('uri');
            $id = $data['id'];

            $this->validateUri($id);
            $this->validateInstanceRoot($id);

            $this->signatureValidator->checkSignature($data['signature'], $id);

            $ids = [$id];

            $this->validateMoveRequest();
            $response = $this->moveAllInstances($ids);
            $this->returnJson($response);
        } catch (\InvalidArgumentException $e) {
            $this->returnJsonError($e->getMessage());
        }
    }
989847
public function load($resource, $type = null)
    {
        $config = include $resource;

        if (!is_array($config)) {
            throw new \InvalidArgumentException(
                sprintf('The file "%s" did not return a valid PHP array when included', $resource)
            );
        }

        return $config;
    }
250007
public function setResource($resource)
    {
        $this->resource = $resource;

        if (null !== $resource) {
            $this->stopPropagation();
        }

        return $this;
    }