2017 © Pedro Peláez
 

symfony-bundle data-sourcery-bundle

Netdudes DataSourceryBundle

image

netdudes/data-sourcery-bundle

Netdudes DataSourceryBundle

  • Monday, June 12, 2017
  • by yakobe
  • Repository
  • 5 Watchers
  • 2 Stars
  • 7,184 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

****** WARNING: THIS PROJECT IS NO LONGER MAINTAINED!! ******

Netdudes\DataSourceryBundle

Build Status Code Climate SensioLabsInsight Scrutinizer Code Quality, (*1)

Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

DataSourceryBundle is a neat tool to handle building and performing complex queries on data sets, including support for natural-language queries and safe handling of user provided query parameters., (*3)

Usage (work in progress!)

Assume we have one entity in our system managed by Doctrine, called User, that looks like this:, (*4)

User {
    string username
    string nameFirst
    string nameLast
    \DateTime registered
    User bestFriend => OtM with another user
    User worstEnemy => OtM with another user
}

You can get the building block of the library, the DataSource, from a builder. From here and now on we will assume you have a DI container (e.g. Symfony) where the needed services are registered., (*5)

$dataSourceBuilder = $container
    ->get('netdudes_data_sourcery.data_source.factory')
    ->createBuilder('My\Entities\User');

With a builder is easy to create a Datasource, (*6)

$dataSourceBuilder
    ->addField('username', 'string', 'username')
    ->addField('bestFriendUsername' 'string', 'bestFriend.username')
    ->addField('worstEnemyUsername', 'string', 'worstEnemy.username')
    ->addField('friendOfMyEnemyUsername', 'string', 'worstEnemy.bestFriend.username')
    ->addField('registered', 'date', 'registered');

$dataSource = $dataSourceBuilder->build();

Alternatively, a data source can be generated from a configuration class, very similarly to how Symfony Forms are built., (*7)

class MyNiceDataSourceConfig implements DataSourceConfigurationInterface
{

    public function getEntityClass()
    {
        return 'My\Entities\User';
    }

    public function buildDataSource(DataSourceBuilderInterface $builder)
    {
        $builder
            ->addField('username', 'string', 'username')
            ->addField('bestFriendUsername', 'string', 'bestFriend.username')
            ->addField('worstEnemyUsername', 'string', 'worstEnemy.username')
            ->addField('friendOfMyEnemyUsername', 'string', 'worstEnemy.bestFriend.username')
            ->addField('registered', 'date', 'registered');
    }
}

$dataSource = $container
    ->get('netdudes_data_sourcery.data_source.factory')
    ->createFromConfiguration(new MyNiceDataSourceConfig());

In order to query you data source, you must have a Query object. Creating one manually is easy:, (*8)

$query = new Query();
$query->setSelect(['username', 'bestFriendUsername', 'worstEnemyUsername', 'friendOfMyEnemyUsername', 'registered']);

$filter = new Filter(
    [
        new FilterCondition('username', FilterCondition::METHOD_STRING_EQ, 'admin')
    ]
);

$query->setFilter($filter);

Alternatively you can use the built in parser for the system's language, UQL:, (*9)

$uqlInterpreter = $container->get('netdudes_data_sourcery.uql.interpreter.factory')->create($dataSource);
$filter = $uqlInterpreter->generateFilters('username != "admin"');

$query->setFilter($filter);

Finally, you can get your data from the data source, (*10)

$data = $dataSource->getData($query);

dump($data);

Giving, (*11)

array:1 [
  0 => array:5 [
    "username" => "admin"
    "bestFriendUsername" => "Max"
    "worstEnemyUsername" => "John"
    "friendOfMyEnemyUsername" => "Max"
    "registered" => DateTime {#124
      +"date": "2014-02-01 00:00:00.000000"
      +"timezone_type": 3
      +"timezone": "Europe/Berlin"
    }
  ]
]

The Versions

12/06 2017
13/10 2016

dev-feature/comparing-against-null-value-using-is-method

dev-feature/comparing-against-null-value-using-is-method https://github.com/netdudes/DataSourceryBundle

Netdudes DataSourceryBundle

  Sources   Download

MIT

The Requires

 

The Development Requires

data sourcery

06/10 2016

dev-feature/is-null-uql-operators

dev-feature/is-null-uql-operators https://github.com/netdudes/DataSourceryBundle

Netdudes DataSourceryBundle

  Sources   Download

MIT

The Requires

 

The Development Requires

data sourcery

31/05 2016

dev-feature/data-type-operator-support-fixes

dev-feature/data-type-operator-support-fixes https://github.com/netdudes/DataSourceryBundle

Netdudes DataSourceryBundle

  Sources   Download

MIT

The Requires

 

The Development Requires

data sourcery