-
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.
Update localisation module and Attributes for User Full Name
- Loading branch information
Tomasz Sapletta
committed
Apr 5, 2019
1 parent
9b57249
commit 80c69d5
Showing
5 changed files
with
286 additions
and
0 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,17 @@ | ||
<?php | ||
|
||
namespace Phunc\Attribute; | ||
|
||
|
||
interface FirstNameInterface | ||
{ | ||
/** | ||
* @return mixed | ||
*/ | ||
public function getFirstName(); | ||
|
||
/** | ||
* @param mixed $first_name | ||
*/ | ||
public function setFirstName($first_name); | ||
} |
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,215 @@ | ||
<?php | ||
|
||
namespace Phunc\Attribute; | ||
|
||
|
||
class FullName implements \Phunc\CollectionInstanceInterface, \Phunc\Attribute\FirstNameInterface, \Phunc\Attribute\LastNameInterface, \Phunc\Attribute\FullNameInterface | ||
{ | ||
/** @var string */ | ||
protected $format; | ||
|
||
/** @var string */ | ||
protected $last_name; | ||
|
||
/** @var string */ | ||
protected $first_name; | ||
|
||
/** @var string */ | ||
protected $full_name; | ||
|
||
|
||
/** | ||
* FullName constructor. | ||
* @param string $format | ||
*/ | ||
public function __construct($format = 'txt') | ||
{ | ||
$this->setFormat($format); | ||
$this->reset(); | ||
} | ||
|
||
public function reset() | ||
{ | ||
$this->setFirstName(''); | ||
$this->setLastName(''); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $array | ||
* | ||
* @return $this | ||
*/ | ||
public function fillFromArray(array $array) | ||
{ | ||
$this->setFirstName($array['first_name']); | ||
$this->setLastName($array['last_name']); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param $last_name | ||
* @param $first_name | ||
*/ | ||
public function fill($last_name, $first_name) | ||
{ | ||
$this->setFirstName($last_name); | ||
$this->setLastName($first_name); | ||
} | ||
|
||
/** | ||
* @param $obj | ||
* @return $this | ||
*/ | ||
public function fillFromObject($obj) | ||
{ | ||
$this->setFirstName($obj->first_name); | ||
$this->setLastName($obj->last_name); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function convertToText() | ||
{ | ||
$this->setFullName( | ||
$this->getLastName() . ', ' . $this->getFirstName() | ||
); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function convertToHtml() | ||
{ | ||
$this->setFullName( | ||
'<span class="last_name">' . $this->getLastName() . '</span><span class="first_name">' . $this->getFirstName() . '</span>' | ||
); | ||
|
||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getLastName() | ||
{ | ||
return $this->last_name; | ||
} | ||
|
||
/** | ||
* @param mixed $last_name | ||
* @return FullName | ||
*/ | ||
public function setLastName($last_name) | ||
{ | ||
$this->last_name = $last_name; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getFirstName() | ||
{ | ||
return $this->first_name; | ||
} | ||
|
||
/** | ||
* @param mixed $first_name | ||
* @return FullName | ||
*/ | ||
public function setFirstName($first_name) | ||
{ | ||
$this->first_name = $first_name; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getFullName() | ||
{ | ||
return $this->full_name; | ||
} | ||
|
||
/** | ||
* @param mixed $full_name | ||
* @return FullName | ||
*/ | ||
public function setFullName($full_name) | ||
{ | ||
$this->full_name = $full_name; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function convertByFormat() | ||
{ | ||
if ($this->format === 'txt') { | ||
$this->convertToText(); | ||
} else { | ||
$this->convertToHtml(); | ||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getFormat(): string | ||
{ | ||
return $this->format; | ||
} | ||
|
||
/** | ||
* @param string $format | ||
* @return FullName | ||
*/ | ||
public function setFormat(string $format): FullName | ||
{ | ||
$this->format = $format; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
$getFields = function ($obj) { | ||
return get_object_vars($obj); | ||
}; | ||
return $getFields($this); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
$this->convertByFormat(); | ||
return (string)$this->getFullName(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return $this->toString(); | ||
} | ||
|
||
} |
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 Phunc\Attribute; | ||
|
||
|
||
class FullNameCollection extends \Phunc\Collection implements \Phunc\FillFromArrayInterface | ||
{ | ||
/** @var \Phunc\Attribute\FullNameInterface */ | ||
protected $instance; | ||
|
||
/** | ||
* Default Value | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->setInstance(new \App\Name\FullName()); | ||
} | ||
|
||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace Phunc\Attribute; | ||
|
||
|
||
interface FullNameInterface | ||
{ | ||
/** | ||
* @return mixed | ||
*/ | ||
public function getFullName(); | ||
|
||
/** | ||
* @param mixed $full_name | ||
*/ | ||
public function setFullName($full_name); | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Phunc\Attribute; | ||
|
||
|
||
interface LastNameInterface | ||
{ | ||
/** | ||
* @return mixed | ||
*/ | ||
public function getLastName(); | ||
|
||
/** | ||
* @param mixed $last_name | ||
*/ | ||
public function setLastName($last_name); | ||
|
||
} |