Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
TypoScript-Backend
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TYPO3
TypoScript-Backend
Commits
1db19b2c
Commit
1db19b2c
authored
9 years ago
by
damjan
Browse files
Options
Downloads
Patches
Plain Diff
[FEATURE] Export adapted for types, properties and pseudo types
parent
f7793674
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/SGalinski/TypoScriptBackendBundle/Service/TypoScriptReferenceExportService.php
+123
-48
123 additions, 48 deletions
...ackendBundle/Service/TypoScriptReferenceExportService.php
with
123 additions
and
48 deletions
src/SGalinski/TypoScriptBackendBundle/Service/TypoScriptReferenceExportService.php
+
123
−
48
View file @
1db19b2c
...
...
@@ -5,8 +5,9 @@ namespace SGalinski\TypoScriptBackendBundle\Service;
use
Doctrine\Bundle\DoctrineBundle\Registry
;
use
DOMDocument
;
use
Monolog\Logger
;
use
SGalinski\TypoScriptBackendBundle\Entity\Attribute
;
use
SGalinski\TypoScriptBackendBundle\Entity\AttributeRepository
;
use
SGalinski\TypoScriptBackendBundle\Entity\Property
;
use
SGalinski\TypoScriptBackendBundle\Entity\Type
;
use
SGalinski\TypoScriptBackendBundle\Entity\TypeRepository
;
use
SGalinski\TypoScriptBackendBundle\Utility\CdataSupportingSimpleXMLElement
;
/**
...
...
@@ -43,7 +44,7 @@ class TypoScriptReferenceExportService {
* @param int $typo3Group
* @return void
*/
public
function
export
(
$fileAddress
,
$typo3Version
=
NULL
,
$typo3Group
=
Attribut
e
::
NORMAL_GROUP
)
{
public
function
export
(
$fileAddress
,
$typo3Version
=
NULL
,
$typo3Group
=
Typ
e
::
NORMAL_GROUP
)
{
$tsrefXmlString
=
$this
->
getTsrefString
(
$typo3Version
,
$typo3Group
);
file_put_contents
(
$fileAddress
,
$tsrefXmlString
);
...
...
@@ -57,12 +58,15 @@ class TypoScriptReferenceExportService {
* @param integer $typo3Group - Attribute::NORMAL_GROUP | Attribute::PAGE_GROUP | Attribute::USER_GROUP
* @return string
*/
public
function
getTsrefString
(
$typo3Version
=
NULL
,
$typo3Group
=
Attribute
::
NORMAL_GROUP
)
{
/** @var AttributeRepository $attributeRepository */
$attributeRepository
=
$this
->
doctrine
->
getRepository
(
'TypoScriptBackendBundle:Attribute'
);
$typeAttributes
=
$attributeRepository
->
findByVersionInRange
(
TRUE
,
$typo3Group
,
$typo3Version
);
public
function
getTsrefString
(
$typo3Version
=
NULL
,
$typo3Group
=
Type
::
NORMAL_GROUP
)
{
/** @var TypeRepository $typeRepository */
$typeRepository
=
$this
->
doctrine
->
getRepository
(
'TypoScriptBackendBundle:Type'
);
$types
=
$typeRepository
->
findByVersionInRange
(
$typo3Group
,
$typo3Version
);
$types
=
$this
->
makePseudoTypesFromSubProperties
(
$types
);
/** @var CdataSupportingSimpleXMLElement $tsrefXml */
$tsrefXml
=
$this
->
phpToXml
(
$type
Attribute
s
);
$tsrefXml
=
$this
->
phpToXml
(
$types
);
$tsrefXmlString
=
$this
->
formatXml
(
$tsrefXml
);
return
$tsrefXmlString
;
}
...
...
@@ -70,77 +74,69 @@ class TypoScriptReferenceExportService {
/**
* Makes XML (SimpleXMLElement) from php array.
*
* @param array $type
Attribute
s
* @param array $types
* @return CdataSupportingSimpleXMLElement
*/
protected
function
phpToXml
(
array
$type
Attribute
s
)
{
protected
function
phpToXml
(
array
$types
)
{
$tsrefXml
=
new
CdataSupportingSimpleXMLElement
(
'<?xml version="1.0" encoding="UTF-8"?>
<tsRef></tsRef>'
);
// Some checks
if
(
!
is_array
(
$type
Attribute
s
))
{
if
(
!
is_array
(
$types
))
{
$message
=
'Not an array. Array of attributes expected.'
;
$this
->
logger
->
addError
(
$message
);
throw
new
\RuntimeException
(
$message
);
}
if
(
empty
(
$type
Attribute
s
))
{
if
(
empty
(
$types
))
{
$this
->
logger
->
addWarning
(
'Type array is empty.'
);
return
$tsrefXml
;
}
//Write XML
/** @var Attribute $typeAttribute */
foreach
(
$typeAttributes
as
$typeAttribute
)
{
if
(
!
$typeAttribute
->
getIsType
())
{
$this
->
logger
->
addWarning
(
'Non-type ('
.
$typeAttribute
->
getName
()
.
') found in the type array.'
);
continue
;
}
/** @var Type $type */
foreach
(
$types
as
$type
)
{
/** @var CdataSupportingSimpleXMLElement $typeTag */
$typeTag
=
$tsrefXml
->
addChild
(
'type'
);
$typeTag
->
addAttribute
(
'id'
,
$type
Attribute
->
getName
());
if
(
$type
Attribute
->
getParent
()
!=
NULL
)
{
$typeTag
->
addAttribute
(
'extends'
,
$type
Attribute
->
getParent
()
->
getName
());
$typeTag
->
addAttribute
(
'id'
,
$type
->
getName
());
if
(
$type
->
getExtends
()
!=
=
NULL
)
{
$typeTag
->
addAttribute
(
'extends'
,
$type
->
getExtends
()
->
getName
());
}
if
(
$type
Attribute
->
getMinVersion
()
!=
NULL
)
{
$typeTag
->
addAttribute
(
'minVersion'
,
$type
Attribute
->
getMinVersion
());
if
(
$type
->
getMinVersion
()
!=
=
NULL
)
{
$typeTag
->
addAttribute
(
'minVersion'
,
$type
->
getMinVersion
());
}
if
(
$type
Attribute
->
getMaxVersion
()
!=
NULL
)
{
$typeTag
->
addAttribute
(
'maxVersion'
,
$type
Attribute
->
getMaxVersion
());
if
(
$type
->
getMaxVersion
()
!=
=
NULL
)
{
$typeTag
->
addAttribute
(
'maxVersion'
,
$type
->
getMaxVersion
());
}
if
(
$type
Attribute
->
getUrlName
()
!=
NULL
)
{
$typeTag
->
addAttribute
(
'urlName'
,
$type
Attribute
->
getUrlName
());
if
(
$type
->
getUrlName
()
!=
=
NULL
)
{
$typeTag
->
addAttribute
(
'urlName'
,
$type
->
getUrlName
());
}
if
(
$type
Attribute
->
getDescription
()
!=
NULL
)
{
$typeTag
->
addChildCData
(
'description'
,
$type
Attribute
->
getDescription
());
if
(
$type
->
getDescription
()
!=
=
NULL
)
{
$typeTag
->
addChildCData
(
'description'
,
$type
->
getDescription
());
}
if
(
$typeAttribute
->
getChildren
()
!=
NULL
)
{
/** @var Attribute $propertyAttribute */
foreach
(
$typeAttribute
->
getChildren
()
as
$propertyAttribute
)
{
if
(
$propertyAttribute
->
getIsType
())
{
continue
;
}
if
(
$type
->
getChildren
()
!==
NULL
)
{
/** @var Property $property */
foreach
(
$type
->
getChildren
()
as
$property
)
{
/** @var CdataSupportingSimpleXMLElement $propertyTag */
$propertyTag
=
$typeTag
->
addChild
(
'property'
);
$propertyTag
->
addAttribute
(
'name'
,
$property
Attribute
->
getName
());
$propertyTag
->
addAttribute
(
'type'
,
$property
Attribute
->
getType
()
->
getName
());
if
(
$property
Attribute
->
getMinVersion
()
!=
NULL
)
{
$propertyTag
->
addAttribute
(
'minVersion'
,
$property
Attribute
->
getMinVersion
());
$propertyTag
->
addAttribute
(
'name'
,
$property
->
getName
());
$propertyTag
->
addAttribute
(
'type'
,
$property
->
getType
()
->
getName
());
if
(
$property
->
getMinVersion
()
!=
=
NULL
)
{
$propertyTag
->
addAttribute
(
'minVersion'
,
$property
->
getMinVersion
());
}
if
(
$property
Attribute
->
getMaxVersion
()
!=
NULL
)
{
$propertyTag
->
addAttribute
(
'maxVersion'
,
$property
Attribute
->
getMaxVersion
());
if
(
$property
->
getMaxVersion
()
!=
=
NULL
)
{
$propertyTag
->
addAttribute
(
'maxVersion'
,
$property
->
getMaxVersion
());
}
if
(
$property
Attribute
->
getUrlName
()
!=
NULL
)
{
$propertyTag
->
addAttribute
(
'urlName'
,
$property
Attribute
->
getUrlName
());
if
(
$property
->
getUrlName
()
!=
=
NULL
)
{
$propertyTag
->
addAttribute
(
'urlName'
,
$property
->
getUrlName
());
}
if
(
$property
Attribute
->
getDescription
()
!=
NULL
)
{
$propertyTag
->
addChildCData
(
'description'
,
$property
Attribute
->
getDescription
());
if
(
$property
->
getDescription
()
!=
=
NULL
)
{
$propertyTag
->
addChildCData
(
'description'
,
$property
->
getDescription
());
}
if
(
$property
Attribute
->
getDefault
()
!=
NULL
)
{
$propertyTag
->
addChildCData
(
'default'
,
$property
Attribute
->
getDefault
());
if
(
$property
->
getDefault
()
!=
=
NULL
)
{
$propertyTag
->
addChildCData
(
'default'
,
$property
->
getDefault
());
}
}
}
...
...
@@ -163,4 +159,83 @@ class TypoScriptReferenceExportService {
$formattedXml
=
$dom
->
saveXML
();
return
$formattedXml
;
}
/**
* Makes pseudo types from sub properties and adds them to type list which is returned.
* Name format: <type name>_<property name>[_<sub property name>*]
* Example:
* <type id="CARRAY+TDParams_TDParams_firstSubProperty!" extends="CARRAY+TDParams_TDParams" minVersion="4.3"
* urlName="CARRAY_TDParams_TDParams_firstSubProperty_">
*
* @param array $types
* @return array
*/
private
function
makePseudoTypesFromSubProperties
(
array
$types
)
{
/** @var Type $type */
foreach
(
$types
as
$key
=>
$type
)
{
if
(
$type
->
getDeleted
())
{
continue
;
}
/** @var Property $property */
foreach
(
$type
->
getChildren
()
as
$property
)
{
if
(
$property
->
getDeleted
())
{
continue
;
}
$pseudoTypes
=
$this
->
handleSubProperties
(
$property
,
$type
);
if
(
!
empty
(
$pseudoTypes
))
{
array_splice
(
$types
,
$key
+
1
,
0
,
$pseudoTypes
);
}
}
}
return
$types
;
}
/**
* Returns array of pseudo types made from properties which have sub properties.
*
* @param Property $parentProperty
* @param Type $parentType
* @param array $pseudoTypesArray
* @return array
*/
protected
function
handleSubProperties
(
Property
$parentProperty
,
Type
$parentType
,
$pseudoTypesArray
=
[])
{
$children
=
$parentProperty
->
getChildren
();
foreach
(
$children
as
$key
=>
$property
)
{
if
(
$property
->
getDeleted
())
{
unset
(
$children
[
$key
]);
}
}
if
(
$children
===
NULL
||
sizeof
(
$children
)
<=
0
)
{
return
$pseudoTypesArray
;
}
$pseudoType
=
$this
->
createPseudoType
(
$parentProperty
,
$parentType
,
$children
);
$pseudoTypesArray
[]
=
$pseudoType
;
foreach
(
$children
as
$property
)
{
$pseudoTypesArray
=
$this
->
handleSubProperties
(
$property
,
$pseudoType
,
$pseudoTypesArray
);
}
return
$pseudoTypesArray
;
}
/**
* Creates and initialises a pseudo type.
*
* @param Property $parentProperty
* @param Type $parentType
* @param $children
* @return Type
*/
protected
function
createPseudoType
(
Property
$parentProperty
,
Type
$parentType
,
$children
)
{
$pseudoType
=
new
Type
();
$pseudoType
->
setName
(
$parentType
->
getName
()
.
'_'
.
$parentProperty
->
getName
());
$pseudoType
->
setMinVersion
(
$parentProperty
->
getMinVersion
());
$pseudoType
->
setMaxVersion
(
$parentProperty
->
getMaxVersion
());
$pseudoType
->
setTypo3Group
(
$parentProperty
->
getTypo3Group
());
$pseudoType
->
setDescription
(
$parentProperty
->
getDescription
());
$pseudoType
->
setChildren
(
$children
);
$pseudoType
->
setExtends
(
$parentType
);
return
$pseudoType
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment