Saves the result into cache.

@param mixed $result Result that should be saved.

@return bool
@throws \Webiny\Component\Rest\RestException
2939
public function saveCallbackResult($result)
    {
        // get cache key
        $cacheKey = $this->getCacheKey();

        // cache the result
        try {
            $cache = $this->cache($this->requestBag->getApiConfig()->get('Cache'));

            return $cache->save($cacheKey, $result, $this->requestBag->getMethodData()['cache']['ttl']);
        } catch (\Exception $e) {
            throw new RestException('Unable to save the result into cache. ' . $e->getMessage());
        }
    }
74876
public function setResult($result): self
    {
        $this->_result = $result;
        $this->_hasResult = true;

        return $this;
    }
611843
public function delete(&$result)
    {
        $entity = $this->accessor->getPropertyValue($result, $this->definition->container());
        if (empty($entity)) {
            return $result;
        }

        $this->assertInstance($entity);

        $this->storage->delete($entity, $this->definition->entity())->execute();

        return $result;
    }
155786
public function create(Result $result)
    {
        $this->om->persist($result);
        $this->om->flush();

        return $result;
    }
431361
private function returnResponse($result): Response
    {
        if ($result instanceof Response) {
            return $result;
        }

        if (is_array($result)) {
            $result = json_encode($result);
        }

        return new Response(200, [], $result);
    }
16626
public function storeResult(Form $form, Result $result)
    {
        $entityManager = $this->container->get('doctrine')->getManager();
        $form->addResult($result);
        $entityManager->persist($form);
        $entityManager->flush();
    }
502356
protected function done($result = null)
    {
        if ($result === null) {
            $this->event('error', $this->error());
        }

        $this->event('done', $result);
        $this->event = null;

        return $result;
    }
1083439
public function delete(&$result)
    {
        $entity = $this->accessor->getPropertyValue($result, $this->definition->container());
        if (empty($entity)) {
            return $result;
        }

        $mediator = [];

        foreach ($this->definition->localKeys() as $entityField => $mediatorField) {
            $mediator[$mediatorField] = $this->accessor->getPropertyValue($result, $entityField);
        }

        foreach ($this->definition->foreignKeys() as $mediatorField => $entityField) {
            $mediator[$mediatorField] = $this->accessor->getPropertyValue($entity, $entityField);
        }

        $this->storage->delete($mediator, $this->definition->mediator())->execute();
        $this->accessor->setPropertyValue($result, $this->definition->container(), $entity);

        return $result;
    }
131874
private function createResult($result)
    {
        switch (\pg_result_status($result, \PGSQL_STATUS_LONG)) {
            case \PGSQL_EMPTY_QUERY:
                throw new QueryError("Empty query string");

            case \PGSQL_COMMAND_OK:
                return new PgSqlCommandResult($result);

            case \PGSQL_TUPLES_OK:
                return new PgSqlResultSet($result);

            case \PGSQL_NONFATAL_ERROR:
            case \PGSQL_FATAL_ERROR:
                $diagnostics = [];
                foreach (self::DIAGNOSTIC_CODES as $fieldCode => $desciption) {
                    $diagnostics[$desciption] = \pg_result_error_field($result, $fieldCode);
                }
                throw new QueryExecutionError(\pg_result_error($result), $diagnostics);

            case \PGSQL_BAD_RESPONSE:
                throw new FailureException(\pg_result_error($result));

            default:
                // @codeCoverageIgnoreStart
                throw new FailureException("Unknown result status");
                // @codeCoverageIgnoreEnd
        }
    }
64529
private function outputResult($result)
    {
        $this->io->writeln(sprintf('<comment>%s</comment>', $this->app['extend.action.io']->getOutput()), OutputInterface::OUTPUT_PLAIN);

        if ($result === 0) {
            $this->io->success('Autoloaders updated');
            $this->auditLog(__CLASS__, 'Autoloaders updated');
        } else {
            $this->io->error('Autoloaders failed update');
        }

        return $result;
    }
631231
public function save()
    {
        $results
            = "<?php \n return " . var_export(self::getResults(), true) . ";";
        file_put_contents($this->file, $results);
    }
1346483
public function afterExecute(
        \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite\Save $subject,
        $result
    ) {
        $productId = (int)$this->request->getParam('product', 0);
        if ($productId) {
            $this->catalogResource->setModified([$productId]);
        }
        return $result;
    }
1325366
public function put($url, $data, $result)
    {
        if (!array_key_exists('$data', $result)) {
            $result['$data'] = null; // Allows for null response
        }

        $this->get_versions();

        $cache_content = $result;
        $cache_content['$cached'] = true;

        $cache_key = $this->get_key($url, $data);
        $cache_path = $this->get_path($cache_key, 'result');
        if ($size = $this->write_cache($cache_path, $cache_content)) {
            if (isset($result['$cached'])) {
                $cached = $result['$cached'];
                foreach ($this->result_collections($result) as $collection) {
                    // Collection may not be cacheable
                    if (!isset($cached[$collection]) && !isset($this->versions[$collection])) {
                        continue;
                    }
                    $this->put_index($collection, $cache_key, $size);
                    if (isset($cached[$collection])) {
                        $this->put_version($collection, $cached[$collection]);
                    }
                }
            }
        }
    }
735545
protected function doSave($result, $cache = null)
    {
        if ($cache === null) {
            $cache = $this->doGet();
        }

        $this->cache->save(
            $cache->expiresAfter($this->lifetime)->set($result)
        );
    }
566746
private function getProcessedTemplateBeforeSave($result)
    {
        //saving array values
        if (empty($args)) {
            $this->getResultIfArgsEmptyForBeforeSave($result);
        } else {
            //saving string value
            $field = $args[0];

            //compress the text body when is a dotmailer template
            if ($field == 'template_text' && ! $this->isStringCompressed($result) &&
                $this->transactionalHelper->isDotmailerTemplate($this->templateCode)
            ) {
                $result = $this->compressString($result);
            }
            if ($field == 'template_id') {
                $this->saveTemplateIdInRegistry($result);
            }
        }

        return $result;
    }
1315659
public function setResult($result, $data = null)
    {
        if (null === $result) {
            return $this;
        }

        if (is_numeric($result)) {
            if ($result > 1000) {
                $result = ResultException::factory($result, $data);
            } else {
                $result = new static::$resultClass((int) $result, $data);
            }
        } elseif ($result instanceof ResultException) {
            // continue
        } elseif (is_array($result) && isset($result[self::RESULT_P_GLOBAL_CODE])) {
            $result = ResultException::factory($result[self::RESULT_P_GLOBAL_CODE], $result[self::RESULT_P_DATA]);
        } else {
            $result = new ResultException(ResultException::E_INTERNAL, $result);
        }

        if (!empty($data)) {
            $result->addData($data);
        }

        $this->result = $result;
        $this->setData(self::P_RESULT, [
            self::RESULT_P_GLOBAL_CODE => $result->getGlobalCode(),
            self::RESULT_P_DATA        => $result->getData(),
        ]);

        return $this;
    }
884330
protected function cacheResults(array $results)
    {
        $mapper = $this->mapper;

        // When hydrating EmbeddedValue object, they'll likely won't
        // have a primary key set.
        if ($mapper->getEntityMap()->getKeyName() !== null) {
            $mapper->getEntityCache()->add($results);
        }
    }