Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adapted to latest changes in Discovery #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
],
"require": {
"php": "^5.3.9|^7.0",
"puli/repository": "^1.0-beta9",
"puli/discovery": "^1.0-beta9",
"puli/repository": "^1.0-beta10@dev",
"puli/discovery": "^1.0-beta10@dev",
"puli/url-generator": "^1.0-beta4",
"webmozart/json": "^1.3@dev",
"webmozart/path-util": "^2.2.3",
Expand Down
33 changes: 0 additions & 33 deletions src/Api/Discovery/BindingDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ public function isLoaded()
return null !== $this->state;
}

/**
* Returns the UUID of the described binding.
*
* @return Uuid The UUID.
*/
public function getUuid()
{
return $this->binding->getUuid();
}

/**
* Returns the name of the bound type.
*
Expand Down Expand Up @@ -260,27 +250,6 @@ public function isEnabled()
return BindingState::ENABLED === $this->state;
}

/**
* Returns whether the binding is disabled.
*
* The method {@link load()} needs to be called before calling this method,
* otherwise an exception is thrown.
*
* @return bool Returns `true` if the state is {@link BindingState::DISABLED}.
*
* @throws NotLoadedException If the descriptor is not loaded.
*
* @see BindingState::DISABLED
*/
public function isDisabled()
{
if (null === $this->state) {
throw new NotLoadedException('The binding descriptor is not loaded.');
}

return BindingState::DISABLED === $this->state;
}

/**
* Returns whether the type of the binding does not exist.
*
Expand Down Expand Up @@ -354,8 +323,6 @@ private function refreshState()
$this->state = BindingState::INVALID;
} elseif ($this->containingModule instanceof RootModule) {
$this->state = BindingState::ENABLED;
} elseif ($this->containingModule->getInstallInfo()->hasDisabledBindingUuid($this->binding->getUuid())) {
$this->state = BindingState::DISABLED;
} else {
$this->state = BindingState::ENABLED;
}
Expand Down
12 changes: 3 additions & 9 deletions src/Api/Discovery/BindingState.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,20 @@ final class BindingState
*/
const ENABLED = 1;

/**
* State: The binding is disabled.
*/
const DISABLED = 2;

/**
* State: The binding's type does not exist.
*/
const TYPE_NOT_FOUND = 3;
const TYPE_NOT_FOUND = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the old numbers? To preserve BC

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's needed. These values are used in memory only.


/**
* State: The binding's type does not exist.
*/
const TYPE_NOT_ENABLED = 4;
const TYPE_NOT_ENABLED = 3;

/**
* State: The binding does not match the constraints of the binding type.
*/
const INVALID = 5;
const INVALID = 4;

/**
* Returns all binding states.
Expand All @@ -54,7 +49,6 @@ public static function all()
{
return array(
self::ENABLED,
self::DISABLED,
self::TYPE_NOT_FOUND,
self::TYPE_NOT_ENABLED,
self::INVALID,
Expand Down
24 changes: 23 additions & 1 deletion src/Api/Discovery/BindingTypeDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class BindingTypeDescriptor
*/
private $parameterDescriptions = array();

/**
* @var bool
*/
private $bindingOrderStrict = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct


/**
* @var int
*/
Expand All @@ -67,17 +72,22 @@ class BindingTypeDescriptor
* @param string[] $parameterDescriptions Human-readable descriptions
* indexed by the type's parameter
* names.
* @param bool $bindingOrderStrict Whether modules containing the
* bindings of this type must be
* strictly ordered with "depend"
* statements.
*
* @throws NoSuchParameterException If a description is passed for an unset
* parameter.
*/
public function __construct(BindingType $type, $description = null, array $parameterDescriptions = array())
public function __construct(BindingType $type, $description = null, array $parameterDescriptions = array(), $bindingOrderStrict = false)
{
Assert::nullOrStringNotEmpty($description, 'The description must be a non-empty string or null. Got: %s');
Assert::allStringNotEmpty($parameterDescriptions, 'The parameter description must be a non-empty string. Got: %s');

$this->type = $type;
$this->description = $description;
$this->bindingOrderStrict = (bool) $bindingOrderStrict;

foreach ($parameterDescriptions as $parameterName => $parameterDescription) {
if (!$type->hasParameter($parameterName)) {
Expand Down Expand Up @@ -245,6 +255,18 @@ public function hasParameterDescriptions()
return count($this->parameterDescriptions) > 0;
}

/**
* Returns whether the modules containing the bindings of this type must
* be strictly ordered.
*
* @return boolean Returns `true` if the modules must be strictly ordered
* and `false` otherwise.
*/
public function isBindingOrderStrict()
{
return $this->bindingOrderStrict;
}

/**
* Returns the module that contains the descriptor.
*
Expand Down
95 changes: 0 additions & 95 deletions src/Api/Discovery/DiscoveryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
namespace Puli\Manager\Api\Discovery;

use Puli\Manager\Api\Context\ProjectContext;
use Puli\Manager\Api\NonRootModuleExpectedException;
use Rhumsaa\Uuid\Uuid;
use Webmozart\Expression\Expression;

/**
Expand Down Expand Up @@ -210,16 +208,6 @@ public function hasTypeDescriptors(Expression $expr = null);
*/
public function addRootBindingDescriptor(BindingDescriptor $bindingDescriptor, $flags = 0);

/**
* Removes a binding from the root module.
*
* The binding descriptor is removed from the root module file. If the
* binding is not found, this method does nothing.
*
* @param Uuid $uuid The UUID of the binding.
*/
public function removeRootBindingDescriptor(Uuid $uuid);

/**
* Removes all bindings matching the given expression.
*
Expand All @@ -236,17 +224,6 @@ public function removeRootBindingDescriptors(Expression $expr);
*/
public function clearRootBindingDescriptors();

/**
* Returns the binding with the given UUID in the root module.
*
* @param Uuid $uuid The UUID of the binding.
*
* @return BindingDescriptor The binding.
*
* @throws NoSuchBindingException If the binding does not exist.
*/
public function getRootBindingDescriptor(Uuid $uuid);

/**
* Returns all bindings in the root module.
*
Expand All @@ -263,17 +240,6 @@ public function getRootBindingDescriptors();
*/
public function findRootBindingDescriptors(Expression $expr);

/**
* Returns whether the binding with the given UUID exists in the root
* module.
*
* @param Uuid $uuid The UUID of the binding.
*
* @return bool Returns `true` if the binding exists in the root module and
* `false` otherwise.
*/
public function hasRootBindingDescriptor(Uuid $uuid);

/**
* Returns whether the manager has any bindings in the root module.
*
Expand All @@ -289,58 +255,6 @@ public function hasRootBindingDescriptor(Uuid $uuid);
*/
public function hasRootBindingDescriptors(Expression $expr = null);

/**
* Enables a binding.
*
* @param Uuid $uuid The UUID of the binding.
*
* @throws NoSuchBindingException If the binding does not exist.
* @throws NoSuchTypeException If the type referenced by the descriptor does
* not exist.
* @throws TypeNotEnabledException If the type referenced by the descriptor
* is not enabled.
* @throws NonRootModuleExpectedException If the binding is in the root
* module. Can only enable bindings
* in non-root modules, because the
* bindings in the root module are
* implicitly enabled.
*/
public function enableBindingDescriptor(Uuid $uuid);

/**
* Disables a binding.
*
* @param Uuid $uuid The UUID of the binding.
*
* @throws NoSuchBindingException If the binding does not exist.
* @throws NoSuchTypeException If the type referenced by the descriptor does
* not exist.
* @throws TypeNotEnabledException If the type referenced by the descriptor
* is not enabled.
* @throws NonRootModuleExpectedException If the binding is in the root
* module. Can only disable bindings
* in non-root modules, because the
* bindings in the root module are
* implicitly enabled.
*/
public function disableBindingDescriptor(Uuid $uuid);

/**
* Removes disabled binding UUIDs that were not found in any module.
*/
public function removeObsoleteDisabledBindingDescriptors();

/**
* Returns the binding with the given UUID.
*
* @param Uuid $uuid The UUID of the binding.
*
* @return BindingDescriptor The binding.
*
* @throws NoSuchBindingException If the binding does not exist.
*/
public function getBindingDescriptor(Uuid $uuid);

/**
* Returns all bindings.
*
Expand All @@ -357,15 +271,6 @@ public function getBindingDescriptors();
*/
public function findBindingDescriptors(Expression $expr);

/**
* Returns whether the binding with the given UUID exists.
*
* @param Uuid $uuid The UUID of the binding.
*
* @return bool Returns `true` if the binding exists and `false` otherwise.
*/
public function hasBindingDescriptor(Uuid $uuid);

/**
* Returns whether the manager has any bindings.
*
Expand Down
42 changes: 0 additions & 42 deletions src/Api/Discovery/DuplicateBindingException.php

This file was deleted.

61 changes: 0 additions & 61 deletions src/Api/Discovery/NoSuchBindingException.php

This file was deleted.

Loading