Obj
\nn\t3::Obj()
Everything you need for objects and models.
Overview of Methods
\nn\t3::Obj()->accessSingleProperty($obj, $key);
Access to a key in an object or array key must be a single string, not a path
nnt3::Obj()->accessSingleProperty( $obj, 'uid' ); nnt3::Obj()->accessSingleProperty( $obj, 'fal_media' ); nnt3::Obj()->accessSingleProperty( $obj, 'falMedia' );
@param mixed $obj Model or array
@param string $key the key that is to be fetched
| @return mixed
\nn\t3::Obj()->diff($objA, $objB, $fieldsToIgnore = [], $fieldsToCompare = [], $options = [], $path = '', $diff = []);
Compares two objects, returns array with differences. If a property of objA does not exist in objB, it is ignored.
// Returns array with differences
\nn\t3::Obj()->diff( $objA, $objB );
// ignores the fields uid and title
\nn\t3::Obj()->diff( $objA, $objB, ['uid', 'title'] );
// Compares ONLY the fields title and bodytext
\nn\t3::Obj()->diff( $objA, $objB, [], ['title', 'bodytext'] );
// Options
\nn\t3::Obj()->diff( $objA, $objB, [], [], ['ignoreWhitespaces'=>true, 'ignoreTags'=>true, 'ignoreEncoding'=>true] );
@param mixed $objA An object, array or model
@param mixed $objB The object or model to be compared
@param array $fieldsToIgnore List of properties that can be ignored. Empty = none
@param array $fieldsToCompare List of properties to be compared. Empty = all
@param boolean $options Options / tolerances when comparing
includeMissing => also add missing properties in $objB
ignoreWhitespaces => ignore spaces
ignoreEncoding => ignore UTF8 / ISO encoding
ignoreTags => ignore HTML tags
depth => depth to be compared
| @return array
\nn\t3::Obj()->forceArray($obj);
Converts to array
| @param mixed $obj
| @return array
\nn\t3::Obj()->get($obj, $key = '');
Access to a value in the object using the key
Alias to \nn\t3::Obj()->accessSingleProperty()
\nn\t3::Obj()->get( $obj, 'title' );
\nn\t3::Obj()->get( $obj, 'falMedia' );
\nn\t3::Obj()->get( $obj, 'fal_media' );
@param mixed $obj Model or array
@param string $key the key / property
| @return mixed
\nn\t3::Obj()->getClassSchema($modelClassName = NULL);
Get information about the classSchema of a model
\nn\t3::Obj()->getClassSchema( \My\Model\Name::class );
\nn\t3::Obj()->getClassSchema( $myModel );
return DataMap
\nn\t3::Obj()->getKeys($obj);
Access to ALL keys that are to be fetched in an object
\nn\t3::Obj()->getKeys( $model ); // ['uid', 'title', 'text', ...]
\nn\t3::Obj()->getKeys( $model ); // ['uid', 'title', 'text', ...]
\nn\t3::Obj()->getKeys( \Nng\MyExt\Domain\Model\Demo::class ); // ['uid', 'title', 'text', ...]
@param mixed $obj Model, array or class name
@return array
\nn\t3::Obj()->getMethodArguments($className = NULL, $methodName = NULL);
Get information about the arguments of a method.
| Also takes into account the``type hinting``specified by@paramain``, e.g. forObjectStorage``.
\nn\t3::Obj()->getMethodArguments( \My\Model\Name::class, 'myMethodName' );
\nn\t3::Obj()->getMethodArguments( $myClassInstance, 'myMethodName' );
Returns as an example:
'varName' => [
'type' => 'Storage',
'storageType' => 'Storage',
'elementType' => 'Model',
'optional' => true,
'defaultValue' => '123'
]
return array
\nn\t3::Obj()->getProps($obj, $key = 'type', $onlySettable = true);
Return the list of properties of an object or model with type.
\nn\t3::Obj()->getProps( $obj ); // ['uid'=>'integer', 'title'=>'string' ...]
\nn\t3::Obj()->getProps( $obj, true ); // ['uid'=>[type=>'integer', 'private'=>TRUE]]
\nn\t3::Obj()->getProps( $obj, 'default' ); // ['uid'=>TRUE]
\nn\t3::Obj()->getProps( \Nng\MyExt\Domain\Model\Demo::class );
@param mixed $obj Model or class name
@param mixed $key If TRUE, array with all information is retrieved, e.g. also default value etc.
@param boolean $onlySettable Only get properties that can also be set via setName()
@return array
\nn\t3::Obj()->getSetableKeys($obj);
Get all keys of an object that have a SETTER.
In contrast to \nn\t3::Obj()->getKeys(), only the property keys are
are returned that can also be set, e.g. via setNameDerProp()
| @return array
\nn\t3::Obj()->getTableName($modelClassName = NULL);
Returns the DB table name for a model
$model = new \Nng\MyExt\Domain\Model\Test;
\nn\t3::Obj()->getTableName( $model ); // 'tx_myext_domain_model_test'
\nn\t3::Obj()->getTableName( Test::class ); // 'tx_myext_domain_model_test'
| @return string
\nn\t3::Obj()->isFalFile($obj);
Checks whether the object is a \TYPO3\CMS\Core\Resource\FileReference.
\nn\t3::Obj()->isFalFile( $obj );
| @return boolean
\nn\t3::Obj()->isFile($obj);
Checks whether the object is a \TYPO3\CMS\Core\Resource\File.
\nn\t3::Obj()->isFile( $obj );
| @return boolean
\nn\t3::Obj()->isFileReference($obj);
Checks whether the object is a \TYPO3\CMS\Extbase\Domain\Model\FileReference.
\nn\t3::Obj()->isFileReference( $obj );
| @return boolean
\nn\t3::Obj()->isModel($obj);
Checks whether the object is a domain model.
\nn\t3::Obj()->isModel( $obj );
| @return boolean
\nn\t3::Obj()->isSimpleType($type = '');
Checks whether a type (string) is a "simple" type.
Simple types are all types apart from models, classes etc. - e.g. array, string, boolean etc.
$isSimple = \nn\t3::Obj()->isSimpleType( 'string' ); // true
$isSimple = \nn\t3::Obj()->isSimpleType( \My\Extname\ClassName::class ); // false
| @return boolean
\nn\t3::Obj()->isStorage($obj);
Checks whether the object is a storage.
\nn\t3::Obj()->isStorage( $obj );
| @return boolean
\nn\t3::Obj()->isSysCategory($obj);
Checks whether the object is a SysCategory.
Takes into account all models that are stored in sys_category.
\nn\t3::Obj()->isSysCategory( $obj );
$cat = new \GeorgRinger\News\Domain\Model\Category();
\nn\t3::Obj()->isSysCategory( $cat );
| @return boolean
\nn\t3::Obj()->merge($model = NULL, $overlay = NULL);
Merge an array into an object
\nn\t3::Obj( \My\Doman\Model )->merge(['title'=>'New title']);
This can even be used to write / overwrite FileReferences.
In this example, $data is merged with an existing model.
| falMedia is an ObjectStorage in the example. The first element in falMedia already exists
already exists in the database(uid = 12). Only the title is updated here.
The second element in the array (without uid) is new. For this, a new
| sys_file_reference is automatically created in the database.
$data = [
'uid' => 10,
'title' => 'The title',
'falMedia' => [
['uid'=>12, 'title'=>'1st image title'],
['title'=>'NEW image title', 'publicUrl'=>'fileadmin/_tests/5e505e6b6143a.jpg'],
]
];
$oldModel = $repository->findByUid( $data['uid'] );
$mergedModel = \nn\t3::Obj($oldModel)->merge($data);
Hint
To create a new model with data from an array, there is the method
there is the method $newModel = \nn\t3::Convert($data)->toModel( \My\Model\Name::class );
| @return object
\nn\t3::Obj()->parseType($paramType = '');
Parse a string with information about ObjectStorage.
\nn\t3::Obj()->parseType( 'string' );
\nn\t3::Obj()->parseType( 'Nng\Nnrestapi\Domain\Model\ApiTest' );
\nn\t3::Obj()->parseType( '\TYPO3\CMS\Extbase\Persistence\ObjectStorage' );
Git an array with information back:
| type is only set if it is an array or an ObjectStorage.
| elementType is always the type of the model or the TypeHinting of the variable
[
'elementType' => 'Nng\Nnrestapi\Domain\Model\ApiTest',
'type' => 'TYPO3\CMS\Extbase\Persistence\ObjectStorage',
'simple' => FALSE
]
| @return array
\nn\t3::Obj()->prop($obj, $key);
Access to a key in an object or array. The key can also be a path, e.g. "img.0.uid"
nnt3::Obj()->prop( $obj, 'img.0.uid' );
@param mixed $obj Model or array
@param string $key the key that is to be fetched
| @return mixed
\nn\t3::Obj()->props($obj, $keys = []);
Get individual properties of an object or array
\nn\t3::Obj()->props( $obj, ['uid', 'pid'] );
\nn\t3::Obj()->props( $obj, 'uid' );
| @return array
\nn\t3::Obj()->set($obj, $key = '', $val = '', $useSetter = true);
Sets a value in an object or array.
\nn\t3::Obj()->set( $obj, 'title', $val );
@param mixed $obj Model or array
@param string $key the key / property
@param mixed $val the value to be set
@param boolean $useSetter setKey() method to use for setting
| @return mixed
\nn\t3::Obj()->toArray($obj, $depth = 3, $fields = [], $addClass = false);
Converts an object into an array For memory problems due to recursion: Specify max depth!
\nn\t3::Obj()->toArray($obj, 2, ['uid', 'title']);
\nn\t3::Obj()->toArray($obj, 1, ['uid', 'title', 'parent.uid']);
@param mixed $obj ObjectStorage, model or array that is to be converted
@param integer $depth Depth to be converted. Always use for recursive conversion
@param array $fields only return these fields from the object / array
@param boolean $addClass Supplement '__class' with information about the class?
| @return array