init
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\TestModule4\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,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModule4\Service\V1;
|
||||
|
||||
use Magento\TestModule4\Service\V1\Entity\DataObjectRequest;
|
||||
use Magento\TestModule4\Service\V1\Entity\DataObjectResponseFactory;
|
||||
use Magento\TestModule4\Service\V1\Entity\ExtensibleRequestInterface;
|
||||
use Magento\TestModule4\Service\V1\Entity\NestedDataObjectRequest;
|
||||
|
||||
class DataObjectService implements \Magento\TestModule4\Service\V1\DataObjectServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var DataObjectResponseFactory
|
||||
*/
|
||||
protected $responseFactory;
|
||||
|
||||
/**
|
||||
* @param DataObjectResponseFactory $responseFactory
|
||||
*/
|
||||
public function __construct(DataObjectResponseFactory $responseFactory)
|
||||
{
|
||||
$this->responseFactory = $responseFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData($id)
|
||||
{
|
||||
return $this->responseFactory->create()->setEntityId($id)->setName("Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateData($id, DataObjectRequest $request)
|
||||
{
|
||||
return $this->responseFactory->create()->setEntityId($id)->setName($request->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function nestedData($id, NestedDataObjectRequest $request)
|
||||
{
|
||||
return $this->responseFactory->create()->setEntityId($id)->setName($request->getDetails()->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test return scalar value
|
||||
*
|
||||
* @param int $id
|
||||
* @return int
|
||||
*/
|
||||
public function scalarResponse($id)
|
||||
{
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function extensibleDataObject($id, ExtensibleRequestInterface $request)
|
||||
{
|
||||
return $this->responseFactory->create()->setEntityId($id)->setName($request->getName());
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\TestModule4\Service\V1;
|
||||
|
||||
use Magento\TestModule4\Service\V1\Entity\DataObjectRequest;
|
||||
use Magento\TestModule4\Service\V1\Entity\NestedDataObjectRequest;
|
||||
|
||||
interface DataObjectServiceInterface
|
||||
{
|
||||
/**
|
||||
* @param int $id
|
||||
* @return \Magento\TestModule4\Service\V1\Entity\DataObjectResponse
|
||||
*/
|
||||
public function getData($id);
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param \Magento\TestModule4\Service\V1\Entity\DataObjectRequest $request
|
||||
* @return \Magento\TestModule4\Service\V1\Entity\DataObjectResponse
|
||||
*/
|
||||
public function updateData($id, DataObjectRequest $request);
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param \Magento\TestModule4\Service\V1\Entity\NestedDataObjectRequest $request
|
||||
* @return \Magento\TestModule4\Service\V1\Entity\DataObjectResponse
|
||||
*/
|
||||
public function nestedData($id, NestedDataObjectRequest $request);
|
||||
|
||||
/**
|
||||
* Test return scalar value
|
||||
*
|
||||
* @param int $id
|
||||
* @return int
|
||||
*/
|
||||
public function scalarResponse($id);
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param \Magento\TestModule4\Service\V1\Entity\ExtensibleRequestInterface $request
|
||||
* @return \Magento\TestModule4\Service\V1\Entity\DataObjectResponse
|
||||
*/
|
||||
public function extensibleDataObject(
|
||||
$id,
|
||||
\Magento\TestModule4\Service\V1\Entity\ExtensibleRequestInterface $request
|
||||
);
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModule4\Service\V1\Entity;
|
||||
|
||||
class DataObjectRequest extends \Magento\Framework\Api\AbstractExtensibleObject
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_get('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
return $this->setData('name', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getEntityId()
|
||||
{
|
||||
return $this->_get('entity_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $entityId
|
||||
* @return $this
|
||||
*/
|
||||
public function setEntityId($entityId)
|
||||
{
|
||||
return $this->setData('entity_id', $entityId);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModule4\Service\V1\Entity;
|
||||
|
||||
class DataObjectResponse extends \Magento\Framework\Api\AbstractExtensibleObject
|
||||
{
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getEntityId()
|
||||
{
|
||||
return $this->_get('entity_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $entityId
|
||||
* @return $this
|
||||
*/
|
||||
public function setEntityId($entityId)
|
||||
{
|
||||
return $this->setData('entity_id', $entityId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_get('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
return $this->setData('name', $name);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\TestModule4\Service\V1\Entity;
|
||||
|
||||
/**
|
||||
* Class ExtensibleRequest
|
||||
*
|
||||
* @method \Magento\TestModule4\Service\V1\Entity\ExtensibleRequestExtensionInterface getExtensionAttributes()
|
||||
*/
|
||||
class ExtensibleRequest extends \Magento\Framework\Model\AbstractExtensibleModel implements ExtensibleRequestInterface
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return $this->getData("name");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
return $this->setData("name", $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $entityId
|
||||
* @return $this
|
||||
*/
|
||||
public function setEntityId($entityId)
|
||||
{
|
||||
return $this->setData("entity_id", $entityId);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModule4\Service\V1\Entity;
|
||||
|
||||
interface ExtensibleRequestInterface extends \Magento\Framework\Api\ExtensibleDataInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getEntityId();
|
||||
|
||||
/**
|
||||
* @param int $entityId
|
||||
* @return $this
|
||||
*/
|
||||
public function setEntityId($entityId);
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModule4\Service\V1\Entity;
|
||||
|
||||
class NestedDataObjectRequest extends \Magento\Framework\Api\AbstractExtensibleObject
|
||||
{
|
||||
/**
|
||||
* @return \Magento\TestModule4\Service\V1\Entity\DataObjectRequest
|
||||
*/
|
||||
public function getDetails()
|
||||
{
|
||||
return $this->_get('details');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\TestModule4\Service\V1\Entity\DataObjectRequest $details
|
||||
* @return $this
|
||||
*/
|
||||
public function setDetails(\Magento\TestModule4\Service\V1\Entity\DataObjectRequest $details = null)
|
||||
{
|
||||
return $this->setData('details', $details);
|
||||
}
|
||||
}
|
||||
@@ -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_TestModule4::all" title="TestModule4" sortOrder="1">
|
||||
<resource id="Magento_TestModule4::resource1" title="Resource1" sortOrder="20"/>
|
||||
<resource id="Magento_TestModule4::resource2" title="Resource2" sortOrder="10"/>
|
||||
<resource id="Magento_TestModule4::resource3" title="Resource3" sortOrder="30"/>
|
||||
</resource>
|
||||
</resource>
|
||||
</resources>
|
||||
</acl>
|
||||
</config>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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\TestModule4\Service\V1\DataObjectServiceInterface" type="Magento\TestModule4\Service\V1\DataObjectService" />
|
||||
<preference for="Magento\TestModule4\Service\V1\Entity\ExtensibleRequestInterface" type="Magento\TestModule4\Service\V1\Entity\ExtensibleRequest" />
|
||||
<type name="Magento\TestModule4\Service\V1\Entity\ExtensibleRequest">
|
||||
<arguments>
|
||||
<argument name="resource" xsi:type="object">Magento\TestModule4\Model\ResourceModel\Item</argument>
|
||||
</arguments>
|
||||
</type>
|
||||
</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_TestModule4" />
|
||||
</config>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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/testmodule4/:id">
|
||||
<service class="Magento\TestModule4\Service\V1\DataObjectServiceInterface" method="getData" />
|
||||
<resources>
|
||||
<resource ref="Magento_TestModule4::resource1" />
|
||||
</resources>
|
||||
</route>
|
||||
<route method="GET" url="/V1/testmodule4/scalar/:id">
|
||||
<service class="Magento\TestModule4\Service\V1\DataObjectServiceInterface" method="scalarResponse" />
|
||||
<resources>
|
||||
<resource ref="Magento_TestModule4::resource1" />
|
||||
</resources>
|
||||
</route>
|
||||
<route method="POST" url="/V1/testmodule4/:id">
|
||||
<service class="Magento\TestModule4\Service\V1\DataObjectServiceInterface" method="updateData" />
|
||||
<resources>
|
||||
<resource ref="Magento_TestModule4::resource2" />
|
||||
</resources>
|
||||
</route>
|
||||
<route method="POST" url="/V1/testmodule4/:id/nested">
|
||||
<service class="Magento\TestModule4\Service\V1\DataObjectServiceInterface" method="nestedData" />
|
||||
<resources>
|
||||
<resource ref="Magento_TestModule4::resource3" />
|
||||
</resources>
|
||||
</route>
|
||||
<route method="POST" url="/V1/testmodule4/extensibleDataObject/:id">
|
||||
<service class="Magento\TestModule4\Service\V1\DataObjectServiceInterface" method="extensibleDataObject" />
|
||||
<resources>
|
||||
<resource ref="Magento_TestModule4::resource3" />
|
||||
</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_TestModule4') === null) {
|
||||
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModule4', __DIR__);
|
||||
}
|
||||
Reference in New Issue
Block a user