This commit is contained in:
Philipp Dieter 2021-11-23 00:00:58 +01:00
commit 0e0e351b0f
9 changed files with 145 additions and 10 deletions

View File

@ -88,7 +88,7 @@ trait DependencyInjectionTrait
); );
$frameworkConfiguration = $this->configurationManager->getConfiguration( $frameworkConfiguration = $this->configurationManager->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
$this->getExtensionKey() str_replace('_', '', $this->getExtensionKey())
); );
$this->configurationManager->setConfiguration( $this->configurationManager->setConfiguration(
$frameworkConfiguration $frameworkConfiguration

View File

@ -16,6 +16,7 @@ use \Opis\JsonSchema\{
Validator, ValidationResult, ValidationError, Schema Validator, ValidationResult, ValidationError, Schema
}; };
use Cjel\TemplatesAide\Utility\ArrayUtility; use Cjel\TemplatesAide\Utility\ArrayUtility;
use Sarhan\Flatten\Flatten;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/** /**
@ -39,6 +40,78 @@ trait ValidationTrait
*/ */
protected $errorLabels = []; protected $errorLabels = [];
/**
* validate objects
*
* @param $input
* @param schema
* @return void
*/
protected function convertInputBySchema($input, $schema)
{
$flatten = new Flatten();
$schemaFlat = $flatten->flattenToArray($schema);
$typesList = [];
$formatsList = [];
foreach ($schemaFlat as $index => $row) {
$dataIndex = preg_replace(
'/(\.)(properties\.|items\.)/',
'$1',
$index
);
$dataIndex = preg_replace(
'/^properties\./',
'',
$dataIndex
);
$dataIndex = preg_replace(
'/\.(type|format)$/',
'',
$dataIndex
);
if (substr($index, -5) == '.type') {
$typesList[$dataIndex] = $row;
}
if (substr($index, -7) == '.format') {
$formatsList[$dataIndex] = $row;
}
}
foreach ($input as $index => $row) {
$rowType = $typesList[$index];
$formatType = $formatsList[$index];
if (!$rowType) {
continue;
}
switch ($rowType) {
case 'integer':
if (is_numeric($row)) {
settype($input[$index], $rowType);
}
break;
case 'boolean':
$testResult = filter_var(
$row,
FILTER_VALIDATE_BOOLEAN,
[FILTER_NULL_ON_FAILURE]
);
if ($testResult === true || $testResult === false) {
$input[$index] = $testResult;
}
case 'string':
switch ($formatType) {
case 'date':
$row = \DateTime::createFromFormat(
'Y-m-d H:i:s',
$row . ' 00:00:00',
);
break;
}
break;
}
}
return $input;
}
/** /**
* validate objects * validate objects
* *
@ -68,9 +141,6 @@ trait ValidationTrait
if (!$validationResult->isValid()) { if (!$validationResult->isValid()) {
$this->isValid = false; $this->isValid = false;
$this->responseStatus = [400 => 'validationError']; $this->responseStatus = [400 => 'validationError'];
//\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(
// $validationResult->getErrors(), false, 9, true
//);
foreach ($validationResult->getErrors() as $error){ foreach ($validationResult->getErrors() as $error){
$field = implode('.', $error->dataPointer()); $field = implode('.', $error->dataPointer());
if ($error->keyword() == 'required') { if ($error->keyword() == 'required') {

View File

@ -22,7 +22,11 @@ class ArrayUtility
*/ */
public static function toObject($array) { public static function toObject($array) {
if (is_array($array)) { if (is_array($array)) {
if (self::isAssoc($array)) {
return (object) array_map([__CLASS__, __METHOD__], $array); return (object) array_map([__CLASS__, __METHOD__], $array);
} else {
return array_map([__CLASS__, __METHOD__], $array);
}
} else { } else {
return $array; return $array;
} }
@ -46,4 +50,15 @@ class ArrayUtility
return $array; return $array;
} }
/**
*
*/
public static function isAssoc(array $arr) {
if (array() === $arr) {
return false;
}
return array_keys($arr) !== range(0, count($arr) - 1);
}
} }

View File

@ -280,6 +280,13 @@ class MailUtility
$bodydataText[] = $textRow; $bodydataText[] = $textRow;
$bodydataHtml[] = $htmlRow; $bodydataHtml[] = $htmlRow;
break; break;
case 'attachment':
$mail->attach(new \Swift_Attachment(
$row['data'][0],
$row['data'][1],
$row['data'][2]
));
break;
case 'attachmentBase64': case 'attachmentBase64':
$attachmentdata = explode(',', $row['data']); $attachmentdata = explode(',', $row['data']);
preg_match('/\w*:(.*);\w*/', $attachmentdata[0], $matches); preg_match('/\w*:(.*);\w*/', $attachmentdata[0], $matches);

View File

@ -27,8 +27,10 @@ class SiteConfigUtility
* @var string $path * @var string $path
* @return string * @return string
*/ */
public static function getByPath($path) public static function getByPath(
{ $path,
$limitToSiteConfig = true
) {
$pathParts = explode('.', $path); $pathParts = explode('.', $path);
$objectManager = GeneralUtility::makeInstance( $objectManager = GeneralUtility::makeInstance(
ObjectManager::class ObjectManager::class
@ -40,7 +42,10 @@ class SiteConfigUtility
ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
); );
$typoscript = GeneralUtility::removeDotsFromTS($typoscript); $typoscript = GeneralUtility::removeDotsFromTS($typoscript);
$siteConfig = $typoscript;
if ($limitToSiteConfig) {
$siteConfig = $typoscript['config']['site']; $siteConfig = $typoscript['config']['site'];
}
$current = &$siteConfig; $current = &$siteConfig;
foreach ($pathParts as $key) { foreach ($pathParts as $key) {
$current = &$current[$key]; $current = &$current[$key];

View File

@ -1 +1,5 @@
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:templates_aide/Resources/Private/PageTSConfig/lib/layout.tsconfig"> <INCLUDE_TYPOSCRIPT: source="FILE:EXT:templates_aide/Resources/Private/PageTSConfig/lib/layout.tsconfig">
[applicationContext = Development]
TCAdefaults.pages.hidden = 0
[end]

View File

@ -9,7 +9,8 @@
} }
], ],
"require": { "require": {
"typo3/cms-core": "8.7.0 - 9.5.99" "typo3/cms-core": "8.7.0 - 10.99.99",
"sarhan/php-flatten": "^4.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

33
composer.json.orig Normal file
View File

@ -0,0 +1,33 @@
{
"name": "cjel/templates-aide",
"type": "typo3-cms-extension",
"description": "",
"authors": [
{
"name": "Philipp Dieter",
"role": "Developer"
}
],
"require": {
<<<<<<< HEAD
"typo3/cms-core": "8.7.0 - 9.5.99",
"sarhan/php-flatten": "^4.0"
=======
"typo3/cms-core": "8.7.0 - 10.99.99"
>>>>>>> 4a4b809d13bd33b85d84f03eba5edb603d74abfb
},
"autoload": {
"psr-4": {
"Cjel\\TemplatesAide\\": "Classes"
}
},
"autoload-dev": {
"psr-4": {
"Cjel\\TemplatesAide\\Tests\\": "Tests"
}
},
"replace": {
"templates_aide": "self.version",
"typo3-ter/templates-aide": "self.version"
}
}

View File

@ -23,7 +23,7 @@ $EM_CONF[$_EXTKEY] = [
'version' => '0.0.1', 'version' => '0.0.1',
'constraints' => [ 'constraints' => [
'depends' => [ 'depends' => [
'typo3' => '8.7.0-9.5.99', 'typo3' => '8.7.0-10.99.99',
], ],
'conflicts' => [], 'conflicts' => [],
'suggests' => [], 'suggests' => [],