1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Polyfill\Intl\Icu\DateFormat;
13
14/**
15 * Parser and formatter for date formats.
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 *
19 * @internal
20 */
21abstract class Transformer
22{
23    /**
24     * Format a value using a configured DateTime as date/time source.
25     *
26     * @param \DateTime $dateTime A DateTime object to be used to generate the formatted value
27     * @param int       $length   The formatted value string length
28     *
29     * @return string The formatted value
30     */
31    abstract public function format(\DateTime $dateTime, int $length): string;
32
33    /**
34     * Returns a reverse matching regular expression of a string generated by format().
35     *
36     * @param int $length The length of the value to be reverse matched
37     *
38     * @return string The reverse matching regular expression
39     */
40    abstract public function getReverseMatchingRegExp(int $length): string;
41
42    /**
43     * Extract date options from a matched value returned by the processing of the reverse matching
44     * regular expression.
45     *
46     * @param string $matched The matched value
47     * @param int    $length  The length of the Transformer pattern string
48     *
49     * @return array An associative array
50     */
51    abstract public function extractDateOptions(string $matched, int $length): array;
52
53    /**
54     * Pad a string with zeros to the left.
55     *
56     * @param string $value  The string to be padded
57     * @param int    $length The length to pad
58     *
59     * @return string The padded string
60     */
61    protected function padLeft(string $value, int $length): string
62    {
63        return str_pad($value, $length, '0', \STR_PAD_LEFT);
64    }
65}
66