Skip to content

SaraivaDaniel/phpstring

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP String

Travis Latest Stable Version Total Downloads Latest Unstable Version MIT license

Create objects filling attribute classes with string data (fork of jansenfelipe/phpstring)

How to use

Add library

$ composer require saraivadaniel/phpstring

Add autoload.php in your file:

require_once 'vendor/autoload.php';  

Add annotations

<?php

class Event
{
    /**
     * @Text(sequence=1, size=20)
     */
    public $name;

    /**
     * @Date(sequence=2, size=8, format="Ymd")
     */
    public $date;

    /**
     * @Numeric(sequence=3, size=6, decimals=2, decimal_separator="")
     */
    public $price;

    /**
     * @Text(sequence=4, size=100)
     */
    public $description;

}

String -> Object

$parser = new PHPString(Event::class);
$event = $parser->toObject("BH Bike Show        20160621002000Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce consequat augue at hendrerit posuere.");

echo $parser->getSize(); //output: 134

String <- Object

$parser = new PHPString(Event::class);

$event = new Event();
$event->name = 'Motocross Adventure';
$event->description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce consequat augue at hendrerit posuere.';
$event->date = Carbon::createFromFormat('Y-m-d', '2016-06-21');
$event->price = 1200.98;

$string = $parser->toString($event);

License

The MIT License (MIT)

About

Create objects filling attribute classes with string data

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%