This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleMSC\Api;
interface AllSoapAndRestInterface
{
/**
* @param int $itemId
* @return \Magento\TestModuleMSC\Api\Data\ItemInterface
*/
public function item($itemId);
/**
* @param string $name
* @return \Magento\TestModuleMSC\Api\Data\ItemInterface
*/
public function create($name);
/**
* @param \Magento\TestModuleMSC\Api\Data\ItemInterface $entityItem
* @return \Magento\TestModuleMSC\Api\Data\ItemInterface
*/
public function update(\Magento\TestModuleMSC\Api\Data\ItemInterface $entityItem);
/**
* @return \Magento\TestModuleMSC\Api\Data\ItemInterface[]
*/
public function items();
/**
* @param string $name
* @return \Magento\TestModuleMSC\Api\Data\ItemInterface
*/
public function testOptionalParam($name = null);
/**
* @param \Magento\TestModuleMSC\Api\Data\ItemInterface $entityItem
* @return \Magento\TestModuleMSC\Api\Data\ItemInterface
*/
public function itemAnyType(\Magento\TestModuleMSC\Api\Data\ItemInterface $entityItem);
/**
* @return \Magento\TestModuleMSC\Api\Data\ItemInterface
*/
public function getPreconfiguredItem();
}
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleMSC\Api\Data;
interface CustomAttributeDataObjectInterface extends \Magento\Framework\Api\ExtensibleDataInterface
{
const NAME = 'name';
/**
* @return string
*/
public function getName();
/**
* @param string $name
* @return $this
*/
public function setName($name);
}
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleMSC\Api\Data;
interface CustomAttributeNestedDataObjectInterface extends \Magento\Framework\Api\ExtensibleDataInterface
{
/**
* @return string
*/
public function getName();
/**
* @param string $name
* @return $this
*/
public function setName($name);
}
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleMSC\Api\Data;
interface ItemInterface extends \Magento\Framework\Api\ExtensibleDataInterface
{
/**
* @return int
*/
public function getItemId();
/**
* @param int $itemId
* @return $this
*/
public function setItemId($itemId);
/**
* @return string
*/
public function getName();
/**
* @param string $name
* @return $this
*/
public function setName($name);
}
@@ -0,0 +1,105 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleMSC\Model;
use Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterfaceFactory;
use Magento\TestModuleMSC\Api\Data\ItemInterfaceFactory;
class AllSoapAndRest implements \Magento\TestModuleMSC\Api\AllSoapAndRestInterface
{
/**
* @var ItemInterfaceFactory
*/
protected $itemDataFactory;
/**
* @var CustomAttributeDataObjectInterfaceFactory
*/
protected $customAttributeDataObjectDataFactory;
/**
* @param ItemInterfaceFactory $itemDataFactory
* @param CustomAttributeDataObjectInterfaceFactory $customAttributeNestedDataObjectFactory
*/
public function __construct(
ItemInterfaceFactory $itemDataFactory,
CustomAttributeDataObjectInterfaceFactory $customAttributeNestedDataObjectFactory
) {
$this->itemDataFactory = $itemDataFactory;
$this->customAttributeDataObjectDataFactory = $customAttributeNestedDataObjectFactory;
}
/**
* {@inheritdoc}
*/
public function item($itemId)
{
return $this->itemDataFactory->create()->setItemId($itemId)->setName('testProduct1');
}
/**
* {@inheritdoc}
*/
public function items()
{
$result1 = $this->itemDataFactory->create()->setItemId(1)->setName('testProduct1');
$result2 = $this->itemDataFactory->create()->setItemId(2)->setName('testProduct2');
return [$result1, $result2];
}
/**
* {@inheritdoc}
*/
public function create($name)
{
return $this->itemDataFactory->create()->setItemId(rand())->setName($name);
}
/**
* {@inheritdoc}
*/
public function update(\Magento\TestModuleMSC\Api\Data\ItemInterface $entityItem)
{
return $this->itemDataFactory->create()->setItemId($entityItem->getItemId())
->setName('Updated' . $entityItem->getName());
}
public function testOptionalParam($name = null)
{
if ($name === null) {
return $this->itemDataFactory->create()->setItemId(3)->setName('No Name');
} else {
return $this->itemDataFactory->create()->setItemId(3)->setName($name);
}
}
/**
* {@inheritdoc}
*/
public function itemAnyType(\Magento\TestModuleMSC\Api\Data\ItemInterface $entityItem)
{
return $entityItem;
}
/**
* {@inheritdoc}
*/
public function getPreconfiguredItem()
{
$customAttributeDataObject = $this->customAttributeDataObjectDataFactory->create()
->setName('nameValue')
->setCustomAttribute('custom_attribute_int', 1);
$item = $this->itemDataFactory->create()
->setItemId(1)
->setName('testProductAnyType')
->setCustomAttribute('custom_attribute_data_object', $customAttributeDataObject)
->setCustomAttribute('custom_attribute_string', 'someStringValue');
return $item;
}
}
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleMSC\Model\Data;
use Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface;
use Magento\Framework\Api\AbstractExtensibleObject;
/**
* Class CustomAttributeDataObject
*
* @method \Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectExtensionInterface getExtensionAttributes()
*/
class CustomAttributeDataObject extends AbstractExtensibleObject implements CustomAttributeDataObjectInterface
{
/**
* @return string
*/
public function getName()
{
return $this->_data['name'];
}
/**
* @param string $name
* @return $this
*/
public function setName($name)
{
return $this->setData('name', $name);
}
}
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleMSC\Model\Data;
use Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface;
/**
* Class CustomAttributeNestedDataObject
*
* @method \Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectExtensionInterface getExtensionAttributes()
*/
class CustomAttributeNestedDataObject extends \Magento\Framework\Model\AbstractExtensibleModel implements
CustomAttributeNestedDataObjectInterface
{
/**
* @return string
*/
public function getName()
{
return $this->_data['name'];
}
/**
* @param string $name
* @return $this
*/
public function setName($name)
{
return $this->setData('name', $name);
}
}
@@ -0,0 +1,66 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleMSC\Model\Data\Eav;
use Magento\Framework\Api\AbstractExtensibleObject;
use Magento\Framework\Api\MetadataObjectInterface;
/**
* Class AttributeMetadata
*/
class AttributeMetadata extends AbstractExtensibleObject implements MetadataObjectInterface
{
/**#@+
* Constants used as keys into $_data
*/
const ATTRIBUTE_ID = 'attribute_id';
const ATTRIBUTE_CODE = 'attribute_code';
/**#@-*/
/**
* Retrieve id of the attribute.
*
* @return string|null
*/
public function getAttributeId()
{
return $this->_get(self::ATTRIBUTE_ID);
}
/**
* Set id of the attribute.
*
* @param string $attributeId
* @return $this
*/
public function setAttributeId($attributeId)
{
return $this->setData(self::ATTRIBUTE_ID, $attributeId);
}
/**
* Retrieve code of the attribute.
*
* @return string|null
*/
public function getAttributeCode()
{
return $this->_get(self::ATTRIBUTE_CODE);
}
/**
* Set code of the attribute.
*
* @param string $attributeCode
* @return $this
*/
public function setAttributeCode($attributeCode)
{
return $this->setData(self::ATTRIBUTE_CODE, $attributeCode);
}
}
@@ -0,0 +1,51 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleMSC\Model\Data;
use Magento\TestModuleMSC\Api\Data\ItemInterface;
/**
* Class Item
*
* @method \Magento\TestModuleMSC\Api\Data\ItemExtensionInterface getExtensionAttributes()
*/
class Item extends \Magento\Framework\Model\AbstractExtensibleModel implements ItemInterface
{
/**
* @return int
*/
public function getItemId()
{
return $this->_data['item_id'];
}
/**
* @param int $itemId
* @return $this
*/
public function setItemId($itemId)
{
return $this->setData('item_id', $itemId);
}
/**
* @return string
*/
public function getName()
{
return $this->_data['name'];
}
/**
* @param string $name
* @return $this
*/
public function setName($name)
{
return $this->setData('name', $name);
}
}
@@ -0,0 +1,23 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestModuleMSC\Model\ResourceModel;
/**
* Sample resource model
*/
class Item extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
* Initialize connection and define main table
*
* @return void
*/
protected function _construct()
{
$this->_init('dummy_item', 'dummy_item_id');
}
}
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Magento_TestModuleMSC::all" title="TestModuleMSC" sortOrder="1">
<resource id="Magento_TestModuleMSC::resource1" title="Resource1" sortOrder="20"/>
<resource id="Magento_TestModuleMSC::resource2" title="Resource2" sortOrder="10"/>
<resource id="Magento_TestModuleMSC::resource3" title="Resource3" sortOrder="30"/>
</resource>
</resource>
</resources>
</acl>
</config>
@@ -0,0 +1,58 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" type="Magento\TestModuleMSC\Model\AllSoapAndRest" />
<preference for="Magento\TestModuleMSC\Api\Data\ItemInterface" type="Magento\TestModuleMSC\Model\Data\Item" />
<preference for="Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface" type="Magento\TestModuleMSC\Model\Data\CustomAttributeDataObject" />
<preference for="Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface" type="Magento\TestModuleMSC\Model\Data\CustomAttributeNestedDataObject" />
<virtualType name="Magento\TestModuleMSC\Service\Config\TestModuleMSCMetadataConfig" type="Magento\Framework\Api\ExtensionAttribute\Config\MetadataConfig">
<arguments>
<argument name="attributeMetadataBuilder" xsi:type="object">Magento\TestModuleMSC\Model\Data\Eav\AttributeMetadataBuilder</argument>
<argument name="dataObjectClassName" xsi:type="string">Magento\TestModuleMSC\Model\Data\Item</argument>
</arguments>
</virtualType>
<type name="Magento\TestModuleMSC\Model\Data\Item">
<arguments>
<argument name="resource" xsi:type="object">Magento\TestModuleMSC\Model\ResourceModel\Item</argument>
<argument name="metadataService" xsi:type="object">Magento\TestModuleMSC\Service\Config\TestModuleMSCMetadataConfig</argument>
</arguments>
</type>
<type name="Magento\TestModuleMSC\Model\Data\CustomAttributeDataObject">
<arguments>
<argument name="resource" xsi:type="object">Magento\TestModuleMSC\Model\ResourceModel\Item</argument>
</arguments>
</type>
<virtualType name="CustomAttributeMap" type="Magento\Framework\DataObject">
<arguments>
<argument name="data" xsi:type="array">
<item name="customAttributeDataObjectInterface" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface</item>
<item name="customAttributeNestedDataObjectInterface" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface</item>
</argument>
</arguments>
</virtualType>
<type name="Magento\Framework\Webapi\ServiceTypeToEntityTypeMap">
<arguments>
<argument name="serviceTypeToEntityTypeMap" xsi:type="array">
<item name="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" xsi:type="string">1</item>
</argument>
</arguments>
</type>
<type name="Magento\Eav\Model\TypeLocator\ComplexType">
<arguments>
<argument name="backendModelToAttributeTypeMap" xsi:type="array">
<item name="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" xsi:type="array">
<item name="Magento\Sample\BackendType1" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface</item>
<item name="Magento\Sample\BackendType2" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface</item>
</item>
</argument>
</arguments>
</type>
</config>
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\TestModuleMSC\Api\Data\ItemInterface">
<attribute code="custom_attribute_data_object" type="Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface" />
<attribute code="custom_attribute_string" type="string" />
</extension_attributes>
<extension_attributes for="Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface">
<attribute code="custom_attribute_nested" type="Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface" />
<attribute code="custom_attribute_int" type="int" />
</extension_attributes>
</config>
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_TestModuleMSC" />
</config>
@@ -0,0 +1,69 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route method="GET" url="/V1/testmoduleMSC/overwritten">
<service class="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" method="item" />
<resources>
<resource ref="Magento_TestModuleMSC::resource1" />
</resources>
<data>
<parameter name="itemId" force="true">-55</parameter>
</data>
</route>
<route method="POST" url="/V1/testmoduleMSC/testOptionalParam">
<service class="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" method="testOptionalParam" />
<resources>
<resource ref="Magento_TestModuleMSC::resource1" />
</resources>
<data>
<parameter name="name">Default Name</parameter>
</data>
</route>
<route method="GET" url="/V1/testmoduleMSC/:itemId">
<service class="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" method="item" />
<resources>
<resource ref="Magento_TestModuleMSC::resource1" />
</resources>
</route>
<route method="GET" url="/V1/testmoduleMSC">
<service class="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" method="items" />
<resources>
<resource ref="Magento_TestModuleMSC::resource2" />
</resources>
</route>
<route method="POST" url="/V1/testmoduleMSC">
<service class="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" method="create" />
<resources>
<resource ref="Magento_TestModuleMSC::resource3" />
</resources>
</route>
<route method="PUT" url="/V1/testmoduleMSC/:itemId">
<service class="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" method="update" />
<resources>
<resource ref="Magento_TestModuleMSC::resource1" />
<resource ref="Magento_TestModuleMSC::resource2" />
</resources>
</route>
<route method="POST" url="/V1/testmoduleMSC/itemAnyType">
<service class="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" method="itemAnyType" />
<resources>
<resource ref="Magento_TestModuleMSC::resource1" />
<resource ref="Magento_TestModuleMSC::resource2" />
</resources>
</route>
<route method="GET" url="/V1/testmoduleMSC/itemPreconfigured">
<service class="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" method="getPreconfiguredItem" />
<resources>
<resource ref="Magento_TestModuleMSC::resource1" />
<resource ref="Magento_TestModuleMSC::resource2" />
</resources>
</route>
</routes>
@@ -0,0 +1,12 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\Component\ComponentRegistrar;
$registrar = new ComponentRegistrar();
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleMSC') === null) {
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleMSC', __DIR__);
}