2017 © Pedro Peláez
 

library data-provider

image

xervice/data-provider

  • Thursday, July 26, 2018
  • by mibexx
  • Repository
  • 1 Watchers
  • 1 Stars
  • 607 Installations
  • PHP
  • 16 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 14 Versions
  • 1191 % Grown

The README.md

Scrutinizer Code Quality Code Coverage Build Status, (*1)

Data transfer objects for xervice packages., (*2)

Installation

composer require xervice/data-provider

Configuration

You have to define, where to search for schema files and where to create the DTOs., (*3)



<DataProviders
  xmlns="xervice:dataprovider-01"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="xervice:dataprovider-01 http://static.xervice.online/schema/dataprovider.schema.xsd"
>

    <DataProvider name="KeyValue">
        <DataElement name="Key" type="string"/>
        <DataElement name="Value" type="string"/>
    </DataProvider>
</DataProviders>

Possible data types: * int * string * bool * double (= float) * float * array * object * DataProviderInterface * DataProviderInterface[] * AnyNameOfDataProvider, (*4)

With the type "DataProviderInterface" you can set any DataProvider., (*5)

Default values You can define default values for the following types: * int * float * double * string * bool * array, (*6)

For the type array only an empty array is possible as default. If you want to define an empty string as default for the type string, you have to set the default to ''., (*7)



<DataProviders
  xmlns="xervice:dataprovider-01"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="xervice:dataprovider-01 http://static.xervice.online/schema/dataprovider.schema.xsd"
>

    <DataProvider name="Default">
        <DataElement name="String" default="Text" type="string"/>
        <DataElement name="EmptyText" default="''" type="string"/>
        <DataElement name="Number" default="5" type="int"/>
        <DataElement name="Boolean" default="true" type="bool"/>
        <DataElement name="Float" default="1.5" type="float"/>
        <DataElement name="List" default="[]" type="array"/>
    </DataProvider>

</DataProviders>

Use DTO

    $dataProvider = new DataProvider\KeyValueDataProvider();

    // Set values
    $dataProvider->setKey('keyname');
    $dataProvider->setValue('value');

    // Get values
    $dataProvider->getKey();

    // Isset
    $dataProvider->hasKey();

    // you can also work with arrays
    $dataProvider->fromArray([
        'Key' => 'keyname',
        'Value' => 'value'
    ]);

    // and back to array
    $dataArray = $dataProvider->toArray();


Extend and sharing, (*8)

Multiple schame-files with the same DataProvider name will be merged. Also you can choose another DataProvider as type or collection., (*9)



<DataProviders
  xmlns="xervice:dataprovider-01"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="xervice:dataprovider-01 http://static.xervice.online/schema/dataprovider.schema.xsd"
>

    <DataProvider name="KeyValue">
        <DataElement name="Key" type="string"/>
        <DataElement name="Values" singleton="Value" type="Value[]"/>
    </DataProvider>
</DataProviders>

Using, (*10)

<?php

    $dto = new KeyValue();

    $value = new Value();
    $dto->addValue($value);

    // List
    $dto->setValues(
        [
            $value
        ]
    );

    // Get List
    $dto->getValues();

The Versions

26/07 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Bertram

26/07 2018
26/07 2018
26/07 2018
26/07 2018
26/07 2018
25/07 2018
25/07 2018
25/07 2018
13/07 2018
13/07 2018
09/07 2018
05/07 2018
05/07 2018