1. Go to this page and download the library: Download dandjo/object-adapter 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/ */
dandjo / object-adapter example snippets
$targetObject = new \stdClass();
$targetObject->foo = 'bar';
$myAdapter = new \Dandjo\ObjectAdapter\ObjectAdapter($targetObject);
echo $myAdapter->foo; // 'bar'
class MyAdapter extends \Dandjo\ObjectAdapter\ObjectAdapter {
/**
* @property\getter myFoo
*/
public function getMyFoo(): string
{
return $this->targetObject->foo;
}
}
$targetObject = new \stdClass();
$targetObject->foo = 'bar';
$myAdapter = new MyAdapter($targetObject);
echo $myAdapter->myFoo; // 'bar'
echo $targetObject->foo; // 'bar'
class MyAdapter extends \Dandjo\ObjectAdapter\ObjectAdapter {
/**
* @property\setter myFoo
*/
public function setMyFoo($value): \Dandjo\ObjectAdapter\ObjectAdapter
{
$this->targetObject->foo = $value;
}
}
$targetObject = new \stdClass();
$targetObject->foo = 'bar';
$myAdapter = new MyAdapter($targetObject);
echo $myAdapter->myFoo; // 'bar'
$myAdapter->myFoo = 'baz';
echo $myAdapter->myFoo; // 'baz'
echo $targetObject->foo; // 'baz'
class MyChildAdapter extends \Dandjo\ObjectAdapter\ObjectAdapter {
/**
* @property\getter myFoo
*/
public function getMyFoo(): string
{
return $this->targetObject->foo;
}
}
class MyAdapter extends \Dandjo\ObjectAdapter\ObjectAdapter {
/**
* @property\getter myChild
*/
public function getMyChild(): string
{
return new MyChildAdapter($this->targetObject->child);
}
}
$targetObject = new \stdClass();
$targetObject->child = new \stdClass();
$targetObject->child->foo = 'bar';
$myAdapter = new MyAdapter($targetObject);
echo $myAdapter->myChild->myFoo; // 'bar'
class MyAdapter extends \Dandjo\ObjectAdapter\ObjectAdapter {
/**
* @property\getter myFoo
*/
public function getMyFoo(): string
{
return $this->targetObject->foo;
}
}
$targetObject = new \stdClass();
$targetObject->foo = 'bar';
$myAdapter = new MyAdapter($targetObject);
echo $myAdapter['foo']; // 'bar'
echo $myAdapter['myFoo']; // 'bar'
foreach ($myAdapter as $propertyName => $propertyValue) {
echo "$propertyName: $propertyValue"; // myFoo: bar
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.