-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQl-44: prototype of format strategy
Signed-off-by: vitaliyboyko <v.boyko@atwix.com>
- Loading branch information
vitaliyboyko
committed
Sep 16, 2018
1 parent
506c148
commit 8aedb95
Showing
5 changed files
with
152 additions
and
27 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
43 changes: 43 additions & 0 deletions
43
.../Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute/FormatFactory.php
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,43 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextareaAttribute; | ||
|
||
use Magento\Framework\ObjectManagerInterface; | ||
|
||
class FormatFactory | ||
{ | ||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @param ObjectManagerInterface $objectManager | ||
*/ | ||
public function __construct(ObjectManagerInterface $objectManager) | ||
{ | ||
$this->objectManager = $objectManager; | ||
} | ||
|
||
/** | ||
* @param string $formatIdentifier | ||
* @param array $data | ||
* @return FormatInterface | ||
*/ | ||
public function create(string $formatIdentifier, $data = []) : FormatInterface | ||
{ | ||
$formatClassName = 'Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextareaAttribute\\' . ucfirst($formatIdentifier); | ||
$formatInstance = $this->objectManager->create($formatClassName, $data); | ||
if (false == $formatInstance instanceof FormatInterface) { | ||
throw new \InvalidArgumentException( | ||
$formatInstance . ' is not instance of \Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextareaAttribute\FormatInterface' | ||
); | ||
} | ||
return $formatInstance; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...agento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute/FormatInterface.php
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,23 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextareaAttribute; | ||
|
||
use Magento\Catalog\Model\Product as ModelProduct; | ||
|
||
interface FormatInterface | ||
{ | ||
/** | ||
* @param ModelProduct $product | ||
* @param string $fieldName | ||
* @return string | ||
*/ | ||
public function getContent( | ||
ModelProduct $product, | ||
string $fieldName | ||
): string; | ||
} |
47 changes: 47 additions & 0 deletions
47
app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute/Html.php
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,47 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextareaAttribute; | ||
|
||
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; | ||
use Magento\Catalog\Helper\Output as OutputHelper; | ||
use Magento\Catalog\Model\Product as ModelProduct; | ||
|
||
class Html implements FormatInterface | ||
{ | ||
/** | ||
* @var ValueFactory | ||
*/ | ||
private $valueFactory; | ||
|
||
/** | ||
* @var OutputHelper | ||
*/ | ||
private $outputHelper; | ||
|
||
/** | ||
* @param ValueFactory $valueFactory | ||
* @param OutputHelper $outputHelper | ||
*/ | ||
public function __construct( | ||
ValueFactory $valueFactory, | ||
OutputHelper $outputHelper | ||
) { | ||
$this->valueFactory = $valueFactory; | ||
$this->outputHelper = $outputHelper; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getContent( | ||
ModelProduct $product, | ||
string $fieldName | ||
): string { | ||
return $this->outputHelper->productAttribute($product, $product->getData($fieldName), $fieldName); | ||
} | ||
} |
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