-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseConvert.php
More file actions
40 lines (34 loc) · 1.15 KB
/
Copy pathBaseConvert.php
File metadata and controls
40 lines (34 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
* Data Mapper (https://github.com/mozahran/data-mapper)
* Copyright 2021, Mohamed Zahran. (https://www.linkedin.com/in/mo-zahran/)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Mohamed Zahran (https://www.linkedin.com/in/mo-zahran/)
* @link https://github.com/mozahran/data-mapper
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace Zahran\Mapper\Mutator;
use Zahran\Mapper\Contract\Mutator as MutatorInterface;
use Zahran\Mapper\Model\Mutator;
class BaseConvert implements MutatorInterface
{
/**
* @var Mutator
*/
protected $model;
protected $defaultToBase = 10;
public function setModel(Mutator $model): MutatorInterface
{
$this->model = $model;
return $this;
}
public function apply($originalValue, array $arguments = [])
{
$fromBase = (int) $arguments[0];
$toBase = ( isset($arguments[1]) && (int) $arguments[1] > 0 ) ? (int) $arguments[1]:$this->defaultToBase;
return base_convert($originalValue,$fromBase,$toBase);
}
}