Write $data values using $this->writers

@param \core_kernel_classes_Resource $resource
@param array $data
@param bool $dryrun
@return bool
@throws MetadataInjectorWriteException
966844
public function write(\core_kernel_classes_Resource $resource, array $data, $dryrun = false)
    {
        $writers = $errors = [];

        foreach ($this->writers as $name => $writer) {
            try {
                $value = $writer->format($data);
                if ($writer->validate($value)) {
                    $writers[$name] = $writer;
                } else {
                    $errors[$name] = 'Writer "' . $name . '" cannot validate value.';
                }
            } catch (MetadataReaderNotFoundException $e) {
                $errors[$name] = 'Writer "' . $name . '" cannot format value: ' . $e->getMessage();
            }
        }

        foreach ($writers as $name => $writer) {
            if (! $writer instanceof OntologyWriter) {
                $errors[$name] = __CLASS__ . ' must implements ' . OntologyWriter::class;
                continue;
            }

            try {
                $writer->write($resource, $data, $dryrun);
            } catch (MetadataWriterException $e) {
                $errors[$name] = $e->getMessage();
            }
        }

        if (! empty($errors)) {
            foreach ($errors as $name => $error) {
                \common_Logger::d('Error on injector "' . __CLASS__ . '" with writer "' . $name . '" : ' . $error);
            }
            throw new MetadataInjectorWriteException(
                'Injector "' . __CLASS__ . '" cannot write values from writers: ' . implode(', ', array_keys($errors))
            );
        }

        return true;
    }
349914
private function _write($file, $data, $config)
    {
        $result = file_put_contents($file, $data);
        if ($result !== false) {
            // set permissions of the new file (no execute)
            $chmod = $config->get('Cache.SerializerPermissions');
            if ($chmod !== null) {
                chmod($file, $chmod & 0666);
            }
        }
        return $result;
    }
416715
public function writeData($path = '', $data, $public = true)
    {
        $path = $this->getStoragePath($path);

        return $this->_storage->write($path, $data, $public);
    }
230229
public function execute($method, $resource, array $data = [])
    {
        $request = new Request($this->handler);
        $dataResource = $request->execute($method, $this->makeUrl($resource), array_merge($data, [
            'headers' => [
                'Authorization' => sprintf('Basic %s', base64_encode($this->token . ':' . ''))
            ]
        ]));

        return $dataResource;
    }
989173
public function validateResource($resource, $data = null)
    {
        // If no data is provided, validate the resource against it's present attributes
        if (is_null($data)) {
            $data = $resource->getAttributes();
        }

        $validator = Validator::make($data, $resource->getValidationRules(), $resource->getValidationMessages());

        if ($validator->fails()) {
            throw new StoreResourceFailedException('Could not create resource.', $validator->errors());
        }
    }
616773
public function write($data = null) {
		if (!is_resource($this->_resource)) {
			return false;
		}
		if (!is_object($data)) {
			$data = $this->_instance($this->_classes['request'], (array) $data + $this->_config);
		}
		$this->set(CURLOPT_URL, $data->to('url'));

		if ($data instanceof Message) {
			if (!empty($this->_config['ignoreExpect'])) {
				$data->headers('Expect', ' ');
			}
			if (isset($data->headers)) {
				$this->set(CURLOPT_HTTPHEADER, $data->headers());
			}
			if (isset($data->method) && $data->method === 'POST') {
				$this->set([CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data->body()]);
			}
			if (isset($data->method) && in_array($data->method,['PUT','PATCH','DELETE'])) {
				$this->set([
					CURLOPT_CUSTOMREQUEST => $data->method,
					CURLOPT_POSTFIELDS => $data->body()
				]);
			}
		}
		return (boolean) curl_setopt_array($this->_resource, $this->options);
	}
905292
private function write_array($writers_schema, $datum, $encoder)
  {
    $datum_count = count($datum);
    if (0 < $datum_count)
    {
      $encoder->write_long($datum_count);
      $items = $writers_schema->items();
      foreach ($datum as $item)
        $this->write_data($items, $item, $encoder);
    }
    return $encoder->write_long(0);
  }
362826
public function updateResource(Resource $resource, $overwrite = false)
    {
        $url = self::makeUrl(null, $resource->uri);
        $body = $resource->toJSON();

        $url .= '?' . Util::query_suffix(array("overwrite" => $overwrite));
        // Isolate the class name, lowercase it, and provide it as a filetype in the headers
        $type = explode('\\', get_class($resource));
        $file_type = 'application/repository.' . lcfirst(end($type)) . '+json';
        $data = $this->service->prepAndSend($url, array(201, 200), 'PUT', $body, true, $file_type, 'application/json');
        return $resource::createFromJSON(json_decode($data, true), get_class($resource));
    }
655920
public function write(
        string $filename,
        string $data,
        int $mode = null,
        bool $ensureDirectory = false,
        bool $append = false
    ): bool {
        $mode = $mode ?? self::DEFAULT_FILE_MODE;

        try {
            if ($ensureDirectory) {
                $this->ensureDirectory(dirname($filename), $mode);
            }

            if ($this->exists($filename)) {
                //Forcing mode for existed file
                $this->setPermissions($filename, $mode);
            }

            $result = file_put_contents(
                $filename,
                $data,
                $append ? FILE_APPEND | LOCK_EX : LOCK_EX
            );

            if ($result !== false) {
                //Forcing mode after file creation
                $this->setPermissions($filename, $mode);
            }
        } catch (\Exception $e) {
            throw new WriteErrorException($e->getMessage(), $e->getCode(), $e);
        }

        return $result;
    }
142362
public function write($data, $mode = 'w', $force = false)
    {
        $success = false;
        if ($this->open($mode, $force) === true) {
            if ($this->lock !== null && flock($this->handle, LOCK_EX) === false) {
                return false;
            }

            if (fwrite($this->handle, $data) !== false) {
                $success = true;
            }
            if ($this->lock !== null) {
                flock($this->handle, LOCK_UN);
            }
        }

        return $success;
    }
527018
public function import(array $data, $dryrun = false)
    {
        try {
            /** @var Injector[] $injectors */
            $injectors = $this->getInjectors();
        } catch (InconsistencyConfigException $e) {
            return \common_report_Report::createFailure('Config problem: ' . $e->getMessage());
        }

        // Global report
        $report = \common_report_Report::createInfo('Report of metadata import.');

        // Foreach line of dateSource
        foreach ($data as $uri => $dataSource) {
            try {

                // Check if resource exists
                $resource = $this->getResource($uri);
                if (! $resource->exists()) {
                    throw new MetadataImportException('Unable to find resource associated to uri : "' . $uri . '"');
                }

                $lineReport = \common_report_Report::createInfo('Report by line.');
                $dataSource = array_change_key_case($dataSource);

                // Foreach injector to map a target source
                /** @var Injector $injector */
                foreach ($injectors as $name => $injector) {
                    $injectorReport = null;

                    try {
                        $dataRead = $injector->read($dataSource);
                        $injector->write($resource, $dataRead, $dryrun);
                        $injectorReport = \common_report_Report::createSuccess('Injector "' . $name . '" successfully ran.');
                    } catch (MetadataInjectorReadException $e) {
                        $injectorReport = \common_report_Report::createFailure(
                            'Injector "' . $name . '" failed to run at read: ' . $e->getMessage()
                        );
                    } catch (MetadataInjectorWriteException $e) {
                        $injectorReport = \common_report_Report::createFailure(
                            'Injector "' . $name . '" failed to run at write: ' . $e->getMessage()
                        );
                    }

                    // Skip if there are no report (no data to read for this injector)
                    if (! is_null($injectorReport)) {
                        $lineReport->add($injectorReport);
                    }

                }

            } catch (MetadataImportException $e) {
                $lineReport = \common_report_Report::createFailure($e->getMessage());
            }
            $report->add($lineReport);
        }

        return $report;
    }
739050
public function writeStream($uri, $resource, array $config = [])
    {
        return $this->mount_manager->writeStream($uri, $resource, $config);
    }
1200598
public function write(string $uri, $data)
    {
        // Create directory recursively if it doesn't exist
        if ( ! file_exists(dirname($uri))) {
            mkdir(dirname($uri), 0755, true);
        }

        // Write file to target directory
        if ( ! file_put_contents($uri, $data)) {
            throw new ErrorException("Failed to write output to file: ".$uri);
        }

        return true;
    }
865991
public function syncProjectPaths($paths, $dryRun = false) {
		foreach($paths as $path) {
			if(!DNProject::get()->filter('Name', $path)->count()) {
				$this->message($path);
				if(!$dryRun) {
					DNProject::create_from_path($path)->write();
				}
			}
		}
	}
831104
public static function write($file, $data, $lock = false) {
		return file_put_contents($file, $data, $lock ? LOCK_EX : 0);
	}
345476
protected function writeMetadata($id, array $metadata)
    {
        $filename = $this->getFilename($id, true);
        $this->assertDirectory($filename);
        $this->assertFile($filename);
        if (false === file_put_contents($filename, serialize($metadata))) {
            throw new RawFileCacheException(sprintf('Cannot write file : %s', $filename), RawFileCacheException::CANNOT_WRITE_FILE);
        }
    }
26826
private void writeResources(List<Resource> resources)
            throws JsonGenerationException, IOException {

        PolicyUtils.validateResourceList(resources);
        List<String> resourceStrings = new ArrayList<String>();

        for (Resource resource : resources) {
            resourceStrings.add(resource.getId());
        }

        // all resources are validated to be of the same type, so it is safe to take the type of the first one
        if (resources.get(0).isNotType()) {
            writeJsonArray(JsonDocumentFields.NOT_RESOURCE, resourceStrings);
        } else {
            writeJsonArray(JsonDocumentFields.RESOURCE, resourceStrings);
        }
    }