12 class Persistor extends \Magento\Framework\Code\Generator\EntityAbstract
29 'visibility' =>
'protected',
31 'shortDescription' =>
'Entity factory',
42 'visibility' =>
'protected',
44 'shortDescription' =>
'Resource model',
55 'visibility' =>
'protected',
57 'shortDescription' =>
'Application Resource',
61 'description' =>
'\\' . \Magento\Framework\App\ResourceConnection::class,
67 'name' =>
'connection',
68 'visibility' =>
'protected',
70 'shortDescription' =>
'Database Adapter',
74 'description' =>
'\\' . \Magento\Framework\DB\Adapter\AdapterInterface::class,
80 'name' =>
'entitiesPool',
81 'visibility' =>
'protected',
84 'shortDescription' =>
'',
88 'description' =>
'array',
95 'visibility' =>
'protected',
98 'shortDescription' =>
'',
102 'description' =>
'array',
137 $temporary = str_replace(
'\\Api\\Data\\',
'\\Model\\Spi\\', $this->
getSourceClassName());
138 $parts = explode(
'\\', ltrim($temporary,
'\\'));
141 return '\\' . implode(
'\\', $parts) .
'\\' .
$className .
'ResourceInterface';
171 'name' =>
'__construct',
182 'name' =>
'resource',
183 'type' =>
'\\' . \Magento\Framework\App\ResourceConnection::class
192 .
"\$this->resource = \$resource;" 195 'shortDescription' => ucfirst(static::ENTITY_TYPE) .
' constructor',
209 'description' =>
'\Magento\Framework\App\ResourceConnection $resource' 221 $body =
"if (!\$this->connection) {\n" 222 .
" \$this->connection = \$this->resource->getConnection(" 223 .
"\\Magento\\Framework\\App\\ResourceConnection::DEFAULT_CONNECTION);\n" 225 .
"return \$this->connection;";
228 'name' =>
'getConnection',
232 'shortDescription' =>
'Returns Adapter interface',
236 'description' =>
"array \\Magento\\Framework\\DB\\Adapter\\AdapterInterface",
250 $body =
"\$entity = \$this->{$this->_getSourceFactoryPropertyName()}->create()->load(\$key);\n" 251 .
"return \$entity;";
253 'name' =>
'loadEntity',
261 'shortDescription' =>
'Load entity by key',
265 'description' =>
"int \$key",
283 $body =
"\$hash = spl_object_hash(\$entity);\n" 284 .
"array_push(\$this->stack, \$hash);\n" 285 .
"\$this->entitiesPool[\$hash] = [\n" 286 .
" 'entity' => \$entity,\n" 287 .
" 'action' => 'removed'\n" 290 'name' =>
'registerDeleted',
299 'shortDescription' =>
'Register entity to delete',
315 $body =
"\$ids = [];\n" 316 .
"\$this->getConnection()->beginTransaction();\n" 319 .
" \$hash = array_pop(\$this->stack);\n" 320 .
" if (isset(\$this->entitiesPool[\$hash])) {\n" 321 .
" \$data = \$this->entitiesPool[\$hash];\n" 322 .
" \$entity = \$data['entity'];\n" 323 .
" if (\$data['action'] == 'created') {\n" 324 .
" \$this->{$this->_getSourceResourcePropertyName()}->save(\$entity);\n" 325 .
" \$ids[] = \$entity->getId();\n" 327 .
" \$ids[] = \$entity->getId();\n" 328 .
" \$this->{$this->_getSourceResourcePropertyName()}->delete(\$entity);\n" 331 .
" unset(\$this->entitiesPool[\$hash]);\n" 333 .
" } while (!empty(\$this->entitiesPool) || \$items === 0);\n" 334 .
" \$this->getConnection()->commit();\n" 336 .
"} catch (\\Exception \$e) {\n" 337 .
" \$this->getConnection()->rollback();\n" 341 'name' =>
'doPersist',
351 'shortDescription' =>
'Perform persist operation',
355 'description' =>
"int \$items",
359 'description' =>
"array",
373 $body =
"\$hash = spl_object_hash(\$entity);\n" 374 .
"\$action = 'created';\n" 375 .
"if (isset(\$this->entitiesPool[\$hash])) {\n" 376 .
" \$action = \$this->entitiesPool[\$hash]['action'];\n" 377 .
" \$tempStack = \$this->stack;\n" 378 .
" array_flip(\$tempStack);\n" 379 .
" unset(\$tempStack[\$hash]);\n" 380 .
" \$this->stack = array_flip(\$tempStack);\n" 381 .
" unset(\$this->entitiesPool[\$hash]);\n" 383 .
"\$action == 'created' ? \$this->registerNew(\$entity) : \$this->registerDeleted(\$entity);\n" 384 .
"return \$this->doPersist(1);";
386 'name' =>
'doPersistEntity',
395 'shortDescription' =>
'Persist entity',
413 $body =
"\$entity = \$this->{$this->_getSourceFactoryPropertyName()}->create(['data' => \$data]);\n" 414 .
"\$this->registerNew(\$entity);\n" 415 .
"return \$entity;";
417 'name' =>
'registerFromArray',
426 'shortDescription' =>
'Register entity to create',
430 'description' =>
"array \$data",
448 $body =
"\$hash = spl_object_hash(\$entity);\n" 450 .
" 'entity' => \$entity,\n" 451 .
" 'action' => 'created'\n" 453 .
"array_push(\$this->stack, \$hash);\n" 454 .
"\$this->entitiesPool[\$hash] = \$data;";
456 'name' =>
'registerNew',
465 'shortDescription' =>
'Register entity to create',
482 $result = parent::_validateData();
488 if ($resultClassName !== $sourceClassName .
'Persistor') {
490 'Invalid Factory class name [' . $resultClassName .
']. Use ' . $sourceClassName .
'Persistor' _getGetConnectionMethod()
_getSourceResourcePropertyName()
_getSourceFactoryPropertyName()
getSourceClassNameWithoutNamespace()
_getRegisterDeletedMethod()
_getDoPersistEntityMethod()
_getRegisterFromArrayMethod()
_getDefaultConstructorDefinition()
_getSourceResourceClassName()