Skip to content

Commit

Permalink
Fix README, fix Symfony 4 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
MisatoTremor committed May 22, 2019
1 parent 0bc1831 commit 2337185
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
20 changes: 18 additions & 2 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<?php
return PhpCsFixer\Config::create()
->setRules(['@Symfony' => true, 'array_syntax' => ['syntax' => 'short'], 'ordered_imports' => true])
->setCacheFile(__DIR__.'/.php_cs.cache');
->setRules(
[
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],
'ordered_class_elements' => true,
'phpdoc_order' => true,
'header_comment' => ['header' => "For the full copyright and license information, please view the LICENSE\nfile that was distributed with this source code."],
]
)
->setCacheFile(__DIR__ . '/.php_cs.cache');
53 changes: 25 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,43 @@ This bundle is listed on packagist.

Simply add it to your apps composer.json file

``` js
```json
"avro/csv-bundle": "*"
```

Enable the bundle in the kernel as well as the dependent AvroCaseBundle:
Enable the bundle in config/bundles.php as well as the dependent AvroCaseBundle:

``` php
// config/bundles.php
```php
Avro\CsvBundle\AvroCsvBundle::class => ['all' => true],
Avro\CaseBundle\AvroCaseBundle::class => ['all' => true],
```

Configuration
-------------

Add this required config to your config/packages/avro_csv.yaml file
Add this required config

``` yaml
```yaml
# config/packages/avro_csv.yaml
avro_csv:
db_driver: orm # supports orm
batch_size: 15 # The batch size between flushing & clearing the doctrine object manager
tmp_upload_dir: "%kernel.root_dir%/../web/uploads/tmp/" # The directory to upload the csv files to
sample_count: 5 # The number of sample rows to show during mapping
```
Add routes to your config/routes/avro_csv.yaml file
Add routes to your config
``` yaml
AvroCsvBundle:
```yaml
# config/routes/avro_csv.yaml
avro_csv:
resource: "@AvroCsvBundle/Resources/config/routing.yml"
```
Add the entities/documents you want to implement importing/exporting for
``` yaml
```yaml
# config/packages/avro_csv.yaml
avro_csv:
#
objects: # the entities/documents you want to be able to import/export data with
Expand Down Expand Up @@ -113,7 +115,7 @@ add them to the objects node as mentioned previously.

Then just include a link to specific import page like so:

``` html
```html
<a href="{{ path('avro_csv_import_upload', {'alias': 'client'}) }}">Go to import page</a>
```

Expand All @@ -132,41 +134,37 @@ Want to customize certain fields on each row? No problem.

An event is fired when a row is added that you can tap into to customize each row of data.

Just create a custom listener in your app that listens for the 'avro_csv.row_added' event.
Just create a custom listener in your app that listens for the ``AvroCsvEvents::ROW_ADDED`` event.

For example...

``` php
<?php
namespace Avro\CrmBundle\Listener;

use Symfony\Component\Security\Core\SecurityContextInterface;
```php
namespace App\EventListener;

use Avro\CsvBundle\AvroCsvEvents;
use Doctrine\ORM\EntityManager;
use Symfony\Component\EventDispatcher\Event;
use Avro\CsvBundle\Event\RowAddedEvent;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;

/**
* Csv import listener
*
* @author Joris de Wit <joris[email protected]>
*/
class ImportListener implements EventSubscriberInterface
{
private $em;
private $context;

/**
* @param EntityManager $em The entity manager
* @param EntityManagerInterface $em The entity manager
* @param SecurityContextInterface $context The security context
*/
public function __construct(EntityManager $em, SecurityContextInterface $context)
public function __construct(EntityManagerInterface $em, SecurityContextInterface $context)
{
$this->em = $em;
$this->context = $context;
}

public static function getSubscribedEvents()
{
return [
Expand All @@ -177,9 +175,9 @@ class ImportListener implements EventSubscriberInterface
/**
* Set the objects createdBy field
*
* @param Event $event
* @param RowAddedEvent $event
*/
public function setCreatedBy(Event $event)
public function setCreatedBy(RowAddedEvent $event)
{
$object = $event->getObject();

Expand All @@ -191,7 +189,6 @@ class ImportListener implements EventSubscriberInterface
```

Register your listener or use autowiring
```

Exporting
---------
Expand All @@ -206,7 +203,7 @@ the queryBuilder from the exporter and add your constraints before calling "getC

Ex.

``` php
```php
namespace App\Controller;

use Avro\CsvBundle\Export\ExporterInterface;
Expand Down
8 changes: 4 additions & 4 deletions Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
avro_csv_import_upload:
path: /import/upload/{alias}
defaults: { _controller: AvroCsvBundle:Import:upload }
defaults: { _controller: 'Avro\CsvBundle\Controller\ImportController::uploadAction' }
avro_csv_import_mapping:
path: /import/mapping/{alias}
defaults: { _controller: AvroCsvBundle:Import:mapping }
defaults: { _controller: 'Avro\CsvBundle\Controller\ImportController::mappingAction' }
avro_csv_import_process:
path: /import/process/{alias}
defaults: { _controller: AvroCsvBundle:Import:process }
defaults: { _controller: 'Avro\CsvBundle\Controller\ImportController::processAction' }

avro_csv_export_export:
path: /export/{alias}
defaults: { _controller: AvroCsvBundle:Export:export }
defaults: { _controller: 'Avro\CsvBundle\Controller\ExportController::exportAction' }

0 comments on commit 2337185

Please sign in to comment.