Выполним действие

@param array  $files          Массив файлов
@param string $container_type Тип контейнера
@param string $container_id   ИД контейнера

@return array

@version 08.01.2019
@author  Дмитрий Щербаков <atomcms@ya.ru>
322861
public function run($files, $container_type = 'default', $container_id = null)
    {
        $file_add = new FileAdd($this->dic);
        $file_remove = new FileRemove($this->dic);

        $files_ids = [];
        $files_errors = [];

        if (!empty($files)) {
            foreach ($files as $file) {
                switch ($file['action']) {
                    case 'add':
                        $result = $file_add->run(
                            $file['file_id'],
                            $file['orig_name'],
                            $container_type,
                            $container_id
                        );

                        if (isset($result['errors'])) {
                            $files_errors[] = array_merge($file, $result);
                        } else {
                            $files_ids[] = $result['data']['id'];
                        }
                        break;

                    case 'remove':
                        $result = $file_remove->run($file['file_id']);

                        if (isset($result['errors'])) {
                            $files_ids[] = $file['file_id'];
                            $files_errors[] = array_merge($file, $result);
                        }
                        break;

                    default:
                        $files_ids[] = $file['file_id'];
                        break;
                }
            }
        }

        return [
            'ids'    => $files_ids,
            'errors' => $files_errors,
        ];
    }
158242
public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('stack_factory')) {
            return;
        }

        $stackFactory = $container->getDefinition('stack_factory');
        $stackPriority = [];

        foreach ($container->findTaggedServiceIds('stack_middleware') as $id => $attributes) {
            $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
            $stackPriority[$priority][] = $this->retrieveArguments($container, $id);
        }

        if (false === empty($stackPriority)) {
            $this->addMiddlewares($stackFactory, $stackPriority);
        }
    }
746205
protected function call($method, $id)
    {
        if (!$this->container) {
            throw new ContainerException('Container not injected');
        }
        if (\method_exists($this->container, $method)) {
            return $this->container->$method($id);
        }
        throw new ContainerException('Container method not found: ' . $method);
    }
944280
public function attach($container_id, $relation_id, Request $request)
    {
        $container = $this->getManager()->getRepository()->findOneBy(['id' => $container_id]);

        if (!$container) {
            return $this->not_found();
        }

        $resource = $this->getRelationManager($container)->getRepository()->findOneBy(['id' => $relation_id]);

        if (!$resource) {
            return $this->not_found();
        }

        $relationName = $this->getRelationName($container);

        if (!$container->$relationName->contains($resource)) {
            $container->$relationName()->attach($resource);
        }

        return $this->success(['message' => 'ok']);
    }
1361271
public function buildContainer(
        ExtensionInterface $extension = null,
        array $config = [],
        array $parameters = [],
        array $compilerPasses = []
    ) {
        $container = new ContainerBuilder();
        if ($extension !== null) {
            $extension->setConfigDirectories($this->configDirectories);
            $extension->buildContainer($container, $config);
        }
        foreach ($parameters as $key => $value) {
            $container->setParameter($key, $value);
        }
        foreach ($compilerPasses as $compilerPass) {
            $container->addCompilerPass($compilerPass);
        }
        $container->compile();

        return $container;
    }
189448
public function delete($id, $type) {
		$params = array(
			'id' => $id,
			'type' => $type
		);
		return $this->master->call('files/delete', $params);
	}
1038629
public static function findByFileType( $parentId, $parentType, $fileType ) {

		$fileTable = CoreTables::getTableName( CoreTables::TABLE_FILE );

		return self::queryByParent( $parentId, $parentType )->andFilterWhere( [ 'like', "$fileTable.type", $fileType ] )->all();
	}
709083
public function process(ContainerBuilder $container)
    {
        $map = [];

        // this is an excellent basemap
        $extRefMapping = $container->getParameter('graviton.document.type.extref.mapping');

        foreach ($extRefMapping as $documentName => $baseRouteName) {
            list(, $bundle, , $document) = explode('.', $baseRouteName);

            $baseRoutingKey = 'document.'.
                $bundle.
                '.'.
                $document;

            $map[$documentName] = [
                'baseRoute' => $baseRouteName,
                'events' => [
                    'put' => $baseRoutingKey.'.update',
                    'patch' => $baseRoutingKey.'.update',
                    'post' => $baseRoutingKey.'.create',
                    'postNoSlash' => $baseRoutingKey.'.create',
                    'delete' => $baseRoutingKey.'.delete',
                ]
            ];
        }

        $container->setParameter('graviton.document.eventmap', $map);
    }
548417
public function listParents($fileId, $optParams = array())
  {
    $params = array('fileId' => $fileId);
    $params = array_merge($params, $optParams);
    return $this->call('list', array($params), "Drive_ParentList");
  }
468562
public function register(Container $container)
    {
        /**
         * @param Container $container A container instance.
         * @return Container The Collection of DatabaseSourceConfig, in a Container.
         */
        $container['databases/config'] = function (Container $container) {
            $config = $container['config'];
            $databases = $config['databases'];
            $configs = new Container();
            foreach ($databases as $dbIdent => $dbOptions) {
                $configs[$dbIdent] = function () use ($dbOptions) {
                    return new DatabaseConfig($dbOptions);
                };
            }
            return $configs;
        };

        /**
         * @param Container $container A container instance.
         * @return Container
         */
        $container['databases'] = function (Container $container) {
            $config = $container['config'];
            $databases = $config['databases'];
            $dbs = new Container();
            $origContainer = $container;
            foreach ($databases as $dbIdent => $dbOptions) {
                unset($dbOptions);

                /**
                 * @param Container $container A container instance.
                 * @return PDO
                 */
                $dbs[$dbIdent] = function () use ($dbIdent, $origContainer) {
                    $dbConfigs = $origContainer['databases/config'];
                    $dbConfig = $dbConfigs[$dbIdent];

                    $type = $dbConfig['type'];
                    $host = $dbConfig['hostname'];

                    $database = $dbConfig['database'];
                    $username = $dbConfig['username'];
                    $password = $dbConfig['password'];

                    // Set UTf-8 compatibility by default. Disable it if it is set as such in config
                    $extraOptions = null;
                    if (!isset($dbConfig['disable_utf8']) || !$dbConfig['disable_utf8']) {
                        $extraOptions = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4'];
                    }

                    if ($type == 'sqlite') {
                        $dsn = $type.':'.$database;
                    } else {
                        $dsn = $type.':host='.$host.';dbname='.$database;
                    }
                    $db = new PDO($dsn, $username, $password, $extraOptions);

                    // Set PDO options
                    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    if ($type == 'mysql') {
                        $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
                    }
                    return $db;
                };
            }
            return $dbs;
        };

        /**
         * The (default) database configuration.
         *
         * @param Container $container A container instance.
         * @return DatabaseSourceConfig
         */
        $container['database/config'] = function (Container $container) {
            $config = $container['config'];
            $databaseIdent = $config['default_database'];
            return $container['databases/config'][$databaseIdent];
        };

        /**
         * The (default) database service, as a PDO object.
         *
         * @param Container $container A container instance.
         * @throws Exception If the database configuration is invalid.
         * @return PDO
         */
        $container['database'] = function (Container $container) {
            $config = $container['config'];
            $databaseIdent = $config['default_database'];
            $databases = $container['databases'];
            if (!isset($databases[$databaseIdent])) {
                throw new Exception(
                    sprintf('The database "%s" is not defined in the "databases" configuration.', $databaseIdent)
                );
            }
            return $databases[$databaseIdent];
        };
    }
1134509
public static function parse(\SplFileInfo $file, ContainerBuilder $container, array $configs = []): array
    {
        return self::proccessFile($file, $container, $configs);
    }
41682
public function prepend(ContainerBuilder $container)
    {
        if ($container->hasExtension('sulu_search')) {
            $container->prependExtensionConfig(
                'sulu_search',
                [
                    'indexes' => [
                        'contact' => [
                            'security_context' => 'sulu.contact.people',
                        ],
                        'account' => [
                            'security_context' => 'sulu.contact.organizations',
                        ],
                    ],
                ]
            );
        }

        if ($container->hasExtension('sulu_media')) {
            $container->prependExtensionConfig(
                'sulu_media',
                [
                    'system_collections' => [
                        'sulu_contact' => [
                            'meta_title' => ['en' => 'Sulu contacts', 'de' => 'Sulu Kontakte'],
                            'collections' => [
                                'contact' => [
                                    'meta_title' => ['en' => 'People', 'de' => 'Personen'],
                                ],
                                'account' => [
                                    'meta_title' => ['en' => 'Organizations', 'de' => 'Organisationen'],
                                ],
                            ],
                        ],
                    ],
                ]
            );
        }

        if ($container->hasExtension('sulu_admin')) {
            $container->prependExtensionConfig(
                'sulu_admin',
                [
                    'lists' => [
                        'directories' => [
                            __DIR__ . '/../Resources/config/lists',
                        ],
                    ],
                    'forms' => [
                        'directories' => [
                            __DIR__ . '/../Resources/config/forms',
                        ],
                    ],
                    'resources' => [
                        'contacts' => [
                            'routes' => [
                                'list' => 'get_contacts',
                                'detail' => 'get_contact',
                            ],
                        ],
                        'accounts' => [
                            'routes' => [
                                'list' => 'get_accounts',
                                'detail' => 'get_account',
                            ],
                        ],
                        'contact_titles' => [
                            'routes' => [
                                'list' => 'get_contact-titles',
                            ],
                        ],
                        'contact_positions' => [
                            'routes' => [
                                'list' => 'get_contact-positions',
                            ],
                        ],
                    ],
                    'field_type_options' => [
                        'single_selection' => [
                            'single_account_selection' => [
                                'default_type' => 'auto_complete',
                                'resource_key' => 'accounts',
                                'types' => [
                                    'auto_complete' => [
                                        'display_property' => 'name',
                                        'search_properties' => ['number', 'name'],
                                    ],
                                    'list_overlay' => [
                                        'adapter' => 'table',
                                        'list_key' => 'accounts',
                                        'display_properties' => ['name'],
                                        'empty_text' => 'sulu_contact.no_account_selected',
                                        'icon' => 'su-house',
                                        'overlay_title' => 'sulu_contact.single_account_selection_overlay_title',
                                    ],
                                ],
                            ],
                            'single_contact_selection' => [
                                'default_type' => 'list_overlay',
                                'resource_key' => 'contacts',
                                'types' => [
                                    'list_overlay' => [
                                        'adapter' => 'table',
                                        'list_key' => 'contacts',
                                        'display_properties' => ['fullName'],
                                        'empty_text' => 'sulu_contact.no_contact_selected',
                                        'icon' => 'su-user',
                                        'overlay_title' => 'sulu_contact.single_contact_selection_overlay_title',
                                    ],
                                ],
                            ],
                            'single_contact_title_selection' => [
                                'default_type' => 'single_select',
                                'resource_key' => 'contact_titles',
                                'types' => [
                                    'single_select' => [
                                        'id_property' => 'id',
                                        'display_property' => 'title',
                                        'overlay_title' => 'sulu_contact.edit_title_overlay_title',
                                    ],
                                ],
                            ],
                            'single_contact_position_selection' => [
                                'default_type' => 'single_select',
                                'resource_key' => 'contact_positions',
                                'types' => [
                                    'single_select' => [
                                        'id_property' => 'id',
                                        'display_property' => 'position',
                                        'overlay_title' => 'sulu_contact.edit_position_overlay_title',
                                    ],
                                ],
                            ],
                        ],
                    ],
                ]
            );
        }
    }
385086
public static function field_loader( $field_type, $file = '' ) {

		if ( isset( self::$loaded[ $field_type ] ) ) {
			$class_vars = get_class_vars( get_class( self::$loaded[ $field_type ] ) );
			// PHP 5.2.x workaround
			self::$field_group = ( isset( $class_vars['group'] ) ? $class_vars['group'] : '' );
			self::$field_type  = $class_vars['type'];

			if ( 'Unknown' !== $class_vars['label'] ) {
				return self::$loaded[ $field_type ];
			}
		}

		include_once PODS_DIR . 'classes/PodsField.php';

		$field_type = self::clean( $field_type, true, true );

		$class_name = ucfirst( $field_type );
		$class_name = "PodsField_{$class_name}";

		$content_dir   = realpath( WP_CONTENT_DIR );
		$plugins_dir   = realpath( WP_PLUGIN_DIR );
		$muplugins_dir = realpath( WPMU_PLUGIN_DIR );
		$abspath_dir   = realpath( ABSPATH );
		$pods_dir      = realpath( PODS_DIR );

		if ( ! class_exists( $class_name ) ) {
			if ( isset( self::$field_types[ $field_type ] ) && ! empty( self::$field_types[ $field_type ]['file'] ) ) {
				$file = realpath( self::$field_types[ $field_type ]['file'] );
			}

			if ( ! empty( $file ) && 0 === strpos( $file, $abspath_dir ) && file_exists( $file ) ) {
				include_once $file;
			} else {
				$file = str_replace( '../', '', apply_filters( 'pods_form_field_include', PODS_DIR . 'classes/fields/' . basename( $field_type ) . '.php', $field_type ) );
				$file = realpath( $file );

				if ( file_exists( $file ) && ( 0 === strpos( $file, $pods_dir ) || 0 === strpos( $file, $content_dir ) || 0 === strpos( $file, $plugins_dir ) || 0 === strpos( $file, $muplugins_dir ) || 0 === strpos( $file, $abspath_dir ) ) ) {
					include_once $file;
				}
			}
		}

		if ( class_exists( $class_name ) ) {
			$class = new $class_name();
		} else {
			$class      = new PodsField();
			$class_name = 'PodsField';
		}

		$class_vars = get_class_vars( $class_name );
		// PHP 5.2.x workaround
		self::$field_group = ( isset( $class_vars['group'] ) ? $class_vars['group'] : '' );
		self::$field_type  = $class_vars['type'];

		self::$loaded[ $field_type ] =& $class;

		return self::$loaded[ $field_type ];
	}
508368
private function getDefinitionDir($type, array $driverConfig, ContainerBuilder $container)
    {
        $defaultDir = sprintf('%s/Resources/As3ModlrBundle', $container->getParameter('kernel.root_dir'));

        $folder = sprintf('%ss', $type);
        $key = sprintf('%s_dir', $type);

        return isset($driverConfig['parameters'][$key])
            ? Utility::locateResource($driverConfig['parameters'][$key], $container)
            : sprintf('%s/%s', $defaultDir, $folder)
        ;
    }
1085481
public function view($id, $type) {
		$params = array(
			'id' => $id,
			'type' => $type
		);
		return $this->master->call('files/view', $params);
	}
649451
protected function prepare(ContainerInterface $container = null, array $arguments = [])
    {
        $result = [];

        foreach ($arguments as $k => $arg) {
            if (is_array($arg)) {
                $result[$k] = $this->prepare($container, $arg);
                continue;
            } elseif ($arg == '@Container') {
                $result[$k] = $container;
                continue;
            } elseif (strpos($arg, '@') !== 0) {
                $result[$k] = $arg;
                continue;
            }

            $arg = substr($arg, 1);

            if (!$container) {
                throw new ContainerException(sprintf('Unable to resolve dependency for "%s" - missing dependency "%s"', $this->class, $arg));
            }

            $result[$k] = $container->get($arg);
        }

        return $result;
    }
883390
public function container($container_link, $options = []) {
		// handling acl_subresource
		if (!empty($options['acl_subresource_remove']) && !$this->tempProcessACLSubresources($options['acl_subresource_remove'], 'Record_View')) {
			$this->misc_settings['acl_subresource_locks'][$container_link]['remove'] = true;
			return;
		}
		if (!empty($options['acl_subresource_edit'])) {
			if ($this->tempProcessACLSubresources($options['acl_subresource_edit'], 'All_Actions')) {
				// nothing
			} else {
				if (!$this->tempProcessACLSubresources($options['acl_subresource_edit'], 'Record_New')) {
					$this->misc_settings['acl_subresource_locks'][$container_link]['no_new'] = true;
				}
				if (!$this->tempProcessACLSubresources($options['acl_subresource_edit'], 'Record_Edit')) {
					$this->misc_settings['acl_subresource_locks'][$container_link]['no_edit'] = true;
				}
				if (!$this->tempProcessACLSubresources($options['acl_subresource_edit'], 'Record_Inactivate')) {
					$this->misc_settings['acl_subresource_locks'][$container_link]['no_inactivate'] = true;
				}
				if (!$this->tempProcessACLSubresources($options['acl_subresource_edit'], 'Record_Delete')) {
					$this->misc_settings['acl_subresource_locks'][$container_link]['no_delete'] = true;
				}
			}
		}
		// see if we have container already
		if (!isset($this->data[$container_link])) {
			$options['container_link'] = $container_link;
			$type = $options['type'] = $options['type'] ?? 'fields';
			// make hidden container last
			if ($container_link == $this::HIDDEN) {
				$options['order'] = 35000;
			}
			// see if we adding a widget
			if (!empty($options['widget'])) {
				// we skip if widgets are not enabled
				$widget = str_replace('detail_', '', $options['widget']);
				$temp = \Object\ACL\Resources::getStatic('widgets', $widget);
				if (empty($temp)) return;
				// handling widgets
				return $this->processWidget($options);
			}
			// processing details
			if ($type == 'details') {
				if (empty($options['details_key']) || empty($options['details_pk'])) {
					Throw new \Exception('Detail key or pk?');
				}
				$options['details_collection_key'] = $options['details_collection_key'] ?? ['details', $options['details_key']];
				$options['details_rendering_type'] = $options['details_rendering_type'] ?? 'grid_with_label';
				$options['details_new_rows'] = $options['details_new_rows'] ?? 0;
			}
			if ($type == 'trees') {
				if (empty($options['details_key']) || empty($options['details_pk'])) {
					Throw new \Exception('Detail key or pk?');
				}
				if (empty($options['details_tree_parent_key']) || empty($options['details_tree_key'])) {
					Throw new \Exception('Detail tree key or parent key?');
				}
				$options['details_collection_key'] = $options['details_collection_key'] ?? ['details', $options['details_key']];
				$options['details_rendering_type'] = $options['details_rendering_type'] ?? 'name_only';
				$options['details_new_rows'] = 0;
			}
			// processing subdetails
			if ($type == 'subdetails' || $type == 'subtrees') {
				if (empty($options['details_key']) || empty($options['details_pk']) || empty($options['details_parent_key'])) {
					Throw new \Exception('Subdetail key, parent key or pk?');
				}
				$options['flag_child'] = true;
				$options['details_collection_key'] = $options['details_collection_key'] ?? ['details', $options['details_parent_key'], 'details', $options['details_key']];
				$options['details_rendering_type'] = $options['details_rendering_type'] ?? 'table';
				$options['details_new_rows'] = $options['details_new_rows'] ?? 0;
			}
			// modal
			if ($type == 'modal') {
				$options['modal_id'] = "form_{$this->form_link}_modal_{$container_link}_dialog";
			}
			$this->data[$container_link] = [
				'options' => $options,
				'order' => $options['order'] ?? 0,
				'type' => $type,
				'flag_child' => !empty($options['flag_child']),
				'default_row_type' => $options['default_row_type'] ?? 'grid',
				'label_name' => $options['label_name'] ?? null,
				'rows' => [],
			];
			// special handling for details
			if ($type == 'details') {
				$model = \Factory::model($options['details_key'], true);
				// if we have relation
				if (!empty($model->relation['field']) && !in_array($model->relation['field'], $model->pk)) {
					$this->element($container_link, $this::HIDDEN, $model->relation['field'], ['label_name' => 'Relation #', 'domain' => 'relation_id_sequence', 'method'=> 'input', 'persistent' => true]);
				}
			}
			/*
			if ($type == 'details' || $type == 'subdetails' || $type == 'trees' || $type == 'subtrees') {
				// if we have autoincrement
				if (!empty($options['details_autoincrement'])) {
					$model = \Factory::model($options['details_key'], true);
					foreach ($options['details_autoincrement'] as $v) {
						$this->element($container_link, $this::HIDDEN, $v, array_merge_hard($model->columns[$v], ['default' => 0]));
					}
				}
			}
			*/
		} else {
			$this->data[$container_link]['options'] = array_merge_hard($this->data[$container_link]['options'] ?? [], $options);
			if (isset($options['order'])) {
				$this->data[$container_link]['order'] = $options['order'];
			}
		}
	}