AddressType
This commit is contained in:
parent
b24139113d
commit
0fa64aecd7
57
src/Contracts/SolidityType.php
Normal file
57
src/Contracts/SolidityType.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of web3.php package.
|
||||||
|
*
|
||||||
|
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
|
||||||
|
*
|
||||||
|
* @author Peter Lai <alk03073135@gmail.com>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Web3\Contracts;
|
||||||
|
|
||||||
|
class SolidityType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* construct
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function __get($name)
|
||||||
|
{
|
||||||
|
$method = 'get' . ucfirst($name);
|
||||||
|
|
||||||
|
if (method_exists($this, $method)) {
|
||||||
|
return call_user_func_array([$this, $method], []);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param mixed $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function __set($name, $value)
|
||||||
|
{
|
||||||
|
$method = 'set' . ucfirst($name);
|
||||||
|
|
||||||
|
if (method_exists($this, $method)) {
|
||||||
|
return call_user_func_array([$this, $method], [$value]);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
49
src/Contracts/Types/Address.php
Normal file
49
src/Contracts/Types/Address.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of web3.php package.
|
||||||
|
*
|
||||||
|
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
|
||||||
|
*
|
||||||
|
* @author Peter Lai <alk03073135@gmail.com>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Web3\Contracts\Types;
|
||||||
|
|
||||||
|
use Web3\Contracts\SolidityType;
|
||||||
|
use Web3\Contracts\Types\IType;
|
||||||
|
|
||||||
|
class Address extends SolidityType implements IType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* construct
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isType
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isType($name)
|
||||||
|
{
|
||||||
|
return (preg_match('/address(\[([0-9]+)\])?/', $name) === 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isDynamicType
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isDynamicType()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
30
src/Contracts/Types/IType.php
Normal file
30
src/Contracts/Types/IType.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of web3.php package.
|
||||||
|
*
|
||||||
|
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
|
||||||
|
*
|
||||||
|
* @author Peter Lai <alk03073135@gmail.com>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Web3\Contracts\Types;
|
||||||
|
|
||||||
|
interface IType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* isType
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isType($name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isDynamicType
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isDynamicType();
|
||||||
|
}
|
69
test/unit/AddressTypeTest.php
Normal file
69
test/unit/AddressTypeTest.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use Test\TestCase;
|
||||||
|
use Web3\Contracts\Types\Address;
|
||||||
|
|
||||||
|
class AddressTypeTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* testTypes
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $testTypes = [
|
||||||
|
[
|
||||||
|
'value' => 'address',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'address[]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'address[4]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'address[][]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'address[3][]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'address[][6][]',
|
||||||
|
'result' => true
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* solidityType
|
||||||
|
*
|
||||||
|
* @var \Web3\Contracts\SolidityType
|
||||||
|
*/
|
||||||
|
protected $solidityType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setUp
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->solidityType = new Address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testIsType
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testIsType()
|
||||||
|
{
|
||||||
|
$solidityType = $this->solidityType;
|
||||||
|
|
||||||
|
foreach ($this->testTypes as $type) {
|
||||||
|
$this->assertEquals($solidityType->isType($type['value']), $type['result']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user