-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 1.0.7 - Added camelCase and case-insensitive camelCase
- Loading branch information
Showing
9 changed files
with
215 additions
and
3 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 |
---|---|---|
|
@@ -70,9 +70,13 @@ public function fromArray($data) | |
|
||
if (method_exists($this, 'set' . ucfirst(strtolower($key)))) { | ||
call_user_func_array([$this, 'set' . ucfirst(strtolower($key))], ['data' => $value]); | ||
} else if (property_exists($this, strtolower($key))) { | ||
} else if (method_exists($this, 'set' . $this->snakeToCamel($key))) { | ||
call_user_func_array([$this, 'set' . $this->snakeToCamel($key)], ['data' => $value]); | ||
} | ||
else if (property_exists($this, strtolower($key))) { | ||
$this->{strtolower($key)} = $value; | ||
} else if (property_exists($this, $key)) { | ||
} | ||
else if (property_exists($this, $key)) { | ||
$this->{$key} = $value; | ||
} | ||
} | ||
|
@@ -96,6 +100,17 @@ public function toJson(array $configuration = []) | |
return json_encode($this->toArray()); | ||
} | ||
|
||
/** | ||
* @param $input | ||
* @return string | ||
* @author George van Engers <[email protected]> | ||
* @since 18-10-2023 | ||
*/ | ||
private function snakeToCamel($input) | ||
{ | ||
return ucfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $input)))); | ||
} | ||
|
||
/** | ||
* @param $configuration | ||
* @param $key | ||
|
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,10 @@ | ||
<?php | ||
|
||
namespace Vanengers\PhpJsonObjectLibrary\Tests\Mocks; | ||
|
||
use Vanengers\PhpJsonObjectLibrary\PhpJsonObject; | ||
|
||
class TestCamelObject extends PhpJsonObject | ||
{ | ||
public $camel_test; | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Vanengers\PhpJsonObjectLibrary\Tests\Mocks; | ||
|
||
use Vanengers\PhpJsonObjectLibrary\PhpJsonObject; | ||
|
||
class TestCamelSetterObject extends PhpJsonObject | ||
{ | ||
public $camel_test; | ||
|
||
public $camel_test_double; | ||
public $camel_test_double_triple; | ||
|
||
public function setCamelTest($data) | ||
{ | ||
$this->camel_test = get_class($this).$data; | ||
} | ||
|
||
/** | ||
* @param mixed $camel_test_double | ||
*/ | ||
public function setCamelTestDouble($data): void | ||
{ | ||
$this->camel_test_double = get_class($this).$data; | ||
} | ||
|
||
/** | ||
* @param mixed $camel_test_double_triple | ||
*/ | ||
public function setCamelTestDoubleTriple($data): void | ||
{ | ||
$this->camel_test_double_triple = get_class($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,19 @@ | ||
<?php | ||
|
||
namespace Vanengers\PhpJsonObjectLibrary\Tests\Mocks; | ||
|
||
use Vanengers\PhpJsonObjectLibrary\PhpJsonObject; | ||
|
||
class TestCaseInsensitiveSetter extends PhpJsonObject | ||
{ | ||
public $createdAt; | ||
public $ThisHasSomeCaseInsentiveFields; | ||
|
||
/** | ||
* @param mixed $ThisHasSomeCaseInsentiveFields | ||
*/ | ||
public function setThisHasSomeCaseInsentiveFields($data): void | ||
{ | ||
$this->ThisHasSomeCaseInsentiveFields = get_class($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,21 @@ | ||
<?php | ||
|
||
namespace Vanengers\PhpJsonObjectLibrary\Tests\Mocks; | ||
|
||
use Vanengers\PhpJsonObjectLibrary\PhpJsonObject; | ||
|
||
class TestCaseInsensitiveSetterCamelCase extends PhpJsonObject | ||
{ | ||
public $createdAt; | ||
public $ThisHas_SomeCase_InsentiveFields; | ||
|
||
/** | ||
* @param mixed $ThisHas_SomeCase_InsentiveFields | ||
*/ | ||
public function setThisHasSomeCaseInsentiveFields($data): void | ||
{ | ||
$this->ThisHas_SomeCase_InsentiveFields = get_class($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
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
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
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