-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Prometee/add-product-aware-on-brand
Add fixture with unit test
- Loading branch information
Showing
17 changed files
with
449 additions
and
75 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
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Loevgaard\SyliusBrandPlugin\Assigner; | ||
|
||
use Loevgaard\SyliusBrandPlugin\Entity\ProductsAwareInterface; | ||
|
||
final class ProductsAssigner implements ProductsAssignerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function assign(ProductsAwareInterface $productsAware, array $products): void | ||
{ | ||
foreach ($products as $product) { | ||
if (null !== $product) { | ||
$productsAware->addProduct($product); | ||
} | ||
} | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Loevgaard\SyliusBrandPlugin\Assigner; | ||
|
||
use Loevgaard\SyliusBrandPlugin\Entity\BrandAwareInterface; | ||
use Loevgaard\SyliusBrandPlugin\Entity\ProductsAwareInterface; | ||
|
||
interface ProductsAssignerInterface | ||
{ | ||
/** | ||
* @param ProductsAwareInterface $productsAware | ||
* @param BrandAwareInterface[] $products | ||
*/ | ||
public function assign(ProductsAwareInterface $productsAware, array $products): void; | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Loevgaard\SyliusBrandPlugin\Entity; | ||
|
||
use Sylius\Component\Core\Model\ImagesAwareInterface as BaseImagesAwareInterface; | ||
|
||
interface ImagesAwareInterface extends BaseImagesAwareInterface | ||
{ | ||
public function initializeImagesCollection(): void; | ||
} |
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,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Loevgaard\SyliusBrandPlugin\Entity; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Sylius\Component\Core\Model\ImageInterface; | ||
|
||
trait ImagesAwareTrait | ||
{ | ||
|
||
/** @var Collection|ImageInterface[] */ | ||
protected $images; | ||
|
||
public function initializeImagesCollection(): void | ||
{ | ||
$this->images = new ArrayCollection(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getImages(): Collection | ||
{ | ||
return $this->images; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getImagesByType(string $type): Collection | ||
{ | ||
return $this->images->filter(function (ImageInterface $image) use ($type) { | ||
return $type === $image->getType(); | ||
}); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function hasImages(): bool | ||
{ | ||
return !$this->images->isEmpty(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function hasImage(ImageInterface $image): bool | ||
{ | ||
return $this->images->contains($image); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function addImage(ImageInterface $image): void | ||
{ | ||
if (false === $this->hasImage($image)) { | ||
$image->setOwner($this); | ||
$this->images->add($image); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function removeImage(ImageInterface $image): void | ||
{ | ||
if ($this->hasImage($image)) { | ||
$image->setOwner(null); | ||
$this->images->removeElement($image); | ||
} | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Loevgaard\SyliusBrandPlugin\Entity; | ||
|
||
use Doctrine\Common\Collections\Collection; | ||
use Sylius\Component\Core\Model\ProductInterface; | ||
|
||
interface ProductsAwareInterface | ||
{ | ||
public function initializeProductsCollection(): void; | ||
|
||
/** | ||
* @return Collection|BrandAwareInterface[]|ProductInterface[] | ||
*/ | ||
public function getProducts(): Collection; | ||
|
||
/** | ||
* @param BrandAwareInterface $product | ||
* @return bool | ||
*/ | ||
public function hasProduct(BrandAwareInterface $product): bool; | ||
|
||
/** | ||
* @param BrandAwareInterface $product | ||
*/ | ||
public function addProduct(BrandAwareInterface $product): void; | ||
|
||
/** | ||
* @param BrandAwareInterface $product | ||
*/ | ||
public function removeProduct(BrandAwareInterface $product): void; | ||
} |
Oops, something went wrong.