Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Object Converter Bundle Laravel Package

baudev/php-object-converter-bundle

View on GitHub
Deep Wiki
Context7

PHPObjectConverterBundle

GitHub release PHP MINIMUM VERSION LICENSE

This Symfony bundle converts PHP objects into ones of different languages.

Installation

Download the Bundle

composer require baudev/php-object-converter-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Enable the Bundle

  • If you're using Flex:

The bundle is automatically enabled :tada:

  • If you're not using Flex:

You must add the bundle to your kernel:

// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new Baudev\PHPObjectConverterBundle\PHPObjectConverterBundle(),
        ];

        // ...
    }

    // ...
}

How to use this Bundle?

Use the following command to convert your PHP classes:

bin/console converter:generate converter source [output]

The command parameters are the following ones:

Parameter Details
converter (required) Name of a converter. E.g. typescript. See available converters.
source (required) The directory containing classes to scan.
output (optional) The output directory for generated classes.

Available Converters

Name Converter file
typescript Entity/converters/TypeScriptConverter.php
More soon! ...

You can create your own converter as explained here.

Demo

This example uses the typescript converter. It is the result of the follwing command bin/console converter:generate typescript src build.

Input class:

// src/Entity/Person.php
class Person extends \App\Kernel
{
    /**
     * @var iterable
     */
    public static $firstName;
    /**
     * @var string
     */
    protected $lastName;
    /**
     * @var int
     */
    private $age;
}

Output class:

// build/Person.ts
class Person extends Kernel 
{

    public static firstName:any;

    protected lastName:string;

    private age:number;

}

Settings

Create file config/packages/php_object_converter.yaml and define:

php_object_converter:
    enable_annotation: true # Enables @Converter annotation. See below.
    ignore_annotation: true # Enables @ConverterIgnore. See below.
    attributes:
        add_private: true # Converts private attributes. Ignore them if false.
        add_protected: true # Converts protected attributes. Ignore them if false.
  • If enable_annotation is true, then only classes with the annotation @Converter will be converted.

  • If disable_annotation is true, then classes with @ConverterIgnore will be ignored.

TODO

  • Write tests.
  • Support interfaces and methods conversion.
  • Add more converters.

Credits

LICENSE

MIT License  
  
Copyright (c) 2019 Baudev
  
Permission is hereby granted, free of charge, to any person obtaining a copy  
of this software and associated documentation files (the "Software"), to deal  
in the Software without restriction, including without limitation the rights  
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
copies of the Software, and to permit persons to whom the Software is  
furnished to do so, subject to the following conditions:  
  
The above copyright notice and this permission notice shall be included in all  
copies or substantial portions of the Software.  
  
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  
SOFTWARE.  
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle