Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
PackageFactory Class Reference

Public Member Functions

 __construct (ObjectManagerInterface $objectManager, $type=Package::class)
 
 create (array $arguments)
 

Detailed Description

Factory class for Package object

See also
Package

Definition at line 17 of file PackageFactory.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ObjectManagerInterface  $objectManager,
  $type = Package::class 
)

PackageFactory constructor

Parameters
ObjectManagerInterface$objectManager
string$type

Definition at line 32 of file PackageFactory.php.

33  {
34  $this->objectManager = $objectManager;
35  $this->type = $type;
36  }
$type
Definition: item.phtml:13

Member Function Documentation

◆ create()

create ( array  $arguments)

Create new instance of Package object

Since returned type can be configured via DI configuration, the method does check type of created object and throws exception if that instance is not successor of \Magento\Deploy\Package

Parameters
array$arguments
Returns
Package
Exceptions
LocalizedException

Definition at line 48 of file PackageFactory.php.

49  {
50  $package = $this->objectManager->create($this->type, $arguments);
51  if (!$package instanceof Package) {
52  throw new LocalizedException(
53  new Phrase("Wrong type specified: '%1'", [$this->type])
54  );
55  }
56  return $package;
57  }
$arguments

The documentation for this class was generated from the following file: