123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549 |
- <?php
- namespace Drupal\features;
- /**
- * Defines a value object for storing package related data.
- *
- * A package contains of a name, version number, containing config etc.
- */
- class Package {
- /**
- * @var string
- */
- protected $machineName = '';
- /**
- * @var string
- */
- protected $name = '';
- /**
- * @var string
- */
- protected $description = '';
- /**
- * @todo This could be fetched from the extension object.
- *
- * @var string
- */
- protected $version = '';
- /**
- * @var string
- */
- protected $core = '8.x';
- /**
- * @todo This could be fetched from the extension object.
- *
- * @var string
- */
- protected $type = 'module';
- /**
- * @var string[]
- */
- protected $themes = [];
- /**
- * @var string
- */
- protected $bundle;
- /**
- * @var string[]
- */
- protected $excluded = [];
- /**
- * @var string[]|bool
- */
- protected $required = false;
- /**
- * @var array
- */
- protected $info = [];
- /**
- * @var string[]
- */
- protected $dependencies = [];
- /**
- * @todo This could be fetched from the extension object.
- *
- * @var int
- */
- protected $status;
- /**
- * @var int
- */
- protected $state;
- /**
- * @todo This could be fetched from the extension object.
- *
- * @var string
- */
- protected $directory;
- /**
- * @var string[]
- */
- protected $files;
- /**
- * @var \Drupal\Core\Extension\Extension
- */
- protected $extension;
- /**
- * @var string[]
- */
- protected $config = [];
- /**
- * @var string[]
- */
- protected $configOrig = [];
- /**
- * Creates a new Package instance.
- *
- * @param string $machine_name
- * The machine name.
- * @param array $additional_properties
- * (optional) Additional properties of the object.
- */
- public function __construct($machine_name, array $additional_properties = []) {
- $this->machineName = $machine_name;
- $properties = get_object_vars($this);
- foreach ($additional_properties as $property => $value) {
- if (!array_key_exists($property, $properties)) {
- throw new \InvalidArgumentException('Invalid property: ' . $property);
- }
- $this->{$property} = $value;
- }
- }
- /**
- * @return mixed
- */
- public function getMachineName() {
- return $this->machineName;
- }
- /**
- * Return TRUE if the machine_name already has the bundle prefix.
- *
- * @param string $machine_name
- * @param string $bundle_name
- * @return bool
- */
- protected function inBundle($machine_name, $bundle_name) {
- return strpos($machine_name, $bundle_name . '_') === 0;
- }
- /**
- * @return string
- */
- public function getFullName() {
- if (empty($this->bundle) || $this->inBundle($this->machineName, $this->bundle)) {
- return $this->machineName;
- }
- else {
- return $this->bundle . '_' . $this->machineName;
- }
- }
- /**
- * @return string
- */
- public function getName() {
- return $this->name;
- }
- /**
- * @return string
- */
- public function getDescription() {
- return $this->description;
- }
- /**
- * @return string
- */
- public function getVersion() {
- return $this->version;
- }
- /**
- * @return int
- */
- public function getStatus() {
- return $this->status;
- }
- /**
- * @return string[]
- */
- public function getConfig() {
- return $this->config;
- }
- /**
- * Append a new filename.
- *
- * @param string $config
- *
- * @return $this
- */
- public function appendConfig($config) {
- $this->config[] = $config;
- $this->config = array_unique($this->config);
- return $this;
- }
- public function removeConfig($name) {
- $this->config = array_diff($this->config, [$name]);
- return $this;
- }
- /**
- * @return string
- */
- public function getBundle() {
- return $this->bundle;
- }
- /**
- * @return string[]
- */
- public function getExcluded() {
- return $this->excluded;
- }
- /**
- * @return string[]
- */
- public function getRequired() {
- return $this->required;
- }
- /**
- * @return bool
- */
- public function getRequiredAll() {
- $config_orig = $this->getConfigOrig();
- $info = is_array($this->required) ? $this->required : array();
- $diff = array_diff($config_orig, $info);
- // Mark all as required if required:true, or required is empty, or
- // if required contains all the exported config
- return empty($diff) || empty($info);
- }
- /**
- * @return string[]
- */
- public function getConfigOrig() {
- return $this->configOrig;
- }
- /**
- * @return string
- */
- public function getCore() {
- return $this->core;
- }
- /**
- * @return string
- */
- public function getType() {
- return $this->type;
- }
- /**
- * @return \string[]
- */
- public function getThemes() {
- return $this->themes;
- }
- /**
- * @return array
- */
- public function getInfo() {
- return $this->info;
- }
- /**
- * @return mixed
- */
- public function getState() {
- return $this->state;
- }
- /**
- * @return string
- */
- public function getDirectory() {
- return $this->directory;
- }
- /**
- * @return mixed
- */
- public function getFiles() {
- return $this->files;
- }
- /**
- * @return \Drupal\Core\Extension\Extension
- */
- public function getExtension() {
- return $this->extension;
- }
- public function getDependencies() {
- return $this->dependencies;
- }
- public function removeDependency($name) {
- $this->dependencies = array_diff($this->dependencies, [$name]);
- return $this;
- }
- public function getDependencyInfo() {
- return isset($this->info['dependencies']) ? $this->info['dependencies'] : [];
- }
- /**
- * Returns the features info.
- *
- * @return array
- */
- public function getFeaturesInfo() {
- $info = [];
- if (!empty($this->bundle)) {
- $info['bundle'] = $this->bundle;
- }
- if (!empty($this->excluded)) {
- $info['excluded'] = $this->excluded;
- }
- if ($this->required !== FALSE) {
- $info['required'] = $this->required;
- }
- return $info;
- }
- /**
- * Sets a new machine name.
- *
- * @param string $machine_name
- * The machine name
- *
- * @return $this
- */
- public function setMachineName($machine_name) {
- $this->machineName = $machine_name;
- return $this;
- }
- /**
- * @param string $name
- *
- * @return $this
- */
- public function setName($name) {
- $this->name = $name;
- return $this;
- }
- /**
- * @param string $description
- *
- * @return $this
- */
- public function setDescription($description) {
- $this->description = $description;
- return $this;
- }
- /**
- * @param string $version
- *
- * @return $this
- */
- public function setVersion($version) {
- $this->version = $version;
- return $this;
- }
- /**
- * @param string $bundle
- *
- * @return $this
- */
- public function setBundle($bundle) {
- $this->bundle = $bundle;
- return $this;
- }
- /**
- * @param array $info
- *
- * @return $this
- */
- public function setInfo($info) {
- $this->info = $info;
- return $this;
- }
- /**
- * @param \string[] $features_info
- *
- * @return $this
- */
- public function setFeaturesInfo($features_info) {
- if (isset($features_info['bundle'])) {
- $this->setBundle($features_info['bundle']);
- }
- $this->setRequired(isset($features_info['required']) ? $features_info['required'] : false);
- $this->setExcluded(isset($features_info['excluded']) ? $features_info['excluded'] : array());
- return $this;
- }
- /**
- * @param \string[] $dependencies
- *
- * @return $this
- */
- public function setDependencies($dependencies) {
- $this->dependencies = $dependencies;
- return $this;
- }
- /**
- * @param string $dependency
- *
- * return $this
- */
- public function appendDependency($dependency) {
- $this->dependencies[] = $dependency;
- return $this;
- }
- /**
- * @param int $status
- *
- * @return $this
- */
- public function setStatus($status) {
- $this->status = $status;
- return $this;
- }
- /**
- * @param \string[] $config
- *
- * @return $this
- */
- public function setConfig($config) {
- $this->config = $config;
- return $this;
- }
- /**
- * @param bool $excluded
- */
- public function setExcluded($excluded) {
- $this->excluded = $excluded;
- }
- /**
- * @param bool $required
- */
- public function setRequired($required) {
- $this->required = $required;
- }
- /**
- * @param string $core
- */
- public function setCore($core) {
- $this->core = $core;
- }
- /**
- * @param string $type
- */
- public function setType($type) {
- $this->type = $type;
- }
- /**
- * @param \string[] $themes
- */
- public function setThemes($themes) {
- $this->themes = $themes;
- }
- /**
- * @param int $state
- */
- public function setState($state) {
- $this->state = $state;
- }
- /**
- * @param string $directory
- */
- public function setDirectory($directory) {
- $this->directory = $directory;
- }
- /**
- * @param \string[] $files
- */
- public function setFiles($files) {
- $this->files = $files;
- }
- /**
- * @param array $file_array
- *
- * @return $this
- */
- public function appendFile(array $file_array, $key = NULL) {
- if (!isset($key)) {
- $this->files[] = $file_array;
- }
- else {
- $this->files[$key] = $file_array;
- }
- return $this;
- }
- /**
- * @param \Drupal\Core\Extension\Extension $extension
- */
- public function setExtension($extension) {
- $this->extension = $extension;
- }
- /**
- * @param \string[] $configOrig
- */
- public function setConfigOrig($configOrig) {
- $this->configOrig = $configOrig;
- }
- }
|