将 Amazon MWS(库存 API)与 CodeIgniter (PHP) 结合使用 [英] Using Amazon MWS (Inventory API) with CodeIgniter (PHP)

查看:23
本文介绍了将 Amazon MWS(库存 API)与 CodeIgniter (PHP) 结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用 Amazon MWS api 有点熟悉,但我是 CodeIgniter 和整个 hmvc 的新手.我很好奇如何将 api 添加到 CodeIgniter 中.我是否必须将整个 api 剖析到适当的 mvc 文件夹中,或者我可以将它添加为一个库.如果是后者,我将如何使用 api?

I'm somewhat familiar with using the Amazon MWS apis, but I'm new to CodeIgniter and the whole hmvc thing. I'm curious how I would add the api into CodeIgniter. Would I have to dissect the entire api into the appropriate mvc folders, or could I just add it as a library. If the latter is the case, how would I use the api?

如果这很模糊,我很抱歉,但如果您愿意提供任何帮助,我将不胜感激!谢谢

I'm sorry if this is vague, but I would greatly appreciate any help you're willing to offer! Thanks

推荐答案

我不能说任何特定于 CodeIgniter 的东西,但我已经使用过各种 MVC 库,所以我可以给出一个总体概述.您的选择是:

I cannot say anthing specific to CodeIgniter, but I've worked with various MVC libraries, so I can give a general overview. Your options are:

I) 从头开始​​编写模型

访问 MWS 的新代码大多会出现在模型"空间中.控制器和视图(您可能最终会需要)超出了 Amazon 提供的代码范围,因此无论如何都需要编写它们.就MVC(和OOP)的想法而言,这是正确"的做法,您可以充分利用继承和多态性.

New code accessing the MWS would mostly end up in the "Model" space. The controllers and views (which you'll probably eventually need) are outside the scope of the code that Amazon provides, so they need to be written anyways. As far as the MVC (and OOP) idea goes, this is the "proper" way to do it, you can make full use of inheritance and polymorphism.

优点:您访问 MWS 的模型将遵循您的 MVC 框架的规则和指南.很容易集成到框架的其他部分,并与其余代码很好地集成.

Advantages: Your model accessing the MWS will follow the rules and guidelines of your MVC framework. It will be easy to integrate into other parts of the framework, and integrate nicely with the rest of the code.

缺点:需要编写大量代码和(更重要的是,因为 MWS 是一个移动目标)需要维护.

Disadvantages: lots of code to write and (more importantly, since MWS is a moving target) maintain.

II) 使用亚马逊的代码作为库

亚马逊的代码将进入图书馆"空间.由于它不遵循您的 MVC 框架的规则,因此它对其余代码感觉"是陌生的.

Amazon's code would go into the "Libraries" space. As it doesn't follow the rules of your MVC framework, it will "feel" foreign to the rest of the code.

优点:需要编写和维护的代码更少.

Advantages: Less code to write and maintain.

缺点:不使用框架,没有代码重用,没有继承,没有多态性.

Disadvantages: No usage of the framework, no code reuse, no inheritance and no polymorphism.

III) 编写包装器

这基本上是上述两个选项的混合.您围绕库编写了一个非常薄的包装器(进入模型空间),它调用未修改的 Amazon 库.如果编写得当,您可能会得到两全其美"——这取决于库的接口与您想要的模型接口的匹配程度.

This is basically a mix of the two options above. You write a very thin wrapper around the library (goes into the Model space) which calls the unmodified Amazon library. Written properly, you might get a "best of both worlds" - this depends on how much the interface the library matches your desired model interface.

优点:与库"方法相比,通常只需要很少的额外代码,而模型可以像完全重写一样使用.

Advantages: Often only little extra code is needed, when compared to the "library" approach", while the model can be used in the same way as a complete rewrite.

缺点:有时需要几乎与从头开始编写一样多的代码.

Disadvantages: Sometimes needs almost as much code as writing from scratch.

建议和评论

我的方法可能是使用包装器,除非我只需要库代码的一小部分.由于 PHP 没有严格的对象层次结构,因此通常可以在需要时适当地模拟继承.

My approach would probably be to go with a wrapper, unless I need just a fraction of the library's code. Since PHP does not have a strict object hierarchy, it is usually possibly to properly mimic inheritance anyways if needed.

关于围绕 MWS 设计模型的旁注:与大多数网络服务不同,对 MWS API(例如 SubmitFeed)的一些调用是异步工作的,因为有关操作成功或失败的信息只会在几分钟(甚至小时)之后.大多数 MVC 模型层次结构和接口都不能很好地处理这种类型的事情,因此完全重写可能不会给您带来通常会获得的好处.

A side note on designing a model around the MWS: Unlike most web services, some calls to the MWS API (e.g. SubmitFeed) work asynchronously in that information about the success or failure of an operation will only be available minutes (or even hours) after the call has been made. Most MVC model hierarchies and interfaces are not designed to handle that type of thing well, so a complete rewrite might not give you the benefits that you'd normally get.

请记住,我对 CodeIgniter 一无所知.您的里程可能会有所不同.

Please remember, that I have no knowledge about CodeIgniter. Your mileage may vary.

这篇关于将 Amazon MWS(库存 API)与 CodeIgniter (PHP) 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆