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

| ➜ Go to source code of Obj::accessSingleProperty()

\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] );
Copied!
@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

| ➜ Go to source code of Obj::diff()

\nn\t3::Obj()->forceArray($obj); 

Converts to array

| @param mixed $obj

| @return array

| ➜ Go to source code of Obj::forceArray()

\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' );
Copied!
@param mixed $obj Model or array
@param string $key the key / property

| @return mixed

| ➜ Go to source code of Obj::get()

\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 );
Copied!

return DataMap

| ➜ Go to source code of Obj::getClassSchema()

\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', ...]
Copied!
@param mixed $obj Model, array or class name
@return array

| ➜ Go to source code of Obj::getKeys()

\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' );
Copied!

Returns as an example:

'varName' => [
    'type' => 'Storage',
    'storageType' => 'Storage',
    'elementType' => 'Model',
 'optional' => true,
 'defaultValue' => '123'
]
Copied!

return array

| ➜ Go to source code of Obj::getMethodArguments()

\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 );
Copied!
@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

| ➜ Go to source code of Obj::getProps()

\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

| ➜ Go to source code of Obj::getSetableKeys()

\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'
Copied!

| @return string

| ➜ Go to source code of Obj::getTableName()

\nn\t3::Obj()->isFalFile($obj); 

Checks whether the object is a \TYPO3\CMS\Core\Resource\FileReference.

\nn\t3::Obj()->isFalFile( $obj );
Copied!

| @return boolean

| ➜ Go to source code of Obj::isFalFile()

\nn\t3::Obj()->isFile($obj); 

Checks whether the object is a \TYPO3\CMS\Core\Resource\File.

\nn\t3::Obj()->isFile( $obj );
Copied!

| @return boolean

| ➜ Go to source code of Obj::isFile()

\nn\t3::Obj()->isFileReference($obj); 

Checks whether the object is a \TYPO3\CMS\Extbase\Domain\Model\FileReference.

\nn\t3::Obj()->isFileReference( $obj );
Copied!

| @return boolean

| ➜ Go to source code of Obj::isFileReference()

\nn\t3::Obj()->isModel($obj); 

Checks whether the object is a domain model.

\nn\t3::Obj()->isModel( $obj );
Copied!

| @return boolean

| ➜ Go to source code of Obj::isModel()

\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
Copied!

| @return boolean

| ➜ Go to source code of Obj::isSimpleType()

\nn\t3::Obj()->isStorage($obj); 

Checks whether the object is a storage.

\nn\t3::Obj()->isStorage( $obj );
Copied!

| @return boolean

| ➜ Go to source code of Obj::isStorage()

\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 );
Copied!

| @return boolean

| ➜ Go to source code of Obj::isSysCategory()

\nn\t3::Obj()->merge($model = NULL, $overlay = NULL); 

Merge an array into an object

\nn\t3::Obj( \My\Doman\Model )->merge(['title'=>'New title']);
Copied!

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);
Copied!

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

| ➜ Go to source code of Obj::merge()

\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' );
Copied!

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
]
Copied!

| @return array

| ➜ Go to source code of Obj::parseType()

\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

| ➜ Go to source code of Obj::prop()

\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' );
Copied!

| @return array

| ➜ Go to source code of Obj::props()

\nn\t3::Obj()->set($obj, $key = '', $val = '', $useSetter = true); 

Sets a value in an object or array.

\nn\t3::Obj()->set( $obj, 'title', $val );
Copied!
@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

| ➜ Go to source code of Obj::set()

\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']);
Copied!
@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

| ➜ Go to source code of Obj::toArray()

Methods