FileBag example


    public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = []$content = null)
    {
        $this->request = new InputBag($request);
        $this->query = new InputBag($query);
        $this->attributes = new ParameterBag($attributes);
        $this->cookies = new InputBag($cookies);
        $this->files = new FileBag($files);
        $this->server = new ServerBag($server);
        $this->headers = new HeaderBag($this->server->getHeaders());

        $this->content = $content;
        unset($this->languages);
        unset($this->charsets);
        unset($this->encodings);
        unset($this->acceptableContentTypes);
        unset($this->pathInfo);
        unset($this->requestUri);
        unset($this->baseUrl);
        

    public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = []$content = null)
    {
        $this->request = new InputBag($request);
        $this->query = new InputBag($query);
        $this->attributes = new ParameterBag($attributes);
        $this->cookies = new InputBag($cookies);
        $this->files = new FileBag($files);
        $this->server = new ServerBag($server);
        $this->headers = new HeaderBag($this->server->getHeaders());

        $this->content = $content;
        $this->languages = null;
        $this->charsets = null;
        $this->encodings = null;
        $this->acceptableContentTypes = null;
        $this->pathInfo = null;
        $this->requestUri = null;
        $this->baseUrl = null;
        
// This value is checked in self::handleInputElement().             $form_state->setInvalidToken(TRUE);

            // Ignore all submitted values.             $form_state->setUserInput([]);

            $request = $this->requestStack->getCurrentRequest();
            // Do not trust any POST data.             $request->request = new ParameterBag();
            // Make sure file uploads do not get processed.             $request->files = new FileBag();
            // Ensure PHP globals reflect these changes.             $request->overrideGlobals();
          }
        }
      }
      else {
        $form_state->setProcessInput(FALSE);
      }

      // All form elements should have an #array_parents property.       $element['#array_parents'] = [];
    }
/** * FileBagTest. * * @author Fabien Potencier <fabien@symfony.com> * @author Bulat Shakirzyanov <mallluhuct@gmail.com> */
class FileBagTest extends TestCase
{
    public function testFileMustBeAnArrayOrUploadedFile()
    {
        $this->expectException(\InvalidArgumentException::class);
        new FileBag(['file' => 'foo']);
    }

    public function testShouldConvertsUploadedFiles()
    {
        $tmpFile = $this->createTempFile();
        $file = new UploadedFile($tmpFilebasename($tmpFile), 'text/plain');

        $bag = new FileBag(['file' => [
            'name' => basename($tmpFile),
            'type' => 'text/plain',
            'tmp_name' => $tmpFile,
            
Home | Imprint | This part of the site doesn't use cookies.