1. Go to this page and download the library: Download maer/entity library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$website = new Website($dataset, function (array &$params) {
if (isset($params['url']) && strpos($params['url'], 'http://') !== 0) {
// We got a parameter called url that doesn't start with http://
$params['url'] = 'http://' . $params['url'];
}
});
$website = Website::make($dataset, null, function (array &$params) {
// ... Modifie the values like the above example
});
class Website extends Maer\Entity\Entity
{
protected $title = '';
protected $url = '';
protected function modifier(array $params)
{
if (isset($params['url']) && strpos($params['url'], 'http://') !== 0) {
// We got a parameter called url that doesn't start with http://
$params['url'] = 'http://' . $params['url'];
}
}
}
$dataset = [
'title' => 'Google',
'url' => 'www.google.com',
];
$website = new Website($dataset);
// Or
$website = Website::make($dataset);
echo $website->url;
// Returns: "http://www.google.com"
if ($hero->has('name')) {
// Yes, it exists and can be used
} else {
// No, doesn't exist. Try to get/set it, an exception will be thrown
}
// New data
$data = [
'name' => 'Batman',
...
];
$entity->replace($data);
// $entity->name now has the value "batman"
// New data
$data = [
'name' => 'Batman',
...
];
$entity->replace($data, function (array $params) {
// Modify the data
});
// $entity->name now has the value "batman"
$entity->reset();
$entity->resetProperty('nameOfTheProperty');
class Hero extends Maer\Entity\Entity
{
protected $name = '';
public function myNewHelper()
{
// Do stuff...
}
}
echo $collection->count();
// same as count($collection)
$firstElement = $collection->first();
// $firstElement now contains the first entity in the collection
$firstElement = $collection->last();
// $firstElement now contains the last entity in the collection
$names = $collection->list('username');
// Will give you something like:
// [
// 'firstUsername',
// 'secondUsername',
// 'thirdUsername',
// ...
// ]
$names = $collection->list('username', 'id');
// Will give you something like:
// [
// 1337 => 'firstUsername',
// 1234 => 'secondUsername',
// 555 => thirdUsername',
// ...
// ]
class Foo extends Maer\Entity\Entity
{
protected $created = '2019-06-10 13:37:00';
// Include the trait
use Maer\Entity\Traits\DateTimeTrait;
}
$foo = new Foo();
// First argument is the property to use
echo $foo->date('created');
// Returns: June 10, 2019
// The second argument is the datetime format (standard PHP-date formats)
echo $foo->date('created', 'Y-m-d');
// Returns: 2019-06-10
// If you want to use a specific timezone, pass it as a third argument
echo $foo->date('created', 'Y-m-d', 'Europe/Stockholm');
// First argument is the propety to use
$date = $foo->dateTime('created');
// Returns an instance of DateTime
// If you want to use a specific timezone, pass it as a second argument
$date = $foo->dateTime('created', 'Europe/Stockholm');
// First argument is the propety to use
$timestamp = $foo->timestamp('created');
// Returns: 1560166620
// If you want to use a specific timezone, pass it as a second argument
$timestamp = $foo->timestamp('created');
class Foo extends Maer\Entity\Entity
{
protected $content = 'Here be some lorem ipsum text';
// Include the trait
use Maer\Entity\Traits\TextTrait;
}
$foo = new Foo();
$maxLength = 20;
$suffix = '...';
echo $foo->excerpt('content', $maxLength, $suffix);
// Returns: Here be some...
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.