Giter VIP home page Giter VIP logo

php-data's Introduction

EventEngine\Data

Build Status Coverage Status

Generate Immutable Objects with ease!

Value Object Template vo_string

Installation

composer require event-engine/php-data

Versions

  • 1.x uses method return type hints to detect ImmutableRecord property types
    • Use this version in PHP 7.2 - PHP 7.3 environments
  • 2.x makes use of PHP 7.4 property type hints
    • Use this version in >= PHP 7.4 environments

PHPStorm Templates

The EventEngine\Data package contains a set of live templates specifically designed to work together with the EventEngine\Data\ImmutableRecord.

You can import the templates by following official PHPStorm instructions.

Please find the settings.zip here.

Usage

Usage is described in the documentation

php-data's People

Contributors

arnedesmedt avatar codeliner avatar jsor avatar sandrokeil avatar zluiten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

php-data's Issues

Add support for DateTimeInterface

When using a DateTimeInterface property we get:

Cannot convert property dateTimeProperty to its native counterpart. Missing to{nativeType}() method in the type class DateTimeInterface.

Immutable record as response for soap call

Hi, for an old API, I need to send and retrieve data by SOAP.

And I want to retrieve my data in an Immutable record.
It's possible via https://www.php.net/manual/en/soapclient.soapcall.php

$decoded = $this->client->__soapCall($method, $arguments)

Via this call the decoded variable contains my immutable record filled with data (It can magically be filled by the soap extension I think), But it hasn't been created by the fromArray method, so no propTypeMap is set, and this will cause some troubles if the toArray function will be called.

There are some solutions:

  • Create the immutable record for the response before the request with some data, so the propTypeMap is set. But I think, this is a bit overkill.

  • Check if the propTypeMap is set in the toArray function. But this is not necessary for all immutable records that are generated with the fromArray (and not with some magical soap shit)
    So I don't prefer that either.

  • Make the buildPropTypeMap static function public. I think this is the best solution. So I could first build that propTypeMap before doing the request.

What do you think?

If we have come to a solution, I will make a Merge request.

Thx in advance,
Arne

And btw, I have never mentioned it before: but thx for the great event-engine libraries! They are just awesome!

Use method return type as fallback in 2.x

@arnedesmedt I had to change your PHP 7.4 implementation a bit, due to ReflectionType::__toString() being deprecated. See #6
I also added the exception back. Now it's thrown when the property has no type hint. However, we could also use the old logic (method return type) as a fallback in case no property type hint is given.
This would ease the migration path from 1.x to 2.x because you don't have to change all your ImmutableRecords at once. What do you think? Can you provide a PR for it and maybe also add some test cases?

Allow value objects in fromArray

With a small change it would be possible to support value objects in fromArray factory method.

This line in ImmutableRecordLogic needs to be changed to:

$recordData[$key] = $this->fromType($this->voTypeToNative($val, $key, $type), $type);

  • Check if it works like expected
  • Add unit tests for it
  • Add doc block comments to fromArray and fromRecordData to explain difference *

*) Difference: fromRecordData avoids mapping values to native data and back to VO. So it is more performant. On the other hand, fromArray can be used as a universal factory, which makes handling much simpler.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.