-
-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BindTargets] Added BindTargets Task (#1476)
- Loading branch information
Showing
6 changed files
with
177 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the LGPL. For more information please see | ||
* <http://phing.info>. | ||
*/ | ||
|
||
/** | ||
* Simple task which bind some targets to some defined extension point | ||
* | ||
* @author Siad Ardroumli <siad.ardroumli@gmail.com> | ||
* @package phing.tasks.system | ||
*/ | ||
class BindTargets extends Task | ||
{ | ||
/** @var string $extensionPoint */ | ||
private $extensionPoint; | ||
|
||
/** @var Target[] $targets */ | ||
private $targets = []; | ||
|
||
private $onMissingExtensionPoint = 'fail'; | ||
|
||
public function setExtensionPoint(string $extensionPoint) | ||
{ | ||
$this->extensionPoint = $extensionPoint; | ||
} | ||
|
||
public function setOnMissingExtensionPoint(string $onMissingExtensionPoint) | ||
{ | ||
if (!in_array($onMissingExtensionPoint, ['fail', 'warn', 'ignore'], true)) { | ||
throw new BuildException("Invalid onMissingExtensionPoint: " . $onMissingExtensionPoint); | ||
} | ||
$this->onMissingExtensionPoint = $onMissingExtensionPoint; | ||
} | ||
|
||
public function setTargets(string $target) | ||
{ | ||
$this->targets = array_values(array_filter(array_map('trim', explode(',', $target)))); | ||
} | ||
|
||
public function main() | ||
{ | ||
if ($this->extensionPoint === null) { | ||
throw new BuildException('extensionPoint required', $this->getLocation()); | ||
} | ||
|
||
if ($this->getOwningTarget() === null || "" !== $this->getOwningTarget()->getName()) { | ||
throw new BuildException('bindtargets only allowed as a top-level task'); | ||
} | ||
|
||
/** @var PhingXMLContext $ctx */ | ||
$ctx = $this->getProject()->getReference(ProjectConfigurator::PARSING_CONTEXT_REFERENCE); | ||
|
||
foreach ($this->targets as $target) { | ||
$ctx->addExtensionPoint([$this->extensionPoint, $target, $this->onMissingExtensionPoint, null]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the LGPL. For more information please see | ||
* <http://phing.info>. | ||
*/ | ||
|
||
/** | ||
* Tests the BindTargets Task | ||
* | ||
* @author Siad Ardroumli <siad.ardroumli@gmail.com> | ||
* @package phing.tasks.system | ||
*/ | ||
class BindTargetsTest extends BuildFileTest | ||
{ | ||
public function setUp(): void | ||
{ | ||
$this->configureProject( | ||
PHING_TEST_BASE . '/etc/tasks/system/BindTargets.xml' | ||
); | ||
} | ||
|
||
public function testBind() | ||
{ | ||
$this->executeTarget(__FUNCTION__); | ||
|
||
$this->assertInLogs('bound #1'); | ||
$this->assertInLogs('bound #2'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
~ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
~ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
~ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
~ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
~ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
~ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
~ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
~ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
~ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
~ | ||
~ This software consists of voluntary contributions made by many individuals | ||
~ and is licensed under the LGPL. For more information please see | ||
~ <http://phing.info>. | ||
--> | ||
|
||
<project name="BindTargets" default="invalid"> | ||
|
||
<target name="invalid"> | ||
<fail>This file should only be run via a testcase</fail> | ||
</target> | ||
|
||
<extension-point name="extension" /> | ||
<bindtargets targets="bound,bound2" extensionpoint="extension" onmissingextensionpoint="warn" /> | ||
<target name="testBind" depends="extension" /> | ||
|
||
<target name="bound"> | ||
<property name="test-bound" value="bound #1" /> | ||
<echo msg="${test-bound}" /> | ||
</target> | ||
|
||
<target name="bound2"> | ||
<property name="test-bound2" value="bound #2" /> | ||
<echo msg="${test-bound2}" /> | ||
</target> | ||
</project> |