-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
464227b
commit 5b35af7
Showing
30 changed files
with
695 additions
and
603 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace RodrigoPedra\LaravelRecordProcessor\Examples; | ||
|
||
use RodrigoPedra\RecordProcessor\Examples\Loggers\ConsoleOutputLogger; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Process\Process; | ||
|
||
class DownloadCommand extends Command | ||
{ | ||
protected function configure() | ||
{ | ||
$this->setName('download'); | ||
|
||
$this->setDescription('Start a server to showcase download usage'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$logger = new ConsoleOutputLogger($output); | ||
|
||
$assetsDirectory = __DIR__ . \DIRECTORY_SEPARATOR . 'download'; | ||
|
||
$process = new Process(['php', '-S', 'localhost:8080', '-t', $assetsDirectory]); | ||
|
||
$logger->info('Navigate in your browser to http://localhost:8080'); | ||
$logger->info('Type CTRL+C to exit'); | ||
|
||
$process->run(function ($type, $buffer) use ($logger) { | ||
$logger->info($buffer); | ||
}); | ||
|
||
$logger->info($process->getOutput()); | ||
|
||
return 0; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace RodrigoPedra\LaravelRecordProcessor\Examples; | ||
|
||
use RodrigoPedra\RecordProcessor\Contracts\Record; | ||
use RodrigoPedra\RecordProcessor\Contracts\RecordSerializer; | ||
use RodrigoPedra\RecordProcessor\Contracts\Serializer; | ||
use RodrigoPedra\RecordProcessor\Records\RecordKeyAggregate; | ||
|
||
class ExampleLaravelBuilderSerializer implements RecordSerializer | ||
{ | ||
public function serializeRecord(Serializer $serializer, Record $record): bool | ||
{ | ||
if (! $record->isValid()) { | ||
return false; | ||
} | ||
|
||
$data = $record->toArray(); | ||
|
||
if ($record instanceof RecordKeyAggregate) { | ||
$data = [ | ||
'name' => $record->key(), | ||
'email' => \implode(', ', | ||
\array_map(fn (Record $record) => $record->field('email'), $record->records())), | ||
]; | ||
} | ||
|
||
$serializer->append(new UserEloquentModel($data)); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
use RodrigoPedra\LaravelRecordProcessor\Examples\ExamplesCommand; | ||
use RodrigoPedra\LaravelRecordProcessor\ProcessorBuilder; | ||
use RodrigoPedra\RecordProcessor\Configurators\Serializers\SerializerConfigurator; | ||
use RodrigoPedra\RecordProcessor\Stages\DownloadFileOutput; | ||
|
||
$storagePath = __DIR__ . '/../../storage/'; | ||
|
||
$command = new ExamplesCommand(); | ||
|
||
$processor = (new ProcessorBuilder()) | ||
->readFromEloquent($command->makeEloquentBuilder()) | ||
->serializeToExcelFile($storagePath . 'output.xlsx', function (SerializerConfigurator $configurator) { | ||
$configurator->withHeader(['name', 'email']); | ||
}) | ||
->downloadFileOutput('report.xlsx', DownloadFileOutput::DELETE_FILE_AFTER_DOWNLOAD) | ||
->build(); | ||
|
||
$processor->process(); | ||
|
||
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<body> | ||
<a href="download.php">download excel</a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace RodrigoPedra\LaravelRecordProcessor\Configurators\Readers; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use RodrigoPedra\LaravelRecordProcessor\Readers\EloquentReader; | ||
use RodrigoPedra\RecordProcessor\Configurators\Readers\ReaderConfigurator; | ||
|
||
/** | ||
* @property \RodrigoPedra\LaravelRecordProcessor\Readers\EloquentReader $reader | ||
*/ | ||
class EloquentReaderConfigurator extends ReaderConfigurator | ||
{ | ||
public function __construct(EloquentReader $reader) | ||
{ | ||
parent::__construct($reader); | ||
} | ||
|
||
public function builder(): Builder | ||
{ | ||
return $this->reader->builder(); | ||
} | ||
} |
Oops, something went wrong.