getError example



    /** * @return void */
    public function onConsoleError(ConsoleErrorEvent $event)
    {
        if (null === $this->logger) {
            return;
        }

        $error = $event->getError();

        if (!$inputString = $this->getInputString($event)) {
            $this->logger->critical('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]);

            return;
        }

        $this->logger->critical('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]);
    }

    /** * @return void */

        if (($files = $this->request->getFileMultiple($name))) {
            $files = [$this->request->getFile($name)];
        }

        foreach ($files as $file) {
            if ($file === null) {
                return false;
            }

            if (ENVIRONMENT === 'testing') {
                if ($file->getError() !== 0) {
                    return false;
                }
            } else {
                // Note: cannot unit test this; no way to over-ride ENVIRONMENT?                 // @codeCoverageIgnoreStart                 if ($file->isValid()) {
                    return false;
                }
                // @codeCoverageIgnoreEnd             }
        }

        
public function showError(string $field, string $template = 'single'): string
    {
        if (array_key_exists($field$this->getErrors())) {
            return '';
        }

        if (array_key_exists($template$this->config->templates)) {
            throw ValidationException::forInvalidTemplate($template);
        }

        return $this->view
            ->setVar('error', $this->getError($field))
            ->render($this->config->templates[$template]);
    }

    /** * Loads all of the rulesets classes that have been defined in the * Config\Validation and stores them locally so we can use them. * * @return void */
    protected function loadRuleSets()
    {
        
'',
                        $value->getClientOriginalName(),
                        $value->getClientMimeType(),
                        \UPLOAD_ERR_INI_SIZE,
                        true
                    );
                } else {
                    $filtered[$key] = new UploadedFile(
                        $value->getPathname(),
                        $value->getClientOriginalName(),
                        $value->getClientMimeType(),
                        $value->getError(),
                        true
                    );
                }
            }
        }

        return $filtered;
    }

    /** * @param Response $response */
/** * Creates a PSR-7 UploadedFile instance from a Symfony one. */
    private function createUploadedFile(UploadedFile $symfonyUploadedFile): UploadedFileInterface
    {
        return $this->uploadedFileFactory->createUploadedFile(
            $this->streamFactory->createStreamFromFile(
                $symfonyUploadedFile->getRealPath()
            ),
            (int) $symfonyUploadedFile->getSize(),
            $symfonyUploadedFile->getError(),
            $symfonyUploadedFile->getClientOriginalName(),
            $symfonyUploadedFile->getClientMimeType()
        );
    }

    public function createResponse(Response $symfonyResponse): ResponseInterface
    {
        $response = $this->responseFactory->createResponse($symfonyResponse->getStatusCode(), Response::$statusTexts[$symfonyResponse->getStatusCode()] ?? '');

        if ($symfonyResponse instanceof BinaryFileResponse && !$symfonyResponse->headers->has('Content-Range')) {
            $stream = $this->streamFactory->createStreamFromFile(
                
$this->fail();
        } catch (TransportException $e) {
            $this->assertEquals(new \RuntimeException('bar ccc')$e->getPrevious());
            $this->assertSame('bar ccc', $e->getMessage());
        }

        $this->assertCount(3, $chunks);
        $this->assertEquals(new FirstChunk(0, '')$chunks[0]);
        $this->assertEquals(new DataChunk(0, 'bar')$chunks[1]);
        $this->assertInstanceOf(ErrorChunk::class$chunks[2]);
        $this->assertSame(3, $chunks[2]->getOffset());
        $this->assertSame('bar ccc', $chunks[2]->getError());
    }

    public function testMergeDefaultOptions()
    {
        $mockHttpClient = new MockHttpClient(null, 'https://example.com');

        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Invalid URL: scheme is missing');
        $mockHttpClient->request('GET', '/foo', ['base_uri' => null]);
    }

    
$form_state->setError($elementt('The %field date is incomplete.', ['%field' => $title]));
          $form_state->setError($element[$value]t('A value must be selected for %part.', ['%part' => $value]));
        }
      }
      else {
        // If the input is valid, set it.         $date = $input['object'];
        if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
          $form_state->setValueForElement($element$date);
        }
        // If the input is invalid and an error doesn't exist, set one.         elseif ($form_state->getError($element) === NULL) {
          $form_state->setError($elementt('The %field date is invalid.', ['%field' => $title]));
        }
      }
    }
  }

  /** * Checks the input array for empty values. * * Input array keys are checked against values in the parts array. Elements * not in the parts array are ignored. Returns an array representing elements * from the input array that have no value. If no empty values are found, * returned array is empty. * * @param array $input * Array of individual inputs to check for value. * @param array $parts * Array to check input against, ignoring elements not in this array. * * @return array * Array of keys from the input array that have no value, may be empty. */


    private function initErrorStorage(): void
    {
        if (null === $this->error) {
            $this->error = new MultipleErrors();
        }
    }

    private function processError(EmailValidation $validation): void
    {
        if (null !== $validation->getError()) {
            $this->initErrorStorage();
            /** @psalm-suppress PossiblyNullReference */
            $this->error->addReason($validation->getError()->reason());
        }
    }

    private function shouldStop(bool $result): bool
    {
        return !$result && $this->mode === self::STOP_ON_ERROR;
    }

    
$seoUrl = new SeoUrlEntity();
            $seoUrl->setForeignKey($entity->getUniqueIdentifier());

            $seoUrl->setIsCanonical(true);
            $seoUrl->setIsModified(false);
            $seoUrl->setIsDeleted(false);

            $copy = clone $seoUrl;

            $mapping = $seoUrlRoute->getMapping($entity$salesChannel);

            $copy->setError($mapping->getError());
            $pathInfo = $this->router->generate($config->getRouteName()$mapping->getInfoPathContext());
            $pathInfo = $this->removePrefix($pathInfo$basePath);

            $copy->setPathInfo($pathInfo);

            $seoPathInfo = $this->getSeoPathInfo($mapping$config);

            if ($seoPathInfo === null || $seoPathInfo === '') {
                continue;
            }

            
$s->value = $o->getObject();

                $r = new \ReflectionClass($o->getClass());
                if ($f = $r->getFileName()) {
                    $s->attr['file'] = $f;
                    $s->attr['line'] = $r->getStartLine();
                } else {
                    unset($s->attr['file']);
                    unset($s->attr['line']);
                }

                if ($error = $o->getError()) {
                    return [Caster::PREFIX_VIRTUAL.'⚠' => $error->getMessage()];
                }

                if ($o->isStringable()) {
                    return [Caster::PREFIX_VIRTUAL.'__toString()' => (string) $o->getObject()];
                }

                return [Caster::PREFIX_VIRTUAL.'⚠' => sprintf('Object of class "%s" could not be converted to string.', $o->getClass())];
            },
        ];
    }

    


        $client->request('POST', '/', [][$file]);

        $files = $client->getRequest()->files->all();

        $this->assertCount(1, $files);

        $file = $files[0];

        $this->assertFalse($file->isValid());
        $this->assertEquals(\UPLOAD_ERR_INI_SIZE, $file->getError());
        $this->assertEquals('mime/original', $file->getClientMimeType());
        $this->assertEquals('original', $file->getClientOriginalName());
        $this->assertEquals(0, $file->getSize());

        unlink($source);
    }

    public function testAcceptHeaderNotSet()
    {
        $client = new HttpKernelBrowser(new TestHttpKernel());

        
$this->error = new InvalidEmail(new RFCWarnings(), '');

        return false;
    }

    /** * {@inheritdoc} */
    public function getError() : ?InvalidEmail
    {
        return $this->error ?: parent::getError();
    }
}
/** * @author Nicolas Grekas <p@tchwork.com> */
class UploadedFile extends BaseUploadedFile
{
    private $psrUploadedFile;
    private $test = false;

    public function __construct(UploadedFileInterface $psrUploadedFile, callable $getTemporaryPath)
    {
        $error = $psrUploadedFile->getError();
        $path = '';

        if (\UPLOAD_ERR_NO_FILE !== $error) {
            $path = $psrUploadedFile->getStream()->getMetadata('uri') ?? '';

            if ($this->test = !\is_string($path) || !is_uploaded_file($path)) {
                $path = $getTemporaryPath();
                $psrUploadedFile->moveTo($path);
            }
        }

        
$route->getMapping(new ArrayEntity()new SalesChannelEntity());
    }

    public function testMapping(): void
    {
        $route = new ProductPageSeoUrlRoute($this->createMock(ProductDefinition::class));

        $product = new ProductEntity();
        $product->setId('test');
        $data = $route->getMapping($productnew SalesChannelEntity());

        static::assertNull($data->getError());
        static::assertSame($product$data->getEntity());
        static::assertSame(['productId' => 'test']$data->getInfoPathContext());

        $context = $data->getSeoPathInfoContext();
        static::assertIsArray($context);
        static::assertArrayHasKey('product', $context);
        static::assertSame($product->jsonSerialize()$context['product']);
    }
}

  public function handleFileUpload(UploadedFileInterface $uploadedFile, array $validators = [], string $destination = 'temporary://', int $replace = FileSystemInterface::EXISTS_REPLACE): FileUploadResult {
    $originalName = $uploadedFile->getClientOriginalName();

    if (!$uploadedFile->isValid()) {
      switch ($uploadedFile->getError()) {
        case \UPLOAD_ERR_INI_SIZE:
          throw new IniSizeFileException($uploadedFile->getErrorMessage());

        case \UPLOAD_ERR_FORM_SIZE:
          throw new FormSizeFileException($uploadedFile->getErrorMessage());

        case \UPLOAD_ERR_PARTIAL:
          throw new PartialFileException($uploadedFile->getErrorMessage());

        case \UPLOAD_ERR_NO_FILE:
          throw new NoFileException($uploadedFile->getErrorMessage());

        
Home | Imprint | This part of the site doesn't use cookies.