![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Soon/DataSync/Model/Transfer/Type/ |
<?php /** * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @author Hervé Guétin <[email protected]> <@herveguetin> * @copyright Copyright (c) 2017 Agence Soon (http://www.agence-soon.fr) */ namespace Soon\DataSync\Model\Transfer\Type; use Soon\DataSync\Model\Config; use Soon\DataSync\Model\Data\Type\DataTypeInterface; use Soon\DataSync\Model\Job\JobInterface; abstract class TransferTypeAbstract extends \StdClass implements TransferTypeInterface { const BASE_DIR_DIRECTIVE = '~'; /** * @var JobInterface */ public $job; /** * @var string */ public $filepath = self::BASE_DIR_DIRECTIVE . '/var/soon_datasync/data'; public function configure(array $config) { Config::populate($this, $config); } /** * @return string */ public function code(): string { return Config::code($this); } /** * @param string $path * @return array */ protected function splitPath(string $path): array { $this->filepath = $path; $dirArr = explode('/', $this->filepath()); $file = end($dirArr); array_pop($dirArr); $dir = implode('/', $dirArr); return [$file, $dir]; } /** * @return string */ public function filepath() { if (strpos($this->filepath, self::BASE_DIR_DIRECTIVE) !== false) { return sprintf('%s%s', $this->parseFilepath(), $this->ext()); } return sprintf('%s%s', $this->filepath, $this->ext()); } /** * @return string */ abstract protected function parseFilepath(): string; /** * @return string */ protected function ext() { /** @var DataTypeInterface $dataType */ $dataType = $this->job->which('dataType'); // If there is no datatype defined or // if the filepath already has an extension (thus has a dot) if (is_null($dataType) || strpos($this->filepath, '.') !== false) { return ''; } return '.' . $dataType->code(); } /** * @param string $subject * @param string $pattern * @return bool */ protected function match(string $subject, string $pattern) { $filterValueRegex = str_replace('*', '(.*?)', $pattern); return (bool)preg_match("/^{$filterValueRegex}\$/i", $subject); } }