-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCp.php
More file actions
71 lines (57 loc) · 1.24 KB
/
Copy pathCp.php
File metadata and controls
71 lines (57 loc) · 1.24 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Mv\Cp;
use Mv\Cp\Converter\DateNumero;
use Mv\Cp\Content\Mag;
/**
* Author: Michaël VEROUX
* Date: 12/07/15
* Time: 09:42
*/
class Cp
{
/**
* @var string|null
*/
private $lastNumero;
/**
* @var Mag
*/
private $mag;
/**
* Cp constructor.
*/
public function __construct($id = 0, $numero = null)
{
$this->mag = new Mag();
$this->mag->setId($id);
if(null === $numero) {
$numero = $this->lastNumero();
}
$this->mag->setNumero($numero);
}
static function numeroValide($numero)
{
if(10 > (int) $numero) {
$numero = sprintf('0%s', $numero);
}
$contentDirectory = sprintf(CONTENU_DIR_PATTERN, $numero);
if(!is_dir($contentDirectory)) {
static::numeroValide((int) $numero--);
}
return (string) $numero;
}
public function lastNumero()
{
if(null === $this->lastNumero) {
$this->lastNumero = static::numeroValide(DateNumero::createFromDate(new \DateTime())->number());
}
return $this->lastNumero;
}
/**
* @return Mag
*/
public function getMag()
{
return $this->mag;
}
}