-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf33fc0
commit 37f769c
Showing
37 changed files
with
2,031 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\CustomField; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
|
||
abstract class Metadata implements \Serializable, Arrayable | ||
{ | ||
protected $data; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$this->set($data); | ||
} | ||
|
||
public function serialize() | ||
{ | ||
return serialize($this->data); | ||
} | ||
|
||
public function unserialize($data) | ||
{ | ||
$this->data = unserialize($data); | ||
} | ||
|
||
public function get() | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function set(array $data) | ||
{ | ||
$this->data = $data; | ||
} | ||
|
||
public function toArray() | ||
{ | ||
return $this->data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace App\CustomField; | ||
|
||
interface MetadataValidationInterface | ||
{ | ||
public function validate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\CustomField; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
|
||
class Payload implements PayloadContract, \Serializable, Arrayable | ||
{ | ||
protected $data; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$this->set($data); | ||
} | ||
|
||
public function get() | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function set(array $data) | ||
{ | ||
$this->data = $data; | ||
|
||
return $this; | ||
} | ||
|
||
public function serialize() | ||
{ | ||
return serialize($this->data); | ||
} | ||
|
||
public function unserialize($data) | ||
{ | ||
$this->data = unserialize($data); | ||
} | ||
|
||
public function toArray() | ||
{ | ||
return $this->data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace App\CustomField; | ||
|
||
interface PayloadContract | ||
{ | ||
public function get(); | ||
public function set(array $payload); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\CustomField; | ||
|
||
use App\CustomField\Metadata; | ||
|
||
class RadioButtonMetadata extends Metadata implements MetadataValidationInterface | ||
{ | ||
public function validate() | ||
{ | ||
/** | ||
* TODO: to be implemented | ||
*/ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\CustomField; | ||
|
||
use App\CustomField\Metadata; | ||
|
||
class TextMetadata extends Metadata implements MetadataValidationInterface | ||
{ | ||
public function validate() | ||
{ | ||
/** | ||
* TODO: to be implemented | ||
*/ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace App\CustomField; | ||
|
||
class TypeMapping | ||
{ | ||
private static $typeStrToIntMapping; | ||
private static $typeIntToStrMapping; | ||
|
||
public static function strToInt($key) | ||
{ | ||
self::mappingType(); | ||
|
||
if (isset(self::$typeStrToIntMapping[$key]['number'])) { | ||
return self::$typeStrToIntMapping[$key]['number']; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static function strToMetadataClass($key) | ||
{ | ||
self::mappingType(); | ||
|
||
if (isset(self::$typeStrToIntMapping[$key]['metadata'])) { | ||
return self::$typeStrToIntMapping[$key]['metadata']; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static function intToStr($key) | ||
{ | ||
self::mappingType(); | ||
|
||
if (isset(self::$typeIntToStrMapping[$key]['type'])) { | ||
return self::$typeIntToStrMapping[$key]['type']; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static function intToClass($key) | ||
{ | ||
self::mappingType(); | ||
|
||
if (isset(self::$typeIntToStrMapping[$key]['class'])) { | ||
return self::$typeIntToStrMapping[$key]['class']; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected static function mappingType() | ||
{ | ||
if (isset(static::$typeStrToIntMapping) && isset(static::$typeIntToStrMapping)) { | ||
return; | ||
} | ||
|
||
/** | ||
* TODO: Check the configuration string exists | ||
*/ | ||
$customFieldTypeConfig = config('constants.custom_field_type'); | ||
static::$typeStrToIntMapping = $customFieldTypeConfig; | ||
static::$typeIntToStrMapping = self::reverseMapping($customFieldTypeConfig, 'type', 'number'); | ||
} | ||
|
||
private static function reverseMapping($value, $originKeyName, $needleReversedKeyName) | ||
{ | ||
$collection = collect($value); | ||
$reversed = []; | ||
$collection->each(function ($item, $key) use (&$reversed, $originKeyName, $needleReversedKeyName) { | ||
$mappingValue = []; | ||
$mappingKeyName = $item[$needleReversedKeyName]; | ||
|
||
unset($item[$needleReversedKeyName]); | ||
|
||
$mappingValue[$originKeyName] = $key; | ||
|
||
foreach ($item as $itemKey => $itemValue) { | ||
$mappingValue[$itemKey] = $itemValue; | ||
} | ||
|
||
$reversed[$mappingKeyName] = $mappingValue; | ||
}); | ||
|
||
return $reversed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.