public function generate()
    {
        $generator = $this->generator;
        $data = $this->data;

        $fgm = new FileGeneratorManager();
        $fm = new FileManager();
        $tm = new TemplateManager();
        $dbm = new DataBuilderManager();

        $result = $dbm->build($generator->data_builder, $data);

        if (!$result->ok()) {
            return $result;
        }

        // Overwrite filename if driver is local
        $diskName = Config::get('medialibrary.disk_name');

        if (Config::get("filesystems.disks.$diskName.driver", 'local') === 'local') {
            $generator->filename = bin2hex(random_bytes(32)).'-'.$generator->filename;
        }

        $data = $result->getResource();
        $result = $fgm->render($generator->data_builder, $generator->filetype, [
            'body'     => $generator->body,
            'filename' => sys_get_temp_dir().'/'.$generator->filename,
        ], $data);

        $bag = new Bag($result->getResource());

        file_put_contents($bag->get('filename'), $bag->get('body'));

        $result = $fm->create([]);
        $resource = $result->getResource();

        $resource
            ->addMedia($bag->get('filename'))
            ->addCustomHeaders([
                'ContentDisposition' => 'attachment; filename='.basename($bag->get('filename')).'',
            ])
            ->toMediaCollection('file');

        return $result;
    }
public function generate()
    {
        $generator = $this->generator;
        $data = $this->data;

        $fgm = new FileGeneratorManager();
        $fm = new FileManager();
        $tm = new TemplateManager();
        $dbm = new DataBuilderManager();

        $result = $dbm->build($generator->data_builder, $data);

        if (!$result->ok()) {
            return $result;
        }

        // Overwrite filename if driver is local
        $diskName = Config::get('medialibrary.disk_name');

        if (Config::get("filesystems.disks.$diskName.driver", 'local') === 'local') {
            $generator->filename = bin2hex(random_bytes(32)).'-'.$generator->filename;
        }

        $data = $result->getResource();
        $result = $fgm->render($generator->data_builder, $generator->filetype, [
            'body'     => $generator->body,
            'filename' => sys_get_temp_dir().'/'.$generator->filename,
        ], $data);

        $bag = new Bag($result->getResource());

        file_put_contents($bag->get('filename'), $bag->get('body'));

        $result = $fm->create([]);
        $resource = $result->getResource();

        $resource
            ->addMedia($bag->get('filename'))
            ->addCustomHeaders([
                'ContentDisposition' => 'attachment; filename='.basename($bag->get('filename')).'',
            ])
            ->toMediaCollection('file');

        return $result;
    }
public function generate ( ) { $ generator = $ this -> generator ; $ data = $ this -> data ; $ fgm = new FileGeneratorManager ( ) ; $ fm = new FileManager ( ) ; $ tm = new TemplateManager ( ) ; $ dbm = new DataBuilderManager ( ) ; $ result = $ dbm -> build ( $ generator -> data_builder , $ data ) ; if ( ! $ result -> ok ( ) ) { return $ result ; } // Overwrite filename if driver is local $ diskName = Config :: get ( 'medialibrary.disk_name' ) ; if ( Config :: get ( "filesystems.disks.$diskName.driver" , 'local' ) === 'local' ) { $ generator -> filename = bin2hex ( random_bytes ( 32 ) ) . '-' . $ generator -> filename ; } $ data = $ result -> getResource ( ) ; $ result = $ fgm -> render ( $ generator -> data_builder , $ generator -> filetype , [ 'body' => $ generator -> body , 'filename' => sys_get_temp_dir ( ) . '/' . $ generator -> filename , ] , $ data ) ; $ bag = new Bag ( $ result -> getResource ( ) ) ; file_put_contents ( $ bag -> get ( 'filename' ) , $ bag -> get ( 'body' ) ) ; $ result = $ fm -> create ( [ ] ) ; $ resource = $ result -> getResource ( ) ; $ resource -> addMedia ( $ bag -> get ( 'filename' ) ) -> addCustomHeaders ( [ 'ContentDisposition' => 'attachment; filename=' . basename ( $ bag -> get ( 'filename' ) ) . '' , ] ) -> toMediaCollection ( 'file' ) ; return $ result ; }
Generate a file.

@return \Railken\Lem\Result
Generate a file .