Lib_ZF - Version 1.11.1.0

Version Notes

1.11.1.0

Download this release

Release Info

Developer Magento Core Team
Extension Lib_ZF
Version 1.11.1.0
Comparing to
See all releases


Code changes from version 1.10.8.0 to 1.11.1.0

Files changed (411) hide show
  1. lib/Zend/Acl.php +118 -48
  2. lib/Zend/Amf/Adobe/Introspector.php +7 -2
  3. lib/Zend/Amf/Parse/Amf0/Deserializer.php +1 -1
  4. lib/Zend/Amf/Parse/Amf0/Serializer.php +1 -1
  5. lib/Zend/Amf/Parse/Amf3/Deserializer.php +1 -1
  6. lib/Zend/Amf/Parse/Amf3/Serializer.php +1 -1
  7. lib/Zend/Amf/Parse/Serializer.php +1 -1
  8. lib/Zend/Amf/Response.php +1 -1
  9. lib/Zend/Amf/Response/Http.php +4 -3
  10. lib/Zend/Amf/Server.php +9 -6
  11. lib/Zend/Amf/Util/BinaryStream.php +1 -1
  12. lib/Zend/Application.php +9 -1
  13. lib/Zend/Application/Bootstrap/Bootstrap.php +1 -1
  14. lib/Zend/Application/Bootstrap/BootstrapAbstract.php +2 -2
  15. lib/Zend/Application/Resource/Cachemanager.php +1 -1
  16. lib/Zend/Application/Resource/Db.php +33 -1
  17. lib/Zend/Application/Resource/Dojo.php +1 -1
  18. lib/Zend/Application/Resource/Exception.php +1 -1
  19. lib/Zend/Application/Resource/Frontcontroller.php +8 -2
  20. lib/Zend/Application/Resource/Layout.php +1 -1
  21. lib/Zend/Application/Resource/Locale.php +1 -1
  22. lib/Zend/Application/Resource/Log.php +1 -1
  23. lib/Zend/Application/Resource/Mail.php +1 -1
  24. lib/Zend/Application/Resource/Modules.php +1 -1
  25. lib/Zend/Application/Resource/Multidb.php +40 -1
  26. lib/Zend/Application/Resource/Navigation.php +5 -1
  27. lib/Zend/Application/Resource/ResourceAbstract.php +6 -4
  28. lib/Zend/Application/Resource/Router.php +1 -1
  29. lib/Zend/Application/Resource/Session.php +1 -1
  30. lib/Zend/Application/Resource/Translate.php +22 -2
  31. lib/Zend/Application/Resource/Useragent.php +72 -0
  32. lib/Zend/Application/Resource/View.php +8 -2
  33. lib/Zend/Auth/Adapter/DbTable.php +1 -1
  34. lib/Zend/Auth/Adapter/Digest.php +24 -2
  35. lib/Zend/Auth/Adapter/Http.php +25 -3
  36. lib/Zend/Auth/Adapter/Ldap.php +1 -1
  37. lib/Zend/Barcode/Exception.php +4 -4
  38. lib/Zend/Barcode/Object/Code128.php +391 -0
  39. lib/Zend/Barcode/Object/Code39.php +12 -1
  40. lib/Zend/Barcode/Object/Ean13.php +13 -12
  41. lib/Zend/Barcode/Object/Ean8.php +3 -2
  42. lib/Zend/Barcode/Object/ObjectAbstract.php +39 -3
  43. lib/Zend/Barcode/Object/Upca.php +2 -1
  44. lib/Zend/Barcode/Object/Upce.php +2 -1
  45. lib/Zend/Barcode/Renderer/Image.php +3 -3
  46. lib/Zend/Barcode/Renderer/Pdf.php +2 -2
  47. lib/Zend/Barcode/Renderer/RendererAbstract.php +8 -8
  48. lib/Zend/Barcode/Renderer/Svg.php +382 -0
  49. lib/Zend/Cache.php +9 -9
  50. lib/Zend/Cache/Backend.php +1 -1
  51. lib/Zend/Cache/Backend/BlackHole.php +1 -1
  52. lib/Zend/Cache/Backend/File.php +1 -1
  53. lib/Zend/Cache/Backend/Libmemcached.php +484 -0
  54. lib/Zend/Cache/Backend/Memcached.php +1 -1
  55. lib/Zend/Cache/Backend/Static.php +21 -28
  56. lib/Zend/Cache/Backend/Test.php +3 -2
  57. lib/Zend/Cache/Backend/TwoLevels.php +1 -1
  58. lib/Zend/Cache/Backend/Xcache.php +7 -2
  59. lib/Zend/Cache/Core.php +1 -1
  60. lib/Zend/Cache/Frontend/Capture.php +2 -1
  61. lib/Zend/Cache/Frontend/Class.php +11 -6
  62. lib/Zend/Cache/Frontend/File.php +20 -11
  63. lib/Zend/Cache/Frontend/Function.php +1 -1
  64. lib/Zend/Cache/Manager.php +1 -1
  65. lib/Zend/Captcha/Image.php +1 -1
  66. lib/Zend/Captcha/Word.php +24 -2
  67. lib/Zend/Cloud/AbstractFactory.php +67 -0
  68. lib/Zend/Cloud/DocumentService/Adapter.php +155 -0
  69. lib/Zend/Cloud/DocumentService/Adapter/AbstractAdapter.php +130 -0
  70. lib/Zend/Cloud/DocumentService/Adapter/SimpleDb.php +468 -0
  71. lib/Zend/Cloud/DocumentService/Adapter/SimpleDb/Query.php +175 -0
  72. lib/Zend/Cloud/DocumentService/Adapter/WindowsAzure.php +628 -0
  73. lib/Zend/Cloud/DocumentService/Adapter/WindowsAzure/Query.php +171 -0
  74. lib/Zend/Cloud/DocumentService/Document.php +248 -0
  75. lib/Zend/Cloud/DocumentService/DocumentSet.php +68 -0
  76. lib/Zend/Cloud/DocumentService/Exception.php +38 -0
  77. lib/Zend/Cloud/DocumentService/Factory.php +77 -0
  78. lib/Zend/Cloud/DocumentService/Query.php +191 -0
  79. lib/Zend/Cloud/DocumentService/QueryAdapter.php +102 -0
  80. lib/Zend/Cloud/Exception.php +53 -0
  81. lib/Zend/Cloud/OperationNotAvailableException.php +34 -0
  82. lib/Zend/Cloud/QueueService/Adapter.php +146 -0
  83. lib/Zend/Cloud/QueueService/Adapter/AbstractAdapter.php +92 -0
  84. lib/Zend/Cloud/QueueService/Adapter/Sqs.php +278 -0
  85. lib/Zend/Cloud/QueueService/Adapter/WindowsAzure.php +343 -0
  86. lib/Zend/Cloud/QueueService/Adapter/ZendQueue.php +301 -0
  87. lib/Zend/Cloud/QueueService/Exception.php +37 -0
  88. lib/Zend/Cloud/QueueService/Factory.php +71 -0
  89. lib/Zend/Cloud/QueueService/Message.php +60 -0
  90. lib/Zend/Cloud/QueueService/MessageSet.php +68 -0
  91. lib/Zend/Cloud/StorageService/Adapter.php +145 -0
  92. lib/Zend/Cloud/StorageService/Adapter/FileSystem.php +267 -0
  93. lib/Zend/Cloud/StorageService/Adapter/Nirvanix.php +399 -0
  94. lib/Zend/Cloud/StorageService/Adapter/S3.php +327 -0
  95. lib/Zend/Cloud/StorageService/Adapter/WindowsAzure.php +443 -0
  96. lib/Zend/Cloud/StorageService/Exception.php +38 -0
  97. lib/Zend/Cloud/StorageService/Factory.php +70 -0
  98. lib/Zend/CodeGenerator/Php/Class.php +1 -1
  99. lib/Zend/CodeGenerator/Php/Parameter.php +1 -1
  100. lib/Zend/CodeGenerator/Php/Property/DefaultValue.php +3 -1
  101. lib/Zend/Config/Json.php +240 -0
  102. lib/Zend/Config/Writer/Ini.php +1 -1
  103. lib/Zend/Config/Writer/Json.php +106 -0
  104. lib/Zend/Config/Writer/Yaml.php +144 -0
  105. lib/Zend/Config/Yaml.php +382 -0
  106. lib/Zend/Console/Getopt.php +1 -1
  107. lib/Zend/Controller/Action.php +1 -1
  108. lib/Zend/Controller/Action/Helper/Cache.php +2 -2
  109. lib/Zend/Controller/Action/Helper/Redirector.php +6 -3
  110. lib/Zend/Controller/Dispatcher/Standard.php +1 -1
  111. lib/Zend/Controller/Request/Http.php +16 -5
  112. lib/Zend/Controller/Response/Abstract.php +1 -1
  113. lib/Zend/Controller/Router/Rewrite.php +3 -3
  114. lib/Zend/Controller/Router/Route/Chain.php +6 -2
  115. lib/Zend/Controller/Router/Route/Static.php +4 -2
  116. lib/Zend/Crypt.php +3 -2
  117. lib/Zend/Crypt/DiffieHellman.php +3 -3
  118. lib/Zend/Crypt/Math/BigInteger.php +4 -4
  119. lib/Zend/Crypt/Math/BigInteger/Bcmath.php +1 -1
  120. lib/Zend/Crypt/Math/BigInteger/Gmp.php +2 -2
  121. lib/Zend/Crypt/Rsa.php +25 -10
  122. lib/Zend/Crypt/Rsa/Exception.php +36 -0
  123. lib/Zend/Crypt/Rsa/Key/Private.php +2 -2
  124. lib/Zend/Currency.php +12 -8
  125. lib/Zend/Currency/CurrencyInterface.php +1 -1
  126. lib/Zend/Date.php +3 -2
  127. lib/Zend/Date/DateObject.php +35 -4
  128. lib/Zend/Db.php +6 -14
  129. lib/Zend/Db/Adapter/Abstract.php +34 -8
  130. lib/Zend/Db/Adapter/Db2.php +10 -2
  131. lib/Zend/Db/Adapter/Oracle.php +1 -41
  132. lib/Zend/Db/Adapter/Pdo/Pgsql.php +1 -1
  133. lib/Zend/Db/Adapter/Sqlsrv.php +27 -22
  134. lib/Zend/Db/Adapter/Sqlsrv/Exception.php +1 -1
  135. lib/Zend/Db/Profiler/Query.php +15 -1
  136. lib/Zend/Db/Select.php +13 -13
  137. lib/Zend/Db/Statement/Exception.php +1 -1
  138. lib/Zend/Db/Statement/Pdo/Oci.php +1 -1
  139. lib/Zend/Db/Statement/Sqlsrv.php +31 -2
  140. lib/Zend/Db/Table/Abstract.php +1 -1
  141. lib/Zend/Db/Table/Row/Abstract.php +1 -1
  142. lib/Zend/Db/Table/Rowset/Abstract.php +30 -19
  143. lib/Zend/Dojo/BuildLayer.php +1 -1
  144. lib/Zend/Dojo/Form/Decorator/DijitElement.php +1 -1
  145. lib/Zend/Dojo/Form/Element/DijitMulti.php +1 -1
  146. lib/Zend/Dojo/View/Helper/Dojo/Container.php +9 -3
  147. lib/Zend/Dom/Query.php +77 -10
  148. lib/Zend/Dom/Query/Css2Xpath.php +1 -1
  149. lib/Zend/Exception.php +1 -0
  150. lib/Zend/Feed/Pubsubhubbub.php +1 -0
  151. lib/Zend/Feed/Pubsubhubbub/CallbackAbstract.php +2 -1
  152. lib/Zend/Feed/Pubsubhubbub/CallbackInterface.php +1 -0
  153. lib/Zend/Feed/Pubsubhubbub/Exception.php +1 -0
  154. lib/Zend/Feed/Pubsubhubbub/HttpResponse.php +1 -0
  155. lib/Zend/Feed/Pubsubhubbub/Model/ModelAbstract.php +2 -1
  156. lib/Zend/Feed/Pubsubhubbub/Model/Subscription.php +1 -0
  157. lib/Zend/Feed/Pubsubhubbub/Model/SubscriptionInterface.php +1 -0
  158. lib/Zend/Feed/Pubsubhubbub/Publisher.php +4 -3
  159. lib/Zend/Feed/Pubsubhubbub/Subscriber.php +8 -4
  160. lib/Zend/Feed/Pubsubhubbub/Subscriber/Callback.php +8 -6
  161. lib/Zend/Feed/Reader.php +3 -3
  162. lib/Zend/Feed/Reader/Collection.php +1 -1
  163. lib/Zend/Feed/Reader/Collection/Category.php +1 -1
  164. lib/Zend/Feed/Reader/Entry/Rss.php +1 -1
  165. lib/Zend/Feed/Reader/Extension/Atom/Entry.php +2 -2
  166. lib/Zend/Feed/Reader/Extension/Atom/Feed.php +26 -2
  167. lib/Zend/Feed/Reader/Extension/Content/Entry.php +1 -1
  168. lib/Zend/Feed/Reader/Extension/EntryAbstract.php +2 -2
  169. lib/Zend/Feed/Reader/Feed/Atom.php +2 -2
  170. lib/Zend/Feed/Reader/Feed/Atom/Source.php +1 -1
  171. lib/Zend/Feed/Reader/Feed/Rss.php +7 -7
  172. lib/Zend/Feed/Reader/FeedAbstract.php +1 -1
  173. lib/Zend/Feed/Reader/FeedSet.php +2 -2
  174. lib/Zend/Feed/Writer/Deleted.php +2 -2
  175. lib/Zend/Feed/Writer/Entry.php +3 -3
  176. lib/Zend/Feed/Writer/Extension/Atom/Renderer/Feed.php +1 -1
  177. lib/Zend/Feed/Writer/Extension/Content/Renderer/Entry.php +1 -1
  178. lib/Zend/Feed/Writer/Extension/DublinCore/Renderer/Entry.php +1 -1
  179. lib/Zend/Feed/Writer/Extension/DublinCore/Renderer/Feed.php +1 -1
  180. lib/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php +3 -3
  181. lib/Zend/Feed/Writer/Extension/ITunes/Renderer/Feed.php +3 -3
  182. lib/Zend/Feed/Writer/Extension/RendererAbstract.php +1 -0
  183. lib/Zend/Feed/Writer/Extension/RendererInterface.php +1 -0
  184. lib/Zend/Feed/Writer/Extension/Slash/Renderer/Entry.php +2 -2
  185. lib/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php +4 -4
  186. lib/Zend/Feed/Writer/Extension/WellFormedWeb/Renderer/Entry.php +1 -1
  187. lib/Zend/Feed/Writer/Feed.php +1 -1
  188. lib/Zend/Feed/Writer/Feed/FeedAbstract.php +35 -4
  189. lib/Zend/Feed/Writer/Renderer/Entry/Atom.php +1 -1
  190. lib/Zend/Feed/Writer/Renderer/Entry/Atom/Deleted.php +1 -1
  191. lib/Zend/Feed/Writer/Renderer/Entry/Rss.php +1 -1
  192. lib/Zend/Feed/Writer/Renderer/Feed/Atom.php +2 -1
  193. lib/Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php +20 -1
  194. lib/Zend/Feed/Writer/Renderer/Feed/Atom/Source.php +1 -1
  195. lib/Zend/Feed/Writer/Renderer/Feed/Rss.php +1 -1
  196. lib/Zend/Feed/Writer/Source.php +1 -1
  197. lib/Zend/File/Transfer.php +1 -1
  198. lib/Zend/File/Transfer/Adapter/Abstract.php +1 -1
  199. lib/Zend/File/Transfer/Adapter/Http.php +1 -1
  200. lib/Zend/Filter.php +1 -1
  201. lib/Zend/Filter/Boolean.php +2 -2
  202. lib/Zend/Filter/Compress/Rar.php +3 -3
  203. lib/Zend/Filter/Encrypt/Mcrypt.php +63 -11
  204. lib/Zend/Filter/Encrypt/Openssl.php +153 -14
  205. lib/Zend/Filter/HtmlEntities.php +1 -1
  206. lib/Zend/Filter/Inflector.php +1 -1
  207. lib/Zend/Filter/Input.php +1 -1
  208. lib/Zend/Filter/PregReplace.php +1 -1
  209. lib/Zend/Filter/StringToLower.php +5 -1
  210. lib/Zend/Filter/StringToUpper.php +5 -1
  211. lib/Zend/Filter/StringTrim.php +6 -6
  212. lib/Zend/Filter/StripTags.php +9 -2
  213. lib/Zend/Filter/Word/CamelCaseToSeparator.php +1 -1
  214. lib/Zend/Form.php +32 -5
  215. lib/Zend/Form/Decorator/Abstract.php +1 -1
  216. lib/Zend/Form/Decorator/DtDdWrapper.php +1 -1
  217. lib/Zend/Form/Decorator/Fieldset.php +2 -2
  218. lib/Zend/Form/Decorator/FormErrors.php +1 -1
  219. lib/Zend/Form/Decorator/HtmlTag.php +7 -2
  220. lib/Zend/Form/Decorator/Label.php +2 -2
  221. lib/Zend/Form/Decorator/ViewScript.php +51 -3
  222. lib/Zend/Form/DisplayGroup.php +43 -1
  223. lib/Zend/Form/Element.php +9 -6
  224. lib/Zend/Form/Element/Captcha.php +2 -2
  225. lib/Zend/Form/Element/File.php +1 -1
  226. lib/Zend/Form/Element/Image.php +1 -1
  227. lib/Zend/Form/Element/Multi.php +1 -1
  228. lib/Zend/Form/Element/Radio.php +1 -1
  229. lib/Zend/Form/Element/Submit.php +1 -1
  230. lib/Zend/Form/SubForm.php +1 -1
  231. lib/Zend/Gdata/App.php +4 -3
  232. lib/Zend/Gdata/App/Base.php +3 -3
  233. lib/Zend/Gdata/App/Feed.php +2 -2
  234. lib/Zend/Gdata/Gapps.php +1 -1
  235. lib/Zend/Http/Client.php +19 -15
  236. lib/Zend/Http/Client/Adapter/Curl.php +1 -1
  237. lib/Zend/Http/Client/Adapter/Proxy.php +1 -1
  238. lib/Zend/Http/Client/Adapter/Socket.php +1 -1
  239. lib/Zend/Http/Client/Adapter/Stream.php +1 -1
  240. lib/Zend/Http/Cookie.php +3 -3
  241. lib/Zend/Http/CookieJar.php +8 -6
  242. lib/Zend/Http/Response.php +1 -1
  243. lib/Zend/Http/Response/Stream.php +1 -1
  244. lib/Zend/Http/UserAgent.php +847 -0
  245. lib/Zend/Http/UserAgent/AbstractDevice.php +974 -0
  246. lib/Zend/Http/UserAgent/Bot.php +128 -0
  247. lib/Zend/Http/UserAgent/Checker.php +76 -0
  248. lib/Zend/Http/UserAgent/Console.php +67 -0
  249. lib/Zend/Http/UserAgent/Desktop.php +56 -0
  250. lib/Zend/Http/UserAgent/Device.php +200 -0
  251. lib/Zend/Http/UserAgent/Email.php +65 -0
  252. lib/Zend/Http/UserAgent/Exception.php +36 -0
  253. lib/Zend/Http/UserAgent/Features/Adapter.php +39 -0
  254. lib/Zend/Http/UserAgent/Features/Adapter/DeviceAtlas.php +78 -0
  255. lib/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php +102 -0
  256. lib/Zend/Http/UserAgent/Features/Adapter/WurflApi.php +103 -0
  257. lib/Zend/Http/UserAgent/Features/Exception.php +36 -0
  258. lib/Zend/Http/UserAgent/Feed.php +81 -0
  259. lib/Zend/Http/UserAgent/Mobile.php +534 -0
  260. lib/Zend/Http/UserAgent/Offline.php +70 -0
  261. lib/Zend/Http/UserAgent/Probe.php +81 -0
  262. lib/Zend/Http/UserAgent/Spam.php +79 -0
  263. lib/Zend/Http/UserAgent/Storage.php +65 -0
  264. lib/Zend/Http/UserAgent/Storage/Exception.php +37 -0
  265. lib/Zend/Http/UserAgent/Storage/NonPersistent.php +97 -0
  266. lib/Zend/Http/UserAgent/Storage/Session.php +166 -0
  267. lib/Zend/Http/UserAgent/Text.php +132 -0
  268. lib/Zend/Http/UserAgent/Validator.php +73 -0
  269. lib/Zend/InfoCard/Xml/Security.php +25 -3
  270. lib/Zend/Json.php +1 -1
  271. lib/Zend/Json/Decoder.php +1 -1
  272. lib/Zend/Json/Encoder.php +1 -1
  273. lib/Zend/Json/Server.php +1 -1
  274. lib/Zend/Ldap.php +22 -11
  275. lib/Zend/Ldap/Attribute.php +41 -47
  276. lib/Zend/Ldap/Converter.php +326 -1
  277. lib/Zend/Ldap/Converter/Exception.php +35 -0
  278. lib/Zend/Ldap/Dn.php +3 -3
  279. lib/Zend/Ldap/Exception.php +1 -2
  280. lib/Zend/Ldap/Filter.php +3 -3
  281. lib/Zend/Ldap/Ldif/Encoder.php +1 -1
  282. lib/Zend/Ldap/Node.php +4 -4
  283. lib/Zend/Loader.php +1 -1
  284. lib/Zend/Loader/Autoloader.php +2 -2
  285. lib/Zend/Loader/Autoloader/Interface.php +10 -1
  286. lib/Zend/Loader/PluginLoader.php +1 -1
  287. lib/Zend/Log.php +152 -8
  288. lib/Zend/Log/FactoryInterface.php +2 -2
  289. lib/Zend/Log/Filter/Abstract.php +3 -3
  290. lib/Zend/Log/Filter/Message.php +2 -2
  291. lib/Zend/Log/Filter/Priority.php +3 -3
  292. lib/Zend/Log/Filter/Suppress.php +4 -4
  293. lib/Zend/Log/Writer/Abstract.php +4 -2
  294. lib/Zend/Log/Writer/Db.php +2 -2
  295. lib/Zend/Log/Writer/Firebug.php +3 -2
  296. lib/Zend/Log/Writer/Mail.php +128 -8
  297. lib/Zend/Log/Writer/Syslog.php +8 -3
  298. lib/Zend/Log/Writer/ZendMonitor.php +22 -3
  299. lib/Zend/Mail.php +33 -17
  300. lib/Zend/Mail/Protocol/Abstract.php +27 -4
  301. lib/Zend/Mail/Protocol/Smtp/Auth/Crammd5.php +1 -1
  302. lib/Zend/Mail/Protocol/Smtp/Auth/Plain.php +1 -1
  303. lib/Zend/Mail/Transport/File.php +134 -0
  304. lib/Zend/Mail/Transport/Sendmail.php +1 -1
  305. lib/Zend/Mail/Transport/Smtp.php +2 -2
  306. lib/Zend/Markup/Parser/Bbcode.php +1 -1
  307. lib/Zend/Markup/Renderer/Html.php +1 -1
  308. lib/Zend/Markup/Renderer/Html/Img.php +1 -1
  309. lib/Zend/Markup/Renderer/Html/Url.php +1 -1
  310. lib/Zend/Markup/Renderer/RendererAbstract.php +1 -1
  311. lib/Zend/Measure/Abstract.php +1 -1
  312. lib/Zend/Memory.php +1 -1
  313. lib/Zend/Navigation/Page.php +27 -1
  314. lib/Zend/Oauth.php +1 -1
  315. lib/Zend/Oauth/Client.php +11 -8
  316. lib/Zend/Oauth/Config.php +3 -3
  317. lib/Zend/Oauth/Consumer.php +18 -12
  318. lib/Zend/Oauth/Exception.php +1 -0
  319. lib/Zend/Oauth/Http.php +6 -6
  320. lib/Zend/Oauth/Http/RequestToken.php +2 -2
  321. lib/Zend/Oauth/Http/Utility.php +2 -2
  322. lib/Zend/Oauth/Signature/Plaintext.php +2 -2
  323. lib/Zend/Oauth/Signature/SignatureAbstract.php +2 -2
  324. lib/Zend/Oauth/Token.php +4 -4
  325. lib/Zend/Oauth/Token/AuthorizedRequest.php +3 -3
  326. lib/Zend/OpenId.php +1 -1
  327. lib/Zend/OpenId/Consumer/Storage/File.php +7 -3
  328. lib/Zend/OpenId/Provider.php +25 -3
  329. lib/Zend/Paginator.php +37 -4
  330. lib/Zend/Paginator/Adapter/Interface.php +2 -9
  331. lib/Zend/Paginator/Adapter/Null.php +1 -1
  332. lib/Zend/Paginator/AdapterAggregate.php +1 -1
  333. lib/Zend/Paginator/SerializableLimitIterator.php +2 -1
  334. lib/Zend/Pdf.php +8 -2
  335. lib/Zend/Pdf/Action.php +1 -1
  336. lib/Zend/Pdf/Annotation/Markup.php +1 -0
  337. lib/Zend/Pdf/Canvas.php +182 -0
  338. lib/Zend/Pdf/Canvas/Abstract.php +1214 -0
  339. lib/Zend/Pdf/Canvas/Interface.php +493 -0
  340. lib/Zend/Pdf/Element.php +19 -1
  341. lib/Zend/Pdf/Element/Array.php +34 -1
  342. lib/Zend/Pdf/Element/Dictionary.php +48 -1
  343. lib/Zend/Pdf/Element/Object.php +35 -1
  344. lib/Zend/Pdf/Element/Object/Stream.php +78 -47
  345. lib/Zend/Pdf/Element/Reference.php +27 -1
  346. lib/Zend/Pdf/Element/Stream.php +14 -1
  347. lib/Zend/Pdf/Element/String.php +1 -1
  348. lib/Zend/Pdf/ElementFactory.php +11 -1
  349. lib/Zend/Pdf/ElementFactory/Interface.php +8 -1
  350. lib/Zend/Pdf/ElementFactory/Proxy.php +11 -1
  351. lib/Zend/Pdf/FileParser/Image/Png.php +1 -1
  352. lib/Zend/Pdf/Filter/Ascii85.php +1 -1
  353. lib/Zend/Pdf/Filter/RunLength.php +1 -0
  354. lib/Zend/Pdf/Outline/Loaded.php +6 -8
  355. lib/Zend/Pdf/Page.php +238 -1246
  356. lib/Zend/Pdf/Parser.php +12 -4
  357. lib/Zend/Pdf/Resource.php +68 -4
  358. lib/Zend/Pdf/Resource/ContentStream.php +114 -0
  359. lib/Zend/Pdf/Resource/Extractor.php +86 -0
  360. lib/Zend/Pdf/Resource/Font/Extracted.php +1 -1
  361. lib/Zend/Pdf/Resource/GraphicsState.php +109 -0
  362. lib/Zend/Pdf/Resource/Image.php +1 -5
  363. lib/Zend/Pdf/Resource/Image/Jpeg.php +19 -8
  364. lib/Zend/Pdf/Resource/Image/Png.php +11 -5
  365. lib/Zend/Pdf/Resource/Unified.php +38 -0
  366. lib/Zend/Pdf/StringParser.php +1 -1
  367. lib/Zend/Pdf/Style.php +1 -2
  368. lib/Zend/Queue/Adapter/Db/queue_sqlite.sql +1 -0
  369. lib/Zend/Queue/Adapter/Db/sqlsrv.sql +44 -0
  370. lib/Zend/Queue/Stomp/Frame.php +5 -5
  371. lib/Zend/Reflection/File.php +1 -1
  372. lib/Zend/Rest/Route.php +13 -1
  373. lib/Zend/Search/Lucene.php +4 -2
  374. lib/Zend/Search/Lucene/Document/Html.php +2 -2
  375. lib/Zend/Search/Lucene/Index/SegmentInfo.php +2 -2
  376. lib/Zend/Search/Lucene/Index/TermsStream/Interface.php +2 -2
  377. lib/Zend/Search/Lucene/MultiSearcher.php +3 -3
  378. lib/Zend/Search/Lucene/Search/Query/Range.php +2 -2
  379. lib/Zend/Search/Lucene/Search/QueryParser.php +1 -1
  380. lib/Zend/Search/Lucene/Storage/File/Filesystem.php +13 -2
  381. lib/Zend/Search/Lucene/TermStreamsPriorityQueue.php +5 -9
  382. lib/Zend/Serializer.php +1 -1
  383. lib/Zend/Serializer/Adapter/AdapterAbstract.php +1 -1
  384. lib/Zend/Serializer/Adapter/AdapterInterface.php +1 -1
  385. lib/Zend/Serializer/Adapter/Amf0.php +1 -1
  386. lib/Zend/Serializer/Adapter/Amf3.php +1 -1
  387. lib/Zend/Serializer/Adapter/Igbinary.php +1 -1
  388. lib/Zend/Serializer/Adapter/Json.php +1 -1
  389. lib/Zend/Serializer/Adapter/PhpCode.php +1 -1
  390. lib/Zend/Serializer/Adapter/PhpSerialize.php +1 -1
  391. lib/Zend/Serializer/Adapter/PythonPickle.php +2 -2
  392. lib/Zend/Serializer/Adapter/Wddx.php +1 -1
  393. lib/Zend/Serializer/Exception.php +1 -1
  394. lib/Zend/Server/Reflection/Function/Abstract.php +15 -3
  395. lib/Zend/Service/Amazon/Authentication.php +82 -0
  396. lib/Zend/Service/Amazon/Authentication/Exception.php +37 -0
  397. lib/Zend/Service/Amazon/Authentication/S3.php +112 -0
  398. lib/Zend/Service/Amazon/Authentication/V1.php +108 -0
  399. lib/Zend/Service/Amazon/Authentication/V2.php +138 -0
  400. lib/Zend/Service/Amazon/Ec2/Ebs.php +1 -1
  401. lib/Zend/Service/Amazon/Ec2/Instance.php +1 -1
  402. lib/Zend/Service/Amazon/Item.php +1 -1
  403. lib/Zend/Service/Amazon/Offer.php +1 -1
  404. lib/Zend/Service/Amazon/S3.php +60 -5
  405. lib/Zend/Service/Amazon/S3/Stream.php +1 -1
  406. lib/Zend/Service/Amazon/SimpleDb.php +580 -0
  407. lib/Zend/Service/Amazon/SimpleDb/Attribute.php +108 -0
  408. lib/Zend/Service/Amazon/SimpleDb/Exception.php +66 -0
  409. lib/Zend/Service/Amazon/SimpleDb/Page.php +97 -0
  410. lib/Zend/Service/Amazon/SimpleDb/Response.php +190 -0
  411. lib/Zend/Service/Amazon/Sqs.php +1 -1
lib/Zend/Acl.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Acl
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Acl.php 22456 2010-06-18 22:41:37Z ralph $
20
  */
21
 
22
 
@@ -632,22 +632,30 @@ class Zend_Acl
632
  unset($rolesTemp);
633
 
634
  // ensure that all specified Resources exist; normalize input to array of Resource objects or null
635
- if (!is_array($resources)) {
636
- $resources = array($resources);
637
- } else if (0 === count($resources)) {
638
- $resources = array(null);
639
- }
640
- $resourcesTemp = $resources;
641
- $resources = array();
642
- foreach ($resourcesTemp as $resource) {
643
- if (null !== $resource) {
644
- $resources[] = $this->get($resource);
645
- } else {
646
- $resources[] = null;
 
 
647
  }
 
 
 
 
 
 
 
648
  }
649
- unset($resourcesTemp);
650
-
651
  // normalize privileges to array
652
  if (null === $privileges) {
653
  $privileges = array();
@@ -659,15 +667,32 @@ class Zend_Acl
659
 
660
  // add to the rules
661
  case self::OP_ADD:
662
- foreach ($resources as $resource) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
663
  foreach ($roles as $role) {
664
- $rules =& $this->_getRules($resource, $role, true);
665
  if (0 === count($privileges)) {
666
  $rules['allPrivileges']['type'] = $type;
667
  $rules['allPrivileges']['assert'] = $assert;
668
- if (!isset($rules['byPrivilegeId'])) {
669
- $rules['byPrivilegeId'] = array();
670
- }
671
  } else {
672
  foreach ($privileges as $privilege) {
673
  $rules['byPrivilegeId'][$privilege]['type'] = $type;
@@ -680,37 +705,81 @@ class Zend_Acl
680
 
681
  // remove from the rules
682
  case self::OP_REMOVE:
683
- foreach ($resources as $resource) {
684
- foreach ($roles as $role) {
685
- $rules =& $this->_getRules($resource, $role);
686
- if (null === $rules) {
687
- continue;
688
- }
689
- if (0 === count($privileges)) {
690
- if (null === $resource && null === $role) {
691
- if ($type === $rules['allPrivileges']['type']) {
692
- $rules = array(
693
- 'allPrivileges' => array(
694
- 'type' => self::TYPE_DENY,
695
- 'assert' => null
696
- ),
697
- 'byPrivilegeId' => array()
698
- );
699
- }
700
  continue;
701
  }
702
-
703
- if (isset($rules['allPrivileges']['type']) &&
704
- $type === $rules['allPrivileges']['type'])
705
- {
706
- unset($rules['allPrivileges']);
707
- }
708
- } else {
709
- foreach ($privileges as $privilege) {
710
- if (isset($rules['byPrivilegeId'][$privilege]) &&
711
- $type === $rules['byPrivilegeId'][$privilege]['type'])
 
 
 
 
 
 
712
  {
713
- unset($rules['byPrivilegeId'][$privilege]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
714
  }
715
  }
716
  }
@@ -1129,6 +1198,7 @@ class Zend_Acl
1129
  return $nullRef;
1130
  }
1131
  $visitor['byRoleId'][$roleId]['byPrivilegeId'] = array();
 
1132
  }
1133
  return $visitor['byRoleId'][$roleId];
1134
  }
16
  * @package Zend_Acl
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Acl.php 23358 2010-11-18 16:19:31Z ralph $
20
  */
21
 
22
 
632
  unset($rolesTemp);
633
 
634
  // ensure that all specified Resources exist; normalize input to array of Resource objects or null
635
+ if ($resources !== null) {
636
+ if (!is_array($resources)) {
637
+ $resources = array($resources);
638
+ } else if (0 === count($resources)) {
639
+ $resources = array(null);
640
+ }
641
+ $resourcesTemp = $resources;
642
+ $resources = array();
643
+ foreach ($resourcesTemp as $resource) {
644
+ if (null !== $resource) {
645
+ $resources[] = $this->get($resource);
646
+ } else {
647
+ $resources[] = null;
648
+ }
649
  }
650
+ unset($resourcesTemp, $resource);
651
+ } else {
652
+ $allResources = array(); // this might be used later if resource iteration is required
653
+ foreach ($this->_resources as $rTarget) {
654
+ $allResources[] = $rTarget['instance'];
655
+ }
656
+ unset($rTarget);
657
  }
658
+
 
659
  // normalize privileges to array
660
  if (null === $privileges) {
661
  $privileges = array();
667
 
668
  // add to the rules
669
  case self::OP_ADD:
670
+ if ($resources !== null) {
671
+ // this block will iterate the provided resources
672
+ foreach ($resources as $resource) {
673
+ foreach ($roles as $role) {
674
+ $rules =& $this->_getRules($resource, $role, true);
675
+ if (0 === count($privileges)) {
676
+ $rules['allPrivileges']['type'] = $type;
677
+ $rules['allPrivileges']['assert'] = $assert;
678
+ if (!isset($rules['byPrivilegeId'])) {
679
+ $rules['byPrivilegeId'] = array();
680
+ }
681
+ } else {
682
+ foreach ($privileges as $privilege) {
683
+ $rules['byPrivilegeId'][$privilege]['type'] = $type;
684
+ $rules['byPrivilegeId'][$privilege]['assert'] = $assert;
685
+ }
686
+ }
687
+ }
688
+ }
689
+ } else {
690
+ // this block will apply to all resources in a global rule
691
  foreach ($roles as $role) {
692
+ $rules =& $this->_getRules(null, $role, true);
693
  if (0 === count($privileges)) {
694
  $rules['allPrivileges']['type'] = $type;
695
  $rules['allPrivileges']['assert'] = $assert;
 
 
 
696
  } else {
697
  foreach ($privileges as $privilege) {
698
  $rules['byPrivilegeId'][$privilege]['type'] = $type;
705
 
706
  // remove from the rules
707
  case self::OP_REMOVE:
708
+ if ($resources !== null) {
709
+ // this block will iterate the provided resources
710
+ foreach ($resources as $resource) {
711
+ foreach ($roles as $role) {
712
+ $rules =& $this->_getRules($resource, $role);
713
+ if (null === $rules) {
 
 
 
 
 
 
 
 
 
 
 
714
  continue;
715
  }
716
+ if (0 === count($privileges)) {
717
+ if (null === $resource && null === $role) {
718
+ if ($type === $rules['allPrivileges']['type']) {
719
+ $rules = array(
720
+ 'allPrivileges' => array(
721
+ 'type' => self::TYPE_DENY,
722
+ 'assert' => null
723
+ ),
724
+ 'byPrivilegeId' => array()
725
+ );
726
+ }
727
+ continue;
728
+ }
729
+
730
+ if (isset($rules['allPrivileges']['type']) &&
731
+ $type === $rules['allPrivileges']['type'])
732
  {
733
+ unset($rules['allPrivileges']);
734
+ }
735
+ } else {
736
+ foreach ($privileges as $privilege) {
737
+ if (isset($rules['byPrivilegeId'][$privilege]) &&
738
+ $type === $rules['byPrivilegeId'][$privilege]['type'])
739
+ {
740
+ unset($rules['byPrivilegeId'][$privilege]);
741
+ }
742
+ }
743
+ }
744
+ }
745
+ }
746
+ } else {
747
+ // this block will apply to all resources in a global rule
748
+ foreach ($roles as $role) {
749
+ /**
750
+ * since null (all resources) was passed to this setRule() call, we need
751
+ * clean up all the rules for the global allResources, as well as the indivually
752
+ * set resources (per privilege as well)
753
+ */
754
+ foreach (array_merge(array(null), $allResources) as $resource) {
755
+ $rules =& $this->_getRules($resource, $role, true);
756
+ if (null === $rules) {
757
+ continue;
758
+ }
759
+ if (0 === count($privileges)) {
760
+ if (null === $role) {
761
+ if ($type === $rules['allPrivileges']['type']) {
762
+ $rules = array(
763
+ 'allPrivileges' => array(
764
+ 'type' => self::TYPE_DENY,
765
+ 'assert' => null
766
+ ),
767
+ 'byPrivilegeId' => array()
768
+ );
769
+ }
770
+ continue;
771
+ }
772
+
773
+ if (isset($rules['allPrivileges']['type']) && $type === $rules['allPrivileges']['type']) {
774
+ unset($rules['allPrivileges']);
775
+ }
776
+ } else {
777
+ foreach ($privileges as $privilege) {
778
+ if (isset($rules['byPrivilegeId'][$privilege]) &&
779
+ $type === $rules['byPrivilegeId'][$privilege]['type'])
780
+ {
781
+ unset($rules['byPrivilegeId'][$privilege]);
782
+ }
783
  }
784
  }
785
  }
1198
  return $nullRef;
1199
  }
1200
  $visitor['byRoleId'][$roleId]['byPrivilegeId'] = array();
1201
+ $visitor['byRoleId'][$roleId]['allPrivileges'] = array('type' => null, 'assert' => null);
1202
  }
1203
  return $visitor['byRoleId'][$roleId];
1204
  }
lib/Zend/Amf/Adobe/Introspector.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Amf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Introspector.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /** @see Zend_Amf_Parse_TypeLoader */
@@ -283,7 +283,12 @@ class Zend_Amf_Adobe_Introspector
283
  return 'Unknown';
284
  }
285
 
286
- if (in_array($typename, array('int', 'integer', 'bool', 'boolean', 'float', 'string', 'object', 'Unknown', 'stdClass', 'array'))) {
 
 
 
 
 
287
  return $typename;
288
  }
289
 
16
  * @package Zend_Amf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Introspector.php 23316 2010-11-10 16:37:40Z matthew $
20
  */
21
 
22
  /** @see Zend_Amf_Parse_TypeLoader */
283
  return 'Unknown';
284
  }
285
 
286
+ // Arrays
287
+ if ('array' == $typename) {
288
+ return 'Unknown[]';
289
+ }
290
+
291
+ if (in_array($typename, array('int', 'integer', 'bool', 'boolean', 'float', 'string', 'object', 'Unknown', 'stdClass'))) {
292
  return $typename;
293
  }
294
 
lib/Zend/Amf/Parse/Amf0/Deserializer.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Parse_Amf0
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Deserializer.php 21210 2010-02-27 10:37:39Z yoshida@zend.co.jp $
21
  */
22
 
23
  /** Zend_Amf_Constants */
17
  * @subpackage Parse_Amf0
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Deserializer.php 21209 2010-02-27 10:37:15Z yoshida@zend.co.jp $
21
  */
22
 
23
  /** Zend_Amf_Constants */
lib/Zend/Amf/Parse/Amf0/Serializer.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Parse_Amf0
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Serializer.php 21969 2010-04-22 03:54:59Z matthew $
21
  */
22
 
23
  /** Zend_Amf_Constants */
17
  * @subpackage Parse_Amf0
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Serializer.php 21968 2010-04-22 03:53:34Z matthew $
21
  */
22
 
23
  /** Zend_Amf_Constants */
lib/Zend/Amf/Parse/Amf3/Deserializer.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Parse_Amf3
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Deserializer.php 21969 2010-04-22 03:54:59Z matthew $
21
  */
22
 
23
  /** Zend_Amf_Parse_Deserializer */
17
  * @subpackage Parse_Amf3
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Deserializer.php 21968 2010-04-22 03:53:34Z matthew $
21
  */
22
 
23
  /** Zend_Amf_Parse_Deserializer */
lib/Zend/Amf/Parse/Amf3/Serializer.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Parse_Amf3
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Serializer.php 21969 2010-04-22 03:54:59Z matthew $
21
  */
22
 
23
  /** Zend_Amf_Constants */
17
  * @subpackage Parse_Amf3
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Serializer.php 22101 2010-05-04 20:07:13Z matthew $
21
  */
22
 
23
  /** Zend_Amf_Constants */
lib/Zend/Amf/Parse/Serializer.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Parse
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Serializer.php 21969 2010-04-22 03:54:59Z matthew $
21
  */
22
 
23
  /**
17
  * @subpackage Parse
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Serializer.php 21968 2010-04-22 03:53:34Z matthew $
21
  */
22
 
23
  /**
lib/Zend/Amf/Response.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Amf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Response.php 21969 2010-04-22 03:54:59Z matthew $
20
  */
21
 
22
  /** @see Zend_Amf_Constants */
16
  * @package Zend_Amf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Response.php 21968 2010-04-22 03:53:34Z matthew $
20
  */
21
 
22
  /** @see Zend_Amf_Constants */
lib/Zend/Amf/Response/Http.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Response
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Http.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /** Zend_Amf_Response */
@@ -41,8 +41,9 @@ class Zend_Amf_Response_Http extends Zend_Amf_Response
41
  public function getResponse()
42
  {
43
  if (!headers_sent()) {
44
- header('Cache-Control: cache, must-revalidate');
45
- header('Pragma: public');
 
46
  header('Content-Type: application/x-amf');
47
  }
48
  return parent::getResponse();
17
  * @subpackage Response
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Http.php 22096 2010-05-04 15:37:23Z wadearnold $
21
  */
22
 
23
  /** Zend_Amf_Response */
41
  public function getResponse()
42
  {
43
  if (!headers_sent()) {
44
+ header('Cache-Control: no-cache, must-revalidate');
45
+ header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
46
+ header('Pragma: no-cache');
47
  header('Content-Type: application/x-amf');
48
  }
49
  return parent::getResponse();
lib/Zend/Amf/Server.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Amf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Server.php 21210 2010-02-27 10:37:39Z yoshida@zend.co.jp $
20
  */
21
 
22
  /** @see Zend_Server_Interface */
@@ -108,7 +108,7 @@ class Zend_Amf_Server implements Zend_Server_Interface
108
  protected $_session = false;
109
 
110
  /**
111
- * Namespace allows all AMF calls to not clobber other php session variables
112
  * @var Zend_Session_NameSpace default session namespace zend_amf
113
  */
114
  protected $_sesionNamespace = 'zend_amf';
@@ -300,12 +300,12 @@ class Zend_Amf_Server implements Zend_Server_Interface
300
  $source = $mapped;
301
  }
302
  }
303
- $qualifiedName = empty($source) ? $method : $source.".".$method;
304
 
305
  if (!isset($this->_table[$qualifiedName])) {
306
  // if source is null a method that was not defined was called.
307
  if ($source) {
308
- $className = str_replace(".", "_", $source);
309
  if(class_exists($className, false) && !isset($this->_classAllowed[$className])) {
310
  #require_once 'Zend/Amf/Server/Exception.php';
311
  throw new Zend_Amf_Server_Exception('Can not call "' . $className . '" - use setClass()');
@@ -318,7 +318,10 @@ class Zend_Amf_Server implements Zend_Server_Interface
318
  }
319
  // Add the new loaded class to the server.
320
  $this->setClass($className, $source);
321
- } else {
 
 
 
322
  #require_once 'Zend/Amf/Server/Exception.php';
323
  throw new Zend_Amf_Server_Exception('Method "' . $method . '" does not exist');
324
  }
@@ -607,7 +610,7 @@ class Zend_Amf_Server implements Zend_Server_Interface
607
  public function handle($request = null)
608
  {
609
  // Check if request was passed otherwise get it from the server
610
- if (is_null($request) || !$request instanceof Zend_Amf_Request) {
611
  $request = $this->getRequest();
612
  } else {
613
  $this->setRequest($request);
16
  * @package Zend_Amf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Server.php 23256 2010-10-26 12:51:54Z alexander $
20
  */
21
 
22
  /** @see Zend_Server_Interface */
108
  protected $_session = false;
109
 
110
  /**
111
+ * Namespace allows all AMF calls to not clobber other PHP session variables
112
  * @var Zend_Session_NameSpace default session namespace zend_amf
113
  */
114
  protected $_sesionNamespace = 'zend_amf';
300
  $source = $mapped;
301
  }
302
  }
303
+ $qualifiedName = empty($source) ? $method : $source . '.' . $method;
304
 
305
  if (!isset($this->_table[$qualifiedName])) {
306
  // if source is null a method that was not defined was called.
307
  if ($source) {
308
+ $className = str_replace('.', '_', $source);
309
  if(class_exists($className, false) && !isset($this->_classAllowed[$className])) {
310
  #require_once 'Zend/Amf/Server/Exception.php';
311
  throw new Zend_Amf_Server_Exception('Can not call "' . $className . '" - use setClass()');
318
  }
319
  // Add the new loaded class to the server.
320
  $this->setClass($className, $source);
321
+ }
322
+
323
+ if (!isset($this->_table[$qualifiedName])) {
324
+ // Source is null or doesn't contain specified method
325
  #require_once 'Zend/Amf/Server/Exception.php';
326
  throw new Zend_Amf_Server_Exception('Method "' . $method . '" does not exist');
327
  }
610
  public function handle($request = null)
611
  {
612
  // Check if request was passed otherwise get it from the server
613
+ if ($request === null || !$request instanceof Zend_Amf_Request) {
614
  $request = $this->getRequest();
615
  } else {
616
  $this->setRequest($request);
lib/Zend/Amf/Util/BinaryStream.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Util
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: BinaryStream.php 21210 2010-02-27 10:37:39Z yoshida@zend.co.jp $
21
  */
22
 
23
  /**
17
  * @subpackage Util
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: BinaryStream.php 22101 2010-05-04 20:07:13Z matthew $
21
  */
22
 
23
  /**
lib/Zend/Application.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Application
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Application.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -387,6 +387,14 @@ class Zend_Application
387
  $config = new Zend_Config_Xml($file, $environment);
388
  break;
389
 
 
 
 
 
 
 
 
 
390
  case 'php':
391
  case 'inc':
392
  $config = include $file;
16
  * @package Zend_Application
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Application.php 23163 2010-10-19 16:30:26Z matthew $
20
  */
21
 
22
  /**
387
  $config = new Zend_Config_Xml($file, $environment);
388
  break;
389
 
390
+ case 'json':
391
+ $config = new Zend_Config_Json($file, $environment);
392
+ break;
393
+
394
+ case 'yaml':
395
+ $config = new Zend_Config_Yaml($file, $environment);
396
+ break;
397
+
398
  case 'php':
399
  case 'inc':
400
  $config = include $file;
lib/Zend/Application/Bootstrap/Bootstrap.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Bootstrap
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Bootstrap.php 20886 2010-02-03 19:36:06Z matthew $
21
  */
22
 
23
  /**
17
  * @subpackage Bootstrap
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Bootstrap.php 20885 2010-02-03 19:33:59Z matthew $
21
  */
22
 
23
  /**
lib/Zend/Application/Bootstrap/BootstrapAbstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Bootstrap
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: BootstrapAbstract.php 22665 2010-07-25 00:40:37Z ramon $
21
  */
22
 
23
  /**
@@ -95,7 +95,7 @@ abstract class Zend_Application_Bootstrap_BootstrapAbstract
95
  *
96
  * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
97
  * @return void
98
- * @throws Zend_Application_Bootstrap_Exception When invalid applicaiton is provided
99
  */
100
  public function __construct($application)
101
  {
17
  * @subpackage Bootstrap
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: BootstrapAbstract.php 23278 2010-10-30 12:50:21Z ramon $
21
  */
22
 
23
  /**
95
  *
96
  * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
97
  * @return void
98
+ * @throws Zend_Application_Bootstrap_Exception When invalid application is provided
99
  */
100
  public function __construct($application)
101
  {
lib/Zend/Application/Resource/Cachemanager.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id$
21
  */
22
 
23
  #require_once 'Zend/Application/Resource/ResourceAbstract.php';
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Cachemanager.php 20785 2010-01-31 09:43:03Z mikaelkael $
21
  */
22
 
23
  #require_once 'Zend/Application/Resource/ResourceAbstract.php';
lib/Zend/Application/Resource/Db.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Db.php 20816 2010-02-01 21:13:54Z freak $
21
  */
22
 
23
  /**
@@ -158,4 +158,36 @@ class Zend_Application_Resource_Db extends Zend_Application_Resource_ResourceAbs
158
  return $db;
159
  }
160
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  }
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Db.php 22544 2010-07-10 15:01:37Z freak $
21
  */
22
 
23
  /**
158
  return $db;
159
  }
160
  }
161
+
162
+ /**
163
+ * Set the default metadata cache
164
+ *
165
+ * @param string|Zend_Cache_Core $cache
166
+ * @return Zend_Application_Resource_Db
167
+ */
168
+ public function setDefaultMetadataCache($cache)
169
+ {
170
+ $metadataCache = null;
171
+
172
+ if (is_string($cache)) {
173
+ $bootstrap = $this->getBootstrap();
174
+ if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper
175
+ && $bootstrap->hasPluginResource('CacheManager')
176
+ ) {
177
+ $cacheManager = $bootstrap->bootstrap('CacheManager')
178
+ ->getResource('CacheManager');
179
+ if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
180
+ $metadataCache = $cacheManager->getCache($cache);
181
+ }
182
+ }
183
+ } else if ($cache instanceof Zend_Cache_Core) {
184
+ $metadataCache = $cache;
185
+ }
186
+
187
+ if ($metadataCache instanceof Zend_Cache_Core) {
188
+ Zend_Db_Table::setDefaultMetadataCache($metadataCache);
189
+ }
190
+
191
+ return $this;
192
+ }
193
  }
lib/Zend/Application/Resource/Dojo.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Layout.php 17687 2009-08-20 12:55:34Z thomas $
21
  */
22
 
23
  /**
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Dojo.php 21318 2010-03-04 13:20:01Z freak $
21
  */
22
 
23
  /**
lib/Zend/Application/Resource/Exception.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Exception.php 22610 2010-07-17 08:49:08Z torio $
21
  */
22
 
23
  /**
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Exception.php 22609 2010-07-17 08:47:59Z torio $
21
  */
22
 
23
  /**
lib/Zend/Application/Resource/Frontcontroller.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Frontcontroller.php 20886 2010-02-03 19:36:06Z matthew $
21
  */
22
 
23
  /**
@@ -68,7 +68,13 @@ class Zend_Application_Resource_Frontcontroller extends Zend_Application_Resourc
68
  break;
69
 
70
  case 'moduledirectory':
71
- $front->addModuleDirectory($value);
 
 
 
 
 
 
72
  break;
73
 
74
  case 'defaultcontrollername':
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Frontcontroller.php 23378 2010-11-18 21:48:27Z bittarman $
21
  */
22
 
23
  /**
68
  break;
69
 
70
  case 'moduledirectory':
71
+ if (is_string($value)) {
72
+ $front->addModuleDirectory($value);
73
+ } elseif (is_array($value)) {
74
+ foreach($value as $moduleDir) {
75
+ $front->addModuleDirectory($moduleDir);
76
+ }
77
+ }
78
  break;
79
 
80
  case 'defaultcontrollername':
lib/Zend/Application/Resource/Layout.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Layout.php 20816 2010-02-01 21:13:54Z freak $
21
  */
22
 
23
  /**
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Layout.php 20814 2010-02-01 20:13:08Z freak $
21
  */
22
 
23
  /**
lib/Zend/Application/Resource/Locale.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Locale.php 20816 2010-02-01 21:13:54Z freak $
21
  */
22
 
23
  /**
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Locale.php 20814 2010-02-01 20:13:08Z freak $
21
  */
22
 
23
  /**
lib/Zend/Application/Resource/Log.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id$
21
  */
22
 
23
  /**
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Log.php 20814 2010-02-01 20:13:08Z freak $
21
  */
22
 
23
  /**
lib/Zend/Application/Resource/Mail.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Db.php 17687 2009-08-20 12:55:34Z thomas $
21
  */
22
 
23
  /**
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Mail.php 21015 2010-02-11 01:56:02Z freak $
21
  */
22
 
23
  /**
lib/Zend/Application/Resource/Modules.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Modules.php 20816 2010-02-01 21:13:54Z freak $
21
  */
22
 
23
  /**
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Modules.php 20814 2010-02-01 20:13:08Z freak $
21
  */
22
 
23
  /**
lib/Zend/Application/Resource/Multidb.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id$
21
  */
22
 
23
  #require_once 'Zend/Application/Resource/ResourceAbstract.php';
@@ -32,6 +32,8 @@
32
  *
33
  * Example configuration:
34
  * <pre>
 
 
35
  * resources.multidb.db1.adapter = "pdo_mysql"
36
  * resources.multidb.db1.host = "localhost"
37
  * resources.multidb.db1.username = "webuser"
@@ -77,6 +79,11 @@ class Zend_Application_Resource_Multidb extends Zend_Application_Resource_Resour
77
  {
78
  $options = $this->getOptions();
79
 
 
 
 
 
 
80
  foreach ($options as $id => $params) {
81
  $adapter = $params['adapter'];
82
  $default = (int) (
@@ -168,4 +175,36 @@ class Zend_Application_Resource_Multidb extends Zend_Application_Resource_Resour
168
  Zend_Db_Table::setDefaultAdapter($adapter);
169
  $this->_defaultDb = $adapter;
170
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  }
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Multidb.php 22546 2010-07-10 15:18:12Z freak $
21
  */
22
 
23
  #require_once 'Zend/Application/Resource/ResourceAbstract.php';
32
  *
33
  * Example configuration:
34
  * <pre>
35
+ * resources.multidb.defaultMetadataCache = "database"
36
+ *
37
  * resources.multidb.db1.adapter = "pdo_mysql"
38
  * resources.multidb.db1.host = "localhost"
39
  * resources.multidb.db1.username = "webuser"
79
  {
80
  $options = $this->getOptions();
81
 
82
+ if (isset($options['defaultMetadataCache'])) {
83
+ $this->_setDefaultMetadataCache($options['defaultMetadataCache']);
84
+ unset($options['defaultMetadataCache']);
85
+ }
86
+
87
  foreach ($options as $id => $params) {
88
  $adapter = $params['adapter'];
89
  $default = (int) (
175
  Zend_Db_Table::setDefaultAdapter($adapter);
176
  $this->_defaultDb = $adapter;
177
  }
178
+
179
+ /**
180
+ * Set the default metadata cache
181
+ *
182
+ * @param string|Zend_Cache_Core $cache
183
+ * @return Zend_Application_Resource_Multidb
184
+ */
185
+ protected function _setDefaultMetadataCache($cache)
186
+ {
187
+ $metadataCache = null;
188
+
189
+ if (is_string($cache)) {
190
+ $bootstrap = $this->getBootstrap();
191
+ if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper &&
192
+ $bootstrap->hasPluginResource('CacheManager')
193
+ ) {
194
+ $cacheManager = $bootstrap->bootstrap('CacheManager')
195
+ ->getResource('CacheManager');
196
+ if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
197
+ $metadataCache = $cacheManager->getCache($cache);
198
+ }
199
+ }
200
+ } else if ($cache instanceof Zend_Cache_Core) {
201
+ $metadataCache = $cache;
202
+ }
203
+
204
+ if ($metadataCache instanceof Zend_Cache_Core) {
205
+ Zend_Db_Table::setDefaultMetadataCache($metadataCache);
206
+ }
207
+
208
+ return $this;
209
+ }
210
  }
lib/Zend/Application/Resource/Navigation.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Navigation.php 20816 2010-02-01 21:13:54Z freak $
21
  */
22
 
23
  /**
@@ -58,6 +58,10 @@ class Zend_Application_Resource_Navigation
58
  $options = $this->getOptions();
59
  $pages = isset($options['pages']) ? $options['pages'] : array();
60
  $this->_container = new Zend_Navigation($pages);
 
 
 
 
61
  }
62
 
63
  $this->store();
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Navigation.php 22882 2010-08-22 14:00:16Z freak $
21
  */
22
 
23
  /**
58
  $options = $this->getOptions();
59
  $pages = isset($options['pages']) ? $options['pages'] : array();
60
  $this->_container = new Zend_Navigation($pages);
61
+
62
+ if(isset($options['defaultPageType'])) {
63
+ Zend_Navigation_Page::setDefaultPageType($options['defaultPageType']);
64
+ }
65
  }
66
 
67
  $this->store();
lib/Zend/Application/Resource/ResourceAbstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: ResourceAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -83,6 +83,11 @@ abstract class Zend_Application_Resource_ResourceAbstract implements Zend_Applic
83
  */
84
  public function setOptions(array $options)
85
  {
 
 
 
 
 
86
  foreach ($options as $key => $value) {
87
  if (in_array(strtolower($key), $this->_skipOptions)) {
88
  continue;
@@ -92,9 +97,6 @@ abstract class Zend_Application_Resource_ResourceAbstract implements Zend_Applic
92
  if (method_exists($this, $method)) {
93
  $this->$method($value);
94
  }
95
- if ('bootstrap' === $key) {
96
- unset($options[$key]);
97
- }
98
  }
99
 
100
  $this->_options = $this->mergeOptions($this->_options, $options);
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: ResourceAbstract.php 23384 2010-11-19 00:00:29Z ramon $
21
  */
22
 
23
  /**
83
  */
84
  public function setOptions(array $options)
85
  {
86
+ if (array_key_exists('bootstrap', $options)) {
87
+ $this->setBootstrap($options['bootstrap']);
88
+ unset($options['bootstrap']);
89
+ }
90
+
91
  foreach ($options as $key => $value) {
92
  if (in_array(strtolower($key), $this->_skipOptions)) {
93
  continue;
97
  if (method_exists($this, $method)) {
98
  $this->$method($value);
99
  }
 
 
 
100
  }
101
 
102
  $this->_options = $this->mergeOptions($this->_options, $options);
lib/Zend/Application/Resource/Router.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Router.php 20816 2010-02-01 21:13:54Z freak $
21
  */
22
 
23
  /**
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Router.php 20814 2010-02-01 20:13:08Z freak $
21
  */
22
 
23
  /**
lib/Zend/Application/Resource/Session.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Session.php 20816 2010-02-01 21:13:54Z freak $
21
  */
22
 
23
  /**
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Session.php 20814 2010-02-01 20:13:08Z freak $
21
  */
22
 
23
  /**
lib/Zend/Application/Resource/Translate.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Translate.php 21770 2010-04-05 20:16:08Z thomas $
21
  */
22
 
23
  /**
@@ -67,9 +67,14 @@ class Zend_Application_Resource_Translate extends Zend_Application_Resource_Reso
67
  if (null === $this->_translate) {
68
  $options = $this->getOptions();
69
 
70
- if (!isset($options['data'])) {
71
  #require_once 'Zend/Application/Resource/Exception.php';
72
  throw new Zend_Application_Resource_Exception('No translation source data provided.');
 
 
 
 
 
73
  }
74
 
75
  if (empty($options['adapter'])) {
@@ -87,6 +92,21 @@ class Zend_Application_Resource_Translate extends Zend_Application_Resource_Reso
87
  }
88
  }
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  $key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
91
  ? $options['registry_key']
92
  : self::DEFAULT_REGISTRY_KEY;
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Translate.php 22968 2010-09-18 19:50:02Z intiilapa $
21
  */
22
 
23
  /**
67
  if (null === $this->_translate) {
68
  $options = $this->getOptions();
69
 
70
+ if (!isset($options['content']) && !isset($options['data'])) {
71
  #require_once 'Zend/Application/Resource/Exception.php';
72
  throw new Zend_Application_Resource_Exception('No translation source data provided.');
73
+ } else if (array_key_exists('content', $options) && array_key_exists('data', $options)) {
74
+ #require_once 'Zend/Application/Resource/Exception.php';
75
+ throw new Zend_Application_Resource_Exception(
76
+ 'Conflict on translation source data: choose only one key between content and data.'
77
+ );
78
  }
79
 
80
  if (empty($options['adapter'])) {
92
  }
93
  }
94
 
95
+ if (!empty($options['cache']) && is_string($options['cache'])) {
96
+ $bootstrap = $this->getBootstrap();
97
+ if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper &&
98
+ $bootstrap->hasPluginResource('CacheManager')
99
+ ) {
100
+ $cacheManager = $bootstrap->bootstrap('CacheManager')
101
+ ->getResource('CacheManager');
102
+ if (null !== $cacheManager &&
103
+ $cacheManager->hasCache($options['cache'])
104
+ ) {
105
+ $options['cache'] = $cacheManager->getCache($options['cache']);
106
+ }
107
+ }
108
+ }
109
+
110
  $key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
111
  ? $options['registry_key']
112
  : self::DEFAULT_REGISTRY_KEY;
lib/Zend/Application/Resource/Useragent.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Application
17
+ * @subpackage Resource
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @category Zend
24
+ * @package Zend_Application
25
+ * @subpackage Resource
26
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
+ * @license http://framework.zend.com/license/new-bsd New BSD License
28
+ */
29
+ class Zend_Application_Resource_UserAgent extends Zend_Application_Resource_ResourceAbstract
30
+ {
31
+ /**
32
+ * @var Zend_Http_UserAgent
33
+ */
34
+ protected $_userAgent;
35
+
36
+ /**
37
+ * Intialize resource
38
+ *
39
+ * @return Zend_Http_UserAgent
40
+ */
41
+ public function init()
42
+ {
43
+ $userAgent = $this->getUserAgent();
44
+
45
+ // Optionally seed the UserAgent view helper
46
+ $bootstrap = $this->getBootstrap();
47
+ if ($bootstrap->hasResource('view') || $bootstrap->hasPluginResource('view')) {
48
+ $bootstrap->bootstrap('view');
49
+ $view = $bootstrap->getResource('view');
50
+ if (null !== $view) {
51
+ $view->userAgent($userAgent);
52
+ }
53
+ }
54
+
55
+ return $userAgent;
56
+ }
57
+
58
+ /**
59
+ * Get UserAgent instance
60
+ *
61
+ * @return Zend_Http_UserAgent
62
+ */
63
+ public function getUserAgent()
64
+ {
65
+ if (null === $this->_userAgent) {
66
+ $options = $this->getOptions();
67
+ $this->_userAgent = new Zend_Http_UserAgent($options);
68
+ }
69
+
70
+ return $this->_userAgent;
71
+ }
72
+ }
lib/Zend/Application/Resource/View.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: View.php 20816 2010-02-01 21:13:54Z freak $
21
  */
22
 
23
  /**
@@ -69,8 +69,14 @@ class Zend_Application_Resource_View extends Zend_Application_Resource_ResourceA
69
  $options = $this->getOptions();
70
  $this->_view = new Zend_View($options);
71
 
72
- if(isset($options['doctype'])) {
73
  $this->_view->doctype()->setDoctype(strtoupper($options['doctype']));
 
 
 
 
 
 
74
  }
75
  }
76
  return $this->_view;
17
  * @subpackage Resource
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: View.php 22965 2010-09-18 17:45:51Z intiilapa $
21
  */
22
 
23
  /**
69
  $options = $this->getOptions();
70
  $this->_view = new Zend_View($options);
71
 
72
+ if (isset($options['doctype'])) {
73
  $this->_view->doctype()->setDoctype(strtoupper($options['doctype']));
74
+ if (isset($options['charset']) && $this->_view->doctype()->isHtml5()) {
75
+ $this->_view->headMeta()->setCharset($options['charset']);
76
+ }
77
+ }
78
+ if (isset($options['contentType'])) {
79
+ $this->_view->headMeta()->appendHttpEquiv('Content-Type', $options['contentType']);
80
  }
81
  }
82
  return $this->_view;
lib/Zend/Auth/Adapter/DbTable.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: DbTable.php 22614 2010-07-17 13:46:07Z dragonbe $
21
  */
22
 
23
 
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: DbTable.php 22613 2010-07-17 13:43:22Z dragonbe $
21
  */
22
 
23
 
lib/Zend/Auth/Adapter/Digest.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Digest.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
 
@@ -213,7 +213,7 @@ class Zend_Auth_Adapter_Digest implements Zend_Auth_Adapter_Interface
213
 
214
  while ($line = trim(fgets($fileHandle))) {
215
  if (substr($line, 0, $idLength) === $id) {
216
- if (substr($line, -32) === md5("$this->_username:$this->_realm:$this->_password")) {
217
  $result['code'] = Zend_Auth_Result::SUCCESS;
218
  } else {
219
  $result['code'] = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
@@ -227,4 +227,26 @@ class Zend_Auth_Adapter_Digest implements Zend_Auth_Adapter_Interface
227
  $result['messages'][] = "Username '$this->_username' and realm '$this->_realm' combination not found";
228
  return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages']);
229
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  }
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Digest.php 23088 2010-10-11 19:53:24Z padraic $
21
  */
22
 
23
 
213
 
214
  while ($line = trim(fgets($fileHandle))) {
215
  if (substr($line, 0, $idLength) === $id) {
216
+ if ($this->_secureStringCompare(substr($line, -32), md5("$this->_username:$this->_realm:$this->_password"))) {
217
  $result['code'] = Zend_Auth_Result::SUCCESS;
218
  } else {
219
  $result['code'] = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
227
  $result['messages'][] = "Username '$this->_username' and realm '$this->_realm' combination not found";
228
  return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages']);
229
  }
230
+
231
+ /**
232
+ * Securely compare two strings for equality while avoided C level memcmp()
233
+ * optimisations capable of leaking timing information useful to an attacker
234
+ * attempting to iteratively guess the unknown string (e.g. password) being
235
+ * compared against.
236
+ *
237
+ * @param string $a
238
+ * @param string $b
239
+ * @return bool
240
+ */
241
+ protected function _secureStringCompare($a, $b)
242
+ {
243
+ if (strlen($a) !== strlen($b)) {
244
+ return false;
245
+ }
246
+ $result = 0;
247
+ for ($i = 0; $i < strlen($a); $i++) {
248
+ $result |= ord($a[$i]) ^ ord($b[$i]);
249
+ }
250
+ return $result == 0;
251
+ }
252
  }
lib/Zend/Auth/Adapter/Http.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Auth_Adapter_Http
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Http.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
 
@@ -538,7 +538,7 @@ class Zend_Auth_Adapter_Http implements Zend_Auth_Adapter_Interface
538
  }
539
 
540
  $password = $this->_basicResolver->resolve($creds[0], $this->_realm);
541
- if ($password && $password == $creds[1]) {
542
  $identity = array('username'=>$creds[0], 'realm'=>$this->_realm);
543
  return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
544
  } else {
@@ -640,7 +640,7 @@ class Zend_Auth_Adapter_Http implements Zend_Auth_Adapter_Interface
640
 
641
  // If our digest matches the client's let them in, otherwise return
642
  // a 401 code and exit to prevent access to the protected resource.
643
- if ($digest == $data['response']) {
644
  $identity = array('username'=>$data['username'], 'realm'=>$data['realm']);
645
  return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
646
  } else {
@@ -844,4 +844,26 @@ class Zend_Auth_Adapter_Http implements Zend_Auth_Adapter_Interface
844
 
845
  return $data;
846
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
847
  }
17
  * @subpackage Zend_Auth_Adapter_Http
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Http.php 23088 2010-10-11 19:53:24Z padraic $
21
  */
22
 
23
 
538
  }
539
 
540
  $password = $this->_basicResolver->resolve($creds[0], $this->_realm);
541
+ if ($password && $this->_secureStringCompare($password, $creds[1])) {
542
  $identity = array('username'=>$creds[0], 'realm'=>$this->_realm);
543
  return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
544
  } else {
640
 
641
  // If our digest matches the client's let them in, otherwise return
642
  // a 401 code and exit to prevent access to the protected resource.
643
+ if ($this->_secureStringCompare($digest, $data['response'])) {
644
  $identity = array('username'=>$data['username'], 'realm'=>$data['realm']);
645
  return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
646
  } else {
844
 
845
  return $data;
846
  }
847
+
848
+ /**
849
+ * Securely compare two strings for equality while avoided C level memcmp()
850
+ * optimisations capable of leaking timing information useful to an attacker
851
+ * attempting to iteratively guess the unknown string (e.g. password) being
852
+ * compared against.
853
+ *
854
+ * @param string $a
855
+ * @param string $b
856
+ * @return bool
857
+ */
858
+ protected function _secureStringCompare($a, $b)
859
+ {
860
+ if (strlen($a) !== strlen($b)) {
861
+ return false;
862
+ }
863
+ $result = 0;
864
+ for ($i = 0; $i < strlen($a); $i++) {
865
+ $result |= ord($a[$i]) ^ ord($b[$i]);
866
+ }
867
+ return $result == 0;
868
+ }
869
  }
lib/Zend/Auth/Adapter/Ldap.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Auth_Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Ldap.php 21320 2010-03-04 16:05:09Z sgehrig $
21
  */
22
 
23
  /**
17
  * @subpackage Zend_Auth_Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Ldap.php 21319 2010-03-04 16:02:16Z sgehrig $
21
  */
22
 
23
  /**
lib/Zend/Barcode/Exception.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Barcode
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
  /**
22
  * Zend_Exception
@@ -41,8 +41,8 @@ class Zend_Barcode_Exception extends Zend_Exception
41
 
42
  /**
43
  * Set renderable flag
44
- *
45
- * @param bool $flag
46
  * @return Zend_Barcode_Exception
47
  */
48
  public function setIsRenderable($flag)
@@ -53,7 +53,7 @@ class Zend_Barcode_Exception extends Zend_Exception
53
 
54
  /**
55
  * Retrieve renderable flag
56
- *
57
  * @return bool
58
  */
59
  public function isRenderable()
16
  * @package Zend_Barcode
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Exception.php 22999 2010-09-23 19:43:14Z mikaelkael $
20
  */
21
  /**
22
  * Zend_Exception
41
 
42
  /**
43
  * Set renderable flag
44
+ *
45
+ * @param bool $flag
46
  * @return Zend_Barcode_Exception
47
  */
48
  public function setIsRenderable($flag)
53
 
54
  /**
55
  * Retrieve renderable flag
56
+ *
57
  * @return bool
58
  */
59
  public function isRenderable()
lib/Zend/Barcode/Object/Code128.php ADDED
@@ -0,0 +1,391 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Barcode
17
+ * @subpackage Object
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Code25.php 20096 2010-01-06 02:05:09Z bkarwin $
21
+ */
22
+
23
+ /**
24
+ * @see Zend_Barcode_Object_ObjectAbstract
25
+ */
26
+ #require_once 'Zend/Barcode/Object/ObjectAbstract.php';
27
+
28
+ /**
29
+ * @see Zend_Validate_Barcode
30
+ */
31
+ #require_once 'Zend/Validate/Barcode.php';
32
+
33
+ /**
34
+ * Class for generate Code128 barcode
35
+ *
36
+ * @category Zend
37
+ * @package Zend_Barcode
38
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
39
+ * @license http://framework.zend.com/license/new-bsd New BSD License
40
+ */
41
+ class Zend_Barcode_Object_Code128 extends Zend_Barcode_Object_ObjectAbstract
42
+ {
43
+ /**
44
+ * Drawing of checksum
45
+ * (even if it's sometime optional, most of time it's required)
46
+ * @var boolean
47
+ */
48
+ protected $_withChecksum = true;
49
+
50
+ /**
51
+ * @var array
52
+ */
53
+ protected $_convertedText = array();
54
+
55
+ protected $_codingMap = array(
56
+ 0 => "11011001100", 1 => "11001101100", 2 => "11001100110",
57
+ 3 => "10010011000", 4 => "10010001100", 5 => "10001001100",
58
+ 6 => "10011001000", 7 => "10011000100", 8 => "10001100100",
59
+ 9 => "11001001000", 10 => "11001000100", 11 => "11000100100",
60
+ 12 => "10110011100", 13 => "10011011100", 14 => "10011001110",
61
+ 15 => "10111001100", 16 => "10011101100", 17 => "10011100110",
62
+ 18 => "11001110010", 19 => "11001011100", 20 => "11001001110",
63
+ 21 => "11011100100", 22 => "11001110100", 23 => "11101101110",
64
+ 24 => "11101001100", 25 => "11100101100", 26 => "11100100110",
65
+ 27 => "11101100100", 28 => "11100110100", 29 => "11100110010",
66
+ 30 => "11011011000", 31 => "11011000110", 32 => "11000110110",
67
+ 33 => "10100011000", 34 => "10001011000", 35 => "10001000110",
68
+ 36 => "10110001000", 37 => "10001101000", 38 => "10001100010",
69
+ 39 => "11010001000", 40 => "11000101000", 41 => "11000100010",
70
+ 42 => "10110111000", 43 => "10110001110", 44 => "10001101110",
71
+ 45 => "10111011000", 46 => "10111000110", 47 => "10001110110",
72
+ 48 => "11101110110", 49 => "11010001110", 50 => "11000101110",
73
+ 51 => "11011101000", 52 => "11011100010", 53 => "11011101110",
74
+ 54 => "11101011000", 55 => "11101000110", 56 => "11100010110",
75
+ 57 => "11101101000", 58 => "11101100010", 59 => "11100011010",
76
+ 60 => "11101111010", 61 => "11001000010", 62 => "11110001010",
77
+ 63 => "10100110000", 64 => "10100001100", 65 => "10010110000",
78
+ 66 => "10010000110", 67 => "10000101100", 68 => "10000100110",
79
+ 69 => "10110010000", 70 => "10110000100", 71 => "10011010000",
80
+ 72 => "10011000010", 73 => "10000110100", 74 => "10000110010",
81
+ 75 => "11000010010", 76 => "11001010000", 77 => "11110111010",
82
+ 78 => "11000010100", 79 => "10001111010", 80 => "10100111100",
83
+ 81 => "10010111100", 82 => "10010011110", 83 => "10111100100",
84
+ 84 => "10011110100", 85 => "10011110010", 86 => "11110100100",
85
+ 87 => "11110010100", 88 => "11110010010", 89 => "11011011110",
86
+ 90 => "11011110110", 91 => "11110110110", 92 => "10101111000",
87
+ 93 => "10100011110", 94 => "10001011110", 95 => "10111101000",
88
+ 96 => "10111100010", 97 => "11110101000", 98 => "11110100010",
89
+ 99 => "10111011110", 100 => "10111101110", 101 => "11101011110",
90
+ 102 => "11110101110",
91
+ 103 => "11010000100", 104 => "11010010000", 105 => "11010011100",
92
+ 106 => "1100011101011");
93
+
94
+ /**
95
+ * Character sets ABC
96
+ * @var array
97
+ */
98
+ protected $_charSets = array(
99
+ 'A' => array(
100
+ ' ', '!', '"', '#', '$', '%', '&', "'",
101
+ '(', ')', '*', '+', ',', '-', '.', '/',
102
+ '0', '1', '2', '3', '4', '5', '6', '7',
103
+ '8', '9', ':', ';', '<', '=', '>', '?',
104
+ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
105
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
106
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
107
+ 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
108
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
109
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
110
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
111
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
112
+ 'FNC3', 'FNC2', 'SHIFT', 'Code C', 'Code B', 'FNC4', 'FNC1',
113
+ 'START A', 'START B', 'START C', 'STOP'),
114
+ 'B' => array(
115
+ ' ', '!', '"', '#', '$', '%', '&', "'",
116
+ '(', ')', '*', '+', ',', '-', '.', '/',
117
+ '0', '1', '2', '3', '4', '5', '6', '7',
118
+ '8', '9', ':', ';', '<', '=', '>', '?',
119
+ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
120
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
121
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
122
+ 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
123
+ '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
124
+ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
125
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
126
+ 'x', 'y', 'z', '{', '|', '}', '~', 0x7F,
127
+ 'FNC3', 'FNC2', 'SHIFT', 'Code C', 'FNC4', 'Code A', 'FNC1',
128
+ 'START A', 'START B', 'START C', 'STOP',),
129
+ 'C' => array(
130
+ '00', '01', '02', '03', '04', '05', '06', '07', '08', '09',
131
+ '10', '11', '12', '13', '14', '15', '16', '17', '18', '19',
132
+ '20', '21', '22', '23', '24', '25', '26', '27', '28', '29',
133
+ '30', '31', '32', '33', '34', '35', '36', '37', '38', '39',
134
+ '40', '41', '42', '43', '44', '45', '46', '47', '48', '49',
135
+ '50', '51', '52', '53', '54', '55', '56', '57', '58', '59',
136
+ '60', '61', '62', '63', '64', '65', '66', '67', '68', '69',
137
+ '70', '71', '72', '73', '74', '75', '76', '77', '78', '79',
138
+ '80', '81', '82', '83', '84', '85', '86', '87', '88', '89',
139
+ '90', '91', '92', '93', '94', '95', '96', '97', '98', '99',
140
+ 'Code B', 'Code A', 'FNC1', 'START A', 'START B', 'START C', 'STOP'));
141
+ /*'A' => array(
142
+ ' '=>0, '!'=>1, '"'=>2, '#'=>3, '$'=>4, '%'=>5, '&'=>6, "'"=>7,
143
+ '('=>8, ')'=>9, '*'=>10, '+'=>11, ','=>12, '-'=>13, '.'=>14, '/'=>15,
144
+ '0'=>16, '1'=>17, '2'=>18, '3'=>19, '4'=>20, '5'=>21, '6'=>22, '7'=>23,
145
+ '8'=>24, '9'=>25, ':'=>26, ';'=>27, '<'=>28, '='=>29, '>'=>30, '?'=>31,
146
+ '@'=>32, 'A'=>33, 'B'=>34, 'C'=>35, 'D'=>36, 'E'=>37, 'F'=>38, 'G'=>39,
147
+ 'H'=>40, 'I'=>41, 'J'=>42, 'K'=>43, 'L'=>44, 'M'=>45, 'N'=>46, 'O'=>47,
148
+ 'P'=>48, 'Q'=>49, 'R'=>50, 'S'=>51, 'T'=>52, 'U'=>53, 'V'=>54, 'W'=>55,
149
+ 'X'=>56, 'Y'=>57, 'Z'=>58, '['=>59, '\\'=>60, ']'=>61, '^'=>62, '_'=>63,
150
+ 0x00=>64, 0x01=>65, 0x02=>66, 0x03=>67, 0x04=>68, 0x05=>69, 0x06=>70, 0x07=>71,
151
+ 0x08=>72, 0x09=>73, 0x0A=>74, 0x0B=>75, 0x0C=>76, 0x0D=>77, 0x0E=>78, 0x0F=>79,
152
+ 0x10=>80, 0x11=>81, 0x12=>82, 0x13=>83, 0x14=>84, 0x15=>85, 0x16=>86, 0x17=>87,
153
+ 0x18=>88, 0x19=>89, 0x1A=>90, 0x1B=>91, 0x1C=>92, 0x1D=>93, 0x1E=>94, 0x1F=>95,
154
+ 'FNC3'=>96, 'FNC2'=>97, 'SHIFT'=>98, 'Code C'=>99, 'Code B'=>100, 'FNC4'=>101, 'FNC1'=>102, 'START A'=>103,
155
+ 'START B'=>104, 'START C'=>105, 'STOP'=>106),
156
+ 'B' => array(
157
+ ' '=>0, '!'=>1, '"'=>2, '#'=>3, '$'=>4, '%'=>5, '&'=>6, "'"=>7,
158
+ '('=>8, ')'=>9, '*'=>10, '+'=>11, ','=>12, '-'=>13, '.'=>14, '/'=>15,
159
+ '0'=>16, '1'=>17, '2'=>18, '3'=>19, '4'=>20, '5'=>21, '6'=>22, '7'=>23,
160
+ '8'=>24, '9'=>25, ':'=>26, ';'=>27, '<'=>28, '='=>29, '>'=>30, '?'=>31,
161
+ '@'=>32, 'A'=>33, 'B'=>34, 'C'=>35, 'D'=>36, 'E'=>37, 'F'=>38, 'G'=>39,
162
+ 'H'=>40, 'I'=>41, 'J'=>42, 'K'=>43, 'L'=>44, 'M'=>45, 'N'=>46, 'O'=>47,
163
+ 'P'=>48, 'Q'=>49, 'R'=>50, 'S'=>51, 'T'=>52, 'U'=>53, 'V'=>54, 'W'=>55,
164
+ 'X'=>56, 'Y'=>57, 'Z'=>58, '['=>59, '\\'=>60, ']'=>61, '^'=>62, '_'=>63,
165
+ '`' =>64, 'a'=>65, 'b'=>66, 'c'=>67, 'd'=>68, 'e'=>69, 'f'=>70, 'g'=>71,
166
+ 'h'=>72, 'i'=>73, 'j'=>74, 'k'=>75, 'l'=>76, 'm'=>77, 'n'=>78, 'o'=>79,
167
+ 'p'=>80, 'q'=>81, 'r'=>82, 's'=>83, 't'=>84, 'u'=>85, 'v'=>86, 'w'=>87,
168
+ 'x'=>88, 'y'=>89, 'z'=>90, '{'=>91, '|'=>92, '}'=>93, '~'=>94, 0x7F=>95,
169
+ 'FNC3'=>96, 'FNC2'=>97, 'SHIFT'=>98, 'Code C'=>99, 'FNC4'=>100, 'Code A'=>101, 'FNC1'=>102, 'START A'=>103,
170
+ 'START B'=>104, 'START C'=>105, 'STOP'=>106,),
171
+ 'C' => array(
172
+ '00'=>0, '01'=>1, '02'=>2, '03'=>3, '04'=>4, '05'=>5, '06'=>6, '07'=>7, '08'=>8, '09'=>9,
173
+ '10'=>10, '11'=>11, '12'=>12, '13'=>13, '14'=>14, '15'=>15, '16'=>16, '17'=>17, '18'=>18, '19'=>19,
174
+ '20'=>20, '21'=>21, '22'=>22, '23'=>23, '24'=>24, '25'=>25, '26'=>26, '27'=>27, '28'=>28, '29'=>29,
175
+ '30'=>30, '31'=>31, '32'=>32, '33'=>33, '34'=>34, '35'=>35, '36'=>36, '37'=>37, '38'=>38, '39'=>39,
176
+ '40'=>40, '41'=>41, '42'=>42, '43'=>43, '44'=>44, '45'=>45, '46'=>46, '47'=>47, '48'=>48, '49'=>49,
177
+ '50'=>50, '51'=>51, '52'=>52, '53'=>53, '54'=>54, '55'=>55, '56'=>56, '57'=>57, '58'=>58, '59'=>59,
178
+ '60'=>60, '61'=>61, '62'=>62, '63'=>63, '64'=>64, '65'=>65, '66'=>66, '67'=>67, '68'=>68, '69'=>69,
179
+ '70'=>70, '71'=>71, '72'=>72, '73'=>73, '74'=>74, '75'=>75, '76'=>76, '77'=>77, '78'=>78, '79'=>79,
180
+ '80'=>80, '81'=>81, '82'=>82, '83'=>83, '84'=>84, '85'=>85, '86'=>86, '87'=>87, '88'=>88, '89'=>89,
181
+ '90'=>90, '91'=>91, '92'=>92, '93'=>93, '94'=>94, '95'=>95, '96'=>96, '97'=>97, '98'=>98, '99'=>99,
182
+ 'Code B'=>100, 'Code A'=>101, 'FNC1'=>102, 'START A'=>103, 'START B'=>104, 'START C'=>105, 'STOP'=>106));*/
183
+
184
+ /**
185
+ * Width of the barcode (in pixels)
186
+ * @return integer
187
+ */
188
+ protected function _calculateBarcodeWidth()
189
+ {
190
+ $quietZone = $this->getQuietZone();
191
+ // Each characters contain 11 bars...
192
+ $characterLength = 11 * $this->_barThinWidth * $this->_factor;
193
+ $convertedChars = count($this->_convertToBarcodeChars($this->getText()));
194
+ if ($this->_withChecksum) {
195
+ $convertedChars++;
196
+ }
197
+ $encodedData = $convertedChars * $characterLength;
198
+ // ...except the STOP character (13)
199
+ $encodedData += $characterLength + 2 * $this->_barThinWidth * $this->_factor;
200
+ $width = $quietZone + $encodedData + $quietZone;
201
+ return $width;
202
+ }
203
+
204
+ /**
205
+ * Partial check of code128 barcode
206
+ * @return void
207
+ */
208
+ protected function _checkParams()
209
+ {
210
+ }
211
+
212
+ /**
213
+ * Prepare array to draw barcode
214
+ * @return array
215
+ */
216
+ protected function _prepareBarcode()
217
+ {
218
+ $barcodeTable = array();
219
+
220
+ $convertedChars = $this->_convertToBarcodeChars($this->getText());
221
+
222
+ if ($this->_withChecksum) {
223
+ $convertedChars[] = $this->getChecksum($this->getText());
224
+ }
225
+
226
+ // STOP CHARACTER
227
+ $convertedChars[] = 106;
228
+
229
+ foreach ($convertedChars as $barcodeChar) {
230
+ $barcodePattern = $this->_codingMap[$barcodeChar];
231
+ foreach (str_split($barcodePattern) as $c) {
232
+ $barcodeTable[] = array($c, 1, 0, 1);
233
+ }
234
+ }
235
+ return $barcodeTable;
236
+ }
237
+
238
+ /**
239
+ * Checks if the next $length chars of $string starting at $pos are numeric.
240
+ * Returns false if the end of the string is reached.
241
+ * @param $string String to search
242
+ * @param $pos Starting position
243
+ * @param $length Length to search
244
+ * @return bool
245
+ */
246
+ protected static function _isDigit($string, $pos, $length = 2)
247
+ {
248
+ if ($pos + $length > strlen($string)) {
249
+ return false;
250
+ }
251
+
252
+ for ($i = $pos; $i < $pos + $length; $i++) {
253
+ if (!is_numeric($string[$i])) {
254
+ return false;
255
+ }
256
+ }
257
+ return true;
258
+ }
259
+
260
+ /**
261
+ * Convert string to barcode string
262
+ * @return array
263
+ */
264
+ protected function _convertToBarcodeChars($string)
265
+ {
266
+ $string = (string) $string;
267
+ if (!strlen($string)) {
268
+ return array();
269
+ }
270
+
271
+ if (isset($this->_convertedText[md5($string)])) {
272
+ return $this->_convertedText[md5($string)];
273
+ }
274
+
275
+ $currentCharset = null;
276
+ $sum = 0;
277
+ $fak = 0;
278
+ $result = array();
279
+
280
+ for ($pos = 0; $pos < strlen($string); $pos++) {
281
+ $char = $string[$pos];
282
+ $code = null;
283
+
284
+ if (self::_isDigit($string, $pos, 4) && $currentCharset != 'C'
285
+ || self::_isDigit($string, $pos, 2) && $currentCharset == 'C') {
286
+ /**
287
+ * Switch to C if the next 4 chars are numeric or stay C if the next 2
288
+ * chars are numeric
289
+ */
290
+ if ($currentCharset != 'C') {
291
+ if ($pos == 0) {
292
+ $code = array_search("START C", $this->_charSets['C']);
293
+ } else {
294
+ $code = array_search("Code C", $this->_charSets[$currentCharset]);
295
+ }
296
+ $result[] = $code;
297
+ $currentCharset = 'C';
298
+ }
299
+ } else if (in_array($char, $this->_charSets['B']) && $currentCharset != 'B'
300
+ && !(in_array($char, $this->_charSets['A']) && $currentCharset == 'A')) {
301
+ /**
302
+ * Switch to B as B contains the char and B is not the current charset.
303
+ */
304
+ if ($pos == 0) {
305
+ $code = array_search("START B", $this->_charSets['B']);
306
+ } else {
307
+ $code = array_search("Code B", $this->_charSets[$currentCharset]);
308
+ }
309
+ $result[] = $code;
310
+ $currentCharset = 'B';
311
+ } else if (array_key_exists($char, $this->_charSets['A']) && $currentCharset != 'A'
312
+ && !(array_key_exists($char, $this->_charSets['B']) && $currentCharset == 'B')) {
313
+ /**
314
+ * Switch to C as C contains the char and C is not the current charset.
315
+ */
316
+ if ($pos == 0) {
317
+ $code = array_search("START A", $this->_charSets['A']);
318
+ } else {
319
+ $code =array_search("Code A", $this->_charSets[$currentCharset]);
320
+ }
321
+ $result[] = $code;
322
+ $currentCharset = 'A';
323
+ }
324
+
325
+ if ($currentCharset == 'C') {
326
+ $code = array_search(substr($string, $pos, 2), $this->_charSets['C']);
327
+ $pos++; //Two chars from input
328
+ } else {
329
+ $code = array_search($string[$pos], $this->_charSets[$currentCharset]);
330
+ }
331
+ $result[] = $code;
332
+ }
333
+
334
+ $this->_convertedText[md5($string)] = $result;
335
+ return $result;
336
+ }
337
+
338
+ /**
339
+ * Set text to encode
340
+ * @param string $value
341
+ * @return Zend_Barcode_Object
342
+ */
343
+ public function setText($value)
344
+ {
345
+ $this->_text = $value;
346
+ return $this;
347
+ }
348
+
349
+ /**
350
+ * Retrieve text to encode
351
+ * @return string
352
+ */
353
+ public function getText()
354
+ {
355
+ return $this->_text;
356
+ }
357
+
358
+ /**
359
+ * Get barcode checksum
360
+ *
361
+ * @param string $text
362
+ * @return int
363
+ */
364
+ public function getChecksum($text)
365
+ {
366
+ $tableOfChars = $this->_convertToBarcodeChars($text);
367
+
368
+ $sum = $tableOfChars[0];
369
+ unset($tableOfChars[0]);
370
+
371
+ $k = 1;
372
+ foreach ($tableOfChars as $char) {
373
+ $sum += ($k++) * $char;
374
+ }
375
+
376
+ $checksum = $sum % 103;
377
+
378
+ return $checksum;
379
+ }
380
+
381
+ /**
382
+ * Standard validation for most of barcode objects
383
+ * @param string $value
384
+ * @param array $options
385
+ */
386
+ protected function _validateText($value, $options = array())
387
+ {
388
+ // @TODO: add code128 validator
389
+ return true;
390
+ }
391
+ }
lib/Zend/Barcode/Object/Code39.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Code39.php 21658 2010-03-27 14:29:57Z mikaelkael $
21
  */
22
 
23
  /**
@@ -112,6 +112,17 @@ class Zend_Barcode_Object_Code39 extends Zend_Barcode_Object_ObjectAbstract
112
  return $quietZone + $encodedData + $quietZone;
113
  }
114
 
 
 
 
 
 
 
 
 
 
 
 
115
  /**
116
  * Retrieve text to display
117
  * @return string
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Code39.php 23398 2010-11-19 17:17:05Z mikaelkael $
21
  */
22
 
23
  /**
112
  return $quietZone + $encodedData + $quietZone;
113
  }
114
 
115
+ /**
116
+ * Set text to encode
117
+ * @param string $value
118
+ * @return Zend_Barcode_Object
119
+ */
120
+ public function setText($value)
121
+ {
122
+ $this->_text = $value;
123
+ return $this;
124
+ }
125
+
126
  /**
127
  * Retrieve text to display
128
  * @return string
lib/Zend/Barcode/Object/Ean13.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Ean13.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -62,17 +62,17 @@ class Zend_Barcode_Object_Ean13 extends Zend_Barcode_Object_ObjectAbstract
62
  ));
63
 
64
  protected $_parities = array(
65
- 0 => array('A','A','A','A','A','A'),
66
- 1 => array('A','A','B','A','B','B'),
67
- 2 => array('A','A','B','B','A','B'),
68
- 3 => array('A','A','B','B','B','A'),
69
- 4 => array('A','B','A','A','B','B'),
70
- 5 => array('A','B','B','A','A','B'),
71
- 6 => array('A','B','B','B','A','A'),
72
- 7 => array('A','B','A','B','A','B'),
73
- 8 => array('A','B','A','B','B','A'),
74
- 9 => array('A','B','B','A','B','A')
75
- );
76
 
77
  /**
78
  * Default options for Postnet barcode
@@ -82,6 +82,7 @@ class Zend_Barcode_Object_Ean13 extends Zend_Barcode_Object_ObjectAbstract
82
  {
83
  $this->_barcodeLength = 13;
84
  $this->_mandatoryChecksum = true;
 
85
  }
86
 
87
  /**
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Ean13.php 22999 2010-09-23 19:43:14Z mikaelkael $
21
  */
22
 
23
  /**
62
  ));
63
 
64
  protected $_parities = array(
65
+ 0 => array('A','A','A','A','A','A'),
66
+ 1 => array('A','A','B','A','B','B'),
67
+ 2 => array('A','A','B','B','A','B'),
68
+ 3 => array('A','A','B','B','B','A'),
69
+ 4 => array('A','B','A','A','B','B'),
70
+ 5 => array('A','B','B','A','A','B'),
71
+ 6 => array('A','B','B','B','A','A'),
72
+ 7 => array('A','B','A','B','A','B'),
73
+ 8 => array('A','B','A','B','B','A'),
74
+ 9 => array('A','B','B','A','B','A')
75
+ );
76
 
77
  /**
78
  * Default options for Postnet barcode
82
  {
83
  $this->_barcodeLength = 13;
84
  $this->_mandatoryChecksum = true;
85
+ $this->_mandatoryQuietZones = true;
86
  }
87
 
88
  /**
lib/Zend/Barcode/Object/Ean8.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Ean8.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -59,9 +59,10 @@ class Zend_Barcode_Object_Ean8 extends Zend_Barcode_Object_Ean13
59
  {
60
  $quietZone = $this->getQuietZone();
61
  $startCharacter = (3 * $this->_barThinWidth) * $this->_factor;
 
62
  $stopCharacter = (3 * $this->_barThinWidth) * $this->_factor;
63
  $encodedData = (7 * $this->_barThinWidth) * $this->_factor * 8;
64
- return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
65
  }
66
 
67
  /**
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Ean8.php 21667 2010-03-28 17:45:14Z mikaelkael $
21
  */
22
 
23
  /**
59
  {
60
  $quietZone = $this->getQuietZone();
61
  $startCharacter = (3 * $this->_barThinWidth) * $this->_factor;
62
+ $middleCharacter = (5 * $this->_barThinWidth) * $this->_factor;
63
  $stopCharacter = (3 * $this->_barThinWidth) * $this->_factor;
64
  $encodedData = (7 * $this->_barThinWidth) * $this->_factor * 8;
65
+ return $quietZone + $startCharacter + $middleCharacter + $encodedData + $stopCharacter + $quietZone;
66
  }
67
 
68
  /**
lib/Zend/Barcode/Object/ObjectAbstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: ObjectAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -103,6 +103,18 @@ abstract class Zend_Barcode_Object_ObjectAbstract
103
  */
104
  protected $_withBorder = false;
105
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  /**
107
  * Orientation of the barcode in degrees
108
  * @var float
@@ -372,7 +384,7 @@ abstract class Zend_Barcode_Object_ObjectAbstract
372
  /**
373
  * Set factor applying to
374
  * thinBarWidth - thickBarWidth - barHeight - fontSize
375
- * @param integer $value
376
  * @return Zend_Barcode_Object
377
  * @throw Zend_Barcode_Object_Exception
378
  */
@@ -478,6 +490,26 @@ abstract class Zend_Barcode_Object_ObjectAbstract
478
  return $this->_withBorder;
479
  }
480
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  /**
482
  * Allow fast inversion of font/bars color and background color
483
  * @return Zend_Barcode_Object
@@ -770,7 +802,11 @@ abstract class Zend_Barcode_Object_ObjectAbstract
770
  */
771
  public function getQuietZone()
772
  {
773
- return 10 * $this->_barThinWidth * $this->_factor;
 
 
 
 
774
  }
775
 
776
  /**
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: ObjectAbstract.php 23400 2010-11-19 17:18:31Z mikaelkael $
21
  */
22
 
23
  /**
103
  */
104
  protected $_withBorder = false;
105
 
106
+ /**
107
+ * Activate/deactivate drawing of quiet zones
108
+ * @var boolean
109
+ */
110
+ protected $_withQuietZones = true;
111
+
112
+ /**
113
+ * Force quiet zones even if
114
+ * @var boolean
115
+ */
116
+ protected $_mandatoryQuietZones = false;
117
+
118
  /**
119
  * Orientation of the barcode in degrees
120
  * @var float
384
  /**
385
  * Set factor applying to
386
  * thinBarWidth - thickBarWidth - barHeight - fontSize
387
+ * @param float $value
388
  * @return Zend_Barcode_Object
389
  * @throw Zend_Barcode_Object_Exception
390
  */
490
  return $this->_withBorder;
491
  }
492
 
493
+ /**
494
+ * Activate/deactivate drawing of the quiet zones
495
+ * @param boolean $value
496
+ * @return Zend_Barcode_Object
497
+ */
498
+ public function setWithQuietZones($value)
499
+ {
500
+ $this->_withQuietZones = (bool) $value;
501
+ return $this;
502
+ }
503
+
504
+ /**
505
+ * Retrieve if quiet zones are draw or not
506
+ * @return boolean
507
+ */
508
+ public function getWithQuietZones()
509
+ {
510
+ return $this->_withQuietZones;
511
+ }
512
+
513
  /**
514
  * Allow fast inversion of font/bars color and background color
515
  * @return Zend_Barcode_Object
802
  */
803
  public function getQuietZone()
804
  {
805
+ if ($this->_withQuietZones || $this->_mandatoryQuietZones) {
806
+ return 10 * $this->_barThinWidth * $this->_factor;
807
+ } else {
808
+ return 0;
809
+ }
810
  }
811
 
812
  /**
lib/Zend/Barcode/Object/Upca.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Upca.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -49,6 +49,7 @@ class Zend_Barcode_Object_Upca extends Zend_Barcode_Object_Ean13
49
  {
50
  $this->_barcodeLength = 12;
51
  $this->_mandatoryChecksum = true;
 
52
  }
53
 
54
  /**
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Upca.php 21667 2010-03-28 17:45:14Z mikaelkael $
21
  */
22
 
23
  /**
49
  {
50
  $this->_barcodeLength = 12;
51
  $this->_mandatoryChecksum = true;
52
+ $this->_mandatoryQuietZones = true;
53
  }
54
 
55
  /**
lib/Zend/Barcode/Object/Upce.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Upce.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -74,6 +74,7 @@ class Zend_Barcode_Object_Upce extends Zend_Barcode_Object_Ean13
74
  {
75
  $this->_barcodeLength = 8;
76
  $this->_mandatoryChecksum = true;
 
77
  }
78
 
79
  /**
17
  * @subpackage Object
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Upce.php 21667 2010-03-28 17:45:14Z mikaelkael $
21
  */
22
 
23
  /**
74
  {
75
  $this->_barcodeLength = 8;
76
  $this->_mandatoryChecksum = true;
77
+ $this->_mandatoryQuietZones = true;
78
  }
79
 
80
  /**
lib/Zend/Barcode/Renderer/Image.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Renderer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Image.php 20367 2010-01-18 04:51:23Z ralph $
21
  */
22
 
23
  /** @see Zend_Barcode_Renderer_RendererAbstract*/
@@ -435,14 +435,14 @@ class Zend_Barcode_Renderer_Image extends Zend_Barcode_Renderer_RendererAbstract
435
  }
436
  imagestring($this->_resource, $font, $positionX, $positionY, $text, $color);
437
  } else {
438
-
439
  if (!function_exists('imagettfbbox')) {
440
  #require_once 'Zend/Barcode/Renderer/Exception.php';
441
  throw new Zend_Barcode_Renderer_Exception(
442
  'A font was provided, but this instance of PHP does not have TTF (FreeType) support'
443
  );
444
  }
445
-
446
  $box = imagettfbbox($size, 0, $font, $text);
447
  switch ($alignment) {
448
  case 'left':
17
  * @subpackage Renderer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Image.php 22999 2010-09-23 19:43:14Z mikaelkael $
21
  */
22
 
23
  /** @see Zend_Barcode_Renderer_RendererAbstract*/
435
  }
436
  imagestring($this->_resource, $font, $positionX, $positionY, $text, $color);
437
  } else {
438
+
439
  if (!function_exists('imagettfbbox')) {
440
  #require_once 'Zend/Barcode/Renderer/Exception.php';
441
  throw new Zend_Barcode_Renderer_Exception(
442
  'A font was provided, but this instance of PHP does not have TTF (FreeType) support'
443
  );
444
  }
445
+
446
  $box = imagettfbbox($size, 0, $font, $text);
447
  switch ($alignment) {
448
  case 'left':
lib/Zend/Barcode/Renderer/Pdf.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Renderer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Pdf.php 22419 2010-06-11 16:29:08Z mikaelkael $
21
  */
22
 
23
  /** @see Zend_Barcode_Renderer_RendererAbstract */
@@ -166,7 +166,7 @@ class Zend_Barcode_Renderer_Pdf extends Zend_Barcode_Renderer_RendererAbstract
166
  }
167
 
168
  /**
169
- * Draw a polygon in the rendering resource
170
  * @param string $text
171
  * @param float $size
172
  * @param array $position
17
  * @subpackage Renderer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Pdf.php 22418 2010-06-11 16:27:22Z mikaelkael $
21
  */
22
 
23
  /** @see Zend_Barcode_Renderer_RendererAbstract */
166
  }
167
 
168
  /**
169
+ * Draw a text in the rendering resource
170
  * @param string $text
171
  * @param float $size
172
  * @param array $position
lib/Zend/Barcode/Renderer/RendererAbstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Renderer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: RendererAbstract.php 20316 2010-01-15 22:27:00Z mikaelkael $
21
  */
22
 
23
  /**
@@ -80,7 +80,7 @@ abstract class Zend_Barcode_Renderer_RendererAbstract
80
 
81
  /**
82
  * Barcode object
83
- * @var Zend_Barcode_Object
84
  */
85
  protected $_barcode;
86
 
@@ -529,12 +529,12 @@ abstract class Zend_Barcode_Renderer_RendererAbstract
529
  * @param float $orientation
530
  */
531
  abstract protected function _drawText(
532
- $text,
533
- $size,
534
- $position,
535
- $font,
536
- $color,
537
- $alignment = 'center',
538
  $orientation = 0
539
  );
540
  }
17
  * @subpackage Renderer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: RendererAbstract.php 22999 2010-09-23 19:43:14Z mikaelkael $
21
  */
22
 
23
  /**
80
 
81
  /**
82
  * Barcode object
83
+ * @var Zend_Barcode_Object_ObjectAbstract
84
  */
85
  protected $_barcode;
86
 
529
  * @param float $orientation
530
  */
531
  abstract protected function _drawText(
532
+ $text,
533
+ $size,
534
+ $position,
535
+ $font,
536
+ $color,
537
+ $alignment = 'center',
538
  $orientation = 0
539
  );
540
  }
lib/Zend/Barcode/Renderer/Svg.php ADDED
@@ -0,0 +1,382 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Barcode
17
+ * @subpackage Renderer
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Image.php 20366 2010-01-18 03:56:52Z ralph $
21
+ */
22
+
23
+ /** @see Zend_Barcode_Renderer_RendererAbstract*/
24
+ #require_once 'Zend/Barcode/Renderer/RendererAbstract.php';
25
+
26
+ /**
27
+ * Class for rendering the barcode as svg
28
+ *
29
+ * @category Zend
30
+ * @package Zend_Barcode
31
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
+ * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ */
34
+ class Zend_Barcode_Renderer_Svg extends Zend_Barcode_Renderer_RendererAbstract
35
+ {
36
+
37
+ /**
38
+ * Resource for the image
39
+ * @var DOMDocument
40
+ */
41
+ protected $_resource = null;
42
+
43
+ /**
44
+ * Root element of the XML structure
45
+ * @var DOMElement
46
+ */
47
+ protected $_rootElement = null;
48
+
49
+ /**
50
+ * Height of the rendered image wanted by user
51
+ * @var integer
52
+ */
53
+ protected $_userHeight = 0;
54
+
55
+ /**
56
+ * Width of the rendered image wanted by user
57
+ * @var integer
58
+ */
59
+ protected $_userWidth = 0;
60
+
61
+ /**
62
+ * Set height of the result image
63
+ * @param null|integer $value
64
+ * @return Zend_Image_Barcode_Abstract
65
+ * @throw Zend_Image_Barcode_Exception
66
+ */
67
+ public function setHeight($value)
68
+ {
69
+ if (!is_numeric($value) || intval($value) < 0) {
70
+ #require_once 'Zend/Barcode/Renderer/Exception.php';
71
+ throw new Zend_Barcode_Renderer_Exception(
72
+ 'Svg height must be greater than or equals 0'
73
+ );
74
+ }
75
+ $this->_userHeight = intval($value);
76
+ return $this;
77
+ }
78
+
79
+ /**
80
+ * Get barcode height
81
+ *
82
+ * @return int
83
+ */
84
+ public function getHeight()
85
+ {
86
+ return $this->_userHeight;
87
+ }
88
+
89
+ /**
90
+ * Set barcode width
91
+ *
92
+ * @param mixed $value
93
+ * @return void
94
+ */
95
+ public function setWidth($value)
96
+ {
97
+ if (!is_numeric($value) || intval($value) < 0) {
98
+ #require_once 'Zend/Barcode/Renderer/Exception.php';
99
+ throw new Zend_Barcode_Renderer_Exception(
100
+ 'Svg width must be greater than or equals 0'
101
+ );
102
+ }
103
+ $this->_userWidth = intval($value);
104
+ return $this;
105
+ }
106
+
107
+ /**
108
+ * Get barcode width
109
+ *
110
+ * @return int
111
+ */
112
+ public function getWidth()
113
+ {
114
+ return $this->_userWidth;
115
+ }
116
+
117
+ /**
118
+ * Set an image resource to draw the barcode inside
119
+ *
120
+ * @param DOMDocument $value
121
+ * @return Zend_Barcode_Renderer
122
+ * @throw Zend_Barcode_Renderer_Exception
123
+ */
124
+ public function setResource($svg)
125
+ {
126
+ if (!$svg instanceof DOMDocument) {
127
+ #require_once 'Zend/Barcode/Renderer/Exception.php';
128
+ throw new Zend_Barcode_Renderer_Exception(
129
+ 'Invalid DOMDocument resource provided to setResource()'
130
+ );
131
+ }
132
+ $this->_resource = $svg;
133
+ return $this;
134
+ }
135
+
136
+ /**
137
+ * Initialize the image resource
138
+ *
139
+ * @return void
140
+ */
141
+ protected function _initRenderer()
142
+ {
143
+ $barcodeWidth = $this->_barcode->getWidth(true);
144
+ $barcodeHeight = $this->_barcode->getHeight(true);
145
+
146
+ $backgroundColor = $this->_barcode->getBackgroundColor();
147
+ $imageBackgroundColor = 'rgb(' . implode(', ', array(($backgroundColor & 0xFF0000) >> 16,
148
+ ($backgroundColor & 0x00FF00) >> 8,
149
+ ($backgroundColor & 0x0000FF))) . ')';
150
+
151
+ $width = $barcodeWidth;
152
+ $height = $barcodeHeight;
153
+ if ($this->_userWidth && $this->_barcode->getType() != 'error') {
154
+ $width = $this->_userWidth;
155
+ }
156
+ if ($this->_userHeight && $this->_barcode->getType() != 'error') {
157
+ $height = $this->_userHeight;
158
+ }
159
+ if ($this->_resource === null) {
160
+ $this->_resource = new DOMDocument('1.0', 'utf-8');
161
+ $this->_resource->formatOutput = true;
162
+ $this->_rootElement = $this->_resource->createElement('svg');
163
+ $this->_rootElement->setAttribute('xmlns', "http://www.w3.org/2000/svg");
164
+ $this->_rootElement->setAttribute('version', '1.1');
165
+ $this->_rootElement->setAttribute('width', $width);
166
+ $this->_rootElement->setAttribute('height', $height);
167
+
168
+ $this->_appendRootElement('title',
169
+ array(),
170
+ "Barcode " . strtoupper($this->_barcode->getType()) . " " . $this->_barcode->getText());
171
+ } else {
172
+ $this->_readRootElement();
173
+ $width = $this->_rootElement->getAttribute('width');
174
+ $height = $this->_rootElement->getAttribute('height');
175
+ }
176
+ $this->_adjustPosition($height, $width);
177
+
178
+ $this->_appendRootElement('rect',
179
+ array('x' => $this->_leftOffset,
180
+ 'y' => $this->_topOffset,
181
+ 'width' => ($this->_leftOffset + $barcodeWidth - 1),
182
+ 'height' => ($this->_topOffset + $barcodeHeight - 1),
183
+ 'fill' => $imageBackgroundColor));
184
+ }
185
+
186
+ protected function _readRootElement()
187
+ {
188
+ if ($this->_resource !== null) {
189
+ $this->_rootElement = $this->_resource->documentElement;
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Append a new DOMElement to the root element
195
+ *
196
+ * @param string $tagName
197
+ * @param array $attributes
198
+ * @param string $textContent
199
+ */
200
+ protected function _appendRootElement($tagName, $attributes = array(), $textContent = null)
201
+ {
202
+ $newElement = $this->_createElement($tagName, $attributes, $textContent);
203
+ $this->_rootElement->appendChild($newElement);
204
+ }
205
+
206
+ /**
207
+ * Create DOMElement
208
+ *
209
+ * @param string $tagName
210
+ * @param array $attributes
211
+ * @param string $textContent
212
+ * @return DOMElement
213
+ */
214
+ protected function _createElement($tagName, $attributes = array(), $textContent = null)
215
+ {
216
+ $element = $this->_resource->createElement($tagName);
217
+ foreach ($attributes as $k =>$v) {
218
+ $element->setAttribute($k, $v);
219
+ }
220
+ if ($textContent !== null) {
221
+ $element->appendChild(new DOMText((string) $textContent));
222
+ }
223
+ return $element;
224
+ }
225
+
226
+ /**
227
+ * Check barcode parameters
228
+ *
229
+ * @return void
230
+ */
231
+ protected function _checkParams()
232
+ {
233
+ $this->_checkDimensions();
234
+ }
235
+
236
+ /**
237
+ * Check barcode dimensions
238
+ *
239
+ * @return void
240
+ */
241
+ protected function _checkDimensions()
242
+ {
243
+ if ($this->_resource !== null) {
244
+ $this->_readRootElement();
245
+ $height = (float) $this->_rootElement->getAttribute('height');
246
+ if ($height < $this->_barcode->getHeight(true)) {
247
+ #require_once 'Zend/Barcode/Renderer/Exception.php';
248
+ throw new Zend_Barcode_Renderer_Exception(
249
+ 'Barcode is define outside the image (height)'
250
+ );
251
+ }
252
+ } else {
253
+ if ($this->_userHeight) {
254
+ $height = $this->_barcode->getHeight(true);
255
+ if ($this->_userHeight < $height) {
256
+ #require_once 'Zend/Barcode/Renderer/Exception.php';
257
+ throw new Zend_Barcode_Renderer_Exception(sprintf(
258
+ "Barcode is define outside the image (calculated: '%d', provided: '%d')",
259
+ $height,
260
+ $this->_userHeight
261
+ ));
262
+ }
263
+ }
264
+ }
265
+ if ($this->_resource !== null) {
266
+ $this->_readRootElement();
267
+ $width = $this->_rootElement->getAttribute('width');
268
+ if ($width < $this->_barcode->getWidth(true)) {
269
+ #require_once 'Zend/Barcode/Renderer/Exception.php';
270
+ throw new Zend_Barcode_Renderer_Exception(
271
+ 'Barcode is define outside the image (width)'
272
+ );
273
+ }
274
+ } else {
275
+ if ($this->_userWidth) {
276
+ $width = (float) $this->_barcode->getWidth(true);
277
+ if ($this->_userWidth < $width) {
278
+ #require_once 'Zend/Barcode/Renderer/Exception.php';
279
+ throw new Zend_Barcode_Renderer_Exception(sprintf(
280
+ "Barcode is define outside the image (calculated: '%d', provided: '%d')",
281
+ $width,
282
+ $this->_userWidth
283
+ ));
284
+ }
285
+ }
286
+ }
287
+ }
288
+
289
+ /**
290
+ * Draw the barcode in the rendering resource
291
+ * @return mixed
292
+ */
293
+ public function draw()
294
+ {
295
+ parent::draw();
296
+ $this->_resource->appendChild($this->_rootElement);
297
+ return $this->_resource;
298
+ }
299
+
300
+ /**
301
+ * Draw and render the barcode with correct headers
302
+ *
303
+ * @return mixed
304
+ */
305
+ public function render()
306
+ {
307
+ $this->draw();
308
+ header("Content-Type: image/svg+xml");
309
+ echo $this->_resource->saveXML();
310
+ }
311
+
312
+ /**
313
+ * Draw a polygon in the svg resource
314
+ *
315
+ * @param array $points
316
+ * @param integer $color
317
+ * @param boolean $filled
318
+ */
319
+ protected function _drawPolygon($points, $color, $filled = true)
320
+ {
321
+ $color = 'rgb(' . implode(', ', array(($color & 0xFF0000) >> 16,
322
+ ($color & 0x00FF00) >> 8,
323
+ ($color & 0x0000FF))) . ')';
324
+ $orientation = $this->getBarcode()->getOrientation();
325
+ $newPoints = array(
326
+ $points[0][0] + $this->_leftOffset,
327
+ $points[0][1] + $this->_topOffset,
328
+ $points[1][0] + $this->_leftOffset,
329
+ $points[1][1] + $this->_topOffset,
330
+ $points[2][0] + $this->_leftOffset + cos(-$orientation),
331
+ $points[2][1] + $this->_topOffset - sin($orientation),
332
+ $points[3][0] + $this->_leftOffset + cos(-$orientation),
333
+ $points[3][1] + $this->_topOffset - sin($orientation),
334
+ );
335
+ $newPoints = implode(' ', $newPoints);
336
+ $attributes['points'] = $newPoints;
337
+ $attributes['fill'] = $color;
338
+ $this->_appendRootElement('polygon', $attributes);
339
+ }
340
+
341
+ /**
342
+ * Draw a polygon in the svg resource
343
+ *
344
+ * @param string $text
345
+ * @param float $size
346
+ * @param array $position
347
+ * @param string $font
348
+ * @param integer $color
349
+ * @param string $alignment
350
+ * @param float $orientation
351
+ */
352
+ protected function _drawText($text, $size, $position, $font, $color, $alignment = 'center', $orientation = 0)
353
+ {
354
+ $color = 'rgb(' . implode(', ', array(($color & 0xFF0000) >> 16,
355
+ ($color & 0x00FF00) >> 8,
356
+ ($color & 0x0000FF))) . ')';
357
+ $attributes['x'] = $position[0] + $this->_leftOffset;
358
+ $attributes['y'] = $position[1] + $this->_topOffset;
359
+ //$attributes['font-family'] = $font;
360
+ $attributes['color'] = $color;
361
+ $attributes['font-size'] = $size * 1.2;
362
+ switch ($alignment) {
363
+ case 'left':
364
+ $textAnchor = 'start';
365
+ break;
366
+ case 'right':
367
+ $textAnchor = 'end';
368
+ break;
369
+ case 'center':
370
+ default:
371
+ $textAnchor = 'middle';
372
+ }
373
+ $attributes['style'] = 'text-anchor: ' . $textAnchor;
374
+ $attributes['transform'] = 'rotate('
375
+ . (- $orientation)
376
+ . ', '
377
+ . ($position[0] + $this->_leftOffset)
378
+ . ', ' . ($position[1] + $this->_topOffset)
379
+ . ')';
380
+ $this->_appendRootElement('text', $attributes, $text);
381
+ }
382
+ }
lib/Zend/Cache.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Cache
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Cache.php 21974 2010-04-23 17:10:17Z alexander $
20
  */
21
 
22
 
@@ -40,7 +40,7 @@ abstract class Zend_Cache
40
  *
41
  * @var array
42
  */
43
- public static $standardBackends = array('File', 'Sqlite', 'Memcached', 'Apc', 'ZendPlatform',
44
  'Xcache', 'TwoLevels', 'ZendServer_Disk', 'ZendServer_ShMem');
45
 
46
  /**
@@ -48,10 +48,10 @@ abstract class Zend_Cache
48
  *
49
  * @var array
50
  */
51
- public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Sqlite');
52
 
53
  /**
54
- * Only for backward compatibily (may be removed in next major release)
55
  *
56
  * @var array
57
  * @deprecated
@@ -59,12 +59,12 @@ abstract class Zend_Cache
59
  public static $availableFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
60
 
61
  /**
62
- * Only for backward compatibily (may be removed in next major release)
63
  *
64
  * @var array
65
  * @deprecated
66
  */
67
- public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Apc', 'ZendPlatform', 'Xcache', 'TwoLevels');
68
 
69
  /**
70
  * Consts for clean() method
@@ -84,7 +84,7 @@ abstract class Zend_Cache
84
  * @param array $backendOptions associative array of options for the corresponding backend constructor
85
  * @param boolean $customFrontendNaming if true, the frontend argument is used as a complete class name ; if false, the frontend argument is used as the end of "Zend_Cache_Frontend_[...]" class name
86
  * @param boolean $customBackendNaming if true, the backend argument is used as a complete class name ; if false, the backend argument is used as the end of "Zend_Cache_Backend_[...]" class name
87
- * @param boolean $autoload if true, there will no #require_once for backend and frontend (usefull only for custom backends/frontends)
88
  * @throws Zend_Cache_Exception
89
  * @return Zend_Cache_Core|Zend_Cache_Frontend
90
  */
@@ -113,7 +113,7 @@ abstract class Zend_Cache
113
  }
114
 
115
  /**
116
- * Frontend Constructor
117
  *
118
  * @param string $backend
119
  * @param array $backendOptions
@@ -154,7 +154,7 @@ abstract class Zend_Cache
154
  }
155
 
156
  /**
157
- * Backend Constructor
158
  *
159
  * @param string $frontend
160
  * @param array $frontendOptions
16
  * @package Zend_Cache
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Cache.php 23154 2010-10-18 17:41:06Z mabe $
20
  */
21
 
22
 
40
  *
41
  * @var array
42
  */
43
+ public static $standardBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform',
44
  'Xcache', 'TwoLevels', 'ZendServer_Disk', 'ZendServer_ShMem');
45
 
46
  /**
48
  *
49
  * @var array
50
  */
51
+ public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Libmemcached', 'Sqlite');
52
 
53
  /**
54
+ * Only for backward compatibility (may be removed in next major release)
55
  *
56
  * @var array
57
  * @deprecated
59
  public static $availableFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
60
 
61
  /**
62
+ * Only for backward compatibility (may be removed in next major release)
63
  *
64
  * @var array
65
  * @deprecated
66
  */
67
+ public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform', 'Xcache', 'TwoLevels');
68
 
69
  /**
70
  * Consts for clean() method
84
  * @param array $backendOptions associative array of options for the corresponding backend constructor
85
  * @param boolean $customFrontendNaming if true, the frontend argument is used as a complete class name ; if false, the frontend argument is used as the end of "Zend_Cache_Frontend_[...]" class name
86
  * @param boolean $customBackendNaming if true, the backend argument is used as a complete class name ; if false, the backend argument is used as the end of "Zend_Cache_Backend_[...]" class name
87
+ * @param boolean $autoload if true, there will no #require_once for backend and frontend (useful only for custom backends/frontends)
88
  * @throws Zend_Cache_Exception
89
  * @return Zend_Cache_Core|Zend_Cache_Frontend
90
  */
113
  }
114
 
115
  /**
116
+ * Backend Constructor
117
  *
118
  * @param string $backend
119
  * @param array $backendOptions
154
  }
155
 
156
  /**
157
+ * Frontend Constructor
158
  *
159
  * @param string $frontend
160
  * @param array $frontendOptions
lib/Zend/Cache/Backend.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Backend.php 20882 2010-02-03 18:19:44Z matthew $
21
  */
22
 
23
 
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Backend.php 20880 2010-02-03 18:18:32Z matthew $
21
  */
22
 
23
 
lib/Zend/Cache/Backend/BlackHole.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: BlackHole.php 17867 2009-08-28 09:42:11Z yoshida@zend.co.jp $
21
  */
22
 
23
  /**
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: BlackHole.php 20785 2010-01-31 09:43:03Z mikaelkael $
21
  */
22
 
23
  /**
lib/Zend/Cache/Backend/File.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: File.php 21642 2010-03-25 17:07:02Z mabe $
21
  */
22
 
23
  /**
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: File.php 21636 2010-03-24 17:10:23Z mabe $
21
  */
22
 
23
  /**
lib/Zend/Cache/Backend/Libmemcached.php ADDED
@@ -0,0 +1,484 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Cache
17
+ * @subpackage Zend_Cache_Backend
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Libmemcached.php 23220 2010-10-22 10:24:14Z mabe $
21
+ */
22
+
23
+
24
+ /**
25
+ * @see Zend_Cache_Backend_Interface
26
+ */
27
+ #require_once 'Zend/Cache/Backend/ExtendedInterface.php';
28
+
29
+ /**
30
+ * @see Zend_Cache_Backend
31
+ */
32
+ #require_once 'Zend/Cache/Backend.php';
33
+
34
+
35
+ /**
36
+ * @package Zend_Cache
37
+ * @subpackage Zend_Cache_Backend
38
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
39
+ * @license http://framework.zend.com/license/new-bsd New BSD License
40
+ */
41
+ class Zend_Cache_Backend_Libmemcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
42
+ {
43
+ /**
44
+ * Default Server Values
45
+ */
46
+ const DEFAULT_HOST = '127.0.0.1';
47
+ const DEFAULT_PORT = 11211;
48
+ const DEFAULT_WEIGHT = 1;
49
+
50
+ /**
51
+ * Log message
52
+ */
53
+ const TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::clean() : tags are unsupported by the Libmemcached backend';
54
+ const TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::save() : tags are unsupported by the Libmemcached backend';
55
+
56
+ /**
57
+ * Available options
58
+ *
59
+ * =====> (array) servers :
60
+ * an array of memcached server ; each memcached server is described by an associative array :
61
+ * 'host' => (string) : the name of the memcached server
62
+ * 'port' => (int) : the port of the memcached server
63
+ * 'weight' => (int) : number of buckets to create for this server which in turn control its
64
+ * probability of it being selected. The probability is relative to the total
65
+ * weight of all servers.
66
+ * =====> (array) client :
67
+ * an array of memcached client options ; the memcached client is described by an associative array :
68
+ * @see http://php.net/manual/memcached.constants.php
69
+ * - The option name can be the name of the constant without the prefix 'OPT_'
70
+ * or the integer value of this option constant
71
+ *
72
+ * @var array available options
73
+ */
74
+ protected $_options = array(
75
+ 'servers' => array(array(
76
+ 'host' => self::DEFAULT_HOST,
77
+ 'port' => self::DEFAULT_PORT,
78
+ 'weight' => self::DEFAULT_WEIGHT,
79
+ )),
80
+ 'client' => array()
81
+ );
82
+
83
+ /**
84
+ * Memcached object
85
+ *
86
+ * @var mixed memcached object
87
+ */
88
+ protected $_memcache = null;
89
+
90
+ /**
91
+ * Constructor
92
+ *
93
+ * @param array $options associative array of options
94
+ * @throws Zend_Cache_Exception
95
+ * @return void
96
+ */
97
+ public function __construct(array $options = array())
98
+ {
99
+ if (!extension_loaded('memcached')) {
100
+ Zend_Cache::throwException('The memcached extension must be loaded for using this backend !');
101
+ }
102
+
103
+ // override default client options
104
+ $this->_options['client'] = array(
105
+ Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
106
+ Memcached::OPT_HASH => Memcached::HASH_MD5,
107
+ Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
108
+ );
109
+
110
+ parent::__construct($options);
111
+
112
+ if (isset($this->_options['servers'])) {
113
+ $value = $this->_options['servers'];
114
+ if (isset($value['host'])) {
115
+ // in this case, $value seems to be a simple associative array (one server only)
116
+ $value = array(0 => $value); // let's transform it into a classical array of associative arrays
117
+ }
118
+ $this->setOption('servers', $value);
119
+ }
120
+ $this->_memcache = new Memcached;
121
+
122
+ // setup memcached client options
123
+ foreach ($this->_options['client'] as $name => $value) {
124
+ $optId = null;
125
+ if (is_int($name)) {
126
+ $optId = $name;
127
+ } else {
128
+ $optConst = 'Memcached::OPT_' . strtoupper($name);
129
+ if (defined($optConst)) {
130
+ $optId = constant($optConst);
131
+ } else {
132
+ $this->_log("Unknown memcached client option '{$name}' ({$optConst})");
133
+ }
134
+ }
135
+ if ($optId) {
136
+ if (!$this->_memcache->setOption($optId, $value)) {
137
+ $this->_log("Setting memcached client option '{$optId}' failed");
138
+ }
139
+ }
140
+ }
141
+
142
+ // setup memcached servers
143
+ $servers = array();
144
+ foreach ($this->_options['servers'] as $server) {
145
+ if (!array_key_exists('port', $server)) {
146
+ $server['port'] = self::DEFAULT_PORT;
147
+ }
148
+ if (!array_key_exists('weight', $server)) {
149
+ $server['weight'] = self::DEFAULT_WEIGHT;
150
+ }
151
+
152
+ $servers[] = array($server['host'], $server['port'], $server['weight']);
153
+ }
154
+ $this->_memcache->addServers($servers);
155
+ }
156
+
157
+ /**
158
+ * Test if a cache is available for the given id and (if yes) return it (false else)
159
+ *
160
+ * @param string $id Cache id
161
+ * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
162
+ * @return string|false cached datas
163
+ */
164
+ public function load($id, $doNotTestCacheValidity = false)
165
+ {
166
+ $tmp = $this->_memcache->get($id);
167
+ if (isset($tmp[0])) {
168
+ return $tmp[0];
169
+ }
170
+ return false;
171
+ }
172
+
173
+ /**
174
+ * Test if a cache is available or not (for the given id)
175
+ *
176
+ * @param string $id Cache id
177
+ * @return int|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
178
+ */
179
+ public function test($id)
180
+ {
181
+ $tmp = $this->_memcache->get($id);
182
+ if (isset($tmp[0], $tmp[1])) {
183
+ return (int)$tmp[1];
184
+ }
185
+ return false;
186
+ }
187
+
188
+ /**
189
+ * Save some string datas into a cache record
190
+ *
191
+ * Note : $data is always "string" (serialization is done by the
192
+ * core not by the backend)
193
+ *
194
+ * @param string $data Datas to cache
195
+ * @param string $id Cache id
196
+ * @param array $tags Array of strings, the cache record will be tagged by each string entry
197
+ * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
198
+ * @return boolean True if no problem
199
+ */
200
+ public function save($data, $id, $tags = array(), $specificLifetime = false)
201
+ {
202
+ $lifetime = $this->getLifetime($specificLifetime);
203
+
204
+ // ZF-8856: using set because add needs a second request if item already exists
205
+ $result = @$this->_memcache->set($id, array($data, time(), $lifetime), $lifetime);
206
+ if ($result === false) {
207
+ $rsCode = $this->_memcache->getResultCode();
208
+ $rsMsg = $this->_memcache->getResultMessage();
209
+ $this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}");
210
+ }
211
+
212
+ if (count($tags) > 0) {
213
+ $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
214
+ }
215
+
216
+ return $result;
217
+ }
218
+
219
+ /**
220
+ * Remove a cache record
221
+ *
222
+ * @param string $id Cache id
223
+ * @return boolean True if no problem
224
+ */
225
+ public function remove($id)
226
+ {
227
+ return $this->_memcache->delete($id);
228
+ }
229
+
230
+ /**
231
+ * Clean some cache records
232
+ *
233
+ * Available modes are :
234
+ * 'all' (default) => remove all cache entries ($tags is not used)
235
+ * 'old' => unsupported
236
+ * 'matchingTag' => unsupported
237
+ * 'notMatchingTag' => unsupported
238
+ * 'matchingAnyTag' => unsupported
239
+ *
240
+ * @param string $mode Clean mode
241
+ * @param array $tags Array of tags
242
+ * @throws Zend_Cache_Exception
243
+ * @return boolean True if no problem
244
+ */
245
+ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
246
+ {
247
+ switch ($mode) {
248
+ case Zend_Cache::CLEANING_MODE_ALL:
249
+ return $this->_memcache->flush();
250
+ break;
251
+ case Zend_Cache::CLEANING_MODE_OLD:
252
+ $this->_log("Zend_Cache_Backend_Libmemcached::clean() : CLEANING_MODE_OLD is unsupported by the Libmemcached backend");
253
+ break;
254
+ case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
255
+ case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
256
+ case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
257
+ $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND);
258
+ break;
259
+ default:
260
+ Zend_Cache::throwException('Invalid mode for clean() method');
261
+ break;
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Return true if the automatic cleaning is available for the backend
267
+ *
268
+ * @return boolean
269
+ */
270
+ public function isAutomaticCleaningAvailable()
271
+ {
272
+ return false;
273
+ }
274
+
275
+ /**
276
+ * Set the frontend directives
277
+ *
278
+ * @param array $directives Assoc of directives
279
+ * @throws Zend_Cache_Exception
280
+ * @return void
281
+ */
282
+ public function setDirectives($directives)
283
+ {
284
+ parent::setDirectives($directives);
285
+ $lifetime = $this->getLifetime(false);
286
+ if ($lifetime > 2592000) {
287
+ // #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
288
+ $this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
289
+ }
290
+ if ($lifetime === null) {
291
+ // #ZF-4614 : we tranform null to zero to get the maximal lifetime
292
+ parent::setDirectives(array('lifetime' => 0));
293
+ }
294
+ }
295
+
296
+ /**
297
+ * Return an array of stored cache ids
298
+ *
299
+ * @return array array of stored cache ids (string)
300
+ */
301
+ public function getIds()
302
+ {
303
+ $this->_log("Zend_Cache_Backend_Libmemcached::save() : getting the list of cache ids is unsupported by the Libmemcached backend");
304
+ return array();
305
+ }
306
+
307
+ /**
308
+ * Return an array of stored tags
309
+ *
310
+ * @return array array of stored tags (string)
311
+ */
312
+ public function getTags()
313
+ {
314
+ $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
315
+ return array();
316
+ }
317
+
318
+ /**
319
+ * Return an array of stored cache ids which match given tags
320
+ *
321
+ * In case of multiple tags, a logical AND is made between tags
322
+ *
323
+ * @param array $tags array of tags
324
+ * @return array array of matching cache ids (string)
325
+ */
326
+ public function getIdsMatchingTags($tags = array())
327
+ {
328
+ $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
329
+ return array();
330
+ }
331
+
332
+ /**
333
+ * Return an array of stored cache ids which don't match given tags
334
+ *
335
+ * In case of multiple tags, a logical OR is made between tags
336
+ *
337
+ * @param array $tags array of tags
338
+ * @return array array of not matching cache ids (string)
339
+ */
340
+ public function getIdsNotMatchingTags($tags = array())
341
+ {
342
+ $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
343
+ return array();
344
+ }
345
+
346
+ /**
347
+ * Return an array of stored cache ids which match any given tags
348
+ *
349
+ * In case of multiple tags, a logical AND is made between tags
350
+ *
351
+ * @param array $tags array of tags
352
+ * @return array array of any matching cache ids (string)
353
+ */
354
+ public function getIdsMatchingAnyTags($tags = array())
355
+ {
356
+ $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
357
+ return array();
358
+ }
359
+
360
+ /**
361
+ * Return the filling percentage of the backend storage
362
+ *
363
+ * @throws Zend_Cache_Exception
364
+ * @return int integer between 0 and 100
365
+ */
366
+ public function getFillingPercentage()
367
+ {
368
+ $mems = $this->_memcache->getStats();
369
+ if ($mems === false) {
370
+ return 0;
371
+ }
372
+
373
+ $memSize = null;
374
+ $memUsed = null;
375
+ foreach ($mems as $key => $mem) {
376
+ if ($mem === false) {
377
+ $this->_log('can\'t get stat from ' . $key);
378
+ continue;
379
+ }
380
+
381
+ $eachSize = $mem['limit_maxbytes'];
382
+ $eachUsed = $mem['bytes'];
383
+ if ($eachUsed > $eachSize) {
384
+ $eachUsed = $eachSize;
385
+ }
386
+
387
+ $memSize += $eachSize;
388
+ $memUsed += $eachUsed;
389
+ }
390
+
391
+ if ($memSize === null || $memUsed === null) {
392
+ Zend_Cache::throwException('Can\'t get filling percentage');
393
+ }
394
+
395
+ return ((int) (100. * ($memUsed / $memSize)));
396
+ }
397
+
398
+ /**
399
+ * Return an array of metadatas for the given cache id
400
+ *
401
+ * The array must include these keys :
402
+ * - expire : the expire timestamp
403
+ * - tags : a string array of tags
404
+ * - mtime : timestamp of last modification time
405
+ *
406
+ * @param string $id cache id
407
+ * @return array array of metadatas (false if the cache id is not found)
408
+ */
409
+ public function getMetadatas($id)
410
+ {
411
+ $tmp = $this->_memcache->get($id);
412
+ if (isset($tmp[0], $tmp[1], $tmp[2])) {
413
+ $data = $tmp[0];
414
+ $mtime = $tmp[1];
415
+ $lifetime = $tmp[2];
416
+ return array(
417
+ 'expire' => $mtime + $lifetime,
418
+ 'tags' => array(),
419
+ 'mtime' => $mtime
420
+ );
421
+ }
422
+
423
+ return false;
424
+ }
425
+
426
+ /**
427
+ * Give (if possible) an extra lifetime to the given cache id
428
+ *
429
+ * @param string $id cache id
430
+ * @param int $extraLifetime
431
+ * @return boolean true if ok
432
+ */
433
+ public function touch($id, $extraLifetime)
434
+ {
435
+ $tmp = $this->_memcache->get($id);
436
+ if (isset($tmp[0], $tmp[1], $tmp[2])) {
437
+ $data = $tmp[0];
438
+ $mtime = $tmp[1];
439
+ $lifetime = $tmp[2];
440
+ $newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
441
+ if ($newLifetime <=0) {
442
+ return false;
443
+ }
444
+ // #ZF-5702 : we try replace() first becase set() seems to be slower
445
+ if (!($result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $newLifetime))) {
446
+ $result = $this->_memcache->set($id, array($data, time(), $newLifetime), $newLifetime);
447
+ if ($result === false) {
448
+ $rsCode = $this->_memcache->getResultCode();
449
+ $rsMsg = $this->_memcache->getResultMessage();
450
+ $this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}");
451
+ }
452
+ }
453
+ return $result;
454
+ }
455
+ return false;
456
+ }
457
+
458
+ /**
459
+ * Return an associative array of capabilities (booleans) of the backend
460
+ *
461
+ * The array must include these keys :
462
+ * - automatic_cleaning (is automating cleaning necessary)
463
+ * - tags (are tags supported)
464
+ * - expired_read (is it possible to read expired cache records
465
+ * (for doNotTestCacheValidity option for example))
466
+ * - priority does the backend deal with priority when saving
467
+ * - infinite_lifetime (is infinite lifetime can work with this backend)
468
+ * - get_list (is it possible to get the list of cache ids and the complete list of tags)
469
+ *
470
+ * @return array associative of with capabilities
471
+ */
472
+ public function getCapabilities()
473
+ {
474
+ return array(
475
+ 'automatic_cleaning' => false,
476
+ 'tags' => false,
477
+ 'expired_read' => false,
478
+ 'priority' => false,
479
+ 'infinite_lifetime' => false,
480
+ 'get_list' => false
481
+ );
482
+ }
483
+
484
+ }
lib/Zend/Cache/Backend/Memcached.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Memcached.php 22208 2010-05-20 16:59:02Z mabe $
21
  */
22
 
23
 
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Memcached.php 22207 2010-05-20 16:47:16Z mabe $
21
  */
22
 
23
 
lib/Zend/Cache/Backend/Static.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: BlackHole.php 17867 2009-08-28 09:42:11Z yoshida@zend.co.jp $
21
  */
22
 
23
  /**
@@ -166,7 +166,7 @@ class Zend_Cache_Backend_Static
166
  if (empty($fileName)) {
167
  $fileName = $this->_options['index_filename'];
168
  }
169
- if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
170
  $this->_tagged = $tagged;
171
  } elseif (!$this->_tagged) {
172
  return false;
@@ -211,7 +211,7 @@ class Zend_Cache_Backend_Static
211
  }
212
 
213
  clearstatcache();
214
- if (is_null($id) || strlen($id) == 0) {
215
  $id = $this->_detectId();
216
  } else {
217
  $id = $this->_decodeId($id);
@@ -225,7 +225,7 @@ class Zend_Cache_Backend_Static
225
  $pathName = realpath($this->_options['public_dir']) . dirname($id);
226
  $this->_createDirectoriesFor($pathName);
227
 
228
- if (is_null($id) || strlen($id) == 0) {
229
  $dataUnserialized = unserialize($data);
230
  $data = $dataUnserialized['data'];
231
  }
@@ -239,9 +239,9 @@ class Zend_Cache_Backend_Static
239
  }
240
  @chmod($file, $this->_octdec($this->_options['cache_file_umask']));
241
 
242
- if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
243
  $this->_tagged = $tagged;
244
- } elseif (is_null($this->_tagged)) {
245
  $this->_tagged = array();
246
  }
247
  if (!isset($this->_tagged[$id])) {
@@ -261,22 +261,15 @@ class Zend_Cache_Backend_Static
261
  */
262
  protected function _createDirectoriesFor($path)
263
  {
264
- if ( !is_dir($path)
265
- && !@mkdir($path, $this->_options['cache_directory_umask'], true)) {
266
- $lastErr = error_get_last();
267
- Zend_Cache::throwException("Can't create directory: {$lastErr['message']}");
268
- }
269
-
270
- /*
271
- $parts = explode('/', $path);
272
- $directory = '';
273
- foreach ($parts as $part) {
274
- $directory = rtrim($directory, '/') . '/' . $part;
275
- if (!is_dir($directory)) {
276
- mkdir($directory, $this->_octdec($this->_options['cache_directory_umask']));
277
  }
 
278
  }
279
- */
280
  }
281
 
282
  /**
@@ -305,7 +298,7 @@ class Zend_Cache_Backend_Static
305
  Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
306
  }
307
  $fileName = basename($id);
308
- if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
309
  $this->_tagged = $tagged;
310
  } elseif (!$this->_tagged) {
311
  return false;
@@ -394,7 +387,7 @@ class Zend_Cache_Backend_Static
394
  if (empty($tags)) {
395
  throw new Zend_Exception('Cannot use tag matching modes as no tags were defined');
396
  }
397
- if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
398
  $this->_tagged = $tagged;
399
  } elseif (!$this->_tagged) {
400
  return true;
@@ -412,11 +405,11 @@ class Zend_Cache_Backend_Static
412
  $result = true;
413
  break;
414
  case Zend_Cache::CLEANING_MODE_ALL:
415
- if (is_null($this->_tagged)) {
416
  $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME);
417
  $this->_tagged = $tagged;
418
  }
419
- if (is_null($this->_tagged) || empty($this->_tagged)) {
420
  return true;
421
  }
422
  $urls = array_keys($this->_tagged);
@@ -434,11 +427,11 @@ class Zend_Cache_Backend_Static
434
  if (empty($tags)) {
435
  throw new Zend_Exception('Cannot use tag matching modes as no tags were defined');
436
  }
437
- if (is_null($this->_tagged)) {
438
  $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME);
439
  $this->_tagged = $tagged;
440
  }
441
- if (is_null($this->_tagged) || empty($this->_tagged)) {
442
  return true;
443
  }
444
  $urls = array_keys($this->_tagged);
@@ -481,7 +474,7 @@ class Zend_Cache_Backend_Static
481
  */
482
  public function getInnerCache()
483
  {
484
- if (is_null($this->_tagCache)) {
485
  Zend_Cache::throwException('An Inner Cache has not been set; use setInnerCache()');
486
  }
487
  return $this->_tagCache;
@@ -550,7 +543,7 @@ class Zend_Cache_Backend_Static
550
  */
551
  protected function _octdec($val)
552
  {
553
- if (decoct(octdec($val)) == $val && is_string($val)) {
554
  return octdec($val);
555
  }
556
  return $val;
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Static.php 22950 2010-09-16 19:33:00Z mabe $
21
  */
22
 
23
  /**
166
  if (empty($fileName)) {
167
  $fileName = $this->_options['index_filename'];
168
  }
169
+ if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
170
  $this->_tagged = $tagged;
171
  } elseif (!$this->_tagged) {
172
  return false;
211
  }
212
 
213
  clearstatcache();
214
+ if ($id === null || strlen($id) == 0) {
215
  $id = $this->_detectId();
216
  } else {
217
  $id = $this->_decodeId($id);
225
  $pathName = realpath($this->_options['public_dir']) . dirname($id);
226
  $this->_createDirectoriesFor($pathName);
227
 
228
+ if ($id === null || strlen($id) == 0) {
229
  $dataUnserialized = unserialize($data);
230
  $data = $dataUnserialized['data'];
231
  }
239
  }
240
  @chmod($file, $this->_octdec($this->_options['cache_file_umask']));
241
 
242
+ if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
243
  $this->_tagged = $tagged;
244
+ } elseif ($this->_tagged === null) {
245
  $this->_tagged = array();
246
  }
247
  if (!isset($this->_tagged[$id])) {
261
  */
262
  protected function _createDirectoriesFor($path)
263
  {
264
+ if (!is_dir($path)) {
265
+ $oldUmask = umask(0);
266
+ if ( !@mkdir($path, $this->_octdec($this->_options['cache_directory_umask']), true)) {
267
+ $lastErr = error_get_last();
268
+ umask($oldUmask);
269
+ Zend_Cache::throwException("Can't create directory: {$lastErr['message']}");
 
 
 
 
 
 
 
270
  }
271
+ umask($oldUmask);
272
  }
 
273
  }
274
 
275
  /**
298
  Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
299
  }
300
  $fileName = basename($id);
301
+ if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
302
  $this->_tagged = $tagged;
303
  } elseif (!$this->_tagged) {
304
  return false;
387
  if (empty($tags)) {
388
  throw new Zend_Exception('Cannot use tag matching modes as no tags were defined');
389
  }
390
+ if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
391
  $this->_tagged = $tagged;
392
  } elseif (!$this->_tagged) {
393
  return true;
405
  $result = true;
406
  break;
407
  case Zend_Cache::CLEANING_MODE_ALL:
408
+ if ($this->_tagged === null) {
409
  $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME);
410
  $this->_tagged = $tagged;
411
  }
412
+ if ($this->_tagged === null || empty($this->_tagged)) {
413
  return true;
414
  }
415
  $urls = array_keys($this->_tagged);
427
  if (empty($tags)) {
428
  throw new Zend_Exception('Cannot use tag matching modes as no tags were defined');
429
  }
430
+ if ($this->_tagged === null) {
431
  $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME);
432
  $this->_tagged = $tagged;
433
  }
434
+ if ($this->_tagged === null || empty($this->_tagged)) {
435
  return true;
436
  }
437
  $urls = array_keys($this->_tagged);
474
  */
475
  public function getInnerCache()
476
  {
477
+ if ($this->_tagCache === null) {
478
  Zend_Cache::throwException('An Inner Cache has not been set; use setInnerCache()');
479
  }
480
  return $this->_tagCache;
543
  */
544
  protected function _octdec($val)
545
  {
546
+ if (is_string($val) && decoct(octdec($val)) == $val) {
547
  return octdec($val);
548
  }
549
  return $val;
lib/Zend/Cache/Backend/Test.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Test.php 22504 2010-06-30 17:05:07Z mabe $
21
  */
22
 
23
 
@@ -109,7 +109,8 @@ class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_B
109
  || $id == 'e83249ea22178277d5befc2c5e2e9ace'
110
  || $id == '40f649b94977c0a6e76902e2a0b43587'
111
  || $id == '88161989b73a4cbfd0b701c446115a99'
112
- || $id == '205fc79cba24f0f0018eb92c7c8b3ba4')
 
113
  {
114
  return false;
115
  }
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Test.php 23051 2010-10-07 17:01:21Z mabe $
21
  */
22
 
23
 
109
  || $id == 'e83249ea22178277d5befc2c5e2e9ace'
110
  || $id == '40f649b94977c0a6e76902e2a0b43587'
111
  || $id == '88161989b73a4cbfd0b701c446115a99'
112
+ || $id == '205fc79cba24f0f0018eb92c7c8b3ba4'
113
+ || $id == '170720e35f38150b811f68a937fb042d')
114
  {
115
  return false;
116
  }
lib/Zend/Cache/Backend/TwoLevels.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: TwoLevels.php 22737 2010-07-30 16:30:42Z andyfowler $
21
  */
22
 
23
 
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: TwoLevels.php 22736 2010-07-30 16:25:54Z andyfowler $
21
  */
22
 
23
 
lib/Zend/Cache/Backend/Xcache.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Xcache.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
 
@@ -182,7 +182,12 @@ class Zend_Cache_Backend_Xcache extends Zend_Cache_Backend implements Zend_Cache
182
  if ($this->_options['password']) {
183
  $_SERVER['PHP_AUTH_PW'] = $this->_options['password'];
184
  }
185
- xcache_clear_cache(XC_TYPE_VAR, 0);
 
 
 
 
 
186
  if (isset($backup['PHP_AUTH_USER'])) {
187
  $_SERVER['PHP_AUTH_USER'] = $backup['PHP_AUTH_USER'];
188
  $_SERVER['PHP_AUTH_PW'] = $backup['PHP_AUTH_PW'];
17
  * @subpackage Zend_Cache_Backend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Xcache.php 23345 2010-11-15 16:31:14Z mabe $
21
  */
22
 
23
 
182
  if ($this->_options['password']) {
183
  $_SERVER['PHP_AUTH_PW'] = $this->_options['password'];
184
  }
185
+
186
+ $cnt = xcache_count(XC_TYPE_VAR);
187
+ for ($i=0; $i < $cnt; $i++) {
188
+ xcache_clear_cache(XC_TYPE_VAR, $i);
189
+ }
190
+
191
  if (isset($backup['PHP_AUTH_USER'])) {
192
  $_SERVER['PHP_AUTH_USER'] = $backup['PHP_AUTH_USER'];
193
  $_SERVER['PHP_AUTH_PW'] = $backup['PHP_AUTH_PW'];
lib/Zend/Cache/Core.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Cache
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Core.php 22652 2010-07-21 04:30:24Z ramon $
20
  */
21
 
22
 
16
  * @package Zend_Cache
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Core.php 22651 2010-07-21 04:19:44Z ramon $
20
  */
21
 
22
 
lib/Zend/Cache/Frontend/Capture.php CHANGED
@@ -17,6 +17,7 @@
17
  * @subpackage Zend_Cache_Frontend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
20
  */
21
 
22
 
@@ -74,7 +75,7 @@ class Zend_Cache_Frontend_Capture extends Zend_Cache_Core
74
  public function _flush($data)
75
  {
76
  $id = array_pop($this->_idStack);
77
- if (is_null($id)) {
78
  Zend_Cache::throwException('use of _flush() without a start()');
79
  }
80
  if ($this->_extension) {
17
  * @subpackage Zend_Cache_Frontend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Capture.php 22662 2010-07-24 17:37:36Z mabe $
21
  */
22
 
23
 
75
  public function _flush($data)
76
  {
77
  $id = array_pop($this->_idStack);
78
+ if ($id === null) {
79
  Zend_Cache::throwException('use of _flush() without a start()');
80
  }
81
  if ($this->_extension) {
lib/Zend/Cache/Frontend/Class.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Cache_Frontend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Class.php 22654 2010-07-22 18:44:13Z mabe $
21
  */
22
 
23
  /**
@@ -218,11 +218,16 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
218
  // A cache is not available (or not valid for this frontend)
219
  ob_start();
220
  ob_implicit_flush(false);
221
- $return = call_user_func_array(array($this->_cachedEntity, $name), $parameters);
222
- $output = ob_get_contents();
223
- ob_end_clean();
224
- $data = array($output, $return);
225
- $this->save($data, $id, $this->_tags, $this->_specificLifetime, $this->_priority);
 
 
 
 
 
226
  }
227
 
228
  echo $output;
17
  * @subpackage Zend_Cache_Frontend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Class.php 23051 2010-10-07 17:01:21Z mabe $
21
  */
22
 
23
  /**
218
  // A cache is not available (or not valid for this frontend)
219
  ob_start();
220
  ob_implicit_flush(false);
221
+
222
+ try {
223
+ $return = call_user_func_array(array($this->_cachedEntity, $name), $parameters);
224
+ $output = ob_get_clean();
225
+ $data = array($output, $return);
226
+ $this->save($data, $id, $this->_tags, $this->_specificLifetime, $this->_priority);
227
+ } catch (Exception $e) {
228
+ ob_end_clean();
229
+ throw $e;
230
+ }
231
  }
232
 
233
  echo $output;
lib/Zend/Cache/Frontend/File.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Cache_Frontend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
 
@@ -97,22 +97,31 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core
97
  }
98
 
99
  /**
100
- * Change the master_file option
101
  *
102
- * @param string $masterFile the complete path and name of the master file
103
  */
104
- public function setMasterFiles($masterFiles)
105
  {
106
- clearstatcache();
107
- $this->_specificOptions['master_file'] = $masterFiles[0]; // to keep a compatibility
108
- $this->_specificOptions['master_files'] = $masterFiles;
109
  $this->_masterFile_mtimes = array();
 
 
110
  $i = 0;
111
  foreach ($masterFiles as $masterFile) {
112
- $this->_masterFile_mtimes[$i] = @filemtime($masterFile);
113
- if ((!($this->_specificOptions['ignore_missing_master_files'])) && (!($this->_masterFile_mtimes[$i]))) {
114
- Zend_Cache::throwException('Unable to read master_file : '.$masterFile);
 
 
 
 
 
 
 
115
  }
 
116
  $i++;
117
  }
118
  }
@@ -127,7 +136,7 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core
127
  */
128
  public function setMasterFile($masterFile)
129
  {
130
- $this->setMasterFiles(array(0 => $masterFile));
131
  }
132
 
133
  /**
17
  * @subpackage Zend_Cache_Frontend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: File.php 23330 2010-11-14 20:08:09Z mabe $
21
  */
22
 
23
 
97
  }
98
 
99
  /**
100
+ * Change the master_files option
101
  *
102
+ * @param array $masterFiles the complete paths and name of the master files
103
  */
104
+ public function setMasterFiles(array $masterFiles)
105
  {
106
+ $this->_specificOptions['master_file'] = null; // to keep a compatibility
107
+ $this->_specificOptions['master_files'] = null;
 
108
  $this->_masterFile_mtimes = array();
109
+
110
+ clearstatcache();
111
  $i = 0;
112
  foreach ($masterFiles as $masterFile) {
113
+ $mtime = @filemtime($masterFile);
114
+
115
+ if (!$this->_specificOptions['ignore_missing_master_files'] && !$mtime) {
116
+ Zend_Cache::throwException('Unable to read master_file : ' . $masterFile);
117
+ }
118
+
119
+ $this->_masterFile_mtimes[$i] = $mtime;
120
+ $this->_specificOptions['master_files'][$i] = $masterFile;
121
+ if ($i === 0) { // to keep a compatibility
122
+ $this->_specificOptions['master_files'] = $masterFile;
123
  }
124
+
125
  $i++;
126
  }
127
  }
136
  */
137
  public function setMasterFile($masterFile)
138
  {
139
+ $this->setMasterFiles(array($masterFile));
140
  }
141
 
142
  /**
lib/Zend/Cache/Frontend/Function.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Cache_Frontend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Function.php 22654 2010-07-22 18:44:13Z mabe $
21
  */
22
 
23
 
17
  * @subpackage Zend_Cache_Frontend
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Function.php 22648 2010-07-20 14:43:27Z mabe $
21
  */
22
 
23
 
lib/Zend/Cache/Manager.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Cache
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id$
20
  */
21
 
22
  /** @see Zend_Cache_Exception */
16
  * @package Zend_Cache
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Manager.php 22727 2010-07-30 12:36:00Z mabe $
20
  */
21
 
22
  /** @see Zend_Cache_Exception */
lib/Zend/Captcha/Image.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Image.php 22590 2010-07-16 20:53:40Z mikaelkael $
21
  */
22
 
23
  /** @see Zend_Captcha_Word */
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Image.php 22589 2010-07-16 20:51:51Z mikaelkael $
21
  */
22
 
23
  /** @see Zend_Captcha_Word */
lib/Zend/Captcha/Word.php CHANGED
@@ -32,7 +32,7 @@
32
  * @subpackage Adapter
33
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
  * @license http://framework.zend.com/license/new-bsd New BSD License
35
- * @version $Id: Word.php 20096 2010-01-06 02:05:09Z bkarwin $
36
  */
37
  abstract class Zend_Captcha_Word extends Zend_Captcha_Base
38
  {
@@ -131,7 +131,7 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base
131
  *
132
  * @return string
133
  */
134
- public function getSessionClass()
135
  {
136
  return $this->_sessionClass;
137
  }
@@ -230,6 +230,28 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base
230
  }
231
 
232
  /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  * Get session object
234
  *
235
  * @return Zend_Session_Namespace
32
  * @subpackage Adapter
33
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
  * @license http://framework.zend.com/license/new-bsd New BSD License
35
+ * @version $Id: Word.php 21793 2010-04-08 00:51:31Z stas $
36
  */
37
  abstract class Zend_Captcha_Word extends Zend_Captcha_Base
38
  {
131
  *
132
  * @return string
133
  */
134
+ public function getSessionClass()
135
  {
136
  return $this->_sessionClass;
137
  }
230
  }
231
 
232
  /**
233
+ * Numbers should be included in the pattern?
234
+ *
235
+ * @return bool
236
+ */
237
+ public function getUseNumbers()
238
+ {
239
+ return $this->_useNumbers;
240
+ }
241
+
242
+ /**
243
+ * Set if numbers should be included in the pattern
244
+ *
245
+ * @param $_useNumbers numbers should be included in the pattern?
246
+ * @return Zend_Captcha_Word
247
+ */
248
+ public function setUseNumbers($_useNumbers)
249
+ {
250
+ $this->_useNumbers = $_useNumbers;
251
+ return $this;
252
+ }
253
+
254
+ /**
255
  * Get session object
256
  *
257
  * @return Zend_Session_Namespace
lib/Zend/Cloud/AbstractFactory.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Cloud
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ */
20
+
21
+ /**
22
+ * Abstract factory for Zend_Cloud resources
23
+ *
24
+ * @category Zend
25
+ * @package Zend_Cloud
26
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
+ * @license http://framework.zend.com/license/new-bsd New BSD License
28
+ */
29
+ class Zend_Cloud_AbstractFactory
30
+ {
31
+ /**
32
+ * Constructor
33
+ *
34
+ * @return void
35
+ */
36
+ private function __construct()
37
+ {
38
+ // private ctor - should not be used
39
+ }
40
+
41
+ /**
42
+ * Get an individual adapter instance
43
+ *
44
+ * @param string $adapterOption
45
+ * @param array|Zend_Config $options
46
+ * @return null|Zend_Cloud_DocumentService_Adapter|Zend_Cloud_QueueService_Adapter|Zend_Cloud_StorageService_Adapter
47
+ */
48
+ protected static function _getAdapter($adapterOption, $options)
49
+ {
50
+ if ($options instanceof Zend_Config) {
51
+ $options = $options->toArray();
52
+ }
53
+
54
+ if (!isset($options[$adapterOption])) {
55
+ return null;
56
+ }
57
+
58
+ $classname = $options[$adapterOption];
59
+ unset($options[$adapterOption]);
60
+ if (!class_exists($classname)) {
61
+ #require_once 'Zend/Loader.php';
62
+ Zend_Loader::loadClass($classname);
63
+ }
64
+
65
+ return new $classname($options);
66
+ }
67
+ }
lib/Zend/Cloud/DocumentService/Adapter.php ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage DocumentService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ /**
21
+ * Common interface for document storage services in the cloud. This interface
22
+ * supports most document services and provides some flexibility for
23
+ * vendor-specific features and requirements via an optional $options array in
24
+ * each method signature. Classes implementing this interface should implement
25
+ * URI construction for collections and documents from the parameters given in each
26
+ * method and the account data passed in to the constructor. Classes
27
+ * implementing this interface are also responsible for security; access control
28
+ * isn't currently supported in this interface, although we are considering
29
+ * access control support in future versions of the interface.
30
+ *
31
+ * @category Zend
32
+ * @package Zend_Cloud
33
+ * @subpackage DocumentService
34
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
35
+ * @license http://framework.zend.com/license/new-bsd New BSD License
36
+ */
37
+ interface Zend_Cloud_DocumentService_Adapter
38
+ {
39
+ // HTTP adapter to use for connections
40
+ const HTTP_ADAPTER = 'http_adapter';
41
+
42
+ /**
43
+ * Create collection.
44
+ *
45
+ * @param string $name
46
+ * @param array $options
47
+ * @return array
48
+ */
49
+ public function createCollection($name, $options = null);
50
+
51
+ /**
52
+ * Delete collection.
53
+ *
54
+ * @param string $name
55
+ * @param array $options
56
+ * @return void
57
+ */
58
+ public function deleteCollection($name, $options = null);
59
+
60
+ /**
61
+ * List collections.
62
+ *
63
+ * @param array $options
64
+ * @return array List of collection names
65
+ */
66
+ public function listCollections($options = null);
67
+
68
+ /**
69
+ * List all documents in a collection
70
+ *
71
+ * @param string $collectionName
72
+ * @param null|array $options
73
+ * @return Zend_Cloud_DocumentService_DocumentSet
74
+ */
75
+ public function listDocuments($collectionName, array $options = null);
76
+
77
+ /**
78
+ * Insert document
79
+ *
80
+ * @param string $collectionName Collection name
81
+ * @param Zend_Cloud_DocumentService_Document $document Document to insert
82
+ * @param array $options
83
+ * @return boolean
84
+ */
85
+ public function insertDocument($collectionName, $document, $options = null);
86
+
87
+ /**
88
+ * Replace document
89
+ * The new document replaces the existing document with the same ID.
90
+ *
91
+ * @param string $collectionName Collection name
92
+ * @param Zend_Cloud_DocumentService_Document $document
93
+ * @param array $options
94
+ */
95
+ public function replaceDocument($collectionName, $document, $options = null);
96
+
97
+ /**
98
+ * Update document
99
+ * The fields of the existing documents will be updated.
100
+ * Fields not specified in the set will be left as-is.
101
+ *
102
+ * @param string $collectionName
103
+ * @param mixed|Zend_Cloud_DocumentService_Document $documentID Document ID, adapter-dependent, or document containing updates
104
+ * @param array|Zend_Cloud_DocumentService_Document $fieldset Set of fields to update
105
+ * @param array $options
106
+ * @return boolean
107
+ */
108
+ public function updateDocument($collectionName, $documentID, $fieldset = null, $options = null);
109
+
110
+ /**
111
+ * Delete document
112
+ *
113
+ * @param string $collectionName Collection name
114
+ * @param mixed $documentID Document ID, adapter-dependent
115
+ * @param array $options
116
+ * @return void
117
+ */
118
+ public function deleteDocument($collectionName, $documentID, $options = null);
119
+
120
+ /**
121
+ * Fetch single document by ID
122
+ *
123
+ * Will return false if the document does not exist
124
+ *
125
+ * @param string $collectionName Collection name
126
+ * @param mixed $documentID Document ID, adapter-dependent
127
+ * @param array $options
128
+ * @return Zend_Cloud_DocumentService_Document
129
+ */
130
+ public function fetchDocument($collectionName, $documentID, $options = null);
131
+
132
+ /**
133
+ * Query for documents stored in the document service. If a string is passed in
134
+ * $query, the query string will be passed directly to the service.
135
+ *
136
+ * @param string $collectionName Collection name
137
+ * @param string $query
138
+ * @param array $options
139
+ * @return array Array of field sets
140
+ */
141
+ public function query($collectionName, $query, $options = null);
142
+
143
+ /**
144
+ * Create query statement
145
+ *
146
+ * @param string $fields
147
+ * @return Zend_Cloud_DocumentService_Query
148
+ */
149
+ public function select($fields = null);
150
+
151
+ /**
152
+ * Get the concrete service client
153
+ */
154
+ public function getClient();
155
+ }
lib/Zend/Cloud/DocumentService/Adapter/AbstractAdapter.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage DocumentService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Cloud/DocumentService/Adapter.php';
21
+ #require_once 'Zend/Cloud/DocumentService/Document.php';
22
+ #require_once 'Zend/Cloud/DocumentService/DocumentSet.php';
23
+ #require_once 'Zend/Cloud/DocumentService/Query.php';
24
+
25
+ /**
26
+ * Abstract document service adapter
27
+ *
28
+ * Provides functionality surrounding setting classes for each of:
29
+ * - document objects
30
+ * - document set objects
31
+ * - query class objects
32
+ *
33
+ * @category Zend
34
+ * @package Zend_Cloud
35
+ * @subpackage DocumentService
36
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
37
+ * @license http://framework.zend.com/license/new-bsd New BSD License
38
+ */
39
+ abstract class Zend_Cloud_DocumentService_Adapter_AbstractAdapter
40
+ implements Zend_Cloud_DocumentService_Adapter
41
+ {
42
+ const DOCUMENT_CLASS = 'document_class';
43
+ const DOCUMENTSET_CLASS = 'documentset_class';
44
+ const QUERY_CLASS = 'query_class';
45
+
46
+ /**
47
+ * Class to utilize for new document objects
48
+ * @var string
49
+ */
50
+ protected $_documentClass = 'Zend_Cloud_DocumentService_Document';
51
+
52
+ /**
53
+ * Class to utilize for new document set objects
54
+ * @var string
55
+ */
56
+ protected $_documentSetClass = 'Zend_Cloud_DocumentService_DocumentSet';
57
+
58
+ /**
59
+ * Class to utilize for new query objects
60
+ *
61
+ * @var string
62
+ */
63
+ protected $_queryClass = 'Zend_Cloud_DocumentService_Query';
64
+
65
+ /**
66
+ * Set the class for document objects
67
+ *
68
+ * @param string $class
69
+ * @return Zend_Cloud_DocumentService_Adapter_AbstractAdapter
70
+ */
71
+ public function setDocumentClass($class)
72
+ {
73
+ $this->_documentClass = (string) $class;
74
+ return $this;
75
+ }
76
+
77
+ /**
78
+ * Get the class for document objects
79
+ *
80
+ * @return string
81
+ */
82
+ public function getDocumentClass()
83
+ {
84
+ return $this->_documentClass;
85
+ }
86
+
87
+ /**
88
+ * Set the class for document set objects
89
+ *
90
+ * @param string $class
91
+ * @return Zend_Cloud_DocumentService_Adapter_AbstractAdapter
92
+ */
93
+ public function setDocumentSetClass($class)
94
+ {
95
+ $this->_documentSetClass = (string) $class;
96
+ return $this;
97
+ }
98
+
99
+ /**
100
+ * Get the class for document set objects
101
+ *
102
+ * @return string
103
+ */
104
+ public function getDocumentSetClass()
105
+ {
106
+ return $this->_documentSetClass;
107
+ }
108
+
109
+ /**
110
+ * Set the query class for query objects
111
+ *
112
+ * @param string $class
113
+ * @return Zend_Cloud_DocumentService_Adapter_AbstractAdapter
114
+ */
115
+ public function setQueryClass($class)
116
+ {
117
+ $this->_queryClass = (string) $class;
118
+ return $this;
119
+ }
120
+
121
+ /**
122
+ * Get the class for query objects
123
+ *
124
+ * @return string
125
+ */
126
+ public function getQueryClass()
127
+ {
128
+ return $this->_queryClass;
129
+ }
130
+ }
lib/Zend/Cloud/DocumentService/Adapter/SimpleDb.php ADDED
@@ -0,0 +1,468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage DocumentService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Cloud/DocumentService/Adapter/AbstractAdapter.php';
21
+ #require_once 'Zend/Cloud/DocumentService/Adapter/SimpleDb/Query.php';
22
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
23
+ #require_once 'Zend/Service/Amazon/SimpleDb.php';
24
+ #require_once 'Zend/Service/Amazon/SimpleDb/Attribute.php';
25
+
26
+ /**
27
+ * SimpleDB adapter for document service.
28
+ *
29
+ * @category Zend
30
+ * @package Zend_Cloud
31
+ * @subpackage DocumentService
32
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33
+ * @license http://framework.zend.com/license/new-bsd New BSD License
34
+ */
35
+ class Zend_Cloud_DocumentService_Adapter_SimpleDb
36
+ extends Zend_Cloud_DocumentService_Adapter_AbstractAdapter
37
+ {
38
+ /*
39
+ * Options array keys for the SimpleDB adapter.
40
+ */
41
+ const AWS_ACCESS_KEY = 'aws_accesskey';
42
+ const AWS_SECRET_KEY = 'aws_secretkey';
43
+
44
+ const ITEM_NAME = 'ItemName';
45
+
46
+ const MERGE_OPTION = "merge";
47
+ const RETURN_DOCUMENTS = "return_documents";
48
+
49
+ const DEFAULT_QUERY_CLASS = 'Zend_Cloud_DocumentService_Adapter_SimpleDb_Query';
50
+
51
+
52
+ /**
53
+ * SQS service instance.
54
+ * @var Zend_Service_Amazon_SimpleDb
55
+ */
56
+ protected $_simpleDb;
57
+
58
+ /**
59
+ * Class to utilize for new query objects
60
+ * @var string
61
+ */
62
+ protected $_queryClass = 'Zend_Cloud_DocumentService_Adapter_SimpleDb_Query';
63
+
64
+ /**
65
+ * Constructor
66
+ *
67
+ * @param array|Zend_Config $options
68
+ * @return void
69
+ */
70
+ public function __construct($options = array())
71
+ {
72
+ if ($options instanceof Zend_Config) {
73
+ $options = $options->toArray();
74
+ }
75
+
76
+ if (!is_array($options)) {
77
+ throw new Zend_Cloud_DocumentService_Exception('Invalid options provided to constructor');
78
+ }
79
+
80
+ $this->_simpleDb = new Zend_Service_Amazon_SimpleDb(
81
+ $options[self::AWS_ACCESS_KEY], $options[self::AWS_SECRET_KEY]
82
+ );
83
+
84
+ if (isset($options[self::HTTP_ADAPTER])) {
85
+ $this->_sqs->getHttpClient()->setAdapter($options[self::HTTP_ADAPTER]);
86
+ }
87
+
88
+ if (isset($options[self::DOCUMENT_CLASS])) {
89
+ $this->setDocumentClass($options[self::DOCUMENT_CLASS]);
90
+ }
91
+
92
+ if (isset($options[self::DOCUMENTSET_CLASS])) {
93
+ $this->setDocumentSetClass($options[self::DOCUMENTSET_CLASS]);
94
+ }
95
+
96
+ if (isset($options[self::QUERY_CLASS])) {
97
+ $this->setQueryClass($options[self::QUERY_CLASS]);
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Create collection.
103
+ *
104
+ * @param string $name
105
+ * @param array $options
106
+ * @return void
107
+ */
108
+ public function createCollection($name, $options = null)
109
+ {
110
+ try {
111
+ $this->_simpleDb->createDomain($name);
112
+ } catch(Zend_Service_Amazon_Exception $e) {
113
+ throw new Zend_Cloud_DocumentService_Exception('Error on domain creation: '.$e->getMessage(), $e->getCode(), $e);
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Delete collection.
119
+ *
120
+ * @param string $name
121
+ * @param array $options
122
+ * @return void
123
+ */
124
+ public function deleteCollection($name, $options = null)
125
+ {
126
+ try {
127
+ $this->_simpleDb->deleteDomain($name);
128
+ } catch(Zend_Service_Amazon_Exception $e) {
129
+ throw new Zend_Cloud_DocumentService_Exception('Error on collection deletion: '.$e->getMessage(), $e->getCode(), $e);
130
+ }
131
+ }
132
+
133
+ /**
134
+ * List collections.
135
+ *
136
+ * @param array $options
137
+ * @return array
138
+ */
139
+ public function listCollections($options = null)
140
+ {
141
+ try {
142
+ // TODO package this in Pages
143
+ $domains = $this->_simpleDb->listDomains()->getData();
144
+ } catch(Zend_Service_Amazon_Exception $e) {
145
+ throw new Zend_Cloud_DocumentService_Exception('Error on collection deletion: '.$e->getMessage(), $e->getCode(), $e);
146
+ }
147
+
148
+ return $domains;
149
+ }
150
+
151
+ /**
152
+ * List documents
153
+ *
154
+ * Returns a key/value array of document names to document objects.
155
+ *
156
+ * @param string $collectionName Name of collection for which to list documents
157
+ * @param array|null $options
158
+ * @return Zend_Cloud_DocumentService_DocumentSet
159
+ */
160
+ public function listDocuments($collectionName, array $options = null)
161
+ {
162
+ $query = $this->select('*')->from($collectionName);
163
+ $items = $this->query($collectionName, $query, $options);
164
+ return $items;
165
+ }
166
+
167
+ /**
168
+ * Insert document
169
+ *
170
+ * @param string $collectionName Collection into which to insert document
171
+ * @param array|Zend_Cloud_DocumentService_Document $document
172
+ * @param array $options
173
+ * @return void
174
+ */
175
+ public function insertDocument($collectionName, $document, $options = null)
176
+ {
177
+ if (is_array($document)) {
178
+ $document = $this->_getDocumentFromArray($document);
179
+ }
180
+
181
+ if (!$document instanceof Zend_Cloud_DocumentService_Document) {
182
+ throw new Zend_Cloud_DocumentService_Exception('Invalid document supplied');
183
+ }
184
+
185
+ try {
186
+ $this->_simpleDb->putAttributes(
187
+ $collectionName,
188
+ $document->getID(),
189
+ $this->_makeAttributes($document->getID(), $document->getFields())
190
+ );
191
+ } catch(Zend_Service_Amazon_Exception $e) {
192
+ throw new Zend_Cloud_DocumentService_Exception('Error on document insertion: '.$e->getMessage(), $e->getCode(), $e);
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Replace an existing document with a new version
198
+ *
199
+ * @param string $collectionName
200
+ * @param array|Zend_Cloud_DocumentService_Document $document
201
+ * @param array $options
202
+ * @return void
203
+ */
204
+ public function replaceDocument($collectionName, $document, $options = null)
205
+ {
206
+ if (is_array($document)) {
207
+ $document = $this->_getDocumentFromArray($document);
208
+ }
209
+
210
+ if (!$document instanceof Zend_Cloud_DocumentService_Document) {
211
+ throw new Zend_Cloud_DocumentService_Exception('Invalid document supplied');
212
+ }
213
+
214
+ // Delete document first, then insert. PutAttributes always keeps any
215
+ // fields not referenced in the payload, but present in the document
216
+ $documentId = $document->getId();
217
+ $fields = $document->getFields();
218
+ $docClass = get_class($document);
219
+ $this->deleteDocument($collectionName, $document, $options);
220
+
221
+ $document = new $docClass($fields, $documentId);
222
+ $this->insertDocument($collectionName, $document);
223
+ }
224
+
225
+ /**
226
+ * Update document. The new document replaces the existing document.
227
+ *
228
+ * Option 'merge' specifies to add all attributes (if true) or
229
+ * specific attributes ("attr" => true) instead of replacing them.
230
+ * By default, attributes are replaced.
231
+ *
232
+ * @param string $collectionName
233
+ * @param mixed|Zend_Cloud_DocumentService_Document $documentId Document ID, adapter-dependent
234
+ * @param array|Zend_Cloud_DocumentService_Document $fieldset Set of fields to update
235
+ * @param array $options
236
+ * @return boolean
237
+ */
238
+ public function updateDocument($collectionName, $documentId, $fieldset = null, $options = null)
239
+ {
240
+ if (null === $fieldset && $documentId instanceof Zend_Cloud_DocumentService_Document) {
241
+ $fieldset = $documentId->getFields();
242
+ if (empty($documentId)) {
243
+ $documentId = $documentId->getId();
244
+ }
245
+ } elseif ($fieldset instanceof Zend_Cloud_DocumentService_Document) {
246
+ if (empty($documentId)) {
247
+ $documentId = $fieldset->getId();
248
+ }
249
+ $fieldset = $fieldset->getFields();
250
+ }
251
+
252
+ $replace = array();
253
+ if (empty($options[self::MERGE_OPTION])) {
254
+ // no merge option - we replace all
255
+ foreach ($fieldset as $key => $value) {
256
+ $replace[$key] = true;
257
+ }
258
+ } elseif (is_array($options[self::MERGE_OPTION])) {
259
+ foreach ($fieldset as $key => $value) {
260
+ if (empty($options[self::MERGE_OPTION][$key])) {
261
+ // if there's merge key, we add it, otherwise we replace it
262
+ $replace[$key] = true;
263
+ }
264
+ }
265
+ } // otherwise $replace is empty - all is merged
266
+
267
+ try {
268
+ $this->_simpleDb->putAttributes(
269
+ $collectionName,
270
+ $documentId,
271
+ $this->_makeAttributes($documentId, $fieldset),
272
+ $replace
273
+ );
274
+ } catch(Zend_Service_Amazon_Exception $e) {
275
+ throw new Zend_Cloud_DocumentService_Exception('Error on document update: '.$e->getMessage(), $e->getCode(), $e);
276
+ }
277
+ return true;
278
+ }
279
+
280
+ /**
281
+ * Delete document.
282
+ *
283
+ * @param string $collectionName Collection from which to delete document
284
+ * @param mixed $document Document ID or Document object.
285
+ * @param array $options
286
+ * @return boolean
287
+ */
288
+ public function deleteDocument($collectionName, $document, $options = null)
289
+ {
290
+ if ($document instanceof Zend_Cloud_DocumentService_Document) {
291
+ $document = $document->getId();
292
+ }
293
+ try {
294
+ $this->_simpleDb->deleteAttributes($collectionName, $document);
295
+ } catch(Zend_Service_Amazon_Exception $e) {
296
+ throw new Zend_Cloud_DocumentService_Exception('Error on document deletion: '.$e->getMessage(), $e->getCode(), $e);
297
+ }
298
+ return true;
299
+ }
300
+
301
+ /**
302
+ * Fetch single document by ID
303
+ *
304
+ * @param string $collectionName Collection name
305
+ * @param mixed $documentId Document ID, adapter-dependent
306
+ * @param array $options
307
+ * @return Zend_Cloud_DocumentService_Document
308
+ */
309
+ public function fetchDocument($collectionName, $documentId, $options = null)
310
+ {
311
+ try {
312
+ $attributes = $this->_simpleDb->getAttributes($collectionName, $documentId);
313
+ if ($attributes == false || count($attributes) == 0) {
314
+ return false;
315
+ }
316
+ return $this->_resolveAttributes($attributes, true);
317
+ } catch(Zend_Service_Amazon_Exception $e) {
318
+ throw new Zend_Cloud_DocumentService_Exception('Error on fetching document: '.$e->getMessage(), $e->getCode(), $e);
319
+ }
320
+ }
321
+
322
+ /**
323
+ * Query for documents stored in the document service. If a string is passed in
324
+ * $query, the query string will be passed directly to the service.
325
+ *
326
+ * @param string $collectionName Collection name
327
+ * @param string $query
328
+ * @param array $options
329
+ * @return array Zend_Cloud_DocumentService_DocumentSet
330
+ */
331
+ public function query($collectionName, $query, $options = null)
332
+ {
333
+ $returnDocs = isset($options[self::RETURN_DOCUMENTS])
334
+ ? (bool) $options[self::RETURN_DOCUMENTS]
335
+ : true;
336
+
337
+ try {
338
+ if ($query instanceof Zend_Cloud_DocumentService_Adapter_SimpleDb_Query) {
339
+ $query = $query->assemble($collectionName);
340
+ }
341
+ $result = $this->_simpleDb->select($query);
342
+ } catch(Zend_Service_Amazon_Exception $e) {
343
+ throw new Zend_Cloud_DocumentService_Exception('Error on document query: '.$e->getMessage(), $e->getCode(), $e);
344
+ }
345
+
346
+ return $this->_getDocumentSetFromResultSet($result, $returnDocs);
347
+ }
348
+
349
+ /**
350
+ * Create query statement
351
+ *
352
+ * @param string $fields
353
+ * @return Zend_Cloud_DocumentService_Adapter_SimpleDb_Query
354
+ */
355
+ public function select($fields = null)
356
+ {
357
+ $queryClass = $this->getQueryClass();
358
+ if (!class_exists($queryClass)) {
359
+ #require_once 'Zend/Loader.php';
360
+ Zend_Loader::loadClass($queryClass);
361
+ }
362
+
363
+ $query = new $queryClass($this);
364
+ $defaultClass = self::DEFAULT_QUERY_CLASS;
365
+ if (!$query instanceof $defaultClass) {
366
+ throw new Zend_Cloud_DocumentService_Exception('Query class must extend ' . self::DEFAULT_QUERY_CLASS);
367
+ }
368
+
369
+ $query->select($fields);
370
+ return $query;
371
+ }
372
+
373
+ /**
374
+ * Get the concrete service client
375
+ *
376
+ * @return Zend_Service_Amazon_SimpleDb
377
+ */
378
+ public function getClient()
379
+ {
380
+ return $this->_simpleDb;
381
+ }
382
+
383
+ /**
384
+ * Convert array of key-value pairs to array of Amazon attributes
385
+ *
386
+ * @param string $name
387
+ * @param array $attributes
388
+ * @return array
389
+ */
390
+ protected function _makeAttributes($name, $attributes)
391
+ {
392
+ $result = array();
393
+ foreach ($attributes as $key => $attr) {
394
+ $result[] = new Zend_Service_Amazon_SimpleDb_Attribute($name, $key, $attr);
395
+ }
396
+ return $result;
397
+ }
398
+
399
+ /**
400
+ * Convert array of Amazon attributes to array of key-value pairs
401
+ *
402
+ * @param array $attributes
403
+ * @return array
404
+ */
405
+ protected function _resolveAttributes($attributes, $returnDocument = false)
406
+ {
407
+ $result = array();
408
+ foreach ($attributes as $attr) {
409
+ $value = $attr->getValues();
410
+ if (count($value) == 0) {
411
+ $value = null;
412
+ } elseif (count($value) == 1) {
413
+ $value = $value[0];
414
+ }
415
+ $result[$attr->getName()] = $value;
416
+ }
417
+
418
+ // Return as document object?
419
+ if ($returnDocument) {
420
+ $documentClass = $this->getDocumentClass();
421
+ return new $documentClass($result, $attr->getItemName());
422
+ }
423
+
424
+ return $result;
425
+ }
426
+
427
+ /**
428
+ * Create suitable document from array of fields
429
+ *
430
+ * @param array $document
431
+ * @return Zend_Cloud_DocumentService_Document
432
+ */
433
+ protected function _getDocumentFromArray($document)
434
+ {
435
+ if (!isset($document[Zend_Cloud_DocumentService_Document::KEY_FIELD])) {
436
+ if (isset($document[self::ITEM_NAME])) {
437
+ $key = $document[self::ITEM_NAME];
438
+ unset($document[self::ITEM_NAME]);
439
+ } else {
440
+ throw new Zend_Cloud_DocumentService_Exception('Fields array should contain the key field '.Zend_Cloud_DocumentService_Document::KEY_FIELD);
441
+ }
442
+ } else {
443
+ $key = $document[Zend_Cloud_DocumentService_Document::KEY_FIELD];
444
+ unset($document[Zend_Cloud_DocumentService_Document::KEY_FIELD]);
445
+ }
446
+
447
+ $documentClass = $this->getDocumentClass();
448
+ return new $documentClass($document, $key);
449
+ }
450
+
451
+ /**
452
+ * Create a DocumentSet from a SimpleDb resultset
453
+ *
454
+ * @param Zend_Service_Amazon_SimpleDb_Page $resultSet
455
+ * @param bool $returnDocs
456
+ * @return Zend_Cloud_DocumentService_DocumentSet
457
+ */
458
+ protected function _getDocumentSetFromResultSet(Zend_Service_Amazon_SimpleDb_Page $resultSet, $returnDocs = true)
459
+ {
460
+ $docs = array();
461
+ foreach ($resultSet->getData() as $item) {
462
+ $docs[] = $this->_resolveAttributes($item, $returnDocs);
463
+ }
464
+
465
+ $setClass = $this->getDocumentSetClass();
466
+ return new $setClass($docs);
467
+ }
468
+ }
lib/Zend/Cloud/DocumentService/Adapter/SimpleDb/Query.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage DocumentService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ /*
21
+ * @see Zend_Cloud_DocumentService_Query
22
+ */
23
+ #require_once 'Zend/Cloud/DocumentService/Query.php';
24
+
25
+ /**
26
+ * Class implementing Query adapter for working with SimpleDb queries in a
27
+ * structured way
28
+ *
29
+ * @category Zend
30
+ * @package Zend_Cloud
31
+ * @subpackage DocumentService
32
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33
+ * @license http://framework.zend.com/license/new-bsd New BSD License
34
+ */
35
+ class Zend_Cloud_DocumentService_Adapter_SimpleDb_Query
36
+ extends Zend_Cloud_DocumentService_Query
37
+ {
38
+ /**
39
+ * @var Zend_Cloud_DocumentService_Adapter_SimpleDb
40
+ */
41
+ protected $_adapter;
42
+
43
+ /**
44
+ * Constructor
45
+ *
46
+ * @param Zend_Cloud_DocumentService_Adapter_SimpleDb $adapter
47
+ * @param null|string $collectionName
48
+ * @return void
49
+ */
50
+ public function __construct(Zend_Cloud_DocumentService_Adapter_SimpleDb $adapter, $collectionName = null)
51
+ {
52
+ $this->_adapter = $adapter;
53
+ if (null !== $collectionName) {
54
+ $this->from($collectionName);
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Get adapter
60
+ *
61
+ * @return Zend_Cloud_DocumentService_Adapter_SimpleDb
62
+ */
63
+ public function getAdapter()
64
+ {
65
+ return $this->_adapter;
66
+ }
67
+
68
+ /**
69
+ * Assemble the query into a format the adapter can utilize
70
+ *
71
+ * @var string $collectionName Name of collection from which to select
72
+ * @return string
73
+ */
74
+ public function assemble($collectionName = null)
75
+ {
76
+ $adapter = $this->getAdapter()->getClient();
77
+ $select = null;
78
+ $from = null;
79
+ $where = null;
80
+ $order = null;
81
+ $limit = null;
82
+ foreach ($this->getClauses() as $clause) {
83
+ list($name, $args) = $clause;
84
+
85
+ switch ($name) {
86
+ case self::QUERY_SELECT:
87
+ $select = $args[0];
88
+ break;
89
+ case self::QUERY_FROM:
90
+ if (null === $from) {
91
+ // Only allow setting FROM clause once
92
+ $from = $adapter->quoteName($args);
93
+ }
94
+ break;
95
+ case self::QUERY_WHERE:
96
+ $statement = $this->_parseWhere($args[0], $args[1]);
97
+ if (null === $where) {
98
+ $where = $statement;
99
+ } else {
100
+ $operator = empty($args[2]) ? 'AND' : $args[2];
101
+ $where .= ' ' . $operator . ' ' . $statement;
102
+ }
103
+ break;
104
+ case self::QUERY_WHEREID:
105
+ $statement = $this->_parseWhere('ItemName() = ?', array($args));
106
+ if (null === $where) {
107
+ $where = $statement;
108
+ } else {
109
+ $operator = empty($args[2]) ? 'AND' : $args[2];
110
+ $where .= ' ' . $operator . ' ' . $statement;
111
+ }
112
+ break;
113
+ case self::QUERY_ORDER:
114
+ $order = $adapter->quoteName($args[0]);
115
+ if (isset($args[1])) {
116
+ $order .= ' ' . $args[1];
117
+ }
118
+ break;
119
+ case self::QUERY_LIMIT:
120
+ $limit = $args;
121
+ break;
122
+ default:
123
+ // Ignore unknown clauses
124
+ break;
125
+ }
126
+ }
127
+
128
+ if (empty($select)) {
129
+ $select = "*";
130
+ }
131
+ if (empty($from)) {
132
+ if (null === $collectionName) {
133
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
134
+ throw new Zend_Cloud_DocumentService_Exception("Query requires a FROM clause");
135
+ }
136
+ $from = $adapter->quoteName($collectionName);
137
+ }
138
+ $query = "select $select from $from";
139
+ if (!empty($where)) {
140
+ $query .= " where $where";
141
+ }
142
+ if (!empty($order)) {
143
+ $query .= " order by $order";
144
+ }
145
+ if (!empty($limit)) {
146
+ $query .= " limit $limit";
147
+ }
148
+ return $query;
149
+ }
150
+
151
+ /**
152
+ * Parse a where statement into service-specific language
153
+ *
154
+ * @todo Ensure this fulfills the entire SimpleDB query specification for WHERE
155
+ * @param string $where
156
+ * @param array $args
157
+ * @return string
158
+ */
159
+ protected function _parseWhere($where, $args)
160
+ {
161
+ if (!is_array($args)) {
162
+ $args = (array) $args;
163
+ }
164
+ $adapter = $this->getAdapter()->getClient();
165
+ $i = 0;
166
+ while (false !== ($pos = strpos($where, '?'))) {
167
+ $where = substr_replace($where, $adapter->quote($args[$i]), $pos);
168
+ ++$i;
169
+ }
170
+ if (('(' != $where[0]) || (')' != $where[strlen($where) - 1])) {
171
+ $where = '(' . $where . ')';
172
+ }
173
+ return $where;
174
+ }
175
+ }
lib/Zend/Cloud/DocumentService/Adapter/WindowsAzure.php ADDED
@@ -0,0 +1,628 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage DocumentService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Cloud/DocumentService/Adapter/AbstractAdapter.php';
21
+ #require_once 'Zend/Cloud/DocumentService/Adapter/WindowsAzure/Query.php';
22
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
23
+ #require_once 'Zend/Service/WindowsAzure/Storage/DynamicTableEntity.php';
24
+ #require_once 'Zend/Service/WindowsAzure/Storage/Table.php';
25
+
26
+ /**
27
+ * SimpleDB adapter for document service.
28
+ *
29
+ * @category Zend
30
+ * @package Zend_Cloud
31
+ * @subpackage DocumentService
32
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33
+ * @license http://framework.zend.com/license/new-bsd New BSD License
34
+ */
35
+ class Zend_Cloud_DocumentService_Adapter_WindowsAzure
36
+ extends Zend_Cloud_DocumentService_Adapter_AbstractAdapter
37
+ {
38
+ /*
39
+ * Options array keys for the Azure adapter.
40
+ */
41
+ const ACCOUNT_NAME = 'storage_accountname';
42
+ const ACCOUNT_KEY = 'storage_accountkey';
43
+ const HOST = "storage_host";
44
+ const PROXY_HOST = "storage_proxy_host";
45
+ const PROXY_PORT = "storage_proxy_port";
46
+ const PROXY_CREDENTIALS = "storage_proxy_credentials";
47
+ const DEFAULT_PARTITION_KEY = "default_partition_key";
48
+
49
+ const PARTITION_KEY = 'PartitionKey';
50
+ const ROW_KEY = 'RowKey';
51
+ const VERIFY_ETAG = "verify_etag";
52
+ const TIMESTAMP_KEY = "Timestamp";
53
+
54
+ const DEFAULT_HOST = Zend_Service_WindowsAzure_Storage::URL_CLOUD_TABLE;
55
+ const DEFAULT_QUERY_CLASS = 'Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query';
56
+
57
+ /**
58
+ * Azure service instance.
59
+ *
60
+ * @var Zend_Service_WindowsAzure_Storage_Table
61
+ */
62
+ protected $_storageClient;
63
+
64
+ /**
65
+ * Class to utilize for new query objects
66
+ *
67
+ * @var string
68
+ */
69
+ protected $_queryClass = 'Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query';
70
+
71
+ /**
72
+ * Partition key to use by default when constructing document identifiers
73
+ * @var string
74
+ */
75
+ protected $_defaultPartitionKey;
76
+
77
+ /**
78
+ * Constructor
79
+ *
80
+ * @param array $options
81
+ * @return void
82
+ */
83
+ public function __construct($options = array())
84
+ {
85
+ if ($options instanceof Zend_Config) {
86
+ $options = $options->toArray();
87
+ }
88
+
89
+ if (empty($options)) {
90
+ $options = array();
91
+ }
92
+
93
+ if (!is_array($options)) {
94
+ throw new Zend_Cloud_DocumentService_Exception('Invalid options provided');
95
+ }
96
+
97
+ if (isset($options[self::DOCUMENT_CLASS])) {
98
+ $this->setDocumentClass($options[self::DOCUMENT_CLASS]);
99
+ }
100
+
101
+ if (isset($options[self::DOCUMENTSET_CLASS])) {
102
+ $this->setDocumentSetClass($options[self::DOCUMENTSET_CLASS]);
103
+ }
104
+
105
+ if (isset($options[self::QUERY_CLASS])) {
106
+ $this->setQueryClass($options[self::QUERY_CLASS]);
107
+ }
108
+
109
+ // Build Zend_Service_WindowsAzure_Storage_Blob instance
110
+ if (!isset($options[self::HOST])) {
111
+ $host = self::DEFAULT_HOST;
112
+ } else {
113
+ $host = $options[self::HOST];
114
+ }
115
+
116
+ if (! isset($options[self::ACCOUNT_NAME])) {
117
+ throw new Zend_Cloud_DocumentService_Exception('No Windows Azure account name provided.');
118
+ }
119
+
120
+ if (! isset($options[self::ACCOUNT_KEY])) {
121
+ throw new Zend_Cloud_DocumentService_Exception('No Windows Azure account key provided.');
122
+ }
123
+
124
+ // TODO: support $usePathStyleUri and $retryPolicy
125
+ try {
126
+ $this->_storageClient = new Zend_Service_WindowsAzure_Storage_Table(
127
+ $host, $options[self::ACCOUNT_NAME], $options[self::ACCOUNT_KEY]);
128
+ // Parse other options
129
+ if (! empty($options[self::PROXY_HOST])) {
130
+ $proxyHost = $options[self::PROXY_HOST];
131
+ $proxyPort = isset($options[self::PROXY_PORT]) ? $options[self::PROXY_PORT] : 8080;
132
+ $proxyCredentials = isset($options[self::PROXY_CREDENTIALS]) ? $options[self::PROXY_CREDENTIALS] : '';
133
+ $this->_storageClient->setProxy(true, $proxyHost, $proxyPort, $proxyCredentials);
134
+ }
135
+ if (isset($options[self::HTTP_ADAPTER])) {
136
+ $this->_storageClient->setHttpClientChannel($options[self::HTTP_ADAPTER]);
137
+ }
138
+ } catch(Zend_Service_WindowsAzure_Exception $e) {
139
+ throw new Zend_Cloud_DocumentService_Exception('Error on document service creation: '.$e->getMessage(), $e->getCode(), $e);
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Set the default partition key
145
+ *
146
+ * @param string $key
147
+ * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure
148
+ */
149
+ public function setDefaultPartitionKey($key)
150
+ {
151
+ $this->_validateKey($key);
152
+ $this->_defaultPartitionKey = $key;
153
+ return $this;
154
+ }
155
+
156
+ /**
157
+ * Retrieve default partition key
158
+ *
159
+ * @return null|string
160
+ */
161
+ public function getDefaultPartitionKey()
162
+ {
163
+ return $this->_defaultPartitionKey;
164
+ }
165
+
166
+ /**
167
+ * Create collection.
168
+ *
169
+ * @param string $name
170
+ * @param array $options
171
+ * @return boolean
172
+ */
173
+ public function createCollection($name, $options = null)
174
+ {
175
+ if (!preg_match('/^[A-Za-z][A-Za-z0-9]{2,}$/', $name)) {
176
+ throw new Zend_Cloud_DocumentService_Exception('Invalid collection name; Windows Azure collection names must consist of alphanumeric characters only, and be at least 3 characters long');
177
+ }
178
+ try {
179
+ $this->_storageClient->createTable($name);
180
+ } catch(Zend_Service_WindowsAzure_Exception $e) {
181
+ if (strpos($e->getMessage(), "table specified already exists") === false) {
182
+ throw new Zend_Cloud_DocumentService_Exception('Error on collection creation: '.$e->getMessage(), $e->getCode(), $e);
183
+ }
184
+ }
185
+ return true;
186
+ }
187
+
188
+ /**
189
+ * Delete collection.
190
+ *
191
+ * @param string $name
192
+ * @param array $options
193
+ * @return boolean
194
+ */
195
+ public function deleteCollection($name, $options = null)
196
+ {
197
+ try {
198
+ $this->_storageClient->deleteTable($name);
199
+ } catch(Zend_Service_WindowsAzure_Exception $e) {
200
+ if (strpos($e->getMessage(), "does not exist") === false) {
201
+ throw new Zend_Cloud_DocumentService_Exception('Error on collection deletion: '.$e->getMessage(), $e->getCode(), $e);
202
+ }
203
+ }
204
+ return true;
205
+ }
206
+
207
+ /**
208
+ * List collections.
209
+ *
210
+ * @param array $options
211
+ * @return array
212
+ */
213
+ public function listCollections($options = null)
214
+ {
215
+ try {
216
+ $tables = $this->_storageClient->listTables();
217
+ $restables = array();
218
+ foreach ($tables as $table) {
219
+ $restables[] = $table->name;
220
+ }
221
+ return $restables;
222
+ } catch(Zend_Service_WindowsAzure_Exception $e) {
223
+ throw new Zend_Cloud_DocumentService_Exception('Error on collection list: '.$e->getMessage(), $e->getCode(), $e);
224
+ }
225
+
226
+ return $tables;
227
+ }
228
+
229
+ /**
230
+ * Create suitable document from array of fields
231
+ *
232
+ * @param array $document
233
+ * @param null|string $collectionName Collection to which this document belongs
234
+ * @return Zend_Cloud_DocumentService_Document
235
+ */
236
+ protected function _getDocumentFromArray($document, $collectionName = null)
237
+ {
238
+ $key = null;
239
+ if (!isset($document[Zend_Cloud_DocumentService_Document::KEY_FIELD])) {
240
+ if (isset($document[self::ROW_KEY])) {
241
+ $rowKey = $document[self::ROW_KEY];
242
+ unset($document[self::ROW_KEY]);
243
+ if (isset($document[self::PARTITION_KEY])) {
244
+ $key = array($document[self::PARTITION_KEY], $rowKey);
245
+ unset($document[self::PARTITION_KEY]);
246
+ } elseif (null !== ($partitionKey = $this->getDefaultPartitionKey())) {
247
+ $key = array($partitionKey, $rowKey);
248
+ } elseif (null !== $collectionName) {
249
+ $key = array($collectionName, $rowKey);
250
+ }
251
+ }
252
+ } else {
253
+ $key = $document[Zend_Cloud_DocumentService_Document::KEY_FIELD];
254
+ unset($document[Zend_Cloud_DocumentService_Document::KEY_FIELD]);
255
+ }
256
+
257
+ $documentClass = $this->getDocumentClass();
258
+ return new $documentClass($document, $key);
259
+ }
260
+
261
+ /**
262
+ * List all documents in a collection
263
+ *
264
+ * @param string $collectionName
265
+ * @param null|array $options
266
+ * @return Zend_Cloud_DocumentService_DocumentSet
267
+ */
268
+ public function listDocuments($collectionName, array $options = null)
269
+ {
270
+ $select = $this->select()->from($collectionName);
271
+ return $this->query($collectionName, $select);
272
+ }
273
+
274
+ /**
275
+ * Insert document
276
+ *
277
+ * @param array|Zend_Cloud_DocumentService_Document $document
278
+ * @param array $options
279
+ * @return boolean
280
+ */
281
+ public function insertDocument($collectionName, $document, $options = null)
282
+ {
283
+ if (is_array($document)) {
284
+ $document = $this->_getDocumentFromArray($document, $collectionName);
285
+ }
286
+
287
+ if (!$document instanceof Zend_Cloud_DocumentService_Document) {
288
+ throw new Zend_Cloud_DocumentService_Exception('Invalid document supplied');
289
+ }
290
+
291
+ $key = $this->_validateDocumentId($document->getId(), $collectionName);
292
+ $document->setId($key);
293
+
294
+ $this->_validateCompositeKey($key);
295
+ $this->_validateFields($document);
296
+ try {
297
+
298
+ $entity = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity($key[0], $key[1]);
299
+ $entity->setAzureValues($document->getFields(), true);
300
+ $this->_storageClient->insertEntity($collectionName, $entity);
301
+ } catch(Zend_Service_WindowsAzure_Exception $e) {
302
+ throw new Zend_Cloud_DocumentService_Exception('Error on document insertion: '.$e->getMessage(), $e->getCode(), $e);
303
+ }
304
+ }
305
+
306
+ /**
307
+ * Replace document.
308
+ *
309
+ * The new document replaces the existing document.
310
+ *
311
+ * @param Zend_Cloud_DocumentService_Document $document
312
+ * @param array $options
313
+ * @return boolean
314
+ */
315
+ public function replaceDocument($collectionName, $document, $options = null)
316
+ {
317
+ if (is_array($document)) {
318
+ $document = $this->_getDocumentFromArray($document, $collectionName);
319
+ }
320
+
321
+ if (!$document instanceof Zend_Cloud_DocumentService_Document) {
322
+ throw new Zend_Cloud_DocumentService_Exception('Invalid document supplied');
323
+ }
324
+
325
+ $key = $this->_validateDocumentId($document->getId(), $collectionName);
326
+ $this->_validateFields($document);
327
+ try {
328
+ $entity = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity($key[0], $key[1]);
329
+ $entity->setAzureValues($document->getFields(), true);
330
+ if (isset($options[self::VERIFY_ETAG])) {
331
+ $entity->setEtag($options[self::VERIFY_ETAG]);
332
+ }
333
+
334
+ $this->_storageClient->updateEntity($collectionName, $entity, isset($options[self::VERIFY_ETAG]));
335
+ } catch(Zend_Service_WindowsAzure_Exception $e) {
336
+ throw new Zend_Cloud_DocumentService_Exception('Error on document replace: '.$e->getMessage(), $e->getCode(), $e);
337
+ }
338
+ }
339
+
340
+ /**
341
+ * Update document.
342
+ *
343
+ * The new document is merged the existing document.
344
+ *
345
+ * @param string $collectionName
346
+ * @param mixed|Zend_Cloud_DocumentService_Document $documentId Document identifier or document contaiing updates
347
+ * @param null|array|Zend_Cloud_DocumentService_Document Fields to update (or new fields))
348
+ * @param array $options
349
+ * @return boolean
350
+ */
351
+ public function updateDocument($collectionName, $documentId, $fieldset = null, $options = null)
352
+ {
353
+ if (null === $fieldset && $documentId instanceof Zend_Cloud_DocumentService_Document) {
354
+ $fieldset = $documentId->getFields();
355
+ $documentId = $documentId->getId();
356
+ } elseif ($fieldset instanceof Zend_Cloud_DocumentService_Document) {
357
+ if ($documentId == null) {
358
+ $documentId = $fieldset->getId();
359
+ }
360
+ $fieldset = $fieldset->getFields();
361
+ }
362
+
363
+ $this->_validateCompositeKey($documentId, $collectionName);
364
+ $this->_validateFields($fieldset);
365
+ try {
366
+ $entity = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity($documentId[0], $documentId[1]);
367
+
368
+ // Ensure timestamp is set correctly
369
+ if (isset($fieldset[self::TIMESTAMP_KEY])) {
370
+ $entity->setTimestamp($fieldset[self::TIMESTAMP_KEY]);
371
+ unset($fieldset[self::TIMESTAMP_KEY]);
372
+ }
373
+
374
+ $entity->setAzureValues($fieldset, true);
375
+ if (isset($options[self::VERIFY_ETAG])) {
376
+ $entity->setEtag($options[self::VERIFY_ETAG]);
377
+ }
378
+
379
+ $this->_storageClient->mergeEntity($collectionName, $entity, isset($options[self::VERIFY_ETAG]));
380
+ } catch(Zend_Service_WindowsAzure_Exception $e) {
381
+ throw new Zend_Cloud_DocumentService_Exception('Error on document update: '.$e->getMessage(), $e->getCode(), $e);
382
+ }
383
+ }
384
+
385
+ /**
386
+ * Delete document.
387
+ *
388
+ * @param mixed $document Document ID or Document object.
389
+ * @param array $options
390
+ * @return void
391
+ */
392
+ public function deleteDocument($collectionName, $documentId, $options = null)
393
+ {
394
+ if ($documentId instanceof Zend_Cloud_DocumentService_Document) {
395
+ $documentId = $documentId->getId();
396
+ }
397
+
398
+ $documentId = $this->_validateDocumentId($documentId, $collectionName);
399
+
400
+ try {
401
+ $entity = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity($documentId[0], $documentId[1]);
402
+ if (isset($options[self::VERIFY_ETAG])) {
403
+ $entity->setEtag($options[self::VERIFY_ETAG]);
404
+ }
405
+ $this->_storageClient->deleteEntity($collectionName, $entity, isset($options[self::VERIFY_ETAG]));
406
+ } catch(Zend_Service_WindowsAzure_Exception $e) {
407
+ if (strpos($e->getMessage(), "does not exist") === false) {
408
+ throw new Zend_Cloud_DocumentService_Exception('Error on document deletion: '.$e->getMessage(), $e->getCode(), $e);
409
+ }
410
+ }
411
+ }
412
+
413
+ /**
414
+ * Fetch single document by ID
415
+ *
416
+ * @param string $collectionName Collection name
417
+ * @param mixed $documentId Document ID, adapter-dependent
418
+ * @param array $options
419
+ * @return Zend_Cloud_DocumentService_Document
420
+ */
421
+ public function fetchDocument($collectionName, $documentId, $options = null)
422
+ {
423
+ $documentId = $this->_validateDocumentId($documentId, $collectionName);
424
+ try {
425
+ $entity = $this->_storageClient->retrieveEntityById($collectionName, $documentId[0], $documentId[1]);
426
+ $documentClass = $this->getDocumentClass();
427
+ return new $documentClass($this->_resolveAttributes($entity), array($entity->getPartitionKey(), $entity->getRowKey()));
428
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
429
+ if (strpos($e->getMessage(), "does not exist") !== false) {
430
+ return false;
431
+ }
432
+ throw new Zend_Cloud_DocumentService_Exception('Error on document fetch: '.$e->getMessage(), $e->getCode(), $e);
433
+ }
434
+ }
435
+
436
+ /**
437
+ * Query for documents stored in the document service. If a string is passed in
438
+ * $query, the query string will be passed directly to the service.
439
+ *
440
+ * @param string $collectionName Collection name
441
+ * @param string|Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query $query
442
+ * @param array $options
443
+ * @return array Zend_Cloud_DocumentService_DocumentSet
444
+ */
445
+ public function query($collectionName, $query, $options = null)
446
+ {
447
+ try {
448
+ if ($query instanceof Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query) {
449
+ $entities = $this->_storageClient->retrieveEntities($query->assemble());
450
+ } else {
451
+ $entities = $this->_storageClient->retrieveEntities($collectionName, $query);
452
+ }
453
+
454
+ $documentClass = $this->getDocumentClass();
455
+ $resultSet = array();
456
+ foreach ($entities as $entity) {
457
+ $resultSet[] = new $documentClass(
458
+ $this->_resolveAttributes($entity),
459
+ array($entity->getPartitionKey(), $entity->getRowKey())
460
+ );
461
+ }
462
+ } catch(Zend_Service_WindowsAzure_Exception $e) {
463
+ throw new Zend_Cloud_DocumentService_Exception('Error on document query: '.$e->getMessage(), $e->getCode(), $e);
464
+ }
465
+
466
+ $setClass = $this->getDocumentSetClass();
467
+ return new $setClass($resultSet);
468
+ }
469
+
470
+ /**
471
+ * Create query statement
472
+ *
473
+ * @return Zend_Cloud_DocumentService_Query
474
+ */
475
+ public function select($fields = null)
476
+ {
477
+ $queryClass = $this->getQueryClass();
478
+ if (!class_exists($queryClass)) {
479
+ #require_once 'Zend/Loader.php';
480
+ Zend_Loader::loadClass($queryClass);
481
+ }
482
+
483
+ $query = new $queryClass();
484
+ $defaultClass = self::DEFAULT_QUERY_CLASS;
485
+ if (!$query instanceof $defaultClass) {
486
+ throw new Zend_Cloud_DocumentService_Exception('Query class must extend ' . self::DEFAULT_QUERY_CLASS);
487
+ }
488
+
489
+ $query->select($fields);
490
+ return $query;
491
+ }
492
+
493
+ /**
494
+ * Get the concrete service client
495
+ *
496
+ * @return Zend_Service_WindowsAzure_Storage_Table
497
+ */
498
+ public function getClient()
499
+ {
500
+ return $this->_storageClient;
501
+ }
502
+
503
+ /**
504
+ * Resolve table values to attributes
505
+ *
506
+ * @param Zend_Service_WindowsAzure_Storage_TableEntity $entity
507
+ * @return array
508
+ */
509
+ protected function _resolveAttributes(Zend_Service_WindowsAzure_Storage_TableEntity $entity)
510
+ {
511
+ $result = array();
512
+ foreach ($entity->getAzureValues() as $attr) {
513
+ $result[$attr->Name] = $attr->Value;
514
+ }
515
+ return $result;
516
+ }
517
+
518
+
519
+ /**
520
+ * Validate a partition or row key
521
+ *
522
+ * @param string $key
523
+ * @return void
524
+ * @throws Zend_Cloud_DocumentService_Exception
525
+ */
526
+ protected function _validateKey($key)
527
+ {
528
+ if (preg_match('@[/#?' . preg_quote('\\') . ']@', $key)) {
529
+ throw new Zend_Cloud_DocumentService_Exception('Invalid partition or row key provided; must not contain /, \\, #, or ? characters');
530
+ }
531
+ }
532
+
533
+ /**
534
+ * Validate a composite key
535
+ *
536
+ * @param array $key
537
+ * @return throws Zend_Cloud_DocumentService_Exception
538
+ */
539
+ protected function _validateCompositeKey(array $key)
540
+ {
541
+ if (2 != count($key)) {
542
+ throw new Zend_Cloud_DocumentService_Exception('Invalid document key provided; must contain exactly two elements: a PartitionKey and a RowKey');
543
+ }
544
+ foreach ($key as $k) {
545
+ $this->_validateKey($k);
546
+ }
547
+ }
548
+
549
+ /**
550
+ * Validate a document identifier
551
+ *
552
+ * If the identifier is an array containing a valid partition and row key,
553
+ * returns it. If the identifier is a string:
554
+ * - if a default partition key is present, it creates an identifier using
555
+ * that and the provided document ID
556
+ * - if a collection name is provided, it will use that for the partition key
557
+ * - otherwise, it's invalid
558
+ *
559
+ * @param array|string $documentId
560
+ * @param null|string $collectionName
561
+ * @return array
562
+ * @throws Zend_Cloud_DocumentService_Exception
563
+ */
564
+ protected function _validateDocumentId($documentId, $collectionName = false)
565
+ {
566
+ if (is_array($documentId)) {
567
+ $this->_validateCompositeKey($documentId);
568
+ return $documentId;
569
+ }
570
+ if (!is_string($documentId)) {
571
+ throw new Zend_Cloud_DocumentService_Exception('Invalid document identifier; must be a string or an array');
572
+ }
573
+
574
+ $this->_validateKey($documentId);
575
+
576
+ if (null !== ($partitionKey = $this->getDefaultPartitionKey())) {
577
+ return array($partitionKey, $documentId);
578
+ }
579
+ if (null !== $collectionName) {
580
+ return array($collectionName, $documentId);
581
+ }
582
+ throw new Zend_Cloud_DocumentService_Exception('Cannot determine partition name; invalid document identifier');
583
+ }
584
+
585
+ /**
586
+ * Validate a document's fields for well-formedness
587
+ *
588
+ * Since Azure uses Atom, and fieldnames are included as part of XML
589
+ * element tag names, the field names must be valid XML names.
590
+ *
591
+ * @param Zend_Cloud_DocumentService_Document|array $document
592
+ * @return void
593
+ * @throws Zend_Cloud_DocumentService_Exception
594
+ */
595
+ public function _validateFields($document)
596
+ {
597
+ if ($document instanceof Zend_Cloud_DocumentService_Document) {
598
+ $document = $document->getFields();
599
+ } elseif (!is_array($document)) {
600
+ throw new Zend_Cloud_DocumentService_Exception('Cannot inspect fields; invalid type provided');
601
+ }
602
+
603
+ foreach (array_keys($document) as $key) {
604
+ $this->_validateFieldKey($key);
605
+ }
606
+ }
607
+
608
+ /**
609
+ * Validate an individual field name for well-formedness
610
+ *
611
+ * Since Azure uses Atom, and fieldnames are included as part of XML
612
+ * element tag names, the field names must be valid XML names.
613
+ *
614
+ * While we could potentially normalize names, this could also lead to
615
+ * conflict with other field names -- which we should avoid. As such,
616
+ * invalid field names will raise an exception.
617
+ *
618
+ * @param string $key
619
+ * @return void
620
+ * @throws Zend_Cloud_DocumentService_Exception
621
+ */
622
+ public function _validateFieldKey($key)
623
+ {
624
+ if (!preg_match('/^[_A-Za-z][-._A-Za-z0-9]*$/', $key)) {
625
+ throw new Zend_Cloud_DocumentService_Exception('Field keys must conform to XML names (^[_A-Za-z][-._A-Za-z0-9]*$); key "' . $key . '" does not match');
626
+ }
627
+ }
628
+ }
lib/Zend/Cloud/DocumentService/Adapter/WindowsAzure/Query.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage DocumentService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ /*
21
+ * @see Zend_Cloud_DocumentService_QueryAdapter
22
+ */
23
+ #require_once 'Zend/Cloud/DocumentService/QueryAdapter.php';
24
+
25
+ /**
26
+ * Class implementing Query adapter for working with Azure queries in a
27
+ * structured way
28
+ *
29
+ * @todo Look into preventing a query injection attack.
30
+ * @category Zend
31
+ * @package Zend_Cloud
32
+ * @subpackage DocumentService
33
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
+ * @license http://framework.zend.com/license/new-bsd New BSD License
35
+ */
36
+ class Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
37
+ implements Zend_Cloud_DocumentService_QueryAdapter
38
+ {
39
+ /**
40
+ * Azure concrete query
41
+ *
42
+ * @var Zend_Service_WindowsAzure_Storage_TableEntityQuery
43
+ */
44
+ protected $_azureSelect;
45
+
46
+ /**
47
+ * Constructor
48
+ *
49
+ * @param null|Zend_Service_WindowsAzure_Storage_TableEntityQuery $select Table select object
50
+ * @return void
51
+ */
52
+ public function __construct($select = null)
53
+ {
54
+ if (!$select instanceof Zend_Service_WindowsAzure_Storage_TableEntityQuery) {
55
+ #require_once 'Zend/Service/WindowsAzure/Storage/TableEntityQuery.php';
56
+ $select = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
57
+ }
58
+ $this->_azureSelect = $select;
59
+ }
60
+
61
+ /**
62
+ * SELECT clause (fields to be selected)
63
+ *
64
+ * Does nothing for Azure.
65
+ *
66
+ * @param string $select
67
+ * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
68
+ */
69
+ public function select($select)
70
+ {
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * FROM clause (table name)
76
+ *
77
+ * @param string $from
78
+ * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
79
+ */
80
+ public function from($from)
81
+ {
82
+ $this->_azureSelect->from($from);
83
+ return $this;
84
+ }
85
+
86
+ /**
87
+ * WHERE clause (conditions to be used)
88
+ *
89
+ * @param string $where
90
+ * @param mixed $value Value or array of values to be inserted instead of ?
91
+ * @param string $op Operation to use to join where clauses (AND/OR)
92
+ * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
93
+ */
94
+ public function where($where, $value = null, $op = 'and')
95
+ {
96
+ if (!empty($value) && !is_array($value)) {
97
+ // fix buglet in Azure - numeric values are quoted unless passed as an array
98
+ $value = array($value);
99
+ }
100
+ $this->_azureSelect->where($where, $value, $op);
101
+ return $this;
102
+ }
103
+
104
+ /**
105
+ * WHERE clause for item ID
106
+ *
107
+ * This one should be used when fetching specific rows since some adapters
108
+ * have special syntax for primary keys
109
+ *
110
+ * @param array $value Row ID for the document (PartitionKey, RowKey)
111
+ * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
112
+ */
113
+ public function whereId($value)
114
+ {
115
+ if (!is_array($value)) {
116
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
117
+ throw new Zend_Cloud_DocumentService_Exception('Invalid document key');
118
+ }
119
+ $this->_azureSelect->wherePartitionKey($value[0])->whereRowKey($value[1]);
120
+ return $this;
121
+ }
122
+
123
+ /**
124
+ * LIMIT clause (how many rows to return)
125
+ *
126
+ * @param int $limit
127
+ * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
128
+ */
129
+ public function limit($limit)
130
+ {
131
+ $this->_azureSelect->top($limit);
132
+ return $this;
133
+ }
134
+
135
+ /**
136
+ * ORDER BY clause (sorting)
137
+ *
138
+ * @todo Azure service doesn't seem to support this yet; emulate?
139
+ * @param string $sort Column to sort by
140
+ * @param string $direction Direction - asc/desc
141
+ * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
142
+ * @throws Zend_Cloud_OperationNotAvailableException
143
+ */
144
+ public function order($sort, $direction = 'asc')
145
+ {
146
+ #require_once 'Zend/Cloud/OperationNotAvailableException.php';
147
+ throw new Zend_Cloud_OperationNotAvailableException('No support for sorting for Azure yet');
148
+ }
149
+
150
+ /**
151
+ * Get Azure select query
152
+ *
153
+ * @return Zend_Service_WindowsAzure_Storage_TableEntityQuery
154
+ */
155
+ public function getAzureSelect()
156
+ {
157
+ return $this->_azureSelect;
158
+ }
159
+
160
+ /**
161
+ * Assemble query
162
+ *
163
+ * Simply return the WindowsAzure table entity query object
164
+ *
165
+ * @return Zend_Service_WindowsAzure_Storage_TableEntityQuery
166
+ */
167
+ public function assemble()
168
+ {
169
+ return $this->getAzureSelect();
170
+ }
171
+ }
lib/Zend/Cloud/DocumentService/Document.php ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage DocumentService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ /**
21
+ * Class encapsulating documents. Fields are stored in a name/value
22
+ * array. Data are represented as strings.
23
+ *
24
+ * TODO Can fields be large enough to warrant support for streams?
25
+ *
26
+ * @category Zend
27
+ * @package Zend_Cloud
28
+ * @subpackage DocumentService
29
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30
+ * @license http://framework.zend.com/license/new-bsd New BSD License
31
+ */
32
+ class Zend_Cloud_DocumentService_Document
33
+ implements ArrayAccess, IteratorAggregate, Countable
34
+ {
35
+ /** key in document denoting identifier */
36
+ const KEY_FIELD = '_id';
37
+
38
+ /**
39
+ * ID of this document.
40
+ * @var mixed
41
+ */
42
+ protected $_id;
43
+
44
+ /**
45
+ * Name/value array of field names to values.
46
+ * @var array
47
+ */
48
+ protected $_fields;
49
+
50
+ /**
51
+ * Construct an instance of Zend_Cloud_DocumentService_Document.
52
+ *
53
+ * If no identifier is provided, but a field matching KEY_FIELD is present,
54
+ * then that field's value will be used as the document identifier.
55
+ *
56
+ * @param array $fields
57
+ * @param mixed $id Document identifier
58
+ * @return void
59
+ */
60
+ public function __construct($fields, $id = null)
61
+ {
62
+ if (!is_array($fields) && !$fields instanceof ArrayAccess) {
63
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
64
+ throw new Zend_Cloud_DocumentService_Exception('Fields must be an array or implement ArrayAccess');
65
+ }
66
+
67
+ if (isset($fields[self::KEY_FIELD])) {
68
+ $id = $fields[self::KEY_FIELD];
69
+ unset($fields[self::KEY_FIELD]);
70
+ }
71
+
72
+ $this->_fields = $fields;
73
+ $this->setId($id);
74
+ }
75
+
76
+ /**
77
+ * Set document identifier
78
+ *
79
+ * @param mixed $id
80
+ * @return Zend_Cloud_DocumentService_Document
81
+ */
82
+ public function setId($id)
83
+ {
84
+ $this->_id = $id;
85
+ return $this;
86
+ }
87
+
88
+ /**
89
+ * Get ID name.
90
+ *
91
+ * @return string
92
+ */
93
+ public function getId()
94
+ {
95
+ return $this->_id;
96
+ }
97
+
98
+ /**
99
+ * Get fields as array.
100
+ *
101
+ * @return array
102
+ */
103
+ public function getFields()
104
+ {
105
+ return $this->_fields;
106
+ }
107
+
108
+ /**
109
+ * Get field by name.
110
+ *
111
+ * @param string $name
112
+ * @return mixed
113
+ */
114
+ public function getField($name)
115
+ {
116
+ if (isset($this->_fields[$name])) {
117
+ return $this->_fields[$name];
118
+ }
119
+ return null;
120
+ }
121
+
122
+ /**
123
+ * Set field by name.
124
+ *
125
+ * @param string $name
126
+ * @param mixed $value
127
+ * @return Zend_Cloud_DocumentService_Document
128
+ */
129
+ public function setField($name, $value)
130
+ {
131
+ $this->_fields[$name] = $value;
132
+ return $this;
133
+ }
134
+
135
+ /**
136
+ * Overloading: get value
137
+ *
138
+ * @param string $name
139
+ * @return mixed
140
+ */
141
+ public function __get($name)
142
+ {
143
+ return $this->getField($name);
144
+ }
145
+
146
+ /**
147
+ * Overloading: set field
148
+ *
149
+ * @param string $name
150
+ * @param mixed $value
151
+ * @return void
152
+ */
153
+ public function __set($name, $value)
154
+ {
155
+ $this->setField($name, $value);
156
+ }
157
+
158
+ /**
159
+ * ArrayAccess: does field exist?
160
+ *
161
+ * @param string $name
162
+ * @return bool
163
+ */
164
+ public function offsetExists($name)
165
+ {
166
+ return isset($this->_fields[$name]);
167
+ }
168
+
169
+ /**
170
+ * ArrayAccess: get field by name
171
+ *
172
+ * @param string $name
173
+ * @return mixed
174
+ */
175
+ public function offsetGet($name)
176
+ {
177
+ return $this->getField($name);
178
+ }
179
+
180
+ /**
181
+ * ArrayAccess: set field to value
182
+ *
183
+ * @param string $name
184
+ * @param mixed $value
185
+ * @return void
186
+ */
187
+ public function offsetSet($name, $value)
188
+ {
189
+ $this->setField($name, $value);
190
+ }
191
+
192
+ /**
193
+ * ArrayAccess: remove field from document
194
+ *
195
+ * @param string $name
196
+ * @return void
197
+ */
198
+ public function offsetUnset($name)
199
+ {
200
+ if ($this->offsetExists($name)) {
201
+ unset($this->_fields[$name]);
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Overloading: retrieve and set fields by name
207
+ *
208
+ * @param string $name
209
+ * @param mixed $args
210
+ * @return mixed
211
+ */
212
+ public function __call($name, $args)
213
+ {
214
+ $prefix = substr($name, 0, 3);
215
+ if ($prefix == 'get') {
216
+ // Get value
217
+ $option = substr($name, 3);
218
+ return $this->getField($option);
219
+ } elseif ($prefix == 'set') {
220
+ // set value
221
+ $option = substr($name, 3);
222
+ return $this->setField($option, $args[0]);
223
+ }
224
+
225
+ #require_once 'Zend/Cloud/OperationNotAvailableException.php';
226
+ throw new Zend_Cloud_OperationNotAvailableException("Unknown operation $name");
227
+ }
228
+
229
+ /**
230
+ * Countable: return count of fields in document
231
+ *
232
+ * @return int
233
+ */
234
+ public function count()
235
+ {
236
+ return count($this->_fields);
237
+ }
238
+
239
+ /**
240
+ * IteratorAggregate: return iterator for iterating over fields
241
+ *
242
+ * @return Iterator
243
+ */
244
+ public function getIterator()
245
+ {
246
+ return new ArrayIterator($this->_fields);
247
+ }
248
+ }
lib/Zend/Cloud/DocumentService/DocumentSet.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage DocumentService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ /**
21
+ * Class encapsulating a set of documents
22
+ *
23
+ * @category Zend
24
+ * @package Zend_Cloud
25
+ * @subpackage DocumentService
26
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
+ * @license http://framework.zend.com/license/new-bsd New BSD License
28
+ */
29
+ class Zend_Cloud_DocumentService_DocumentSet implements Countable, IteratorAggregate
30
+ {
31
+ /** @var int */
32
+ protected $_documentCount;
33
+
34
+ /** @var ArrayIterator */
35
+ protected $_documents;
36
+
37
+ /**
38
+ * Constructor
39
+ *
40
+ * @param array $documents
41
+ * @return void
42
+ */
43
+ public function __construct(array $documents)
44
+ {
45
+ $this->_documentCount = count($documents);
46
+ $this->_documents = new ArrayIterator($documents);
47
+ }
48
+
49
+ /**
50
+ * Countable: number of documents in set
51
+ *
52
+ * @return int
53
+ */
54
+ public function count()
55
+ {
56
+ return $this->_documentCount;
57
+ }
58
+
59
+ /**
60
+ * IteratorAggregate: retrieve iterator
61
+ *
62
+ * @return Traversable
63
+ */
64
+ public function getIterator()
65
+ {
66
+ return $this->_documents;
67
+ }
68
+ }
lib/Zend/Cloud/DocumentService/Exception.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Cloud
17
+ * @subpackage DocumentService
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+
23
+ /**
24
+ * Zend_Cloud_Exception
25
+ */
26
+ #require_once 'Zend/Cloud/Exception.php';
27
+
28
+
29
+ /**
30
+ * @category Zend
31
+ * @package Zend_Cloud
32
+ * @subpackage DocumentService
33
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
+ * @license http://framework.zend.com/license/new-bsd New BSD License
35
+ */
36
+ class Zend_Cloud_DocumentService_Exception extends Zend_Cloud_Exception
37
+ {}
38
+
lib/Zend/Cloud/DocumentService/Factory.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Cloud
17
+ * @subpackage DocumentService
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Cloud/AbstractFactory.php';
23
+
24
+ /**
25
+ * Class implementing working with Azure queries in a structured way
26
+ *
27
+ * TODO Look into preventing a query injection attack.
28
+ *
29
+ * @category Zend
30
+ * @package Zend_Cloud
31
+ * @subpackage DocumentService
32
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33
+ * @license http://framework.zend.com/license/new-bsd New BSD License
34
+ */
35
+ class Zend_Cloud_DocumentService_Factory extends Zend_Cloud_AbstractFactory
36
+ {
37
+ const DOCUMENT_ADAPTER_KEY = 'document_adapter';
38
+
39
+ /**
40
+ * @var string Interface which adapter must implement to be considered valid
41
+ */
42
+ protected static $_adapterInterface = 'Zend_Cloud_DocumentService_Adapter';
43
+
44
+ /**
45
+ * Constructor
46
+ *
47
+ * @return void
48
+ */
49
+ private function __construct()
50
+ {
51
+ // private ctor - should not be used
52
+ }
53
+
54
+ /**
55
+ * Retrieve an adapter instance
56
+ *
57
+ * @param array $options
58
+ * @return void
59
+ */
60
+ public static function getAdapter($options = array())
61
+ {
62
+ $adapter = parent::_getAdapter(self::DOCUMENT_ADAPTER_KEY, $options);
63
+ if (!$adapter) {
64
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
65
+ throw new Zend_Cloud_DocumentService_Exception(
66
+ 'Class must be specified using the \''
67
+ . self::DOCUMENT_ADAPTER_KEY . '\' key'
68
+ );
69
+ } elseif (!$adapter instanceof self::$_adapterInterface) {
70
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
71
+ throw new Zend_Cloud_DocumentService_Exception(
72
+ 'Adapter must implement \'' . self::$_adapterInterface . '\''
73
+ );
74
+ }
75
+ return $adapter;
76
+ }
77
+ }
lib/Zend/Cloud/DocumentService/Query.php ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage DocumentService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Cloud/DocumentService/QueryAdapter.php';
21
+
22
+ /**
23
+ * Generic query object
24
+ *
25
+ * Aggregates operations in an array of clauses, where the first element
26
+ * describes the clause type, and the next element describes the criteria.
27
+ *
28
+ * @category Zend
29
+ * @package Zend_Cloud
30
+ * @subpackage DocumentService
31
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
+ * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ */
34
+ class Zend_Cloud_DocumentService_Query
35
+ implements Zend_Cloud_DocumentService_QueryAdapter
36
+ {
37
+ /**
38
+ * Known query types
39
+ */
40
+ const QUERY_SELECT = 'select';
41
+ const QUERY_FROM = 'from';
42
+ const QUERY_WHERE = 'where';
43
+ const QUERY_WHEREID = 'whereid'; // request element by ID
44
+ const QUERY_LIMIT = 'limit';
45
+ const QUERY_ORDER = 'order';
46
+
47
+ /**
48
+ * Clause list
49
+ *
50
+ * @var array
51
+ */
52
+ protected $_clauses = array();
53
+
54
+ /**
55
+ * Generic clause
56
+ *
57
+ * You can use any clause by doing $query->foo('bar')
58
+ * but concrete adapters should be able to recognise it
59
+ *
60
+ * The call will be iterpreted as clause 'foo' with argument 'bar'
61
+ *
62
+ * @param string $name Clause/method name
63
+ * @param mixed $args
64
+ * @return Zend_Cloud_DocumentService_Query
65
+ */
66
+ public function __call($name, $args)
67
+ {
68
+ $this->_clauses[] = array(strtolower($name), $args);
69
+ return $this;
70
+ }
71
+
72
+ /**
73
+ * SELECT clause (fields to be selected)
74
+ *
75
+ * @param null|string|array $select
76
+ * @return Zend_Cloud_DocumentService_Query
77
+ */
78
+ public function select($select)
79
+ {
80
+ if (empty($select)) {
81
+ return $this;
82
+ }
83
+ if (!is_string($select) && !is_array($select)) {
84
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
85
+ throw new Zend_Cloud_DocumentService_Exception("SELECT argument must be a string or an array of strings");
86
+ }
87
+ $this->_clauses[] = array(self::QUERY_SELECT, $select);
88
+ return $this;
89
+ }
90
+
91
+ /**
92
+ * FROM clause
93
+ *
94
+ * @param string $name Field names
95
+ * @return Zend_Cloud_DocumentService_Query
96
+ */
97
+ public function from($name)
98
+ {
99
+ if(!is_string($name)) {
100
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
101
+ throw new Zend_Cloud_DocumentService_Exception("FROM argument must be a string");
102
+ }
103
+ $this->_clauses[] = array(self::QUERY_FROM, $name);
104
+ return $this;
105
+ }
106
+
107
+ /**
108
+ * WHERE query
109
+ *
110
+ * @param string $cond Condition
111
+ * @param array $args Arguments to substitute instead of ?'s in condition
112
+ * @param string $op relation to other clauses - and/or
113
+ * @return Zend_Cloud_DocumentService_Query
114
+ */
115
+ public function where($cond, $value = null, $op = 'and')
116
+ {
117
+ if (!is_string($cond)) {
118
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
119
+ throw new Zend_Cloud_DocumentService_Exception("WHERE argument must be a string");
120
+ }
121
+ $this->_clauses[] = array(self::QUERY_WHERE, array($cond, $value, $op));
122
+ return $this;
123
+ }
124
+
125
+ /**
126
+ * Select record or fields by ID
127
+ *
128
+ * @param string|int $value Identifier to select by
129
+ * @return Zend_Cloud_DocumentService_Query
130
+ */
131
+ public function whereId($value)
132
+ {
133
+ if (!is_scalar($value)) {
134
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
135
+ throw new Zend_Cloud_DocumentService_Exception("WHEREID argument must be a scalar");
136
+ }
137
+ $this->_clauses[] = array(self::QUERY_WHEREID, $value);
138
+ return $this;
139
+ }
140
+
141
+ /**
142
+ * LIMIT clause (how many items to return)
143
+ *
144
+ * @param int $limit
145
+ * @return Zend_Cloud_DocumentService_Query
146
+ */
147
+ public function limit($limit)
148
+ {
149
+ if ($limit != (int) $limit) {
150
+ #require_once 'Zend/Cloud/DocumentService/Exception.php';
151
+ throw new Zend_Cloud_DocumentService_Exception("LIMIT argument must be an integer");
152
+ }
153
+ $this->_clauses[] = array(self::QUERY_LIMIT, $limit);
154
+ return $this;
155
+ }
156
+
157
+ /**
158
+ * ORDER clause; field or fields to sort by, and direction to sort
159
+ *
160
+ * @param string|int|array $sort
161
+ * @param string $direction
162
+ * @return Zend_Cloud_DocumentService_Query
163
+ */
164
+ public function order($sort, $direction = 'asc')
165
+ {
166
+ $this->_clauses[] = array(self::QUERY_ORDER, array($sort, $direction));
167
+ return $this;
168
+ }
169
+
170
+ /**
171
+ * "Assemble" the query
172
+ *
173
+ * Simply returns the clauses present.
174
+ *
175
+ * @return array
176
+ */
177
+ public function assemble()
178
+ {
179
+ return $this->getClauses();
180
+ }
181
+
182
+ /**
183
+ * Return query clauses as an array
184
+ *
185
+ * @return array Clauses in the query
186
+ */
187
+ public function getClauses()
188
+ {
189
+ return $this->_clauses;
190
+ }
191
+ }
lib/Zend/Cloud/DocumentService/QueryAdapter.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage DocumentService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ /**
21
+ * This interface describes the API that concrete query adapter should implement
22
+ *
23
+ * Common interface for document storage services in the cloud. This interface
24
+ * supports most document services and provides some flexibility for
25
+ * vendor-specific features and requirements via an optional $options array in
26
+ * each method signature. Classes implementing this interface should implement
27
+ * URI construction for collections and documents from the parameters given in each
28
+ * method and the account data passed in to the constructor. Classes
29
+ * implementing this interface are also responsible for security; access control
30
+ * isn't currently supported in this interface, although we are considering
31
+ * access control support in future versions of the interface. Query
32
+ * optimization mechanisms are also not supported in this version.
33
+ *
34
+ * @category Zend
35
+ * @package Zend_Cloud
36
+ * @subpackage DocumentService
37
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
38
+ * @license http://framework.zend.com/license/new-bsd New BSD License
39
+ */
40
+ interface Zend_Cloud_DocumentService_QueryAdapter
41
+ {
42
+ /**
43
+ * SELECT clause (fields to be selected)
44
+ *
45
+ * @param string $select
46
+ * @return Zend_Cloud_DocumentService_QueryAdapter
47
+ */
48
+ public function select($select);
49
+
50
+ /**
51
+ * FROM clause (table name)
52
+ *
53
+ * @param string $from
54
+ * @return Zend_Cloud_DocumentService_QueryAdapter
55
+ */
56
+ public function from($from);
57
+
58
+ /**
59
+ * WHERE clause (conditions to be used)
60
+ *
61
+ * @param string $where
62
+ * @param mixed $value Value or array of values to be inserted instead of ?
63
+ * @param string $op Operation to use to join where clauses (AND/OR)
64
+ * @return Zend_Cloud_DocumentService_QueryAdapter
65
+ */
66
+ public function where($where, $value = null, $op = 'and');
67
+
68
+ /**
69
+ * WHERE clause for item ID
70
+ *
71
+ * This one should be used when fetching specific rows since some adapters
72
+ * have special syntax for primary keys
73
+ *
74
+ * @param mixed $value Row ID for the document
75
+ * @return Zend_Cloud_DocumentService_QueryAdapter
76
+ */
77
+ public function whereId($value);
78
+
79
+ /**
80
+ * LIMIT clause (how many rows ot return)
81
+ *
82
+ * @param int $limit
83
+ * @return Zend_Cloud_DocumentService_QueryAdapter
84
+ */
85
+ public function limit($limit);
86
+
87
+ /**
88
+ * ORDER BY clause (sorting)
89
+ *
90
+ * @param string $sort Column to sort by
91
+ * @param string $direction Direction - asc/desc
92
+ * @return Zend_Cloud_DocumentService_QueryAdapter
93
+ */
94
+ public function order($sort, $direction = 'asc');
95
+
96
+ /**
97
+ * Assemble the query into a format the adapter can utilize
98
+ *
99
+ * @return mixed
100
+ */
101
+ public function assemble();
102
+ }
lib/Zend/Cloud/Exception.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Cloud
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ */
20
+
21
+
22
+ /**
23
+ * Zend_Exception
24
+ */
25
+ #require_once 'Zend/Exception.php';
26
+
27
+
28
+ /**
29
+ * @category Zend
30
+ * @package Zend_Cloud
31
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
+ * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ */
34
+ class Zend_Cloud_Exception extends Zend_Exception
35
+ {
36
+ /**
37
+ * Exception for the underlying adapter
38
+ *
39
+ * @var Exception
40
+ */
41
+ protected $_clientException;
42
+
43
+ public function __construct($message, $code = 0, $clientException = null)
44
+ {
45
+ $this->_clientException = $clientException;
46
+ parent::__construct($message, $code, $clientException);
47
+ }
48
+
49
+ public function getClientException() {
50
+ return $this->_getPrevious();
51
+ }
52
+ }
53
+
lib/Zend/Cloud/OperationNotAvailableException.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Cloud
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ */
20
+
21
+ /**
22
+ * Zend_Exception
23
+ */
24
+ #require_once 'Zend/Exception.php';
25
+
26
+ /**
27
+ * @category Zend
28
+ * @package Zend_Cloud
29
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30
+ * @license http://framework.zend.com/license/new-bsd New BSD License
31
+ */
32
+ class Zend_Cloud_OperationNotAvailableException extends Zend_Exception
33
+ {}
34
+
lib/Zend/Cloud/QueueService/Adapter.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage QueueService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ /**
21
+ * Common interface for queue services in the cloud. This interface supports
22
+ * most queue services and provides some flexibility for vendor-specific
23
+ * features and requirements via an optional $options array in each method
24
+ * signature. Classes implementing this interface should implement URI
25
+ * construction for queues from the parameters given in each method and the
26
+ * account data passed in to the constructor. Classes implementing this
27
+ * interface are also responsible for security; access control isn't currently
28
+ * supported in this interface, although we are considering access control
29
+ * support in future versions of the interface.
30
+ *
31
+ * @category Zend
32
+ * @package Zend_Cloud
33
+ * @subpackage QueueService
34
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
35
+ * @license http://framework.zend.com/license/new-bsd New BSD License
36
+ */
37
+ interface Zend_Cloud_QueueService_Adapter
38
+ {
39
+ /** Ctor HTTP adapter option */
40
+ const HTTP_ADAPTER = 'http_adapter';
41
+
42
+ /** Message visibility timeout option */
43
+ const VISIBILITY_TIMEOUT = 'visibility_timeout';
44
+
45
+ /** Default visibility timeout */
46
+ const DEFAULT_TIMEOUT = 30;
47
+
48
+ /**
49
+ * Create a queue. Returns the ID of the created queue (typically the URL).
50
+ * It may take some time to create the queue. Check your vendor's
51
+ * documentation for details.
52
+ *
53
+ * Name constraints: Maximum 80 characters
54
+ * Only alphanumeric characters, hyphens (-), and underscores (_)
55
+ *
56
+ * @param string $name
57
+ * @param array $options
58
+ * @return string Queue ID (typically URL)
59
+ */
60
+ public function createQueue($name, $options = null);
61
+
62
+ /**
63
+ * Delete a queue. All messages in the queue will also be deleted.
64
+ *
65
+ * @param string $queueId
66
+ * @param array $options
67
+ * @return boolean true if successful, false otherwise
68
+ */
69
+ public function deleteQueue($queueId, $options = null);
70
+
71
+ /**
72
+ * List all queues.
73
+ *
74
+ * @param array $options
75
+ * @return array Queue IDs
76
+ */
77
+ public function listQueues($options = null);
78
+
79
+ /**
80
+ * Get a key/value array of metadata for the given queue.
81
+ *
82
+ * @param string $queueId
83
+ * @param array $options
84
+ * @return array
85
+ */
86
+ public function fetchQueueMetadata($queueId, $options = null);
87
+
88
+ /**
89
+ * Store a key/value array of metadata for the specified queue.
90
+ * WARNING: This operation overwrites any metadata that is located at
91
+ * $destinationPath. Some adapters may not support this method.
92
+ *
93
+ * @param string $queueId
94
+ * @param array $metadata
95
+ * @param array $options
96
+ * @return void
97
+ */
98
+ public function storeQueueMetadata($queueId, $metadata, $options = null);
99
+
100
+ /**
101
+ * Send a message to the specified queue.
102
+ *
103
+ * @param string $queueId
104
+ * @param string $message
105
+ * @param array $options
106
+ * @return string Message ID
107
+ */
108
+ public function sendMessage($queueId, $message, $options = null);
109
+
110
+ /**
111
+ * Recieve at most $max messages from the specified queue and return the
112
+ * message IDs for messages recieved.
113
+ *
114
+ * @param string $queueId
115
+ * @param int $max
116
+ * @param array $options
117
+ * @return array[Zend_Cloud_QueueService_Message] Array of messages
118
+ */
119
+ public function receiveMessages($queueId, $max = 1, $options = null);
120
+
121
+ /**
122
+ * Peek at the messages from the specified queue without removing them.
123
+ *
124
+ * @param string $queueId
125
+ * @param int $num How many messages
126
+ * @param array $options
127
+ * @return array[Zend_Cloud_QueueService_Message]
128
+ */
129
+ public function peekMessages($queueId, $num = 1, $options = null);
130
+
131
+ /**
132
+ * Delete the specified message from the specified queue.
133
+ *
134
+ * @param string $queueId
135
+ * @param Zend_Cloud_QueueService_Message $message Message to delete
136
+ * @param array $options
137
+ * @return void
138
+ *
139
+ */
140
+ public function deleteMessage($queueId, $message, $options = null);
141
+
142
+ /**
143
+ * Get the concrete adapter.
144
+ */
145
+ public function getClient();
146
+ }
lib/Zend/Cloud/QueueService/Adapter/AbstractAdapter.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage QueueService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Cloud/QueueService/Adapter.php';
21
+ #require_once 'Zend/Cloud/QueueService/Message.php';
22
+ #require_once 'Zend/Cloud/QueueService/MessageSet.php';
23
+
24
+ /**
25
+ * Abstract queue adapter
26
+ *
27
+ * Provides functionality around setting message and message set classes.
28
+ *
29
+ * @category Zend
30
+ * @package Zend_Cloud
31
+ * @subpackage QueueService
32
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33
+ * @license http://framework.zend.com/license/new-bsd New BSD License
34
+ */
35
+ abstract class Zend_Cloud_QueueService_Adapter_AbstractAdapter
36
+ implements Zend_Cloud_QueueService_Adapter
37
+ {
38
+ /**@+ option keys */
39
+ const MESSAGE_CLASS = 'message_class';
40
+ const MESSAGESET_CLASS = 'messageset_class';
41
+ /**@-*/
42
+
43
+ /** @var string Class to use for queue messages */
44
+ protected $_messageClass = 'Zend_Cloud_QueueService_Message';
45
+
46
+ /** @var string Class to use for collections of queue messages */
47
+ protected $_messageSetClass = 'Zend_Cloud_QueueService_MessageSet';
48
+
49
+ /**
50
+ * Set class to use for message objects
51
+ *
52
+ * @param string $class
53
+ * @return Zend_Cloud_QueueService_Adapter_AbstractAdapter
54
+ */
55
+ public function setMessageClass($class)
56
+ {
57
+ $this->_messageClass = (string) $class;
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * Get class to use for message objects
63
+ *
64
+ * @return string
65
+ */
66
+ public function getMessageClass()
67
+ {
68
+ return $this->_messageClass;
69
+ }
70
+
71
+ /**
72
+ * Set class to use for message collection objects
73
+ *
74
+ * @param string $class
75
+ * @return Zend_Cloud_QueueService_Adapter_AbstractAdapter
76
+ */
77
+ public function setMessageSetClass($class)
78
+ {
79
+ $this->_messageSetClass = (string) $class;
80
+ return $this;
81
+ }
82
+
83
+ /**
84
+ * Get class to use for message collection objects
85
+ *
86
+ * @return string
87
+ */
88
+ public function getMessageSetClass()
89
+ {
90
+ return $this->_messageSetClass;
91
+ }
92
+ }
lib/Zend/Cloud/QueueService/Adapter/Sqs.php ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage QueueService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Service/Amazon/Sqs.php';
21
+ #require_once 'Zend/Cloud/QueueService/Adapter/AbstractAdapter.php';
22
+ #require_once 'Zend/Cloud/QueueService/Exception.php';
23
+ #require_once 'Zend/Cloud/QueueService/Message.php';
24
+
25
+ /**
26
+ * SQS adapter for simple queue service.
27
+ *
28
+ * @category Zend
29
+ * @package Zend_Cloud
30
+ * @subpackage QueueService
31
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
+ * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ */
34
+ class Zend_Cloud_QueueService_Adapter_Sqs
35
+ extends Zend_Cloud_QueueService_Adapter_AbstractAdapter
36
+ {
37
+ /*
38
+ * Options array keys for the SQS adapter.
39
+ */
40
+ const AWS_ACCESS_KEY = 'aws_accesskey';
41
+ const AWS_SECRET_KEY = 'aws_secretkey';
42
+
43
+ /**
44
+ * Defaults
45
+ */
46
+ const CREATE_TIMEOUT = 30;
47
+
48
+ /**
49
+ * SQS service instance.
50
+ * @var Zend_Service_Amazon_Sqs
51
+ */
52
+ protected $_sqs;
53
+
54
+ /**
55
+ * Constructor
56
+ *
57
+ * @param array|Zend_Config $options
58
+ * @return void
59
+ */
60
+ public function __construct($options = array())
61
+ {
62
+ if ($options instanceof Zend_Config) {
63
+ $options = $options->toArray();
64
+ }
65
+
66
+ if (!is_array($options)) {
67
+ throw new Zend_Cloud_QueueService_Exception('Invalid options provided');
68
+ }
69
+
70
+ if (isset($options[self::MESSAGE_CLASS])) {
71
+ $this->setMessageClass($options[self::MESSAGE_CLASS]);
72
+ }
73
+
74
+ if (isset($options[self::MESSAGESET_CLASS])) {
75
+ $this->setMessageSetClass($options[self::MESSAGESET_CLASS]);
76
+ }
77
+
78
+ try {
79
+ $this->_sqs = new Zend_Service_Amazon_Sqs(
80
+ $options[self::AWS_ACCESS_KEY], $options[self::AWS_SECRET_KEY]
81
+ );
82
+ } catch(Zend_Service_Amazon_Exception $e) {
83
+ throw new Zend_Cloud_QueueService_Exception('Error on create: '.$e->getMessage(), $e->getCode(), $e);
84
+ }
85
+
86
+ if(isset($options[self::HTTP_ADAPTER])) {
87
+ $this->_sqs->getHttpClient()->setAdapter($options[self::HTTP_ADAPTER]);
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Create a queue. Returns the ID of the created queue (typically the URL).
93
+ * It may take some time to create the queue. Check your vendor's
94
+ * documentation for details.
95
+ *
96
+ * @param string $name
97
+ * @param array $options
98
+ * @return string Queue ID (typically URL)
99
+ */
100
+ public function createQueue($name, $options = null)
101
+ {
102
+ try {
103
+ return $this->_sqs->create($name, $options[self::CREATE_TIMEOUT]);
104
+ } catch(Zend_Service_Amazon_Exception $e) {
105
+ throw new Zend_Cloud_QueueService_Exception('Error on queue creation: '.$e->getMessage(), $e->getCode(), $e);
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Delete a queue. All messages in the queue will also be deleted.
111
+ *
112
+ * @param string $queueId
113
+ * @param array $options
114
+ * @return boolean true if successful, false otherwise
115
+ */
116
+ public function deleteQueue($queueId, $options = null)
117
+ {
118
+ try {
119
+ return $this->_sqs->delete($queueId);
120
+ } catch(Zend_Service_Amazon_Exception $e) {
121
+ throw Zend_Cloud_QueueService_Exception('Error on queue deletion: '.$e->getMessage(), $e->getCode(), $e);
122
+ }
123
+ }
124
+
125
+ /**
126
+ * List all queues.
127
+ *
128
+ * @param array $options
129
+ * @return array Queue IDs
130
+ */
131
+ public function listQueues($options = null)
132
+ {
133
+ try {
134
+ return $this->_sqs->getQueues();
135
+ } catch(Zend_Service_Amazon_Exception $e) {
136
+ throw new Zend_Cloud_QueueService_Exception('Error on listing queues: '.$e->getMessage(), $e->getCode(), $e);
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Get a key/value array of metadata for the given queue.
142
+ *
143
+ * @param string $queueId
144
+ * @param array $options
145
+ * @return array
146
+ */
147
+ public function fetchQueueMetadata($queueId, $options = null)
148
+ {
149
+ try {
150
+ // TODO: ZF-9050 Fix the SQS client library in trunk to return all attribute values
151
+ $attributes = $this->_sqs->getAttribute($queueId, 'All');
152
+ if(is_array($attributes)) {
153
+ return $attributes;
154
+ } else {
155
+ return array('All' => $this->_sqs->getAttribute($queueId, 'All'));
156
+ }
157
+ } catch(Zend_Service_Amazon_Exception $e) {
158
+ throw new Zend_Cloud_QueueService_Exception('Error on fetching queue metadata: '.$e->getMessage(), $e->getCode(), $e);
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Store a key/value array of metadata for the specified queue.
164
+ * WARNING: This operation overwrites any metadata that is located at
165
+ * $destinationPath. Some adapters may not support this method.
166
+ *
167
+ * @param array $metadata
168
+ * @param string $queueId
169
+ * @param array $options
170
+ * @return void
171
+ */
172
+ public function storeQueueMetadata($queueId, $metadata, $options = null)
173
+ {
174
+ // TODO Add support for SetQueueAttributes to client library
175
+ #require_once 'Zend/Cloud/OperationNotAvailableException.php';
176
+ throw new Zend_Cloud_OperationNotAvailableException('Amazon SQS doesn\'t currently support storing metadata');
177
+ }
178
+
179
+ /**
180
+ * Send a message to the specified queue.
181
+ *
182
+ * @param string $message
183
+ * @param string $queueId
184
+ * @param array $options
185
+ * @return string Message ID
186
+ */
187
+ public function sendMessage($queueId, $message, $options = null)
188
+ {
189
+ try {
190
+ return $this->_sqs->send($queueId, $message);
191
+ } catch(Zend_Service_Amazon_Exception $e) {
192
+ throw new Zend_Cloud_QueueService_Exception('Error on sending message: '.$e->getMessage(), $e->getCode(), $e);
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Recieve at most $max messages from the specified queue and return the
198
+ * message IDs for messages recieved.
199
+ *
200
+ * @param string $queueId
201
+ * @param int $max
202
+ * @param array $options
203
+ * @return array
204
+ */
205
+ public function receiveMessages($queueId, $max = 1, $options = null)
206
+ {
207
+ try {
208
+ return $this->_makeMessages($this->_sqs->receive($queueId, $max, $options[self::VISIBILITY_TIMEOUT]));
209
+ } catch(Zend_Service_Amazon_Exception $e) {
210
+ throw new Zend_Cloud_QueueService_Exception('Error on recieving messages: '.$e->getMessage(), $e->getCode(), $e);
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Create Zend_Cloud_QueueService_Message array for
216
+ * Sqs messages.
217
+ *
218
+ * @param array $messages
219
+ * @return Zend_Cloud_QueueService_Message[]
220
+ */
221
+ protected function _makeMessages($messages)
222
+ {
223
+ $messageClass = $this->getMessageClass();
224
+ $setClass = $this->getMessageSetClass();
225
+ $result = array();
226
+ foreach($messages as $message) {
227
+ $result[] = new $messageClass($message['body'], $message);
228
+ }
229
+ return new $setClass($result);
230
+ }
231
+
232
+ /**
233
+ * Delete the specified message from the specified queue.
234
+ *
235
+ * @param string $queueId
236
+ * @param Zend_Cloud_QueueService_Message $message
237
+ * @param array $options
238
+ * @return void
239
+ */
240
+ public function deleteMessage($queueId, $message, $options = null)
241
+ {
242
+ try {
243
+ if($message instanceof Zend_Cloud_QueueService_Message) {
244
+ $message = $message->getMessage();
245
+ }
246
+ $messageId = $message['handle'];
247
+ return $this->_sqs->deleteMessage($queueId, $messageId);
248
+ } catch(Zend_Service_Amazon_Exception $e) {
249
+ throw new Zend_Cloud_QueueService_Exception('Error on deleting a message: '.$e->getMessage(), $e->getCode(), $e);
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Peek at the messages from the specified queue without removing them.
255
+ *
256
+ * @param string $queueId
257
+ * @param int $num How many messages
258
+ * @param array $options
259
+ * @return Zend_Cloud_QueueService_Message[]
260
+ */
261
+ public function peekMessages($queueId, $num = 1, $options = null)
262
+ {
263
+ try {
264
+ return $this->_makeMessages($this->_sqs->receive($queueId, $num, 0));
265
+ } catch(Zend_Service_Amazon_Exception $e) {
266
+ throw new Zend_Cloud_QueueService_Exception('Error on peeking messages: '.$e->getMessage(), $e->getCode(), $e);
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Get SQS implementation
272
+ * @return Zend_Service_Amazon_Sqs
273
+ */
274
+ public function getClient()
275
+ {
276
+ return $this->_sqs;
277
+ }
278
+ }
lib/Zend/Cloud/QueueService/Adapter/WindowsAzure.php ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage QueueService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Cloud/QueueService/Adapter/AbstractAdapter.php';
21
+ #require_once 'Zend/Cloud/QueueService/Exception.php';
22
+ #require_once 'Zend/Service/WindowsAzure/Storage/Queue.php';
23
+
24
+ /**
25
+ * WindowsAzure adapter for simple queue service.
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Cloud
29
+ * @subpackage QueueService
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Cloud_QueueService_Adapter_WindowsAzure
34
+ extends Zend_Cloud_QueueService_Adapter_AbstractAdapter
35
+ {
36
+ /**
37
+ * Option array keys for the Windows Azure adapter.
38
+ */
39
+ const ACCOUNT_NAME = 'storage_accountname';
40
+ const ACCOUNT_KEY = 'storage_accountkey';
41
+ const HOST = "storage_host";
42
+ const PROXY_HOST = "storage_proxy_host";
43
+ const PROXY_PORT = "storage_proxy_port";
44
+ const PROXY_CREDENTIALS = "storage_proxy_credentials";
45
+
46
+ /** list options */
47
+ const LIST_PREFIX = 'prefix';
48
+ const LIST_MAX_RESULTS = 'max_results';
49
+
50
+ /** message options */
51
+ const MESSAGE_TTL = 'ttl';
52
+
53
+ const DEFAULT_HOST = Zend_Service_WindowsAzure_Storage::URL_CLOUD_QUEUE;
54
+
55
+ /**
56
+ * Storage client
57
+ *
58
+ * @var Zend_Service_WindowsAzure_Storage_Queue
59
+ */
60
+ protected $_storageClient = null;
61
+
62
+ /**
63
+ * Constructor
64
+ *
65
+ * @param array|Zend_Config $options
66
+ * @return void
67
+ */
68
+ public function __construct($options = array())
69
+ {
70
+ if ($options instanceof Zend_Config) {
71
+ $options = $options->toArray();
72
+ }
73
+
74
+ if (!is_array($options)) {
75
+ throw new Zend_Cloud_QueueService_Exception('Invalid options provided');
76
+ }
77
+
78
+ if (isset($options[self::MESSAGE_CLASS])) {
79
+ $this->setMessageClass($options[self::MESSAGE_CLASS]);
80
+ }
81
+
82
+ if (isset($options[self::MESSAGESET_CLASS])) {
83
+ $this->setMessageSetClass($options[self::MESSAGESET_CLASS]);
84
+ }
85
+
86
+ // Build Zend_Service_WindowsAzure_Storage_Blob instance
87
+ if (!isset($options[self::HOST])) {
88
+ $host = self::DEFAULT_HOST;
89
+ } else {
90
+ $host = $options[self::HOST];
91
+ }
92
+ if (! isset($options[self::ACCOUNT_NAME])) {
93
+ throw new Zend_Cloud_Storage_Exception('No Windows Azure account name provided.');
94
+ }
95
+ if (! isset($options[self::ACCOUNT_KEY])) {
96
+ throw new Zend_Cloud_Storage_Exception('No Windows Azure account key provided.');
97
+ }
98
+ try {
99
+ // TODO: support $usePathStyleUri and $retryPolicy
100
+ $this->_storageClient = new Zend_Service_WindowsAzure_Storage_Queue(
101
+ $host, $options[self::ACCOUNT_NAME], $options[self::ACCOUNT_KEY]);
102
+ // Parse other options
103
+ if (! empty($options[self::PROXY_HOST])) {
104
+ $proxyHost = $options[self::PROXY_HOST];
105
+ $proxyPort = isset($options[self::PROXY_PORT]) ? $options[self::PROXY_PORT] : 8080;
106
+ $proxyCredentials = isset($options[self::PROXY_CREDENTIALS]) ? $options[self::PROXY_CREDENTIALS] : '';
107
+ $this->_storageClient->setProxy(true, $proxyHost, $proxyPort, $proxyCredentials);
108
+ }
109
+ if (isset($options[self::HTTP_ADAPTER])) {
110
+ $this->_storageClient->setHttpClientChannel($httpAdapter);
111
+ }
112
+ } catch(Zend_Service_WindowsAzure_Exception $e) {
113
+ throw new Zend_Cloud_QueueService_Exception('Error on create: '.$e->getMessage(), $e->getCode(), $e);
114
+ }
115
+
116
+ }
117
+
118
+ /**
119
+ * Create a queue. Returns the ID of the created queue (typically the URL).
120
+ * It may take some time to create the queue. Check your vendor's
121
+ * documentation for details.
122
+ *
123
+ * @param string $name
124
+ * @param array $options
125
+ * @return string Queue ID (typically URL)
126
+ */
127
+ public function createQueue($name, $options = null)
128
+ {
129
+ try {
130
+ $queue = $this->_storageClient->createQueue($name, $options);
131
+ return $queue->Name;
132
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
133
+ throw new Zend_Cloud_QueueService_Exception('Error on queue creation: '.$e->getMessage(), $e->getCode(), $e);
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Delete a queue. All messages in the queue will also be deleted.
139
+ *
140
+ * @param string $queueId
141
+ * @param array $options
142
+ * @return boolean true if successful, false otherwise
143
+ */
144
+ public function deleteQueue($queueId, $options = null)
145
+ {
146
+ try {
147
+ if ($queueId instanceof Zend_Service_WindowsAzure_Storage_QueueInstance) {
148
+ $queueId = $queueId->Name;
149
+ }
150
+ return $this->_storageClient->deleteQueue($queueId);
151
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
152
+ throw new Zend_Cloud_QueueService_Exception('Error on queue deletion: '.$e->getMessage(), $e->getCode(), $e);
153
+ }
154
+ }
155
+
156
+ /**
157
+ * List all queues.
158
+ *
159
+ * @param array $options
160
+ * @return array Queue IDs
161
+ */
162
+ public function listQueues($options = null)
163
+ {
164
+ $prefix = $maxResults = null;
165
+ if (is_array($options)) {
166
+ isset($options[self::LIST_PREFIX]) ? $prefix = $options[self::LIST_PREFIX] : null;
167
+ isset($options[self::LIST_MAX_RESULTS]) ? $maxResults = $options[self::LIST_MAX_RESULTS] : null;
168
+ }
169
+ try {
170
+ $queues = $this->_storageClient->listQueues($prefix, $maxResults);
171
+ $result = array();
172
+ foreach ($queues as $queue) {
173
+ $result[] = $queue->Name;
174
+ }
175
+ return $result;
176
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
177
+ throw new Zend_Cloud_QueueService_Exception('Error on listing queues: '.$e->getMessage(), $e->getCode(), $e);
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Get a key/value array of metadata for the given queue.
183
+ *
184
+ * @param string $queueId
185
+ * @param array $options
186
+ * @return array
187
+ */
188
+ public function fetchQueueMetadata($queueId, $options = null)
189
+ {
190
+ try {
191
+ if ($queueId instanceof Zend_Service_WindowsAzure_Storage_QueueInstance) {
192
+ $queueId = $queueId->Name;
193
+ }
194
+ return $this->_storageClient->getQueueMetadata($queueId);
195
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
196
+ throw new Zend_Cloud_QueueService_Exception('Error on fetching queue metadata: '.$e->getMessage(), $e->getCode(), $e);
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Store a key/value array of metadata for the specified queue.
202
+ * WARNING: This operation overwrites any metadata that is located at
203
+ * $destinationPath. Some adapters may not support this method.
204
+ *
205
+ * @param string $queueId
206
+ * @param array $metadata
207
+ * @param array $options
208
+ * @return void
209
+ */
210
+ public function storeQueueMetadata($queueId, $metadata, $options = null)
211
+ {
212
+ try {
213
+ if ($queueId instanceof Zend_Service_WindowsAzure_Storage_QueueInstance) {
214
+ $queueId = $queueId->Name;
215
+ }
216
+ return $this->_storageClient->setQueueMetadata($queueId, $metadata);
217
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
218
+ throw new Zend_Cloud_QueueService_Exception('Error on setting queue metadata: '.$e->getMessage(), $e->getCode(), $e);
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Send a message to the specified queue.
224
+ *
225
+ * @param string $queueId
226
+ * @param string $message
227
+ * @param array $options
228
+ * @return string Message ID
229
+ */
230
+ public function sendMessage($queueId, $message, $options = null)
231
+ {
232
+ try {
233
+ if ($queueId instanceof Zend_Service_WindowsAzure_Storage_QueueInstance) {
234
+ $queueId = $queueId->Name;
235
+ }
236
+ return $this->_storageClient->putMessage(
237
+ $queueId, $message, $options[self::MESSAGE_TTL]
238
+ );
239
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
240
+ throw new Zend_Cloud_QueueService_Exception('Error on sending message: '.$e->getMessage(), $e->getCode(), $e);
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Recieve at most $max messages from the specified queue and return the
246
+ * message IDs for messages recieved.
247
+ *
248
+ * @param string $queueId
249
+ * @param int $max
250
+ * @param array $options
251
+ * @return Zend_Cloud_QueueService_Message[]
252
+ */
253
+ public function receiveMessages($queueId, $max = 1, $options = null)
254
+ {
255
+ try {
256
+ if ($queueId instanceof Zend_Service_WindowsAzure_Storage_QueueInstance) {
257
+ $queueId = $queueId->Name;
258
+ }
259
+ if (isset($options[self::VISIBILITY_TIMEOUT])) {
260
+ $visibility = $options[self::VISIBILITY_TIMEOUT];
261
+ } else {
262
+ $visibility = self::DEFAULT_TIMEOUT;
263
+ }
264
+ return $this->_makeMessages($this->_storageClient->getMessages($queueId, $max, $visibility, false));
265
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
266
+ throw new Zend_Cloud_QueueService_Exception('Error on recieving messages: '.$e->getMessage(), $e->getCode(), $e);
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Create Zend_Cloud_QueueService_Message array for
272
+ * Azure messages.
273
+ *
274
+ * @param array $messages
275
+ * @return Zend_Cloud_QueueService_Message[]
276
+ */
277
+ protected function _makeMessages($messages)
278
+ {
279
+ $messageClass = $this->getMessageClass();
280
+ $setClass = $this->getMessageSetClass();
281
+ $result = array();
282
+ foreach ($messages as $message) {
283
+ $result[] = new $messageClass($message->MessageText, $message);
284
+ }
285
+ return new $setClass($result);
286
+ }
287
+
288
+ /**
289
+ * Delete the specified message from the specified queue.
290
+ *
291
+ * @param string $queueId
292
+ * @param Zend_Cloud_QueueService_Message $message Message ID or message
293
+ * @param array $options
294
+ * @return void
295
+ */
296
+ public function deleteMessage($queueId, $message, $options = null)
297
+ {
298
+ try {
299
+ if ($queueId instanceof Zend_Service_WindowsAzure_Storage_QueueInstance) {
300
+ $queueId = $queueId->Name;
301
+ }
302
+ if ($message instanceof Zend_Cloud_QueueService_Message) {
303
+ $message = $message->getMessage();
304
+ }
305
+ if ($message instanceof Zend_Service_WindowsAzure_Storage_QueueMessage) {
306
+ return $this->_storageClient->deleteMessage($queueId, $message);
307
+ } else {
308
+ throw new Zend_Cloud_QueueService_Exception('Cannot delete the message: message object required');
309
+ }
310
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
311
+ throw new Zend_Cloud_QueueService_Exception('Error on deleting a message: '.$e->getMessage(), $e->getCode(), $e);
312
+ }
313
+ }
314
+
315
+ /**
316
+ * Peek at the messages from the specified queue without removing them.
317
+ *
318
+ * @param string $queueId
319
+ * @param int $num How many messages
320
+ * @param array $options
321
+ * @return Zend_Cloud_QueueService_Message[]
322
+ */
323
+ public function peekMessages($queueId, $num = 1, $options = null)
324
+ {
325
+ try {
326
+ if ($queueId instanceof Zend_Service_WindowsAzure_Storage_QueueInstance) {
327
+ $queueId = $queueId->Name;
328
+ }
329
+ return $this->_makeMessages($this->_storageClient->peekMessages($queueId, $num));
330
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
331
+ throw new Zend_Cloud_QueueService_Exception('Error on peeking messages: '.$e->getMessage(), $e->getCode(), $e);
332
+ }
333
+ }
334
+
335
+ /**
336
+ * Get Azure implementation
337
+ * @return Zend_Service_Azure_Storage_Queue
338
+ */
339
+ public function getClient()
340
+ {
341
+ return $this->_storageClient;
342
+ }
343
+ }
lib/Zend/Cloud/QueueService/Adapter/ZendQueue.php ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage QueueService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Cloud/QueueService/Adapter/AbstractAdapter.php';
21
+ #require_once 'Zend/Cloud/QueueService/Exception.php';
22
+ #require_once 'Zend/Queue.php';
23
+
24
+ /**
25
+ * WindowsAzure adapter for simple queue service.
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Cloud
29
+ * @subpackage QueueService
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Cloud_QueueService_Adapter_ZendQueue
34
+ extends Zend_Cloud_QueueService_Adapter_AbstractAdapter
35
+ {
36
+ /**
37
+ * Options array keys for the Zend_Queue adapter.
38
+ */
39
+ const ADAPTER = 'adapter';
40
+
41
+ /**
42
+ * Storage client
43
+ *
44
+ * @var Zend_Queue
45
+ */
46
+ protected $_queue = null;
47
+
48
+ /**
49
+ * @var array All queues
50
+ */
51
+ protected $_queues = array();
52
+
53
+ /**
54
+ * Constructor
55
+ *
56
+ * @param array|Zend_Config $options
57
+ * @return void
58
+ */
59
+ public function __construct ($options = array())
60
+ {
61
+ if ($options instanceof Zend_Config) {
62
+ $options = $options->toArray();
63
+ }
64
+
65
+ if (!is_array($options)) {
66
+ throw new Zend_Cloud_QueueService_Exception('Invalid options provided');
67
+ }
68
+
69
+ if (isset($options[self::MESSAGE_CLASS])) {
70
+ $this->setMessageClass($options[self::MESSAGE_CLASS]);
71
+ }
72
+
73
+ if (isset($options[self::MESSAGESET_CLASS])) {
74
+ $this->setMessageSetClass($options[self::MESSAGESET_CLASS]);
75
+ }
76
+
77
+ // Build Zend_Service_WindowsAzure_Storage_Blob instance
78
+ if (!isset($options[self::ADAPTER])) {
79
+ throw new Zend_Cloud_QueueService_Exception('No Zend_Queue adapter provided');
80
+ } else {
81
+ $adapter = $options[self::ADAPTER];
82
+ unset($options[self::ADAPTER]);
83
+ }
84
+ try {
85
+ $this->_queue = new Zend_Queue($adapter, $options);
86
+ } catch (Zend_Queue_Exception $e) {
87
+ throw new Zend_Cloud_QueueService_Exception('Error on create: '.$e->getMessage(), $e->getCode(), $e);
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Create a queue. Returns the ID of the created queue (typically the URL).
93
+ * It may take some time to create the queue. Check your vendor's
94
+ * documentation for details.
95
+ *
96
+ * @param string $name
97
+ * @param array $options
98
+ * @return string Queue ID (typically URL)
99
+ */
100
+ public function createQueue($name, $options = null)
101
+ {
102
+ try {
103
+ $this->_queues[$name] = $this->_queue->createQueue($name, isset($options[Zend_Queue::TIMEOUT])?$options[Zend_Queue::TIMEOUT]:null);
104
+ return $name;
105
+ } catch (Zend_Queue_Exception $e) {
106
+ throw new Zend_Cloud_QueueService_Exception('Error on queue creation: '.$e->getMessage(), $e->getCode(), $e);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Delete a queue. All messages in the queue will also be deleted.
112
+ *
113
+ * @param string $queueId
114
+ * @param array $options
115
+ * @return boolean true if successful, false otherwise
116
+ */
117
+ public function deleteQueue($queueId, $options = null)
118
+ {
119
+ if (!isset($this->_queues[$queueId])) {
120
+ return false;
121
+ }
122
+ try {
123
+ if ($this->_queues[$queueId]->deleteQueue()) {
124
+ unset($this->_queues[$queueId]);
125
+ return true;
126
+ }
127
+ } catch (Zend_Queue_Exception $e) {
128
+ throw new Zend_Cloud_QueueService_Exception('Error on queue deletion: '.$e->getMessage(), $e->getCode(), $e);
129
+ }
130
+ }
131
+
132
+ /**
133
+ * List all queues.
134
+ *
135
+ * @param array $options
136
+ * @return array Queue IDs
137
+ */
138
+ public function listQueues($options = null)
139
+ {
140
+ try {
141
+ return $this->_queue->getQueues();
142
+ } catch (Zend_Queue_Exception $e) {
143
+ throw new Zend_Cloud_QueueService_Exception('Error on listing queues: '.$e->getMessage(), $e->getCode(), $e);
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Get a key/value array of metadata for the given queue.
149
+ *
150
+ * @param string $queueId
151
+ * @param array $options
152
+ * @return array
153
+ */
154
+ public function fetchQueueMetadata($queueId, $options = null)
155
+ {
156
+ if (!isset($this->_queues[$queueId])) {
157
+ return false;
158
+ }
159
+ try {
160
+ return $this->_queues[$queueId]->getOptions();
161
+ } catch (Zend_Queue_Exception $e) {
162
+ throw new Zend_Cloud_QueueService_Exception('Error on fetching queue metadata: '.$e->getMessage(), $e->getCode(), $e);
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Store a key/value array of metadata for the specified queue.
168
+ * WARNING: This operation overwrites any metadata that is located at
169
+ * $destinationPath. Some adapters may not support this method.
170
+ *
171
+ * @param string $queueId
172
+ * @param array $metadata
173
+ * @param array $options
174
+ * @return void
175
+ */
176
+ public function storeQueueMetadata($queueId, $metadata, $options = null)
177
+ {
178
+ if (!isset($this->_queues[$queueId])) {
179
+ throw new Zend_Cloud_QueueService_Exception("No such queue: $queueId");
180
+ }
181
+ try {
182
+ return $this->_queues[$queueId]->setOptions($metadata);
183
+ } catch (Zend_Queue_Exception $e) {
184
+ throw new Zend_Cloud_QueueService_Exception('Error on setting queue metadata: '.$e->getMessage(), $e->getCode(), $e);
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Send a message to the specified queue.
190
+ *
191
+ * @param string $queueId
192
+ * @param string $message
193
+ * @param array $options
194
+ * @return string Message ID
195
+ */
196
+ public function sendMessage($queueId, $message, $options = null)
197
+ {
198
+ if (!isset($this->_queues[$queueId])) {
199
+ throw new Zend_Cloud_QueueService_Exception("No such queue: $queueId");
200
+ }
201
+ try {
202
+ return $this->_queues[$queueId]->send($message);
203
+ } catch (Zend_Queue_Exception $e) {
204
+ throw new Zend_Cloud_QueueService_Exception('Error on sending message: '.$e->getMessage(), $e->getCode(), $e);
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Recieve at most $max messages from the specified queue and return the
210
+ * message IDs for messages recieved.
211
+ *
212
+ * @param string $queueId
213
+ * @param int $max
214
+ * @param array $options
215
+ * @return array
216
+ */
217
+ public function receiveMessages($queueId, $max = 1, $options = null)
218
+ {
219
+ if (!isset($this->_queues[$queueId])) {
220
+ throw new Zend_Cloud_QueueService_Exception("No such queue: $queueId");
221
+ }
222
+ try {
223
+ $res = $this->_queues[$queueId]->receive($max, isset($options[Zend_Queue::TIMEOUT])?$options[Zend_Queue::TIMEOUT]:null);
224
+ if ($res instanceof Iterator) {
225
+ return $this->_makeMessages($res);
226
+ } else {
227
+ return $this->_makeMessages(array($res));
228
+ }
229
+ } catch (Zend_Queue_Exception $e) {
230
+ throw new Zend_Cloud_QueueService_Exception('Error on recieving messages: '.$e->getMessage(), $e->getCode(), $e);
231
+ }
232
+ }
233
+
234
+ /**
235
+ * Create Zend_Cloud_QueueService_Message array for
236
+ * Azure messages.
237
+ *
238
+ * @param array $messages
239
+ * @return Zend_Cloud_QueueService_Message[]
240
+ */
241
+ protected function _makeMessages($messages)
242
+ {
243
+ $messageClass = $this->getMessageClass();
244
+ $setClass = $this->getMessageSetClass();
245
+ $result = array();
246
+ foreach ($messages as $message) {
247
+ $result[] = new $messageClass($message->body, $message);
248
+ }
249
+ return new $setClass($result);
250
+ }
251
+
252
+ /**
253
+ * Delete the specified message from the specified queue.
254
+ *
255
+ * @param string $queueId
256
+ * @param Zend_Cloud_QueueService_Message $message Message ID or message
257
+ * @param array $options
258
+ * @return void
259
+ */
260
+ public function deleteMessage($queueId, $message, $options = null)
261
+ {
262
+ if (!isset($this->_queues[$queueId])) {
263
+ throw new Zend_Cloud_QueueService_Exception("No such queue: $queueId");
264
+ }
265
+ try {
266
+ if ($message instanceof Zend_Cloud_QueueService_Message) {
267
+ $message = $message->getMessage();
268
+ }
269
+ if (!($message instanceof Zend_Queue_Message)) {
270
+ throw new Zend_Cloud_QueueService_Exception('Cannot delete the message: Zend_Queue_Message object required');
271
+ }
272
+
273
+ return $this->_queues[$queueId]->deleteMessage($message);
274
+ } catch (Zend_Queue_Exception $e) {
275
+ throw new Zend_Cloud_QueueService_Exception('Error on deleting a message: '.$e->getMessage(), $e->getCode(), $e);
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Peek at the messages from the specified queue without removing them.
281
+ *
282
+ * @param string $queueId
283
+ * @param int $num How many messages
284
+ * @param array $options
285
+ * @return Zend_Cloud_QueueService_Message[]
286
+ */
287
+ public function peekMessages($queueId, $num = 1, $options = null)
288
+ {
289
+ #require_once 'Zend/Cloud/OperationNotAvailableException.php';
290
+ throw new Zend_Cloud_OperationNotAvailableException('ZendQueue doesn\'t currently support message peeking');
291
+ }
292
+
293
+ /**
294
+ * Get Azure implementation
295
+ * @return Zend_Queue
296
+ */
297
+ public function getClient()
298
+ {
299
+ return $this->_queue;
300
+ }
301
+ }
lib/Zend/Cloud/QueueService/Exception.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Cloud
17
+ * @subpackage QueueService
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+
23
+ /**
24
+ * Zend_Cloud_Exception
25
+ */
26
+ #require_once 'Zend/Cloud/Exception.php';
27
+
28
+
29
+ /**
30
+ * @category Zend
31
+ * @package Zend_Cloud
32
+ * @subpackage QueueService
33
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
+ * @license http://framework.zend.com/license/new-bsd New BSD License
35
+ */
36
+ class Zend_Cloud_QueueService_Exception extends Zend_Cloud_Exception
37
+ {}
lib/Zend/Cloud/QueueService/Factory.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Cloud
17
+ * @subpackage QueueService
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Cloud/AbstractFactory.php';
23
+
24
+ /**
25
+ * @category Zend
26
+ * @package Zend_Cloud
27
+ * @subpackage QueueService
28
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
29
+ * @license http://framework.zend.com/license/new-bsd New BSD License
30
+ */
31
+ class Zend_Cloud_QueueService_Factory extends Zend_Cloud_AbstractFactory
32
+ {
33
+ const QUEUE_ADAPTER_KEY = 'queue_adapter';
34
+
35
+ /**
36
+ * @var string Interface which adapter must implement to be considered valid
37
+ */
38
+ protected static $_adapterInterface = 'Zend_Cloud_QueueService_Adapter';
39
+
40
+ /**
41
+ * Constructor
42
+ *
43
+ * @return void
44
+ */
45
+ private function __construct()
46
+ {
47
+ // private ctor - should not be used
48
+ }
49
+
50
+ /**
51
+ * Retrieve QueueService adapter
52
+ *
53
+ * @param array $options
54
+ * @return void
55
+ */
56
+ public static function getAdapter($options = array())
57
+ {
58
+ $adapter = parent::_getAdapter(self::QUEUE_ADAPTER_KEY, $options);
59
+ if (!$adapter) {
60
+ #require_once 'Zend/Cloud/QueueService/Exception.php';
61
+ throw new Zend_Cloud_QueueService_Exception('Class must be specified using the \'' .
62
+ self::QUEUE_ADAPTER_KEY . '\' key');
63
+ } elseif (!$adapter instanceof self::$_adapterInterface) {
64
+ #require_once 'Zend/Cloud/QueueService/Exception.php';
65
+ throw new Zend_Cloud_QueueService_Exception(
66
+ 'Adapter must implement \'' . self::$_adapterInterface . '\''
67
+ );
68
+ }
69
+ return $adapter;
70
+ }
71
+ }
lib/Zend/Cloud/QueueService/Message.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage QueueService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ /**
21
+ * Generic message class
22
+ *
23
+ * @category Zend
24
+ * @package Zend_Cloud
25
+ * @subpackage QueueService
26
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
+ * @license http://framework.zend.com/license/new-bsd New BSD License
28
+ */
29
+ class Zend_Cloud_QueueService_Message
30
+ {
31
+ protected $_body;
32
+ protected $_clientMessage;
33
+
34
+ /**
35
+ * @param string $body Message text
36
+ * @param $message Original message
37
+ */
38
+ function __construct($body, $message)
39
+ {
40
+ $this->_body = $body;
41
+ $this->_clientMessage = $message;
42
+ }
43
+
44
+ /**
45
+ * Get the message body
46
+ * @return string
47
+ */
48
+ public function getBody()
49
+ {
50
+ return $this->_body;
51
+ }
52
+
53
+ /**
54
+ * Get the original adapter-specific message
55
+ */
56
+ public function getMessage()
57
+ {
58
+ return $this->_clientMessage;
59
+ }
60
+ }
lib/Zend/Cloud/QueueService/MessageSet.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage QueueService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ /**
21
+ * Collection of message objects
22
+ *
23
+ * @category Zend
24
+ * @package Zend_Cloud
25
+ * @subpackage QueueService
26
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
+ * @license http://framework.zend.com/license/new-bsd New BSD License
28
+ */
29
+ class Zend_Cloud_QueueService_MessageSet implements Countable, IteratorAggregate
30
+ {
31
+ /** @var int */
32
+ protected $_messageCount;
33
+
34
+ /** @var ArrayAccess Messages */
35
+ protected $_messages;
36
+
37
+ /**
38
+ * Constructor
39
+ *
40
+ * @param array $messages
41
+ * @return void
42
+ */
43
+ public function __construct(array $messages)
44
+ {
45
+ $this->_messageCount = count($messages);
46
+ $this->_messages = new ArrayIterator($messages);
47
+ }
48
+
49
+ /**
50
+ * Countable: number of messages in collection
51
+ *
52
+ * @return int
53
+ */
54
+ public function count()
55
+ {
56
+ return $this->_messageCount;
57
+ }
58
+
59
+ /**
60
+ * IteratorAggregate: return iterable object
61
+ *
62
+ * @return Traversable
63
+ */
64
+ public function getIterator()
65
+ {
66
+ return $this->_messages;
67
+ }
68
+ }
lib/Zend/Cloud/StorageService/Adapter.php ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage StorageService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ /**
21
+ * Common interface for unstructured cloud storage.
22
+ *
23
+ * @category Zend
24
+ * @package Zend_Cloud
25
+ * @subpackage StorageService
26
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
+ * @license http://framework.zend.com/license/new-bsd New BSD License
28
+ */
29
+ interface Zend_Cloud_StorageService_Adapter
30
+ {
31
+ // HTTP adapter to use for connections
32
+ const HTTP_ADAPTER = 'http_adapter';
33
+
34
+ /**
35
+ * Get an item from the storage service.
36
+ *
37
+ * @param string $path
38
+ * @param array $options
39
+ * @return mixed
40
+ */
41
+ public function fetchItem($path, $options = null);
42
+
43
+ /**
44
+ * Store an item in the storage service.
45
+ * WARNING: This operation overwrites any item that is located at
46
+ * $destinationPath.
47
+ * @param string $destinationPath
48
+ * @param mixed $data
49
+ * @param array $options
50
+ * @return boolean
51
+ */
52
+ public function storeItem($destinationPath,
53
+ $data,
54
+ $options = null);
55
+
56
+ /**
57
+ * Delete an item in the storage service.
58
+ *
59
+ * @param string $path
60
+ * @param array $options
61
+ * @return void
62
+ */
63
+ public function deleteItem($path, $options = null);
64
+
65
+ /**
66
+ * Copy an item in the storage service to a given path.
67
+ *
68
+ * The $destinationPath must be a directory.
69
+ *
70
+ * @param string $sourcePath
71
+ * @param string $destination path
72
+ * @param array $options
73
+ * @return void
74
+ */
75
+ public function copyItem($sourcePath, $destinationPath, $options = null);
76
+
77
+ /**
78
+ * Move an item in the storage service to a given path.
79
+ *
80
+ * The $destinationPath must be a directory.
81
+ *
82
+ * @param string $sourcePath
83
+ * @param string $destination path
84
+ * @param array $options
85
+ * @return void
86
+ */
87
+ public function moveItem($sourcePath, $destinationPath, $options = null);
88
+
89
+ /**
90
+ * Rename an item in the storage service to a given name.
91
+ *
92
+ *
93
+ * @param string $path
94
+ * @param string $name
95
+ * @param array $options
96
+ * @return void
97
+ */
98
+ public function renameItem($path, $name, $options = null);
99
+
100
+ /**
101
+ * List items in the given directory in the storage service
102
+ *
103
+ * The $path must be a directory
104
+ *
105
+ *
106
+ * @param string $path Must be a directory
107
+ * @param array $options
108
+ * @return array A list of item names
109
+ */
110
+ public function listItems($path, $options = null);
111
+
112
+ /**
113
+ * Get a key/value array of metadata for the given path.
114
+ *
115
+ * @param string $path
116
+ * @param array $options
117
+ * @return array
118
+ */
119
+ public function fetchMetadata($path, $options = null);
120
+
121
+ /**
122
+ * Store a key/value array of metadata at the given path.
123
+ * WARNING: This operation overwrites any metadata that is located at
124
+ * $destinationPath.
125
+ *
126
+ * @param string $destinationPath
127
+ * @param array $options
128
+ * @return void
129
+ */
130
+ public function storeMetadata($destinationPath, $metadata, $options = null);
131
+
132
+ /**
133
+ * Delete a key/value array of metadata at the given path.
134
+ *
135
+ * @param string $path
136
+ * @param array $options
137
+ * @return void
138
+ */
139
+ public function deleteMetadata($path);
140
+
141
+ /**
142
+ * Get the concrete client.
143
+ */
144
+ public function getClient();
145
+ }
lib/Zend/Cloud/StorageService/Adapter/FileSystem.php ADDED
@@ -0,0 +1,267 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage StorageService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Cloud/StorageService/Adapter.php';
21
+ #require_once 'Zend/Cloud/StorageService/Exception.php';
22
+
23
+ /**
24
+ * FileSystem adapter for unstructured cloud storage.
25
+ *
26
+ * @category Zend
27
+ * @package Zend_Cloud
28
+ * @subpackage StorageService
29
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30
+ * @license http://framework.zend.com/license/new-bsd New BSD License
31
+ */
32
+ class Zend_Cloud_StorageService_Adapter_FileSystem implements Zend_Cloud_StorageService_Adapter
33
+ {
34
+
35
+ /**
36
+ * Options array keys for the file system adapter.
37
+ */
38
+ const LOCAL_DIRECTORY = 'local_directory';
39
+
40
+ /**
41
+ * The directory for the data
42
+ * @var string
43
+ */
44
+ protected $_directory = null;
45
+
46
+ /**
47
+ * Constructor
48
+ *
49
+ * @param array|Zend_Config $options
50
+ * @return void
51
+ */
52
+ public function __construct($options = array())
53
+ {
54
+ if ($options instanceof Zend_Config) {
55
+ $options = $options->toArray();
56
+ }
57
+
58
+ if (!is_array($options)) {
59
+ throw new Zend_Cloud_StorageService_Exception('Invalid options provided');
60
+ }
61
+
62
+ if (isset($options[self::LOCAL_DIRECTORY])) {
63
+ $this->_directory = $options[self::LOCAL_DIRECTORY];
64
+ } else {
65
+ $this->_directory = realpath(sys_get_temp_dir());
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Get an item from the storage service.
71
+ *
72
+ * TODO: Support streaming
73
+ *
74
+ * @param string $path
75
+ * @param array $options
76
+ * @return false|string
77
+ */
78
+ public function fetchItem($path, $options = array())
79
+ {
80
+ $filepath = $this->_getFullPath($path);
81
+ $path = realpath($filepath);
82
+
83
+ if (!$path) {
84
+ return false;
85
+ }
86
+
87
+ return file_get_contents($path);
88
+ }
89
+
90
+ /**
91
+ * Store an item in the storage service.
92
+ *
93
+ * WARNING: This operation overwrites any item that is located at
94
+ * $destinationPath.
95
+ *
96
+ * @TODO Support streams
97
+ *
98
+ * @param string $destinationPath
99
+ * @param mixed $data
100
+ * @param array $options
101
+ * @return void
102
+ */
103
+ public function storeItem($destinationPath, $data, $options = array())
104
+ {
105
+ $path = $this->_getFullPath($destinationPath);
106
+ file_put_contents($path, $data);
107
+ chmod($path, 0777);
108
+ }
109
+
110
+ /**
111
+ * Delete an item in the storage service.
112
+ *
113
+ * @param string $path
114
+ * @param array $options
115
+ * @return void
116
+ */
117
+ public function deleteItem($path, $options = array())
118
+ {
119
+ if (!isset($path)) {
120
+ return;
121
+ }
122
+
123
+ $filepath = $this->_getFullPath($path);
124
+ if (file_exists($filepath)) {
125
+ unlink($filepath);
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Copy an item in the storage service to a given path.
131
+ *
132
+ * WARNING: This operation is *very* expensive for services that do not
133
+ * support copying an item natively.
134
+ *
135
+ * @TODO Support streams for those services that don't support natively
136
+ *
137
+ * @param string $sourcePath
138
+ * @param string $destination path
139
+ * @param array $options
140
+ * @return void
141
+ */
142
+ public function copyItem($sourcePath, $destinationPath, $options = array())
143
+ {
144
+ copy($this->_getFullPath($sourcePath), $this->_getFullPath($destinationPath));
145
+ }
146
+
147
+ /**
148
+ * Move an item in the storage service to a given path.
149
+ *
150
+ * WARNING: This operation is *very* expensive for services that do not
151
+ * support moving an item natively.
152
+ *
153
+ * @TODO Support streams for those services that don't support natively
154
+ *
155
+ * @param string $sourcePath
156
+ * @param string $destination path
157
+ * @param array $options
158
+ * @return void
159
+ */
160
+ public function moveItem($sourcePath, $destinationPath, $options = array())
161
+ {
162
+ rename($this->_getFullPath($sourcePath), $this->_getFullPath($destinationPath));
163
+ }
164
+
165
+ /**
166
+ * Rename an item in the storage service to a given name.
167
+ *
168
+ *
169
+ * @param string $path
170
+ * @param string $name
171
+ * @param array $options
172
+ * @return void
173
+ */
174
+ public function renameItem($path, $name, $options = null)
175
+ {
176
+ rename(
177
+ $this->_getFullPath($path),
178
+ dirname($this->_getFullPath($path)) . DIRECTORY_SEPARATOR . $name
179
+ );
180
+ }
181
+
182
+ /**
183
+ * List items in the given directory in the storage service
184
+ *
185
+ * The $path must be a directory
186
+ *
187
+ *
188
+ * @param string $path Must be a directory
189
+ * @param array $options
190
+ * @return array A list of item names
191
+ */
192
+ public function listItems($path, $options = null)
193
+ {
194
+ $listing = scandir($this->_getFullPath($path));
195
+
196
+ // Remove the hidden navigation directories
197
+ $listing = array_diff($listing, array('.', '..'));
198
+
199
+ return $listing;
200
+ }
201
+
202
+ /**
203
+ * Get a key/value array of metadata for the given path.
204
+ *
205
+ * @param string $path
206
+ * @param array $options
207
+ * @return array
208
+ */
209
+ public function fetchMetadata($path, $options = array())
210
+ {
211
+ $fullPath = $this->_getFullPath($path);
212
+ $metadata = null;
213
+ if (file_exists($fullPath)) {
214
+ $metadata = stat(realpath($fullPath));
215
+ }
216
+
217
+ return isset($metadata) ? $metadata : false;
218
+ }
219
+
220
+ /**
221
+ * Store a key/value array of metadata at the given path.
222
+ * WARNING: This operation overwrites any metadata that is located at
223
+ * $destinationPath.
224
+ *
225
+ * @param string $destinationPath
226
+ * @param array $options
227
+ * @return void
228
+ */
229
+ public function storeMetadata($destinationPath, $metadata, $options = array())
230
+ {
231
+ #require_once 'Zend/Cloud/OperationNotAvailableException.php';
232
+ throw new Zend_Cloud_OperationNotAvailableException('Storing metadata not implemented');
233
+ }
234
+
235
+ /**
236
+ * Delete a key/value array of metadata at the given path.
237
+ *
238
+ * @param string $path
239
+ * @param array $options
240
+ * @return void
241
+ */
242
+ public function deleteMetadata($path)
243
+ {
244
+ #require_once 'Zend/Cloud/OperationNotAvailableException.php';
245
+ throw new Zend_Cloud_OperationNotAvailableException('Deleting metadata not implemented');
246
+ }
247
+
248
+ /**
249
+ * Return the full path for the file.
250
+ *
251
+ * @param string $path
252
+ * @return string
253
+ */
254
+ private function _getFullPath($path)
255
+ {
256
+ return $this->_directory . DIRECTORY_SEPARATOR . $path;
257
+ }
258
+
259
+ /**
260
+ * Get the concrete client.
261
+ * @return strings
262
+ */
263
+ public function getClient()
264
+ {
265
+ return $this->_directory;
266
+ }
267
+ }
lib/Zend/Cloud/StorageService/Adapter/Nirvanix.php ADDED
@@ -0,0 +1,399 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage StorageService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Cloud/StorageService/Adapter.php';
21
+ #require_once 'Zend/Cloud/StorageService/Exception.php';
22
+ #require_once 'Zend/Service/Nirvanix.php';
23
+
24
+ /**
25
+ * Adapter for Nirvanix cloud storage
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Cloud
29
+ * @subpackage StorageService
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Cloud_StorageService_Adapter_Nirvanix
34
+ implements Zend_Cloud_StorageService_Adapter
35
+ {
36
+ const USERNAME = 'auth_username';
37
+ const PASSWORD = 'auth_password';
38
+ const APP_KEY = 'auth_accesskey';
39
+ const REMOTE_DIRECTORY = 'remote_directory';
40
+
41
+ /**
42
+ * The Nirvanix adapter
43
+ * @var Zend_Service_Nirvanix
44
+ */
45
+ protected $_nirvanix;
46
+ protected $_imfNs;
47
+ protected $_metadataNs;
48
+ protected $_remoteDirectory;
49
+ private $maxPageSize = 500;
50
+
51
+ /**
52
+ * Constructor
53
+ *
54
+ * @param array|Zend_Config $options
55
+ * @return void
56
+ */
57
+ function __construct($options = array())
58
+ {
59
+ if ($options instanceof Zend_Config) {
60
+ $options = $options->toArray();
61
+ }
62
+
63
+ if (!is_array($options)) {
64
+ throw new Zend_Cloud_StorageService_Exception('Invalid options provided');
65
+ }
66
+
67
+ $auth = array(
68
+ 'username' => $options[self::USERNAME],
69
+ 'password' => $options[self::PASSWORD],
70
+ 'appKey' => $options[self::APP_KEY],
71
+ );
72
+ $nirvanix_options = array();
73
+ if (isset($options[self::HTTP_ADAPTER])) {
74
+ $httpc = new Zend_Http_Client();
75
+ $httpc->setAdapter($options[self::HTTP_ADAPTER]);
76
+ $nirvanix_options['httpClient'] = $httpc;
77
+ }
78
+ try {
79
+ $this->_nirvanix = new Zend_Service_Nirvanix($auth, $nirvanix_options);
80
+ $this->_remoteDirectory = $options[self::REMOTE_DIRECTORY];
81
+ $this->_imfNs = $this->_nirvanix->getService('IMFS');
82
+ $this->_metadataNs = $this->_nirvanix->getService('Metadata');
83
+ } catch (Zend_Service_Nirvanix_Exception $e) {
84
+ throw new Zend_Cloud_StorageService_Exception('Error on create: '.$e->getMessage(), $e->getCode(), $e);
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Get an item from the storage service.
90
+ *
91
+ * @param string $path
92
+ * @param array $options
93
+ * @return mixed
94
+ */
95
+ public function fetchItem($path, $options = null)
96
+ {
97
+ $path = $this->_getFullPath($path);
98
+ try {
99
+ $item = $this->_imfNs->getContents($path);
100
+ } catch (Zend_Service_Nirvanix_Exception $e) {
101
+ throw new Zend_Cloud_StorageService_Exception('Error on fetch: '.$e->getMessage(), $e->getCode(), $e);
102
+ }
103
+ return $item;
104
+ }
105
+
106
+ /**
107
+ * Store an item in the storage service.
108
+ * WARNING: This operation overwrites any item that is located at
109
+ * $destinationPath.
110
+ * @param string $destinationPath
111
+ * @param mixed $data
112
+ * @param array $options
113
+ * @return void
114
+ */
115
+ public function storeItem($destinationPath, $data, $options = null)
116
+ {
117
+ try {
118
+ $path = $this->_getFullPath($destinationPath);
119
+ $this->_imfNs->putContents($path, $data);
120
+ } catch (Zend_Service_Nirvanix_Exception $e) {
121
+ throw new Zend_Cloud_StorageService_Exception('Error on store: '.$e->getMessage(), $e->getCode(), $e);
122
+ }
123
+ return true;
124
+ }
125
+
126
+ /**
127
+ * Delete an item in the storage service.
128
+ *
129
+ * @param string $path
130
+ * @param array $options
131
+ * @return void
132
+ */
133
+ public function deleteItem($path, $options = null)
134
+ {
135
+ try {
136
+ $path = $this->_getFullPath($path);
137
+ $this->_imfNs->unlink($path);
138
+ } catch(Zend_Service_Nirvanix_Exception $e) {
139
+ // if (trim(strtoupper($e->getMessage())) != 'INVALID PATH') {
140
+ // // TODO Differentiate among errors in the Nirvanix adapter
141
+ throw new Zend_Cloud_StorageService_Exception('Error on delete: '.$e->getMessage(), $e->getCode(), $e);
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Copy an item in the storage service to a given path.
147
+ * WARNING: This operation is *very* expensive for services that do not
148
+ * support copying an item natively.
149
+ *
150
+ * @param string $sourcePath
151
+ * @param string $destination path
152
+ * @param array $options
153
+ * @return void
154
+ */
155
+ public function copyItem($sourcePath, $destinationPath, $options = null)
156
+ {
157
+ try {
158
+ $sourcePath = $this->_getFullPath($sourcePath);
159
+ $destinationPath = $this->_getFullPath($destinationPath);
160
+ $this->_imfNs->CopyFiles(array('srcFilePath' => $sourcePath,
161
+ 'destFolderPath' => $destinationPath));
162
+ } catch (Zend_Service_Nirvanix_Exception $e) {
163
+ throw new Zend_Cloud_StorageService_Exception('Error on copy: '.$e->getMessage(), $e->getCode(), $e);
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Move an item in the storage service to a given path.
169
+ * WARNING: This operation is *very* expensive for services that do not
170
+ * support moving an item natively.
171
+ *
172
+ * @param string $sourcePath
173
+ * @param string $destination path
174
+ * @param array $options
175
+ * @return void
176
+ */
177
+ public function moveItem($sourcePath, $destinationPath, $options = null)
178
+ {
179
+ try {
180
+ $sourcePath = $this->_getFullPath($sourcePath);
181
+ $destinationPath = $this->_getFullPath($destinationPath);
182
+ $this->_imfNs->RenameFile(array('filePath' => $sourcePath,
183
+ 'newFileName' => $destinationPath));
184
+ // $this->_imfNs->MoveFiles(array('srcFilePath' => $sourcePath,
185
+ // 'destFolderPath' => $destinationPath));
186
+ } catch (Zend_Service_Nirvanix_Exception $e) {
187
+ throw new Zend_Cloud_StorageService_Exception('Error on move: '.$e->getMessage(), $e->getCode(), $e);
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Rename an item in the storage service to a given name.
193
+ *
194
+ *
195
+ * @param string $path
196
+ * @param string $name
197
+ * @param array $options
198
+ * @return void
199
+ */
200
+ public function renameItem($path, $name, $options = null)
201
+ {
202
+ #require_once 'Zend/Cloud/OperationNotAvailableException.php';
203
+ throw new Zend_Cloud_OperationNotAvailableException('Renaming not implemented');
204
+ }
205
+
206
+ /**
207
+ * Get a key/value array of metadata for the given path.
208
+ *
209
+ * @param string $path
210
+ * @param array $options
211
+ * @return array An associative array of key/value pairs specifying the metadata for this object.
212
+ * If no metadata exists, an empty array is returned.
213
+ */
214
+ public function fetchMetadata($path, $options = null)
215
+ {
216
+ $path = $this->_getFullPath($path);
217
+ try {
218
+ $metadataNode = $this->_metadataNs->getMetadata(array('path' => $path));
219
+ } catch (Zend_Service_Nirvanix_Exception $e) {
220
+ throw new Zend_Cloud_StorageService_Exception('Error on fetching metadata: '.$e->getMessage(), $e->getCode(), $e);
221
+ }
222
+
223
+ $metadata = array();
224
+ $length = count($metadataNode->Metadata);
225
+
226
+ // Need to special case this as Nirvanix returns an array if there is
227
+ // more than one, but doesn't return an array if there is only one.
228
+ if ($length == 1)
229
+ {
230
+ $metadata[(string)$metadataNode->Metadata->Type->value] = (string)$metadataNode->Metadata->Value;
231
+ }
232
+ else if ($length > 1)
233
+ {
234
+ for ($i=0; $i<$length; $i++)
235
+ {
236
+ $metadata[(string)$metadataNode->Metadata[$i]->Type] = (string)$metadataNode->Metadata[$i]->Value;
237
+ }
238
+ }
239
+ return $metadata;
240
+ }
241
+
242
+ /**
243
+ * Store a key/value array of metadata at the given path.
244
+ * WARNING: This operation overwrites any metadata that is located at
245
+ * $destinationPath.
246
+ *
247
+ * @param array $metadata - An associative array specifying the key/value pairs for the metadata.
248
+ * @param $destinationPath
249
+ * @param array $options
250
+ * @return void
251
+ */
252
+ public function storeMetadata($destinationPath, $metadata, $options = null)
253
+ {
254
+ $destinationPath = $this->_getFullPath($destinationPath);
255
+ if ($metadata != null) {
256
+ try {
257
+ foreach ($metadata AS $key=>$value) {
258
+ $metadataString = $key . ":" . $value;
259
+ $this->_metadataNs->SetMetadata(array(
260
+ 'path' => $destinationPath,
261
+ 'metadata' => $metadataString,
262
+ ));
263
+ }
264
+ } catch (Zend_Service_Nirvanix_Exception $e) {
265
+ throw new Zend_Cloud_StorageService_Exception('Error on storing metadata: '.$e->getMessage(), $e->getCode(), $e);
266
+ }
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Delete a key/value array of metadata at the given path.
272
+ *
273
+ * @param string $path
274
+ * @param array $metadata - An associative array specifying the key/value pairs for the metadata
275
+ * to be deleted. If null, all metadata associated with the object will
276
+ * be deleted.
277
+ * @param array $options
278
+ * @return void
279
+ */
280
+ public function deleteMetadata($path, $metadata = null, $options = null)
281
+ {
282
+ $path = $this->_getFullPath($path);
283
+ try {
284
+ if ($metadata == null) {
285
+ $this->_metadataNs->DeleteAllMetadata(array('path' => $path));
286
+ } else {
287
+ foreach ($metadata AS $key=>$value) {
288
+ $this->_metadataNs->DeleteMetadata(array(
289
+ 'path' => $path,
290
+ 'metadata' => $key,
291
+ ));
292
+ }
293
+ }
294
+ } catch (Zend_Service_Nirvanix_Exception $e) {
295
+ throw new Zend_Cloud_StorageService_Exception('Error on deleting metadata: '.$e->getMessage(), $e->getCode(), $e);
296
+ }
297
+ }
298
+
299
+ /*
300
+ * Recursively traverse all the folders and build an array that contains
301
+ * the path names for each folder.
302
+ *
303
+ * @param $path - The folder path to get the list of folders from.
304
+ * @param &$resultArray - reference to the array that contains the path names
305
+ * for each folder.
306
+ */
307
+ private function getAllFolders($path, &$resultArray)
308
+ {
309
+ $response = $this->_imfNs->ListFolder(array(
310
+ 'folderPath' => $path,
311
+ 'pageNumber' => 1,
312
+ 'pageSize' => $this->maxPageSize,
313
+ ));
314
+ $numFolders = $response->ListFolder->TotalFolderCount;
315
+ if ($numFolders == 0) {
316
+ return;
317
+ } else {
318
+ //Need to special case this as Nirvanix returns an array if there is
319
+ //more than one, but doesn't return an array if there is only one.
320
+ if ($numFolders == 1) {
321
+ $folderPath = $response->ListFolder->Folder->Path;
322
+ array_push($resultArray, $folderPath);
323
+ $this->getAllFolders('/' . $folderPath, $resultArray);
324
+ } else {
325
+ foreach ($response->ListFolder->Folder as $arrayElem) {
326
+ $folderPath = $arrayElem->Path;
327
+ array_push($resultArray, $folderPath);
328
+ $this->getAllFolders('/' . $folderPath, $resultArray);
329
+ }
330
+ }
331
+ }
332
+ }
333
+
334
+ /**
335
+ * Return an array of the items contained in the given path. The items
336
+ * returned are the files or objects that in the specified path.
337
+ *
338
+ * @param string $path
339
+ * @param array $options
340
+ * @return array
341
+ */
342
+ public function listItems($path, $options = null)
343
+ {
344
+ $path = $this->_getFullPath($path);
345
+ $resultArray = array();
346
+
347
+ if (!isset($path)) {
348
+ return false;
349
+ } else {
350
+ try {
351
+ $response = $this->_imfNs->ListFolder(array(
352
+ 'folderPath' => $path,
353
+ 'pageNumber' => 1,
354
+ 'pageSize' => $this->maxPageSize,
355
+ ));
356
+ } catch (Zend_Service_Nirvanix_Exception $e) {
357
+ throw new Zend_Cloud_StorageService_Exception('Error on list: '.$e->getMessage(), $e->getCode(), $e);
358
+ }
359
+
360
+ $numFiles = $response->ListFolder->TotalFileCount;
361
+
362
+ //Add the file names to the array
363
+ if ($numFiles != 0) {
364
+ //Need to special case this as Nirvanix returns an array if there is
365
+ //more than one, but doesn't return an array if there is only one.
366
+ if ($numFiles == 1) {
367
+ $resultArray[] = (string)$response->ListFolder->File->Name;
368
+ }
369
+ else {
370
+ foreach ($response->ListFolder->File as $arrayElem) {
371
+ $resultArray[] = (string) $arrayElem->Name;
372
+ }
373
+ }
374
+ }
375
+ }
376
+
377
+ return $resultArray;
378
+ }
379
+
380
+ /**
381
+ * Get full path to an object
382
+ *
383
+ * @param string $path
384
+ * @return string
385
+ */
386
+ private function _getFullPath($path)
387
+ {
388
+ return $this->_remoteDirectory . $path;
389
+ }
390
+
391
+ /**
392
+ * Get the concrete client.
393
+ * @return Zend_Service_Nirvanix
394
+ */
395
+ public function getClient()
396
+ {
397
+ return $this->_nirvanix;
398
+ }
399
+ }
lib/Zend/Cloud/StorageService/Adapter/S3.php ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage StorageService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Service/Amazon/S3.php';
21
+ #require_once 'Zend/Cloud/StorageService/Adapter.php';
22
+ #require_once 'Zend/Cloud/StorageService/Exception.php';
23
+
24
+ /**
25
+ * S3 adapter for unstructured cloud storage.
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Cloud
29
+ * @subpackage StorageService
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Cloud_StorageService_Adapter_S3
34
+ implements Zend_Cloud_StorageService_Adapter
35
+ {
36
+ /*
37
+ * Options array keys for the S3 adapter.
38
+ */
39
+ const BUCKET_NAME = 'bucket_name';
40
+ const BUCKET_AS_DOMAIN = 'bucket_as_domain?';
41
+ const FETCH_STREAM = 'fetch_stream';
42
+ const METADATA = 'metadata';
43
+
44
+ /**
45
+ * AWS constants
46
+ */
47
+ const AWS_ACCESS_KEY = 'aws_accesskey';
48
+ const AWS_SECRET_KEY = 'aws_secretkey';
49
+
50
+ /**
51
+ * S3 service instance.
52
+ * @var Zend_Service_Amazon_S3
53
+ */
54
+ protected $_s3;
55
+ protected $_defaultBucketName = null;
56
+ protected $_defaultBucketAsDomain = false;
57
+
58
+ /**
59
+ * Constructor
60
+ *
61
+ * @param array|Zend_Config $options
62
+ * @return void
63
+ */
64
+ public function __construct($options = array())
65
+ {
66
+ if ($options instanceof Zend_Config) {
67
+ $options = $options->toArray();
68
+ }
69
+
70
+ if (!is_array($options)) {
71
+ throw new Zend_Cloud_StorageService_Exception('Invalid options provided');
72
+ }
73
+
74
+ if (!isset($options[self::AWS_ACCESS_KEY]) || !isset($options[self::AWS_SECRET_KEY])) {
75
+ throw new Zend_Cloud_StorageService_Exception('AWS keys not specified!');
76
+ }
77
+
78
+ try {
79
+ $this->_s3 = new Zend_Service_Amazon_S3($options[self::AWS_ACCESS_KEY],
80
+ $options[self::AWS_SECRET_KEY]);
81
+ } catch (Zend_Service_Amazon_S3_Exception $e) {
82
+ throw new Zend_Cloud_StorageService_Exception('Error on create: '.$e->getMessage(), $e->getCode(), $e);
83
+ }
84
+
85
+ if (isset($options[self::HTTP_ADAPTER])) {
86
+ $this->_s3->getHttpClient()->setAdapter($options[self::HTTP_ADAPTER]);
87
+ }
88
+
89
+ if (isset($options[self::BUCKET_NAME])) {
90
+ $this->_defaultBucketName = $options[self::BUCKET_NAME];
91
+ }
92
+
93
+ if (isset($options[self::BUCKET_AS_DOMAIN])) {
94
+ $this->_defaultBucketAsDomain = $options[self::BUCKET_AS_DOMAIN];
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Get an item from the storage service.
100
+ *
101
+ * @TODO Support streams
102
+ *
103
+ * @param string $path
104
+ * @param array $options
105
+ * @return string
106
+ */
107
+ public function fetchItem($path, $options = array())
108
+ {
109
+ $fullPath = $this->_getFullPath($path, $options);
110
+ try {
111
+ if (!empty($options[self::FETCH_STREAM])) {
112
+ return $this->_s3->getObjectStream($fullPath, $options[self::FETCH_STREAM]);
113
+ } else {
114
+ return $this->_s3->getObject($fullPath);
115
+ }
116
+ } catch (Zend_Service_Amazon_S3_Exception $e) {
117
+ throw new Zend_Cloud_StorageService_Exception('Error on fetch: '.$e->getMessage(), $e->getCode(), $e);
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Store an item in the storage service.
123
+ *
124
+ * WARNING: This operation overwrites any item that is located at
125
+ * $destinationPath.
126
+ *
127
+ * @TODO Support streams
128
+ *
129
+ * @param string $destinationPath
130
+ * @param string|resource $data
131
+ * @param array $options
132
+ * @return void
133
+ */
134
+ public function storeItem($destinationPath, $data, $options = array())
135
+ {
136
+ try {
137
+ $fullPath = $this->_getFullPath($destinationPath, $options);
138
+ return $this->_s3->putObject(
139
+ $fullPath,
140
+ $data,
141
+ empty($options[self::METADATA]) ? null : $options[self::METADATA]
142
+ );
143
+ } catch (Zend_Service_Amazon_S3_Exception $e) {
144
+ throw new Zend_Cloud_StorageService_Exception('Error on store: '.$e->getMessage(), $e->getCode(), $e);
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Delete an item in the storage service.
150
+ *
151
+ * @param string $path
152
+ * @param array $options
153
+ * @return void
154
+ */
155
+ public function deleteItem($path, $options = array())
156
+ {
157
+ try {
158
+ $this->_s3->removeObject($this->_getFullPath($path, $options));
159
+ } catch (Zend_Service_Amazon_S3_Exception $e) {
160
+ throw new Zend_Cloud_StorageService_Exception('Error on delete: '.$e->getMessage(), $e->getCode(), $e);
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Copy an item in the storage service to a given path.
166
+ *
167
+ * WARNING: This operation is *very* expensive for services that do not
168
+ * support copying an item natively.
169
+ *
170
+ * @TODO Support streams for those services that don't support natively
171
+ *
172
+ * @param string $sourcePath
173
+ * @param string $destination path
174
+ * @param array $options
175
+ * @return void
176
+ */
177
+ public function copyItem($sourcePath, $destinationPath, $options = array())
178
+ {
179
+ try {
180
+ // TODO We *really* need to add support for object copying in the S3 adapter
181
+ $item = $this->fetch($_getFullPath(sourcePath), $options);
182
+ $this->storeItem($item, $destinationPath, $options);
183
+ } catch (Zend_Service_Amazon_S3_Exception $e) {
184
+ throw new Zend_Cloud_StorageService_Exception('Error on copy: '.$e->getMessage(), $e->getCode(), $e);
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Move an item in the storage service to a given path.
190
+ *
191
+ * @TODO Support streams for those services that don't support natively
192
+ *
193
+ * @param string $sourcePath
194
+ * @param string $destination path
195
+ * @param array $options
196
+ * @return void
197
+ */
198
+ public function moveItem($sourcePath, $destinationPath, $options = array())
199
+ {
200
+ try {
201
+ $fullSourcePath = $this->_getFullPath($sourcePath, $options);
202
+ $fullDestPath = $this->_getFullPath($destinationPath, $options);
203
+ return $this->_s3->moveObject(
204
+ $fullSourcePath,
205
+ $fullDestPath,
206
+ empty($options[self::METADATA]) ? null : $options[self::METADATA]
207
+ );
208
+ } catch (Zend_Service_Amazon_S3_Exception $e) {
209
+ throw new Zend_Cloud_StorageService_Exception('Error on move: '.$e->getMessage(), $e->getCode(), $e);
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Rename an item in the storage service to a given name.
215
+ *
216
+ *
217
+ * @param string $path
218
+ * @param string $name
219
+ * @param array $options
220
+ * @return void
221
+ */
222
+ public function renameItem($path, $name, $options = null)
223
+ {
224
+ #require_once 'Zend/Cloud/OperationNotAvailableException.php';
225
+ throw new Zend_Cloud_OperationNotAvailableException('Rename not implemented');
226
+ }
227
+
228
+ /**
229
+ * List items in the given directory in the storage service
230
+ *
231
+ * The $path must be a directory
232
+ *
233
+ *
234
+ * @param string $path Must be a directory
235
+ * @param array $options
236
+ * @return array A list of item names
237
+ */
238
+ public function listItems($path, $options = null)
239
+ {
240
+ try {
241
+ // TODO Support 'prefix' parameter for Zend_Service_Amazon_S3::getObjectsByBucket()
242
+ return $this->_s3->getObjectsByBucket($this->_defaultBucketName);
243
+ } catch (Zend_Service_Amazon_S3_Exception $e) {
244
+ throw new Zend_Cloud_StorageService_Exception('Error on list: '.$e->getMessage(), $e->getCode(), $e);
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Get a key/value array of metadata for the given path.
250
+ *
251
+ * @param string $path
252
+ * @param array $options
253
+ * @return array
254
+ */
255
+ public function fetchMetadata($path, $options = array())
256
+ {
257
+ try {
258
+ return $this->_s3->getInfo($this->_getFullPath($path, $options));
259
+ } catch (Zend_Service_Amazon_S3_Exception $e) {
260
+ throw new Zend_Cloud_StorageService_Exception('Error on fetch: '.$e->getMessage(), $e->getCode(), $e);
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Store a key/value array of metadata at the given path.
266
+ * WARNING: This operation overwrites any metadata that is located at
267
+ * $destinationPath.
268
+ *
269
+ * @param string $destinationPath
270
+ * @param array $options
271
+ * @return void
272
+ */
273
+ public function storeMetadata($destinationPath, $metadata, $options = array())
274
+ {
275
+ #require_once 'Zend/Cloud/OperationNotAvailableException.php';
276
+ throw new Zend_Cloud_OperationNotAvailableException('Storing separate metadata is not supported, use storeItem() with \'metadata\' option key');
277
+ }
278
+
279
+ /**
280
+ * Delete a key/value array of metadata at the given path.
281
+ *
282
+ * @param string $path
283
+ * @param array $options
284
+ * @return void
285
+ */
286
+ public function deleteMetadata($path)
287
+ {
288
+ #require_once 'Zend/Cloud/OperationNotAvailableException.php';
289
+ throw new Zend_Cloud_OperationNotAvailableException('Deleting metadata not supported');
290
+ }
291
+
292
+ /**
293
+ * Get full path, including bucket, for an object
294
+ *
295
+ * @param string $path
296
+ * @param array $options
297
+ * @return void
298
+ */
299
+ protected function _getFullPath($path, $options)
300
+ {
301
+ if (isset($options[self::BUCKET_NAME])) {
302
+ $bucket = $options[self::BUCKET_NAME];
303
+ } else if (isset($this->_defaultBucketName)) {
304
+ $bucket = $this->_defaultBucketName;
305
+ } else {
306
+ #require_once 'Zend/Cloud/StorageService/Exception.php';
307
+ throw new Zend_Cloud_StorageService_Exception('Bucket name must be specified for S3 adapter.');
308
+ }
309
+
310
+ if (isset($options[self::BUCKET_AS_DOMAIN])) {
311
+ // TODO: support bucket domain names
312
+ #require_once 'Zend/Cloud/StorageService/Exception.php';
313
+ throw new Zend_Cloud_StorageService_Exception('The S3 adapter does not currently support buckets in domain names.');
314
+ }
315
+
316
+ return trim($bucket) . '/' . trim($path);
317
+ }
318
+
319
+ /**
320
+ * Get the concrete client.
321
+ * @return Zend_Service_Amazon_S3
322
+ */
323
+ public function getClient()
324
+ {
325
+ return $this->_s3;
326
+ }
327
+ }
lib/Zend/Cloud/StorageService/Adapter/WindowsAzure.php ADDED
@@ -0,0 +1,443 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * LICENSE
4
+ *
5
+ * This source file is subject to the new BSD license that is bundled
6
+ * with this package in the file LICENSE.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://framework.zend.com/license/new-bsd
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@zend.com so we can send you a copy immediately.
12
+ *
13
+ * @category Zend
14
+ * @package Zend_Cloud
15
+ * @subpackage StorageService
16
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
17
+ * @license http://framework.zend.com/license/new-bsd New BSD License
18
+ */
19
+
20
+ #require_once 'Zend/Cloud/StorageService/Adapter.php';
21
+ #require_once 'Zend/Service/WindowsAzure/Storage/Blob.php';
22
+ #require_once 'Zend/Cloud/StorageService/Exception.php';
23
+
24
+ /**
25
+ *
26
+ * Windows Azure Blob Service abstraction
27
+ *
28
+ * @category Zend
29
+ * @package Zend_Cloud
30
+ * @subpackage StorageService
31
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
+ * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ */
34
+ class Zend_Cloud_StorageService_Adapter_WindowsAzure
35
+ implements Zend_Cloud_StorageService_Adapter
36
+ {
37
+ const ACCOUNT_NAME = 'storage_accountname';
38
+ const ACCOUNT_KEY = 'storage_accountkey';
39
+ const HOST = "storage_host";
40
+ const PROXY_HOST = "storage_proxy_host";
41
+ const PROXY_PORT = "storage_proxy_port";
42
+ const PROXY_CREDENTIALS = "storage_proxy_credentials";
43
+ const CONTAINER = "storage_container";
44
+ const RETURN_TYPE = 'return_type';
45
+ const RETURN_PATHNAME = 'return_path';
46
+ const RETURN_OPENMODE = 'return_openmode';
47
+
48
+ /** return types for fetch */
49
+ const RETURN_PATH = 1; // return filename
50
+ const RETURN_STRING = 2; // return data as string
51
+ const RETURN_STREAM = 3; // return PHP stream
52
+
53
+ /** return types for list */
54
+ const RETURN_LIST = 1; // return native list
55
+ const RETURN_NAMES = 2; // return only names
56
+
57
+ const DEFAULT_HOST = Zend_Service_WindowsAzure_Storage::URL_CLOUD_BLOB;
58
+
59
+ /**
60
+ * Storage container to operate on
61
+ *
62
+ * @var string
63
+ */
64
+ protected $_container;
65
+
66
+ /**
67
+ * Storage client
68
+ *
69
+ * @var Zend_Service_WindowsAzure_Storage_Blob
70
+ */
71
+ protected $_storageClient = null;
72
+
73
+ /**
74
+ * Creates a new Zend_Cloud_Storage_WindowsAzure instance
75
+ *
76
+ * @param array|Zend_Config $options Options for the Zend_Cloud_Storage_WindowsAzure instance
77
+ */
78
+ public function __construct($options = array())
79
+ {
80
+ if ($options instanceof Zend_Config) {
81
+ $options = $options->toArray();
82
+ }
83
+
84
+ if (!is_array($options)) {
85
+ throw new Zend_Cloud_StorageService_Exception('Invalid options provided');
86
+ }
87
+
88
+ // Build Zend_Service_WindowsAzure_Storage_Blob instance
89
+ if (!isset($options[self::HOST])) {
90
+ $host = self::DEFAULT_HOST;
91
+ } else {
92
+ $host = $options[self::HOST];
93
+ }
94
+
95
+ if (!isset($options[self::ACCOUNT_NAME])) {
96
+ throw new Zend_Cloud_StorageService_Exception('No Windows Azure account name provided.');
97
+ }
98
+ if (!isset($options[self::ACCOUNT_KEY])) {
99
+ throw new Zend_Cloud_StorageService_Exception('No Windows Azure account key provided.');
100
+ }
101
+
102
+ $this->_storageClient = new Zend_Service_WindowsAzure_Storage_Blob($host,
103
+ $options[self::ACCOUNT_NAME], $options[self::ACCOUNT_KEY]);
104
+
105
+ // Parse other options
106
+ if (!empty($options[self::PROXY_HOST])) {
107
+ $proxyHost = $options[self::PROXY_HOST];
108
+ $proxyPort = isset($options[self::PROXY_PORT]) ? $options[self::PROXY_PORT] : 8080;
109
+ $proxyCredentials = isset($options[self::PROXY_CREDENTIALS]) ? $options[self::PROXY_CREDENTIALS] : '';
110
+
111
+ $this->_storageClient->setProxy(true, $proxyHost, $proxyPort, $proxyCredentials);
112
+ }
113
+
114
+ if (isset($options[self::HTTP_ADAPTER])) {
115
+ $this->_storageClient->setHttpClientChannel($options[self::HTTP_ADAPTER]);
116
+ }
117
+
118
+ // Set container
119
+ $this->_container = $options[self::CONTAINER];
120
+
121
+ // Make sure the container exists
122
+ if (!$this->_storageClient->containerExists($this->_container)) {
123
+ $this->_storageClient->createContainer($this->_container);
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Get an item from the storage service.
129
+ *
130
+ * @param string $path
131
+ * @param array $options
132
+ * @return mixed
133
+ */
134
+ public function fetchItem($path, $options = null)
135
+ {
136
+ // Options
137
+ $returnType = self::RETURN_STRING;
138
+ $returnPath = tempnam('', 'azr');
139
+ $openMode = 'r';
140
+
141
+ // Parse options
142
+ if (is_array($options)) {
143
+ if (isset($options[self::RETURN_TYPE])) {
144
+ $returnType = $options[self::RETURN_TYPE];
145
+ }
146
+
147
+ if (isset($options[self::RETURN_PATHNAME])) {
148
+ $returnPath = $options[self::RETURN_PATHNAME];
149
+ }
150
+
151
+ if (isset($options[self::RETURN_OPENMODE])) {
152
+ $openMode = $options[self::RETURN_OPENMODE];
153
+ }
154
+ }
155
+
156
+ // Fetch the blob
157
+ try {
158
+ $this->_storageClient->getBlob(
159
+ $this->_container,
160
+ $path,
161
+ $returnPath
162
+ );
163
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
164
+ if (strpos($e->getMessage(), "does not exist") !== false) {
165
+ return false;
166
+ }
167
+ throw new Zend_Cloud_StorageService_Exception('Error on fetch: '.$e->getMessage(), $e->getCode(), $e);
168
+ }
169
+
170
+ // Return value
171
+ if ($returnType == self::RETURN_PATH) {
172
+ return $returnPath;
173
+ }
174
+ if ($returnType == self::RETURN_STRING) {
175
+ return file_get_contents($returnPath);
176
+ }
177
+ if ($returnType == self::RETURN_STREAM) {
178
+ return fopen($returnPath, $openMode);
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Store an item in the storage service.
184
+ * WARNING: This operation overwrites any item that is located at
185
+ * $destinationPath.
186
+ * @param string $destinationPath
187
+ * @param mixed $data
188
+ * @param array $options
189
+ * @return boolean
190
+ */
191
+ public function storeItem($destinationPath, $data, $options = null)
192
+ {
193
+ // Create a temporary file that will be uploaded
194
+ $temporaryFilePath = '';
195
+ $removeTemporaryFilePath = false;
196
+
197
+ if (is_resource($data)) {
198
+ $temporaryFilePath = tempnam('', 'azr');
199
+ $fpDestination = fopen($temporaryFilePath, 'w');
200
+
201
+ $fpSource = $data;
202
+ rewind($fpSource);
203
+ while (!feof($fpSource)) {
204
+ fwrite($fpDestination, fread($fpSource, 8192));
205
+ }
206
+
207
+ fclose($fpDestination);
208
+
209
+ $removeTemporaryFilePath = true;
210
+ } elseif (file_exists($data)) {
211
+ $temporaryFilePath = $data;
212
+ $removeTemporaryFilePath = false;
213
+ } else {
214
+ $temporaryFilePath = tempnam('', 'azr');
215
+ file_put_contents($temporaryFilePath, $data);
216
+ $removeTemporaryFilePath = true;
217
+ }
218
+
219
+ try {
220
+ // Upload data
221
+ $this->_storageClient->putBlob(
222
+ $this->_container,
223
+ $destinationPath,
224
+ $temporaryFilePath
225
+ );
226
+ } catch(Zend_Service_WindowsAzure_Exception $e) {
227
+ @unlink($temporaryFilePath);
228
+ throw new Zend_Cloud_StorageService_Exception('Error on store: '.$e->getMessage(), $e->getCode(), $e);
229
+ }
230
+ if ($removeTemporaryFilePath) {
231
+ @unlink($temporaryFilePath);
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Delete an item in the storage service.
237
+ *
238
+ * @param string $path
239
+ * @param array $options
240
+ * @return void
241
+ */
242
+ public function deleteItem($path, $options = null)
243
+ {
244
+ try {
245
+ $this->_storageClient->deleteBlob(
246
+ $this->_container,
247
+ $path
248
+ );
249
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
250
+ throw new Zend_Cloud_StorageService_Exception('Error on delete: '.$e->getMessage(), $e->getCode(), $e);
251
+ }
252
+ }
253
+
254
+ /**
255
+ * Copy an item in the storage service to a given path.
256
+ *
257
+ * @param string $sourcePath
258
+ * @param string $destinationPath
259
+ * @param array $options
260
+ * @return void
261
+ */
262
+ public function copyItem($sourcePath, $destinationPath, $options = null)
263
+ {
264
+ try {
265
+ $this->_storageClient->copyBlob(
266
+ $this->_container,
267
+ $sourcePath,
268
+ $this->_container,
269
+ $destinationPath
270
+ );
271
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
272
+ throw new Zend_Cloud_StorageService_Exception('Error on copy: '.$e->getMessage(), $e->getCode(), $e);
273
+ }
274
+ }
275
+
276
+ /**
277
+ * Move an item in the storage service to a given path.
278
+ *
279
+ * @param string $sourcePath
280
+ * @param string $destinationPath
281
+ * @param array $options
282
+ * @return void
283
+ */
284
+ public function moveItem($sourcePath, $destinationPath, $options = null)
285
+ {
286
+ try {
287
+ $this->_storageClient->copyBlob(
288
+ $this->_container,
289
+ $sourcePath,
290
+ $this->_container,
291
+ $destinationPath
292
+ );
293
+
294
+ $this->_storageClient->deleteBlob(
295
+ $this->_container,
296
+ $sourcePath
297
+ );
298
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
299
+ throw new Zend_Cloud_StorageService_Exception('Error on move: '.$e->getMessage(), $e->getCode(), $e);
300
+ }
301
+
302
+ }
303
+
304
+ /**
305
+ * Rename an item in the storage service to a given name.
306
+ *
307
+ *
308
+ * @param string $path
309
+ * @param string $name
310
+ * @param array $options
311
+ * @return void
312
+ */
313
+ public function renameItem($path, $name, $options = null)
314
+ {
315
+ return $this->moveItem($path, $name, $options);
316
+ }
317
+
318
+ /**
319
+ * List items in the given directory in the storage service
320
+ *
321
+ * The $path must be a directory
322
+ *
323
+ *
324
+ * @param string $path Must be a directory
325
+ * @param array $options
326
+ * @return array A list of item names
327
+ */
328
+ public function listItems($path, $options = null)
329
+ {
330
+ // Options
331
+ $returnType = self::RETURN_NAMES; // 1: return list of paths, 2: return raw output from underlying provider
332
+
333
+ // Parse options
334
+ if (is_array($options)&& isset($options[self::RETURN_TYPE])) {
335
+ $returnType = $options[self::RETURN_TYPE];
336
+ }
337
+
338
+ try {
339
+ // Fetch list
340
+ $blobList = $this->_storageClient->listBlobs(
341
+ $this->_container,
342
+ $path
343
+ );
344
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
345
+ throw new Zend_Cloud_StorageService_Exception('Error on list: '.$e->getMessage(), $e->getCode(), $e);
346
+ }
347
+
348
+ // Return
349
+ if ($returnType == self::RETURN_LIST) {
350
+ return $blobList;
351
+ }
352
+
353
+ $returnValue = array();
354
+ foreach ($blobList as $blob) {
355
+ $returnValue[] = $blob->Name;
356
+ }
357
+
358
+ return $returnValue;
359
+ }
360
+
361
+ /**
362
+ * Get a key/value array of metadata for the given path.
363
+ *
364
+ * @param string $path
365
+ * @param array $options
366
+ * @return array
367
+ */
368
+ public function fetchMetadata($path, $options = null)
369
+ {
370
+ try {
371
+ return $this->_storageClient->getBlobMetaData(
372
+ $this->_container,
373
+ $path
374
+ );
375
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
376
+ if (strpos($e->getMessage(), "could not be accessed") !== false) {
377
+ return false;
378
+ }
379
+ throw new Zend_Cloud_StorageService_Exception('Error on fetch: '.$e->getMessage(), $e->getCode(), $e);
380
+ }
381
+ }
382
+
383
+ /**
384
+ * Store a key/value array of metadata at the given path.
385
+ * WARNING: This operation overwrites any metadata that is located at
386
+ * $destinationPath.
387
+ *
388
+ * @param string $destinationPath
389
+ * @param array $options
390
+ * @return void
391
+ */
392
+ public function storeMetadata($destinationPath, $metadata, $options = null)
393
+ {
394
+ try {
395
+ $this->_storageClient->setBlobMetadata($this->_container, $destinationPath, $metadata);
396
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
397
+ if (strpos($e->getMessage(), "could not be accessed") === false) {
398
+ throw new Zend_Cloud_StorageService_Exception('Error on store metadata: '.$e->getMessage(), $e->getCode(), $e);
399
+ }
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Delete a key/value array of metadata at the given path.
405
+ *
406
+ * @param string $path
407
+ * @param array $options
408
+ * @return void
409
+ */
410
+ public function deleteMetadata($path, $options = null)
411
+ {
412
+ try {
413
+ $this->_storageClient->setBlobMetadata($this->_container, $destinationPath, array());
414
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
415
+ if (strpos($e->getMessage(), "could not be accessed") === false) {
416
+ throw new Zend_Cloud_StorageService_Exception('Error on delete metadata: '.$e->getMessage(), $e->getCode(), $e);
417
+ }
418
+ }
419
+ }
420
+
421
+ /**
422
+ * Delete container
423
+ *
424
+ * @return void
425
+ */
426
+ public function deleteContainer()
427
+ {
428
+ try {
429
+ $this->_storageClient->deleteContainer($this->_container);
430
+ } catch (Zend_Service_WindowsAzure_Exception $e) {
431
+ throw new Zend_Cloud_StorageService_Exception('Error on delete: '.$e->getMessage(), $e->getCode(), $e);
432
+ }
433
+ }
434
+
435
+ /**
436
+ * Get the concrete adapter.
437
+ * @return Zend_Service_Azure_Storage_Blob
438
+ */
439
+ public function getClient()
440
+ {
441
+ return $this->_storageClient;
442
+ }
443
+ }
lib/Zend/Cloud/StorageService/Exception.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Cloud
17
+ * @subpackage StorageService
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+
23
+ /**
24
+ * Zend_Cloud_Exception
25
+ */
26
+ #require_once 'Zend/Cloud/Exception.php';
27
+
28
+
29
+ /**
30
+ * @category Zend
31
+ * @package Zend_Cloud
32
+ * @subpackage StorageService
33
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
+ * @license http://framework.zend.com/license/new-bsd New BSD License
35
+ */
36
+ class Zend_Cloud_StorageService_Exception extends Zend_Cloud_Exception
37
+ {}
38
+
lib/Zend/Cloud/StorageService/Factory.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Cloud
17
+ * @subpackage StorageService
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Cloud/AbstractFactory.php';
23
+
24
+ /**
25
+ * @category Zend
26
+ * @package Zend_Cloud
27
+ * @subpackage StorageService
28
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
29
+ * @license http://framework.zend.com/license/new-bsd New BSD License
30
+ */
31
+ class Zend_Cloud_StorageService_Factory extends Zend_Cloud_AbstractFactory
32
+ {
33
+ const STORAGE_ADAPTER_KEY = 'storage_adapter';
34
+
35
+ /**
36
+ * @var string Interface which adapter must implement to be considered valid
37
+ */
38
+ protected static $_adapterInterface = 'Zend_Cloud_StorageService_Adapter';
39
+ /**
40
+ * Constructor
41
+ *
42
+ * @return void
43
+ */
44
+ private function __construct()
45
+ {
46
+ // private ctor - should not be used
47
+ }
48
+
49
+ /**
50
+ * Retrieve StorageService adapter
51
+ *
52
+ * @param array $options
53
+ * @return void
54
+ */
55
+ public static function getAdapter($options = array())
56
+ {
57
+ $adapter = parent::_getAdapter(self::STORAGE_ADAPTER_KEY, $options);
58
+ if (!$adapter) {
59
+ #require_once 'Zend/Cloud/StorageService/Exception.php';
60
+ throw new Zend_Cloud_StorageService_Exception('Class must be specified using the \'' .
61
+ self::STORAGE_ADAPTER_KEY . '\' key');
62
+ } elseif (!$adapter instanceof self::$_adapterInterface) {
63
+ #require_once 'Zend/Cloud/StorageService/Exception.php';
64
+ throw new Zend_Cloud_StorageService_Exception(
65
+ 'Adapter must implement \'' . self::$_adapterInterface . '\''
66
+ );
67
+ }
68
+ return $adapter;
69
+ }
70
+ }
lib/Zend/CodeGenerator/Php/Class.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage PHP
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Class.php 21916 2010-04-16 20:41:42Z matthew $
21
  */
22
 
23
  /**
17
  * @subpackage PHP
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Class.php 21915 2010-04-16 20:40:15Z matthew $
21
  */
22
 
23
  /**
lib/Zend/CodeGenerator/Php/Parameter.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage PHP
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Parameter.php 22765 2010-08-02 03:13:29Z ramon $
21
  */
22
 
23
  /**
17
  * @subpackage PHP
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Parameter.php 21889 2010-04-16 18:40:50Z juokaz $
21
  */
22
 
23
  /**
lib/Zend/CodeGenerator/Php/Property/DefaultValue.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage PHP
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: DefaultValue.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -94,6 +94,8 @@ class Zend_CodeGenerator_Php_Property_DefaultValue extends Zend_CodeGenerator_Ph
94
  {
95
  if ($this->_type == self::TYPE_AUTO) {
96
  $type = $this->_getAutoDeterminedType($this->_value);
 
 
97
  }
98
 
99
  // valid types for constants
17
  * @subpackage PHP
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: DefaultValue.php 21979 2010-04-24 11:07:11Z jan $
21
  */
22
 
23
  /**
94
  {
95
  if ($this->_type == self::TYPE_AUTO) {
96
  $type = $this->_getAutoDeterminedType($this->_value);
97
+ } else {
98
+ $type = $this->_type;
99
  }
100
 
101
  // valid types for constants
lib/Zend/Config/Json.php ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Config
17
+ * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Json.php 23294 2010-11-05 00:27:34Z ramon $
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Config
24
+ */
25
+ #require_once 'Zend/Config.php';
26
+
27
+ /**
28
+ * @see Zend_Json
29
+ */
30
+ #require_once 'Zend/Json.php';
31
+
32
+ /**
33
+ * JSON Adapter for Zend_Config
34
+ *
35
+ * @category Zend
36
+ * @package Zend_Config
37
+ * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
38
+ * @license http://framework.zend.com/license/new-bsd New BSD License
39
+ */
40
+ class Zend_Config_Json extends Zend_Config
41
+ {
42
+ /**
43
+ * Name of object key indicating section current section extends
44
+ */
45
+ const EXTENDS_NAME = "_extends";
46
+
47
+ /**
48
+ * Whether or not to ignore constants in the JSON string
49
+ *
50
+ * Note: if you do not have constant names in quotations in your JSON
51
+ * string, they may lead to syntax errors when parsing.
52
+ *
53
+ * @var bool
54
+ */
55
+ protected $_ignoreConstants = false;
56
+
57
+ /**
58
+ * Whether to skip extends or not
59
+ *
60
+ * @var boolean
61
+ */
62
+ protected $_skipExtends = false;
63
+
64
+ /**
65
+ * Loads the section $section from the config file encoded as JSON
66
+ *
67
+ * Sections are defined as properties of the main object
68
+ *
69
+ * In order to extend another section, a section defines the "_extends"
70
+ * property having a value of the section name from which the extending
71
+ * section inherits values.
72
+ *
73
+ * Note that the keys in $section will override any keys of the same
74
+ * name in the sections that have been included via "_extends".
75
+ *
76
+ * @param string $json JSON file or string to process
77
+ * @param mixed $section Section to process
78
+ * @param boolean $options Whether modifiacations are allowed at runtime
79
+ * @throws Zend_Config_Exception When JSON text is not set or cannot be loaded
80
+ * @throws Zend_Config_Exception When section $sectionName cannot be found in $json
81
+ */
82
+ public function __construct($json, $section = null, $options = false)
83
+ {
84
+ if (empty($json)) {
85
+ #require_once 'Zend/Config/Exception.php';
86
+ throw new Zend_Config_Exception('Filename is not set');
87
+ }
88
+
89
+ $allowModifications = false;
90
+ if (is_bool($options)) {
91
+ $allowModifications = $options;
92
+ } elseif (is_array($options)) {
93
+ foreach ($options as $key => $value) {
94
+ switch (strtolower($key)) {
95
+ case 'allow_modifications':
96
+ case 'allowmodifications':
97
+ $allowModifications = (bool) $value;
98
+ break;
99
+ case 'skip_extends':
100
+ case 'skipextends':
101
+ $this->_skipExtends = (bool) $value;
102
+ break;
103
+ case 'ignore_constants':
104
+ case 'ignoreconstants':
105
+ $this->_ignoreConstants = (bool) $value;
106
+ break;
107
+ default:
108
+ break;
109
+ }
110
+ }
111
+ }
112
+
113
+ set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed
114
+ if ($json[0] != '{') {
115
+ $json = file_get_contents($json);
116
+ }
117
+ restore_error_handler();
118
+
119
+ // Check if there was a error while loading file
120
+ if ($this->_loadFileErrorStr !== null) {
121
+ #require_once 'Zend/Config/Exception.php';
122
+ throw new Zend_Config_Exception($this->_loadFileErrorStr);
123
+ }
124
+
125
+ // Replace constants
126
+ if (!$this->_ignoreConstants) {
127
+ $json = $this->_replaceConstants($json);
128
+ }
129
+
130
+ // Parse/decode
131
+ $config = Zend_Json::decode($json);
132
+
133
+ if (null === $config) {
134
+ // decode failed
135
+ #require_once 'Zend/Config/Exception.php';
136
+ throw new Zend_Config_Exception("Error parsing JSON data");
137
+ }
138
+
139
+ if ($section === null) {
140
+ $dataArray = array();
141
+ foreach ($config as $sectionName => $sectionData) {
142
+ $dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
143
+ }
144
+
145
+ parent::__construct($dataArray, $allowModifications);
146
+ } elseif (is_array($section)) {
147
+ $dataArray = array();
148
+ foreach ($section as $sectionName) {
149
+ if (!isset($config[$sectionName])) {
150
+ #require_once 'Zend/Config/Exception.php';
151
+ throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $sectionName));
152
+ }
153
+
154
+ $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
155
+ }
156
+
157
+ parent::__construct($dataArray, $allowModifications);
158
+ } else {
159
+ if (!isset($config[$section])) {
160
+ #require_once 'Zend/Config/Exception.php';
161
+ throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
162
+ }
163
+
164
+ $dataArray = $this->_processExtends($config, $section);
165
+ if (!is_array($dataArray)) {
166
+ // Section in the JSON data contains just one top level string
167
+ $dataArray = array($section => $dataArray);
168
+ }
169
+
170
+ parent::__construct($dataArray, $allowModifications);
171
+ }
172
+
173
+ $this->_loadedSection = $section;
174
+ }
175
+
176
+ /**
177
+ * Helper function to process each element in the section and handle
178
+ * the "_extends" inheritance attribute.
179
+ *
180
+ * @param array $data Data array to process
181
+ * @param string $section Section to process
182
+ * @param array $config Configuration which was parsed yet
183
+ * @throws Zend_Config_Exception When $section cannot be found
184
+ * @return array
185
+ */
186
+ protected function _processExtends(array $data, $section, array $config = array())
187
+ {
188
+ if (!isset($data[$section])) {
189
+ #require_once 'Zend/Config/Exception.php';
190
+ throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
191
+ }
192
+
193
+ $thisSection = $data[$section];
194
+
195
+ if (is_array($thisSection) && isset($thisSection[self::EXTENDS_NAME])) {
196
+ if (is_array($thisSection[self::EXTENDS_NAME])) {
197
+ #require_once 'Zend/Config/Exception.php';
198
+ throw new Zend_Config_Exception('Invalid extends clause: must be a string; array received');
199
+ }
200
+ $this->_assertValidExtend($section, $thisSection[self::EXTENDS_NAME]);
201
+
202
+ if (!$this->_skipExtends) {
203
+ $config = $this->_processExtends($data, $thisSection[self::EXTENDS_NAME], $config);
204
+ }
205
+ unset($thisSection[self::EXTENDS_NAME]);
206
+ }
207
+
208
+ $config = $this->_arrayMergeRecursive($config, $thisSection);
209
+
210
+ return $config;
211
+ }
212
+
213
+ /**
214
+ * Replace any constants referenced in a string with their values
215
+ *
216
+ * @param string $value
217
+ * @return string
218
+ */
219
+ protected function _replaceConstants($value)
220
+ {
221
+ foreach ($this->_getConstants() as $constant) {
222
+ if (strstr($value, $constant)) {
223
+ $value = str_replace($constant, constant($constant), $value);
224
+ }
225
+ }
226
+ return $value;
227
+ }
228
+
229
+ /**
230
+ * Get (reverse) sorted list of defined constant names
231
+ *
232
+ * @return array
233
+ */
234
+ protected function _getConstants()
235
+ {
236
+ $constants = array_keys(get_defined_constants());
237
+ rsort($constants, SORT_STRING);
238
+ return $constants;
239
+ }
240
+ }
lib/Zend/Config/Writer/Ini.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Config
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Ini.php 22869 2010-08-21 13:57:59Z ramon $
20
  */
21
 
22
  /**
16
  * @package Zend_Config
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Ini.php 21983 2010-04-25 08:09:09Z jan $
20
  */
21
 
22
  /**
lib/Zend/Config/Writer/Json.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Config
17
+ * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Json.php 23294 2010-11-05 00:27:34Z ramon $
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Config_Writer
24
+ */
25
+ #require_once 'Zend/Config/Writer/FileAbstract.php';
26
+
27
+ /**
28
+ * @see Zend_Config_Json
29
+ */
30
+ #require_once 'Zend/Config/Json.php';
31
+
32
+ /**
33
+ * @category Zend
34
+ * @package Zend_Config
35
+ * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
36
+ * @license http://framework.zend.com/license/new-bsd New BSD License
37
+ */
38
+ class Zend_Config_Writer_Json extends Zend_Config_Writer_FileAbstract
39
+ {
40
+ /**
41
+ * If we need to pretty-print JSON data
42
+ *
43
+ * @var boolean
44
+ */
45
+ protected $_prettyPrint = false;
46
+
47
+ /**
48
+ * Get prettyPrint flag
49
+ *
50
+ * @return the prettyPrint flag
51
+ */
52
+ public function prettyPrint()
53
+ {
54
+ return $this->_prettyPrint;
55
+ }
56
+
57
+ /**
58
+ * Set prettyPrint flag
59
+ *
60
+ * @param bool $prettyPrint PrettyPrint flag
61
+ * @return Zend_Config_Writer_Json
62
+ */
63
+ public function setPrettyPrint($flag)
64
+ {
65
+ $this->_prettyPrint = (bool) $flag;
66
+ return $this;
67
+ }
68
+
69
+ /**
70
+ * Render a Zend_Config into a JSON config string.
71
+ *
72
+ * @since 1.10
73
+ * @return string
74
+ */
75
+ public function render()
76
+ {
77
+ $data = $this->_config->toArray();
78
+ $sectionName = $this->_config->getSectionName();
79
+ $extends = $this->_config->getExtends();
80
+
81
+ if (is_string($sectionName)) {
82
+ $data = array($sectionName => $data);
83
+ }
84
+
85
+ foreach ($extends as $section => $parentSection) {
86
+ $data[$section][Zend_Config_Json::EXTENDS_NAME] = $parentSection;
87
+ }
88
+
89
+ // Ensure that each "extends" section actually exists
90
+ foreach ($data as $section => $sectionData) {
91
+ if (is_array($sectionData) && isset($sectionData[Zend_Config_Json::EXTENDS_NAME])) {
92
+ $sectionExtends = $sectionData[Zend_Config_Json::EXTENDS_NAME];
93
+ if (!isset($data[$sectionExtends])) {
94
+ // Remove "extends" declaration if section does not exist
95
+ unset($data[$section][Zend_Config_Json::EXTENDS_NAME]);
96
+ }
97
+ }
98
+ }
99
+
100
+ $out = Zend_Json::encode($data);
101
+ if ($this->prettyPrint()) {
102
+ $out = Zend_Json::prettyPrint($out);
103
+ }
104
+ return $out;
105
+ }
106
+ }
lib/Zend/Config/Writer/Yaml.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Config
17
+ * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Yaml.php 23294 2010-11-05 00:27:34Z ramon $
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Config_Writer
24
+ */
25
+ #require_once 'Zend/Config/Writer/FileAbstract.php';
26
+
27
+ /**
28
+ * @see Zend_Config_Yaml
29
+ */
30
+ #require_once 'Zend/Config/Yaml.php';
31
+
32
+ /**
33
+ * @category Zend
34
+ * @package Zend_Config
35
+ * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
36
+ * @license http://framework.zend.com/license/new-bsd New BSD License
37
+ */
38
+ class Zend_Config_Writer_Yaml extends Zend_Config_Writer_FileAbstract
39
+ {
40
+ /**
41
+ * What to call when we need to decode some YAML?
42
+ *
43
+ * @var callable
44
+ */
45
+ protected $_yamlEncoder = array('Zend_Config_Writer_Yaml', 'encode');
46
+
47
+ /**
48
+ * Get callback for decoding YAML
49
+ *
50
+ * @return callable
51
+ */
52
+ public function getYamlEncoder()
53
+ {
54
+ return $this->_yamlEncoder;
55
+ }
56
+
57
+ /**
58
+ * Set callback for decoding YAML
59
+ *
60
+ * @param $yamlEncoder the decoder to set
61
+ * @return Zend_Config_Yaml
62
+ */
63
+ public function setYamlEncoder($yamlEncoder)
64
+ {
65
+ if (!is_callable($yamlEncoder)) {
66
+ #require_once 'Zend/Config/Exception.php';
67
+ throw new Zend_Config_Exception('Invalid parameter to setYamlEncoder - must be callable');
68
+ }
69
+
70
+ $this->_yamlEncoder = $yamlEncoder;
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * Render a Zend_Config into a YAML config string.
76
+ *
77
+ * @since 1.10
78
+ * @return string
79
+ */
80
+ public function render()
81
+ {
82
+ $data = $this->_config->toArray();
83
+ $sectionName = $this->_config->getSectionName();
84
+ $extends = $this->_config->getExtends();
85
+
86
+ if (is_string($sectionName)) {
87
+ $data = array($sectionName => $data);
88
+ }
89
+
90
+ foreach ($extends as $section => $parentSection) {
91
+ $data[$section][Zend_Config_Yaml::EXTENDS_NAME] = $parentSection;
92
+ }
93
+
94
+ // Ensure that each "extends" section actually exists
95
+ foreach ($data as $section => $sectionData) {
96
+ if (is_array($sectionData) && isset($sectionData[Zend_Config_Yaml::EXTENDS_NAME])) {
97
+ $sectionExtends = $sectionData[Zend_Config_Yaml::EXTENDS_NAME];
98
+ if (!isset($data[$sectionExtends])) {
99
+ // Remove "extends" declaration if section does not exist
100
+ unset($data[$section][Zend_Config_Yaml::EXTENDS_NAME]);
101
+ }
102
+ }
103
+ }
104
+
105
+ return call_user_func($this->getYamlEncoder(), $data);
106
+ }
107
+
108
+ /**
109
+ * Very dumb YAML encoder
110
+ *
111
+ * Until we have Zend_Yaml...
112
+ *
113
+ * @param array $data YAML data
114
+ * @return string
115
+ */
116
+ public static function encode($data)
117
+ {
118
+ return self::_encodeYaml(0, $data);
119
+ }
120
+
121
+ /**
122
+ * Service function for encoding YAML
123
+ *
124
+ * @param int $indent Current indent level
125
+ * @param array $data Data to encode
126
+ * @return string
127
+ */
128
+ protected static function _encodeYaml($indent, $data)
129
+ {
130
+ reset($data);
131
+ $result = "";
132
+ $numeric = is_numeric(key($data));
133
+
134
+ foreach($data as $key => $value) {
135
+ if(is_array($value)) {
136
+ $encoded = "\n".self::_encodeYaml($indent+1, $value);
137
+ } else {
138
+ $encoded = (string)$value."\n";
139
+ }
140
+ $result .= str_repeat(" ", $indent).($numeric?"- ":"$key: ").$encoded;
141
+ }
142
+ return $result;
143
+ }
144
+ }
lib/Zend/Config/Yaml.php ADDED
@@ -0,0 +1,382 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Config
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Yaml.php 23294 2010-11-05 00:27:34Z ramon $
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Config
24
+ */
25
+ #require_once 'Zend/Config.php';
26
+
27
+ /**
28
+ * YAML Adapter for Zend_Config
29
+ *
30
+ * @category Zend
31
+ * @package Zend_Config
32
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33
+ * @license http://framework.zend.com/license/new-bsd New BSD License
34
+ */
35
+ class Zend_Config_Yaml extends Zend_Config
36
+ {
37
+ /**
38
+ * Attribute name that indicates what section a config extends from
39
+ */
40
+ const EXTENDS_NAME = "_extends";
41
+
42
+ /**
43
+ * Whether to skip extends or not
44
+ *
45
+ * @var boolean
46
+ */
47
+ protected $_skipExtends = false;
48
+
49
+ /**
50
+ * What to call when we need to decode some YAML?
51
+ *
52
+ * @var callable
53
+ */
54
+ protected $_yamlDecoder = array(__CLASS__, 'decode');
55
+
56
+ /**
57
+ * Whether or not to ignore constants in parsed YAML
58
+ * @var bool
59
+ */
60
+ protected static $_ignoreConstants = false;
61
+
62
+ /**
63
+ * Indicate whether parser should ignore constants or not
64
+ *
65
+ * @param bool $flag
66
+ * @return void
67
+ */
68
+ public static function setIgnoreConstants($flag)
69
+ {
70
+ self::$_ignoreConstants = (bool) $flag;
71
+ }
72
+
73
+ /**
74
+ * Whether parser should ignore constants or not
75
+ *
76
+ * @return bool
77
+ */
78
+ public static function ignoreConstants()
79
+ {
80
+ return self::$_ignoreConstants;
81
+ }
82
+
83
+ /**
84
+ * Get callback for decoding YAML
85
+ *
86
+ * @return callable
87
+ */
88
+ public function getYamlDecoder()
89
+ {
90
+ return $this->_yamlDecoder;
91
+ }
92
+
93
+ /**
94
+ * Set callback for decoding YAML
95
+ *
96
+ * @param $yamlDecoder the decoder to set
97
+ * @return Zend_Config_Yaml
98
+ */
99
+ public function setYamlDecoder($yamlDecoder)
100
+ {
101
+ if (!is_callable($yamlDecoder)) {
102
+ #require_once 'Zend/Config/Exception.php';
103
+ throw new Zend_Config_Exception('Invalid parameter to setYamlDecoder() - must be callable');
104
+ }
105
+
106
+ $this->_yamlDecoder = $yamlDecoder;
107
+ return $this;
108
+ }
109
+
110
+ /**
111
+ * Loads the section $section from the config file encoded as YAML
112
+ *
113
+ * Sections are defined as properties of the main object
114
+ *
115
+ * In order to extend another section, a section defines the "_extends"
116
+ * property having a value of the section name from which the extending
117
+ * section inherits values.
118
+ *
119
+ * Note that the keys in $section will override any keys of the same
120
+ * name in the sections that have been included via "_extends".
121
+ *
122
+ * Options may include:
123
+ * - allow_modifications: whether or not the config object is mutable
124
+ * - skip_extends: whether or not to skip processing of parent configuration
125
+ * - yaml_decoder: a callback to use to decode the Yaml source
126
+ *
127
+ * @param string $yaml YAML file to process
128
+ * @param mixed $section Section to process
129
+ * @param boolean $options Whether modifiacations are allowed at runtime
130
+ */
131
+ public function __construct($yaml, $section = null, $options = false)
132
+ {
133
+ if (empty($yaml)) {
134
+ #require_once 'Zend/Config/Exception.php';
135
+ throw new Zend_Config_Exception('Filename is not set');
136
+ }
137
+
138
+ $ignoreConstants = $staticIgnoreConstants = self::ignoreConstants();
139
+ $allowModifications = false;
140
+ if (is_bool($options)) {
141
+ $allowModifications = $options;
142
+ } elseif (is_array($options)) {
143
+ foreach ($options as $key => $value) {
144
+ switch (strtolower($key)) {
145
+ case 'allow_modifications':
146
+ case 'allowmodifications':
147
+ $allowModifications = (bool) $value;
148
+ break;
149
+ case 'skip_extends':
150
+ case 'skipextends':
151
+ $this->_skipExtends = (bool) $value;
152
+ break;
153
+ case 'ignore_constants':
154
+ case 'ignoreconstants':
155
+ $ignoreConstants = (bool) $value;
156
+ break;
157
+ case 'yaml_decoder':
158
+ case 'yamldecoder':
159
+ $this->setYamlDecoder($value);
160
+ break;
161
+ default:
162
+ break;
163
+ }
164
+ }
165
+ }
166
+
167
+ // Suppress warnings and errors while loading file
168
+ set_error_handler(array($this, '_loadFileErrorHandler'));
169
+ $yaml = file_get_contents($yaml);
170
+ restore_error_handler();
171
+
172
+ // Check if there was a error while loading file
173
+ if ($this->_loadFileErrorStr !== null) {
174
+ #require_once 'Zend/Config/Exception.php';
175
+ throw new Zend_Config_Exception($this->_loadFileErrorStr);
176
+ }
177
+
178
+ // Override static value for ignore_constants if provided in $options
179
+ self::setIgnoreConstants($ignoreConstants);
180
+
181
+ // Parse YAML
182
+ $config = call_user_func($this->getYamlDecoder(), $yaml);
183
+
184
+ // Reset original static state of ignore_constants
185
+ self::setIgnoreConstants($staticIgnoreConstants);
186
+
187
+ if (null === $config) {
188
+ // decode failed
189
+ #require_once 'Zend/Config/Exception.php';
190
+ throw new Zend_Config_Exception("Error parsing YAML data");
191
+ }
192
+
193
+ if (null === $section) {
194
+ $dataArray = array();
195
+ foreach ($config as $sectionName => $sectionData) {
196
+ $dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
197
+ }
198
+ parent::__construct($dataArray, $allowModifications);
199
+ } elseif (is_array($section)) {
200
+ $dataArray = array();
201
+ foreach ($section as $sectionName) {
202
+ if (!isset($config[$sectionName])) {
203
+ #require_once 'Zend/Config/Exception.php';
204
+ throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
205
+ }
206
+
207
+ $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
208
+ }
209
+ parent::__construct($dataArray, $allowModifications);
210
+ } else {
211
+ if (!isset($config[$section])) {
212
+ #require_once 'Zend/Config/Exception.php';
213
+ throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
214
+ }
215
+
216
+ $dataArray = $this->_processExtends($config, $section);
217
+ if (!is_array($dataArray)) {
218
+ // Section in the yaml data contains just one top level string
219
+ $dataArray = array($section => $dataArray);
220
+ }
221
+ parent::__construct($dataArray, $allowModifications);
222
+ }
223
+
224
+ $this->_loadedSection = $section;
225
+ }
226
+
227
+ /**
228
+ * Helper function to process each element in the section and handle
229
+ * the "_extends" inheritance attribute.
230
+ *
231
+ * @param array $data Data array to process
232
+ * @param string $section Section to process
233
+ * @param array $config Configuration which was parsed yet
234
+ * @return array
235
+ * @throws Zend_Config_Exception When $section cannot be found
236
+ */
237
+ protected function _processExtends(array $data, $section, array $config = array())
238
+ {
239
+ if (!isset($data[$section])) {
240
+ #require_once 'Zend/Config/Exception.php';
241
+ throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
242
+ }
243
+
244
+ $thisSection = $data[$section];
245
+
246
+ if (is_array($thisSection) && isset($thisSection[self::EXTENDS_NAME])) {
247
+ $this->_assertValidExtend($section, $thisSection[self::EXTENDS_NAME]);
248
+
249
+ if (!$this->_skipExtends) {
250
+ $config = $this->_processExtends($data, $thisSection[self::EXTENDS_NAME], $config);
251
+ }
252
+ unset($thisSection[self::EXTENDS_NAME]);
253
+ }
254
+
255
+ $config = $this->_arrayMergeRecursive($config, $thisSection);
256
+
257
+ return $config;
258
+ }
259
+
260
+ /**
261
+ * Very dumb YAML parser
262
+ *
263
+ * Until we have Zend_Yaml...
264
+ *
265
+ * @param string $yaml YAML source
266
+ * @return array Decoded data
267
+ */
268
+ public static function decode($yaml)
269
+ {
270
+ $lines = explode("\n", $yaml);
271
+ reset($lines);
272
+ return self::_decodeYaml(0, $lines);
273
+ }
274
+
275
+ /**
276
+ * Service function to decode YAML
277
+ *
278
+ * @param int $currentIndent Current indent level
279
+ * @param array $lines YAML lines
280
+ * @return array|string
281
+ */
282
+ protected static function _decodeYaml($currentIndent, &$lines)
283
+ {
284
+ $config = array();
285
+ $inIndent = false;
286
+ while (list($n, $line) = each($lines)) {
287
+ $lineno = $n+1;
288
+ if (strlen($line) == 0) {
289
+ continue;
290
+ }
291
+ if ($line[0] == '#') {
292
+ // comment
293
+ continue;
294
+ }
295
+ $indent = strspn($line, " ");
296
+
297
+ // line without the spaces
298
+ $line = trim($line);
299
+ if (strlen($line) == 0) {
300
+ continue;
301
+ }
302
+
303
+ if ($indent < $currentIndent) {
304
+ // this level is done
305
+ prev($lines);
306
+ return $config;
307
+ }
308
+
309
+ if (!$inIndent) {
310
+ $currentIndent = $indent;
311
+ $inIndent = true;
312
+ }
313
+
314
+ if (preg_match("/(\w+):\s*(.*)/", $line, $m)) {
315
+ // key: value
316
+ if ($m[2]) {
317
+ // simple key: value
318
+ $value = $m[2];
319
+ // Check for booleans and constants
320
+ if (preg_match('/^(t(rue)?|on|y(es)?)$/i', $value)) {
321
+ $value = true;
322
+ } elseif (preg_match('/^(f(alse)?|off|n(o)?)$/i', $value)) {
323
+ $value = false;
324
+ } elseif (!self::$_ignoreConstants) {
325
+ // test for constants
326
+ $value = self::_replaceConstants($value);
327
+ }
328
+ } else {
329
+ // key: and then values on new lines
330
+ $value = self::_decodeYaml($currentIndent + 1, $lines);
331
+ if (is_array($value) && !count($value)) {
332
+ $value = "";
333
+ }
334
+ }
335
+ $config[$m[1]] = $value;
336
+ } elseif ($line[0] == "-") {
337
+ // item in the list:
338
+ // - FOO
339
+ if (strlen($line) > 2) {
340
+ $config[] = substr($line, 2);
341
+ } else {
342
+ $config[] = self::_decodeYaml($currentIndent + 1, $lines);
343
+ }
344
+ } else {
345
+ #require_once 'Zend/Config/Exception.php';
346
+ throw new Zend_Config_Exception(sprintf(
347
+ 'Error parsing YAML at line %d - unsupported syntax: "%s"',
348
+ $lineno, $line
349
+ ));
350
+ }
351
+ }
352
+ return $config;
353
+ }
354
+
355
+ /**
356
+ * Replace any constants referenced in a string with their values
357
+ *
358
+ * @param string $value
359
+ * @return string
360
+ */
361
+ protected static function _replaceConstants($value)
362
+ {
363
+ foreach (self::_getConstants() as $constant) {
364
+ if (strstr($value, $constant)) {
365
+ $value = str_replace($constant, constant($constant), $value);
366
+ }
367
+ }
368
+ return $value;
369
+ }
370
+
371
+ /**
372
+ * Get (reverse) sorted list of defined constant names
373
+ *
374
+ * @return array
375
+ */
376
+ protected static function _getConstants()
377
+ {
378
+ $constants = array_keys(get_defined_constants());
379
+ rsort($constants, SORT_STRING);
380
+ return $constants;
381
+ }
382
+ }
lib/Zend/Console/Getopt.php CHANGED
@@ -17,7 +17,7 @@
17
  * @package Zend_Console_Getopt
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Getopt.php 22485 2010-06-25 22:54:25Z ramon $
21
  */
22
 
23
  /**
17
  * @package Zend_Console_Getopt
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Getopt.php 22191 2010-05-17 21:50:14Z jan $
21
  */
22
 
23
  /**
lib/Zend/Controller/Action.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Controller
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Action.php 22793 2010-08-05 18:32:52Z matthew $
20
  */
21
 
22
  /**
16
  * @package Zend_Controller
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Action.php 22792 2010-08-05 18:30:27Z matthew $
20
  */
21
 
22
  /**
lib/Zend/Controller/Action/Helper/Cache.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Controller
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id$
20
  */
21
 
22
  /**
@@ -223,7 +223,7 @@ class Zend_Controller_Action_Helper_Cache
223
  */
224
  public function getManager()
225
  {
226
- if (!is_null($this->_manager)) {
227
  return $this->_manager;
228
  }
229
  $front = Zend_Controller_Front::getInstance();
16
  * @package Zend_Controller
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Cache.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
223
  */
224
  public function getManager()
225
  {
226
+ if ($this->_manager !== null) {
227
  return $this->_manager;
228
  }
229
  $front = Zend_Controller_Front::getInstance();
lib/Zend/Controller/Action/Helper/Redirector.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_Controller_Action_Helper
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Redirector.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -215,7 +215,10 @@ class Zend_Controller_Action_Helper_Redirector extends Zend_Controller_Action_He
215
  $port = (isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:80);
216
  $uri = $proto . '://' . $host;
217
  if ((('http' == $proto) && (80 != $port)) || (('https' == $proto) && (443 != $port))) {
218
- $uri .= ':' . $port;
 
 
 
219
  }
220
  $url = $uri . '/' . ltrim($url, '/');
221
  }
@@ -463,7 +466,7 @@ class Zend_Controller_Action_Helper_Redirector extends Zend_Controller_Action_He
463
  */
464
  public function gotoUrlAndExit($url, array $options = array())
465
  {
466
- $this->gotoUrl($url, $options);
467
  $this->redirectAndExit();
468
  }
469
 
17
  * @subpackage Zend_Controller_Action_Helper
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Redirector.php 23248 2010-10-26 12:45:52Z matthew $
21
  */
22
 
23
  /**
215
  $port = (isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:80);
216
  $uri = $proto . '://' . $host;
217
  if ((('http' == $proto) && (80 != $port)) || (('https' == $proto) && (443 != $port))) {
218
+ // do not append if HTTP_HOST already contains port
219
+ if (strrchr($host, ':') === false) {
220
+ $uri .= ':' . $port;
221
+ }
222
  }
223
  $url = $uri . '/' . ltrim($url, '/');
224
  }
466
  */
467
  public function gotoUrlAndExit($url, array $options = array())
468
  {
469
+ $this->setGotoUrl($url, $options);
470
  $this->redirectAndExit();
471
  }
472
 
lib/Zend/Controller/Dispatcher/Standard.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Dispatcher
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Standard.php 22039 2010-04-28 18:56:43Z matthew $
21
  */
22
 
23
  /** Zend_Loader */
17
  * @subpackage Dispatcher
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Standard.php 22038 2010-04-28 18:54:22Z matthew $
21
  */
22
 
23
  /** Zend_Loader */
lib/Zend/Controller/Request/Http.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Controller
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Http.php 20984 2010-02-08 16:25:08Z matthew $
20
  */
21
 
22
  /** @see Zend_Controller_Request_Abstract */
@@ -551,7 +551,7 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
551
  $this->setBaseUrl();
552
  }
553
 
554
- return $this->_baseUrl;
555
  }
556
 
557
  /**
@@ -622,6 +622,8 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
622
  if ($pos = strpos($requestUri, '?')) {
623
  $requestUri = substr($requestUri, 0, $pos);
624
  }
 
 
625
 
626
  if (null !== $baseUrl
627
  && ((!empty($baseUrl) && 0 === strpos($requestUri, $baseUrl))
@@ -979,7 +981,7 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
979
 
980
  // Try to get it from the $_SERVER array first
981
  $temp = 'HTTP_' . strtoupper(str_replace('-', '_', $header));
982
- if (!empty($_SERVER[$temp])) {
983
  return $_SERVER[$temp];
984
  }
985
 
@@ -987,9 +989,15 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
987
  // Apache
988
  if (function_exists('apache_request_headers')) {
989
  $headers = apache_request_headers();
990
- if (!empty($headers[$header])) {
991
  return $headers[$header];
992
  }
 
 
 
 
 
 
993
  }
994
 
995
  return false;
@@ -1025,7 +1033,10 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
1025
  $name = $this->getServer('SERVER_NAME');
1026
  $port = $this->getServer('SERVER_PORT');
1027
 
1028
- if (($scheme == self::SCHEME_HTTP && $port == 80) || ($scheme == self::SCHEME_HTTPS && $port == 443)) {
 
 
 
1029
  return $name;
1030
  } else {
1031
  return $name . ':' . $port;
16
  * @package Zend_Controller
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Http.php 23414 2010-11-20 10:56:11Z bittarman $
20
  */
21
 
22
  /** @see Zend_Controller_Request_Abstract */
551
  $this->setBaseUrl();
552
  }
553
 
554
+ return urldecode($this->_baseUrl);
555
  }
556
 
557
  /**
622
  if ($pos = strpos($requestUri, '?')) {
623
  $requestUri = substr($requestUri, 0, $pos);
624
  }
625
+
626
+ $requestUri = urldecode($requestUri);
627
 
628
  if (null !== $baseUrl
629
  && ((!empty($baseUrl) && 0 === strpos($requestUri, $baseUrl))
981
 
982
  // Try to get it from the $_SERVER array first
983
  $temp = 'HTTP_' . strtoupper(str_replace('-', '_', $header));
984
+ if (isset($_SERVER[$temp])) {
985
  return $_SERVER[$temp];
986
  }
987
 
989
  // Apache
990
  if (function_exists('apache_request_headers')) {
991
  $headers = apache_request_headers();
992
+ if (isset($headers[$header])) {
993
  return $headers[$header];
994
  }
995
+ $header = strtolower($header);
996
+ foreach ($headers as $key => $value) {
997
+ if (strtolower($key) == $header) {
998
+ return $value;
999
+ }
1000
+ }
1001
  }
1002
 
1003
  return false;
1033
  $name = $this->getServer('SERVER_NAME');
1034
  $port = $this->getServer('SERVER_PORT');
1035
 
1036
+ if(null === $name) {
1037
+ return '';
1038
+ }
1039
+ elseif (($scheme == self::SCHEME_HTTP && $port == 80) || ($scheme == self::SCHEME_HTTPS && $port == 443)) {
1040
  return $name;
1041
  } else {
1042
  return $name . ':' . $port;
lib/Zend/Controller/Response/Abstract.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Controller
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Abstract.php 21302 2010-03-02 23:01:38Z yoshida@zend.co.jp $
20
  */
21
 
22
  /**
16
  * @package Zend_Controller
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Abstract.php 21301 2010-03-02 23:01:19Z yoshida@zend.co.jp $
20
  */
21
 
22
  /**
lib/Zend/Controller/Router/Rewrite.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Controller
17
  * @subpackage Router
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
- * @version $Id: Rewrite.php 22417 2010-06-11 14:15:05Z rob $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
@@ -95,7 +95,7 @@ class Zend_Controller_Router_Rewrite extends Zend_Controller_Router_Abstract
95
  #require_once 'Zend/Controller/Router/Route/Module.php';
96
  $compat = new Zend_Controller_Router_Route_Module(array(), $dispatcher, $request);
97
 
98
- $this->_routes = array_merge(array('default' => $compat), $this->_routes);
99
  }
100
 
101
  return $this;
@@ -382,7 +382,7 @@ class Zend_Controller_Router_Rewrite extends Zend_Controller_Router_Abstract
382
  // Find the matching route
383
  $routeMatched = false;
384
 
385
- foreach (array_reverse($this->_routes) as $name => $route) {
386
  // TODO: Should be an interface method. Hack for 1.0 BC
387
  if (method_exists($route, 'isAbstract') && $route->isAbstract()) {
388
  continue;
16
  * @package Zend_Controller
17
  * @subpackage Router
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @version $Id: Rewrite.php 23362 2010-11-18 17:22:41Z bittarman $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
95
  #require_once 'Zend/Controller/Router/Route/Module.php';
96
  $compat = new Zend_Controller_Router_Route_Module(array(), $dispatcher, $request);
97
 
98
+ $this->_routes = array('default' => $compat) + $this->_routes;
99
  }
100
 
101
  return $this;
382
  // Find the matching route
383
  $routeMatched = false;
384
 
385
+ foreach (array_reverse($this->_routes, true) as $name => $route) {
386
  // TODO: Should be an interface method. Hack for 1.0 BC
387
  if (method_exists($route, 'isAbstract') && $route->isAbstract()) {
388
  continue;
lib/Zend/Controller/Router/Route/Chain.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Controller
17
  * @subpackage Router
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
- * @version $Id: Chain.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
@@ -77,7 +77,11 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
77
  $values = array();
78
 
79
  foreach ($this->_routes as $key => $route) {
80
- if ($key > 0 && $matchedPath !== null) {
 
 
 
 
81
  $separator = substr($subPath, 0, strlen($this->_separators[$key]));
82
 
83
  if ($separator !== $this->_separators[$key]) {
16
  * @package Zend_Controller
17
  * @subpackage Router
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @version $Id: Chain.php 23187 2010-10-20 18:42:37Z matthew $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
77
  $values = array();
78
 
79
  foreach ($this->_routes as $key => $route) {
80
+ if ($key > 0
81
+ && $matchedPath !== null
82
+ && $subPath !== ''
83
+ && $subPath !== false
84
+ ) {
85
  $separator = substr($subPath, 0, strlen($this->_separators[$key]));
86
 
87
  if ($separator !== $this->_separators[$key]) {
lib/Zend/Controller/Router/Route/Static.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Controller
17
  * @subpackage Router
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
- * @version $Id: Static.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
@@ -76,7 +76,9 @@ class Zend_Controller_Router_Route_Static extends Zend_Controller_Router_Route_A
76
  public function match($path, $partial = false)
77
  {
78
  if ($partial) {
79
- if (substr($path, 0, strlen($this->_route)) === $this->_route) {
 
 
80
  $this->setMatchedPath($this->_route);
81
  return $this->_defaults;
82
  }
16
  * @package Zend_Controller
17
  * @subpackage Router
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @version $Id: Static.php 23210 2010-10-21 16:10:55Z matthew $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
76
  public function match($path, $partial = false)
77
  {
78
  if ($partial) {
79
+ if ((empty($path) && empty($this->_route))
80
+ || (substr($path, 0, strlen($this->_route)) === $this->_route)
81
+ ) {
82
  $this->setMatchedPath($this->_route);
83
  return $this->_defaults;
84
  }
lib/Zend/Crypt.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Crypt
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Crypt.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -87,6 +87,7 @@ class Zend_Crypt
87
  self::_detectHashSupport($algorithm);
88
  $supportedMethod = '_digest' . ucfirst(self::$_type);
89
  $result = self::$supportedMethod($algorithm, $data, $binaryOutput);
 
90
  }
91
 
92
  /**
@@ -164,4 +165,4 @@ class Zend_Crypt
164
  return openssl_digest($data, $algorithm, $binaryOutput);
165
  }
166
 
167
- }
16
  * @package Zend_Crypt
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Crypt.php 23089 2010-10-12 17:05:31Z padraic $
20
  */
21
 
22
  /**
87
  self::_detectHashSupport($algorithm);
88
  $supportedMethod = '_digest' . ucfirst(self::$_type);
89
  $result = self::$supportedMethod($algorithm, $data, $binaryOutput);
90
+ return $result;
91
  }
92
 
93
  /**
165
  return openssl_digest($data, $algorithm, $binaryOutput);
166
  }
167
 
168
+ }
lib/Zend/Crypt/DiffieHellman.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage DiffieHellman
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: DiffieHellman.php 22053 2010-04-29 14:29:52Z padraic $
21
  */
22
 
23
  /**
@@ -108,7 +108,7 @@ class Zend_Crypt_DiffieHellman
108
  {
109
  $this->setPrime($prime);
110
  $this->setGenerator($generator);
111
- if (!is_null($privateKey)) {
112
  $this->setPrivateKey($privateKey, $privateKeyType);
113
  }
114
  $this->setBigIntegerMath();
@@ -170,7 +170,7 @@ class Zend_Crypt_DiffieHellman
170
  */
171
  public function getPublicKey($type = self::NUMBER)
172
  {
173
- if (is_null($this->_publicKey)) {
174
  #require_once 'Zend/Crypt/DiffieHellman/Exception.php';
175
  throw new Zend_Crypt_DiffieHellman_Exception('A public key has not yet been generated using a prior call to generateKeys()');
176
  }
17
  * @subpackage DiffieHellman
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: DiffieHellman.php 22662 2010-07-24 17:37:36Z mabe $
21
  */
22
 
23
  /**
108
  {
109
  $this->setPrime($prime);
110
  $this->setGenerator($generator);
111
+ if ($privateKey !== null) {
112
  $this->setPrivateKey($privateKey, $privateKeyType);
113
  }
114
  $this->setBigIntegerMath();
170
  */
171
  public function getPublicKey($type = self::NUMBER)
172
  {
173
+ if ($this->_publicKey === null) {
174
  #require_once 'Zend/Crypt/DiffieHellman/Exception.php';
175
  throw new Zend_Crypt_DiffieHellman_Exception('A public key has not yet been generated using a prior call to generateKeys()');
176
  }
lib/Zend/Crypt/Math/BigInteger.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Math
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: BigInteger.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -61,7 +61,7 @@ class Zend_Crypt_Math_BigInteger
61
  */
62
  public function __construct($extension = null)
63
  {
64
- if (!is_null($extension) && !in_array($extension, array('bcmath', 'gmp', 'bigint'))) {
65
  #require_once('Zend/Crypt/Math/BigInteger/Exception.php');
66
  throw new Zend_Crypt_Math_BigInteger_Exception('Invalid extension type; please use one of bcmath, gmp or bigint');
67
  }
@@ -90,7 +90,7 @@ class Zend_Crypt_Math_BigInteger
90
  */
91
  protected function _loadAdapter($extension = null)
92
  {
93
- if (is_null($extension)) {
94
  if (extension_loaded('gmp')) {
95
  $extension = 'gmp';
96
  //} elseif (extension_loaded('big_int')) {
@@ -105,7 +105,7 @@ class Zend_Crypt_Math_BigInteger
105
  //} elseif($extension == 'bigint' && extension_loaded('big_int')) {
106
  // #require_once 'Zend/Crypt_Math/BigInteger/Bigint.php';
107
  // $this->_math = new Zend_Crypt_Math_BigInteger_Bigint();
108
- } elseif ($extension == 'bcmath') {
109
  #require_once 'Zend/Crypt/Math/BigInteger/Bcmath.php';
110
  $this->_math = new Zend_Crypt_Math_BigInteger_Bcmath();
111
  } else {
17
  * @subpackage Math
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: BigInteger.php 23439 2010-11-23 21:10:14Z alexander $
21
  */
22
 
23
  /**
61
  */
62
  public function __construct($extension = null)
63
  {
64
+ if ($extension !== null && !in_array($extension, array('bcmath', 'gmp', 'bigint'))) {
65
  #require_once('Zend/Crypt/Math/BigInteger/Exception.php');
66
  throw new Zend_Crypt_Math_BigInteger_Exception('Invalid extension type; please use one of bcmath, gmp or bigint');
67
  }
90
  */
91
  protected function _loadAdapter($extension = null)
92
  {
93
+ if ($extension === null) {
94
  if (extension_loaded('gmp')) {
95
  $extension = 'gmp';
96
  //} elseif (extension_loaded('big_int')) {
105
  //} elseif($extension == 'bigint' && extension_loaded('big_int')) {
106
  // #require_once 'Zend/Crypt_Math/BigInteger/Bigint.php';
107
  // $this->_math = new Zend_Crypt_Math_BigInteger_Bigint();
108
+ } elseif ($extension == 'bcmath' && extension_loaded('bcmath')) {
109
  #require_once 'Zend/Crypt/Math/BigInteger/Bcmath.php';
110
  $this->_math = new Zend_Crypt_Math_BigInteger_Bcmath();
111
  } else {
lib/Zend/Crypt/Math/BigInteger/Bcmath.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Math
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Bcmath.php 22655 2010-07-22 18:47:20Z mabe $
21
  */
22
 
23
  /**
17
  * @subpackage Math
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Bcmath.php 22653 2010-07-22 18:41:39Z mabe $
21
  */
22
 
23
  /**
lib/Zend/Crypt/Math/BigInteger/Gmp.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Math
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Gmp.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -28,7 +28,7 @@
28
  /**
29
  * Support for arbitrary precision mathematics in PHP.
30
  *
31
- * Zend_Crypt_Math_BigInteger_Bcmath is a wrapper across the PHP BCMath
32
  * extension.
33
  *
34
  * @category Zend
17
  * @subpackage Math
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Gmp.php 23439 2010-11-23 21:10:14Z alexander $
21
  */
22
 
23
  /**
28
  /**
29
  * Support for arbitrary precision mathematics in PHP.
30
  *
31
+ * Zend_Crypt_Math_BigInteger_Gmp is a wrapper across the PHP BCMath
32
  * extension.
33
  *
34
  * @category Zend
lib/Zend/Crypt/Rsa.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Rsa
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Rsa.php 22042 2010-04-28 19:33:31Z padraic $
21
  */
22
 
23
  /**
@@ -42,27 +42,42 @@ class Zend_Crypt_Rsa
42
  const BINARY = 'binary';
43
  const BASE64 = 'base64';
44
 
45
- protected $_privateKey = null;
46
 
47
- protected $_publicKey = null;
48
 
49
  /**
50
  * @var string
51
  */
52
- protected $_pemString = null;
53
 
54
- protected $_pemPath = null;
55
 
56
- protected $_certificateString = null;
57
 
58
- protected $_certificatePath = null;
59
 
60
- protected $_hashAlgorithm = OPENSSL_ALGO_SHA1;
61
 
62
- protected $_passPhrase = null;
63
 
 
 
 
 
 
 
64
  public function __construct(array $options = null)
65
  {
 
 
 
 
 
 
 
 
 
66
  if (isset($options)) {
67
  $this->setOptions($options);
68
  }
@@ -190,7 +205,7 @@ class Zend_Crypt_Rsa
190
  {
191
  $config = null;
192
  $passPhrase = null;
193
- if (!is_null($configargs)) {
194
  if (isset($configargs['passPhrase'])) {
195
  $passPhrase = $configargs['passPhrase'];
196
  unset($configargs['passPhrase']);
17
  * @subpackage Rsa
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Rsa.php 23439 2010-11-23 21:10:14Z alexander $
21
  */
22
 
23
  /**
42
  const BINARY = 'binary';
43
  const BASE64 = 'base64';
44
 
45
+ protected $_privateKey;
46
 
47
+ protected $_publicKey;
48
 
49
  /**
50
  * @var string
51
  */
52
+ protected $_pemString;
53
 
54
+ protected $_pemPath;
55
 
56
+ protected $_certificateString;
57
 
58
+ protected $_certificatePath;
59
 
60
+ protected $_hashAlgorithm;
61
 
62
+ protected $_passPhrase;
63
 
64
+ /**
65
+ * Class constructor
66
+ *
67
+ * @param array $options
68
+ * @throws Zend_Crypt_Rsa_Exception
69
+ */
70
  public function __construct(array $options = null)
71
  {
72
+ if (!extension_loaded('openssl')) {
73
+ #require_once 'Zend/Crypt/Rsa/Exception.php';
74
+ throw new Zend_Crypt_Rsa_Exception('Zend_Crypt_Rsa requires openssl extention to be loaded.');
75
+ }
76
+
77
+ // Set _hashAlgorithm property when we are sure, that openssl extension is loaded
78
+ // and OPENSSL_ALGO_SHA1 constant is available
79
+ $this->_hashAlgorithm = OPENSSL_ALGO_SHA1;
80
+
81
  if (isset($options)) {
82
  $this->setOptions($options);
83
  }
205
  {
206
  $config = null;
207
  $passPhrase = null;
208
+ if ($configargs !== null) {
209
  if (isset($configargs['passPhrase'])) {
210
  $passPhrase = $configargs['passPhrase'];
211
  unset($configargs['passPhrase']);
lib/Zend/Crypt/Rsa/Exception.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Crypt
17
+ * @subpackage Math
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
21
+ */
22
+
23
+ /**
24
+ * @see Zend_Crypt_Exception
25
+ */
26
+ #require_once 'Zend/Crypt/Exception.php';
27
+
28
+ /**
29
+ * @category Zend
30
+ * @package Zend_Crypt
31
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
+ * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ */
34
+ class Zend_Crypt_Rsa_Exception extends Zend_Crypt_Exception
35
+ {
36
+ }
lib/Zend/Crypt/Rsa/Key/Private.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Rsa
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Private.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -62,7 +62,7 @@ class Zend_Crypt_Rsa_Key_Private extends Zend_Crypt_Rsa_Key
62
 
63
  public function getPublicKey()
64
  {
65
- if (is_null($this->_publicKey)) {
66
  /**
67
  * @see Zend_Crypt_Rsa_Key_Public
68
  */
17
  * @subpackage Rsa
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Private.php 22662 2010-07-24 17:37:36Z mabe $
21
  */
22
 
23
  /**
62
 
63
  public function getPublicKey()
64
  {
65
+ if ($this->_publicKey === null) {
66
  /**
67
  * @see Zend_Crypt_Rsa_Key_Public
68
  */
lib/Zend/Currency.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Currency
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Currency.php 22369 2010-06-04 14:54:43Z thomas $
20
  */
21
 
22
  /**
@@ -77,7 +77,8 @@ class Zend_Currency
77
  'symbol' => null,
78
  'locale' => null,
79
  'value' => 0,
80
- 'service' => null
 
81
  );
82
 
83
  /**
@@ -431,7 +432,7 @@ class Zend_Currency
431
  throw new Zend_Currency_Exception('No currency defined');
432
  }
433
 
434
- $data = Zend_Locale_Data::getContent('', 'regiontocurrency', $currency);
435
 
436
  $result = explode(' ', $data);
437
  return $result;
@@ -453,7 +454,10 @@ class Zend_Currency
453
  }
454
  }
455
 
456
- return Zend_Locale_Data::getList('', 'regiontocurrency', $region);
 
 
 
457
  }
458
 
459
  /**
@@ -483,8 +487,7 @@ class Zend_Currency
483
  */
484
  public static function getCache()
485
  {
486
- $cache = Zend_Locale_Data::getCache();
487
- return $cache;
488
  }
489
 
490
  /**
@@ -521,11 +524,12 @@ class Zend_Currency
521
  /**
522
  * Clears all set cache data
523
  *
 
524
  * @return void
525
  */
526
- public static function clearCache()
527
  {
528
- Zend_Locale_Data::clearCache();
529
  }
530
 
531
  /**
16
  * @package Zend_Currency
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Currency.php 22708 2010-07-28 07:25:16Z thomas $
20
  */
21
 
22
  /**
77
  'symbol' => null,
78
  'locale' => null,
79
  'value' => 0,
80
+ 'service' => null,
81
+ 'tag' => 'Zend_Locale'
82
  );
83
 
84
  /**
432
  throw new Zend_Currency_Exception('No currency defined');
433
  }
434
 
435
+ $data = Zend_Locale_Data::getContent($this->_options['locale'], 'regiontocurrency', $currency);
436
 
437
  $result = explode(' ', $data);
438
  return $result;
454
  }
455
  }
456
 
457
+ $data = Zend_Locale_Data::getContent($this->_options['locale'], 'currencytoregion', $region);
458
+
459
+ $result = explode(' ', $data);
460
+ return $result;
461
  }
462
 
463
  /**
487
  */
488
  public static function getCache()
489
  {
490
+ return Zend_Locale_Data::getCache();
 
491
  }
492
 
493
  /**
524
  /**
525
  * Clears all set cache data
526
  *
527
+ * @param string $tag Tag to clear when the default tag name is not used
528
  * @return void
529
  */
530
+ public static function clearCache($tag = null)
531
  {
532
+ Zend_Locale_Data::clearCache($tag);
533
  }
534
 
535
  /**
lib/Zend/Currency/CurrencyInterface.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Currency
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Exception.php 16971 2009-07-22 18:05:45Z mikaelkael $
20
  */
21
 
22
  /**
16
  * @package Zend_Currency
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: CurrencyInterface.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  /**
lib/Zend/Date.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Date
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Date.php 22321 2010-05-30 09:35:10Z thomas $
20
  */
21
 
22
  /**
@@ -274,6 +274,7 @@ class Zend_Date extends Zend_Date_DateObject
274
  }
275
 
276
  parent::$_cache = $value;
 
277
  Zend_Locale_Data::setCache($value);
278
  }
279
  break;
@@ -557,7 +558,7 @@ class Zend_Date extends Zend_Date_DateObject
557
  $comment = false;
558
  $format = '';
559
  $orig = '';
560
- for ($i = 0; $i < strlen($part); ++$i) {
561
  if ($part[$i] == "'") {
562
  $comment = $comment ? false : true;
563
  if (isset($part[$i+1]) && ($part[$i+1] == "'")) {
16
  * @package Zend_Date
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Date.php 22713 2010-07-29 11:41:56Z thomas $
20
  */
21
 
22
  /**
274
  }
275
 
276
  parent::$_cache = $value;
277
+ parent::$_cacheTags = Zend_Date_DateObject::_getTagSupportForCache();
278
  Zend_Locale_Data::setCache($value);
279
  }
280
  break;
558
  $comment = false;
559
  $format = '';
560
  $orig = '';
561
+ for ($i = 0; isset($part[$i]); ++$i) {
562
  if ($part[$i] == "'") {
563
  $comment = $comment ? false : true;
564
  if (isset($part[$i+1]) && ($part[$i+1] == "'")) {
lib/Zend/Date/DateObject.php CHANGED
@@ -15,7 +15,7 @@
15
  * @category Zend
16
  * @package Zend_Date
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
- * @version $Id: DateObject.php 22071 2010-05-01 17:25:23Z thomas $
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
  */
21
 
@@ -33,6 +33,7 @@ abstract class Zend_Date_DateObject {
33
  */
34
  private $_unixTimestamp;
35
  protected static $_cache = null;
 
36
  protected static $_defaultOffset = 0;
37
 
38
  /**
@@ -254,7 +255,11 @@ abstract class Zend_Date_DateObject {
254
  }
255
 
256
  if (isset(self::$_cache)) {
257
- self::$_cache->save( serialize($date), $id);
 
 
 
 
258
  }
259
 
260
  return $date;
@@ -340,7 +345,11 @@ abstract class Zend_Date_DateObject {
340
  }
341
 
342
  if (isset(self::$_cache)) {
343
- self::$_cache->save( serialize($timestamp), $idstamp);
 
 
 
 
344
  }
345
  }
346
 
@@ -828,7 +837,11 @@ abstract class Zend_Date_DateObject {
828
  }
829
 
830
  if (isset(self::$_cache)) {
831
- self::$_cache->save( serialize($array), $id);
 
 
 
 
832
  }
833
 
834
  return $array;
@@ -1055,4 +1068,22 @@ abstract class Zend_Date_DateObject {
1055
 
1056
  return $offset;
1057
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1058
  }
15
  * @category Zend
16
  * @package Zend_Date
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @version $Id: DateObject.php 22712 2010-07-29 08:24:28Z thomas $
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
  */
21
 
33
  */
34
  private $_unixTimestamp;
35
  protected static $_cache = null;
36
+ protected static $_cacheTags = false;
37
  protected static $_defaultOffset = 0;
38
 
39
  /**
255
  }
256
 
257
  if (isset(self::$_cache)) {
258
+ if (self::$_cacheTags) {
259
+ self::$_cache->save( serialize($date), $id, array('Zend_Date'));
260
+ } else {
261
+ self::$_cache->save( serialize($date), $id);
262
+ }
263
  }
264
 
265
  return $date;
345
  }
346
 
347
  if (isset(self::$_cache)) {
348
+ if (self::$_cacheTags) {
349
+ self::$_cache->save( serialize($timestamp), $idstamp, array('Zend_Date'));
350
+ } else {
351
+ self::$_cache->save( serialize($timestamp), $idstamp);
352
+ }
353
  }
354
  }
355
 
837
  }
838
 
839
  if (isset(self::$_cache)) {
840
+ if (self::$_cacheTags) {
841
+ self::$_cache->save( serialize($array), $id, array('Zend_Date'));
842
+ } else {
843
+ self::$_cache->save( serialize($array), $id);
844
+ }
845
  }
846
 
847
  return $array;
1068
 
1069
  return $offset;
1070
  }
1071
+
1072
+ /**
1073
+ * Internal method to check if the given cache supports tags
1074
+ *
1075
+ * @param Zend_Cache $cache
1076
+ */
1077
+ protected static function _getTagSupportForCache()
1078
+ {
1079
+ $backend = self::$_cache->getBackend();
1080
+ if ($backend instanceof Zend_Cache_Backend_ExtendedInterface) {
1081
+ $cacheOptions = $backend->getCapabilities();
1082
+ self::$_cacheTags = $cacheOptions['tags'];
1083
+ } else {
1084
+ self::$_cacheTags = false;
1085
+ }
1086
+
1087
+ return self::$_cacheTags;
1088
+ }
1089
  }
lib/Zend/Db.php CHANGED
@@ -17,7 +17,7 @@
17
  * @package Zend_Db
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Db.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
 
@@ -42,6 +42,11 @@ class Zend_Db
42
  */
43
  const CASE_FOLDING = 'caseFolding';
44
 
 
 
 
 
 
45
  /**
46
  * Use the AUTO_QUOTE_IDENTIFIERS constant in the config of a Zend_Db_Adapter.
47
  */
@@ -85,9 +90,6 @@ class Zend_Db
85
  * 'NULL_TO_STRING', 'ERR_NONE', 'FETCH_ORI_NEXT',
86
  * 'FETCH_ORI_PRIOR', 'FETCH_ORI_FIRST', 'FETCH_ORI_LAST',
87
  * 'FETCH_ORI_ABS', 'FETCH_ORI_REL', 'CURSOR_FWDONLY', 'CURSOR_SCROLL',
88
- * 'ERR_CANT_MAP', 'ERR_SYNTAX', 'ERR_CONSTRAINT', 'ERR_NOT_FOUND',
89
- * 'ERR_ALREADY_EXISTS', 'ERR_NOT_IMPLEMENTED', 'ERR_MISMATCH',
90
- * 'ERR_TRUNCATED', 'ERR_DISCONNECTED', 'ERR_NO_PERM',
91
  * );
92
  *
93
  * $const = array();
@@ -120,17 +122,7 @@ class Zend_Db
120
  const CASE_UPPER = 1;
121
  const CURSOR_FWDONLY = 0;
122
  const CURSOR_SCROLL = 1;
123
- const ERR_ALREADY_EXISTS = NULL;
124
- const ERR_CANT_MAP = NULL;
125
- const ERR_CONSTRAINT = NULL;
126
- const ERR_DISCONNECTED = NULL;
127
- const ERR_MISMATCH = NULL;
128
- const ERR_NO_PERM = NULL;
129
  const ERR_NONE = '00000';
130
- const ERR_NOT_FOUND = NULL;
131
- const ERR_NOT_IMPLEMENTED = NULL;
132
- const ERR_SYNTAX = NULL;
133
- const ERR_TRUNCATED = NULL;
134
  const ERRMODE_EXCEPTION = 2;
135
  const ERRMODE_SILENT = 0;
136
  const ERRMODE_WARNING = 1;
17
  * @package Zend_Db
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Db.php 23405 2010-11-19 19:46:10Z bittarman $
21
  */
22
 
23
 
42
  */
43
  const CASE_FOLDING = 'caseFolding';
44
 
45
+ /**
46
+ * Use the FETCH_MODE constant in the config of a Zend_Db_Adapter.
47
+ */
48
+ const FETCH_MODE = 'fetchMode';
49
+
50
  /**
51
  * Use the AUTO_QUOTE_IDENTIFIERS constant in the config of a Zend_Db_Adapter.
52
  */
90
  * 'NULL_TO_STRING', 'ERR_NONE', 'FETCH_ORI_NEXT',
91
  * 'FETCH_ORI_PRIOR', 'FETCH_ORI_FIRST', 'FETCH_ORI_LAST',
92
  * 'FETCH_ORI_ABS', 'FETCH_ORI_REL', 'CURSOR_FWDONLY', 'CURSOR_SCROLL',
 
 
 
93
  * );
94
  *
95
  * $const = array();
122
  const CASE_UPPER = 1;
123
  const CURSOR_FWDONLY = 0;
124
  const CURSOR_SCROLL = 1;
 
 
 
 
 
 
125
  const ERR_NONE = '00000';
 
 
 
 
126
  const ERRMODE_EXCEPTION = 2;
127
  const ERRMODE_SILENT = 0;
128
  const ERRMODE_WARNING = 1;
lib/Zend/Db/Adapter/Abstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
 
@@ -184,7 +184,8 @@ abstract class Zend_Db_Adapter_Abstract
184
 
185
  $options = array(
186
  Zend_Db::CASE_FOLDING => $this->_caseFolding,
187
- Zend_Db::AUTO_QUOTE_IDENTIFIERS => $this->_autoQuoteIdentifiers
 
188
  );
189
  $driverOptions = array();
190
 
@@ -236,6 +237,16 @@ abstract class Zend_Db_Adapter_Abstract
236
  }
237
  }
238
 
 
 
 
 
 
 
 
 
 
 
239
  // obtain quoting property if there is one
240
  if (array_key_exists(Zend_Db::AUTO_QUOTE_IDENTIFIERS, $options)) {
241
  $this->_autoQuoteIdentifiers = (bool) $options[Zend_Db::AUTO_QUOTE_IDENTIFIERS];
@@ -526,13 +537,27 @@ abstract class Zend_Db_Adapter_Abstract
526
  // extract and quote col names from the array keys
527
  $cols = array();
528
  $vals = array();
 
529
  foreach ($bind as $col => $val) {
530
  $cols[] = $this->quoteIdentifier($col, true);
531
  if ($val instanceof Zend_Db_Expr) {
532
  $vals[] = $val->__toString();
533
  unset($bind[$col]);
534
  } else {
535
- $vals[] = '?';
 
 
 
 
 
 
 
 
 
 
 
 
 
536
  }
537
  }
538
 
@@ -543,7 +568,10 @@ abstract class Zend_Db_Adapter_Abstract
543
  . 'VALUES (' . implode(', ', $vals) . ')';
544
 
545
  // execute the statement and return the number of affected rows
546
- $stmt = $this->query($sql, array_values($bind));
 
 
 
547
  $result = $stmt->rowCount();
548
  return $result;
549
  }
@@ -574,8 +602,8 @@ abstract class Zend_Db_Adapter_Abstract
574
  } else {
575
  if ($this->supportsParameters('named')) {
576
  unset($bind[$col]);
577
- $bind[':'.$col.$i] = $val;
578
- $val = ':'.$col.$i;
579
  $i++;
580
  } else {
581
  /** @see Zend_Db_Adapter_Exception */
@@ -754,8 +782,6 @@ abstract class Zend_Db_Adapter_Abstract
754
  /**
755
  * Fetches the first column of all SQL result rows as an array.
756
  *
757
- * The first column in each row is used as the array key.
758
- *
759
  * @param string|Zend_Db_Select $sql An SQL SELECT statement.
760
  * @param mixed $bind Data to bind into SELECT placeholders.
761
  * @return array
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Abstract.php 23252 2010-10-26 12:48:32Z matthew $
21
  */
22
 
23
 
184
 
185
  $options = array(
186
  Zend_Db::CASE_FOLDING => $this->_caseFolding,
187
+ Zend_Db::AUTO_QUOTE_IDENTIFIERS => $this->_autoQuoteIdentifiers,
188
+ Zend_Db::FETCH_MODE => $this->_fetchMode,
189
  );
190
  $driverOptions = array();
191
 
237
  }
238
  }
239
 
240
+ if (array_key_exists(Zend_Db::FETCH_MODE, $options)) {
241
+ if (is_string($options[Zend_Db::FETCH_MODE])) {
242
+ $constant = 'Zend_Db::FETCH_' . strtoupper($options[Zend_Db::FETCH_MODE]);
243
+ if(defined($constant)) {
244
+ $options[Zend_Db::FETCH_MODE] = constant($constant);
245
+ }
246
+ }
247
+ $this->setFetchMode((int) $options[Zend_Db::FETCH_MODE]);
248
+ }
249
+
250
  // obtain quoting property if there is one
251
  if (array_key_exists(Zend_Db::AUTO_QUOTE_IDENTIFIERS, $options)) {
252
  $this->_autoQuoteIdentifiers = (bool) $options[Zend_Db::AUTO_QUOTE_IDENTIFIERS];
537
  // extract and quote col names from the array keys
538
  $cols = array();
539
  $vals = array();
540
+ $i = 0;
541
  foreach ($bind as $col => $val) {
542
  $cols[] = $this->quoteIdentifier($col, true);
543
  if ($val instanceof Zend_Db_Expr) {
544
  $vals[] = $val->__toString();
545
  unset($bind[$col]);
546
  } else {
547
+ if ($this->supportsParameters('positional')) {
548
+ $vals[] = '?';
549
+ } else {
550
+ if ($this->supportsParameters('named')) {
551
+ unset($bind[$col]);
552
+ $bind[':col'.$i] = $val;
553
+ $vals[] = ':col'.$i;
554
+ $i++;
555
+ } else {
556
+ /** @see Zend_Db_Adapter_Exception */
557
+ #require_once 'Zend/Db/Adapter/Exception.php';
558
+ throw new Zend_Db_Adapter_Exception(get_class($this) ." doesn't support positional or named binding");
559
+ }
560
+ }
561
  }
562
  }
563
 
568
  . 'VALUES (' . implode(', ', $vals) . ')';
569
 
570
  // execute the statement and return the number of affected rows
571
+ if ($this->supportsParameters('positional')) {
572
+ $bind = array_values($bind);
573
+ }
574
+ $stmt = $this->query($sql, $bind);
575
  $result = $stmt->rowCount();
576
  return $result;
577
  }
602
  } else {
603
  if ($this->supportsParameters('named')) {
604
  unset($bind[$col]);
605
+ $bind[':col'.$i] = $val;
606
+ $val = ':col'.$i;
607
  $i++;
608
  } else {
609
  /** @see Zend_Db_Adapter_Exception */
782
  /**
783
  * Fetches the first column of all SQL result rows as an array.
784
  *
 
 
785
  * @param string|Zend_Db_Select $sql An SQL SELECT statement.
786
  * @param mixed $bind Data to bind into SELECT placeholders.
787
  * @return array
lib/Zend/Db/Adapter/Db2.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Db2.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  *
22
  */
23
 
@@ -154,6 +154,14 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
154
  $this->_config['driver_options']['DB2_ATTR_CASE'] = $caseAttrMap[$this->_config['options'][Zend_Db::CASE_FOLDING]];
155
  }
156
 
 
 
 
 
 
 
 
 
157
  if ($this->_config['host'] !== 'localhost' && !$this->_isI5) {
158
  // if the host isn't localhost, use extended connection params
159
  $dbname = 'DRIVER={IBM DB2 ODBC DRIVER}' .
@@ -411,7 +419,7 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
411
  AND C.TABLE_NAME = k.TABLE_NAME
412
  AND C.COLUMN_NAME = k.COLUMN_NAME)
413
  WHERE "
414
- . $this->quoteInto('UPPER(C.TABLE_NAME) = UPPER(?)', $tableName);
415
 
416
  if ($schemaName) {
417
  $sql .= $this->quoteInto(' AND UPPER(C.TABLE_SCHEMA) = UPPER(?)', $schemaName);
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Db2.php 23199 2010-10-21 14:27:06Z ralph $
21
  *
22
  */
23
 
154
  $this->_config['driver_options']['DB2_ATTR_CASE'] = $caseAttrMap[$this->_config['options'][Zend_Db::CASE_FOLDING]];
155
  }
156
 
157
+ if ($this->_isI5 && isset($this->_config['driver_options']['i5_naming'])) {
158
+ if ($this->_config['driver_options']['i5_naming']) {
159
+ $this->_config['driver_options']['i5_naming'] = DB2_I5_NAMING_ON;
160
+ } else {
161
+ $this->_config['driver_options']['i5_naming'] = DB2_I5_NAMING_OFF;
162
+ }
163
+ }
164
+
165
  if ($this->_config['host'] !== 'localhost' && !$this->_isI5) {
166
  // if the host isn't localhost, use extended connection params
167
  $dbname = 'DRIVER={IBM DB2 ODBC DRIVER}' .
419
  AND C.TABLE_NAME = k.TABLE_NAME
420
  AND C.COLUMN_NAME = k.COLUMN_NAME)
421
  WHERE "
422
+ . $this->quoteInto('UPPER(C.TABLE_NAME) = UPPER(?)', $tableName);
423
 
424
  if ($schemaName) {
425
  $sql .= $this->quoteInto(' AND UPPER(C.TABLE_SCHEMA) = UPPER(?)', $schemaName);
lib/Zend/Db/Adapter/Oracle.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Oracle.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -602,46 +602,6 @@ class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_Abstract
602
  return $this->_execute_mode;
603
  }
604
 
605
- /**
606
- * Inserts a table row with specified data.
607
- *
608
- * Oracle does not support anonymous ('?') binds.
609
- *
610
- * @param mixed $table The table to insert data into.
611
- * @param array $bind Column-value pairs.
612
- * @return int The number of affected rows.
613
- */
614
- public function insert($table, array $bind)
615
- {
616
- $i = 0;
617
- // extract and quote col names from the array keys
618
- $cols = array();
619
- $vals = array();
620
- foreach ($bind as $col => $val) {
621
- $cols[] = $this->quoteIdentifier($col, true);
622
- if ($val instanceof Zend_Db_Expr) {
623
- $vals[] = $val->__toString();
624
- unset($bind[$col]);
625
- } else {
626
- $vals[] = ':'.$col.$i;
627
- unset($bind[$col]);
628
- $bind[':'.$col.$i] = $val;
629
- }
630
- $i++;
631
- }
632
-
633
- // build the statement
634
- $sql = "INSERT INTO "
635
- . $this->quoteIdentifier($table, true)
636
- . ' (' . implode(', ', $cols) . ') '
637
- . 'VALUES (' . implode(', ', $vals) . ')';
638
-
639
- // execute the statement and return the number of affected rows
640
- $stmt = $this->query($sql, $bind);
641
- $result = $stmt->rowCount();
642
- return $result;
643
- }
644
-
645
  /**
646
  * Check if the adapter supports real SQL parameters.
647
  *
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Oracle.php 21108 2010-02-19 22:36:08Z mikaelkael $
21
  */
22
 
23
  /**
602
  return $this->_execute_mode;
603
  }
604
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
605
  /**
606
  * Check if the adapter supports real SQL parameters.
607
  *
lib/Zend/Db/Adapter/Pdo/Pgsql.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Pgsql.php 22789 2010-08-03 19:01:10Z ramon $
21
  */
22
 
23
 
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Pgsql.php 22788 2010-08-03 18:29:55Z ramon $
21
  */
22
 
23
 
lib/Zend/Db/Adapter/Sqlsrv.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Sqlsrv.php 21197 2010-02-24 16:12:53Z rob $
21
  */
22
 
23
  /**
@@ -437,6 +437,13 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
437
  $sql = "exec sp_columns @table_name = " . $this->quoteIdentifier($tableName, true);
438
  $stmt = $this->query($sql);
439
  $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
 
 
 
 
 
 
 
440
 
441
  $owner = 1;
442
  $table_name = 2;
@@ -609,25 +616,23 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
609
  $sql = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . $count . ' ', $sql);
610
  } else {
611
  $orderby = stristr($sql, 'ORDER BY');
612
- if ($orderby !== false) {
613
- $sort = (stripos($orderby, ' desc') !== false) ? 'desc' : 'asc';
614
- $order = str_ireplace('ORDER BY', '', $orderby);
615
- $order = trim(preg_replace('/\bASC\b|\bDESC\b/i', '', $order));
616
- }
617
-
618
- $sql = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . ($count+$offset) . ' ', $sql);
619
-
620
- $sql = 'SELECT * FROM (SELECT TOP ' . $count . ' * FROM (' . $sql . ') AS inner_tbl';
621
- if ($orderby !== false) {
622
- $innerOrder = preg_replace('/\".*\".\"(.*)\"/i', '"inner_tbl"."$1"', $order);
623
- $sql .= ' ORDER BY ' . $innerOrder . ' ';
624
- $sql .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
625
- }
626
- $sql .= ') AS outer_tbl';
627
- if ($orderby !== false) {
628
- $outerOrder = preg_replace('/\".*\".\"(.*)\"/i', '"outer_tbl"."$1"', $order);
629
- $sql .= ' ORDER BY ' . $outerOrder . ' ' . $sort;
630
  }
 
 
 
 
 
 
 
 
 
 
 
631
  }
632
 
633
  return $sql;
@@ -657,10 +662,10 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
657
  public function getServerVersion()
658
  {
659
  $this->_connect();
660
- $version = sqlsrv_client_info($this->_connection);
661
 
662
- if ($version !== false) {
663
- return $version['DriverVer'];
664
  }
665
 
666
  return null;
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Sqlsrv.php 21885 2010-04-16 15:13:40Z juokaz $
21
  */
22
 
23
  /**
437
  $sql = "exec sp_columns @table_name = " . $this->quoteIdentifier($tableName, true);
438
  $stmt = $this->query($sql);
439
  $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
440
+
441
+ // ZF-7698
442
+ $stmt->closeCursor();
443
+
444
+ if (count($result) == 0) {
445
+ return array();
446
+ }
447
 
448
  $owner = 1;
449
  $table_name = 2;
616
  $sql = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . $count . ' ', $sql);
617
  } else {
618
  $orderby = stristr($sql, 'ORDER BY');
619
+
620
+ if (!$orderby) {
621
+ $over = 'ORDER BY (SELECT 0)';
622
+ } else {
623
+ $over = preg_replace('/\"[^,]*\".\"([^,]*)\"/i', '"inner_tbl"."$1"', $orderby);
 
 
 
 
 
 
 
 
 
 
 
 
 
624
  }
625
+
626
+ // Remove ORDER BY clause from $sql
627
+ $sql = preg_replace('/\s+ORDER BY(.*)/', '', $sql);
628
+
629
+ // Add ORDER BY clause as an argument for ROW_NUMBER()
630
+ $sql = "SELECT ROW_NUMBER() OVER ($over) AS \"ZEND_DB_ROWNUM\", * FROM ($sql) AS inner_tbl";
631
+
632
+ $start = $offset + 1;
633
+ $end = $offset + $count;
634
+
635
+ $sql = "WITH outer_tbl AS ($sql) SELECT * FROM outer_tbl WHERE \"ZEND_DB_ROWNUM\" BETWEEN $start AND $end";
636
  }
637
 
638
  return $sql;
662
  public function getServerVersion()
663
  {
664
  $this->_connect();
665
+ $serverInfo = sqlsrv_server_info($this->_connection);
666
 
667
+ if ($serverInfo !== false) {
668
+ return $serverInfo['SQLServerVersion'];
669
  }
670
 
671
  return null;
lib/Zend/Db/Adapter/Sqlsrv/Exception.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Exception.php 20629 2010-01-25 21:17:23Z ralph $
21
  */
22
 
23
  /**
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Exception.php 20625 2010-01-25 21:03:53Z ralph $
21
  */
22
 
23
  /**
lib/Zend/Db/Profiler/Query.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Profiler
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Query.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
 
@@ -195,5 +195,19 @@ class Zend_Db_Profiler_Query
195
 
196
  return $this->_endedMicrotime - $this->_startedMicrotime;
197
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  }
199
 
17
  * @subpackage Profiler
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Query.php 23382 2010-11-18 22:50:50Z bittarman $
21
  */
22
 
23
 
195
 
196
  return $this->_endedMicrotime - $this->_startedMicrotime;
197
  }
198
+
199
+ /**
200
+ * Get the time (in seconds) when the profiler started running.
201
+ *
202
+ * @return bool|float
203
+ */
204
+ public function getStartedMicrotime()
205
+ {
206
+ if(null === $this->_startedMicrotime) {
207
+ return false;
208
+ }
209
+
210
+ return $this->_startedMicrotime;
211
+ }
212
  }
213
 
lib/Zend/Db/Select.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Select
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Select.php 22853 2010-08-19 19:01:09Z padraic $
21
  */
22
 
23
 
@@ -467,7 +467,7 @@ class Zend_Db_Select
467
  *
468
  * @param string $cond The WHERE condition.
469
  * @param mixed $value OPTIONAL The value to quote into the condition.
470
- * @param constant $type OPTIONAL The type of the given value
471
  * @return Zend_Db_Select This Zend_Db_Select object.
472
  */
473
  public function where($cond, $value = null, $type = null)
@@ -484,7 +484,7 @@ class Zend_Db_Select
484
  *
485
  * @param string $cond The WHERE condition.
486
  * @param mixed $value OPTIONAL The value to quote into the condition.
487
- * @param constant $type OPTIONAL The type of the given value
488
  * @return Zend_Db_Select This Zend_Db_Select object.
489
  *
490
  * @see where()
@@ -526,14 +526,14 @@ class Zend_Db_Select
526
  * appears. See {@link where()} for an example
527
  *
528
  * @param string $cond The HAVING condition.
529
- * @param string|Zend_Db_Expr $val The value to quote into the condition.
 
530
  * @return Zend_Db_Select This Zend_Db_Select object.
531
  */
532
- public function having($cond)
533
  {
534
- if (func_num_args() > 1) {
535
- $val = func_get_arg(1);
536
- $cond = $this->_adapter->quoteInto($cond, $val);
537
  }
538
 
539
  if ($this->_parts[self::HAVING]) {
@@ -551,16 +551,16 @@ class Zend_Db_Select
551
  * Otherwise identical to orHaving().
552
  *
553
  * @param string $cond The HAVING condition.
554
- * @param mixed $val The value to quote into the condition.
 
555
  * @return Zend_Db_Select This Zend_Db_Select object.
556
  *
557
  * @see having()
558
  */
559
- public function orHaving($cond)
560
  {
561
- if (func_num_args() > 1) {
562
- $val = func_get_arg(1);
563
- $cond = $this->_adapter->quoteInto($cond, $val);
564
  }
565
 
566
  if ($this->_parts[self::HAVING]) {
17
  * @subpackage Select
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Select.php 23254 2010-10-26 12:49:23Z matthew $
21
  */
22
 
23
 
467
  *
468
  * @param string $cond The WHERE condition.
469
  * @param mixed $value OPTIONAL The value to quote into the condition.
470
+ * @param int $type OPTIONAL The type of the given value
471
  * @return Zend_Db_Select This Zend_Db_Select object.
472
  */
473
  public function where($cond, $value = null, $type = null)
484
  *
485
  * @param string $cond The WHERE condition.
486
  * @param mixed $value OPTIONAL The value to quote into the condition.
487
+ * @param int $type OPTIONAL The type of the given value
488
  * @return Zend_Db_Select This Zend_Db_Select object.
489
  *
490
  * @see where()
526
  * appears. See {@link where()} for an example
527
  *
528
  * @param string $cond The HAVING condition.
529
+ * @param mixed $value OPTIONAL The value to quote into the condition.
530
+ * @param int $type OPTIONAL The type of the given value
531
  * @return Zend_Db_Select This Zend_Db_Select object.
532
  */
533
+ public function having($cond, $value = null, $type = null)
534
  {
535
+ if ($value !== null) {
536
+ $cond = $this->_adapter->quoteInto($cond, $value, $type);
 
537
  }
538
 
539
  if ($this->_parts[self::HAVING]) {
551
  * Otherwise identical to orHaving().
552
  *
553
  * @param string $cond The HAVING condition.
554
+ * @param mixed $value OPTIONAL The value to quote into the condition.
555
+ * @param int $type OPTIONAL The type of the given value
556
  * @return Zend_Db_Select This Zend_Db_Select object.
557
  *
558
  * @see having()
559
  */
560
+ public function orHaving($cond, $value = null, $type = null)
561
  {
562
+ if ($value !== null) {
563
+ $cond = $this->_adapter->quoteInto($cond, $value, $type);
 
564
  }
565
 
566
  if ($this->_parts[self::HAVING]) {
lib/Zend/Db/Statement/Exception.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Statement
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Exception.php 20514 2010-01-22 07:57:10Z ralph $
21
  */
22
 
23
  /**
17
  * @subpackage Statement
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Exception.php 20513 2010-01-22 07:55:48Z ralph $
21
  */
22
 
23
  /**
lib/Zend/Db/Statement/Pdo/Oci.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Statement
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Oci.php 21105 2010-02-19 21:27:09Z mikaelkael $
21
  */
22
 
23
  /**
17
  * @subpackage Statement
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Oci.php 21104 2010-02-19 21:26:36Z mikaelkael $
21
  */
22
 
23
  /**
lib/Zend/Db/Statement/Sqlsrv.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Statement
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Sqlsrv.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -376,8 +376,11 @@ class Zend_Db_Statement_Sqlsrv extends Zend_Db_Statement
376
  #require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
377
  throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
378
  }
 
 
 
379
 
380
- //else - moved to next (or there are no more rows)
381
  }
382
 
383
  /**
@@ -408,4 +411,30 @@ class Zend_Db_Statement_Sqlsrv extends Zend_Db_Statement
408
 
409
  return $num_rows;
410
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  }
17
  * @subpackage Statement
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Sqlsrv.php 21887 2010-04-16 18:28:10Z juokaz $
21
  */
22
 
23
  /**
376
  #require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
377
  throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
378
  }
379
+
380
+ // reset column keys
381
+ $this->_keys = null;
382
 
383
+ return true;
384
  }
385
 
386
  /**
411
 
412
  return $num_rows;
413
  }
414
+
415
+ /**
416
+ * Returns an array containing all of the result set rows.
417
+ *
418
+ * @param int $style OPTIONAL Fetch mode.
419
+ * @param int $col OPTIONAL Column number, if fetch mode is by column.
420
+ * @return array Collection of rows, each in a format by the fetch mode.
421
+ *
422
+ * Behaves like parent, but if limit()
423
+ * is used, the final result removes the extra column
424
+ * 'zend_db_rownum'
425
+ */
426
+ public function fetchAll($style = null, $col = null)
427
+ {
428
+ $data = parent::fetchAll($style, $col);
429
+ $results = array();
430
+ $remove = $this->_adapter->foldCase('ZEND_DB_ROWNUM');
431
+
432
+ foreach ($data as $row) {
433
+ if (is_array($row) && array_key_exists($remove, $row)) {
434
+ unset($row[$remove]);
435
+ }
436
+ $results[] = $row;
437
+ }
438
+ return $results;
439
+ }
440
  }
lib/Zend/Db/Table/Abstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Table
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Abstract.php 21079 2010-02-18 18:15:49Z tech13 $
21
  */
22
 
23
  /**
17
  * @subpackage Table
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Abstract.php 21078 2010-02-18 18:07:16Z tech13 $
21
  */
22
 
23
  /**
lib/Zend/Db/Table/Row/Abstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Table
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Abstract.php 22230 2010-05-21 20:59:18Z ralph $
21
  */
22
 
23
  /**
17
  * @subpackage Table
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Abstract.php 22229 2010-05-21 20:55:01Z ralph $
21
  */
22
 
23
  /**
lib/Zend/Db/Table/Rowset/Abstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Table
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Abstract.php 22616 2010-07-17 15:53:16Z ramon $
21
  */
22
 
23
  /**
@@ -245,20 +245,8 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta
245
  return null;
246
  }
247
 
248
- // do we already have a row object for this position?
249
- if (empty($this->_rows[$this->_pointer])) {
250
- $this->_rows[$this->_pointer] = new $this->_rowClass(
251
- array(
252
- 'table' => $this->_table,
253
- 'data' => $this->_data[$this->_pointer],
254
- 'stored' => $this->_stored,
255
- 'readOnly' => $this->_readOnly
256
- )
257
- );
258
- }
259
-
260
  // return the row object
261
- return $this->_rows[$this->_pointer];
262
  }
263
 
264
  /**
@@ -390,17 +378,17 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta
390
  */
391
  public function getRow($position, $seek = false)
392
  {
393
- $key = $this->key();
394
  try {
395
- $this->seek($position);
396
- $row = $this->current();
397
  } catch (Zend_Db_Table_Rowset_Exception $e) {
398
  #require_once 'Zend/Db/Table/Rowset/Exception.php';
399
  throw new Zend_Db_Table_Rowset_Exception('No row could be found at position ' . (int) $position, 0, $e);
400
  }
401
- if ($seek == false) {
402
- $this->seek($key);
 
403
  }
 
404
  return $row;
405
  }
406
 
@@ -420,5 +408,28 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta
420
  }
421
  return $this->_data;
422
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
423
 
424
  }
17
  * @subpackage Table
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Abstract.php 23380 2010-11-18 22:22:28Z ralph $
21
  */
22
 
23
  /**
245
  return null;
246
  }
247
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  // return the row object
249
+ return $this->_loadAndReturnRow($this->_pointer);
250
  }
251
 
252
  /**
378
  */
379
  public function getRow($position, $seek = false)
380
  {
 
381
  try {
382
+ $row = $this->_loadAndReturnRow($position);
 
383
  } catch (Zend_Db_Table_Rowset_Exception $e) {
384
  #require_once 'Zend/Db/Table/Rowset/Exception.php';
385
  throw new Zend_Db_Table_Rowset_Exception('No row could be found at position ' . (int) $position, 0, $e);
386
  }
387
+
388
+ if ($seek == true) {
389
+ $this->seek($position);
390
  }
391
+
392
  return $row;
393
  }
394
 
408
  }
409
  return $this->_data;
410
  }
411
+
412
+ protected function _loadAndReturnRow($position)
413
+ {
414
+ if (!isset($this->_data[$position])) {
415
+ #require_once 'Zend/Db/Table/Rowset/Exception.php';
416
+ throw new Zend_Db_Table_Rowset_Exception("Data for provided position does not exist");
417
+ }
418
+
419
+ // do we already have a row object for this position?
420
+ if (empty($this->_rows[$position])) {
421
+ $this->_rows[$position] = new $this->_rowClass(
422
+ array(
423
+ 'table' => $this->_table,
424
+ 'data' => $this->_data[$position],
425
+ 'stored' => $this->_stored,
426
+ 'readOnly' => $this->_readOnly
427
+ )
428
+ );
429
+ }
430
+
431
+ // return the row object
432
+ return $this->_rows[$position];
433
+ }
434
 
435
  }
lib/Zend/Dojo/BuildLayer.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Dojo
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: BuildLayer.php 22279 2010-05-24 20:38:52Z matthew $
20
  */
21
 
22
  /**
16
  * @package Zend_Dojo
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: BuildLayer.php 22280 2010-05-24 20:39:45Z matthew $
20
  */
21
 
22
  /**
lib/Zend/Dojo/Form/Decorator/DijitElement.php CHANGED
@@ -38,7 +38,7 @@
38
  * @subpackage Form_Decorator
39
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
40
  * @license http://framework.zend.com/license/new-bsd New BSD License
41
- * @version $Id: DijitElement.php 20622 2010-01-25 20:25:57Z matthew $
42
  */
43
  class Zend_Dojo_Form_Decorator_DijitElement extends Zend_Form_Decorator_ViewHelper
44
  {
38
  * @subpackage Form_Decorator
39
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
40
  * @license http://framework.zend.com/license/new-bsd New BSD License
41
+ * @version $Id: DijitElement.php 20621 2010-01-25 20:25:23Z matthew $
42
  */
43
  class Zend_Dojo_Form_Decorator_DijitElement extends Zend_Form_Decorator_ViewHelper
44
  {
lib/Zend/Dojo/Form/Element/DijitMulti.php CHANGED
@@ -32,7 +32,7 @@
32
  * @subpackage Form_Element
33
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
  * @license http://framework.zend.com/license/new-bsd New BSD License
35
- * @version $Id: DijitMulti.php 22323 2010-05-30 11:15:38Z thomas $
36
  */
37
  abstract class Zend_Dojo_Form_Element_DijitMulti extends Zend_Dojo_Form_Element_Dijit
38
  {
32
  * @subpackage Form_Element
33
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
  * @license http://framework.zend.com/license/new-bsd New BSD License
35
+ * @version $Id: DijitMulti.php 22322 2010-05-30 11:12:57Z thomas $
36
  */
37
  abstract class Zend_Dojo_Form_Element_DijitMulti extends Zend_Dojo_Form_Element_Dijit
38
  {
lib/Zend/Dojo/View/Helper/Dojo/Container.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Dojo
17
  * @subpackage View
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
- * @version $Id: Container.php 21705 2010-03-31 17:38:19Z matthew $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
@@ -67,7 +67,7 @@ class Zend_Dojo_View_Helper_Dojo_Container
67
  * Dojo version to use from CDN
68
  * @var string
69
  */
70
- protected $_cdnVersion = '1.4.1';
71
 
72
  /**
73
  * Has the dijit loader been registered?
@@ -267,6 +267,12 @@ class Zend_Dojo_View_Helper_Dojo_Container
267
  case 'registerdojostylesheet':
268
  $this->registerDojoStylesheet($value);
269
  break;
 
 
 
 
 
 
270
  }
271
  }
272
 
@@ -839,7 +845,7 @@ class Zend_Dojo_View_Helper_Dojo_Container
839
  public function dijitsToJson()
840
  {
841
  #require_once 'Zend/Json.php';
842
- return Zend_Json::encode($this->getDijits());
843
  }
844
 
845
  /**
16
  * @package Zend_Dojo
17
  * @subpackage View
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @version $Id: Container.php 23368 2010-11-18 19:56:30Z bittarman $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
67
  * Dojo version to use from CDN
68
  * @var string
69
  */
70
+ protected $_cdnVersion = '1.5.0';
71
 
72
  /**
73
  * Has the dijit loader been registered?
267
  case 'registerdojostylesheet':
268
  $this->registerDojoStylesheet($value);
269
  break;
270
+ case 'enable':
271
+ if($value) {
272
+ $this->enable();
273
+ } else {
274
+ $this->disable();
275
+ }
276
  }
277
  }
278
 
845
  public function dijitsToJson()
846
  {
847
  #require_once 'Zend/Json.php';
848
+ return Zend_Json::encode($this->getDijits(), false, array('enableJsonExprFinder' => true));
849
  }
850
 
851
  /**
lib/Zend/Dom/Query.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Dom
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Query.php 21157 2010-02-23 17:52:15Z matthew $
20
  */
21
 
22
  /**
@@ -64,48 +64,88 @@ class Zend_Dom_Query
64
  */
65
  protected $_docType;
66
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  /**
68
  * Constructor
69
  *
70
  * @param null|string $document
71
  * @return void
72
  */
73
- public function __construct($document = null)
74
  {
 
75
  $this->setDocument($document);
76
  }
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  /**
79
  * Set document to query
80
  *
81
  * @param string $document
 
82
  * @return Zend_Dom_Query
83
  */
84
- public function setDocument($document)
85
  {
86
  if (0 === strlen($document)) {
87
  return $this;
88
  }
89
  // breaking XML declaration to make syntax highlighting work
90
  if ('<' . '?xml' == substr(trim($document), 0, 5)) {
91
- return $this->setDocumentXml($document);
92
  }
93
  if (strstr($document, 'DTD XHTML')) {
94
- return $this->setDocumentXhtml($document);
95
  }
96
- return $this->setDocumentHtml($document);
97
  }
98
 
99
  /**
100
  * Register HTML document
101
  *
102
  * @param string $document
 
103
  * @return Zend_Dom_Query
104
  */
105
- public function setDocumentHtml($document)
106
  {
107
  $this->_document = (string) $document;
108
  $this->_docType = self::DOC_HTML;
 
 
 
109
  return $this;
110
  }
111
 
@@ -113,12 +153,16 @@ class Zend_Dom_Query
113
  * Register XHTML document
114
  *
115
  * @param string $document
 
116
  * @return Zend_Dom_Query
117
  */
118
- public function setDocumentXhtml($document)
119
  {
120
  $this->_document = (string) $document;
121
  $this->_docType = self::DOC_XHTML;
 
 
 
122
  return $this;
123
  }
124
 
@@ -126,12 +170,16 @@ class Zend_Dom_Query
126
  * Register XML document
127
  *
128
  * @param string $document
 
129
  * @return Zend_Dom_Query
130
  */
131
- public function setDocumentXml($document)
132
  {
133
  $this->_document = (string) $document;
134
  $this->_docType = self::DOC_XML;
 
 
 
135
  return $this;
136
  }
137
 
@@ -191,8 +239,13 @@ class Zend_Dom_Query
191
  throw new Zend_Dom_Exception('Cannot query; no document registered');
192
  }
193
 
 
194
  libxml_use_internal_errors(true);
195
- $domDoc = new DOMDocument;
 
 
 
 
196
  $type = $this->getDocumentType();
197
  switch ($type) {
198
  case self::DOC_XML:
@@ -220,6 +273,17 @@ class Zend_Dom_Query
220
  return new Zend_Dom_Query_Result($query, $xpathQuery, $domDoc, $nodeList);
221
  }
222
 
 
 
 
 
 
 
 
 
 
 
 
223
  /**
224
  * Prepare node list
225
  *
@@ -230,6 +294,9 @@ class Zend_Dom_Query
230
  protected function _getNodeList($document, $xpathQuery)
231
  {
232
  $xpath = new DOMXPath($document);
 
 
 
233
  $xpathQuery = (string) $xpathQuery;
234
  if (preg_match_all('|\[contains\((@[a-z0-9_-]+),\s?\' |i', $xpathQuery, $matches)) {
235
  foreach ($matches[1] as $attribute) {
16
  * @package Zend_Dom
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Query.php 23062 2010-10-08 14:05:45Z matthew $
20
  */
21
 
22
  /**
64
  */
65
  protected $_docType;
66
 
67
+ /**
68
+ * Document encoding
69
+ * @var null|string
70
+ */
71
+ protected $_encoding;
72
+
73
+ /**
74
+ * XPath namespaces
75
+ * @var array
76
+ */
77
+ protected $_xpathNamespaces = array();
78
+
79
  /**
80
  * Constructor
81
  *
82
  * @param null|string $document
83
  * @return void
84
  */
85
+ public function __construct($document = null, $encoding = null)
86
  {
87
+ $this->setEncoding($encoding);
88
  $this->setDocument($document);
89
  }
90
 
91
+ /**
92
+ * Set document encoding
93
+ *
94
+ * @param string $encoding
95
+ * @return Zend_Dom_Query
96
+ */
97
+ public function setEncoding($encoding)
98
+ {
99
+ $this->_encoding = (null === $encoding) ? null : (string) $encoding;
100
+ return $this;
101
+ }
102
+
103
+ /**
104
+ * Get document encoding
105
+ *
106
+ * @return null|string
107
+ */
108
+ public function getEncoding()
109
+ {
110
+ return $this->_encoding;
111
+ }
112
+
113
  /**
114
  * Set document to query
115
  *
116
  * @param string $document
117
+ * @param null|string $encoding Document encoding
118
  * @return Zend_Dom_Query
119
  */
120
+ public function setDocument($document, $encoding = null)
121
  {
122
  if (0 === strlen($document)) {
123
  return $this;
124
  }
125
  // breaking XML declaration to make syntax highlighting work
126
  if ('<' . '?xml' == substr(trim($document), 0, 5)) {
127
+ return $this->setDocumentXml($document, $encoding);
128
  }
129
  if (strstr($document, 'DTD XHTML')) {
130
+ return $this->setDocumentXhtml($document, $encoding);
131
  }
132
+ return $this->setDocumentHtml($document, $encoding);
133
  }
134
 
135
  /**
136
  * Register HTML document
137
  *
138
  * @param string $document
139
+ * @param null|string $encoding Document encoding
140
  * @return Zend_Dom_Query
141
  */
142
+ public function setDocumentHtml($document, $encoding = null)
143
  {
144
  $this->_document = (string) $document;
145
  $this->_docType = self::DOC_HTML;
146
+ if (null !== $encoding) {
147
+ $this->setEncoding($encoding);
148
+ }
149
  return $this;
150
  }
151
 
153
  * Register XHTML document
154
  *
155
  * @param string $document
156
+ * @param null|string $encoding Document encoding
157
  * @return Zend_Dom_Query
158
  */
159
+ public function setDocumentXhtml($document, $encoding = null)
160
  {
161
  $this->_document = (string) $document;
162
  $this->_docType = self::DOC_XHTML;
163
+ if (null !== $encoding) {
164
+ $this->setEncoding($encoding);
165
+ }
166
  return $this;
167
  }
168
 
170
  * Register XML document
171
  *
172
  * @param string $document
173
+ * @param null|string $encoding Document encoding
174
  * @return Zend_Dom_Query
175
  */
176
+ public function setDocumentXml($document, $encoding = null)
177
  {
178
  $this->_document = (string) $document;
179
  $this->_docType = self::DOC_XML;
180
+ if (null !== $encoding) {
181
+ $this->setEncoding($encoding);
182
+ }
183
  return $this;
184
  }
185
 
239
  throw new Zend_Dom_Exception('Cannot query; no document registered');
240
  }
241
 
242
+ $encoding = $this->getEncoding();
243
  libxml_use_internal_errors(true);
244
+ if (null === $encoding) {
245
+ $domDoc = new DOMDocument('1.0');
246
+ } else {
247
+ $domDoc = new DOMDocument('1.0', $encoding);
248
+ }
249
  $type = $this->getDocumentType();
250
  switch ($type) {
251
  case self::DOC_XML:
273
  return new Zend_Dom_Query_Result($query, $xpathQuery, $domDoc, $nodeList);
274
  }
275
 
276
+ /**
277
+ * Register XPath namespaces
278
+ *
279
+ * @param array $xpathNamespaces
280
+ * @return void
281
+ */
282
+ public function registerXpathNamespaces($xpathNamespaces)
283
+ {
284
+ $this->_xpathNamespaces = $xpathNamespaces;
285
+ }
286
+
287
  /**
288
  * Prepare node list
289
  *
294
  protected function _getNodeList($document, $xpathQuery)
295
  {
296
  $xpath = new DOMXPath($document);
297
+ foreach ($this->_xpathNamespaces as $prefix => $namespaceUri) {
298
+ $xpath->registerNamespace($prefix, $namespaceUri);
299
+ }
300
  $xpathQuery = (string) $xpathQuery;
301
  if (preg_match_all('|\[contains\((@[a-z0-9_-]+),\s?\' |i', $xpathQuery, $matches)) {
302
  foreach ($matches[1] as $attribute) {
lib/Zend/Dom/Query/Css2Xpath.php CHANGED
@@ -25,7 +25,7 @@
25
  * @subpackage Query
26
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
  * @license http://framework.zend.com/license/new-bsd New BSD License
28
- * @version $Id: Css2Xpath.php 22045 2010-04-28 19:59:49Z matthew $
29
  */
30
  class Zend_Dom_Query_Css2Xpath
31
  {
25
  * @subpackage Query
26
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
  * @license http://framework.zend.com/license/new-bsd New BSD License
28
+ * @version $Id: Css2Xpath.php 22044 2010-04-28 19:58:29Z matthew $
29
  */
30
  class Zend_Dom_Query_Css2Xpath
31
  {
lib/Zend/Exception.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
  /**
16
  * @package Zend
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Exception.php 20978 2010-02-08 15:35:25Z matthew $
20
  */
21
 
22
  /**
lib/Zend/Feed/Pubsubhubbub.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
  /**
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Pubsubhubbub.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  /**
lib/Zend/Feed/Pubsubhubbub/CallbackAbstract.php CHANGED
@@ -17,6 +17,7 @@
17
  * @subpackage Callback
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
20
  */
21
 
22
  /**
@@ -73,7 +74,7 @@ abstract class Zend_Feed_Pubsubhubbub_CallbackAbstract
73
  */
74
  public function __construct($config = null)
75
  {
76
- if (!is_null($config)) {
77
  $this->setConfig($config);
78
  }
79
  }
17
  * @subpackage Callback
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: CallbackAbstract.php 22662 2010-07-24 17:37:36Z mabe $
21
  */
22
 
23
  /**
74
  */
75
  public function __construct($config = null)
76
  {
77
+ if ($config !== null) {
78
  $this->setConfig($config);
79
  }
80
  }
lib/Zend/Feed/Pubsubhubbub/CallbackInterface.php CHANGED
@@ -17,6 +17,7 @@
17
  * @subpackage Callback
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
20
  */
21
 
22
  /**
17
  * @subpackage Callback
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: CallbackInterface.php 20785 2010-01-31 09:43:03Z mikaelkael $
21
  */
22
 
23
  /**
lib/Zend/Feed/Pubsubhubbub/Exception.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
  /**
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Exception.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  /**
lib/Zend/Feed/Pubsubhubbub/HttpResponse.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
  /**
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: HttpResponse.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  /**
lib/Zend/Feed/Pubsubhubbub/Model/ModelAbstract.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
 
@@ -52,7 +53,7 @@ class Zend_Feed_Pubsubhubbub_Model_ModelAbstract
52
  */
53
  public function __construct(Zend_Db_Table_Abstract $tableGateway = null)
54
  {
55
- if (is_null($tableGateway)) {
56
  $parts = explode('_', get_class($this));
57
  $table = strtolower(array_pop($parts));
58
  $this->_db = new Zend_Db_Table($table);
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: ModelAbstract.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
 
53
  */
54
  public function __construct(Zend_Db_Table_Abstract $tableGateway = null)
55
  {
56
+ if ($tableGateway === null) {
57
  $parts = explode('_', get_class($this));
58
  $table = strtolower(array_pop($parts));
59
  $this->_db = new Zend_Db_Table($table);
lib/Zend/Feed/Pubsubhubbub/Model/Subscription.php CHANGED
@@ -17,6 +17,7 @@
17
  * @subpackage Entity
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
20
  */
21
 
22
  /** @see Zend_Feed_Pubsubhubbub_Model_ModelAbstract */
17
  * @subpackage Entity
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Subscription.php 22507 2010-06-30 19:11:27Z ramon $
21
  */
22
 
23
  /** @see Zend_Feed_Pubsubhubbub_Model_ModelAbstract */
lib/Zend/Feed/Pubsubhubbub/Model/SubscriptionInterface.php CHANGED
@@ -17,6 +17,7 @@
17
  * @subpackage Entity
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
20
  */
21
 
22
  /**
17
  * @subpackage Entity
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: SubscriptionInterface.php 20785 2010-01-31 09:43:03Z mikaelkael $
21
  */
22
 
23
  /**
lib/Zend/Feed/Pubsubhubbub/Publisher.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
  /**
@@ -73,7 +74,7 @@ class Zend_Feed_Pubsubhubbub_Publisher
73
  */
74
  public function __construct($config = null)
75
  {
76
- if (!is_null($config)) {
77
  $this->setConfig($config);
78
  }
79
  }
@@ -305,7 +306,7 @@ class Zend_Feed_Pubsubhubbub_Publisher
305
  $this->removeParameter($name);
306
  return $this;
307
  }
308
- if (empty($value) || (!is_string($value) && !is_null($value))) {
309
  #require_once 'Zend/Feed/Pubsubhubbub/Exception.php';
310
  throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "value"'
311
  .' of "' . $value . '" must be a non-empty string');
@@ -411,7 +412,7 @@ class Zend_Feed_Pubsubhubbub_Publisher
411
  $params[] = urlencode($name) . '=' . urlencode($value);
412
  }
413
  $paramString = implode('&', $params);
414
- $client->setRawData($paramString);
415
  return $client;
416
  }
417
  }
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Publisher.php 23075 2010-10-10 21:31:30Z padraic $
20
  */
21
 
22
  /**
74
  */
75
  public function __construct($config = null)
76
  {
77
+ if ($config !== null) {
78
  $this->setConfig($config);
79
  }
80
  }
306
  $this->removeParameter($name);
307
  return $this;
308
  }
309
+ if (empty($value) || (!is_string($value) && $value !== null)) {
310
  #require_once 'Zend/Feed/Pubsubhubbub/Exception.php';
311
  throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "value"'
312
  .' of "' . $value . '" must be a non-empty string');
412
  $params[] = urlencode($name) . '=' . urlencode($value);
413
  }
414
  $paramString = implode('&', $params);
415
+ $client->setRawData($paramString, 'application/x-www-form-urlencoded');
416
  return $client;
417
  }
418
  }
lib/Zend/Feed/Pubsubhubbub/Subscriber.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
  /**
@@ -149,7 +150,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber
149
  */
150
  public function __construct($config = null)
151
  {
152
- if (!is_null($config)) {
153
  $this->setConfig($config);
154
  }
155
  }
@@ -470,7 +471,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber
470
  $this->removeParameter($name);
471
  return $this;
472
  }
473
- if (empty($value) || (!is_string($value) && !is_null($value))) {
474
  #require_once 'Zend/Feed/Pubsubhubbub/Exception.php';
475
  throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "value"'
476
  . ' of "' . $value . '" must be a non-empty string');
@@ -637,7 +638,10 @@ class Zend_Feed_Pubsubhubbub_Subscriber
637
  $client->setAuth($auth[0], $auth[1]);
638
  }
639
  $client->setUri($url);
640
- $client->setRawData($this->_getRequestParameters($url, $mode));
 
 
 
641
  $response = $client->request();
642
  if ($response->getStatus() !== 204
643
  && $response->getStatus() !== 202
@@ -732,7 +736,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber
732
  $params['hub.callback'] = rtrim($this->getCallbackUrl(), '/')
733
  . '/' . Zend_Feed_Pubsubhubbub::urlencode($key);
734
  }
735
- if ($mode == 'subscribe' && !is_null($this->getLeaseSeconds())) {
736
  $params['hub.lease_seconds'] = $this->getLeaseSeconds();
737
  }
738
 
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Subscriber.php 23170 2010-10-19 18:29:24Z mabe $
20
  */
21
 
22
  /**
150
  */
151
  public function __construct($config = null)
152
  {
153
+ if ($config !== null) {
154
  $this->setConfig($config);
155
  }
156
  }
471
  $this->removeParameter($name);
472
  return $this;
473
  }
474
+ if (empty($value) || (!is_string($value) && $value !== null)) {
475
  #require_once 'Zend/Feed/Pubsubhubbub/Exception.php';
476
  throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "value"'
477
  . ' of "' . $value . '" must be a non-empty string');
638
  $client->setAuth($auth[0], $auth[1]);
639
  }
640
  $client->setUri($url);
641
+ $client->setRawData(
642
+ $this->_getRequestParameters($url, $mode),
643
+ 'application/x-www-form-urlencoded'
644
+ );
645
  $response = $client->request();
646
  if ($response->getStatus() !== 204
647
  && $response->getStatus() !== 202
736
  $params['hub.callback'] = rtrim($this->getCallbackUrl(), '/')
737
  . '/' . Zend_Feed_Pubsubhubbub::urlencode($key);
738
  }
739
+ if ($mode == 'subscribe' && $this->getLeaseSeconds() !== null) {
740
  $params['hub.lease_seconds'] = $this->getLeaseSeconds();
741
  }
742
 
lib/Zend/Feed/Pubsubhubbub/Subscriber/Callback.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
  /**
@@ -101,13 +102,14 @@ class Zend_Feed_Pubsubhubbub_Subscriber_Callback
101
  * SHOULD be validated/processed by an asynchronous process so as
102
  * to avoid holding up responses to the Hub.
103
  */
 
104
  if (strtolower($_SERVER['REQUEST_METHOD']) == 'post'
105
  && $this->_hasValidVerifyToken(null, false)
106
- && ($this->_getHeader('Content-Type') == 'application/atom+xml'
107
- || $this->_getHeader('Content-Type') == 'application/rss+xml'
108
- || $this->_getHeader('Content-Type') == 'application/xml'
109
- || $this->_getHeader('Content-Type') == 'text/xml'
110
- || $this->_getHeader('Content-Type') == 'application/rdf+xml')
111
  ) {
112
  $this->setFeedUpdate($this->_getRawBody());
113
  $this->getHttpResponse()
@@ -207,7 +209,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber_Callback
207
  */
208
  public function hasFeedUpdate()
209
  {
210
- if (is_null($this->_feedUpdate)) {
211
  return false;
212
  }
213
  return true;
16
  * @package Zend_Feed_Pubsubhubbub
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Callback.php 23069 2010-10-10 10:57:42Z padraic $
20
  */
21
 
22
  /**
102
  * SHOULD be validated/processed by an asynchronous process so as
103
  * to avoid holding up responses to the Hub.
104
  */
105
+ $contentType = $this->_getHeader('Content-Type');
106
  if (strtolower($_SERVER['REQUEST_METHOD']) == 'post'
107
  && $this->_hasValidVerifyToken(null, false)
108
+ && (stripos($contentType, 'application/atom+xml') === 0
109
+ || stripos($contentType, 'application/rss+xml') === 0
110
+ || stripos($contentType, 'application/xml') === 0
111
+ || stripos($contentType, 'text/xml') === 0
112
+ || stripos($contentType, 'application/rdf+xml') === 0)
113
  ) {
114
  $this->setFeedUpdate($this->_getRawBody());
115
  $this->getHttpResponse()
209
  */
210
  public function hasFeedUpdate()
211
  {
212
+ if ($this->_feedUpdate === null) {
213
  return false;
214
  }
215
  return true;
lib/Zend/Feed/Reader.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Reader.php 22093 2010-05-04 12:55:06Z padraic $
20
  */
21
 
22
  /**
@@ -236,10 +236,10 @@ class Zend_Feed_Reader
236
  if (self::$_httpConditionalGet && $cache) {
237
  $data = $cache->load($cacheId);
238
  if ($data) {
239
- if (is_null($etag)) {
240
  $etag = $cache->load($cacheId.'_etag');
241
  }
242
- if (is_null($lastModified)) {
243
  $lastModified = $cache->load($cacheId.'_lastmodified');;
244
  }
245
  if ($etag) {
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Reader.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
236
  if (self::$_httpConditionalGet && $cache) {
237
  $data = $cache->load($cacheId);
238
  if ($data) {
239
+ if ($etag === null) {
240
  $etag = $cache->load($cacheId.'_etag');
241
  }
242
+ if ($lastModified === null) {
243
  $lastModified = $cache->load($cacheId.'_lastmodified');;
244
  }
245
  if ($etag) {
lib/Zend/Feed/Reader/Collection.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id$
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Collection.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  /**
lib/Zend/Feed/Reader/Collection/Category.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Category.php 20954 2010-02-06 17:56:27Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Category.php 20953 2010-02-06 17:55:34Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Reader/Entry/Rss.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Rss.php 22301 2010-05-26 10:15:13Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Rss.php 22300 2010-05-26 10:13:34Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Reader/Extension/Atom/Entry.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Entry.php 22301 2010-05-26 10:15:13Z padraic $
20
  */
21
 
22
  /**
@@ -584,7 +584,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry
584
  protected function _absolutiseUri($link)
585
  {
586
  if (!Zend_Uri::check($link)) {
587
- if (!is_null($this->getBaseUrl())) {
588
  $link = $this->getBaseUrl() . $link;
589
  if (!Zend_Uri::check($link)) {
590
  $link = null;
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Entry.php 23170 2010-10-19 18:29:24Z mabe $
20
  */
21
 
22
  /**
584
  protected function _absolutiseUri($link)
585
  {
586
  if (!Zend_Uri::check($link)) {
587
+ if ($this->getBaseUrl() !== null) {
588
  $link = $this->getBaseUrl() . $link;
589
  if (!Zend_Uri::check($link)) {
590
  $link = null;
lib/Zend/Feed/Reader/Extension/Atom/Feed.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Feed.php 22301 2010-05-26 10:15:13Z padraic $
20
  */
21
 
22
  /**
@@ -315,6 +315,30 @@ class Zend_Feed_Reader_Extension_Atom_Feed
315
 
316
  return $this->_data['image'];
317
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
 
319
  /**
320
  * Get the base URI of the feed (if set).
@@ -515,7 +539,7 @@ class Zend_Feed_Reader_Extension_Atom_Feed
515
  protected function _absolutiseUri($link)
516
  {
517
  if (!Zend_Uri::check($link)) {
518
- if (!is_null($this->getBaseUrl())) {
519
  $link = $this->getBaseUrl() . $link;
520
  if (!Zend_Uri::check($link)) {
521
  $link = null;
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Feed.php 23170 2010-10-19 18:29:24Z mabe $
20
  */
21
 
22
  /**
315
 
316
  return $this->_data['image'];
317
  }
318
+
319
+ /**
320
+ * Get the feed image
321
+ *
322
+ * @return array|null
323
+ */
324
+ public function getIcon()
325
+ {
326
+ if (array_key_exists('icon', $this->_data)) {
327
+ return $this->_data['icon'];
328
+ }
329
+
330
+ $imageUrl = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:icon)');
331
+
332
+ if (!$imageUrl) {
333
+ $image = null;
334
+ } else {
335
+ $image = array('uri'=>$imageUrl);
336
+ }
337
+
338
+ $this->_data['icon'] = $image;
339
+
340
+ return $this->_data['icon'];
341
+ }
342
 
343
  /**
344
  * Get the base URI of the feed (if set).
539
  protected function _absolutiseUri($link)
540
  {
541
  if (!Zend_Uri::check($link)) {
542
+ if ($this->getBaseUrl() !== null) {
543
  $link = $this->getBaseUrl() . $link;
544
  if (!Zend_Uri::check($link)) {
545
  $link = null;
lib/Zend/Feed/Reader/Extension/Content/Entry.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Entry.php 22301 2010-05-26 10:15:13Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Entry.php 22300 2010-05-26 10:13:34Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Reader/Extension/EntryAbstract.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: EntryAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -83,7 +83,7 @@ abstract class Zend_Feed_Reader_Extension_EntryAbstract
83
  $this->_entryKey = $entryKey;
84
  $this->_domDocument = $entry->ownerDocument;
85
 
86
- if (!is_null($type)) {
87
  $this->_data['type'] = $type;
88
  } else {
89
  $this->_data['type'] = Zend_Feed_Reader::detectType($entry->ownerDocument, true);
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: EntryAbstract.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
83
  $this->_entryKey = $entryKey;
84
  $this->_domDocument = $entry->ownerDocument;
85
 
86
+ if ($type !== null) {
87
  $this->_data['type'] = $type;
88
  } else {
89
  $this->_data['type'] = Zend_Feed_Reader::detectType($entry->ownerDocument, true);
lib/Zend/Feed/Reader/Feed/Atom.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Atom.php 22108 2010-05-05 13:44:11Z padraic $
20
  */
21
 
22
  /**
@@ -318,7 +318,7 @@ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract
318
 
319
  $link = $this->getExtension('Atom')->getFeedLink();
320
 
321
- if (is_null($link) || empty($link)) {
322
  $link = $this->getOriginalSourceUri();
323
  }
324
 
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Atom.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
318
 
319
  $link = $this->getExtension('Atom')->getFeedLink();
320
 
321
+ if ($link === null || empty($link)) {
322
  $link = $this->getOriginalSourceUri();
323
  }
324
 
lib/Zend/Feed/Reader/Feed/Atom/Source.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Atom.php 19165 2009-11-21 16:46:40Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Source.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  /**
lib/Zend/Feed/Reader/Feed/Rss.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Rss.php 22301 2010-05-26 10:15:13Z padraic $
20
  */
21
 
22
  /**
@@ -178,7 +178,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract
178
  $copyright = $this->_xpath->evaluate('string(/rss/channel/copyright)');
179
  }
180
 
181
- if (!$copyright && !is_null($this->getExtension('DublinCore'))) {
182
  $copyright = $this->getExtension('DublinCore')->getCopyright();
183
  }
184
 
@@ -344,7 +344,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract
344
  $description = $this->_xpath->evaluate('string(/rdf:RDF/rss:channel/rss:description)');
345
  }
346
 
347
- if (!$description && !is_null($this->getExtension('DublinCore'))) {
348
  $description = $this->getExtension('DublinCore')->getDescription();
349
  }
350
 
@@ -379,7 +379,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract
379
  $id = $this->_xpath->evaluate('string(/rss/channel/guid)');
380
  }
381
 
382
- if (!$id && !is_null($this->getExtension('DublinCore'))) {
383
  $id = $this->getExtension('DublinCore')->getId();
384
  }
385
 
@@ -474,7 +474,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract
474
  $language = $this->_xpath->evaluate('string(/rss/channel/language)');
475
  }
476
 
477
- if (!$language && !is_null($this->getExtension('DublinCore'))) {
478
  $language = $this->getExtension('DublinCore')->getLanguage();
479
  }
480
 
@@ -543,7 +543,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract
543
 
544
  $link = $this->getExtension('Atom')->getFeedLink();
545
 
546
- if (is_null($link) || empty($link)) {
547
  $link = $this->getOriginalSourceUri();
548
  }
549
 
@@ -612,7 +612,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract
612
  $title = $this->_xpath->evaluate('string(/rdf:RDF/rss:channel/rss:title)');
613
  }
614
 
615
- if (!$title && !is_null($this->getExtension('DublinCore'))) {
616
  $title = $this->getExtension('DublinCore')->getTitle();
617
  }
618
 
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Rss.php 23170 2010-10-19 18:29:24Z mabe $
20
  */
21
 
22
  /**
178
  $copyright = $this->_xpath->evaluate('string(/rss/channel/copyright)');
179
  }
180
 
181
+ if (!$copyright && $this->getExtension('DublinCore') !== null) {
182
  $copyright = $this->getExtension('DublinCore')->getCopyright();
183
  }
184
 
344
  $description = $this->_xpath->evaluate('string(/rdf:RDF/rss:channel/rss:description)');
345
  }
346
 
347
+ if (!$description && $this->getExtension('DublinCore') !== null) {
348
  $description = $this->getExtension('DublinCore')->getDescription();
349
  }
350
 
379
  $id = $this->_xpath->evaluate('string(/rss/channel/guid)');
380
  }
381
 
382
+ if (!$id && $this->getExtension('DublinCore') !== null) {
383
  $id = $this->getExtension('DublinCore')->getId();
384
  }
385
 
474
  $language = $this->_xpath->evaluate('string(/rss/channel/language)');
475
  }
476
 
477
+ if (!$language && $this->getExtension('DublinCore') !== null) {
478
  $language = $this->getExtension('DublinCore')->getLanguage();
479
  }
480
 
543
 
544
  $link = $this->getExtension('Atom')->getFeedLink();
545
 
546
+ if ($link === null || empty($link)) {
547
  $link = $this->getOriginalSourceUri();
548
  }
549
 
612
  $title = $this->_xpath->evaluate('string(/rdf:RDF/rss:channel/rss:title)');
613
  }
614
 
615
+ if (!$title && $this->getExtension('DublinCore') !== null) {
616
  $title = $this->getExtension('DublinCore')->getTitle();
617
  }
618
 
lib/Zend/Feed/Reader/FeedAbstract.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: FeedAbstract.php 22093 2010-05-04 12:55:06Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: FeedAbstract.php 22092 2010-05-04 12:50:51Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Reader/FeedSet.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: FeedSet.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -88,7 +88,7 @@ class Zend_Feed_Reader_FeedSet extends ArrayObject
88
  protected function _absolutiseUri($link, $uri = null)
89
  {
90
  if (!Zend_Uri::check($link)) {
91
- if (!is_null($uri)) {
92
  $uri = Zend_Uri::factory($uri);
93
 
94
  if ($link[0] !== '/') {
16
  * @package Zend_Feed_Reader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: FeedSet.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
88
  protected function _absolutiseUri($link, $uri = null)
89
  {
90
  if (!Zend_Uri::check($link)) {
91
+ if ($uri !== null) {
92
  $uri = Zend_Uri::factory($uri);
93
 
94
  if ($link[0] !== '/') {
lib/Zend/Feed/Writer/Deleted.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  #require_once 'Zend/Feed/Writer/Feed/FeedAbstract.php';
@@ -126,7 +126,7 @@ class Zend_Feed_Writer_Deleted
126
  public function setWhen($date = null)
127
  {
128
  $zdate = null;
129
- if (is_null($date)) {
130
  $zdate = new Zend_Date;
131
  } elseif (ctype_digit($date) && strlen($date) == 10) {
132
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Deleted.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  #require_once 'Zend/Feed/Writer/Feed/FeedAbstract.php';
126
  public function setWhen($date = null)
127
  {
128
  $zdate = null;
129
+ if ($date === null) {
130
  $zdate = new Zend_Date;
131
  } elseif (ctype_digit($date) && strlen($date) == 10) {
132
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
lib/Zend/Feed/Writer/Entry.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Entry.php 22065 2010-04-30 14:04:57Z padraic $
20
  */
21
 
22
  /**
@@ -212,7 +212,7 @@ class Zend_Feed_Writer_Entry
212
  public function setDateCreated($date = null)
213
  {
214
  $zdate = null;
215
- if (is_null($date)) {
216
  $zdate = new Zend_Date;
217
  } elseif (ctype_digit($date) && strlen($date) == 10) {
218
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
@@ -233,7 +233,7 @@ class Zend_Feed_Writer_Entry
233
  public function setDateModified($date = null)
234
  {
235
  $zdate = null;
236
- if (is_null($date)) {
237
  $zdate = new Zend_Date;
238
  } elseif (ctype_digit($date) && strlen($date) == 10) {
239
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Entry.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
212
  public function setDateCreated($date = null)
213
  {
214
  $zdate = null;
215
+ if ($date === null) {
216
  $zdate = new Zend_Date;
217
  } elseif (ctype_digit($date) && strlen($date) == 10) {
218
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
233
  public function setDateModified($date = null)
234
  {
235
  $zdate = null;
236
+ if ($date === null) {
237
  $zdate = new Zend_Date;
238
  } elseif (ctype_digit($date) && strlen($date) == 10) {
239
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
lib/Zend/Feed/Writer/Extension/Atom/Renderer/Feed.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Feed.php 20326 2010-01-16 00:20:43Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Feed.php 20325 2010-01-16 00:17:59Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Writer/Extension/Content/Renderer/Entry.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Entry.php 20325 2010-01-16 00:17:59Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Writer/Extension/DublinCore/Renderer/Entry.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Entry.php 20325 2010-01-16 00:17:59Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Writer/Extension/DublinCore/Renderer/Feed.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Feed.php 20326 2010-01-16 00:20:43Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Feed.php 20325 2010-01-16 00:17:59Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $
20
  */
21
 
22
  /**
@@ -104,7 +104,7 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry
104
  protected function _setBlock(DOMDocument $dom, DOMElement $root)
105
  {
106
  $block = $this->getDataContainer()->getItunesBlock();
107
- if (is_null($block)) {
108
  return;
109
  }
110
  $el = $dom->createElement('itunes:block');
@@ -144,7 +144,7 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry
144
  protected function _setExplicit(DOMDocument $dom, DOMElement $root)
145
  {
146
  $explicit = $this->getDataContainer()->getItunesExplicit();
147
- if (is_null($explicit)) {
148
  return;
149
  }
150
  $el = $dom->createElement('itunes:explicit');
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Entry.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
104
  protected function _setBlock(DOMDocument $dom, DOMElement $root)
105
  {
106
  $block = $this->getDataContainer()->getItunesBlock();
107
+ if ($block === null) {
108
  return;
109
  }
110
  $el = $dom->createElement('itunes:block');
144
  protected function _setExplicit(DOMDocument $dom, DOMElement $root)
145
  {
146
  $explicit = $this->getDataContainer()->getItunesExplicit();
147
+ if ($explicit === null) {
148
  return;
149
  }
150
  $el = $dom->createElement('itunes:explicit');
lib/Zend/Feed/Writer/Extension/ITunes/Renderer/Feed.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Feed.php 20326 2010-01-16 00:20:43Z padraic $
20
  */
21
 
22
  /**
@@ -109,7 +109,7 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed
109
  protected function _setBlock(DOMDocument $dom, DOMElement $root)
110
  {
111
  $block = $this->getDataContainer()->getItunesBlock();
112
- if (is_null($block)) {
113
  return;
114
  }
115
  $el = $dom->createElement('itunes:block');
@@ -200,7 +200,7 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed
200
  protected function _setExplicit(DOMDocument $dom, DOMElement $root)
201
  {
202
  $explicit = $this->getDataContainer()->getItunesExplicit();
203
- if (is_null($explicit)) {
204
  return;
205
  }
206
  $el = $dom->createElement('itunes:explicit');
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Feed.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
109
  protected function _setBlock(DOMDocument $dom, DOMElement $root)
110
  {
111
  $block = $this->getDataContainer()->getItunesBlock();
112
+ if ($block === null) {
113
  return;
114
  }
115
  $el = $dom->createElement('itunes:block');
200
  protected function _setExplicit(DOMDocument $dom, DOMElement $root)
201
  {
202
  $explicit = $this->getDataContainer()->getItunesExplicit();
203
+ if ($explicit === null) {
204
  return;
205
  }
206
  $el = $dom->createElement('itunes:explicit');
lib/Zend/Feed/Writer/Extension/RendererAbstract.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend_Feed_Writer_Entry_Rss
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
  /**
16
  * @package Zend_Feed_Writer_Entry_Rss
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: RendererAbstract.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  /**
lib/Zend/Feed/Writer/Extension/RendererInterface.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
  /**
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: RendererInterface.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  /**
lib/Zend/Feed/Writer/Extension/Slash/Renderer/Entry.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $
20
  */
21
 
22
  /**
@@ -81,7 +81,7 @@ class Zend_Feed_Writer_Extension_Slash_Renderer_Entry
81
  {
82
  $count = $this->getDataContainer()->getCommentCount();
83
  if (!$count) {
84
- $count = 0;
85
  }
86
  $tcount = $this->_dom->createElement('slash:comments');
87
  $tcount->nodeValue = $count;
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Entry.php 23077 2010-10-10 23:06:49Z padraic $
20
  */
21
 
22
  /**
81
  {
82
  $count = $this->getDataContainer()->getCommentCount();
83
  if (!$count) {
84
+ return;
85
  }
86
  $tcount = $this->_dom->createElement('slash:comments');
87
  $tcount->nodeValue = $count;
lib/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $
20
  */
21
 
22
  /**
@@ -90,7 +90,7 @@ class Zend_Feed_Writer_Extension_Threading_Renderer_Entry
90
  $clink->setAttribute('type', 'text/html');
91
  $clink->setAttribute('href', $link);
92
  $count = $this->getDataContainer()->getCommentCount();
93
- if (!is_null($count)) {
94
  $clink->setAttribute('thr:count', $count);
95
  }
96
  $root->appendChild($clink);
@@ -116,7 +116,7 @@ class Zend_Feed_Writer_Extension_Threading_Renderer_Entry
116
  $flink->setAttribute('type', 'application/'. $link['type'] .'+xml');
117
  $flink->setAttribute('href', $link['uri']);
118
  $count = $this->getDataContainer()->getCommentCount();
119
- if (!is_null($count)) {
120
  $flink->setAttribute('thr:count', $count);
121
  }
122
  $root->appendChild($flink);
@@ -134,7 +134,7 @@ class Zend_Feed_Writer_Extension_Threading_Renderer_Entry
134
  protected function _setCommentCount(DOMDocument $dom, DOMElement $root)
135
  {
136
  $count = $this->getDataContainer()->getCommentCount();
137
- if (is_null($count)) {
138
  return;
139
  }
140
  $tcount = $this->_dom->createElement('thr:total');
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Entry.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
90
  $clink->setAttribute('type', 'text/html');
91
  $clink->setAttribute('href', $link);
92
  $count = $this->getDataContainer()->getCommentCount();
93
+ if ($count !== null) {
94
  $clink->setAttribute('thr:count', $count);
95
  }
96
  $root->appendChild($clink);
116
  $flink->setAttribute('type', 'application/'. $link['type'] .'+xml');
117
  $flink->setAttribute('href', $link['uri']);
118
  $count = $this->getDataContainer()->getCommentCount();
119
+ if ($count !== null) {
120
  $flink->setAttribute('thr:count', $count);
121
  }
122
  $root->appendChild($flink);
134
  protected function _setCommentCount(DOMDocument $dom, DOMElement $root)
135
  {
136
  $count = $this->getDataContainer()->getCommentCount();
137
+ if ($count === null) {
138
  return;
139
  }
140
  $tcount = $this->_dom->createElement('thr:total');
lib/Zend/Feed/Writer/Extension/WellFormedWeb/Renderer/Entry.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Entry.php 20325 2010-01-16 00:17:59Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Writer/Feed.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Feed.php 20519 2010-01-22 14:06:24Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Feed.php 20518 2010-01-22 14:00:30Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Writer/Feed/FeedAbstract.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -174,7 +174,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract
174
  public function setDateCreated($date = null)
175
  {
176
  $zdate = null;
177
- if (is_null($date)) {
178
  $zdate = new Zend_Date;
179
  } elseif (ctype_digit($date) && strlen($date) == 10) {
180
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
@@ -195,7 +195,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract
195
  public function setDateModified($date = null)
196
  {
197
  $zdate = null;
198
- if (is_null($date)) {
199
  $zdate = new Zend_Date;
200
  } elseif (ctype_digit($date) && strlen($date) == 10) {
201
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
@@ -216,7 +216,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract
216
  public function setLastBuildDate($date = null)
217
  {
218
  $zdate = null;
219
- if (is_null($date)) {
220
  $zdate = new Zend_Date;
221
  } elseif (ctype_digit($date) && strlen($date) == 10) {
222
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
@@ -361,6 +361,24 @@ class Zend_Feed_Writer_Feed_FeedAbstract
361
  }
362
  $this->_data['image'] = $data;
363
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
 
365
  /**
366
  * Set the feed language
@@ -653,6 +671,19 @@ class Zend_Feed_Writer_Feed_FeedAbstract
653
  }
654
  return $this->_data['image'];
655
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
656
 
657
  /**
658
  * Get the feed language
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: FeedAbstract.php 23090 2010-10-12 17:28:16Z padraic $
20
  */
21
 
22
  /**
174
  public function setDateCreated($date = null)
175
  {
176
  $zdate = null;
177
+ if ($date === null) {
178
  $zdate = new Zend_Date;
179
  } elseif (ctype_digit($date) && strlen($date) == 10) {
180
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
195
  public function setDateModified($date = null)
196
  {
197
  $zdate = null;
198
+ if ($date === null) {
199
  $zdate = new Zend_Date;
200
  } elseif (ctype_digit($date) && strlen($date) == 10) {
201
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
216
  public function setLastBuildDate($date = null)
217
  {
218
  $zdate = null;
219
+ if ($date === null) {
220
  $zdate = new Zend_Date;
221
  } elseif (ctype_digit($date) && strlen($date) == 10) {
222
  $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
361
  }
362
  $this->_data['image'] = $data;
363
  }
364
+
365
+ /**
366
+ * Set a feed icon (URI at minimum). Parameter is a single array with the
367
+ * required key 'uri'. Only 'uri' is required and used for Atom rendering.
368
+ * RSS does not support an Icon tag except via Atom 1.0 as an extension.
369
+ *
370
+ * @param array $data
371
+ */
372
+ public function setIcon(array $data)
373
+ {
374
+ if (empty($data['uri']) || !is_string($data['uri'])
375
+ || !Zend_Uri::check($data['uri'])) {
376
+ #require_once 'Zend/Feed/Exception.php';
377
+ throw new Zend_Feed_Exception('Invalid parameter: parameter \'uri\''
378
+ . ' must be a non-empty string and valid URI/IRI');
379
+ }
380
+ $this->_data['icon'] = $data;
381
+ }
382
 
383
  /**
384
  * Set the feed language
671
  }
672
  return $this->_data['image'];
673
  }
674
+
675
+ /**
676
+ * Get the feed icon URI
677
+ *
678
+ * @return array
679
+ */
680
+ public function getIcon()
681
+ {
682
+ if (!array_key_exists('icon', $this->_data)) {
683
+ return null;
684
+ }
685
+ return $this->_data['icon'];
686
+ }
687
 
688
  /**
689
  * Get the feed language
lib/Zend/Feed/Writer/Renderer/Entry/Atom.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Atom.php 22759 2010-08-01 19:26:34Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Atom.php 22758 2010-08-01 19:23:27Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Writer/Renderer/Entry/Atom/Deleted.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Atom.php 20506 2010-01-21 22:19:05Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Deleted.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  /**
lib/Zend/Feed/Writer/Renderer/Entry/Rss.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Rss.php 22065 2010-04-30 14:04:57Z padraic $
20
  */
21
 
22
  /**
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Rss.php 22064 2010-04-30 14:02:38Z padraic $
20
  */
21
 
22
  /**
lib/Zend/Feed/Writer/Renderer/Feed/Atom.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Atom.php 22098 2010-05-04 18:03:29Z padraic $
20
  */
21
 
22
  /** @see Zend_Feed_Writer_Feed */
@@ -82,6 +82,7 @@ class Zend_Feed_Writer_Renderer_Feed_Atom
82
  $this->_setTitle($this->_dom, $root);
83
  $this->_setDescription($this->_dom, $root);
84
  $this->_setImage($this->_dom, $root);
 
85
  $this->_setDateCreated($this->_dom, $root);
86
  $this->_setDateModified($this->_dom, $root);
87
  $this->_setGenerator($this->_dom, $root);
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Atom.php 23090 2010-10-12 17:28:16Z padraic $
20
  */
21
 
22
  /** @see Zend_Feed_Writer_Feed */
82
  $this->_setTitle($this->_dom, $root);
83
  $this->_setDescription($this->_dom, $root);
84
  $this->_setImage($this->_dom, $root);
85
+ $this->_setIcon($this->_dom, $root);
86
  $this->_setDateCreated($this->_dom, $root);
87
  $this->_setDateModified($this->_dom, $root);
88
  $this->_setGenerator($this->_dom, $root);
lib/Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /** @see Zend_Feed_Writer_Feed */
@@ -341,6 +341,25 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract
341
  $img->appendChild($text);
342
  }
343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
  /**
345
  * Set date feed was created
346
  *
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: AtomAbstract.php 23090 2010-10-12 17:28:16Z padraic $
20
  */
21
 
22
  /** @see Zend_Feed_Writer_Feed */
341
  $img->appendChild($text);
342
  }
343
 
344
+ /**
345
+ * Set feed level icon (image)
346
+ *
347
+ * @param DOMDocument $dom
348
+ * @param DOMElement $root
349
+ * @return void
350
+ */
351
+ protected function _setIcon(DOMDocument $dom, DOMElement $root)
352
+ {
353
+ $image = $this->getDataContainer()->getIcon();
354
+ if (!$image) {
355
+ return;
356
+ }
357
+ $img = $dom->createElement('icon');
358
+ $root->appendChild($img);
359
+ $text = $dom->createTextNode($image['uri']);
360
+ $img->appendChild($text);
361
+ }
362
+
363
  /**
364
  * Set date feed was created
365
  *
lib/Zend/Feed/Writer/Renderer/Feed/Atom/Source.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  #require_once 'Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php';
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Source.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  #require_once 'Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php';
lib/Zend/Feed/Writer/Renderer/Feed/Rss.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Rss.php 22108 2010-05-05 13:44:11Z padraic $
20
  */
21
 
22
  /** @see Zend_Feed_Writer_Feed */
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Rss.php 22107 2010-05-05 13:42:20Z padraic $
20
  */
21
 
22
  /** @see Zend_Feed_Writer_Feed */
lib/Zend/Feed/Writer/Source.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  #require_once 'Zend/Feed/Writer/Feed/FeedAbstract.php';
16
  * @package Zend_Feed_Writer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Source.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  #require_once 'Zend/Feed/Writer/Feed/FeedAbstract.php';
lib/Zend/File/Transfer.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_File_Transfer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Transfer.php 21202 2010-02-24 22:16:44Z thomas $
20
  */
21
 
22
  /**
16
  * @package Zend_File_Transfer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Transfer.php 21201 2010-02-24 22:13:20Z thomas $
20
  */
21
 
22
  /**
lib/Zend/File/Transfer/Adapter/Abstract.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_File_Transfer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Abstract.php 22372 2010-06-04 20:17:58Z thomas $
20
  */
21
 
22
  /**
16
  * @package Zend_File_Transfer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Abstract.php 22371 2010-06-04 20:09:44Z thomas $
20
  */
21
 
22
  /**
lib/Zend/File/Transfer/Adapter/Http.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_File_Transfer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Http.php 22564 2010-07-15 20:43:55Z thomas $
20
  */
21
 
22
  /**
16
  * @package Zend_File_Transfer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Http.php 22563 2010-07-15 20:42:04Z thomas $
20
  */
21
 
22
  /**
lib/Zend/Filter.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Filter.php 21097 2010-02-19 20:11:34Z thomas $
20
  */
21
 
22
  /**
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Filter.php 21096 2010-02-19 20:10:54Z thomas $
20
  */
21
 
22
  /**
lib/Zend/Filter/Boolean.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id:$
20
  */
21
 
22
  /**
@@ -273,7 +273,7 @@ class Zend_Filter_Boolean implements Zend_Filter_Interface
273
  // NULL (null)
274
  if ($type >= self::NULL) {
275
  $type -= self::NULL;
276
- if (is_null($value)) {
277
  return false;
278
  }
279
  }
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Boolean.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
273
  // NULL (null)
274
  if ($type >= self::NULL) {
275
  $type -= self::NULL;
276
+ if ($value === null) {
277
  return false;
278
  }
279
  }
lib/Zend/Filter/Compress/Rar.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Rar.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -176,7 +176,7 @@ class Zend_Filter_Compress_Rar extends Zend_Filter_Compress_CompressAbstract
176
  public function compress($content)
177
  {
178
  $callback = $this->getCallback();
179
- if (is_null($callback)) {
180
  #require_once 'Zend/Filter/Exception.php';
181
  throw new Zend_Filter_Exception('No compression callback available');
182
  }
@@ -210,7 +210,7 @@ class Zend_Filter_Compress_Rar extends Zend_Filter_Compress_CompressAbstract
210
  }
211
 
212
  $password = $this->getPassword();
213
- if (!is_null($password)) {
214
  $archive = rar_open($archive, $password);
215
  } else {
216
  $archive = rar_open($archive);
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Rar.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
176
  public function compress($content)
177
  {
178
  $callback = $this->getCallback();
179
+ if ($callback === null) {
180
  #require_once 'Zend/Filter/Exception.php';
181
  throw new Zend_Filter_Exception('No compression callback available');
182
  }
210
  }
211
 
212
  $password = $this->getPassword();
213
+ if ($password !== null) {
214
  $archive = rar_open($archive, $password);
215
  } else {
216
  $archive = rar_open($archive);
lib/Zend/Filter/Encrypt/Mcrypt.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Mcrypt.php 20132 2010-01-07 21:33:50Z ralph $
20
  */
21
 
22
  /**
@@ -54,8 +54,15 @@ class Zend_Filter_Encrypt_Mcrypt implements Zend_Filter_Encrypt_Interface
54
  'salt' => false
55
  );
56
 
 
 
 
 
 
 
 
57
  protected static $_srandCalled = false;
58
-
59
  /**
60
  * Class constructor
61
  *
@@ -77,6 +84,11 @@ class Zend_Filter_Encrypt_Mcrypt implements Zend_Filter_Encrypt_Interface
77
  throw new Zend_Filter_Exception('Invalid options argument provided to filter');
78
  }
79
 
 
 
 
 
 
80
  $this->setEncryption($options);
81
  }
82
 
@@ -180,16 +192,49 @@ class Zend_Filter_Encrypt_Mcrypt implements Zend_Filter_Encrypt_Interface
180
  return $this;
181
  }
182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  /**
184
  * Defined by Zend_Filter_Interface
185
  *
186
- * Encrypts the file $value with the defined settings
187
  *
188
- * @param string $value Full path of file to change
189
- * @return string The filename which has been set, or false when there were errors
190
  */
191
  public function encrypt($value)
192
  {
 
 
 
 
 
 
 
193
  $cipher = $this->_openCipher();
194
  $this->_initCipher($cipher);
195
  $encrypted = mcrypt_generic($cipher, $value);
@@ -202,10 +247,10 @@ class Zend_Filter_Encrypt_Mcrypt implements Zend_Filter_Encrypt_Interface
202
  /**
203
  * Defined by Zend_Filter_Interface
204
  *
205
- * Decrypts the file $value with the defined settings
206
  *
207
- * @param string $value Full path of file to change
208
- * @return string The filename which has been set, or false when there were errors
209
  */
210
  public function decrypt($value)
211
  {
@@ -215,6 +260,13 @@ class Zend_Filter_Encrypt_Mcrypt implements Zend_Filter_Encrypt_Interface
215
  mcrypt_generic_deinit($cipher);
216
  $this->_closeCipher($cipher);
217
 
 
 
 
 
 
 
 
218
  return $decrypted;
219
  }
220
 
@@ -292,10 +344,10 @@ class Zend_Filter_Encrypt_Mcrypt implements Zend_Filter_Encrypt_Interface
292
 
293
  return $this;
294
  }
295
-
296
  /**
297
  * _srand() interception
298
- *
299
  * @see ZF-8742
300
  */
301
  protected function _srand()
@@ -303,7 +355,7 @@ class Zend_Filter_Encrypt_Mcrypt implements Zend_Filter_Encrypt_Interface
303
  if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
304
  return;
305
  }
306
-
307
  if (!self::$_srandCalled) {
308
  srand((double) microtime() * 1000000);
309
  self::$_srandCalled = true;
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Mcrypt.php 21212 2010-02-27 17:33:27Z thomas $
20
  */
21
 
22
  /**
54
  'salt' => false
55
  );
56
 
57
+ /**
58
+ * Internal compression
59
+ *
60
+ * @var array
61
+ */
62
+ protected $_compression;
63
+
64
  protected static $_srandCalled = false;
65
+
66
  /**
67
  * Class constructor
68
  *
84
  throw new Zend_Filter_Exception('Invalid options argument provided to filter');
85
  }
86
 
87
+ if (array_key_exists('compression', $options)) {
88
+ $this->setCompression($options['compression']);
89
+ unset($options['compress']);
90
+ }
91
+
92
  $this->setEncryption($options);
93
  }
94
 
192
  return $this;
193
  }
194
 
195
+ /**
196
+ * Returns the compression
197
+ *
198
+ * @return array
199
+ */
200
+ public function getCompression()
201
+ {
202
+ return $this->_compression;
203
+ }
204
+
205
+ /**
206
+ * Sets a internal compression for values to encrypt
207
+ *
208
+ * @param string|array $compression
209
+ * @return Zend_Filter_Encrypt_Mcrypt
210
+ */
211
+ public function setCompression($compression)
212
+ {
213
+ if (is_string($this->_compression)) {
214
+ $compression = array('adapter' => $compression);
215
+ }
216
+
217
+ $this->_compression = $compression;
218
+ return $this;
219
+ }
220
+
221
  /**
222
  * Defined by Zend_Filter_Interface
223
  *
224
+ * Encrypts $value with the defined settings
225
  *
226
+ * @param string $value The content to encrypt
227
+ * @return string The encrypted content
228
  */
229
  public function encrypt($value)
230
  {
231
+ // compress prior to encryption
232
+ if (!empty($this->_compression)) {
233
+ #require_once 'Zend/Filter/Compress.php';
234
+ $compress = new Zend_Filter_Compress($this->_compression);
235
+ $value = $compress->filter($value);
236
+ }
237
+
238
  $cipher = $this->_openCipher();
239
  $this->_initCipher($cipher);
240
  $encrypted = mcrypt_generic($cipher, $value);
247
  /**
248
  * Defined by Zend_Filter_Interface
249
  *
250
+ * Decrypts $value with the defined settings
251
  *
252
+ * @param string $value Content to decrypt
253
+ * @return string The decrypted content
254
  */
255
  public function decrypt($value)
256
  {
260
  mcrypt_generic_deinit($cipher);
261
  $this->_closeCipher($cipher);
262
 
263
+ // decompress after decryption
264
+ if (!empty($this->_compression)) {
265
+ #require_once 'Zend/Filter/Decompress.php';
266
+ $decompress = new Zend_Filter_Decompress($this->_compression);
267
+ $decrypted = $decompress->filter($decrypted);
268
+ }
269
+
270
  return $decrypted;
271
  }
272
 
344
 
345
  return $this;
346
  }
347
+
348
  /**
349
  * _srand() interception
350
+ *
351
  * @see ZF-8742
352
  */
353
  protected function _srand()
355
  if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
356
  return;
357
  }
358
+
359
  if (!self::$_srandCalled) {
360
  srand((double) microtime() * 1000000);
361
  self::$_srandCalled = true;
lib/Zend/Filter/Encrypt/Openssl.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Openssl.php 20288 2010-01-14 20:15:43Z thomas $
20
  */
21
 
22
  /**
@@ -55,13 +55,29 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
55
  */
56
  protected $_passphrase;
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  /**
59
  * Class constructor
60
  * Available options
61
- * 'public' => public key
62
- * 'private' => private key
63
- * 'envelope' => envelope key
64
- * 'passphrase' => passphrase
 
 
65
  *
66
  * @param string|array $options Options for this adapter
67
  */
@@ -85,6 +101,16 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
85
  unset($options['passphrase']);
86
  }
87
 
 
 
 
 
 
 
 
 
 
 
88
  $this->_setKeys($options);
89
  }
90
 
@@ -150,7 +176,8 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
150
  */
151
  public function getPublicKey()
152
  {
153
- return $this->_keys['public'];
 
154
  }
155
 
156
  /**
@@ -182,7 +209,8 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
182
  */
183
  public function getPrivateKey()
184
  {
185
- return $this->_keys['private'];
 
186
  }
187
 
188
  /**
@@ -219,7 +247,8 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
219
  */
220
  public function getEnvelopeKey()
221
  {
222
- return $this->_keys['envelope'];
 
223
  }
224
 
225
  /**
@@ -267,7 +296,55 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
267
  }
268
 
269
  /**
270
- * Encrypts the file $value with the defined settings
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  * Note that you also need the "encrypted" keys to be able to decrypt
272
  *
273
  * @param string $value Content to encrypt
@@ -284,8 +361,27 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
284
  throw new Zend_Filter_Exception('Openssl can not encrypt without public keys');
285
  }
286
 
 
 
 
287
  foreach($this->_keys['public'] as $key => $cert) {
288
  $keys[$key] = openssl_pkey_get_public($cert);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  }
290
 
291
  $crypt = openssl_seal($value, $encrypted, $encryptedkeys, $keys);
@@ -295,17 +391,28 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
295
 
296
  if ($crypt === false) {
297
  #require_once 'Zend/Filter/Exception.php';
298
- throw new Zend_Filter_Exception('Openssl was not able to encrypt you content with the given options');
299
  }
300
 
301
  $this->_keys['envelope'] = $encryptedkeys;
 
 
 
 
 
 
 
 
 
 
 
302
  return $encrypted;
303
  }
304
 
305
  /**
306
  * Defined by Zend_Filter_Interface
307
  *
308
- * Decrypts the file $value with the defined settings
309
  *
310
  * @param string $value Content to decrypt
311
  * @return string The decrypted content
@@ -318,18 +425,43 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
318
 
319
  if (count($this->_keys['private']) !== 1) {
320
  #require_once 'Zend/Filter/Exception.php';
321
- throw new Zend_Filter_Exception('Openssl can only decrypt with one private key');
322
  }
323
 
324
- if (empty($envelope)) {
325
  #require_once 'Zend/Filter/Exception.php';
326
- throw new Zend_Filter_Exception('Openssl can only decrypt with one envelope key');
327
  }
328
 
329
  foreach($this->_keys['private'] as $key => $cert) {
330
  $keys = openssl_pkey_get_private($cert, $this->getPassphrase());
331
  }
332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  $crypt = openssl_open($value, $decrypted, $envelope, $keys);
334
  openssl_free_key($keys);
335
 
@@ -338,6 +470,13 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
338
  throw new Zend_Filter_Exception('Openssl was not able to decrypt you content with the given options');
339
  }
340
 
 
 
 
 
 
 
 
341
  return $decrypted;
342
  }
343
 
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Openssl.php 21212 2010-02-27 17:33:27Z thomas $
20
  */
21
 
22
  /**
55
  */
56
  protected $_passphrase;
57
 
58
+ /**
59
+ * Internal compression
60
+ *
61
+ * @var array
62
+ */
63
+ protected $_compression;
64
+
65
+ /**
66
+ * Internal create package
67
+ *
68
+ * @var boolean
69
+ */
70
+ protected $_package = false;
71
+
72
  /**
73
  * Class constructor
74
  * Available options
75
+ * 'public' => public key
76
+ * 'private' => private key
77
+ * 'envelope' => envelope key
78
+ * 'passphrase' => passphrase
79
+ * 'compression' => compress value with this compression adapter
80
+ * 'package' => pack envelope keys into encrypted string, simplifies decryption
81
  *
82
  * @param string|array $options Options for this adapter
83
  */
101
  unset($options['passphrase']);
102
  }
103
 
104
+ if (array_key_exists('compression', $options)) {
105
+ $this->setCompression($options['compression']);
106
+ unset($options['compress']);
107
+ }
108
+
109
+ if (array_key_exists('package', $options)) {
110
+ $this->setPackage($options['package']);
111
+ unset($options['package']);
112
+ }
113
+
114
  $this->_setKeys($options);
115
  }
116
 
176
  */
177
  public function getPublicKey()
178
  {
179
+ $key = $this->_keys['public'];
180
+ return $key;
181
  }
182
 
183
  /**
209
  */
210
  public function getPrivateKey()
211
  {
212
+ $key = $this->_keys['private'];
213
+ return $key;
214
  }
215
 
216
  /**
247
  */
248
  public function getEnvelopeKey()
249
  {
250
+ $key = $this->_keys['envelope'];
251
+ return $key;
252
  }
253
 
254
  /**
296
  }
297
 
298
  /**
299
+ * Returns the compression
300
+ *
301
+ * @return array
302
+ */
303
+ public function getCompression()
304
+ {
305
+ return $this->_compression;
306
+ }
307
+
308
+ /**
309
+ * Sets a internal compression for values to encrypt
310
+ *
311
+ * @param string|array $compression
312
+ * @return Zend_Filter_Encrypt_Openssl
313
+ */
314
+ public function setCompression($compression)
315
+ {
316
+ if (is_string($this->_compression)) {
317
+ $compression = array('adapter' => $compression);
318
+ }
319
+
320
+ $this->_compression = $compression;
321
+ return $this;
322
+ }
323
+
324
+ /**
325
+ * Returns if header should be packaged
326
+ *
327
+ * @return boolean
328
+ */
329
+ public function getPackage()
330
+ {
331
+ return $this->_package;
332
+ }
333
+
334
+ /**
335
+ * Sets if the envelope keys should be included in the encrypted value
336
+ *
337
+ * @param boolean $package
338
+ * @return Zend_Filter_Encrypt_Openssl
339
+ */
340
+ public function setPackage($package)
341
+ {
342
+ $this->_package = (boolean) $package;
343
+ return $this;
344
+ }
345
+
346
+ /**
347
+ * Encrypts $value with the defined settings
348
  * Note that you also need the "encrypted" keys to be able to decrypt
349
  *
350
  * @param string $value Content to encrypt
361
  throw new Zend_Filter_Exception('Openssl can not encrypt without public keys');
362
  }
363
 
364
+ $keys = array();
365
+ $fingerprints = array();
366
+ $count = -1;
367
  foreach($this->_keys['public'] as $key => $cert) {
368
  $keys[$key] = openssl_pkey_get_public($cert);
369
+ if ($this->_package) {
370
+ $details = openssl_pkey_get_details($keys[$key]);
371
+ if ($details === false) {
372
+ $details = array('key' => 'ZendFramework');
373
+ }
374
+
375
+ ++$count;
376
+ $fingerprints[$count] = md5($details['key']);
377
+ }
378
+ }
379
+
380
+ // compress prior to encryption
381
+ if (!empty($this->_compression)) {
382
+ #require_once 'Zend/Filter/Compress.php';
383
+ $compress = new Zend_Filter_Compress($this->_compression);
384
+ $value = $compress->filter($value);
385
  }
386
 
387
  $crypt = openssl_seal($value, $encrypted, $encryptedkeys, $keys);
391
 
392
  if ($crypt === false) {
393
  #require_once 'Zend/Filter/Exception.php';
394
+ throw new Zend_Filter_Exception('Openssl was not able to encrypt your content with the given options');
395
  }
396
 
397
  $this->_keys['envelope'] = $encryptedkeys;
398
+
399
+ // Pack data and envelope keys into single string
400
+ if ($this->_package) {
401
+ $header = pack('n', count($this->_keys['envelope']));
402
+ foreach($this->_keys['envelope'] as $key => $envKey) {
403
+ $header .= pack('H32n', $fingerprints[$key], strlen($envKey)) . $envKey;
404
+ }
405
+
406
+ $encrypted = $header . $encrypted;
407
+ }
408
+
409
  return $encrypted;
410
  }
411
 
412
  /**
413
  * Defined by Zend_Filter_Interface
414
  *
415
+ * Decrypts $value with the defined settings
416
  *
417
  * @param string $value Content to decrypt
418
  * @return string The decrypted content
425
 
426
  if (count($this->_keys['private']) !== 1) {
427
  #require_once 'Zend/Filter/Exception.php';
428
+ throw new Zend_Filter_Exception('Please give a private key for decryption with Openssl');
429
  }
430
 
431
+ if (!$this->_package && empty($envelope)) {
432
  #require_once 'Zend/Filter/Exception.php';
433
+ throw new Zend_Filter_Exception('Please give a envelope key for decryption with Openssl');
434
  }
435
 
436
  foreach($this->_keys['private'] as $key => $cert) {
437
  $keys = openssl_pkey_get_private($cert, $this->getPassphrase());
438
  }
439
 
440
+ if ($this->_package) {
441
+ $details = openssl_pkey_get_details($keys);
442
+ if ($details !== false) {
443
+ $fingerprint = md5($details['key']);
444
+ } else {
445
+ $fingerprint = md5("ZendFramework");
446
+ }
447
+
448
+ $count = unpack('ncount', $value);
449
+ $count = $count['count'];
450
+ $length = 2;
451
+ for($i = $count; $i > 0; --$i) {
452
+ $header = unpack('H32print/nsize', substr($value, $length, 18));
453
+ $length += 18;
454
+ if ($header['print'] == $fingerprint) {
455
+ $envelope = substr($value, $length, $header['size']);
456
+ }
457
+
458
+ $length += $header['size'];
459
+ }
460
+
461
+ // remainder of string is the value to decrypt
462
+ $value = substr($value, $length);
463
+ }
464
+
465
  $crypt = openssl_open($value, $decrypted, $envelope, $keys);
466
  openssl_free_key($keys);
467
 
470
  throw new Zend_Filter_Exception('Openssl was not able to decrypt you content with the given options');
471
  }
472
 
473
+ // decompress after decryption
474
+ if (!empty($this->_compression)) {
475
+ #require_once 'Zend/Filter/Decompress.php';
476
+ $decompress = new Zend_Filter_Decompress($this->_compression);
477
+ $decrypted = $decompress->filter($decrypted);
478
+ }
479
+
480
  return $decrypted;
481
  }
482
 
lib/Zend/Filter/HtmlEntities.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: HtmlEntities.php 21061 2010-02-15 21:56:54Z thomas $
20
  */
21
 
22
  /**
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: HtmlEntities.php 21060 2010-02-15 21:56:07Z thomas $
20
  */
21
 
22
  /**
lib/Zend/Filter/Inflector.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Inflector.php 21372 2010-03-07 19:58:08Z thomas $
20
  */
21
 
22
  /**
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Inflector.php 21371 2010-03-07 19:56:01Z thomas $
20
  */
21
 
22
  /**
lib/Zend/Filter/Input.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Input.php 22473 2010-06-20 08:30:04Z thomas $
20
  */
21
 
22
  /**
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Input.php 22472 2010-06-20 07:36:16Z thomas $
20
  */
21
 
22
  /**
lib/Zend/Filter/PregReplace.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: PregReplace.php 21086 2010-02-18 21:10:39Z thomas $
20
  */
21
 
22
  /**
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: PregReplace.php 21085 2010-02-18 21:08:39Z thomas $
20
  */
21
 
22
  /**
lib/Zend/Filter/StringToLower.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: StringToLower.php 20912 2010-02-04 19:44:42Z thomas $
20
  */
21
 
22
  /**
@@ -57,6 +57,10 @@ class Zend_Filter_StringToLower implements Zend_Filter_Interface
57
  $options = $temp;
58
  }
59
 
 
 
 
 
60
  if (array_key_exists('encoding', $options)) {
61
  $this->setEncoding($options['encoding']);
62
  }
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: StringToLower.php 22790 2010-08-03 19:16:33Z thomas $
20
  */
21
 
22
  /**
57
  $options = $temp;
58
  }
59
 
60
+ if (!array_key_exists('encoding', $options) && function_exists('mb_internal_encoding')) {
61
+ $options['encoding'] = mb_internal_encoding();
62
+ }
63
+
64
  if (array_key_exists('encoding', $options)) {
65
  $this->setEncoding($options['encoding']);
66
  }
lib/Zend/Filter/StringToUpper.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: StringToUpper.php 20912 2010-02-04 19:44:42Z thomas $
20
  */
21
 
22
  /**
@@ -57,6 +57,10 @@ class Zend_Filter_StringToUpper implements Zend_Filter_Interface
57
  $options = $temp;
58
  }
59
 
 
 
 
 
60
  if (array_key_exists('encoding', $options)) {
61
  $this->setEncoding($options['encoding']);
62
  }
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: StringToUpper.php 22790 2010-08-03 19:16:33Z thomas $
20
  */
21
 
22
  /**
57
  $options = $temp;
58
  }
59
 
60
+ if (!array_key_exists('encoding', $options) && function_exists('mb_internal_encoding')) {
61
+ $options['encoding'] = mb_internal_encoding();
62
+ }
63
+
64
  if (array_key_exists('encoding', $options)) {
65
  $this->setEncoding($options['encoding']);
66
  }
lib/Zend/Filter/StringTrim.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: StringTrim.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -45,14 +45,14 @@ class Zend_Filter_StringTrim implements Zend_Filter_Interface
45
  /**
46
  * Sets filter options
47
  *
48
- * @param string|array|Zend_Config $charList
49
  * @return void
50
  */
51
- public function __construct($charList = null)
52
  {
53
- if ($charList instanceof Zend_Config) {
54
- $charList = $charList->toArray();
55
- } else if (!is_array($charList)) {
56
  $options = func_get_args();
57
  $temp['charlist'] = array_shift($options);
58
  $options = $temp;
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: StringTrim.php 23401 2010-11-19 18:52:08Z ramon $
20
  */
21
 
22
  /**
45
  /**
46
  * Sets filter options
47
  *
48
+ * @param string|array|Zend_Config $options
49
  * @return void
50
  */
51
+ public function __construct($options = null)
52
  {
53
+ if ($options instanceof Zend_Config) {
54
+ $options = $options->toArray();
55
+ } else if (!is_array($options)) {
56
  $options = func_get_args();
57
  $temp['charlist'] = array_shift($options);
58
  $options = $temp;
lib/Zend/Filter/StripTags.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: StripTags.php 22548 2010-07-11 12:48:34Z thomas $
20
  */
21
 
22
 
@@ -244,7 +244,14 @@ class Zend_Filter_StripTags implements Zend_Filter_Interface
244
  $pos = strrpos($value, '<!--');
245
  $start = substr($value, 0, $pos);
246
  $value = substr($value, $pos);
247
- $value = preg_replace('/<(?:!(?:--[\s\S]*?--\s*)?(>))/s', '', $value);
 
 
 
 
 
 
 
248
  $value = $start . $value;
249
  }
250
 
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: StripTags.php 22806 2010-08-08 08:31:28Z thomas $
20
  */
21
 
22
 
244
  $pos = strrpos($value, '<!--');
245
  $start = substr($value, 0, $pos);
246
  $value = substr($value, $pos);
247
+
248
+ // If there is no comment closing tag, strip whole text
249
+ if (!preg_match('/--\s*>/s', $value)) {
250
+ $value = '';
251
+ } else {
252
+ $value = preg_replace('/<(?:!(?:--[\s\S]*?--\s*)?(>))/s', '', $value);
253
+ }
254
+
255
  $value = $start . $value;
256
  }
257
 
lib/Zend/Filter/Word/CamelCaseToSeparator.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: CamelCaseToSeparator.php 21089 2010-02-19 06:49:15Z thomas $
20
  */
21
 
22
  /**
16
  * @package Zend_Filter
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: CamelCaseToSeparator.php 21088 2010-02-19 06:47:48Z thomas $
20
  */
21
 
22
  /**
lib/Zend/Form.php CHANGED
@@ -28,7 +28,7 @@
28
  * @package Zend_Form
29
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30
  * @license http://framework.zend.com/license/new-bsd New BSD License
31
- * @version $Id: Form.php 22465 2010-06-19 17:41:03Z alab $
32
  */
33
  class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
34
  {
@@ -354,7 +354,7 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
354
  }
355
 
356
  $forbidden = array(
357
- 'Options', 'Config', 'PluginLoader', 'SubForms', 'View', 'Translator',
358
  'Attrib', 'Default',
359
  );
360
 
@@ -366,6 +366,9 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
366
 
367
  $method = 'set' . $normalized;
368
  if (method_exists($this, $method)) {
 
 
 
369
  $this->$method($value);
370
  } else {
371
  $this->setAttrib($key, $value);
@@ -1782,10 +1785,13 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
1782
  {
1783
  $group = array();
1784
  foreach ($elements as $element) {
 
 
 
 
1785
  if (isset($this->_elements[$element])) {
1786
  $add = $this->getElement($element);
1787
  if (null !== $add) {
1788
- unset($this->_order[$element]);
1789
  $group[] = $add;
1790
  }
1791
  }
@@ -1798,12 +1804,17 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
1798
  $name = (string) $name;
1799
 
1800
  if (is_array($options)) {
 
1801
  $options['elements'] = $group;
1802
  } elseif ($options instanceof Zend_Config) {
1803
  $options = $options->toArray();
 
1804
  $options['elements'] = $group;
1805
  } else {
1806
- $options = array('elements' => $group);
 
 
 
1807
  }
1808
 
1809
  if (isset($options['displayGroupClass'])) {
@@ -1850,6 +1861,7 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
1850
  }
1851
 
1852
  $this->_displayGroups[$name] = $group;
 
1853
 
1854
  if (!empty($this->_displayGroupPrefixPaths)) {
1855
  $this->_displayGroups[$name]->addPrefixPaths($this->_displayGroupPrefixPaths);
@@ -2222,7 +2234,8 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
2222
  }
2223
  $context = $data;
2224
  foreach ($this->getElements() as $key => $element) {
2225
- if (null !== $translator && !$element->hasTranslator()) {
 
2226
  $element->setTranslator($translator);
2227
  }
2228
  $check = $data;
@@ -3276,6 +3289,20 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
3276
  return $this;
3277
  }
3278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3279
  /**
3280
  * Sort items according to their order
3281
  *
28
  * @package Zend_Form
29
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30
  * @license http://framework.zend.com/license/new-bsd New BSD License
31
+ * @version $Id: Form.php 23429 2010-11-22 23:06:46Z bittarman $
32
  */
33
  class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
34
  {
354
  }
355
 
356
  $forbidden = array(
357
+ 'Options', 'Config', 'PluginLoader', 'SubForms', 'Translator',
358
  'Attrib', 'Default',
359
  );
360
 
366
 
367
  $method = 'set' . $normalized;
368
  if (method_exists($this, $method)) {
369
+ if($normalized == 'View' && !($value instanceof Zend_View_Interface)) {
370
+ continue;
371
+ }
372
  $this->$method($value);
373
  } else {
374
  $this->setAttrib($key, $value);
1785
  {
1786
  $group = array();
1787
  foreach ($elements as $element) {
1788
+ if($element instanceof Zend_Form_Element) {
1789
+ $element = $element->getId();
1790
+ }
1791
+
1792
  if (isset($this->_elements[$element])) {
1793
  $add = $this->getElement($element);
1794
  if (null !== $add) {
 
1795
  $group[] = $add;
1796
  }
1797
  }
1804
  $name = (string) $name;
1805
 
1806
  if (is_array($options)) {
1807
+ $options['form'] = $this;
1808
  $options['elements'] = $group;
1809
  } elseif ($options instanceof Zend_Config) {
1810
  $options = $options->toArray();
1811
+ $options['form'] = $this;
1812
  $options['elements'] = $group;
1813
  } else {
1814
+ $options = array(
1815
+ 'form' => $this,
1816
+ 'elements' => $group,
1817
+ );
1818
  }
1819
 
1820
  if (isset($options['displayGroupClass'])) {
1861
  }
1862
 
1863
  $this->_displayGroups[$name] = $group;
1864
+ $group->setForm($this);
1865
 
1866
  if (!empty($this->_displayGroupPrefixPaths)) {
1867
  $this->_displayGroups[$name]->addPrefixPaths($this->_displayGroupPrefixPaths);
2234
  }
2235
  $context = $data;
2236
  foreach ($this->getElements() as $key => $element) {
2237
+ if (null !== $translator && $this->hasTranslator()
2238
+ && !$element->hasTranslator()) {
2239
  $element->setTranslator($translator);
2240
  }
2241
  $check = $data;
3289
  return $this;
3290
  }
3291
 
3292
+ /**
3293
+ * Remove an element from iteration
3294
+ *
3295
+ * @param string $name Element/group/form name
3296
+ * @return void
3297
+ */
3298
+ public function removeFromIteration($name)
3299
+ {
3300
+ if (array_key_exists($name, $this->_order)) {
3301
+ unset($this->_order[$name]);
3302
+ $this->_orderUpdated = true;
3303
+ }
3304
+ }
3305
+
3306
  /**
3307
  * Sort items according to their order
3308
  *
lib/Zend/Form/Decorator/Abstract.php CHANGED
@@ -29,7 +29,7 @@
29
  * @subpackage Decorator
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
- * @version $Id: Abstract.php 21147 2010-02-23 14:42:04Z yoshida@zend.co.jp $
33
  */
34
  abstract class Zend_Form_Decorator_Abstract implements Zend_Form_Decorator_Interface
35
  {
29
  * @subpackage Decorator
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ * @version $Id: Abstract.php 21146 2010-02-23 14:35:57Z yoshida@zend.co.jp $
33
  */
34
  abstract class Zend_Form_Decorator_Abstract implements Zend_Form_Decorator_Interface
35
  {
lib/Zend/Form/Decorator/DtDdWrapper.php CHANGED
@@ -33,7 +33,7 @@
33
  * @subpackage Decorator
34
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
35
  * @license http://framework.zend.com/license/new-bsd New BSD License
36
- * @version $Id: DtDdWrapper.php 22129 2010-05-06 11:20:39Z alab $
37
  */
38
  class Zend_Form_Decorator_DtDdWrapper extends Zend_Form_Decorator_Abstract
39
  {
33
  * @subpackage Decorator
34
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
35
  * @license http://framework.zend.com/license/new-bsd New BSD License
36
+ * @version $Id: DtDdWrapper.php 22128 2010-05-06 11:18:02Z alab $
37
  */
38
  class Zend_Form_Decorator_DtDdWrapper extends Zend_Form_Decorator_Abstract
39
  {
lib/Zend/Form/Decorator/Fieldset.php CHANGED
@@ -32,7 +32,7 @@
32
  * @subpackage Decorator
33
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
  * @license http://framework.zend.com/license/new-bsd New BSD License
35
- * @version $Id: Fieldset.php 21967 2010-04-21 23:22:00Z alab $
36
  */
37
  class Zend_Form_Decorator_Fieldset extends Zend_Form_Decorator_Abstract
38
  {
@@ -72,7 +72,7 @@ class Zend_Form_Decorator_Fieldset extends Zend_Form_Decorator_Abstract
72
  $options = parent::getOptions();
73
  if (null !== ($element = $this->getElement())) {
74
  $attribs = $element->getAttribs();
75
- $options = array_merge($options, $attribs);
76
  $this->setOptions($options);
77
  }
78
  return $options;
32
  * @subpackage Decorator
33
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
  * @license http://framework.zend.com/license/new-bsd New BSD License
35
+ * @version $Id: Fieldset.php 23426 2010-11-22 22:50:25Z bittarman $
36
  */
37
  class Zend_Form_Decorator_Fieldset extends Zend_Form_Decorator_Abstract
38
  {
72
  $options = parent::getOptions();
73
  if (null !== ($element = $this->getElement())) {
74
  $attribs = $element->getAttribs();
75
+ $options = array_merge($attribs, $options);
76
  $this->setOptions($options);
77
  }
78
  return $options;
lib/Zend/Form/Decorator/FormErrors.php CHANGED
@@ -34,7 +34,7 @@
34
  * @subpackage Decorator
35
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
36
  * @license http://framework.zend.com/license/new-bsd New BSD License
37
- * @version $Id: FormErrors.php 22317 2010-05-29 10:13:31Z alab $
38
  */
39
  class Zend_Form_Decorator_FormErrors extends Zend_Form_Decorator_Abstract
40
  {
34
  * @subpackage Decorator
35
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
36
  * @license http://framework.zend.com/license/new-bsd New BSD License
37
+ * @version $Id: FormErrors.php 22316 2010-05-29 10:03:37Z alab $
38
  */
39
  class Zend_Form_Decorator_FormErrors extends Zend_Form_Decorator_Abstract
40
  {
lib/Zend/Form/Decorator/HtmlTag.php CHANGED
@@ -45,7 +45,7 @@
45
  * @subpackage Decorator
46
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
47
  * @license http://framework.zend.com/license/new-bsd New BSD License
48
- * @version $Id: HtmlTag.php 20104 2010-01-06 21:26:01Z matthew $
49
  */
50
  class Zend_Form_Decorator_HtmlTag extends Zend_Form_Decorator_Abstract
51
  {
@@ -84,7 +84,12 @@ class Zend_Form_Decorator_HtmlTag extends Zend_Form_Decorator_Abstract
84
  foreach ((array) $attribs as $key => $val) {
85
  $key = htmlspecialchars($key, ENT_COMPAT, $enc);
86
  if (is_array($val)) {
87
- $val = implode(' ', $val);
 
 
 
 
 
88
  }
89
  $val = htmlspecialchars($val, ENT_COMPAT, $enc);
90
  $xhtml .= " $key=\"$val\"";
45
  * @subpackage Decorator
46
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
47
  * @license http://framework.zend.com/license/new-bsd New BSD License
48
+ * @version $Id: HtmlTag.php 21970 2010-04-22 18:14:45Z alab $
49
  */
50
  class Zend_Form_Decorator_HtmlTag extends Zend_Form_Decorator_Abstract
51
  {
84
  foreach ((array) $attribs as $key => $val) {
85
  $key = htmlspecialchars($key, ENT_COMPAT, $enc);
86
  if (is_array($val)) {
87
+ if (array_key_exists('callback', $val)
88
+ && is_callable($val['callback'])) {
89
+ $val = $val['callback']($this);
90
+ } else {
91
+ $val = implode(' ', $val);
92
+ }
93
  }
94
  $val = htmlspecialchars($val, ENT_COMPAT, $enc);
95
  $xhtml .= " $key=\"$val\"";
lib/Zend/Form/Decorator/Label.php CHANGED
@@ -41,7 +41,7 @@
41
  * @subpackage Decorator
42
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
43
  * @license http://framework.zend.com/license/new-bsd New BSD License
44
- * @version $Id: Label.php 22129 2010-05-06 11:20:39Z alab $
45
  */
46
  class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
47
  {
@@ -317,7 +317,7 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
317
  #require_once 'Zend/Form/Decorator/HtmlTag.php';
318
  $decorator = new Zend_Form_Decorator_HtmlTag();
319
  $decorator->setOptions(array('tag' => $tag,
320
- 'id' => $this->getElement()->getName() . '-label'));
321
 
322
  $label = $decorator->render($label);
323
  }
41
  * @subpackage Decorator
42
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
43
  * @license http://framework.zend.com/license/new-bsd New BSD License
44
+ * @version $Id: Label.php 22128 2010-05-06 11:18:02Z alab $
45
  */
46
  class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
47
  {
317
  #require_once 'Zend/Form/Decorator/HtmlTag.php';
318
  $decorator = new Zend_Form_Decorator_HtmlTag();
319
  $decorator->setOptions(array('tag' => $tag,
320
+ 'id' => $id . '-label'));
321
 
322
  $label = $decorator->render($label);
323
  }
lib/Zend/Form/Decorator/ViewScript.php CHANGED
@@ -31,6 +31,7 @@
31
  * - separator: separator to use between view script content and provided content (defaults to PHP_EOL)
32
  * - placement: whether to append or prepend view script content to provided content (defaults to prepend)
33
  * - viewScript: view script to use
 
34
  *
35
  * The view script is rendered as a partial; the element being decorated is
36
  * passed in as the 'element' variable:
@@ -39,7 +40,7 @@
39
  * echo $this->element->getLabel();
40
  * </code>
41
  *
42
- * Any options other than separator, placement, and viewScript are passed to
43
  * the partial as local variables.
44
  *
45
  * @category Zend
@@ -47,7 +48,7 @@
47
  * @subpackage Decorator
48
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
49
  * @license http://framework.zend.com/license/new-bsd New BSD License
50
- * @version $Id: ViewScript.php 20096 2010-01-06 02:05:09Z bkarwin $
51
  */
52
  class Zend_Form_Decorator_ViewScript extends Zend_Form_Decorator_Abstract
53
  {
@@ -63,6 +64,12 @@ class Zend_Form_Decorator_ViewScript extends Zend_Form_Decorator_Abstract
63
  */
64
  protected $_viewScript;
65
 
 
 
 
 
 
 
66
  /**
67
  * Set view script
68
  *
@@ -99,6 +106,42 @@ class Zend_Form_Decorator_ViewScript extends Zend_Form_Decorator_Abstract
99
  return $this->_viewScript;
100
  }
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  /**
103
  * Render a view script
104
  *
@@ -127,7 +170,12 @@ class Zend_Form_Decorator_ViewScript extends Zend_Form_Decorator_Abstract
127
  $vars['content'] = $content;
128
  $vars['decorator'] = $this;
129
 
130
- $renderedContent = $view->partial($viewScript, $vars);
 
 
 
 
 
131
 
132
  // Get placement again to see if it has changed
133
  $placement = $this->getPlacement();
31
  * - separator: separator to use between view script content and provided content (defaults to PHP_EOL)
32
  * - placement: whether to append or prepend view script content to provided content (defaults to prepend)
33
  * - viewScript: view script to use
34
+ * - viewModule: module that view script is in (optional)
35
  *
36
  * The view script is rendered as a partial; the element being decorated is
37
  * passed in as the 'element' variable:
40
  * echo $this->element->getLabel();
41
  * </code>
42
  *
43
+ * Any options other than separator, placement, viewScript, and viewModule are passed to
44
  * the partial as local variables.
45
  *
46
  * @category Zend
48
  * @subpackage Decorator
49
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
50
  * @license http://framework.zend.com/license/new-bsd New BSD License
51
+ * @version $Id: ViewScript.php 23299 2010-11-05 04:38:14Z matthew $
52
  */
53
  class Zend_Form_Decorator_ViewScript extends Zend_Form_Decorator_Abstract
54
  {
64
  */
65
  protected $_viewScript;
66
 
67
+ /**
68
+ * View script module
69
+ * @var string
70
+ */
71
+ protected $_viewModule;
72
+
73
  /**
74
  * Set view script
75
  *
106
  return $this->_viewScript;
107
  }
108
 
109
+ /**
110
+ * Set view script module
111
+ *
112
+ * @param string $module
113
+ * @return Zend_Form_Decorator_ViewScript
114
+ */
115
+ public function setViewModule($viewModule)
116
+ {
117
+ $this->_viewModule = (string) $viewModule;
118
+ return $this;
119
+ }
120
+
121
+ /**
122
+ * Get view script module
123
+ *
124
+ * @return string|null
125
+ */
126
+ public function getViewModule()
127
+ {
128
+ if (null === $this->_viewModule) {
129
+ if (null !== ($element = $this->getElement())) {
130
+ if (null !== ($viewModule = $element->getAttrib('viewModule'))) {
131
+ $this->setViewModule($viewModule);
132
+ return $viewModule;
133
+ }
134
+ }
135
+
136
+ if (null !== ($viewModule = $this->getOption('viewModule'))) {
137
+ $this->setViewModule($viewModule)
138
+ ->removeOption('viewModule');
139
+ }
140
+ }
141
+
142
+ return $this->_viewModule;
143
+ }
144
+
145
  /**
146
  * Render a view script
147
  *
170
  $vars['content'] = $content;
171
  $vars['decorator'] = $this;
172
 
173
+ $viewModule = $this->getViewModule();
174
+ if (empty($viewModule)) {
175
+ $renderedContent = $view->partial($viewScript, $vars);
176
+ } else {
177
+ $renderedContent = $view->partial($viewScript, $viewModule, $vars);
178
+ }
179
 
180
  // Get placement again to see if it has changed
181
  $placement = $this->getPlacement();
lib/Zend/Form/DisplayGroup.php CHANGED
@@ -25,7 +25,7 @@
25
  * @package Zend_Form
26
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
  * @license http://framework.zend.com/license/new-bsd New BSD License
28
- * @version $Id: DisplayGroup.php 22465 2010-06-19 17:41:03Z alab $
29
  */
30
  class Zend_Form_DisplayGroup implements Iterator,Countable
31
  {
@@ -65,6 +65,13 @@ class Zend_Form_DisplayGroup implements Iterator,Countable
65
  */
66
  protected $_elements = array();
67
 
 
 
 
 
 
 
 
68
  /**
69
  * Whether or not a new element has been added to the group
70
  * @var bool
@@ -275,6 +282,35 @@ class Zend_Form_DisplayGroup implements Iterator,Countable
275
  return $this;
276
  }
277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  /**
279
  * Filter a name to only allow valid variable characters
280
  *
@@ -432,6 +468,12 @@ class Zend_Form_DisplayGroup implements Iterator,Countable
432
  {
433
  $this->_elements[$element->getName()] = $element;
434
  $this->_groupUpdated = true;
 
 
 
 
 
 
435
  return $this;
436
  }
437
 
25
  * @package Zend_Form
26
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
  * @license http://framework.zend.com/license/new-bsd New BSD License
28
+ * @version $Id: DisplayGroup.php 22930 2010-09-09 18:45:18Z matthew $
29
  */
30
  class Zend_Form_DisplayGroup implements Iterator,Countable
31
  {
65
  */
66
  protected $_elements = array();
67
 
68
+ /**
69
+ * Form object to which the display group is currently registered
70
+ *
71
+ * @var Zend_Form
72
+ */
73
+ protected $_form;
74
+
75
  /**
76
  * Whether or not a new element has been added to the group
77
  * @var bool
282
  return $this;
283
  }
284
 
285
+ /**
286
+ * Set form object to which the display group is attached
287
+ *
288
+ * @param Zend_Form $form
289
+ * @return Zend_Form_DisplayGroup
290
+ */
291
+ public function setForm(Zend_Form $form)
292
+ {
293
+ $this->_form = $form;
294
+
295
+ // Ensure any elements attached prior to setting the form are now
296
+ // removed from iteration by the form
297
+ foreach ($this->getElements() as $element) {
298
+ $form->removeFromIteration($element->getName());
299
+ }
300
+
301
+ return $this;
302
+ }
303
+
304
+ /**
305
+ * Get form object to which the group is attached
306
+ *
307
+ * @return Zend_Form|null
308
+ */
309
+ public function getForm()
310
+ {
311
+ return $this->_form;
312
+ }
313
+
314
  /**
315
  * Filter a name to only allow valid variable characters
316
  *
468
  {
469
  $this->_elements[$element->getName()] = $element;
470
  $this->_groupUpdated = true;
471
+
472
+ // Display group will now handle display of element
473
+ if (null !== ($form = $this->getForm())) {
474
+ $form->removeFromIteration($element->getName());
475
+ }
476
+
477
  return $this;
478
  }
479
 
lib/Zend/Form/Element.php CHANGED
@@ -38,7 +38,7 @@
38
  * @subpackage Element
39
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
40
  * @license http://framework.zend.com/license/new-bsd New BSD License
41
- * @version $Id: Element.php 22465 2010-06-19 17:41:03Z alab $
42
  */
43
  class Zend_Form_Element implements Zend_Validate_Interface
44
  {
@@ -315,12 +315,15 @@ class Zend_Form_Element implements Zend_Validate_Interface
315
 
316
  $decorators = $this->getDecorators();
317
  if (empty($decorators)) {
 
 
 
318
  $this->addDecorator('ViewHelper')
319
- ->addDecorator('Errors')
320
- ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
321
- ->addDecorator('HtmlTag', array('tag' => 'dd',
322
- 'id' => $this->getName() . '-element'))
323
- ->addDecorator('Label', array('tag' => 'dt'));
324
  }
325
  return $this;
326
  }
38
  * @subpackage Element
39
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
40
  * @license http://framework.zend.com/license/new-bsd New BSD License
41
+ * @version $Id: Element.php 22464 2010-06-19 17:31:21Z alab $
42
  */
43
  class Zend_Form_Element implements Zend_Validate_Interface
44
  {
315
 
316
  $decorators = $this->getDecorators();
317
  if (empty($decorators)) {
318
+ $getId = create_function('$decorator',
319
+ 'return $decorator->getElement()->getId()
320
+ . "-element";');
321
  $this->addDecorator('ViewHelper')
322
+ ->addDecorator('Errors')
323
+ ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
324
+ ->addDecorator('HtmlTag', array('tag' => 'dd',
325
+ 'id' => array('callback' => $getId)))
326
+ ->addDecorator('Label', array('tag' => 'dt'));
327
  }
328
  return $this;
329
  }
lib/Zend/Form/Element/Captcha.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Element
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Captcha.php 22329 2010-05-30 15:12:58Z bittarman $
21
  */
22
 
23
  /** @see Zend_Form_Element_Xhtml */
@@ -265,7 +265,7 @@ class Zend_Form_Element_Captcha extends Zend_Form_Element_Xhtml
265
  if (empty($decorators)) {
266
  $this->addDecorator('Errors')
267
  ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
268
- ->addDecorator('HtmlTag', array('tag' => 'dd'))
269
  ->addDecorator('Label', array('tag' => 'dt'));
270
  }
271
  return $this;
17
  * @subpackage Element
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Captcha.php 22328 2010-05-30 15:09:06Z bittarman $
21
  */
22
 
23
  /** @see Zend_Form_Element_Xhtml */
265
  if (empty($decorators)) {
266
  $this->addDecorator('Errors')
267
  ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
268
+ ->addDecorator('HtmlTag', array('tag' => 'dd', 'id' => $this->getName() . '-element'))
269
  ->addDecorator('Label', array('tag' => 'dt'));
270
  }
271
  return $this;
lib/Zend/Form/Element/File.php CHANGED
@@ -29,7 +29,7 @@
29
  * @subpackage Element
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
- * @version $Id: File.php 22372 2010-06-04 20:17:58Z thomas $
33
  */
34
  class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
35
  {
29
  * @subpackage Element
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ * @version $Id: File.php 22371 2010-06-04 20:09:44Z thomas $
33
  */
34
  class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
35
  {
lib/Zend/Form/Element/Image.php CHANGED
@@ -30,7 +30,7 @@
30
  * @subpackage Element
31
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
  * @license http://framework.zend.com/license/new-bsd New BSD License
33
- * @version $Id: Image.php 22329 2010-05-30 15:12:58Z bittarman $
34
  */
35
  class Zend_Form_Element_Image extends Zend_Form_Element_Xhtml
36
  {
30
  * @subpackage Element
31
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
  * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ * @version $Id: Image.php 22328 2010-05-30 15:09:06Z bittarman $
34
  */
35
  class Zend_Form_Element_Image extends Zend_Form_Element_Xhtml
36
  {
lib/Zend/Form/Element/Multi.php CHANGED
@@ -30,7 +30,7 @@
30
  * @subpackage Element
31
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
  * @license http://framework.zend.com/license/new-bsd New BSD License
33
- * @version $Id: Multi.php 22323 2010-05-30 11:15:38Z thomas $
34
  */
35
  abstract class Zend_Form_Element_Multi extends Zend_Form_Element_Xhtml
36
  {
30
  * @subpackage Element
31
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
  * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ * @version $Id: Multi.php 22322 2010-05-30 11:12:57Z thomas $
34
  */
35
  abstract class Zend_Form_Element_Multi extends Zend_Form_Element_Xhtml
36
  {
lib/Zend/Form/Element/Radio.php CHANGED
@@ -30,7 +30,7 @@
30
  * @subpackage Element
31
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
  * @license http://framework.zend.com/license/new-bsd New BSD License
33
- * @version $Id: Radio.php 22329 2010-05-30 15:12:58Z bittarman $
34
  */
35
  class Zend_Form_Element_Radio extends Zend_Form_Element_Multi
36
  {
30
  * @subpackage Element
31
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
  * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ * @version $Id: Radio.php 22328 2010-05-30 15:09:06Z bittarman $
34
  */
35
  class Zend_Form_Element_Radio extends Zend_Form_Element_Multi
36
  {
lib/Zend/Form/Element/Submit.php CHANGED
@@ -30,7 +30,7 @@
30
  * @subpackage Element
31
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
  * @license http://framework.zend.com/license/new-bsd New BSD License
33
- * @version $Id: Submit.php 22329 2010-05-30 15:12:58Z bittarman $
34
  */
35
  class Zend_Form_Element_Submit extends Zend_Form_Element_Xhtml
36
  {
30
  * @subpackage Element
31
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
  * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ * @version $Id: Submit.php 22328 2010-05-30 15:09:06Z bittarman $
34
  */
35
  class Zend_Form_Element_Submit extends Zend_Form_Element_Xhtml
36
  {
lib/Zend/Form/SubForm.php CHANGED
@@ -28,7 +28,7 @@
28
  * @package Zend_Form
29
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30
  * @license http://framework.zend.com/license/new-bsd New BSD License
31
- * @version $Id: SubForm.php 22329 2010-05-30 15:12:58Z bittarman $
32
  */
33
  class Zend_Form_SubForm extends Zend_Form
34
  {
28
  * @package Zend_Form
29
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30
  * @license http://framework.zend.com/license/new-bsd New BSD License
31
+ * @version $Id: SubForm.php 22328 2010-05-30 15:09:06Z bittarman $
32
  */
33
  class Zend_Form_SubForm extends Zend_Form
34
  {
lib/Zend/Gdata/App.php CHANGED
@@ -18,7 +18,7 @@
18
  * @subpackage App
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
- * @version $Id: App.php 22515 2010-07-03 19:11:00Z rboyd $
22
  */
23
 
24
  /**
@@ -640,12 +640,13 @@ class Zend_Gdata_App
640
 
641
  // Set the params for the new request to be performed
642
  $this->_httpClient->setHeaders($headers);
 
643
  $uri = Zend_Uri_Http::fromString($url);
644
  preg_match("/^(.*?)(\?.*)?$/", $url, $matches);
645
  $this->_httpClient->setUri($matches[1]);
646
  $queryArray = $uri->getQueryAsArray();
647
- foreach ($queryArray as $name => $value) {
648
- $this->_httpClient->setParameterGet($name, $value);
649
  }
650
 
651
 
18
  * @subpackage App
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
+ * @version $Id: App.php 22972 2010-09-18 20:33:53Z ramon $
22
  */
23
 
24
  /**
640
 
641
  // Set the params for the new request to be performed
642
  $this->_httpClient->setHeaders($headers);
643
+ #require_once 'Zend/Uri/Http.php';
644
  $uri = Zend_Uri_Http::fromString($url);
645
  preg_match("/^(.*?)(\?.*)?$/", $url, $matches);
646
  $this->_httpClient->setUri($matches[1]);
647
  $queryArray = $uri->getQueryAsArray();
648
+ foreach ($queryArray as $name => $value) {
649
+ $this->_httpClient->setParameterGet($name, $value);
650
  }
651
 
652
 
lib/Zend/Gdata/App/Base.php CHANGED
@@ -18,7 +18,7 @@
18
  * @subpackage App
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
- * @version $Id: Base.php 20096 2010-01-06 02:05:09Z bkarwin $
22
  */
23
 
24
  /**
@@ -375,8 +375,8 @@ abstract class Zend_Gdata_App_Base
375
  {
376
  // Check for a memoized result
377
  $key = $prefix . ' ' .
378
- (is_null($majorVersion) ? 'NULL' : $majorVersion) .
379
- ' '. (is_null($minorVersion) ? 'NULL' : $minorVersion);
380
  if (array_key_exists($key, self::$_namespaceLookupCache))
381
  return self::$_namespaceLookupCache[$key];
382
  // If no match, return the prefix by default
18
  * @subpackage App
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
+ * @version $Id: Base.php 22662 2010-07-24 17:37:36Z mabe $
22
  */
23
 
24
  /**
375
  {
376
  // Check for a memoized result
377
  $key = $prefix . ' ' .
378
+ ($majorVersion === null ? 'NULL' : $majorVersion) .
379
+ ' '. ($minorVersion === null ? 'NULL' : $minorVersion);
380
  if (array_key_exists($key, self::$_namespaceLookupCache))
381
  return self::$_namespaceLookupCache[$key];
382
  // If no match, return the prefix by default
lib/Zend/Gdata/App/Feed.php CHANGED
@@ -18,7 +18,7 @@
18
  * @subpackage App
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
- * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
22
  */
23
 
24
  /**
@@ -41,7 +41,7 @@
41
  * @license http://framework.zend.com/license/new-bsd New BSD License
42
  */
43
  class Zend_Gdata_App_Feed extends Zend_Gdata_App_FeedSourceParent
44
- implements Iterator, ArrayAccess
45
  {
46
 
47
  /**
18
  * @subpackage App
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
+ * @version $Id: Feed.php 22880 2010-08-21 23:44:00Z ramon $
22
  */
23
 
24
  /**
41
  * @license http://framework.zend.com/license/new-bsd New BSD License
42
  */
43
  class Zend_Gdata_App_Feed extends Zend_Gdata_App_FeedSourceParent
44
+ implements Iterator, ArrayAccess, Countable
45
  {
46
 
47
  /**
lib/Zend/Gdata/Gapps.php CHANGED
@@ -18,7 +18,7 @@
18
  * @subpackage Gapps
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
- * @version $Id: Gapps.php 22534 2010-07-07 19:11:51Z tjohns $
22
  */
23
 
24
  /**
18
  * @subpackage Gapps
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
+ * @version $Id: Gapps.php 22511 2010-07-01 01:41:46Z tjohns $
22
  */
23
 
24
  /**
lib/Zend/Http/Client.php CHANGED
@@ -16,7 +16,7 @@
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Client
19
- * @version $Id: Client.php 22539 2010-07-08 12:47:44Z shahar $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
@@ -50,10 +50,10 @@
50
  #require_once 'Zend/Http/Response/Stream.php';
51
 
52
  /**
53
- * Zend_Http_Client is an implemetation of an HTTP client in PHP. The client
54
  * supports basic features like sending different HTTP requests and handling
55
  * redirections, as well as more advanced features like proxy settings, HTTP
56
- * authentication and cookie persistance (using a Zend_Http_CookieJar object)
57
  *
58
  * @todo Implement proxy settings
59
  * @category Zend
@@ -75,7 +75,7 @@ class Zend_Http_Client
75
  const DELETE = 'DELETE';
76
  const TRACE = 'TRACE';
77
  const OPTIONS = 'OPTIONS';
78
- const CONNECT = 'CONNECT';
79
  const MERGE = 'MERGE';
80
 
81
  /**
@@ -119,10 +119,11 @@ class Zend_Http_Client
119
  'strict' => true,
120
  'output_stream' => false,
121
  'encodecookies' => true,
 
122
  );
123
 
124
  /**
125
- * The adapter used to preform the actual connection to the server
126
  *
127
  * @var Zend_Http_Client_Adapter_Interface
128
  */
@@ -157,7 +158,7 @@ class Zend_Http_Client
157
  protected $paramsGet = array();
158
 
159
  /**
160
- * Assiciative array of POST parameters
161
  *
162
  * @var array
163
  */
@@ -232,7 +233,7 @@ class Zend_Http_Client
232
  /**
233
  * Fileinfo magic database resource
234
  *
235
- * This varaiable is populated the first time _detectFileMimeType is called
236
  * and is then reused on every call to this method
237
  *
238
  * @var resource
@@ -240,7 +241,7 @@ class Zend_Http_Client
240
  static protected $_fileInfoDb = null;
241
 
242
  /**
243
- * Contructor method. Will create a new HTTP client. Accepts the target
244
  * URL and optionally configuration array.
245
  *
246
  * @param Zend_Uri_Http|string $uri
@@ -368,12 +369,12 @@ class Zend_Http_Client
368
  *
369
  * This function can be used in several ways to set the client's request
370
  * headers:
371
- * 1. By providing two parameters: $name as the header to set (eg. 'Host')
372
- * and $value as it's value (eg. 'www.example.com').
373
  * 2. By providing a single header string as the only parameter
374
- * eg. 'Host: www.example.com'
375
  * 3. By providing an array of headers as the first parameter
376
- * eg. array('host' => 'www.example.com', 'x-foo: bar'). In This case
377
  * the function will call itself recursively for each array item.
378
  *
379
  * @param string|array $name Header name, full header string ('Header: value')
@@ -384,7 +385,7 @@ class Zend_Http_Client
384
  */
385
  public function setHeaders($name, $value = null)
386
  {
387
- // If we got an array, go recusive!
388
  if (is_array($name)) {
389
  foreach ($name as $k => $v) {
390
  if (is_string($k)) {
@@ -950,6 +951,9 @@ class Zend_Http_Client
950
  $query .= '&';
951
  }
952
  $query .= http_build_query($this->paramsGet, null, '&');
 
 
 
953
 
954
  $uri->setQuery($query);
955
  }
@@ -1009,7 +1013,7 @@ class Zend_Http_Client
1009
 
1010
  // Load cookies into cookie jar
1011
  if (isset($this->cookiejar)) {
1012
- $this->cookiejar->addCookiesFromResponse($response, $uri);
1013
  }
1014
 
1015
  // If we got redirected, look for the Location header
@@ -1104,7 +1108,7 @@ class Zend_Http_Client
1104
  }
1105
 
1106
  // Set the Content-Type header
1107
- if ($this->method == self::POST &&
1108
  (! isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
1109
 
1110
  $headers[] = self::CONTENT_TYPE . ': ' . $this->enctype;
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Client
19
+ * @version $Id: Client.php 23443 2010-11-24 11:53:13Z shahar $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
50
  #require_once 'Zend/Http/Response/Stream.php';
51
 
52
  /**
53
+ * Zend_Http_Client is an implementation of an HTTP client in PHP. The client
54
  * supports basic features like sending different HTTP requests and handling
55
  * redirections, as well as more advanced features like proxy settings, HTTP
56
+ * authentication and cookie persistence (using a Zend_Http_CookieJar object)
57
  *
58
  * @todo Implement proxy settings
59
  * @category Zend
75
  const DELETE = 'DELETE';
76
  const TRACE = 'TRACE';
77
  const OPTIONS = 'OPTIONS';
78
+ const CONNECT = 'CONNECT';
79
  const MERGE = 'MERGE';
80
 
81
  /**
119
  'strict' => true,
120
  'output_stream' => false,
121
  'encodecookies' => true,
122
+ 'rfc3986_strict' => false
123
  );
124
 
125
  /**
126
+ * The adapter used to perform the actual connection to the server
127
  *
128
  * @var Zend_Http_Client_Adapter_Interface
129
  */
158
  protected $paramsGet = array();
159
 
160
  /**
161
+ * Associative array of POST parameters
162
  *
163
  * @var array
164
  */
233
  /**
234
  * Fileinfo magic database resource
235
  *
236
+ * This variable is populated the first time _detectFileMimeType is called
237
  * and is then reused on every call to this method
238
  *
239
  * @var resource
241
  static protected $_fileInfoDb = null;
242
 
243
  /**
244
+ * Constructor method. Will create a new HTTP client. Accepts the target
245
  * URL and optionally configuration array.
246
  *
247
  * @param Zend_Uri_Http|string $uri
369
  *
370
  * This function can be used in several ways to set the client's request
371
  * headers:
372
+ * 1. By providing two parameters: $name as the header to set (e.g. 'Host')
373
+ * and $value as it's value (e.g. 'www.example.com').
374
  * 2. By providing a single header string as the only parameter
375
+ * e.g. 'Host: www.example.com'
376
  * 3. By providing an array of headers as the first parameter
377
+ * e.g. array('host' => 'www.example.com', 'x-foo: bar'). In This case
378
  * the function will call itself recursively for each array item.
379
  *
380
  * @param string|array $name Header name, full header string ('Header: value')
385
  */
386
  public function setHeaders($name, $value = null)
387
  {
388
+ // If we got an array, go recursive!
389
  if (is_array($name)) {
390
  foreach ($name as $k => $v) {
391
  if (is_string($k)) {
951
  $query .= '&';
952
  }
953
  $query .= http_build_query($this->paramsGet, null, '&');
954
+ if ($this->config['rfc3986_strict']) {
955
+ $query = str_replace('+', '%20', $query);
956
+ }
957
 
958
  $uri->setQuery($query);
959
  }
1013
 
1014
  // Load cookies into cookie jar
1015
  if (isset($this->cookiejar)) {
1016
+ $this->cookiejar->addCookiesFromResponse($response, $uri, $this->config['encodecookies']);
1017
  }
1018
 
1019
  // If we got redirected, look for the Location header
1108
  }
1109
 
1110
  // Set the Content-Type header
1111
+ if (($this->method == self::POST || $this->method == self::PUT) &&
1112
  (! isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
1113
 
1114
  $headers[] = self::CONTENT_TYPE . ': ' . $this->enctype;
lib/Zend/Http/Client/Adapter/Curl.php CHANGED
@@ -16,7 +16,7 @@
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Client_Adapter
19
- * @version $Id: Curl.php 22221 2010-05-21 07:00:58Z dragonbe $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Client_Adapter
19
+ * @version $Id: Curl.php 22216 2010-05-20 21:12:05Z dragonbe $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
lib/Zend/Http/Client/Adapter/Proxy.php CHANGED
@@ -16,7 +16,7 @@
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Client_Adapter
19
- * @version $Id: Proxy.php 22445 2010-06-16 09:09:12Z bate $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Client_Adapter
19
+ * @version $Id: Proxy.php 21792 2010-04-08 00:27:06Z stas $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
lib/Zend/Http/Client/Adapter/Socket.php CHANGED
@@ -16,7 +16,7 @@
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Client_Adapter
19
- * @version $Id: Socket.php 22577 2010-07-16 15:51:51Z dragonbe $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Client_Adapter
19
+ * @version $Id: Socket.php 22576 2010-07-16 15:49:24Z dragonbe $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
lib/Zend/Http/Client/Adapter/Stream.php CHANGED
@@ -16,7 +16,7 @@
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Client_Adapter
19
- * @version $Id: Interface.php 16214 2009-06-21 19:34:03Z thomas $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Client_Adapter
19
+ * @version $Id: Stream.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
lib/Zend/Http/Cookie.php CHANGED
@@ -17,7 +17,7 @@
17
  * @package Zend_Http
18
  * @subpackage Cookie
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
- * @version $Id: Cookie.php 21020 2010-02-11 17:27:23Z shahar $
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
23
 
@@ -277,7 +277,7 @@ class Zend_Http_Cookie
277
  *
278
  * @param string $cookieStr
279
  * @param Zend_Uri_Http|string $refUri Reference URI for default values (domain, path)
280
- * @param boolean $encodeValue Weither or not the cookie's value should be
281
  * passed through urlencode/urldecode
282
  * @return Zend_Http_Cookie A new Zend_Http_Cookie object or false on failure.
283
  */
@@ -395,7 +395,7 @@ class Zend_Http_Cookie
395
 
396
  // Check for either exact match or suffix match
397
  return ($cookieDomain == $host ||
398
- preg_match("/\.$cookieDomain$/", $host));
399
  }
400
 
401
  /**
17
  * @package Zend_Http
18
  * @subpackage Cookie
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
+ * @version $Id: Cookie.php 23443 2010-11-24 11:53:13Z shahar $
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
23
 
277
  *
278
  * @param string $cookieStr
279
  * @param Zend_Uri_Http|string $refUri Reference URI for default values (domain, path)
280
+ * @param boolean $encodeValue Whether or not the cookie's value should be
281
  * passed through urlencode/urldecode
282
  * @return Zend_Http_Cookie A new Zend_Http_Cookie object or false on failure.
283
  */
395
 
396
  // Check for either exact match or suffix match
397
  return ($cookieDomain == $host ||
398
+ preg_match('/\.' . preg_quote($cookieDomain) . '$/', $host));
399
  }
400
 
401
  /**
lib/Zend/Http/CookieJar.php CHANGED
@@ -15,7 +15,7 @@
15
  * @category Zend
16
  * @package Zend_Http
17
  * @subpackage CookieJar
18
- * @version $Id: CookieJar.php 20096 2010-01-06 02:05:09Z bkarwin $
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
@@ -116,11 +116,12 @@ class Zend_Http_CookieJar implements Countable, IteratorAggregate
116
  *
117
  * @param Zend_Http_Cookie|string $cookie
118
  * @param Zend_Uri_Http|string $ref_uri Optional reference URI (for domain, path, secure)
 
119
  */
120
- public function addCookie($cookie, $ref_uri = null)
121
  {
122
  if (is_string($cookie)) {
123
- $cookie = Zend_Http_Cookie::fromString($cookie, $ref_uri);
124
  }
125
 
126
  if ($cookie instanceof Zend_Http_Cookie) {
@@ -142,8 +143,9 @@ class Zend_Http_CookieJar implements Countable, IteratorAggregate
142
  *
143
  * @param Zend_Http_Response $response
144
  * @param Zend_Uri_Http|string $ref_uri Requested URI
 
145
  */
146
- public function addCookiesFromResponse($response, $ref_uri)
147
  {
148
  if (! $response instanceof Zend_Http_Response) {
149
  #require_once 'Zend/Http/Exception.php';
@@ -155,10 +157,10 @@ class Zend_Http_CookieJar implements Countable, IteratorAggregate
155
 
156
  if (is_array($cookie_hdrs)) {
157
  foreach ($cookie_hdrs as $cookie) {
158
- $this->addCookie($cookie, $ref_uri);
159
  }
160
  } elseif (is_string($cookie_hdrs)) {
161
- $this->addCookie($cookie_hdrs, $ref_uri);
162
  }
163
  }
164
 
15
  * @category Zend
16
  * @package Zend_Http
17
  * @subpackage CookieJar
18
+ * @version $Id: CookieJar.php 23443 2010-11-24 11:53:13Z shahar $
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
116
  *
117
  * @param Zend_Http_Cookie|string $cookie
118
  * @param Zend_Uri_Http|string $ref_uri Optional reference URI (for domain, path, secure)
119
+ * @param boolean $encodeValue
120
  */
121
+ public function addCookie($cookie, $ref_uri = null, $encodeValue = true)
122
  {
123
  if (is_string($cookie)) {
124
+ $cookie = Zend_Http_Cookie::fromString($cookie, $ref_uri, $encodeValue);
125
  }
126
 
127
  if ($cookie instanceof Zend_Http_Cookie) {
143
  *
144
  * @param Zend_Http_Response $response
145
  * @param Zend_Uri_Http|string $ref_uri Requested URI
146
+ * @param boolean $encodeValue
147
  */
148
+ public function addCookiesFromResponse($response, $ref_uri, $encodeValue = true)
149
  {
150
  if (! $response instanceof Zend_Http_Response) {
151
  #require_once 'Zend/Http/Exception.php';
157
 
158
  if (is_array($cookie_hdrs)) {
159
  foreach ($cookie_hdrs as $cookie) {
160
+ $this->addCookie($cookie, $ref_uri, $encodeValue);
161
  }
162
  } elseif (is_string($cookie_hdrs)) {
163
+ $this->addCookie($cookie_hdrs, $ref_uri, $encodeValue);
164
  }
165
  }
166
 
lib/Zend/Http/Response.php CHANGED
@@ -16,7 +16,7 @@
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Response
19
- * @version $Id: Response.php 22811 2010-08-08 10:33:21Z shahar $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Response
19
+ * @version $Id: Response.php 22810 2010-08-08 10:29:09Z shahar $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
lib/Zend/Http/Response/Stream.php CHANGED
@@ -16,7 +16,7 @@
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Response
19
- * @version $Id: Response.php 17131 2009-07-26 10:03:39Z shahar $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
16
  * @category Zend
17
  * @package Zend_Http
18
  * @subpackage Response
19
+ * @version $Id: Stream.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
  * @license http://framework.zend.com/license/new-bsd New BSD License
22
  */
lib/Zend/Http/UserAgent.php ADDED
@@ -0,0 +1,847 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http_UserAgent
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * Lists of User Agent chains for testing :
24
+ *
25
+ * - http://www.useragentstring.com/layout/useragentstring.php
26
+ * - http://user-agent-string.info/list-of-ua
27
+ * - http://www.user-agents.org/allagents.xml
28
+ * - http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones
29
+ * - http://www.mobilemultimedia.be/fr/
30
+ *
31
+ * @category Zend
32
+ * @package Zend_Http_UserAgent
33
+ * @subpackage UserAgent
34
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
35
+ * @license http://framework.zend.com/license/new-bsd New BSD License
36
+ */
37
+ class Zend_Http_UserAgent implements Serializable
38
+ {
39
+ /**
40
+ * 'desktop' by default if the sequence return false for each item or is empty
41
+ */
42
+ const DEFAULT_IDENTIFICATION_SEQUENCE = 'mobile,desktop';
43
+
44
+ /**
45
+ * Default persitent storage adapter : Session or NonPersitent
46
+ */
47
+ const DEFAULT_PERSISTENT_STORAGE_ADAPTER = 'Session';
48
+
49
+ /**
50
+ * 'desktop' by default if the sequence return false for each item
51
+ */
52
+ const DEFAULT_BROWSER_TYPE = 'desktop';
53
+
54
+ /**
55
+ * Default User Agent chain to prevent empty value
56
+ */
57
+ const DEFAULT_HTTP_USER_AGENT = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)';
58
+
59
+ /**
60
+ * Default Http Accept param to prevent empty value
61
+ */
62
+ const DEFAULT_HTTP_ACCEPT = "application/xhtml+xml";
63
+
64
+ /**
65
+ * Default markup language
66
+ */
67
+ const DEFAULT_MARKUP_LANGUAGE = "xhtml";
68
+
69
+ /**
70
+ * Browser type
71
+ *
72
+ * @var string
73
+ */
74
+ protected $_browserType;
75
+
76
+ /**
77
+ * Browser type class
78
+ *
79
+ * Map of browser types to classes.
80
+ *
81
+ * @var array
82
+ */
83
+ protected $_browserTypeClass = array();
84
+
85
+ /**
86
+ * Array to store config
87
+ *
88
+ * Default values are provided to ensure specific keys are present at
89
+ * instantiation.
90
+ *
91
+ * @var array
92
+ */
93
+ protected $_config = array(
94
+ 'identification_sequence' => self::DEFAULT_IDENTIFICATION_SEQUENCE,
95
+ 'storage' => array(
96
+ 'adapter' => self::DEFAULT_PERSISTENT_STORAGE_ADAPTER,
97
+ ),
98
+ );
99
+
100
+ /**
101
+ * Identified device
102
+ *
103
+ * @var Zend_Http_UserAgent_Device
104
+ */
105
+ protected $_device;
106
+
107
+ /**
108
+ * Whether or not this instance is immutable.
109
+ *
110
+ * If true, none of the following may be modified:
111
+ * - $_server
112
+ * - $_browserType
113
+ * - User-Agent (defined in $_server)
114
+ * - HTTP Accept value (defined in $_server)
115
+ * - $_storage
116
+ *
117
+ * @var bool
118
+ */
119
+ protected $_immutable = false;
120
+
121
+ /**
122
+ * Plugin loaders
123
+ * @var array
124
+ */
125
+ protected $_loaders = array();
126
+
127
+ /**
128
+ * Valid plugin loader types
129
+ * @var array
130
+ */
131
+ protected $_loaderTypes = array('storage', 'device');
132
+
133
+ /**
134
+ * Trace of items matched to identify the browser type
135
+ *
136
+ * @var array
137
+ */
138
+ protected $_matchLog = array();
139
+
140
+ /**
141
+ * Server variable
142
+ *
143
+ * @var array
144
+ */
145
+ protected $_server;
146
+
147
+ /**
148
+ * Persistent storage handler
149
+ *
150
+ * @var Zend_Http_UserAgent_Storage
151
+ */
152
+ protected $_storage;
153
+
154
+ /**
155
+ * Constructor
156
+ *
157
+ * @param null|array|Zend_Config|ArrayAccess $options
158
+ * @return void
159
+ */
160
+ public function __construct($options = null)
161
+ {
162
+ if (null !== $options) {
163
+ $this->setOptions($options);
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Serialized representation of the object
169
+ *
170
+ * @return string
171
+ */
172
+ public function serialize()
173
+ {
174
+ $spec = array(
175
+ 'browser_type' => $this->_browserType,
176
+ 'config' => $this->_config,
177
+ 'device_class' => get_class($this->_device),
178
+ 'device' => $this->_device->serialize(),
179
+ 'user_agent' => $this->getServerValue('http_user_agent'),
180
+ 'http_accept' => $this->getServerValue('http_accept'),
181
+ );
182
+ return serialize($spec);
183
+ }
184
+
185
+ /**
186
+ * Unserialize a previous representation of the object
187
+ *
188
+ * @param string $serialized
189
+ * @return void
190
+ */
191
+ public function unserialize($serialized)
192
+ {
193
+ $spec = unserialize($serialized);
194
+
195
+ $this->setOptions($spec);
196
+
197
+ // Determine device class and ensure the class is loaded
198
+ $deviceClass = $spec['device_class'];
199
+ if (!class_exists($deviceClass)) {
200
+ $this->_getUserAgentDevice($this->getBrowserType());
201
+ }
202
+
203
+ // Get device specification and instantiate
204
+ $deviceSpec = unserialize($spec['device']);
205
+ $deviceSpec['_config'] = $this->getConfig();
206
+ $deviceSpec['_server'] = $this->getServer();
207
+ $this->_device = new $deviceClass($deviceSpec);
208
+ }
209
+
210
+ /**
211
+ * Configure instance
212
+ *
213
+ * @param array|Zend_Config|ArrayAccess $options
214
+ * @return Zend_Http_UserAgent
215
+ */
216
+ public function setOptions($options)
217
+ {
218
+ if ($options instanceof Zend_Config) {
219
+ $options = $options->toArray();
220
+ }
221
+
222
+ if (!is_array($options)
223
+ && !$options instanceof ArrayAccess
224
+ && !$options instanceof Traversable
225
+ ) {
226
+ #require_once 'Zend/Http/UserAgent/Exception.php';
227
+ throw new Zend_Http_UserAgent_Exception(sprintf(
228
+ 'Invalid argument; expected array, Zend_Config object, or object implementing ArrayAccess and Traversable; received %s',
229
+ (is_object($options) ? get_class($options) : gettype($options))
230
+ ));
231
+ }
232
+
233
+ // Set $_SERVER first
234
+ if (isset($options['server'])) {
235
+ $this->setServer($options['server']);
236
+ unset($options['server']);
237
+ }
238
+
239
+ // Get plugin loaders sorted
240
+ if (isset($options['plugin_loader'])) {
241
+ $plConfig = $options['plugin_loader'];
242
+ if (is_array($plConfig) || $plConfig instanceof Traversable) {
243
+ foreach ($plConfig as $type => $class) {
244
+ $this->setPluginLoader($type, $class);
245
+ }
246
+ }
247
+ unset($plConfig, $options['plugin_loader']);
248
+ }
249
+
250
+ // And then loop through the remaining options
251
+ $config = array();
252
+ foreach ($options as $key => $value) {
253
+ switch (strtolower($key)) {
254
+ case 'browser_type':
255
+ $this->setBrowserType($value);
256
+ break;
257
+ case 'http_accept':
258
+ $this->setHttpAccept($value);
259
+ break;
260
+ case 'user_agent':
261
+ $this->setUserAgent($value);
262
+ break;
263
+ default:
264
+ // Cache remaining options for $_config
265
+ $config[$key] = $value;
266
+ break;
267
+ }
268
+ }
269
+ $this->setConfig($config);
270
+
271
+ return $this;
272
+ }
273
+
274
+ /**
275
+ * Comparison of the UserAgent chain and browser signatures.
276
+ *
277
+ * The comparison is case-insensitive : the browser signatures must be in lower
278
+ * case
279
+ *
280
+ * @param string $deviceClass Name of class against which a match will be attempted
281
+ * @return bool
282
+ */
283
+ protected function _match($deviceClass)
284
+ {
285
+ // Validate device class
286
+ $r = new ReflectionClass($deviceClass);
287
+ if (!$r->implementsInterface('Zend_Http_UserAgent_Device')) {
288
+ throw new Zend_Http_UserAgent_Exception(sprintf(
289
+ 'Invalid device class provided ("%s"); must implement Zend_Http_UserAgent_Device',
290
+ $deviceClass
291
+ ));
292
+ }
293
+
294
+ $userAgent = $this->getUserAgent();
295
+
296
+ // Call match method on device class
297
+ return call_user_func(
298
+ array($deviceClass, 'match'),
299
+ $userAgent,
300
+ $this->getServer()
301
+ );
302
+ }
303
+
304
+ /**
305
+ * Loads class for a user agent device
306
+ *
307
+ * @param string $browserType Browser type
308
+ * @return string
309
+ * @throws Zend_Loader_PluginLoader_Exception if unable to load UA device
310
+ */
311
+ protected function _getUserAgentDevice($browserType)
312
+ {
313
+ $browserType = strtolower($browserType);
314
+ if (isset($this->_browserTypeClass[$browserType])) {
315
+ return $this->_browserTypeClass[$browserType];
316
+ }
317
+
318
+ if (isset($this->_config[$browserType])
319
+ && isset($this->_config[$browserType]['device'])
320
+ ) {
321
+ $deviceConfig = $this->_config[$browserType]['device'];
322
+ if (is_array($deviceConfig) && isset($deviceConfig['classname'])) {
323
+ $device = (string) $deviceConfig['classname'];
324
+ if (!class_exists($device)) {
325
+ #require_once 'Zend/Http/UserAgent/Exception.php';
326
+ throw new Zend_Http_UserAgent_Exception(sprintf(
327
+ 'Invalid classname "%s" provided in device configuration for browser type "%s"',
328
+ $device,
329
+ $browserType
330
+ ));
331
+ }
332
+ } elseif (is_array($deviceConfig) && isset($deviceConfig['path'])) {
333
+ $loader = $this->getPluginLoader('device');
334
+ $path = $deviceConfig['path'];
335
+ $prefix = isset($deviceConfig['prefix']) ? $deviceConfig['prefix'] : 'Zend_Http_UserAgent';
336
+ $loader->addPrefixPath($prefix, $path);
337
+
338
+ $device = $loader->load($browserType);
339
+ } else {
340
+ $loader = $this->getPluginLoader('device');
341
+ $device = $loader->load($browserType);
342
+ }
343
+ } else {
344
+ $loader = $this->getPluginLoader('device');
345
+ $device = $loader->load($browserType);
346
+ }
347
+
348
+ $this->_browserTypeClass[$browserType] = $device;
349
+
350
+ return $device;
351
+ }
352
+
353
+ /**
354
+ * Returns the User Agent value
355
+ *
356
+ * If $userAgent param is null, the value of $_server['HTTP_USER_AGENT'] is
357
+ * returned.
358
+ *
359
+ * @return string
360
+ */
361
+ public function getUserAgent()
362
+ {
363
+ if (null === ($ua = $this->getServerValue('http_user_agent'))) {
364
+ $ua = self::DEFAULT_HTTP_USER_AGENT;
365
+ $this->setUserAgent($ua);
366
+ }
367
+
368
+ return $ua;
369
+ }
370
+
371
+ /**
372
+ * Force or replace the UA chain in $_server variable
373
+ *
374
+ * @param string $userAgent Forced UserAgent chain
375
+ * @return Zend_Http_UserAgent
376
+ */
377
+ public function setUserAgent($userAgent)
378
+ {
379
+ $this->setServerValue('http_user_agent', $userAgent);
380
+ return $this;
381
+ }
382
+
383
+ /**
384
+ * Returns the HTTP Accept server param
385
+ *
386
+ * @param string $httpAccept (option) forced HTTP Accept chain
387
+ * @return string
388
+ */
389
+ public function getHttpAccept($httpAccept = null)
390
+ {
391
+ if (null === ($accept = $this->getServerValue('http_accept'))) {
392
+ $accept = self::DEFAULT_HTTP_ACCEPT;
393
+ $this->setHttpAccept($accept);
394
+ }
395
+ return $accept;
396
+ }
397
+
398
+ /**
399
+ * Force or replace the HTTP_ACCEPT chain in self::$_server variable
400
+ *
401
+ * @param string $httpAccept Forced HTTP Accept chain
402
+ * @return Zend_Http_UserAgent
403
+ */
404
+ public function setHttpAccept($httpAccept)
405
+ {
406
+ $this->setServerValue('http_accept', $httpAccept);
407
+ return $this;
408
+ }
409
+
410
+ /**
411
+ * Returns the persistent storage handler
412
+ *
413
+ * Session storage is used by default unless a different storage adapter
414
+ * has been set via the "persistent_storage_adapter" key. That key should
415
+ * contain either a fully qualified class name, or a short name that
416
+ * resolves via the plugin loader.
417
+ *
418
+ * @param string $browser Browser identifier (User Agent chain)
419
+ * @return Zend_Http_UserAgent_Storage
420
+ */
421
+ public function getStorage($browser = null)
422
+ {
423
+ if (null === $browser) {
424
+ $browser = $this->getUserAgent();
425
+ }
426
+ if (null === $this->_storage) {
427
+ $config = $this->_config['storage'];
428
+ $adapter = $config['adapter'];
429
+ if (!class_exists($adapter)) {
430
+ $loader = $this->getPluginLoader('storage');
431
+ $adapter = $loader->load($adapter);
432
+ $loader = $this->getPluginLoader('storage');
433
+ }
434
+ $options = array('browser_type' => $browser);
435
+ if (isset($config['options'])) {
436
+ $options = array_merge($options, $config['options']);
437
+ }
438
+ $this->setStorage(new $adapter($options));
439
+ }
440
+ return $this->_storage;
441
+ }
442
+
443
+ /**
444
+ * Sets the persistent storage handler
445
+ *
446
+ * @param Zend_Http_UserAgent_Storage $storage
447
+ * @return Zend_Http_UserAgent
448
+ */
449
+ public function setStorage(Zend_Http_UserAgent_Storage $storage)
450
+ {
451
+ if ($this->_immutable) {
452
+ #require_once 'Zend/Http/UserAgent/Exception.php';
453
+ throw new Zend_Http_UserAgent_Exception(
454
+ 'The User-Agent device object has already been retrieved; the storage object is now immutable'
455
+ );
456
+ }
457
+
458
+ $this->_storage = $storage;
459
+ return $this;
460
+ }
461
+
462
+ /**
463
+ * Clean the persistent storage
464
+ *
465
+ * @param string $browser Browser identifier (User Agent chain)
466
+ * @return void
467
+ */
468
+ public function clearStorage($browser = null)
469
+ {
470
+ $this->getStorage($browser)->clear();
471
+ }
472
+
473
+ /**
474
+ * Get user configuration
475
+ *
476
+ * @return array
477
+ */
478
+ public function getConfig()
479
+ {
480
+ return $this->_config;
481
+ }
482
+
483
+ /**
484
+ * Config parameters is an Array or a Zend_Config object
485
+ *
486
+ * The allowed parameters are :
487
+ * - the identification sequence (can be empty) => desktop browser type is the
488
+ * default browser type returned
489
+ * $config['identification_sequence'] : ',' separated browser types
490
+ * - the persistent storage adapter
491
+ * $config['persistent_storage_adapter'] = "Session" or "NonPersistent"
492
+ * - to add or replace a browser type device
493
+ * $config[(type)]['device']['path']
494
+ * $config[(type)]['device']['classname']
495
+ * - to add or replace a browser type features adapter
496
+ * $config[(type)]['features']['path']
497
+ * $config[(type)]['features']['classname']
498
+ *
499
+ * @param mixed $config (option) Config array
500
+ * @return Zend_Http_UserAgent
501
+ */
502
+ public function setConfig($config = array())
503
+ {
504
+ if ($config instanceof Zend_Config) {
505
+ $config = $config->toArray();
506
+ }
507
+
508
+ // Verify that Config parameters are in an array.
509
+ if (!is_array($config) && !$config instanceof Traversable) {
510
+ #require_once 'Zend/Http/UserAgent/Exception.php';
511
+ throw new Zend_Http_UserAgent_Exception(sprintf(
512
+ 'Config parameters must be in an array or a Traversable object; received "%s"',
513
+ (is_object($config) ? get_class($config) : gettype($config))
514
+ ));
515
+ }
516
+
517
+ if ($config instanceof Traversable) {
518
+ $tmp = array();
519
+ foreach ($config as $key => $value) {
520
+ $tmp[$key] = $value;
521
+ }
522
+ $config = $tmp;
523
+ unset($tmp);
524
+ }
525
+
526
+ $this->_config = array_merge($this->_config, $config);
527
+ return $this;
528
+ }
529
+
530
+ /**
531
+ * @return the $device
532
+ */
533
+ public function getDevice()
534
+ {
535
+ if (null !== $this->_device) {
536
+ return $this->_device;
537
+ }
538
+
539
+ $userAgent = $this->getUserAgent();
540
+
541
+ // search an existing identification in the session
542
+ $storage = $this->getStorage($userAgent);
543
+
544
+ if (!$storage->isEmpty()) {
545
+ // If the user agent and features are already existing, the
546
+ // Zend_Http_UserAgent object is serialized in the session
547
+ $object = $storage->read();
548
+ $this->unserialize($object);
549
+ } else {
550
+ // Otherwise, the identification is made and stored in the session.
551
+ // Find the browser type:
552
+ $this->setBrowserType($this->_matchUserAgent());
553
+ $this->_createDevice();
554
+
555
+ // put the result in storage:
556
+ $this->getStorage($userAgent)
557
+ ->write($this->serialize());
558
+ }
559
+
560
+ // Mark the object as immutable
561
+ $this->_immutable = true;
562
+
563
+ // Return the device instance
564
+ return $this->_device;
565
+ }
566
+
567
+ /**
568
+ * Retrieve the browser type
569
+ *
570
+ * @return string $browserType
571
+ */
572
+ public function getBrowserType()
573
+ {
574
+ return $this->_browserType;
575
+ }
576
+
577
+ /**
578
+ * Set the browser "type"
579
+ *
580
+ * @param string $browserType
581
+ * @return Zend_Http_UserAgent
582
+ */
583
+ public function setBrowserType($browserType)
584
+ {
585
+ if ($this->_immutable) {
586
+ #require_once 'Zend/Http/UserAgent/Exception.php';
587
+ throw new Zend_Http_UserAgent_Exception(
588
+ 'The User-Agent device object has already been retrieved; the browser type is now immutable'
589
+ );
590
+ }
591
+
592
+ $this->_browserType = $browserType;
593
+ return $this;
594
+ }
595
+
596
+ /**
597
+ * Retrieve the "$_SERVER" array
598
+ *
599
+ * Basically, the $_SERVER array or an equivalent container storing the
600
+ * data that will be introspected.
601
+ *
602
+ * If the value has not been previously set, it sets itself from the
603
+ * $_SERVER superglobal.
604
+ *
605
+ * @return array
606
+ */
607
+ public function getServer()
608
+ {
609
+ if (null === $this->_server) {
610
+ $this->setServer($_SERVER);
611
+ }
612
+ return $this->_server;
613
+ }
614
+
615
+ /**
616
+ * Retrieve the "$_SERVER" array
617
+ *
618
+ * Basically, the $_SERVER array or an equivalent container storing the
619
+ * data that will be introspected.
620
+ *
621
+ * @param array|ArrayAccess $server
622
+ * @return void
623
+ * @throws Zend_Http_UserAgent_Exception on invalid parameter
624
+ */
625
+ public function setServer($server)
626
+ {
627
+ if ($this->_immutable) {
628
+ #require_once 'Zend/Http/UserAgent/Exception.php';
629
+ throw new Zend_Http_UserAgent_Exception(
630
+ 'The User-Agent device object has already been retrieved; the server array is now immutable'
631
+ );
632
+ }
633
+
634
+ if (!is_array($server) && !$server instanceof Traversable) {
635
+ #require_once 'Zend/Http/UserAgent/Exception.php';
636
+ throw new Zend_Http_UserAgent_Exception(sprintf(
637
+ 'Expected an array or object implementing Traversable; received %s',
638
+ (is_object($server) ? get_class($server) : gettype($server))
639
+ ));
640
+ }
641
+
642
+ // Get an array if we don't have one
643
+ if ($server instanceof ArrayObject) {
644
+ $server = $server->getArrayCopy();
645
+ } elseif ($server instanceof Traversable) {
646
+ $tmp = array();
647
+ foreach ($server as $key => $value) {
648
+ $tmp[$key] = $value;
649
+ }
650
+ $server = $tmp;
651
+ unset($tmp);
652
+ }
653
+
654
+ // Normalize key case
655
+ $server = array_change_key_case($server, CASE_LOWER);
656
+
657
+ $this->_server = $server;
658
+ return $this;
659
+ }
660
+
661
+ /**
662
+ * Retrieve a server value
663
+ *
664
+ * @param string $key
665
+ * @return mixed
666
+ */
667
+ public function getServerValue($key)
668
+ {
669
+ $key = strtolower($key);
670
+ $server = $this->getServer();
671
+ $return = null;
672
+ if (isset($server[$key])) {
673
+ $return = $server[$key];
674
+ }
675
+ unset($server);
676
+ return $return;
677
+ }
678
+
679
+ /**
680
+ * Set a server value
681
+ *
682
+ * @param string|int|float $key
683
+ * @param mixed $value
684
+ * @return void
685
+ */
686
+ public function setServerValue($key, $value)
687
+ {
688
+ if ($this->_immutable) {
689
+ #require_once 'Zend/Http/UserAgent/Exception.php';
690
+ throw new Zend_Http_UserAgent_Exception(
691
+ 'The User-Agent device object has already been retrieved; the server array is now immutable'
692
+ );
693
+ }
694
+
695
+ $server = $this->getServer(); // ensure it's been initialized
696
+ $key = strtolower($key);
697
+ $this->_server[$key] = $value;
698
+ return $this;
699
+ }
700
+
701
+ /**
702
+ * Set plugin loader
703
+ *
704
+ * @param string $type Type of plugin loader; one of 'storage', (?)
705
+ * @param string|Zend_Loader_PluginLoader $loader
706
+ * @return Zend_Http_UserAgent
707
+ */
708
+ public function setPluginLoader($type, $loader)
709
+ {
710
+ $type = $this->_validateLoaderType($type);
711
+
712
+ if (is_string($loader)) {
713
+ if (!class_exists($loader)) {
714
+ #require_once 'Zend/Loader.php';
715
+ Zend_Loader::loadClass($loader);
716
+ }
717
+ $loader = new $loader();
718
+ } elseif (!is_object($loader)) {
719
+ #require_once 'Zend/Http/UserAgent/Exception.php';
720
+ throw new Zend_Http_UserAgent_Exception(sprintf(
721
+ 'Expected a plugin loader class or object; received %s',
722
+ gettype($loader)
723
+ ));
724
+ }
725
+ if (!$loader instanceof Zend_Loader_PluginLoader) {
726
+ #require_once 'Zend/Http/UserAgent/Exception.php';
727
+ throw new Zend_Http_UserAgent_Exception(sprintf(
728
+ 'Expected an object extending Zend_Loader_PluginLoader; received %s',
729
+ get_class($loader)
730
+ ));
731
+ }
732
+
733
+ $basePrefix = 'Zend_Http_UserAgent_';
734
+ $basePath = 'Zend/Http/UserAgent/';
735
+ switch ($type) {
736
+ case 'storage':
737
+ $prefix = $basePrefix . 'Storage';
738
+ $path = $basePath . 'Storage';
739
+ break;
740
+ case 'device':
741
+ $prefix = $basePrefix;
742
+ $path = $basePath;
743
+ break;
744
+ }
745
+ $loader->addPrefixPath($prefix, $path);
746
+ $this->_loaders[$type] = $loader;
747
+ return $this;
748
+ }
749
+
750
+ /**
751
+ * Get a plugin loader
752
+ *
753
+ * @param string $type A valid plugin loader type; see {@link $_loaderTypes}
754
+ * @return Zend_Loader_PluginLoader
755
+ */
756
+ public function getPluginLoader($type)
757
+ {
758
+ $type = $this->_validateLoaderType($type);
759
+ if (!isset($this->_loaders[$type])) {
760
+ #require_once 'Zend/Loader/PluginLoader.php';
761
+ $this->setPluginLoader($type, new Zend_Loader_PluginLoader());
762
+ }
763
+ return $this->_loaders[$type];
764
+ }
765
+
766
+ /**
767
+ * Validate a plugin loader type
768
+ *
769
+ * Verifies that it is in {@link $_loaderTypes}, and returns a normalized
770
+ * version of the type.
771
+ *
772
+ * @param string $type
773
+ * @return string
774
+ * @throws Zend_Http_UserAgent_Exception on invalid type
775
+ */
776
+ protected function _validateLoaderType($type)
777
+ {
778
+ $type = strtolower($type);
779
+ if (!in_array($type, $this->_loaderTypes)) {
780
+ $types = implode(', ', $this->_loaderTypes);
781
+
782
+ #require_once 'Zend/Http/UserAgent/Exception.php';
783
+ throw new Zend_Http_UserAgent_Exception(sprintf(
784
+ 'Expected one of "%s" for plugin loader type; received "%s"',
785
+ $types,
786
+ (string) $type
787
+ ));
788
+ }
789
+ return $type;
790
+ }
791
+
792
+ /**
793
+ * Run the identification sequence to match the right browser type according to the
794
+ * user agent
795
+ *
796
+ * @return Zend_Http_UserAgent_Result
797
+ */
798
+ protected function _matchUserAgent()
799
+ {
800
+ $type = self::DEFAULT_BROWSER_TYPE;
801
+
802
+ // If we have no identification sequence, just return the default type
803
+ if (empty($this->_config['identification_sequence'])) {
804
+ return $type;
805
+ }
806
+
807
+ // Get sequence against which to match
808
+ $sequence = explode(',', $this->_config['identification_sequence']);
809
+
810
+ // If a browser type is already configured, push that to the front of the list
811
+ if (null !== ($browserType = $this->getBrowserType())) {
812
+ array_unshift($sequence, $browserType);
813
+ }
814
+
815
+ // Append the default browser type to the list if not alread in the list
816
+ if (!in_array($type, $sequence)) {
817
+ $sequence[] = $type;
818
+ }
819
+
820
+ // Test each type until we find a match
821
+ foreach ($sequence as $browserType) {
822
+ $browserType = trim($browserType);
823
+ $className = $this->_getUserAgentDevice($browserType);
824
+
825
+ // Attempt to match this device class
826
+ if ($this->_match($className)) {
827
+ $type = $browserType;
828
+ $this->_browserTypeClass[$type] = $className;
829
+ break;
830
+ }
831
+ }
832
+
833
+ return $type;
834
+ }
835
+
836
+ /**
837
+ * Creates device object instance
838
+ *
839
+ * @return void
840
+ */
841
+ protected function _createDevice()
842
+ {
843
+ $browserType = $this->getBrowserType();
844
+ $classname = $this->_getUserAgentDevice($browserType);
845
+ $this->_device = new $classname($this->getUserAgent(), $this->getServer(), $this->getConfig());
846
+ }
847
+ }
lib/Zend/Http/UserAgent/AbstractDevice.php ADDED
@@ -0,0 +1,974 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Http/UserAgent/Device.php';
23
+
24
+ /**
25
+ * Abstract Class to define a browser device.
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Http
29
+ * @subpackage UserAgent
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ abstract class Zend_Http_UserAgent_AbstractDevice
34
+ implements Zend_Http_UserAgent_Device
35
+ {
36
+ /**
37
+ * Browser signature
38
+ *
39
+ * @var string
40
+ */
41
+ protected $_browser = '';
42
+
43
+ /**
44
+ * Browser version
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_browserVersion = '';
49
+
50
+ /**
51
+ * Configuration
52
+ *
53
+ * @var array
54
+ */
55
+ protected $_config;
56
+
57
+ /**
58
+ * User Agent chain
59
+ *
60
+ * @var string
61
+ */
62
+ protected $_userAgent;
63
+
64
+ /**
65
+ * Server variable
66
+ *
67
+ * @var array
68
+ */
69
+ protected $_server;
70
+
71
+ /**
72
+ * Image types
73
+ *
74
+ * @var array
75
+ */
76
+ protected $_images = array(
77
+ 'jpeg',
78
+ 'gif',
79
+ 'png',
80
+ 'pjpeg',
81
+ 'x-png',
82
+ 'bmp',
83
+ );
84
+
85
+ /**
86
+ * Browser/Device features
87
+ *
88
+ * @var array
89
+ */
90
+ protected $_aFeatures = array();
91
+
92
+ /**
93
+ * Browser/Device features groups
94
+ *
95
+ * @var array
96
+ */
97
+ protected $_aGroup = array();
98
+
99
+ /**
100
+ * Constructor
101
+ *
102
+ * @param null|string|array $userAgent If array, restores from serialized version
103
+ * @param array $server
104
+ * @param array $config
105
+ * @return void
106
+ */
107
+ public function __construct($userAgent = null, array $server = array(), array $config = array())
108
+ {
109
+ if (is_array($userAgent)) {
110
+ // Restoring from serialized array
111
+ $this->_restoreFromArray($userAgent);
112
+ } else {
113
+ // Constructing new object
114
+ $this->setUserAgent($userAgent);
115
+ $this->_server = $server;
116
+ $this->_config = $config;
117
+ $this->_getDefaultFeatures();
118
+ $this->_defineFeatures();
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Serialize object
124
+ *
125
+ * @return string
126
+ */
127
+ public function serialize()
128
+ {
129
+ $spec = array(
130
+ '_aFeatures' => $this->_aFeatures,
131
+ '_aGroup' => $this->_aGroup,
132
+ '_browser' => $this->_browser,
133
+ '_browserVersion' => $this->_browserVersion,
134
+ '_userAgent' => $this->_userAgent,
135
+ '_images' => $this->_images,
136
+ );
137
+ return serialize($spec);
138
+ }
139
+
140
+ /**
141
+ * Unserialize
142
+ *
143
+ * @param string $serialized
144
+ * @return void
145
+ */
146
+ public function unserialize($serialized)
147
+ {
148
+ $spec = unserialize($serialized);
149
+ $this->_restoreFromArray($spec);
150
+ }
151
+
152
+ /**
153
+ * Restore object state from array
154
+ *
155
+ * @param array $spec
156
+ * @return void
157
+ */
158
+ protected function _restoreFromArray(array $spec)
159
+ {
160
+ foreach ($spec as $key => $value) {
161
+ if (property_exists($this, $key)) {
162
+ $this->{$key} = $value;
163
+ }
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Look for features
169
+ *
170
+ * @return array|null
171
+ */
172
+ protected function _defineFeatures()
173
+ {
174
+ $features = $this->_loadFeaturesAdapter();
175
+
176
+ if (is_array($features)) {
177
+ $this->_aFeatures = array_merge($this->_aFeatures, $features);
178
+ }
179
+
180
+ return $this->_aFeatures;
181
+ }
182
+
183
+ /**
184
+ * Gets the browser type identifier
185
+ *
186
+ * @return string
187
+ */
188
+ abstract public function getType();
189
+
190
+ /**
191
+ * Check a feature for the current browser/device.
192
+ *
193
+ * @param string $feature The feature to check.
194
+ * @return bool
195
+ */
196
+ public function hasFeature($feature)
197
+ {
198
+ return (!empty($this->_aFeatures[$feature]));
199
+ }
200
+
201
+ /**
202
+ * Gets the value of the current browser/device feature
203
+ *
204
+ * @param string $feature Feature to search
205
+ * @return string|null
206
+ */
207
+ public function getFeature($feature)
208
+ {
209
+ if ($this->hasFeature($feature)) {
210
+ return $this->_aFeatures[$feature];
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Set a feature for the current browser/device.
216
+ *
217
+ * @param string $feature The feature to set.
218
+ * @param string $value (option) feature value.
219
+ * @param string $group (option) Group to associate with the feature
220
+ * @return Zend_Http_UserAgent_AbstractDevice
221
+ */
222
+ public function setFeature($feature, $value = false, $group = '')
223
+ {
224
+ $this->_aFeatures[$feature] = $value;
225
+ if (!empty($group)) {
226
+ $this->setGroup($group, $feature);
227
+ }
228
+ return $this;
229
+ }
230
+
231
+ /**
232
+ * Affects a feature to a group
233
+ *
234
+ * @param string $group Group name
235
+ * @param string $feature Feature name
236
+ * @return Zend_Http_UserAgent_AbstractDevice
237
+ */
238
+ public function setGroup($group, $feature)
239
+ {
240
+ if (!isset($this->_aGroup[$group])) {
241
+ $this->_aGroup[$group] = array();
242
+ }
243
+ if (!in_array($feature, $this->_aGroup[$group])) {
244
+ $this->_aGroup[$group][] = $feature;
245
+ }
246
+ return $this;
247
+ }
248
+
249
+ /**
250
+ * Gets an array of features associated to a group
251
+ *
252
+ * @param string $group Group param
253
+ * @return array
254
+ */
255
+ public function getGroup($group)
256
+ {
257
+ return $this->_aGroup[$group];
258
+ }
259
+
260
+ /**
261
+ * Gets all the browser/device features
262
+ *
263
+ * @return array
264
+ */
265
+ public function getAllFeatures()
266
+ {
267
+ return $this->_aFeatures;
268
+ }
269
+
270
+ /**
271
+ * Gets all the browser/device features' groups
272
+ *
273
+ * @return array
274
+ */
275
+ public function getAllGroups()
276
+ {
277
+ return $this->_aGroup;
278
+ }
279
+
280
+ /**
281
+ * Sets all the standard features extracted from the User Agent chain and $this->_server
282
+ * vars
283
+ *
284
+ * @return void
285
+ */
286
+ protected function _getDefaultFeatures()
287
+ {
288
+ $server = array();
289
+
290
+ // gets info from user agent chain
291
+ $uaExtract = $this->extractFromUserAgent($this->getUserAgent());
292
+
293
+ if (is_array($uaExtract)) {
294
+ foreach ($uaExtract as $key => $info) {
295
+ $this->setFeature($key, $info, 'product_info');
296
+ }
297
+ }
298
+
299
+ if (isset($uaExtract['browser_name'])) {
300
+ $this->_browser = $uaExtract['browser_name'];
301
+ }
302
+ if (isset($uaExtract['browser_version'])) {
303
+ $this->_browserVersion = $uaExtract['browser_version'];
304
+ }
305
+ if (isset($uaExtract['device_os'])) {
306
+ $this->device_os = $uaExtract['device_os_name'];
307
+ }
308
+
309
+ /* browser & device info */
310
+ $this->setFeature('is_wireless_device', false, 'product_info');
311
+ $this->setFeature('is_mobile', false, 'product_info');
312
+ $this->setFeature('is_desktop', false, 'product_info');
313
+ $this->setFeature('is_tablet', false, 'product_info');
314
+ $this->setFeature('is_bot', false, 'product_info');
315
+ $this->setFeature('is_email', false, 'product_info');
316
+ $this->setFeature('is_text', false, 'product_info');
317
+ $this->setFeature('device_claims_web_support', false, 'product_info');
318
+
319
+ $this->setFeature('is_' . strtolower($this->getType()), true, 'product_info');
320
+
321
+ /* sets the browser name */
322
+ if (isset($this->list) && empty($this->_browser)) {
323
+ $lowerUserAgent = strtolower($this->getUserAgent());
324
+ foreach ($this->list as $browser_signature) {
325
+ if (strpos($lowerUserAgent, $browser_signature) !== false) {
326
+ $this->_browser = strtolower($browser_signature);
327
+ $this->setFeature('browser_name', $this->_browser, 'product_info');
328
+ }
329
+ }
330
+ }
331
+
332
+ /* sets the client IP */
333
+ if (isset($this->_server['remote_addr'])) {
334
+ $this->setFeature('client_ip', $this->_server['remote_addr'], 'product_info');
335
+ } elseif (isset($this->_server['http_x_forwarded_for'])) {
336
+ $this->setFeature('client_ip', $this->_server['http_x_forwarded_for'], 'product_info');
337
+ } elseif (isset($this->_server['http_client_ip'])) {
338
+ $this->setFeature('client_ip', $this->_server['http_client_ip'], 'product_info');
339
+ }
340
+
341
+ /* sets the server infos */
342
+ if (isset($this->_server['server_software'])) {
343
+ if (strpos($this->_server['server_software'], 'Apache') !== false || strpos($this->_server['server_software'], 'LiteSpeed') !== false) {
344
+ $server['version'] = 1;
345
+ if (strpos($this->_server['server_software'], 'Apache/2') !== false) {
346
+ $server['version'] = 2;
347
+ }
348
+ $server['server'] = 'apache';
349
+ }
350
+
351
+ if (strpos($this->_server['server_software'], 'Microsoft-IIS') !== false) {
352
+ $server['server'] = 'iis';
353
+ }
354
+
355
+ if (strpos($this->_server['server_software'], 'Unix') !== false) {
356
+ $server['os'] = 'unix';
357
+ if (isset($_ENV['MACHTYPE'])) {
358
+ if (strpos($_ENV['MACHTYPE'], 'linux') !== false) {
359
+ $server['os'] = 'linux';
360
+ }
361
+ }
362
+ } elseif (strpos($this->_server['server_software'], 'Win') !== false) {
363
+ $server['os'] = 'windows';
364
+ }
365
+
366
+ if (preg_match('/Apache\/([0-9\.]*)/', $this->_server['server_software'], $arr)) {
367
+ if ($arr[1]) {
368
+ $server['version'] = $arr[1];
369
+ $server['server'] = 'apache';
370
+ }
371
+ }
372
+ }
373
+
374
+ $this->setFeature('php_version', phpversion(), 'server_info');
375
+ if (isset($server['server'])) {
376
+ $this->setFeature('server_os', $server['server'], 'server_info');
377
+ }
378
+ if (isset($server['version'])) {
379
+ $this->setFeature('server_os_version', $server['version'], 'server_info');
380
+ }
381
+ if (isset($this->_server['http_accept'])) {
382
+ $this->setFeature('server_http_accept', $this->_server['http_accept'], 'server_info');
383
+ }
384
+ if (isset($this->_server['http_accept_language'])) {
385
+ $this->setFeature('server_http_accept_language', $this->_server['http_accept_language'], 'server_info');
386
+ }
387
+ if (isset($this->_server['server_addr'])) {
388
+ $this->setFeature('server_ip', $this->_server['server_addr'], 'server_info');
389
+ }
390
+ if (isset($this->_server['server_name'])) {
391
+ $this->setFeature('server_name', $this->_server['server_name'], 'server_info');
392
+ }
393
+ }
394
+
395
+ /**
396
+ * Extract and sets informations from the User Agent chain
397
+ *
398
+ * @param string $userAgent User Agent chain
399
+ * @return array
400
+ */
401
+ public static function extractFromUserAgent($userAgent)
402
+ {
403
+ $userAgent = trim($userAgent);
404
+
405
+ /**
406
+ * @see http://www.texsoft.it/index.php?c=software&m=sw.php.useragent&l=it
407
+ */
408
+ $pattern = "(([^/\s]*)(/(\S*))?)(\s*\[[a-zA-Z][a-zA-Z]\])?\s*(\\((([^()]|(\\([^()]*\\)))*)\\))?\s*";
409
+ preg_match("#^$pattern#", $userAgent, $match);
410
+
411
+ $comment = array();
412
+ if (isset($match[7])) {
413
+ $comment = explode(';', $match[7]);
414
+ }
415
+
416
+ // second part if exists
417
+ $end = substr($userAgent, strlen($match[0]));
418
+ if (!empty($end)) {
419
+ $result['others']['full'] = $end;
420
+ }
421
+
422
+ $match2 = array();
423
+ if (isset($result['others'])) {
424
+ preg_match_all('/(([^\/\s]*)(\/)?([^\/\(\)\s]*)?)(\s\((([^\)]*)*)\))?/i', $result['others']['full'], $match2);
425
+ }
426
+ $result['user_agent'] = trim($match[1]);
427
+ $result['product_name'] = isset($match[2]) ? trim($match[2]) : '';
428
+ $result['browser_name'] = $result['product_name'];
429
+ if (isset($match[4]) && trim($match[4])) {
430
+ $result['product_version'] = trim($match[4]);
431
+ $result['browser_version'] = trim($match[4]);
432
+ }
433
+ if (count($comment) && !empty($comment[0])) {
434
+ $result['comment']['full'] = trim($match[7]);
435
+ $result['comment']['detail'] = $comment;
436
+ $result['compatibility_flag'] = trim($comment[0]);
437
+ if (isset($comment[1])) {
438
+ $result['browser_token'] = trim($comment[1]);
439
+ }
440
+ if (isset($comment[2])) {
441
+ $result['device_os_token'] = trim($comment[2]);
442
+ }
443
+ }
444
+ if (empty($result['device_os_token']) && !empty($result['compatibility_flag'])) {
445
+ // some browsers do not have a platform token
446
+ $result['device_os_token'] = $result['compatibility_flag'];
447
+ }
448
+ if ($match2) {
449
+ $i = 0;
450
+ $max = count($match2[0]);
451
+ for ($i = 0; $i < $max; $i ++) {
452
+ if (!empty($match2[0][$i])) {
453
+ $result['others']['detail'][] = array(
454
+ $match2[0][$i],
455
+ $match2[2][$i],
456
+ $match2[4][$i],
457
+ );
458
+ }
459
+ }
460
+ }
461
+
462
+ /** Security level */
463
+ $security = array(
464
+ 'N' => 'no security',
465
+ 'U' => 'strong security',
466
+ 'I' => 'weak security',
467
+ );
468
+ if (!empty($result['browser_token'])) {
469
+ if (isset($security[$result['browser_token']])) {
470
+ $result['security_level'] = $security[$result['browser_token']];
471
+ unset($result['browser_token']);
472
+ }
473
+ }
474
+
475
+ $product = strtolower($result['browser_name']);
476
+
477
+ // Mozilla : true && false
478
+ $compatibleOrIe = false;
479
+ if (isset($result['compatibility_flag']) && isset($result['comment'])) {
480
+ $compatibleOrIe = ($result['compatibility_flag'] == 'compatible' || strpos($result['comment']['full'], "MSIE") !== false);
481
+ }
482
+ if ($product == 'mozilla' && $compatibleOrIe) {
483
+ if (!empty($result['browser_token'])) {
484
+ // Classic Mozilla chain
485
+ preg_match_all('/([^\/\s].*)(\/|\s)(.*)/i', $result['browser_token'], $real);
486
+ } else {
487
+ // MSIE specific chain with 'Windows' compatibility flag
488
+ foreach ($result['comment']['detail'] as $v) {
489
+ if (strpos($v, 'MSIE') !== false) {
490
+ $real[0][1] = trim($v);
491
+ $result['browser_engine'] = "MSIE";
492
+ $real[1][0] = "Internet Explorer";
493
+ $temp = explode(' ', trim($v));
494
+ $real[3][0] = $temp[1];
495
+
496
+ }
497
+ if (strpos($v, 'Win') !== false) {
498
+ $result['device_os_token'] = trim($v);
499
+ }
500
+ }
501
+ }
502
+
503
+ if (!empty($real[0])) {
504
+ $result['browser_name'] = $real[1][0];
505
+ $result['browser_version'] = $real[3][0];
506
+ } else {
507
+ $result['browser_name'] = $result['browser_token'];
508
+ $result['browser_version'] = '??';
509
+ }
510
+ } elseif ($product == 'mozilla' && $result['browser_version'] < 5.0) {
511
+ // handles the real Mozilla (or old Netscape if version < 5.0)
512
+ $result['browser_name'] = 'Netscape';
513
+ }
514
+
515
+ /** windows */
516
+ if ($result['browser_name'] == 'MSIE') {
517
+ $result['browser_engine'] = 'MSIE';
518
+ $result['browser_name'] = 'Internet Explorer';
519
+ }
520
+ if (isset($result['device_os_token'])) {
521
+ if (strpos($result['device_os_token'], 'Win') !== false) {
522
+
523
+ $windows = array(
524
+ 'Windows NT 6.1' => 'Windows 7',
525
+ 'Windows NT 6.0' => 'Windows Vista',
526
+ 'Windows NT 5.2' => 'Windows Server 2003',
527
+ 'Windows NT 5.1' => 'Windows XP',
528
+ 'Windows NT 5.01' => 'Windows 2000 SP1',
529
+ 'Windows NT 5.0' => 'Windows 2000',
530
+ 'Windows NT 4.0' => 'Microsoft Windows NT 4.0',
531
+ 'WinNT' => 'Microsoft Windows NT 4.0',
532
+ 'Windows 98; Win 9x 4.90' => 'Windows Me',
533
+ 'Windows 98' => 'Windows 98',
534
+ 'Win98' => 'Windows 98',
535
+ 'Windows 95' => 'Windows 95',
536
+ 'Win95' => 'Windows 95',
537
+ 'Windows CE' => 'Windows CE',
538
+ );
539
+ if (isset($windows[$result['device_os_token']])) {
540
+ $result['device_os_name'] = $windows[$result['device_os_token']];
541
+ } else {
542
+ $result['device_os_name'] = $result['device_os_token'];
543
+ }
544
+ }
545
+ }
546
+
547
+ // iphone
548
+ $apple_device = array(
549
+ 'iPhone',
550
+ 'iPod',
551
+ 'iPad',
552
+ );
553
+ if (isset($result['compatibility_flag'])) {
554
+ if (in_array($result['compatibility_flag'], $apple_device)) {
555
+ $result['device'] = strtolower($result['compatibility_flag']);
556
+ $result['device_os_token'] = 'iPhone OS';
557
+ $result['browser_language'] = trim($comment[3]);
558
+ $result['browser_version'] = $result['others']['detail'][1][2];
559
+ if (!empty($result['others']['detail'][2])) {
560
+ $result['firmware'] = $result['others']['detail'][2][2];
561
+ }
562
+ if (!empty($result['others']['detail'][3])) {
563
+ $result['browser_name'] = $result['others']['detail'][3][1];
564
+ $result['browser_build'] = $result['others']['detail'][3][2];
565
+ }
566
+ }
567
+ }
568
+
569
+ // Safari
570
+ if (isset($result['others'])) {
571
+ if ($result['others']['detail'][0][1] == 'AppleWebKit') {
572
+ $result['browser_engine'] = 'AppleWebKit';
573
+ if ($result['others']['detail'][1][1] == 'Version') {
574
+ $result['browser_version'] = $result['others']['detail'][1][2];
575
+ } else {
576
+ $result['browser_version'] = $result['others']['detail'][count($result['others']['detail']) - 1][2];
577
+ }
578
+ if (isset($comment[3])) {
579
+ $result['browser_language'] = trim($comment[3]);
580
+ }
581
+
582
+ $last = $result['others']['detail'][count($result['others']['detail']) - 1][1];
583
+
584
+ if (empty($result['others']['detail'][2][1]) || $result['others']['detail'][2][1] == 'Safari') {
585
+ $result['browser_name'] = ($result['others']['detail'][1][1] && $result['others']['detail'][1][1] != 'Version' ? $result['others']['detail'][1][1] : 'Safari');
586
+ $result['browser_version'] = ($result['others']['detail'][1][2] ? $result['others']['detail'][1][2] : $result['others']['detail'][0][2]);
587
+ } else {
588
+ $result['browser_name'] = $result['others']['detail'][2][1];
589
+ $result['browser_version'] = $result['others']['detail'][2][2];
590
+
591
+ // mobile version
592
+ if ($result['browser_name'] == 'Mobile') {
593
+ $result['browser_name'] = 'Safari ' . $result['browser_name'];
594
+ if ($result['others']['detail'][1][1] == 'Version') {
595
+ $result['browser_version'] = $result['others']['detail'][1][2];
596
+ }
597
+ }
598
+ }
599
+
600
+ // For Safari < 2.2, AppleWebKit version gives the Safari version
601
+ if (strpos($result['browser_version'], '.') > 2 || (int) $result['browser_version'] > 20) {
602
+ $temp = explode('.', $result['browser_version']);
603
+ $build = (int) $temp[0];
604
+ $awkVersion = array(
605
+ 48 => '0.8',
606
+ 73 => '0.9',
607
+ 85 => '1.0',
608
+ 103 => '1.1',
609
+ 124 => '1.2',
610
+ 300 => '1.3',
611
+ 400 => '2.0',
612
+ );
613
+ foreach ($awkVersion as $k => $v) {
614
+ if ($build >= $k) {
615
+ $result['browser_version'] = $v;
616
+ }
617
+ }
618
+ }
619
+ }
620
+
621
+ // Gecko (Firefox or compatible)
622
+ if ($result['others']['detail'][0][1] == 'Gecko') {
623
+ $searchRV = true;
624
+ if (!empty($result['others']['detail'][1][1]) && !empty($result['others']['detail'][count($result['others']['detail']) - 1][2]) || strpos(strtolower($result['others']['full']), 'opera') !== false) {
625
+ $searchRV = false;
626
+ $result['browser_engine'] = $result['others']['detail'][0][1];
627
+
628
+ // the name of the application is at the end indepenently
629
+ // of quantity of information in $result['others']['detail']
630
+ $last = count($result['others']['detail']) - 1;
631
+
632
+ // exception : if the version of the last information is
633
+ // empty we take the previous one
634
+ if (empty($result['others']['detail'][$last][2])) {
635
+ $last --;
636
+ }
637
+
638
+ // exception : if the last one is 'Red Hat' or 'Debian' =>
639
+ // use rv: to find browser_version */
640
+ if (in_array($result['others']['detail'][$last][1], array(
641
+ 'Debian',
642
+ 'Hat',
643
+ ))) {
644
+ $searchRV = true;
645
+ }
646
+ $result['browser_name'] = $result['others']['detail'][$last][1];
647
+ $result['browser_version'] = $result['others']['detail'][$last][2];
648
+ if (isset($comment[4])) {
649
+ $result['browser_build'] = trim($comment[4]);
650
+ }
651
+ $result['browser_language'] = trim($comment[3]);
652
+
653
+ // Netscape
654
+ if ($result['browser_name'] == 'Navigator' || $result['browser_name'] == 'Netscape6') {
655
+ $result['browser_name'] = 'Netscape';
656
+ }
657
+ }
658
+ if ($searchRV) {
659
+ // Mozilla alone : the version is identified by rv:
660
+ $result['browser_name'] = 'Mozilla';
661
+ if (isset($result['comment']['detail'])) {
662
+ foreach ($result['comment']['detail'] as $rv) {
663
+ if (strpos($rv, 'rv:') !== false) {
664
+ $result['browser_version'] = trim(str_replace('rv:', '', $rv));
665
+ }
666
+ }
667
+ }
668
+ }
669
+ }
670
+
671
+ // Netscape
672
+ if ($result['others']['detail'][0][1] == 'Netscape') {
673
+ $result['browser_name'] = 'Netscape';
674
+ $result['browser_version'] = $result['others']['detail'][0][2];
675
+ }
676
+
677
+ // Opera
678
+ // Opera: engine Presto
679
+ if ($result['others']['detail'][0][1] == 'Presto') {
680
+ $result['browser_engine'] = 'Presto';
681
+ if (!empty($result['others']['detail'][1][2])) {
682
+ $result['browser_version'] = $result['others']['detail'][1][2];
683
+ }
684
+ }
685
+
686
+ // UA ends with 'Opera X.XX'
687
+ if ($result['others']['detail'][0][1] == 'Opera') {
688
+ $result['browser_name'] = $result['others']['detail'][0][1];
689
+ $result['browser_version'] = $result['others']['detail'][1][1];
690
+ }
691
+
692
+ // Opera Mini
693
+ if (isset($result["browser_token"])) {
694
+ if (strpos($result["browser_token"], 'Opera Mini') !== false) {
695
+ $result['browser_name'] = 'Opera Mini';
696
+ }
697
+ }
698
+
699
+ // Symbian
700
+ if ($result['others']['detail'][0][1] == 'SymbianOS') {
701
+ $result['device_os_token'] = 'SymbianOS';
702
+ }
703
+ }
704
+
705
+ // UA ends with 'Opera X.XX'
706
+ if (isset($result['browser_name']) && isset($result['browser_engine'])) {
707
+ if ($result['browser_name'] == 'Opera' && $result['browser_engine'] == 'Gecko' && empty($result['browser_version'])) {
708
+ $result['browser_version'] = $result['others']['detail'][count($result['others']['detail']) - 1][1];
709
+ }
710
+ }
711
+
712
+ // cleanup
713
+ if (isset($result['browser_version']) && isset($result['browser_build'])) {
714
+ if ($result['browser_version'] == $result['browser_build']) {
715
+ unset($result['browser_build']);
716
+ }
717
+ }
718
+
719
+ // compatibility
720
+ $compatibility['AppleWebKit'] = 'Safari';
721
+ $compatibility['Gecko'] = 'Firefox';
722
+ $compatibility['MSIE'] = 'Internet Explorer';
723
+ $compatibility['Presto'] = 'Opera';
724
+ if (!empty($result['browser_engine'])) {
725
+ if (isset($compatibility[$result['browser_engine']])) {
726
+ $result['browser_compatibility'] = $compatibility[$result['browser_engine']];
727
+ }
728
+ }
729
+
730
+ ksort($result);
731
+ return $result;
732
+ }
733
+
734
+ /**
735
+ * Loads the Features Adapter if it's defined in the $config array
736
+ * Otherwise, nothing is done
737
+ *
738
+ * @param string $browserType Browser type
739
+ * @return array
740
+ */
741
+ protected function _loadFeaturesAdapter()
742
+ {
743
+ $config = $this->_config;
744
+ $browserType = $this->getType();
745
+ if (!isset($config[$browserType]) || !isset($config[$browserType]['features'])) {
746
+ return array();
747
+ }
748
+ $config = $config[$browserType]['features'];
749
+
750
+ if (empty($config['classname'])) {
751
+ #require_once 'Zend/Http/UserAgent/Exception.php';
752
+ throw new Zend_Http_UserAgent_Exception('The ' . $this->getType() . ' features adapter must have a "classname" config parameter defined');
753
+ }
754
+
755
+ $className = $config['classname'];
756
+ if (!class_exists($className)) {
757
+ if (isset($config['path'])) {
758
+ $path = $config['path'];
759
+ } else {
760
+ #require_once 'Zend/Http/UserAgent/Exception.php';
761
+ throw new Zend_Http_UserAgent_Exception('The ' . $this->getType() . ' features adapter must have a "path" config parameter defined');
762
+ }
763
+
764
+ if (false === include_once ($path)) {
765
+ #require_once 'Zend/Http/UserAgent/Exception.php';
766
+ throw new Zend_Http_UserAgent_Exception('The ' . $this->getType() . ' features adapter path that does not exist');
767
+ }
768
+ }
769
+
770
+ return call_user_func(array($className, 'getFromRequest'), $this->_server, $this->_config);
771
+ }
772
+
773
+ /**
774
+ * Retrieve image format support
775
+ *
776
+ * @return array
777
+ */
778
+ public function getImageFormatSupport()
779
+ {
780
+ return $this->_images;
781
+ }
782
+
783
+ /**
784
+ * Get maximum image height supported by this device
785
+ *
786
+ * @return int
787
+ */
788
+ public function getMaxImageHeight()
789
+ {
790
+ return null;
791
+ }
792
+
793
+ /**
794
+ * Get maximum image width supported by this device
795
+ *
796
+ * @return int
797
+ */
798
+ public function getMaxImageWidth()
799
+ {
800
+ return null;
801
+ }
802
+
803
+ /**
804
+ * Get physical screen height of this device
805
+ *
806
+ * @return int
807
+ */
808
+ public function getPhysicalScreenHeight()
809
+ {
810
+ return null;
811
+ }
812
+
813
+ /**
814
+ * Get physical screen width of this device
815
+ *
816
+ * @return int
817
+ */
818
+ public function getPhysicalScreenWidth()
819
+ {
820
+ return null;
821
+ }
822
+
823
+ /**
824
+ * Get preferred markup type
825
+ *
826
+ * @return string
827
+ */
828
+ public function getPreferredMarkup()
829
+ {
830
+ return 'xhtml';
831
+ }
832
+
833
+ /**
834
+ * Get supported X/HTML version
835
+ *
836
+ * @return int
837
+ */
838
+ public function getXhtmlSupportLevel()
839
+ {
840
+ return 4;
841
+ }
842
+
843
+ /**
844
+ * Does the device support Flash?
845
+ *
846
+ * @return bool
847
+ */
848
+ public function hasFlashSupport()
849
+ {
850
+ return true;
851
+ }
852
+
853
+ /**
854
+ * Does the device support PDF?
855
+ *
856
+ * @return bool
857
+ */
858
+ public function hasPdfSupport()
859
+ {
860
+ return true;
861
+ }
862
+
863
+ /**
864
+ * Does the device have a phone number associated with it?
865
+ *
866
+ * @return bool
867
+ */
868
+ public function hasPhoneNumber()
869
+ {
870
+ return false;
871
+ }
872
+
873
+ /**
874
+ * Does the device support HTTPS?
875
+ *
876
+ * @return bool
877
+ */
878
+ public function httpsSupport()
879
+ {
880
+ return true;
881
+ }
882
+
883
+ /**
884
+ * Get the browser type
885
+ *
886
+ * @return string
887
+ */
888
+ public function getBrowser()
889
+ {
890
+ return $this->_browser;
891
+ }
892
+
893
+ /**
894
+ * Get the browser version
895
+ *
896
+ * @return string
897
+ */
898
+ public function getBrowserVersion()
899
+ {
900
+ return $this->_browserVersion;
901
+ }
902
+
903
+ /**
904
+ * Get the user agent string
905
+ *
906
+ * @return string
907
+ */
908
+ public function getUserAgent()
909
+ {
910
+ return $this->_userAgent;
911
+ }
912
+
913
+ /**
914
+ * @return the $_images
915
+ */
916
+ public function getImages()
917
+ {
918
+ return $this->_images;
919
+ }
920
+
921
+ /**
922
+ * @param string $browser
923
+ */
924
+ public function setBrowser($browser)
925
+ {
926
+ $this->_browser = $browser;
927
+ }
928
+
929
+ /**
930
+ * @param string $browserVersion
931
+ */
932
+ public function setBrowserVersion($browserVersion)
933
+ {
934
+ $this->_browserVersion = $browserVersion;
935
+ }
936
+
937
+ /**
938
+ * @param string $userAgent
939
+ */
940
+ public function setUserAgent($userAgent)
941
+ {
942
+ $this->_userAgent = $userAgent;
943
+ return $this;
944
+ }
945
+
946
+ /**
947
+ * @param array $_images
948
+ */
949
+ public function setImages($_images)
950
+ {
951
+ $this->_images = $_images;
952
+ }
953
+
954
+ /**
955
+ * Match a user agent string against a list of signatures
956
+ *
957
+ * @param string $userAgent
958
+ * @param array $signatures
959
+ * @return bool
960
+ */
961
+ protected static function _matchAgentAgainstSignatures($userAgent, $signatures)
962
+ {
963
+ $userAgent = strtolower($userAgent);
964
+ foreach ($signatures as $signature) {
965
+ if (!empty($signature)) {
966
+ if (strpos($userAgent, $signature) !== false) {
967
+ // Browser signature was found in user agent string
968
+ return true;
969
+ }
970
+ }
971
+ }
972
+ return false;
973
+ }
974
+ }
lib/Zend/Http/UserAgent/Bot.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+ #require_once 'Zend/Http/UserAgent/AbstractDevice.php';
22
+
23
+ /**
24
+ * Bot browser type matcher
25
+ *
26
+ * @category Zend
27
+ * @package Zend_Http
28
+ * @subpackage UserAgent
29
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30
+ * @license http://framework.zend.com/license/new-bsd New BSD License
31
+ */
32
+
33
+ class Zend_Http_UserAgent_Bot extends Zend_Http_UserAgent_AbstractDevice
34
+ {
35
+
36
+ /**
37
+ * User Agent Signatures
38
+ *
39
+ * @var array
40
+ */
41
+ protected static $_uaSignatures = array(
42
+ // The most common ones.
43
+ 'googlebot',
44
+ 'msnbot',
45
+ 'slurp',
46
+ 'yahoo',
47
+
48
+ // The rest, alphabetically.
49
+ 'alexa',
50
+ 'appie',
51
+ 'archiver',
52
+ 'ask jeeves',
53
+ 'baiduspider',
54
+ 'bot',
55
+ 'crawl',
56
+ 'crawler',
57
+ 'curl',
58
+ 'eventbox',
59
+ 'facebookexternal',
60
+ 'fast',
61
+ 'feedfetcher-google',
62
+ 'firefly',
63
+ 'froogle',
64
+ 'gigabot',
65
+ 'girafabot',
66
+ 'google',
67
+ 'infoseek',
68
+ 'inktomi',
69
+ 'java',
70
+ 'larbin',
71
+ 'looksmart',
72
+ 'mechanize',
73
+ 'mediapartners-google',
74
+ 'monitor',
75
+ 'nambu',
76
+ 'nationaldirectory',
77
+ 'novarra',
78
+ 'pear',
79
+ 'perl',
80
+ 'python',
81
+ 'rabaz',
82
+ 'radian',
83
+ 'rankivabot',
84
+ 'scooter',
85
+ 'sogou web spider',
86
+ 'spade',
87
+ 'sphere',
88
+ 'spider',
89
+ 'technoratisnoop',
90
+ 'tecnoseek',
91
+ 'teoma',
92
+ 'toolbar',
93
+ 'transcoder',
94
+ 'twitt',
95
+ 'url_spider_sql',
96
+ 'webalta crawler',
97
+ 'webbug',
98
+ 'webfindbot',
99
+ 'wordpress',
100
+ 'www.galaxy.com',
101
+ 'yahoo! searchmonkey',
102
+ 'yahoo! slurp',
103
+ 'yandex',
104
+ 'zyborg',
105
+ );
106
+
107
+ /**
108
+ * Comparison of the UserAgent chain and browser signatures
109
+ *
110
+ * @param string $userAgent User Agent chain
111
+ * @param array $server $_SERVER like param
112
+ * @return bool
113
+ */
114
+ public static function match($userAgent, $server)
115
+ {
116
+ return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures);
117
+ }
118
+
119
+ /**
120
+ * Gives the current browser type
121
+ *
122
+ * @return string
123
+ */
124
+ public function getType()
125
+ {
126
+ return 'bot';
127
+ }
128
+ }
lib/Zend/Http/UserAgent/Checker.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+ #require_once 'Zend/Http/UserAgent/Desktop.php';
22
+
23
+ /**
24
+ * Checker browser type matcher
25
+ *
26
+ * @category Zend
27
+ * @package Zend_Http
28
+ * @subpackage UserAgent
29
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30
+ * @license http://framework.zend.com/license/new-bsd New BSD License
31
+ */
32
+
33
+ class Zend_Http_UserAgent_Checker extends Zend_Http_UserAgent_Desktop
34
+ {
35
+
36
+ /**
37
+ * User Agent Signatures
38
+ *
39
+ * @var array
40
+ */
41
+ protected static $_uaSignatures = array(
42
+ 'abilogic',
43
+ 'checklink',
44
+ 'checker',
45
+ 'linksmanager',
46
+ 'mojoo',
47
+ 'notifixious',
48
+ 'ploetz',
49
+ 'zeller',
50
+ 'sitebar',
51
+ 'xenu',
52
+ 'sleuth',
53
+ );
54
+
55
+ /**
56
+ * Comparison of the UserAgent chain and User Agent signatures
57
+ *
58
+ * @param string $userAgent User Agent chain
59
+ * @param array $server $_SERVER like param
60
+ * @return bool
61
+ */
62
+ public static function match($userAgent, $server)
63
+ {
64
+ return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures);
65
+ }
66
+
67
+ /**
68
+ * Gives the current browser type
69
+ *
70
+ * @return string
71
+ */
72
+ public function getType()
73
+ {
74
+ return 'bot';
75
+ }
76
+ }
lib/Zend/Http/UserAgent/Console.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Http/UserAgent/Desktop.php';
23
+
24
+ /**
25
+ * Console browser type matcher
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Http
29
+ * @subpackage UserAgent
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Http_UserAgent_Console extends Zend_Http_UserAgent_Desktop
34
+ {
35
+ /**
36
+ * User Agent Signatures
37
+ *
38
+ * @var array
39
+ */
40
+ protected static $_uaSignatures = array(
41
+ 'playstation',
42
+ 'wii',
43
+ 'libnup',
44
+ );
45
+
46
+ /**
47
+ * Comparison of the UserAgent chain and User Agent signatures
48
+ *
49
+ * @param string $userAgent User Agent chain
50
+ * @param array $server $_SERVER like param
51
+ * @return bool
52
+ */
53
+ public static function match($userAgent, $server)
54
+ {
55
+ return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures);
56
+ }
57
+
58
+ /**
59
+ * Gives the current browser type
60
+ *
61
+ * @return string
62
+ */
63
+ public function getType()
64
+ {
65
+ return 'console';
66
+ }
67
+ }
lib/Zend/Http/UserAgent/Desktop.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Http/UserAgent/AbstractDevice.php';
23
+
24
+ /**
25
+ * Desktop browser type matcher
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Browser
29
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30
+ * @license http://framework.zend.com/license/new-bsd New BSD License
31
+ */
32
+ class Zend_Http_UserAgent_Desktop extends Zend_Http_UserAgent_AbstractDevice
33
+ {
34
+
35
+ /**
36
+ * Used by default : must be always true
37
+ *
38
+ * @param string $userAgent User Agent chain
39
+ * @param array $server $_SERVER like param
40
+ * @return bool
41
+ */
42
+ public static function match($userAgent, $server)
43
+ {
44
+ return true;
45
+ }
46
+
47
+ /**
48
+ * Gives the current browser type
49
+ *
50
+ * @return string
51
+ */
52
+ public function getType()
53
+ {
54
+ return 'desktop';
55
+ }
56
+ }
lib/Zend/Http/UserAgent/Device.php ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * Interface defining a browser device type.
24
+ *
25
+ * @category Zend
26
+ * @package Zend_Http
27
+ * @subpackage UserAgent
28
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
29
+ * @license http://framework.zend.com/license/new-bsd New BSD License
30
+ */
31
+ interface Zend_Http_UserAgent_Device extends Serializable
32
+ {
33
+ /**
34
+ * Constructor
35
+ *
36
+ * Allows injecting user agent, server array, and/or config array. If an
37
+ * array is provided for the first argument, the assumption should be that
38
+ * the device object is being seeded with cached values from serialization.
39
+ *
40
+ * @param null|string|array $userAgent
41
+ * @param array $server
42
+ * @param array $config
43
+ * @return void
44
+ */
45
+ public function __construct($userAgent = null, array $server = array(), array $config = array());
46
+
47
+ /**
48
+ * Attempt to match the user agent
49
+ *
50
+ * Return either an array of browser signature strings, or a boolean.
51
+ *
52
+ * @param string $userAgent
53
+ * @param array $server
54
+ * @return bool|array
55
+ */
56
+ public static function match($userAgent, $server);
57
+
58
+ /**
59
+ * Get all browser/device features
60
+ *
61
+ * @return array
62
+ */
63
+ public function getAllFeatures();
64
+
65
+ /**
66
+ * Get all of the browser/device's features' groups
67
+ *
68
+ * @return void
69
+ */
70
+ public function getAllGroups();
71
+
72
+ /**
73
+ * Whether or not the device has a given feature
74
+ *
75
+ * @param string $feature
76
+ * @return bool
77
+ */
78
+ public function hasFeature($feature);
79
+
80
+ /**
81
+ * Get the value of a specific device feature
82
+ *
83
+ * @param string $feature
84
+ * @return mixed
85
+ */
86
+ public function getFeature($feature);
87
+
88
+ /**
89
+ * Get the browser type
90
+ *
91
+ * @return string
92
+ */
93
+ public function getBrowser();
94
+
95
+ /**
96
+ * Retrurn the browser version
97
+ *
98
+ * @return string
99
+ */
100
+ public function getBrowserVersion();
101
+
102
+ /**
103
+ * Get an array of features associated with a group
104
+ *
105
+ * @param string $group
106
+ * @return array
107
+ */
108
+ public function getGroup($group);
109
+
110
+ /**
111
+ * Retrieve image format support
112
+ *
113
+ * @return array
114
+ */
115
+ public function getImageFormatSupport();
116
+
117
+ /**
118
+ * Get image types
119
+ *
120
+ * @return array
121
+ */
122
+ public function getImages();
123
+
124
+ /**
125
+ * Get the maximum image height supported by this device
126
+ *
127
+ * @return int
128
+ */
129
+ public function getMaxImageHeight();
130
+
131
+ /**
132
+ * Get the maximum image width supported by this device
133
+ *
134
+ * @return int
135
+ */
136
+ public function getMaxImageWidth();
137
+
138
+ /**
139
+ * Get the physical screen height of this device
140
+ *
141
+ * @return int
142
+ */
143
+ public function getPhysicalScreenHeight();
144
+
145
+ /**
146
+ * Get the physical screen width of this device
147
+ *
148
+ * @return int
149
+ */
150
+ public function getPhysicalScreenWidth();
151
+
152
+ /**
153
+ * Get the preferred markup type
154
+ *
155
+ * @return string
156
+ */
157
+ public function getPreferredMarkup();
158
+
159
+ /**
160
+ * Get the user agent string
161
+ *
162
+ * @return string
163
+ */
164
+ public function getUserAgent();
165
+
166
+ /**
167
+ * Get supported X/HTML version
168
+ *
169
+ * @return int
170
+ */
171
+ public function getXhtmlSupportLevel();
172
+
173
+ /**
174
+ * Does the device support Flash?
175
+ *
176
+ * @return bool
177
+ */
178
+ public function hasFlashSupport();
179
+
180
+ /**
181
+ * Does the device support PDF?
182
+ *
183
+ * @return bool
184
+ */
185
+ public function hasPdfSupport();
186
+
187
+ /**
188
+ * Does the device have a phone number associated with it?
189
+ *
190
+ * @return bool
191
+ */
192
+ public function hasPhoneNumber();
193
+
194
+ /**
195
+ * Does the device support HTTPS?
196
+ *
197
+ * @return bool
198
+ */
199
+ public function httpsSupport();
200
+ }
lib/Zend/Http/UserAgent/Email.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Http/UserAgent/Desktop.php';
23
+
24
+ /**
25
+ * Email browser type matcher
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Http
29
+ * @subpackage UserAgent
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Http_UserAgent_Email extends Zend_Http_UserAgent_Desktop
34
+ {
35
+ /**
36
+ * User Agent Signatures
37
+ *
38
+ * @var array
39
+ */
40
+ protected static $_uaSignatures = array(
41
+ 'thunderbird',
42
+ );
43
+
44
+ /**
45
+ * Comparison of the UserAgent chain and User Agent signatures
46
+ *
47
+ * @param string $userAgent User Agent chain
48
+ * @param array $server $_SERVER like param
49
+ * @return bool
50
+ */
51
+ public static function match($userAgent, $server)
52
+ {
53
+ return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures);
54
+ }
55
+
56
+ /**
57
+ * Gives the current browser type
58
+ *
59
+ * @return string
60
+ */
61
+ public function getType()
62
+ {
63
+ return 'email';
64
+ }
65
+ }
lib/Zend/Http/UserAgent/Exception.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * Zend_Exception
24
+ */
25
+ #require_once 'Zend/Exception.php';
26
+
27
+ /**
28
+ * @category Zend
29
+ * @package Zend_Http
30
+ * @subpackage UserAgent
31
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
+ * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ */
34
+ class Zend_Http_UserAgent_Exception extends Zend_Exception
35
+ {
36
+ }
lib/Zend/Http/UserAgent/Features/Adapter.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * The interface required by all Zend_Browser_Features Adapter classes to implement.
24
+ *
25
+ * @category Zend
26
+ * @package Zend_Http
27
+ * @subpackage UserAgent
28
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
29
+ * @license http://framework.zend.com/license/new-bsd New BSD License
30
+ */
31
+ interface Zend_Http_UserAgent_Features_Adapter
32
+ {
33
+ /**
34
+ * Retrieve the browser's features from a given request object ($_SERVER)
35
+ *
36
+ * @return array
37
+ */
38
+ public static function getFromRequest($request, array $config);
39
+ }
lib/Zend/Http/UserAgent/Features/Adapter/DeviceAtlas.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * Zend_Http_UserAgent_Features_Adapter_Interface
24
+ */
25
+ #require_once 'Zend/Http/UserAgent/Features/Adapter.php';
26
+
27
+ /**
28
+ * Features adapter build with the Tera Wurfl Api
29
+ * See installation instruction here : http://deviceatlas.com/licences
30
+ * Download : http://deviceatlas.com/getAPI/php
31
+ *
32
+ * @package Zend_Http
33
+ * @subpackage UserAgent
34
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
35
+ * @license http://framework.zend.com/license/new-bsd New BSD License
36
+ */
37
+ class Zend_Http_UserAgent_Features_Adapter_DeviceAtlas implements Zend_Http_UserAgent_Features_Adapter
38
+ {
39
+ /**
40
+ * Get features from request
41
+ *
42
+ * @param array $request $_SERVER variable
43
+ * @return array
44
+ */
45
+ public static function getFromRequest($request, array $config)
46
+ {
47
+ if (!class_exists('Mobi_Mtld_DA_Api')) {
48
+ if (!isset($config['deviceatlas'])) {
49
+ #require_once 'Zend/Http/UserAgent/Features/Exception.php';
50
+ throw new Zend_Http_UserAgent_Features_Exception('"DeviceAtlas" configuration is not defined');
51
+ }
52
+ }
53
+
54
+ $config = $config['deviceatlas'];
55
+
56
+ if (!class_exists('Mobi_Mtld_DA_Api')) {
57
+ if (empty($config['deviceatlas_lib_dir'])) {
58
+ #require_once 'Zend/Http/UserAgent/Features/Exception.php';
59
+ throw new Zend_Http_UserAgent_Features_Exception('The "deviceatlas_lib_dir" parameter is not defined');
60
+ }
61
+
62
+ // Include the Device Atlas file from the specified lib_dir
63
+ #require_once ($config['deviceatlas_lib_dir'] . '/Mobi/Mtld/DA/Api.php');
64
+ }
65
+
66
+ if (empty($config['deviceatlas_data'])) {
67
+ #require_once 'Zend/Http/UserAgent/Features/Exception.php';
68
+ throw new Zend_Http_UserAgent_Features_Exception('The "deviceatlas_data" parameter is not defined');
69
+ }
70
+
71
+ //load the device data-tree : e.g. 'json/DeviceAtlas.json
72
+ $tree = Mobi_Mtld_DA_Api::getTreeFromFile($config['deviceatlas_data']);
73
+
74
+ $properties = Mobi_Mtld_DA_Api::getProperties($tree, $request['http_user_agent']);
75
+
76
+ return $properties;
77
+ }
78
+ }
lib/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * Zend_Http_UserAgent_Features_Adapter_Interface
24
+ */
25
+ #require_once 'Zend/Http/UserAgent/Features/Adapter.php';
26
+
27
+ /**
28
+ * Features adapter build with the Tera Wurfl Api
29
+ * See installation instruction here : http://www.tera-wurfl.com/wiki/index.php/Installation
30
+ * Download : http://www.tera-wurfl.com/wiki/index.php/Downloads
31
+ *
32
+ * @package Zend_Http
33
+ * @subpackage UserAgent
34
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
35
+ * @license http://framework.zend.com/license/new-bsd New BSD License
36
+ */
37
+ class Zend_Http_UserAgent_Features_Adapter_TeraWurfl implements Zend_Http_UserAgent_Features_Adapter
38
+ {
39
+ /**
40
+ * Get features from request
41
+ *
42
+ * @param array $request $_SERVER variable
43
+ * @return array
44
+ */
45
+ public static function getFromRequest($request, array $config)
46
+ {
47
+ if (!class_exists('TeraWurfl')) {
48
+ // If TeraWurfl class not found, see if we can load it from
49
+ // configuration
50
+ //
51
+ if (!isset($config['terawurfl'])) {
52
+ // No configuration
53
+ #require_once 'Zend/Http/UserAgent/Features/Exception.php';
54
+ throw new Zend_Http_UserAgent_Features_Exception('"TeraWurfl" configuration is not defined');
55
+ }
56
+
57
+ $config = $config['terawurfl'];
58
+
59
+ if (empty($config['terawurfl_lib_dir'])) {
60
+ // No lib_dir given
61
+ #require_once 'Zend/Http/UserAgent/Features/Exception.php';
62
+ throw new Zend_Http_UserAgent_Features_Exception('The "terawurfl_lib_dir" parameter is not defined');
63
+ }
64
+
65
+ // Include the Tera-WURFL file
66
+ #require_once ($config['terawurfl_lib_dir'] . '/TeraWurfl.php');
67
+ }
68
+
69
+
70
+ // instantiate the Tera-WURFL object
71
+ $wurflObj = new TeraWurfl();
72
+
73
+ // Get the capabilities of the current client.
74
+ $matched = $wurflObj->getDeviceCapabilitiesFromRequest(array_change_key_case($request, CASE_UPPER));
75
+
76
+ return self::getAllCapabilities($wurflObj);
77
+ }
78
+
79
+ /***
80
+ * Builds an array with all capabilities
81
+ *
82
+ * @param TeraWurfl $wurflObj TeraWurfl object
83
+ */
84
+ public static function getAllCapabilities(TeraWurfl $wurflObj)
85
+ {
86
+
87
+ foreach ($wurflObj->capabilities as $group) {
88
+ if (!is_array($group)) {
89
+ continue;
90
+ }
91
+ while (list ($key, $value) = each($group)) {
92
+ if (is_bool($value)) {
93
+ // to have the same type than the official WURFL API
94
+ $features[$key] = ($value ? 'true' : 'false');
95
+ } else {
96
+ $features[$key] = $value;
97
+ }
98
+ }
99
+ }
100
+ return $features;
101
+ }
102
+ }
lib/Zend/Http/UserAgent/Features/Adapter/WurflApi.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * Zend_Http_UserAgent_Features_Adapter_Interface
24
+ */
25
+ #require_once 'Zend/Http/UserAgent/Features/Adapter.php';
26
+
27
+ /**
28
+ * Features adapter build with the official WURFL PHP API
29
+ * See installation instruction here : http://wurfl.sourceforge.net/nphp/
30
+ * Download : http://sourceforge.net/projects/wurfl/files/WURFL PHP/1.1/wurfl-php-1.1.tar.gz/download
31
+ *
32
+ * @package Zend_Http
33
+ * @subpackage UserAgent
34
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
35
+ * @license http://framework.zend.com/license/new-bsd New BSD License
36
+ */
37
+ class Zend_Http_UserAgent_Features_Adapter_WurflApi
38
+ implements Zend_Http_UserAgent_Features_Adapter
39
+ {
40
+ const DEFAULT_API_VERSION = '1.1';
41
+
42
+ /**
43
+ * Get features from request
44
+ *
45
+ * @param array $request $_SERVER variable
46
+ * @return array
47
+ */
48
+ public static function getFromRequest($request, array $config)
49
+ {
50
+ if (!isset($config['wurflapi'])) {
51
+ #require_once 'Zend/Http/UserAgent/Features/Exception.php';
52
+ throw new Zend_Http_UserAgent_Features_Exception('"wurflapi" configuration is not defined');
53
+ }
54
+
55
+ $config = $config['wurflapi'];
56
+
57
+ if (empty($config['wurfl_lib_dir'])) {
58
+ #require_once 'Zend/Http/UserAgent/Features/Exception.php';
59
+ throw new Zend_Http_UserAgent_Features_Exception('The "wurfl_lib_dir" parameter is not defined');
60
+ }
61
+ if (empty($config['wurfl_config_file']) && empty($config['wurfl_config_array'])) {
62
+ #require_once 'Zend/Http/UserAgent/Features/Exception.php';
63
+ throw new Zend_Http_UserAgent_Features_Exception('The "wurfl_config_file" parameter is not defined');
64
+ }
65
+
66
+ if (empty($config['wurfl_api_version'])) {
67
+ $config['wurfl_api_version'] = self::DEFAULT_API_VERSION;
68
+ }
69
+
70
+ switch ($config['wurfl_api_version']) {
71
+ case '1.0':
72
+ // Zend_Http_UserAgent::$config['wurfl_config_file'] must be an XML file
73
+ #require_once ($config['wurfl_lib_dir'] . 'WURFLManagerProvider.php');
74
+ $wurflManager = WURFL_WURFLManagerProvider::getWURFLManager(Zend_Http_UserAgent::$config['wurfl_config_file']);
75
+ break;
76
+ case '1.1':
77
+ #require_once ($config['wurfl_lib_dir'] . 'Application.php');
78
+ if (!empty($config['wurfl_config_file'])) {
79
+ $wurflConfig = WURFL_Configuration_ConfigFactory::create($config['wurfl_config_file']);
80
+ } elseif (!empty($config['wurfl_config_array'])) {
81
+ $c = $config['wurfl_config_array'];
82
+ $wurflConfig = new WURFL_Configuration_InMemoryConfig();
83
+ $wurflConfig->wurflFile($c['wurfl']['main-file'])
84
+ ->wurflPatch($c['wurfl']['patches'])
85
+ ->persistence($c['persistence']['provider'], $c['persistence']['dir']);
86
+ }
87
+
88
+ $wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig);
89
+ $wurflManager = $wurflManagerFactory->create();
90
+ break;
91
+ default:
92
+ #require_once 'Zend/Http/UserAgent/Features/Exception.php';
93
+ throw new Zend_Http_UserAgent_Features_Exception(sprintf(
94
+ 'Unknown API version "%s"',
95
+ $config['wurfl_api_version']
96
+ ));
97
+ }
98
+
99
+ $device = $wurflManager->getDeviceForHttpRequest(array_change_key_case($request, CASE_UPPER));
100
+ $features = $device->getAllCapabilities();
101
+ return $features;
102
+ }
103
+ }
lib/Zend/Http/UserAgent/Features/Exception.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Browser_Exception
24
+ */
25
+ #require_once 'Zend/Http/UserAgent/Exception.php';
26
+
27
+ /**
28
+ * @category Zend
29
+ * @package Zend_Http
30
+ * @subpackage UserAgent
31
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
+ * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ */
34
+ class Zend_Http_UserAgent_Features_Exception extends Zend_Http_UserAgent_Exception
35
+ {
36
+ }
lib/Zend/Http/UserAgent/Feed.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Http/UserAgent/AbstractDevice.php';
23
+
24
+ /**
25
+ * Feed browser type matcher
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Http
29
+ * @subpackage UserAgent
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Http_UserAgent_Feed extends Zend_Http_UserAgent_AbstractDevice
34
+ {
35
+ /**
36
+ * User Agent Signatures
37
+ *
38
+ * @var array
39
+ */
40
+ protected static $_uaSignatures = array(
41
+ 'bloglines',
42
+ 'everyfeed',
43
+ 'feedfetcher',
44
+ 'gregarius',
45
+ );
46
+
47
+ /**
48
+ * Comparison of the UserAgent chain and User Agent signatures
49
+ *
50
+ * @param string $userAgent User Agent chain
51
+ * @param array $server $_SERVER like param
52
+ * @return bool
53
+ */
54
+ public static function match($userAgent, $server)
55
+ {
56
+ return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures);
57
+ }
58
+
59
+ /**
60
+ * Gives the current browser type
61
+ *
62
+ * @return string
63
+ */
64
+ public function getType()
65
+ {
66
+ return 'feed';
67
+ }
68
+
69
+ /**
70
+ * Look for features
71
+ *
72
+ * @return string
73
+ */
74
+ protected function _defineFeatures()
75
+ {
76
+ $this->setFeature('iframes', false, 'product_capability');
77
+ $this->setFeature('frames', false, 'product_capability');
78
+ $this->setFeature('javascript', false, 'product_capability');
79
+ return parent::_defineFeatures();
80
+ }
81
+ }
lib/Zend/Http/UserAgent/Mobile.php ADDED
@@ -0,0 +1,534 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Http/UserAgent/AbstractDevice.php';
23
+
24
+ /**
25
+ * Mobile browser type matcher
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Http
29
+ * @subpackage UserAgent
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Http_UserAgent_Mobile extends Zend_Http_UserAgent_AbstractDevice
34
+ {
35
+
36
+ const DEFAULT_FEATURES_ADAPTER_CLASSNAME = 'Zend_Http_UserAgent_Features_Adapter_WurflApi';
37
+
38
+ const DEFAULT_FEATURES_ADAPTER_PATH = 'Zend/Http/UserAgent/Features/Adapter/WurflApi.php';
39
+
40
+ /**
41
+ * User Agent Signatures
42
+ *
43
+ * @var array
44
+ */
45
+ protected static $_uaSignatures = array(
46
+ 'iphone',
47
+ 'ipod',
48
+ 'ipad',
49
+ 'android',
50
+ 'blackberry',
51
+ 'opera mini',
52
+ 'opera mobi',
53
+ 'palm',
54
+ 'palmos',
55
+ 'elaine',
56
+ 'windows ce',
57
+ ' ppc',
58
+ '_mms',
59
+ 'ahong',
60
+ 'archos',
61
+ 'armv',
62
+ 'astel',
63
+ 'avantgo',
64
+ 'benq',
65
+ 'blazer',
66
+ 'brew',
67
+ 'com2',
68
+ 'compal',
69
+ 'danger',
70
+ 'pocket',
71
+ 'docomo',
72
+ 'epoc',
73
+ 'ericsson',
74
+ 'eudoraweb',
75
+ 'hiptop',
76
+ 'htc-',
77
+ 'htc_',
78
+ 'iemobile',
79
+ 'ipad',
80
+ 'iris',
81
+ 'j-phone',
82
+ 'kddi',
83
+ 'kindle',
84
+ 'lg ',
85
+ 'lg-',
86
+ 'lg/',
87
+ 'lg;lx',
88
+ 'lge vx',
89
+ 'lge',
90
+ 'lge-',
91
+ 'lge-cx',
92
+ 'lge-lx',
93
+ 'lge-mx',
94
+ 'linux armv',
95
+ 'maemo',
96
+ 'midp',
97
+ 'mini 9.5',
98
+ 'minimo',
99
+ 'mob-x',
100
+ 'mobi',
101
+ 'mobile',
102
+ 'mobilephone',
103
+ 'mot 24',
104
+ 'mot-',
105
+ 'motorola',
106
+ 'n410',
107
+ 'netfront',
108
+ 'nintendo wii',
109
+ 'nintendo',
110
+ 'nitro',
111
+ 'nokia',
112
+ 'novarra-vision',
113
+ 'nuvifone',
114
+ 'openweb',
115
+ 'opwv',
116
+ 'palmsource',
117
+ 'pdxgw',
118
+ 'phone',
119
+ 'playstation',
120
+ 'polaris',
121
+ 'portalmmm',
122
+ 'qt embedded',
123
+ 'reqwirelessweb',
124
+ 'sagem',
125
+ 'sam-r',
126
+ 'samsu',
127
+ 'samsung',
128
+ 'sec-',
129
+ 'sec-sgh',
130
+ 'semc-browser',
131
+ 'series60',
132
+ 'series70',
133
+ 'series80',
134
+ 'series90',
135
+ 'sharp',
136
+ 'sie-m',
137
+ 'sie-s',
138
+ 'smartphone',
139
+ 'sony cmd',
140
+ 'sonyericsson',
141
+ 'sprint',
142
+ 'spv',
143
+ 'symbian os',
144
+ 'symbian',
145
+ 'symbianos',
146
+ 'telco',
147
+ 'teleca',
148
+ 'treo',
149
+ 'up.browser',
150
+ 'up.link',
151
+ 'vodafone',
152
+ 'vodaphone',
153
+ 'webos',
154
+ 'webpro',
155
+ 'windows phone os 7',
156
+ 'wireless',
157
+ 'wm5 pie',
158
+ 'wms pie',
159
+ 'xiino',
160
+ 'wap',
161
+ 'up/',
162
+ 'psion',
163
+ 'j2me',
164
+ 'klondike',
165
+ 'kbrowser'
166
+ );
167
+
168
+ /**
169
+ * @var array
170
+ */
171
+ protected static $_haTerms = array(
172
+ 'midp',
173
+ 'wml',
174
+ 'vnd.rim',
175
+ 'vnd.wap',
176
+ );
177
+
178
+ /**
179
+ * first 4 letters of mobile User Agent chains
180
+ *
181
+ * @var array
182
+ */
183
+ protected static $_uaBegin = array(
184
+ 'w3c ',
185
+ 'acs-',
186
+ 'alav',
187
+ 'alca',
188
+ 'amoi',
189
+ 'audi',
190
+ 'avan',
191
+ 'benq',
192
+ 'bird',
193
+ 'blac',
194
+ 'blaz',
195
+ 'brew',
196
+ 'cell',
197
+ 'cldc',
198
+ 'cmd-',
199
+ 'dang',
200
+ 'doco',
201
+ 'eric',
202
+ 'hipt',
203
+ 'inno',
204
+ 'ipaq',
205
+ 'java',
206
+ 'jigs',
207
+ 'kddi',
208
+ 'keji',
209
+ 'leno',
210
+ 'lg-c',
211
+ 'lg-d',
212
+ 'lg-g',
213
+ 'lge-',
214
+ 'maui',
215
+ 'maxo',
216
+ 'midp',
217
+ 'mits',
218
+ 'mmef',
219
+ 'mobi',
220
+ 'mot-',
221
+ 'moto',
222
+ 'mwbp',
223
+ 'nec-',
224
+ 'newt',
225
+ 'noki',
226
+ 'oper',
227
+ 'palm',
228
+ 'pana',
229
+ 'pant',
230
+ 'phil',
231
+ 'play',
232
+ 'port',
233
+ 'prox',
234
+ 'qwap',
235
+ 'sage',
236
+ 'sams',
237
+ 'sany',
238
+ 'sch-',
239
+ 'sec-',
240
+ 'send',
241
+ 'seri',
242
+ 'sgh-',
243
+ 'shar',
244
+ 'sie-',
245
+ 'siem',
246
+ 'smal',
247
+ 'smar',
248
+ 'sony',
249
+ 'sph-',
250
+ 'symb',
251
+ 't-mo',
252
+ 'teli',
253
+ 'tim-',
254
+ 'tosh',
255
+ 'tsm-',
256
+ 'upg1',
257
+ 'upsi',
258
+ 'vk-v',
259
+ 'voda',
260
+ 'wap-',
261
+ 'wapa',
262
+ 'wapi',
263
+ 'wapp',
264
+ 'wapr',
265
+ 'webc',
266
+ 'winw',
267
+ 'winw',
268
+ 'xda',
269
+ 'xda-',
270
+ );
271
+
272
+ /**
273
+ * Comparison of the UserAgent chain and User Agent signatures
274
+ *
275
+ * @param string $userAgent User Agent chain
276
+ * @param array $server $_SERVER like param
277
+ * @return bool
278
+ */
279
+ public static function match($userAgent, $server)
280
+ {
281
+ // To have a quick identification, try light-weight tests first
282
+ if (isset($server['all_http'])) {
283
+ if (strpos(strtolower(str_replace(' ', '', $server['all_http'])), 'operam') !== false) {
284
+ // Opera Mini or Opera Mobi
285
+ return true;
286
+ }
287
+ }
288
+ if (isset($server['http_x_wap_profile']) || isset($server['http_profile'])) {
289
+ return true;
290
+ }
291
+
292
+ if (self::_matchAgentAgainstSignatures($userAgent, self::$_haTerms)) {
293
+ return true;
294
+ }
295
+
296
+ if (self::userAgentStart($userAgent)) {
297
+ return true;
298
+ }
299
+
300
+ if (self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures)) {
301
+ return true;
302
+ }
303
+
304
+ return false;
305
+ }
306
+
307
+ /**
308
+ * Retrieve beginning clause of user agent
309
+ *
310
+ * @param string $userAgent
311
+ * @return string
312
+ */
313
+ public static function userAgentStart($userAgent)
314
+ {
315
+
316
+ $mobile_ua = strtolower(substr($userAgent, 0, 4));
317
+
318
+ return (in_array($mobile_ua, self::$_uaBegin));
319
+ }
320
+
321
+ /**
322
+ * Constructor
323
+ *
324
+ * @return void
325
+ */
326
+ public function __construct($userAgent = null, array $server = array(), array $config = array())
327
+ {
328
+ // For mobile detection, an adapter must be defined
329
+ if (empty($config['mobile']['features'])) {
330
+ $config['mobile']['features']['path'] = self::DEFAULT_FEATURES_ADAPTER_PATH;
331
+ $config['mobile']['features']['classname'] = self::DEFAULT_FEATURES_ADAPTER_CLASSNAME;
332
+ }
333
+ parent::__construct($userAgent, $server, $config);
334
+ }
335
+
336
+ /**
337
+ * Gives the current browser type
338
+ *
339
+ * @return string
340
+ */
341
+ public function getType()
342
+ {
343
+ return 'mobile';
344
+ }
345
+
346
+ /**
347
+ * Look for features
348
+ *
349
+ * @return string
350
+ */
351
+ protected function _defineFeatures()
352
+ {
353
+ $this->setFeature('is_wireless_device', false, 'product_info');
354
+
355
+ parent::_defineFeatures();
356
+
357
+ if (isset($this->_aFeatures["mobile_browser"])) {
358
+ $this->setFeature("browser_name", $this->_aFeatures["mobile_browser"]);
359
+ $this->_browser = $this->_aFeatures["mobile_browser"];
360
+ }
361
+ if (isset($this->_aFeatures["mobile_browser_version"])) {
362
+ $this->setFeature("browser_version", $this->_aFeatures["mobile_browser_version"]);
363
+ $this->_browserVersion = $this->_aFeatures["mobile_browser_version"];
364
+ }
365
+
366
+ // markup
367
+ if ($this->getFeature('device_os') == 'iPhone OS'
368
+ || $this->getFeature('device_os_token') == 'iPhone OS'
369
+ ) {
370
+ $this->setFeature('markup', 'iphone');
371
+ } else {
372
+ $this->setFeature('markup', $this->getMarkupLanguage($this->getFeature('preferred_markup')));
373
+ }
374
+
375
+ // image format
376
+ $this->_images = array();
377
+
378
+ if ($this->getFeature('png')) {
379
+ $this->_images[] = 'png';
380
+ }
381
+ if ($this->getFeature('jpg')) {
382
+ $this->_images[] = 'jpg';
383
+ }
384
+ if ($this->getFeature('gif')) {
385
+ $this->_images[] = 'gif';
386
+ }
387
+ if ($this->getFeature('wbmp')) {
388
+ $this->_images[] = 'wbmp';
389
+ }
390
+
391
+ return $this->_aFeatures;
392
+ }
393
+
394
+ /**
395
+ * Determine markup language expected
396
+ *
397
+ * @access public
398
+ * @return __TYPE__
399
+ */
400
+ public function getMarkupLanguage($preferredMarkup = null)
401
+ {
402
+ $return = '';
403
+ switch ($preferredMarkup) {
404
+ case 'wml_1_1':
405
+ case 'wml_1_2':
406
+ case 'wml_1_3':
407
+ $return = 'wml'; //text/vnd.wap.wml encoding="ISO-8859-15"
408
+ case 'html_wi_imode_compact_generic':
409
+ case 'html_wi_imode_html_1':
410
+ case 'html_wi_imode_html_2':
411
+ case 'html_wi_imode_html_3':
412
+ case 'html_wi_imode_html_4':
413
+ case 'html_wi_imode_html_5':
414
+ $return = 'chtml'; //text/html
415
+ case 'html_wi_oma_xhtmlmp_1_0': //application/vnd.wap.xhtml+xml
416
+ case 'html_wi_w3_xhtmlbasic': //application/xhtml+xml DTD XHTML Basic 1.0
417
+ $return = 'xhtml';
418
+ case 'html_web_3_2': //text/html DTD Html 3.2 Final
419
+ case 'html_web_4_0': //text/html DTD Html 4.01 Transitional
420
+ $return = '';
421
+ }
422
+ return $return;
423
+ }
424
+
425
+ /**
426
+ * Determine image format support
427
+ *
428
+ * @return array
429
+ */
430
+ public function getImageFormatSupport()
431
+ {
432
+ return $this->_images;
433
+ }
434
+
435
+ /**
436
+ * Determine maximum image height supported
437
+ *
438
+ * @return int
439
+ */
440
+ public function getMaxImageHeight()
441
+ {
442
+ return $this->getFeature('max_image_height');
443
+ }
444
+
445
+ /**
446
+ * Determine maximum image width supported
447
+ *
448
+ * @return int
449
+ */
450
+ public function getMaxImageWidth()
451
+ {
452
+ return $this->getFeature('max_image_width');
453
+ }
454
+
455
+ /**
456
+ * Determine physical screen height
457
+ *
458
+ * @return int
459
+ */
460
+ public function getPhysicalScreenHeight()
461
+ {
462
+ return $this->getFeature('physical_screen_height');
463
+ }
464
+
465
+ /**
466
+ * Determine physical screen width
467
+ *
468
+ * @return int
469
+ */
470
+ public function getPhysicalScreenWidth()
471
+ {
472
+ return $this->getFeature('physical_screen_width');
473
+ }
474
+
475
+ /**
476
+ * Determine preferred markup
477
+ *
478
+ * @return string
479
+ */
480
+ public function getPreferredMarkup()
481
+ {
482
+ return $this->getFeature("markup");
483
+ }
484
+
485
+ /**
486
+ * Determine X/HTML support level
487
+ *
488
+ * @return int
489
+ */
490
+ public function getXhtmlSupportLevel()
491
+ {
492
+ return $this->getFeature('xhtml_support_level');
493
+ }
494
+
495
+ /**
496
+ * Does the device support Flash?
497
+ *
498
+ * @return bool
499
+ */
500
+ public function hasFlashSupport()
501
+ {
502
+ return $this->getFeature('fl_browser');
503
+ }
504
+
505
+ /**
506
+ * Does the device support PDF?
507
+ *
508
+ * @return bool
509
+ */
510
+ public function hasPdfSupport()
511
+ {
512
+ return $this->getFeature('pdf_support');
513
+ }
514
+
515
+ /**
516
+ * Does the device have an associated phone number?
517
+ *
518
+ * @return bool
519
+ */
520
+ public function hasPhoneNumber()
521
+ {
522
+ return $this->getFeature('can_assign_phone_number');
523
+ }
524
+
525
+ /**
526
+ * Does the device support HTTPS?
527
+ *
528
+ * @return bool
529
+ */
530
+ public function httpsSupport()
531
+ {
532
+ return ($this->getFeature('https_support') == 'supported');
533
+ }
534
+ }
lib/Zend/Http/UserAgent/Offline.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Http/UserAgent/Desktop.php';
23
+
24
+ /**
25
+ * Offline browser type matcher
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Http
29
+ * @subpackage UserAgent
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Http_UserAgent_Offline extends Zend_Http_UserAgent_Desktop
34
+ {
35
+ /**
36
+ * User Agent Signatures
37
+ *
38
+ * @var array
39
+ */
40
+ protected static $_uaSignatures = array(
41
+ 'wget',
42
+ 'webzip',
43
+ 'webcopier',
44
+ 'downloader',
45
+ 'superbot',
46
+ 'offline',
47
+ );
48
+
49
+ /**
50
+ * Comparison of the UserAgent chain and User Agent signatures
51
+ *
52
+ * @param string $userAgent User Agent chain
53
+ * @param array $server $_SERVER like param
54
+ * @return bool
55
+ */
56
+ public static function match($userAgent, $server)
57
+ {
58
+ return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures);
59
+ }
60
+
61
+ /**
62
+ * Gives the current browser type
63
+ *
64
+ * @return string
65
+ */
66
+ public function getType()
67
+ {
68
+ return 'offline';
69
+ }
70
+ }
lib/Zend/Http/UserAgent/Probe.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Http/UserAgent/AbstractDevice.php';
23
+
24
+ /**
25
+ * Probe browser type matcher
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Http
29
+ * @subpackage UserAgent
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Http_UserAgent_Probe extends Zend_Http_UserAgent_AbstractDevice
34
+ {
35
+ /**
36
+ * User Agent Signatures
37
+ *
38
+ * @var array
39
+ */
40
+ protected static $_uaSignatures = array(
41
+ 'witbe',
42
+ 'netvigie',
43
+ );
44
+
45
+ /**
46
+ * Comparison of the UserAgent chain and User Agent signatures
47
+ *
48
+ * @param string $userAgent User Agent chain
49
+ * @param array $server $_SERVER like param
50
+ * @return bool
51
+ */
52
+ public static function match($userAgent, $server)
53
+ {
54
+ return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures);
55
+ }
56
+
57
+
58
+ /**
59
+ * Gives the current browser type
60
+ *
61
+ * @return string
62
+ */
63
+ public function getType()
64
+ {
65
+ return 'probe';
66
+ }
67
+
68
+ /**
69
+ * Look for features
70
+ *
71
+ * @return string
72
+ */
73
+ protected function _defineFeatures()
74
+ {
75
+ $this->setFeature('images', false, 'product_capability');
76
+ $this->setFeature('iframes', false, 'product_capability');
77
+ $this->setFeature('frames', false, 'product_capability');
78
+ $this->setFeature('javascript', false, 'product_capability');
79
+ return parent::_defineFeatures();
80
+ }
81
+ }
lib/Zend/Http/UserAgent/Spam.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Http/UserAgent/AbstractDevice.php';
23
+
24
+ /**
25
+ * Spam browser type matcher
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Http
29
+ * @subpackage UserAgent
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Http_UserAgent_Spam extends Zend_Http_UserAgent_AbstractDevice
34
+ {
35
+ /**
36
+ * @todo User Agent Signatures
37
+ *
38
+ * @var array
39
+ */
40
+ protected static $_uaSignatures = array(
41
+ '',
42
+ );
43
+
44
+ /**
45
+ * Comparison of the UserAgent chain and User Agent signatures
46
+ *
47
+ * @param string $userAgent User Agent chain
48
+ * @param array $server $_SERVER like param
49
+ * @return bool
50
+ */
51
+ public static function match($userAgent, $server)
52
+ {
53
+ return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures);
54
+ }
55
+
56
+ /**
57
+ * Gives the current browser type
58
+ *
59
+ * @return string
60
+ */
61
+ public function getType()
62
+ {
63
+ return 'spam';
64
+ }
65
+
66
+ /**
67
+ * Look for features
68
+ *
69
+ * @return string
70
+ */
71
+ protected function _defineFeatures()
72
+ {
73
+ $this->setFeature('images', false, 'product_capability');
74
+ $this->setFeature('iframes', false, 'product_capability');
75
+ $this->setFeature('frames', false, 'product_capability');
76
+ $this->setFeature('javascript', false, 'product_capability');
77
+ return parent::_defineFeatures();
78
+ }
79
+ }
lib/Zend/Http/UserAgent/Storage.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @category Zend
24
+ * @package Zend_Http
25
+ * @subpackage UserAgent
26
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
+ * @license http://framework.zend.com/license/new-bsd New BSD License
28
+ */
29
+ interface Zend_Http_UserAgent_Storage
30
+ {
31
+ /**
32
+ * Returns true if and only if storage is empty
33
+ *
34
+ * @throws Zend_Http_UserAgent_Storage_Exception If it is impossible to determine whether storage is empty
35
+ * @return boolean
36
+ */
37
+ public function isEmpty();
38
+
39
+ /**
40
+ * Returns the contents of storage associated to the key parameter
41
+ *
42
+ * Behavior is undefined when storage is empty.
43
+ *
44
+ * @throws Zend_Http_UserAgent_Storage_Exception If reading contents from storage is impossible
45
+ * @return mixed
46
+ */
47
+ public function read();
48
+
49
+ /**
50
+ * Writes $contents associated to the key parameter to storage
51
+ *
52
+ * @param mixed $contents
53
+ * @throws Zend_Http_UserAgent_Storage_Exception If writing $contents to storage is impossible
54
+ * @return void
55
+ */
56
+ public function write($contents);
57
+
58
+ /**
59
+ * Clears contents from storage
60
+ *
61
+ * @throws Zend_Http_UserAgent_Storage_Exception If clearing contents from storage is impossible
62
+ * @return void
63
+ */
64
+ public function clear();
65
+ }
lib/Zend/Http/UserAgent/Storage/Exception.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+
23
+ /**
24
+ * @see Zend_Http_UserAgent_Exception
25
+ */
26
+ #require_once 'Zend/Http/UserAgent/Exception.php';
27
+
28
+
29
+ /**
30
+ * @package Zend_Http
31
+ * @subpackage UserAgent
32
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33
+ * @license http://framework.zend.com/license/new-bsd New BSD License
34
+ */
35
+ class Zend_Http_UserAgent_Storage_Exception extends Zend_Http_UserAgent_Exception
36
+ {
37
+ }
lib/Zend/Http/UserAgent/Storage/NonPersistent.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: NonPersistent.php 20096 2010-01-06 02:05:09Z bkarwin $
21
+ */
22
+
23
+
24
+ /**
25
+ * @see Zend_Http_UserAgent_Storage_Interface
26
+ */
27
+ #require_once 'Zend/Http/UserAgent/Storage.php';
28
+
29
+
30
+ /**
31
+ * Non-Persistent Browser Storage
32
+ *
33
+ * Since HTTP Browserentication happens again on each request, this will always be
34
+ * re-populated. So there's no need to use sessions, this simple value class
35
+ * will hold the data for rest of the current request.
36
+ *
37
+ * @package Zend_Http
38
+ * @subpackage UserAgent
39
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
40
+ * @license http://framework.zend.com/license/new-bsd New BSD License
41
+ */
42
+ class Zend_Http_UserAgent_Storage_NonPersistent
43
+ implements Zend_Http_UserAgent_Storage
44
+ {
45
+ /**
46
+ * Holds the actual Browser data
47
+ * @var mixed
48
+ */
49
+ protected $_data;
50
+
51
+ /**
52
+ * Returns true if and only if storage is empty
53
+ *
54
+ * @throws Zend_Http_UserAgent_Storage_Exception If it is impossible to determine whether storage is empty
55
+ * @return boolean
56
+ */
57
+ public function isEmpty()
58
+ {
59
+ return empty($this->_data);
60
+ }
61
+
62
+ /**
63
+ * Returns the contents of storage
64
+ *
65
+ * Behavior is undefined when storage is empty.
66
+ *
67
+ * @throws Zend_Http_UserAgent_Storage_Exception If reading contents from storage is impossible
68
+ * @return mixed
69
+ */
70
+ public function read()
71
+ {
72
+ return $this->_data;
73
+ }
74
+
75
+ /**
76
+ * Writes $contents to storage
77
+ *
78
+ * @param mixed $contents
79
+ * @throws Zend_Http_UserAgent_Storage_Exception If writing $contents to storage is impossible
80
+ * @return void
81
+ */
82
+ public function write($contents)
83
+ {
84
+ $this->_data = $contents;
85
+ }
86
+
87
+ /**
88
+ * Clears contents from storage
89
+ *
90
+ * @throws Zend_Http_UserAgent_Storage_Exception If clearing contents from storage is impossible
91
+ * @return void
92
+ */
93
+ public function clear()
94
+ {
95
+ $this->_data = null;
96
+ }
97
+ }
lib/Zend/Http/UserAgent/Storage/Session.php ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Http_UserAgent_Storage
24
+ */
25
+ #require_once 'Zend/Http/UserAgent/Storage.php';
26
+
27
+ /**
28
+ * @see Zend_Session_Namespace
29
+ */
30
+ #require_once 'Zend/Session/Namespace.php';
31
+
32
+ /**
33
+ * @package Zend_Http
34
+ * @subpackage UserAgent
35
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
36
+ * @license http://framework.zend.com/license/new-bsd New BSD License
37
+ */
38
+ class Zend_Http_UserAgent_Storage_Session implements Zend_Http_UserAgent_Storage
39
+ {
40
+ /**
41
+ * Default session namespace
42
+ */
43
+ const NAMESPACE_DEFAULT = 'Zend_Http_UserAgent';
44
+
45
+ /**
46
+ * Default session object member name
47
+ */
48
+ const MEMBER_DEFAULT = 'storage';
49
+
50
+ /**
51
+ * Object to proxy $_SESSION storage
52
+ *
53
+ * @var Zend_Session_Namespace
54
+ */
55
+ protected $_session;
56
+
57
+ /**
58
+ * Session namespace
59
+ *
60
+ * @var mixed
61
+ */
62
+ protected $_namespace;
63
+
64
+ /**
65
+ * Session object member
66
+ *
67
+ * @var mixed
68
+ */
69
+ protected $_member;
70
+
71
+ /**
72
+ * Sets session storage options and initializes session namespace object
73
+ *
74
+ * Expects options to contain 0 or more of the following keys:
75
+ * - browser_type -- maps to "namespace" internally
76
+ * - member
77
+ *
78
+ * @param null|array|object $options
79
+ * @return void
80
+ * @throws Zend_Http_UserAgent_Storage_Exception on invalid $options argument
81
+ */
82
+ public function __construct($options = null)
83
+ {
84
+ if (is_object($options) && method_exists($options, 'toArray')) {
85
+ $options = $options->toArray();
86
+ } elseif (is_object($options)) {
87
+ $options = (array) $options;
88
+ }
89
+ if (null !== $options && !is_array($options)) {
90
+ #require_once 'Zend/Http/UserAgent/Storage/Exception.php';
91
+ throw new Zend_Http_UserAgent_Storage_Exception(sprintf(
92
+ 'Expected array or object options; "%s" provided',
93
+ gettype($options)
94
+ ));
95
+ }
96
+
97
+ // add '.' to prevent the message ''Session namespace must not start with a number'
98
+ $this->_namespace = '.'
99
+ . (isset($options['browser_type'])
100
+ ? $options['browser_type']
101
+ : self::NAMESPACE_DEFAULT);
102
+ $this->_member = isset($options['member']) ? $options['member'] : self::MEMBER_DEFAULT;
103
+ $this->_session = new Zend_Session_Namespace($this->_namespace);
104
+ }
105
+
106
+ /**
107
+ * Returns the session namespace name
108
+ *
109
+ * @return string
110
+ */
111
+ public function getNamespace()
112
+ {
113
+ return $this->_namespace;
114
+ }
115
+
116
+ /**
117
+ * Returns the name of the session object member
118
+ *
119
+ * @return string
120
+ */
121
+ public function getMember()
122
+ {
123
+ return $this->_member;
124
+ }
125
+
126
+ /**
127
+ * Defined by Zend_Http_UserAgent_Storage
128
+ *
129
+ * @return boolean
130
+ */
131
+ public function isEmpty()
132
+ {
133
+ return empty($this->_session->{$this->_member});
134
+ }
135
+
136
+ /**
137
+ * Defined by Zend_Http_UserAgent_Storage
138
+ *
139
+ * @return mixed
140
+ */
141
+ public function read()
142
+ {
143
+ return $this->_session->{$this->_member};
144
+ }
145
+
146
+ /**
147
+ * Defined by Zend_Http_UserAgent_Storage
148
+ *
149
+ * @param mixed $contents
150
+ * @return void
151
+ */
152
+ public function write($content)
153
+ {
154
+ $this->_session->{$this->_member} = $content;
155
+ }
156
+
157
+ /**
158
+ * Defined by Zend_Http_UserAgent_Storage
159
+ *
160
+ * @return void
161
+ */
162
+ public function clear()
163
+ {
164
+ unset($this->_session->{$this->_member});
165
+ }
166
+ }
lib/Zend/Http/UserAgent/Text.php ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Http/UserAgent/AbstractDevice.php';
23
+
24
+ /**
25
+ * Text browser type matcher
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Http
29
+ * @subpackage UserAgent
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Http_UserAgent_Text extends Zend_Http_UserAgent_AbstractDevice
34
+ {
35
+ /**
36
+ * User Agent Signatures
37
+ *
38
+ * @var array
39
+ */
40
+ protected static $_uaSignatures = array(
41
+ 'lynx',
42
+ 'retawq',
43
+ 'w3m',
44
+ );
45
+
46
+ /**
47
+ * Comparison of the UserAgent chain and User Agent signatures
48
+ *
49
+ * @param string $userAgent User Agent chain
50
+ * @param array $server $_SERVER like param
51
+ * @return bool
52
+ */
53
+ public static function match($userAgent, $server)
54
+ {
55
+ return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures);
56
+ }
57
+
58
+ /**
59
+ * Gives the current browser type
60
+ *
61
+ * @return string
62
+ */
63
+ public function getType()
64
+ {
65
+ return 'text';
66
+ }
67
+
68
+ /**
69
+ * Look for features
70
+ *
71
+ * @return string
72
+ */
73
+ protected function _defineFeatures()
74
+ {
75
+ $this->setFeature('images', false, 'product_capability');
76
+ $this->setFeature('iframes', false, 'product_capability');
77
+ $this->setFeature('frames', false, 'product_capability');
78
+ $this->setFeature('javascript', false, 'product_capability');
79
+ return parent::_defineFeatures();
80
+ }
81
+
82
+ /**
83
+ * Determine supported image formats
84
+ *
85
+ * @return null
86
+ */
87
+ public function getImageFormatSupport()
88
+ {
89
+ return null;
90
+ }
91
+
92
+ /**
93
+ * Get preferred markup format
94
+ *
95
+ * @return string
96
+ */
97
+ public function getPreferredMarkup()
98
+ {
99
+ return 'xhtml';
100
+ }
101
+
102
+ /**
103
+ * Get supported X/HTML markup level
104
+ *
105
+ * @return int
106
+ */
107
+ public function getXhtmlSupportLevel()
108
+ {
109
+ return 1;
110
+ }
111
+
112
+ /**
113
+ * Does the device support Flash?
114
+ *
115
+ * @return bool
116
+ */
117
+ public function hasFlashSupport()
118
+ {
119
+
120
+ return false;
121
+ }
122
+
123
+ /**
124
+ * Does the device support PDF?
125
+ *
126
+ * @return bool
127
+ */
128
+ public function hasPdfSupport()
129
+ {
130
+ return false;
131
+ }
132
+ }
lib/Zend/Http/UserAgent/Validator.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Http
17
+ * @subpackage UserAgent
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ #require_once 'Zend/Http/UserAgent/Desktop.php';
23
+
24
+ /**
25
+ * Validator browser type matcher
26
+ *
27
+ * @category Zend
28
+ * @package Zend_Http
29
+ * @subpackage UserAgent
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Http_UserAgent_Validator extends Zend_Http_UserAgent_Desktop
34
+ {
35
+ /**
36
+ * User Agent Signatures
37
+ *
38
+ * @var array
39
+ */
40
+ protected static $_uaSignatures = array(
41
+ 'htmlvalidator',
42
+ 'csscheck',
43
+ 'cynthia',
44
+ 'htmlparser',
45
+ 'validator',
46
+ 'jfouffa',
47
+ 'jigsaw',
48
+ 'w3c_validator',
49
+ 'wdg_validator',
50
+ );
51
+
52
+ /**
53
+ * Comparison of the UserAgent chain and User Agent signatures
54
+ *
55
+ * @param string $userAgent User Agent chain
56
+ * @param array $server $_SERVER like param
57
+ * @return bool
58
+ */
59
+ public static function match($userAgent, $server)
60
+ {
61
+ return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures);
62
+ }
63
+
64
+ /**
65
+ * Gives the current browser type
66
+ *
67
+ * @return string
68
+ */
69
+ public function getType()
70
+ {
71
+ return 'validator';
72
+ }
73
+ }
lib/Zend/InfoCard/Xml/Security.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Zend_InfoCard_Xml_Security
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Security.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -174,7 +174,7 @@ class Zend_InfoCard_Xml_Security
174
 
175
  $transformed_xml_binhash = pack("H*", sha1($transformed_xml));
176
 
177
- if($transformed_xml_binhash != $dValue) {
178
  #require_once 'Zend/InfoCard/Xml/Security/Exception.php';
179
  throw new Zend_InfoCard_Xml_Security_Exception("Locally Transformed XML does not match XML Document. Cannot Verify Signature");
180
  }
@@ -302,4 +302,26 @@ class Zend_InfoCard_Xml_Security
302
  #require_once 'Zend/InfoCard/Xml/Security/Exception.php';
303
  throw new Zend_InfoCard_Xml_Security_Exception("Invalid code path");
304
  }
305
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  * @subpackage Zend_InfoCard_Xml_Security
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Security.php 23280 2010-10-31 10:28:58Z ramon $
21
  */
22
 
23
  /**
174
 
175
  $transformed_xml_binhash = pack("H*", sha1($transformed_xml));
176
 
177
+ if(!self::_secureStringCompare($transformed_xml_binhash, $dValue)) {
178
  #require_once 'Zend/InfoCard/Xml/Security/Exception.php';
179
  throw new Zend_InfoCard_Xml_Security_Exception("Locally Transformed XML does not match XML Document. Cannot Verify Signature");
180
  }
302
  #require_once 'Zend/InfoCard/Xml/Security/Exception.php';
303
  throw new Zend_InfoCard_Xml_Security_Exception("Invalid code path");
304
  }
305
+
306
+ /**
307
+ * Securely compare two strings for equality while avoided C level memcmp()
308
+ * optimisations capable of leaking timing information useful to an attacker
309
+ * attempting to iteratively guess the unknown string (e.g. password) being
310
+ * compared against.
311
+ *
312
+ * @param string $a
313
+ * @param string $b
314
+ * @return bool
315
+ */
316
+ static protected function _secureStringCompare($a, $b)
317
+ {
318
+ if (strlen($a) !== strlen($b)) {
319
+ return false;
320
+ }
321
+ $result = 0;
322
+ for ($i = 0; $i < strlen($a); $i++) {
323
+ $result |= ord($a[$i]) ^ ord($b[$i]);
324
+ }
325
+ return $result == 0;
326
+ }
327
+ }
lib/Zend/Json.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Json
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Json.php 20616 2010-01-25 19:56:04Z matthew $
20
  */
21
 
22
  /**
16
  * @package Zend_Json
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Json.php 20615 2010-01-25 19:54:12Z matthew $
20
  */
21
 
22
  /**
lib/Zend/Json/Decoder.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Json
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Decoder.php 22655 2010-07-22 18:47:20Z mabe $
20
  */
21
 
22
  /**
16
  * @package Zend_Json
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Decoder.php 22653 2010-07-22 18:41:39Z mabe $
20
  */
21
 
22
  /**
lib/Zend/Json/Encoder.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Json
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Encoder.php 22453 2010-06-18 18:17:52Z ralph $
20
  */
21
 
22
  /**
16
  * @package Zend_Json
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Encoder.php 22452 2010-06-18 18:13:23Z ralph $
20
  */
21
 
22
  /**
lib/Zend/Json/Server.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Json
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Server.php 22276 2010-05-24 18:31:59Z andyfowler $
20
  */
21
 
22
  /**
16
  * @package Zend_Json
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Server.php 22237 2010-05-21 23:58:00Z andyfowler $
20
  */
21
 
22
  /**
lib/Zend/Ldap.php CHANGED
@@ -17,7 +17,7 @@
17
  * @package Zend_Ldap
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Ldap.php 22502 2010-06-29 08:19:18Z sgehrig $
21
  */
22
 
23
  /**
@@ -913,6 +913,8 @@ class Zend_Ldap
913
  * - attributes
914
  * - sort
915
  * - collectionClass
 
 
916
  *
917
  * @param string|Zend_Ldap_Filter_Abstract|array $filter
918
  * @param string|Zend_Ldap_Dn|null $basedn
@@ -920,11 +922,13 @@ class Zend_Ldap
920
  * @param array $attributes
921
  * @param string|null $sort
922
  * @param string|null $collectionClass
 
 
923
  * @return Zend_Ldap_Collection
924
  * @throws Zend_Ldap_Exception
925
  */
926
- public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB,
927
- array $attributes = array(), $sort = null, $collectionClass = null)
928
  {
929
  if (is_array($filter)) {
930
  $options = array_change_key_case($filter, CASE_LOWER);
@@ -944,6 +948,9 @@ class Zend_Ldap
944
  case 'collectionclass':
945
  $collectionClass = $value;
946
  break;
 
 
 
947
  }
948
  }
949
  }
@@ -961,14 +968,14 @@ class Zend_Ldap
961
 
962
  switch ($scope) {
963
  case self::SEARCH_SCOPE_ONE:
964
- $search = @ldap_list($this->getResource(), $basedn, $filter, $attributes);
965
  break;
966
  case self::SEARCH_SCOPE_BASE:
967
- $search = @ldap_read($this->getResource(), $basedn, $filter, $attributes);
968
  break;
969
  case self::SEARCH_SCOPE_SUB:
970
  default:
971
- $search = @ldap_search($this->getResource(), $basedn, $filter, $attributes);
972
  break;
973
  }
974
 
@@ -979,7 +986,7 @@ class Zend_Ldap
979
  #require_once 'Zend/Ldap/Exception.php';
980
  throw new Zend_Ldap_Exception($this, 'searching: ' . $filter);
981
  }
982
- if (!is_null($sort) && is_string($sort)) {
983
  $isSorted = @ldap_sort($this->getResource(), $search, $sort);
984
  if($isSorted === false) {
985
  /**
@@ -1091,6 +1098,8 @@ class Zend_Ldap
1091
  * - attributes
1092
  * - sort
1093
  * - reverseSort
 
 
1094
  *
1095
  * @param string|Zend_Ldap_Filter_Abstract|array $filter
1096
  * @param string|Zend_Ldap_Dn|null $basedn
@@ -1098,11 +1107,13 @@ class Zend_Ldap
1098
  * @param array $attributes
1099
  * @param string|null $sort
1100
  * @param boolean $reverseSort
 
 
1101
  * @return array
1102
  * @throws Zend_Ldap_Exception
1103
  */
1104
  public function searchEntries($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB,
1105
- array $attributes = array(), $sort = null, $reverseSort = false)
1106
  {
1107
  if (is_array($filter)) {
1108
  $filter = array_change_key_case($filter, CASE_LOWER);
@@ -1114,7 +1125,7 @@ class Zend_Ldap
1114
  unset($filter['reversesort']);
1115
  }
1116
  }
1117
- $result = $this->search($filter, $basedn, $scope, $attributes, $sort);
1118
  $items = $result->toArray();
1119
  if ((bool)$reverseSort === true) {
1120
  $items = array_reverse($items, false);
@@ -1156,7 +1167,7 @@ class Zend_Ldap
1156
  foreach ($entry as $key => $value) {
1157
  if (is_array($value)) {
1158
  foreach ($value as $i => $v) {
1159
- if (is_null($v)) unset($value[$i]);
1160
  else if (!is_scalar($v)) {
1161
  throw new InvalidArgumentException('Only scalar values allowed in LDAP data');
1162
  } else {
@@ -1170,7 +1181,7 @@ class Zend_Ldap
1170
  }
1171
  $entry[$key] = array_values($value);
1172
  } else {
1173
- if (is_null($value)) $entry[$key] = array();
1174
  else if (!is_scalar($value)) {
1175
  throw new InvalidArgumentException('Only scalar values allowed in LDAP data');
1176
  } else {
17
  * @package Zend_Ldap
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Ldap.php 22996 2010-09-22 17:01:46Z sgehrig $
21
  */
22
 
23
  /**
913
  * - attributes
914
  * - sort
915
  * - collectionClass
916
+ * - sizelimit
917
+ * - timelimit
918
  *
919
  * @param string|Zend_Ldap_Filter_Abstract|array $filter
920
  * @param string|Zend_Ldap_Dn|null $basedn
922
  * @param array $attributes
923
  * @param string|null $sort
924
  * @param string|null $collectionClass
925
+ * @param integer $sizelimit
926
+ * @param integer $timelimit
927
  * @return Zend_Ldap_Collection
928
  * @throws Zend_Ldap_Exception
929
  */
930
+ public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB, array $attributes = array(),
931
+ $sort = null, $collectionClass = null, $sizelimit = 0, $timelimit = 0)
932
  {
933
  if (is_array($filter)) {
934
  $options = array_change_key_case($filter, CASE_LOWER);
948
  case 'collectionclass':
949
  $collectionClass = $value;
950
  break;
951
+ case 'sizelimit':
952
+ case 'timelimit':
953
+ $$key = (int)$value;
954
  }
955
  }
956
  }
968
 
969
  switch ($scope) {
970
  case self::SEARCH_SCOPE_ONE:
971
+ $search = @ldap_list($this->getResource(), $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
972
  break;
973
  case self::SEARCH_SCOPE_BASE:
974
+ $search = @ldap_read($this->getResource(), $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
975
  break;
976
  case self::SEARCH_SCOPE_SUB:
977
  default:
978
+ $search = @ldap_search($this->getResource(), $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
979
  break;
980
  }
981
 
986
  #require_once 'Zend/Ldap/Exception.php';
987
  throw new Zend_Ldap_Exception($this, 'searching: ' . $filter);
988
  }
989
+ if ($sort !== null && is_string($sort)) {
990
  $isSorted = @ldap_sort($this->getResource(), $search, $sort);
991
  if($isSorted === false) {
992
  /**
1098
  * - attributes
1099
  * - sort
1100
  * - reverseSort
1101
+ * - sizelimit
1102
+ * - timelimit
1103
  *
1104
  * @param string|Zend_Ldap_Filter_Abstract|array $filter
1105
  * @param string|Zend_Ldap_Dn|null $basedn
1107
  * @param array $attributes
1108
  * @param string|null $sort
1109
  * @param boolean $reverseSort
1110
+ * @param integer $sizelimit
1111
+ * @param integer $timelimit
1112
  * @return array
1113
  * @throws Zend_Ldap_Exception
1114
  */
1115
  public function searchEntries($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB,
1116
+ array $attributes = array(), $sort = null, $reverseSort = false, $sizelimit = 0, $timelimit = 0)
1117
  {
1118
  if (is_array($filter)) {
1119
  $filter = array_change_key_case($filter, CASE_LOWER);
1125
  unset($filter['reversesort']);
1126
  }
1127
  }
1128
+ $result = $this->search($filter, $basedn, $scope, $attributes, $sort, null, $sizelimit, $timelimit);
1129
  $items = $result->toArray();
1130
  if ((bool)$reverseSort === true) {
1131
  $items = array_reverse($items, false);
1167
  foreach ($entry as $key => $value) {
1168
  if (is_array($value)) {
1169
  foreach ($value as $i => $v) {
1170
+ if ($v === null) unset($value[$i]);
1171
  else if (!is_scalar($v)) {
1172
  throw new InvalidArgumentException('Only scalar values allowed in LDAP data');
1173
  } else {
1181
  }
1182
  $entry[$key] = array_values($value);
1183
  } else {
1184
+ if ($value === null) $entry[$key] = array();
1185
  else if (!is_scalar($value)) {
1186
  throw new InvalidArgumentException('Only scalar values allowed in LDAP data');
1187
  } else {
lib/Zend/Ldap/Attribute.php CHANGED
@@ -16,9 +16,14 @@
16
  * @package Zend_Ldap
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Attribute.php 21941 2010-04-18 19:12:08Z sgehrig $
20
  */
21
 
 
 
 
 
 
22
  /**
23
  * Zend_Ldap_Attribute is a collection of LDAP attribute related functions.
24
  *
@@ -53,13 +58,13 @@ class Zend_Ldap_Attribute
53
  foreach ($value as $v)
54
  {
55
  $v = self::_valueToLdap($v);
56
- if (!is_null($v)) $valArray[] = $v;
57
  }
58
  }
59
- else if (!is_null($value))
60
  {
61
  $value = self::_valueToLdap($value);
62
- if (!is_null($value)) $valArray[] = $value;
63
  }
64
 
65
  if ($append === true && isset($data[$attribName]))
@@ -84,7 +89,7 @@ class Zend_Ldap_Attribute
84
  public static function getAttribute(array $data, $attribName, $index = null)
85
  {
86
  $attribName = strtolower($attribName);
87
- if (is_null($index)) {
88
  if (!isset($data[$attribName])) return array();
89
  $retArray = array();
90
  foreach ($data[$attribName] as $v)
@@ -185,32 +190,33 @@ class Zend_Ldap_Attribute
185
  */
186
  private static function _valueToLdap($value)
187
  {
188
- if (is_string($value)) return $value;
189
- else if (is_int($value) || is_float($value)) return (string)$value;
190
- else if (is_bool($value)) return ($value === true) ? 'TRUE' : 'FALSE';
191
- else if (is_object($value) || is_array($value)) return serialize($value);
192
- else if (is_resource($value) && get_resource_type($value) === 'stream')
193
- return stream_get_contents($value);
194
- else return null;
195
  }
196
 
197
  /**
198
  * @param string $value
199
- * @return string|boolean
200
  */
201
  private static function _valueFromLdap($value)
202
  {
203
- $value = (string)$value;
204
- if ($value === 'TRUE') return true;
205
- else if ($value === 'FALSE') return false;
206
- else return $value;
 
 
 
 
 
 
207
  }
208
 
209
  /**
210
  * Converts a PHP data type into its LDAP representation
211
  *
212
- * @param mixed $value
213
- * @return string|null - null if the PHP data type cannot be converted.
 
214
  */
215
  public static function convertToLdapValue($value)
216
  {
@@ -220,8 +226,9 @@ class Zend_Ldap_Attribute
220
  /**
221
  * Converts an LDAP value into its PHP data type
222
  *
223
- * @param string $value
224
- * @return mixed
 
225
  */
226
  public static function convertFromLdapValue($value)
227
  {
@@ -344,12 +351,12 @@ class Zend_Ldap_Attribute
344
  {
345
  foreach ($value as $v) {
346
  $v = self::_valueToLdapDateTime($v, $utc);
347
- if (!is_null($v)) $convertedValues[] = $v;
348
  }
349
  }
350
- else if (!is_null($value)) {
351
  $value = self::_valueToLdapDateTime($value, $utc);
352
- if (!is_null($value)) $convertedValues[] = $value;
353
  }
354
  self::setAttribute($data, $attribName, $convertedValues, $append);
355
  }
@@ -362,8 +369,7 @@ class Zend_Ldap_Attribute
362
  private static function _valueToLdapDateTime($value, $utc)
363
  {
364
  if (is_int($value)) {
365
- if ($utc === true) return gmdate('YmdHis', $value) . 'Z';
366
- else return date('YmdHisO', $value);
367
  }
368
  else return null;
369
  }
@@ -393,31 +399,19 @@ class Zend_Ldap_Attribute
393
  }
394
 
395
  /**
396
- * @param string $value
397
  * @return integer|null
398
  */
399
  private static function _valueFromLdapDateTime($value)
400
  {
401
- $matches = array();
402
- if (preg_match('/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:\.0)?([+-]\d{4}|Z)$/', $value, $matches)) {
403
- $year = $matches[1];
404
- $month = $matches[2];
405
- $day = $matches[3];
406
- $hour = $matches[4];
407
- $minute = $matches[5];
408
- $second = $matches[6];
409
- $timezone = $matches[7];
410
- $date = gmmktime($hour, $minute, $second, $month, $day, $year);
411
- if ($timezone !== 'Z') {
412
- $tzDirection = substr($timezone, 0, 1);
413
- $tzOffsetHour = substr($timezone, 1, 2);
414
- $tzOffsetMinute = substr($timezone, 3, 2);
415
- $tzOffset = ($tzOffsetHour*60*60) + ($tzOffsetMinute*60);
416
- if ($tzDirection == '+') $date -= $tzOffset;
417
- else if ($tzDirection == '-') $date += $tzOffset;
418
  }
419
- return $date;
420
- }
421
- else return null;
422
  }
423
  }
16
  * @package Zend_Ldap
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Attribute.php 22996 2010-09-22 17:01:46Z sgehrig $
20
  */
21
 
22
+ /**
23
+ * @see Zend_Ldap_Converter
24
+ */
25
+ #require_once 'Zend/Ldap/Converter.php';
26
+
27
  /**
28
  * Zend_Ldap_Attribute is a collection of LDAP attribute related functions.
29
  *
58
  foreach ($value as $v)
59
  {
60
  $v = self::_valueToLdap($v);
61
+ if ($v !== null) $valArray[] = $v;
62
  }
63
  }
64
+ else if ($value !== null)
65
  {
66
  $value = self::_valueToLdap($value);
67
+ if ($value !== null) $valArray[] = $value;
68
  }
69
 
70
  if ($append === true && isset($data[$attribName]))
89
  public static function getAttribute(array $data, $attribName, $index = null)
90
  {
91
  $attribName = strtolower($attribName);
92
+ if ($index === null) {
93
  if (!isset($data[$attribName])) return array();
94
  $retArray = array();
95
  foreach ($data[$attribName] as $v)
190
  */
191
  private static function _valueToLdap($value)
192
  {
193
+ return Zend_Ldap_Converter::toLdap($value);
 
 
 
 
 
 
194
  }
195
 
196
  /**
197
  * @param string $value
198
+ * @return mixed
199
  */
200
  private static function _valueFromLdap($value)
201
  {
202
+ try {
203
+ $return = Zend_Ldap_Converter::fromLdap($value, Zend_Ldap_Converter::STANDARD, false);
204
+ if ($return instanceof DateTime) {
205
+ return Zend_Ldap_Converter::toLdapDateTime($return, false);
206
+ } else {
207
+ return $return;
208
+ }
209
+ } catch (InvalidArgumentException $e) {
210
+ return $value;
211
+ }
212
  }
213
 
214
  /**
215
  * Converts a PHP data type into its LDAP representation
216
  *
217
+ * @deprected use Zend_Ldap_Converter instead
218
+ * @param mixed $value
219
+ * @return string|null - null if the PHP data type cannot be converted.
220
  */
221
  public static function convertToLdapValue($value)
222
  {
226
  /**
227
  * Converts an LDAP value into its PHP data type
228
  *
229
+ * @deprected use Zend_Ldap_Converter instead
230
+ * @param string $value
231
+ * @return mixed
232
  */
233
  public static function convertFromLdapValue($value)
234
  {
351
  {
352
  foreach ($value as $v) {
353
  $v = self::_valueToLdapDateTime($v, $utc);
354
+ if ($v !== null) $convertedValues[] = $v;
355
  }
356
  }
357
+ else if ($value !== null) {
358
  $value = self::_valueToLdapDateTime($value, $utc);
359
+ if ($value !== null) $convertedValues[] = $value;
360
  }
361
  self::setAttribute($data, $attribName, $convertedValues, $append);
362
  }
369
  private static function _valueToLdapDateTime($value, $utc)
370
  {
371
  if (is_int($value)) {
372
+ return Zend_Ldap_Converter::toLdapDateTime($value, $utc);
 
373
  }
374
  else return null;
375
  }
399
  }
400
 
401
  /**
402
+ * @param string|DateTime $value
403
  * @return integer|null
404
  */
405
  private static function _valueFromLdapDateTime($value)
406
  {
407
+ if ($value instanceof DateTime) {
408
+ return $value->format('U');
409
+ } else if (is_string($value)) {
410
+ try {
411
+ return Zend_Ldap_Converter::fromLdapDateTime($value, false)->format('U');
412
+ } catch (InvalidArgumentException $e) {
413
+ return null;
 
 
 
 
 
 
 
 
 
 
414
  }
415
+ } else return null;
 
 
416
  }
417
  }
lib/Zend/Ldap/Converter.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Ldap
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Converter.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -29,6 +29,10 @@
29
  */
30
  class Zend_Ldap_Converter
31
  {
 
 
 
 
32
  /**
33
  * Converts all ASCII chars < 32 to "\HEX"
34
  *
@@ -68,4 +72,325 @@ class Zend_Ldap_Converter
68
  $string = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $string);
69
  return $string;
70
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
16
  * @package Zend_Ldap
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Converter.php 22996 2010-09-22 17:01:46Z sgehrig $
20
  */
21
 
22
  /**
29
  */
30
  class Zend_Ldap_Converter
31
  {
32
+ const STANDARD = 0;
33
+ const BOOLEAN = 1;
34
+ const GENERALIZED_TIME = 2;
35
+
36
  /**
37
  * Converts all ASCII chars < 32 to "\HEX"
38
  *
72
  $string = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $string);
73
  return $string;
74
  }
75
+
76
+ /**
77
+ * Convert any value to an LDAP-compatible value.
78
+ *
79
+ * By setting the <var>$type</var>-parameter the conversion of a certain
80
+ * type can be forced
81
+ *
82
+ * @todo write more tests
83
+ *
84
+ * @param mixed $value The value to convert
85
+ * @param int $ytpe The conversion type to use
86
+ * @return string
87
+ * @throws Zend_Ldap_Converter_Exception
88
+ */
89
+ public static function toLdap($value, $type = self::STANDARD)
90
+ {
91
+ try {
92
+ switch ($type) {
93
+ case self::BOOLEAN:
94
+ return self::toldapBoolean($value);
95
+ break;
96
+ case self::GENERALIZED_TIME:
97
+ return self::toLdapDatetime($value);
98
+ break;
99
+ default:
100
+ if (is_string($value)) {
101
+ return $value;
102
+ } else if (is_int($value) || is_float($value)) {
103
+ return (string)$value;
104
+ } else if (is_bool($value)) {
105
+ return self::toldapBoolean($value);
106
+ } else if (is_object($value)) {
107
+ if ($value instanceof DateTime) {
108
+ return self::toLdapDatetime($value);
109
+ } else if ($value instanceof Zend_Date) {
110
+ return self::toLdapDatetime($value);
111
+ } else {
112
+ return self::toLdapSerialize($value);
113
+ }
114
+ } else if (is_array($value)) {
115
+ return self::toLdapSerialize($value);
116
+ } else if (is_resource($value) && get_resource_type($value) === 'stream') {
117
+ return stream_get_contents($value);
118
+ } else {
119
+ return null;
120
+ }
121
+ break;
122
+ }
123
+ } catch (Exception $e) {
124
+ throw new Zend_Ldap_Converter_Exception($e->getMessage(), $e->getCode(), $e);
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Converts a date-entity to an LDAP-compatible date-string
130
+ *
131
+ * The date-entity <var>$date</var> can be either a timestamp, a
132
+ * DateTime Object, a string that is parseable by strtotime() or a Zend_Date
133
+ * Object.
134
+ *
135
+ * @param integer|string|DateTimt|Zend_Date $date The date-entity
136
+ * @param boolean $asUtc Whether to return the LDAP-compatible date-string
137
+ * as UTC or as local value
138
+ * @return string
139
+ * @throws InvalidArgumentException
140
+ */
141
+ public static function toLdapDateTime($date, $asUtc = true)
142
+ {
143
+ if (!($date instanceof DateTime)) {
144
+ if (is_int($date)) {
145
+ $date = new DateTime('@' . $date);
146
+ $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
147
+ } else if (is_string($date)) {
148
+ $date = new DateTime($date);
149
+ } else if ($date instanceof Zend_Date) {
150
+ $date = new DateTime($date->get(Zend_Date::ISO_8601));
151
+ } else {
152
+ throw new InvalidArgumentException('Parameter $date is not of the expected type');
153
+ }
154
+ }
155
+ $timezone = $date->format('O');
156
+ if (true === $asUtc) {
157
+ $date->setTimezone(new DateTimeZone('UTC'));
158
+ $timezone = 'Z';
159
+ }
160
+ if ( '+0000' === $timezone ) {
161
+ $timezone = 'Z';
162
+ }
163
+ return $date->format('YmdHis') . $timezone;
164
+ }
165
+
166
+ /**
167
+ * Convert a boolean value to an LDAP-compatible string
168
+ *
169
+ * This converts a boolean value of TRUE, an integer-value of 1 and a
170
+ * case-insensitive string 'true' to an LDAP-compatible 'TRUE'. All other
171
+ * other values are converted to an LDAP-compatible 'FALSE'.
172
+ *
173
+ * @param boolean|integer|string $value The boolean value to encode
174
+ * @return string
175
+ */
176
+ public static function toLdapBoolean($value)
177
+ {
178
+ $return = 'FALSE';
179
+ if (!is_scalar($value)) {
180
+ return $return;
181
+ }
182
+ if (true === $value || 'true' === strtolower($value) || 1 === $value) {
183
+ $return = 'TRUE';
184
+ }
185
+ return $return;
186
+ }
187
+
188
+ /**
189
+ * Serialize any value for storage in LDAP
190
+ *
191
+ * @param mixed $value The value to serialize
192
+ * @return string
193
+ */
194
+ public static function toLdapSerialize($value)
195
+ {
196
+ return serialize($value);
197
+ }
198
+
199
+ /**
200
+ * Convert an LDAP-compatible value to a corresponding PHP-value.
201
+ *
202
+ * By setting the <var>$type</var>-parameter the conversion of a certain
203
+ * type can be forced
204
+ * .
205
+ * @param string $value The value to convert
206
+ * @param int $ytpe The conversion type to use
207
+ * @param boolean $dateTimeAsUtc Return DateTime values in UTC timezone
208
+ * @return mixed
209
+ * @throws Zend_Ldap_Converter_Exception
210
+ */
211
+ public static function fromLdap($value, $type = self::STANDARD, $dateTimeAsUtc = true)
212
+ {
213
+ switch ($type) {
214
+ case self::BOOLEAN:
215
+ return self::fromldapBoolean($value);
216
+ break;
217
+ case self::GENERALIZED_TIME:
218
+ return self::fromLdapDateTime($value);
219
+ break;
220
+ default:
221
+ if (is_numeric($value)) {
222
+ return (float)$value;
223
+ } else if ('TRUE' === $value || 'FALSE' === $value) {
224
+ return self::fromLdapBoolean($value);
225
+ }
226
+ if (preg_match('/^\d{4}[\d\+\-Z\.]*$/', $value)) {
227
+ return self::fromLdapDateTime($value, $dateTimeAsUtc);
228
+ }
229
+ try {
230
+ return self::fromLdapUnserialize($value);
231
+ } catch (UnexpectedValueException $e) { }
232
+ break;
233
+ }
234
+ return $value;
235
+ }
236
+
237
+ /**
238
+ * Convert an LDAP-Generalized-Time-entry into a DateTime-Object
239
+ *
240
+ * CAVEAT: The DateTime-Object returned will alwasy be set to UTC-Timezone.
241
+ *
242
+ * @param string $date The generalized-Time
243
+ * @param boolean $asUtc Return the DateTime with UTC timezone
244
+ * @return DateTime
245
+ * @throws InvalidArgumentException if a non-parseable-format is given
246
+ */
247
+ public static function fromLdapDateTime($date, $asUtc = true)
248
+ {
249
+ $datepart = array ();
250
+ if (!preg_match('/^(\d{4})/', $date, $datepart) ) {
251
+ throw new InvalidArgumentException('Invalid date format found');
252
+ }
253
+
254
+ if ($datepart[1] < 4) {
255
+ throw new InvalidArgumentException('Invalid date format found (too short)');
256
+ }
257
+
258
+ $time = array (
259
+ // The year is mandatory!
260
+ 'year' => $datepart[1],
261
+ 'month' => 1,
262
+ 'day' => 1,
263
+ 'hour' => 0,
264
+ 'minute' => 0,
265
+ 'second' => 0,
266
+ 'offdir' => '+',
267
+ 'offsethours' => 0,
268
+ 'offsetminutes' => 0
269
+ );
270
+
271
+ $length = strlen($date);
272
+
273
+ // Check for month.
274
+ if ($length >= 6) {
275
+ $month = substr($date, 4, 2);
276
+ if ($month < 1 || $month > 12) {
277
+ throw new InvalidArgumentException('Invalid date format found (invalid month)');
278
+ }
279
+ $time['month'] = $month;
280
+ }
281
+
282
+ // Check for day
283
+ if ($length >= 8) {
284
+ $day = substr($date, 6, 2);
285
+ if ($day < 1 || $day > 31) {
286
+ throw new InvalidArgumentException('Invalid date format found (invalid day)');
287
+ }
288
+ $time['day'] = $day;
289
+ }
290
+
291
+ // Check for Hour
292
+ if ($length >= 10) {
293
+ $hour = substr($date, 8, 2);
294
+ if ($hour < 0 || $hour > 23) {
295
+ throw new InvalidArgumentException('Invalid date format found (invalid hour)');
296
+ }
297
+ $time['hour'] = $hour;
298
+ }
299
+
300
+ // Check for minute
301
+ if ($length >= 12) {
302
+ $minute = substr($date, 10, 2);
303
+ if ($minute < 0 || $minute > 59) {
304
+ throw new InvalidArgumentException('Invalid date format found (invalid minute)');
305
+ }
306
+ $time['minute'] = $minute;
307
+ }
308
+
309
+ // Check for seconds
310
+ if ($length >= 14) {
311
+ $second = substr($date, 12, 2);
312
+ if ($second < 0 || $second > 59) {
313
+ throw new InvalidArgumentException('Invalid date format found (invalid second)');
314
+ }
315
+ $time['second'] = $second;
316
+ }
317
+
318
+ // Set Offset
319
+ $offsetRegEx = '/([Z\-\+])(\d{2}\'?){0,1}(\d{2}\'?){0,1}$/';
320
+ $off = array ();
321
+ if (preg_match($offsetRegEx, $date, $off)) {
322
+ $offset = $off[1];
323
+ if ($offset == '+' || $offset == '-') {
324
+ $time['offdir'] = $offset;
325
+ // we have an offset, so lets calculate it.
326
+ if (isset($off[2])) {
327
+ $offsetHours = substr($off[2], 0, 2);
328
+ if ($offsetHours < 0 || $offsetHours > 12) {
329
+ throw new InvalidArgumentException('Invalid date format found (invalid offset hour)');
330
+ }
331
+ $time['offsethours'] = $offsetHours;
332
+ }
333
+ if (isset($off[3])) {
334
+ $offsetMinutes = substr($off[3], 0, 2);
335
+ if ($offsetMinutes < 0 || $offsetMinutes > 59) {
336
+ throw new InvalidArgumentException('Invalid date format found (invalid offset minute)');
337
+ }
338
+ $time['offsetminutes'] = $offsetMinutes;
339
+ }
340
+ }
341
+ }
342
+
343
+ // Raw-Data is present, so lets create a DateTime-Object from it.
344
+ $offset = $time['offdir']
345
+ . str_pad($time['offsethours'],2,'0',STR_PAD_LEFT)
346
+ . str_pad($time['offsetminutes'],2,'0',STR_PAD_LEFT);
347
+ $timestring = $time['year'] . '-'
348
+ . str_pad($time['month'], 2, '0', STR_PAD_LEFT) . '-'
349
+ . str_pad($time['day'], 2, '0', STR_PAD_LEFT) . ' '
350
+ . str_pad($time['hour'], 2, '0', STR_PAD_LEFT) . ':'
351
+ . str_pad($time['minute'], 2, '0', STR_PAD_LEFT) . ':'
352
+ . str_pad($time['second'], 2, '0', STR_PAD_LEFT)
353
+ . $time['offdir']
354
+ . str_pad($time['offsethours'], 2, '0', STR_PAD_LEFT)
355
+ . str_pad($time['offsetminutes'], 2, '0', STR_PAD_LEFT);
356
+ $date = new DateTime($timestring);
357
+ if ($asUtc) {
358
+ $date->setTimezone(new DateTimeZone('UTC'));
359
+ }
360
+ return $date;
361
+ }
362
+
363
+ /**
364
+ * Convert an LDAP-compatible boolean value into a PHP-compatible one
365
+ *
366
+ * @param string $value The value to convert
367
+ * @return boolean
368
+ * @throws InvalidArgumentException
369
+ */
370
+ public static function fromLdapBoolean($value)
371
+ {
372
+ if ( 'TRUE' === $value ) {
373
+ return true;
374
+ } else if ( 'FALSE' === $value ) {
375
+ return false;
376
+ } else {
377
+ throw new InvalidArgumentException('The given value is not a boolean value');
378
+ }
379
+ }
380
+
381
+ /**
382
+ * Unserialize a serialized value to return the corresponding object
383
+ *
384
+ * @param string $value The value to convert
385
+ * @return mixed
386
+ * @throws UnexpectedValueException
387
+ */
388
+ public static function fromLdapUnserialize($value)
389
+ {
390
+ $v = @unserialize($value);
391
+ if (false===$v && $value != 'b:0;') {
392
+ throw new UnexpectedValueException('The given value could not be unserialized');
393
+ }
394
+ return $v;
395
+ }
396
  }
lib/Zend/Ldap/Converter/Exception.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Ldap
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Exception
24
+ */
25
+ #require_once 'Zend/Exception.php';
26
+
27
+ /**
28
+ * @category Zend
29
+ * @package Zend_Ldap
30
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
+ * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ */
33
+ class Zend_Ldap_Converter_Exception extends Zend_Exception
34
+ {
35
+ }
lib/Zend/Ldap/Dn.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Ldap
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Dn.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -610,8 +610,8 @@ class Zend_Ldap_Dn implements ArrayAccess
610
  $ret[] = array($k[$i] => $v[$i]);
611
  }
612
  }
613
- if (!is_null($keys)) $keys = $k;
614
- if (!is_null($vals)) $vals = $v;
615
  return $ret;
616
  }
617
 
16
  * @package Zend_Ldap
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Dn.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /**
610
  $ret[] = array($k[$i] => $v[$i]);
611
  }
612
  }
613
+ if ($keys !== null) $keys = $k;
614
+ if ($vals !== null) $vals = $v;
615
  return $ret;
616
  }
617
 
lib/Zend/Ldap/Exception.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  /**
4
  * Zend Framework
5
  *
@@ -17,7 +16,7 @@
17
  * @package Zend_Ldap
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
1
  <?php
 
2
  /**
3
  * Zend Framework
4
  *
16
  * @package Zend_Ldap
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Exception.php 22996 2010-09-22 17:01:46Z sgehrig $
20
  */
21
 
22
  /**
lib/Zend/Ldap/Filter.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Filter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Filter.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -242,9 +242,9 @@ class Zend_Ldap_Filter extends Zend_Ldap_Filter_String
242
  private static function _createFilterString($attr, $value, $filtertype, $prepend = null, $append = null)
243
  {
244
  $str = $attr . $filtertype;
245
- if (!is_null($prepend)) $str .= $prepend;
246
  $str .= self::escapeValue($value);
247
- if (!is_null($append)) $str .= $append;
248
  return $str;
249
  }
250
 
17
  * @subpackage Filter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Filter.php 22662 2010-07-24 17:37:36Z mabe $
21
  */
22
 
23
  /**
242
  private static function _createFilterString($attr, $value, $filtertype, $prepend = null, $append = null)
243
  {
244
  $str = $attr . $filtertype;
245
+ if ($prepend !== null) $str .= $prepend;
246
  $str .= self::escapeValue($value);
247
+ if ($append !== null) $str .= $append;
248
  return $str;
249
  }
250
 
lib/Zend/Ldap/Ldif/Encoder.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Ldif
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Encoder.php 21007 2010-02-09 13:40:16Z sgehrig $
21
  */
22
 
23
  /**
17
  * @subpackage Ldif
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Encoder.php 21005 2010-02-09 13:16:26Z sgehrig $
21
  */
22
 
23
  /**
lib/Zend/Ldap/Node.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Node
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Node.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -99,7 +99,7 @@ class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, Recurs
99
  protected function __construct(Zend_Ldap_Dn $dn, array $data, $fromDataSource, Zend_Ldap $ldap = null)
100
  {
101
  parent::__construct($dn, $data, $fromDataSource);
102
- if (!is_null($ldap)) $this->attachLdap($ldap);
103
  else $this->detachLdap();
104
  }
105
 
@@ -136,7 +136,7 @@ class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, Recurs
136
  */
137
  public function getLdap()
138
  {
139
- if (is_null($this->_ldap)) {
140
  /**
141
  * @see Zend_Ldap_Exception
142
  */
@@ -205,7 +205,7 @@ class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, Recurs
205
  */
206
  public function isAttached()
207
  {
208
- return (!is_null($this->_ldap));
209
  }
210
 
211
  /**
17
  * @subpackage Node
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Node.php 22662 2010-07-24 17:37:36Z mabe $
21
  */
22
 
23
  /**
99
  protected function __construct(Zend_Ldap_Dn $dn, array $data, $fromDataSource, Zend_Ldap $ldap = null)
100
  {
101
  parent::__construct($dn, $data, $fromDataSource);
102
+ if ($ldap !== null) $this->attachLdap($ldap);
103
  else $this->detachLdap();
104
  }
105
 
136
  */
137
  public function getLdap()
138
  {
139
+ if ($this->_ldap === null) {
140
  /**
141
  * @see Zend_Ldap_Exception
142
  */
205
  */
206
  public function isAttached()
207
  {
208
+ return ($this->_ldap !== null);
209
  }
210
 
211
  /**
lib/Zend/Loader.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Loader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Loader.php 22020 2010-04-27 16:35:56Z matthew $
20
  */
21
 
22
  /**
16
  * @package Zend_Loader
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Loader.php 22019 2010-04-27 16:33:31Z matthew $
20
  */
21
 
22
  /**
lib/Zend/Loader/Autoloader.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Loader
17
  * @subpackage Autoloader
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
- * @version $Id: Autoloader.php 22480 2010-06-21 17:37:20Z matthew $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
@@ -560,7 +560,7 @@ class Zend_Loader_Autoloader
560
  $versionLen = strlen($version);
561
  $versions = array();
562
  $dirs = glob("$path/*", GLOB_ONLYDIR);
563
- foreach ($dirs as $dir) {
564
  $dirName = substr($dir, strlen($path) + 1);
565
  if (!preg_match('/^(?:ZendFramework-)?(\d+\.\d+\.\d+((a|b|pl|pr|p|rc)\d+)?)(?:-minimal)?$/i', $dirName, $matches)) {
566
  continue;
16
  * @package Zend_Loader
17
  * @subpackage Autoloader
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @version $Id: Autoloader.php 23161 2010-10-19 16:08:36Z matthew $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
560
  $versionLen = strlen($version);
561
  $versions = array();
562
  $dirs = glob("$path/*", GLOB_ONLYDIR);
563
+ foreach ((array) $dirs as $dir) {
564
  $dirName = substr($dir, strlen($path) + 1);
565
  if (!preg_match('/^(?:ZendFramework-)?(\d+\.\d+\.\d+((a|b|pl|pr|p|rc)\d+)?)(?:-minimal)?$/i', $dirName, $matches)) {
566
  continue;
lib/Zend/Loader/Autoloader/Interface.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Loader
17
  * @subpackage Autoloader
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
- * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
@@ -30,5 +30,14 @@
30
  */
31
  interface Zend_Loader_Autoloader_Interface
32
  {
 
 
 
 
 
 
 
 
 
33
  public function autoload($class);
34
  }
16
  * @package Zend_Loader
17
  * @subpackage Autoloader
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @version $Id: Interface.php 22913 2010-08-29 00:28:02Z ramon $
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
  */
22
 
30
  */
31
  interface Zend_Loader_Autoloader_Interface
32
  {
33
+ /**
34
+ * Autoload a class
35
+ *
36
+ * @abstract
37
+ * @param string $class
38
+ * @return mixed
39
+ * False [if unable to load $class]
40
+ * get_class($class) [if $class is successfully loaded]
41
+ */
42
  public function autoload($class);
43
  }
lib/Zend/Loader/PluginLoader.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage PluginLoader
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: PluginLoader.php 22604 2010-07-17 00:14:06Z ramon $
21
  */
22
 
23
  /** Zend_Loader_PluginLoader_Interface */
17
  * @subpackage PluginLoader
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: PluginLoader.php 22603 2010-07-17 00:02:10Z ramon $
21
  */
22
 
23
  /** Zend_Loader_PluginLoader_Interface */
lib/Zend/Log.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Log
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Log.php 22632 2010-07-18 18:30:08Z ramon $
20
  */
21
 
22
  /**
@@ -24,7 +24,7 @@
24
  * @package Zend_Log
25
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
26
  * @license http://framework.zend.com/license/new-bsd New BSD License
27
- * @version $Id: Log.php 22632 2010-07-18 18:30:08Z ramon $
28
  */
29
  class Zend_Log
30
  {
@@ -70,6 +70,29 @@ class Zend_Log
70
  */
71
  protected $_defaultFilterNamespace = 'Zend_Log_Filter';
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  /**
75
  * Class constructor. Create a new logger
@@ -105,7 +128,7 @@ class Zend_Log
105
  throw new Zend_Log_Exception('Configuration must be an array or instance of Zend_Config');
106
  }
107
 
108
- $log = new Zend_Log;
109
 
110
  if (!is_array(current($config))) {
111
  $log->addWriter(current($config));
@@ -232,6 +255,25 @@ class Zend_Log
232
  return $fullClassName;
233
  }
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  /**
236
  * Class destructor. Shutdown log writers
237
  *
@@ -306,11 +348,7 @@ class Zend_Log
306
  }
307
 
308
  // pack into event required by filters and writers
309
- $event = array_merge(array('timestamp' => date('c'),
310
- 'message' => $message,
311
- 'priority' => $priority,
312
- 'priorityName' => $this->_priorities[$priority]),
313
- $this->_extras);
314
 
315
  // Check to see if any extra information was passed
316
  if (!empty($extras)) {
@@ -364,6 +402,7 @@ class Zend_Log
364
  }
365
 
366
  $this->_priorities[$priority] = $name;
 
367
  }
368
 
369
  /**
@@ -391,6 +430,7 @@ class Zend_Log
391
  }
392
 
393
  $this->_filters[] = $filter;
 
394
  }
395
 
396
  /**
@@ -416,6 +456,7 @@ class Zend_Log
416
  }
417
 
418
  $this->_writers[] = $writer;
 
419
  }
420
 
421
  /**
@@ -428,5 +469,108 @@ class Zend_Log
428
  public function setEventItem($name, $value)
429
  {
430
  $this->_extras = array_merge($this->_extras, array($name => $value));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431
  }
432
  }
16
  * @package Zend_Log
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Log.php 22976 2010-09-19 11:57:26Z intiilapa $
20
  */
21
 
22
  /**
24
  * @package Zend_Log
25
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
26
  * @license http://framework.zend.com/license/new-bsd New BSD License
27
+ * @version $Id: Log.php 22976 2010-09-19 11:57:26Z intiilapa $
28
  */
29
  class Zend_Log
30
  {
70
  */
71
  protected $_defaultFilterNamespace = 'Zend_Log_Filter';
72
 
73
+ /**
74
+ *
75
+ * @var callback
76
+ */
77
+ protected $_origErrorHandler = null;
78
+
79
+ /**
80
+ *
81
+ * @var boolean
82
+ */
83
+ protected $_registeredErrorHandler = false;
84
+
85
+ /**
86
+ *
87
+ * @var array
88
+ */
89
+ protected $_errorHandlerMap = false;
90
+
91
+ /**
92
+ *
93
+ * @var string
94
+ */
95
+ protected $_timestampFormat = 'c';
96
 
97
  /**
98
  * Class constructor. Create a new logger
128
  throw new Zend_Log_Exception('Configuration must be an array or instance of Zend_Config');
129
  }
130
 
131
+ $log = new self;
132
 
133
  if (!is_array(current($config))) {
134
  $log->addWriter(current($config));
255
  return $fullClassName;
256
  }
257
 
258
+ /**
259
+ * Packs message and priority into Event array
260
+ *
261
+ * @param string $message Message to log
262
+ * @param integer $priority Priority of message
263
+ * @return array Event array
264
+ **/
265
+ protected function _packEvent($message, $priority)
266
+ {
267
+ return array_merge(array(
268
+ 'timestamp' => date($this->_timestampFormat),
269
+ 'message' => $message,
270
+ 'priority' => $priority,
271
+ 'priorityName' => $this->_priorities[$priority]
272
+ ),
273
+ $this->_extras
274
+ );
275
+ }
276
+
277
  /**
278
  * Class destructor. Shutdown log writers
279
  *
348
  }
349
 
350
  // pack into event required by filters and writers
351
+ $event = $this->_packEvent($message, $priority);
 
 
 
 
352
 
353
  // Check to see if any extra information was passed
354
  if (!empty($extras)) {
402
  }
403
 
404
  $this->_priorities[$priority] = $name;
405
+ return $this;
406
  }
407
 
408
  /**
430
  }
431
 
432
  $this->_filters[] = $filter;
433
+ return $this;
434
  }
435
 
436
  /**
456
  }
457
 
458
  $this->_writers[] = $writer;
459
+ return $this;
460
  }
461
 
462
  /**
469
  public function setEventItem($name, $value)
470
  {
471
  $this->_extras = array_merge($this->_extras, array($name => $value));
472
+ return $this;
473
+ }
474
+
475
+ /**
476
+ * Register Logging system as an error handler to log php errors
477
+ * Note: it still calls the original error handler if set_error_handler is able to return it.
478
+ *
479
+ * Errors will be mapped as:
480
+ * E_NOTICE, E_USER_NOTICE => NOTICE
481
+ * E_WARNING, E_CORE_WARNING, E_USER_WARNING => WARN
482
+ * E_ERROR, E_USER_ERROR, E_CORE_ERROR, E_RECOVERABLE_ERROR => ERR
483
+ * E_DEPRECATED, E_STRICT, E_USER_DEPRECATED => DEBUG
484
+ * (unknown/other) => INFO
485
+ *
486
+ * @link http://www.php.net/manual/en/function.set-error-handler.php Custom error handler
487
+ *
488
+ * @return Zend_Log
489
+ */
490
+ public function registerErrorHandler()
491
+ {
492
+ // Only register once. Avoids loop issues if it gets registered twice.
493
+ if ($this->_registeredErrorHandler) {
494
+ return $this;
495
+ }
496
+
497
+ $this->_origErrorHandler = set_error_handler(array($this, 'errorHandler'));
498
+
499
+ // Contruct a default map of phpErrors to Zend_Log priorities.
500
+ // Some of the errors are uncatchable, but are included for completeness
501
+ $this->_errorHandlerMap = array(
502
+ E_NOTICE => Zend_Log::NOTICE,
503
+ E_USER_NOTICE => Zend_Log::NOTICE,
504
+ E_WARNING => Zend_Log::WARN,
505
+ E_CORE_WARNING => Zend_Log::WARN,
506
+ E_USER_WARNING => Zend_Log::WARN,
507
+ E_ERROR => Zend_Log::ERR,
508
+ E_USER_ERROR => Zend_Log::ERR,
509
+ E_CORE_ERROR => Zend_Log::ERR,
510
+ E_RECOVERABLE_ERROR => Zend_Log::ERR,
511
+ E_STRICT => Zend_Log::DEBUG,
512
+ );
513
+ // PHP 5.3.0+
514
+ if (defined('E_DEPRECATED')) {
515
+ $this->_errorHandlerMap['E_DEPRECATED'] = Zend_Log::DEBUG;
516
+ }
517
+ if (defined('E_USER_DEPRECATED')) {
518
+ $this->_errorHandlerMap['E_USER_DEPRECATED'] = Zend_Log::DEBUG;
519
+ }
520
+
521
+ $this->_registeredErrorHandler = true;
522
+ return $this;
523
+ }
524
+
525
+ /**
526
+ * Error Handler will convert error into log message, and then call the original error handler
527
+ *
528
+ * @link http://www.php.net/manual/en/function.set-error-handler.php Custom error handler
529
+ * @param int $errno
530
+ * @param string $errstr
531
+ * @param string $errfile
532
+ * @param int $errline
533
+ * @param array $errcontext
534
+ * @return boolean
535
+ */
536
+ public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
537
+ {
538
+ $errorLevel = error_reporting();
539
+
540
+ if ($errorLevel && $errno) {
541
+ if (isset($this->_errorHandlerMap[$errno])) {
542
+ $priority = $this->_errorHandlerMap[$errno];
543
+ } else {
544
+ $priority = Zend_Log::INFO;
545
+ }
546
+ $this->log($errstr, $priority, array('errno'=>$errno, 'file'=>$errfile, 'line'=>$errline, 'context'=>$errcontext));
547
+ }
548
+
549
+ if ($this->_origErrorHandler !== null) {
550
+ return call_user_func($this->_origErrorHandler, $errno, $errstr, $errfile, $errline, $errcontext);
551
+ }
552
+ return false;
553
+ }
554
+
555
+ /**
556
+ * Set timestamp format for log entries.
557
+ *
558
+ * @param string $format
559
+ * @return Zend_Log
560
+ */
561
+ public function setTimestampFormat($format)
562
+ {
563
+ $this->_timestampFormat = $format;
564
+ return $this;
565
+ }
566
+
567
+ /**
568
+ * Get timestamp format used for log entries.
569
+ *
570
+ * @return string
571
+ */
572
+ public function getTimestampFormat()
573
+ {
574
+ return $this->_timestampFormat;
575
  }
576
  }
lib/Zend/Log/FactoryInterface.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Log
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id$
20
  */
21
 
22
  /**
@@ -24,7 +24,7 @@
24
  * @package Zend_Log
25
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
26
  * @license http://framework.zend.com/license/new-bsd New BSD License
27
- * @version $Id$
28
  */
29
  interface Zend_Log_FactoryInterface
30
  {
16
  * @package Zend_Log
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: FactoryInterface.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  /**
24
  * @package Zend_Log
25
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
26
  * @license http://framework.zend.com/license/new-bsd New BSD License
27
+ * @version $Id: FactoryInterface.php 20785 2010-01-31 09:43:03Z mikaelkael $
28
  */
29
  interface Zend_Log_FactoryInterface
30
  {
lib/Zend/Log/Filter/Abstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id$
21
  */
22
 
23
  /** @see Zend_Log_Filter_Interface */
@@ -29,10 +29,10 @@
29
  /**
30
  * @category Zend
31
  * @package Zend_Log
32
- * @subpackage Writer
33
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
  * @license http://framework.zend.com/license/new-bsd New BSD License
35
- * @version $Id$
36
  */
37
  abstract class Zend_Log_Filter_Abstract
38
  implements Zend_Log_Filter_Interface, Zend_Log_FactoryInterface
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Abstract.php 21892 2010-04-16 19:15:20Z juokaz $
21
  */
22
 
23
  /** @see Zend_Log_Filter_Interface */
29
  /**
30
  * @category Zend
31
  * @package Zend_Log
32
+ * @subpackage Filter
33
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
  * @license http://framework.zend.com/license/new-bsd New BSD License
35
+ * @version $Id: Abstract.php 21892 2010-04-16 19:15:20Z juokaz $
36
  */
37
  abstract class Zend_Log_Filter_Abstract
38
  implements Zend_Log_Filter_Interface, Zend_Log_FactoryInterface
lib/Zend/Log/Filter/Message.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Filter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Message.php 20982 2010-02-08 15:51:36Z matthew $
21
  */
22
 
23
  /** Zend_Log_Filter_Abstract */
@@ -29,7 +29,7 @@
29
  * @subpackage Filter
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
- * @version $Id: Message.php 20982 2010-02-08 15:51:36Z matthew $
33
  */
34
  class Zend_Log_Filter_Message extends Zend_Log_Filter_Abstract
35
  {
17
  * @subpackage Filter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Message.php 20981 2010-02-08 15:51:02Z matthew $
21
  */
22
 
23
  /** Zend_Log_Filter_Abstract */
29
  * @subpackage Filter
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ * @version $Id: Message.php 20981 2010-02-08 15:51:02Z matthew $
33
  */
34
  class Zend_Log_Filter_Message extends Zend_Log_Filter_Abstract
35
  {
lib/Zend/Log/Filter/Priority.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Filter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Priority.php 20260 2010-01-13 18:29:22Z ralph $
21
  */
22
 
23
  /** Zend_Log_Filter_Abstract */
@@ -29,7 +29,7 @@
29
  * @subpackage Filter
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
- * @version $Id: Priority.php 20260 2010-01-13 18:29:22Z ralph $
33
  */
34
  class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract
35
  {
@@ -59,7 +59,7 @@ class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract
59
  }
60
 
61
  $this->_priority = $priority;
62
- $this->_operator = is_null($operator) ? '<=' : $operator;
63
  }
64
 
65
  /**
17
  * @subpackage Filter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Priority.php 22662 2010-07-24 17:37:36Z mabe $
21
  */
22
 
23
  /** Zend_Log_Filter_Abstract */
29
  * @subpackage Filter
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ * @version $Id: Priority.php 22662 2010-07-24 17:37:36Z mabe $
33
  */
34
  class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract
35
  {
59
  }
60
 
61
  $this->_priority = $priority;
62
+ $this->_operator = $operator === null ? '<=' : $operator;
63
  }
64
 
65
  /**
lib/Zend/Log/Filter/Suppress.php CHANGED
@@ -17,11 +17,11 @@
17
  * @subpackage Filter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /** Zend_Log_Filter_Interface */
24
- #require_once 'Zend/Log/Filter/Interface.php';
25
 
26
  /**
27
  * @category Zend
@@ -29,7 +29,7 @@
29
  * @subpackage Filter
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
- * @version $Id: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $
33
  */
34
  class Zend_Log_Filter_Suppress extends Zend_Log_Filter_Abstract
35
  {
@@ -65,7 +65,7 @@ class Zend_Log_Filter_Suppress extends Zend_Log_Filter_Abstract
65
 
66
  /**
67
  * Create a new instance of Zend_Log_Filter_Suppress
68
- *
69
  * @param array|Zend_Config $config
70
  * @return Zend_Log_Filter_Suppress
71
  * @throws Zend_Log_Exception
17
  * @subpackage Filter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Suppress.php 22977 2010-09-19 12:44:00Z intiilapa $
21
  */
22
 
23
  /** Zend_Log_Filter_Interface */
24
+ #require_once 'Zend/Log/Filter/Abstract.php';
25
 
26
  /**
27
  * @category Zend
29
  * @subpackage Filter
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ * @version $Id: Suppress.php 22977 2010-09-19 12:44:00Z intiilapa $
33
  */
34
  class Zend_Log_Filter_Suppress extends Zend_Log_Filter_Abstract
35
  {
65
 
66
  /**
67
  * Create a new instance of Zend_Log_Filter_Suppress
68
+ *
69
  * @param array|Zend_Config $config
70
  * @return Zend_Log_Filter_Suppress
71
  * @throws Zend_Log_Exception
lib/Zend/Log/Writer/Abstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Abstract.php 22632 2010-07-18 18:30:08Z ramon $
21
  */
22
 
23
  /** Zend_Log_Filter_Priority */
@@ -29,7 +29,7 @@
29
  * @subpackage Writer
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
- * @version $Id: Abstract.php 22632 2010-07-18 18:30:08Z ramon $
33
  */
34
  abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface
35
  {
@@ -63,6 +63,7 @@ abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface
63
  }
64
 
65
  $this->_filters[] = $filter;
 
66
  }
67
 
68
  /**
@@ -92,6 +93,7 @@ abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface
92
  public function setFormatter(Zend_Log_Formatter_Interface $formatter)
93
  {
94
  $this->_formatter = $formatter;
 
95
  }
96
 
97
  /**
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Abstract.php 22567 2010-07-16 03:32:31Z ramon $
21
  */
22
 
23
  /** Zend_Log_Filter_Priority */
29
  * @subpackage Writer
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ * @version $Id: Abstract.php 22567 2010-07-16 03:32:31Z ramon $
33
  */
34
  abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface
35
  {
63
  }
64
 
65
  $this->_filters[] = $filter;
66
+ return $this;
67
  }
68
 
69
  /**
93
  public function setFormatter(Zend_Log_Formatter_Interface $formatter)
94
  {
95
  $this->_formatter = $formatter;
96
+ return $this;
97
  }
98
 
99
  /**
lib/Zend/Log/Writer/Db.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Db.php 22514 2010-07-01 14:11:18Z ramon $
21
  */
22
 
23
  /** Zend_Log_Writer_Abstract */
@@ -29,7 +29,7 @@
29
  * @subpackage Writer
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
- * @version $Id: Db.php 22514 2010-07-01 14:11:18Z ramon $
33
  */
34
  class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract
35
  {
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Db.php 22513 2010-07-01 13:48:39Z ramon $
21
  */
22
 
23
  /** Zend_Log_Writer_Abstract */
29
  * @subpackage Writer
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ * @version $Id: Db.php 22513 2010-07-01 13:48:39Z ramon $
33
  */
34
  class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract
35
  {
lib/Zend/Log/Writer/Firebug.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Firebug.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /** Zend_Log */
@@ -195,6 +195,7 @@ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract
195
  Zend_Wildfire_Plugin_FirePhp::getInstance()->send($message,
196
  $label,
197
  $type,
198
- array('traceOffset'=>6));
 
199
  }
200
  }
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Firebug.php 23066 2010-10-09 23:29:20Z cadorn $
21
  */
22
 
23
  /** Zend_Log */
195
  Zend_Wildfire_Plugin_FirePhp::getInstance()->send($message,
196
  $label,
197
  $type,
198
+ array('traceOffset'=>4,
199
+ 'fixZendLogOffsetIfApplicable'=>true));
200
  }
201
  }
lib/Zend/Log/Writer/Mail.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Mail.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /** Zend_Log_Writer_Abstract */
@@ -41,7 +41,7 @@
41
  * @subpackage Writer
42
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
43
  * @license http://framework.zend.com/license/new-bsd New BSD License
44
- * @version $Id: Mail.php 20096 2010-01-06 02:05:09Z bkarwin $
45
  */
46
  class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract
47
  {
@@ -100,6 +100,18 @@ class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract
100
  */
101
  protected $_subjectPrependText;
102
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  /**
104
  * Class constructor.
105
  *
@@ -113,21 +125,129 @@ class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract
113
  */
114
  public function __construct(Zend_Mail $mail, Zend_Layout $layout = null)
115
  {
116
- $this->_mail = $mail;
117
- $this->_layout = $layout;
 
 
118
  $this->_formatter = new Zend_Log_Formatter_Simple();
119
  }
120
-
121
  /**
122
  * Create a new instance of Zend_Log_Writer_Mail
123
- *
124
  * @param array|Zend_Config $config
125
  * @return Zend_Log_Writer_Mail
126
- * @throws Zend_Log_Exception
127
  */
128
  static public function factory($config)
129
  {
130
- throw new Zend_Exception('Zend_Log_Writer_Mail does not currently implement a factory');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  }
132
 
133
  /**
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Mail.php 22971 2010-09-18 20:32:24Z mikaelkael $
21
  */
22
 
23
  /** Zend_Log_Writer_Abstract */
41
  * @subpackage Writer
42
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
43
  * @license http://framework.zend.com/license/new-bsd New BSD License
44
+ * @version $Id: Mail.php 22971 2010-09-18 20:32:24Z mikaelkael $
45
  */
46
  class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract
47
  {
100
  */
101
  protected $_subjectPrependText;
102
 
103
+ /**
104
+ * MethodMap for Zend_Mail's headers
105
+ *
106
+ * @var array
107
+ */
108
+ protected static $_methodMapHeaders = array(
109
+ 'from' => 'setFrom',
110
+ 'to' => 'addTo',
111
+ 'cc' => 'addCc',
112
+ 'bcc' => 'addBcc',
113
+ );
114
+
115
  /**
116
  * Class constructor.
117
  *
125
  */
126
  public function __construct(Zend_Mail $mail, Zend_Layout $layout = null)
127
  {
128
+ $this->_mail = $mail;
129
+ if (null !== $layout) {
130
+ $this->setLayout($layout);
131
+ }
132
  $this->_formatter = new Zend_Log_Formatter_Simple();
133
  }
134
+
135
  /**
136
  * Create a new instance of Zend_Log_Writer_Mail
137
+ *
138
  * @param array|Zend_Config $config
139
  * @return Zend_Log_Writer_Mail
 
140
  */
141
  static public function factory($config)
142
  {
143
+ $config = self::_parseConfig($config);
144
+ $mail = self::_constructMailFromConfig($config);
145
+ $writer = new self($mail);
146
+
147
+ if (isset($config['layout']) || isset($config['layoutOptions'])) {
148
+ $writer->setLayout($config);
149
+ }
150
+ if (isset($config['layoutFormatter'])) {
151
+ $layoutFormatter = new $config['layoutFormatter'];
152
+ $writer->setLayoutFormatter($layoutFormatter);
153
+ }
154
+ if (isset($config['subjectPrependText'])) {
155
+ $writer->setSubjectPrependText($config['subjectPrependText']);
156
+ }
157
+
158
+ return $writer;
159
+ }
160
+
161
+ /**
162
+ * Set the layout
163
+ *
164
+ * @param Zend_Layout|array $layout
165
+ * @return Zend_Log_Writer_Mail
166
+ * @throws Zend_Log_Exception
167
+ */
168
+ public function setLayout($layout)
169
+ {
170
+ if (is_array($layout)) {
171
+ $layout = $this->_constructLayoutFromConfig($layout);
172
+ }
173
+
174
+ if (!$layout instanceof Zend_Layout) {
175
+ #require_once 'Zend/Log/Exception.php';
176
+ throw new Zend_Log_Exception('Mail must be an instance of Zend_Layout or an array');
177
+ }
178
+ $this->_layout = $layout;
179
+
180
+ return $this;
181
+ }
182
+
183
+ /**
184
+ * Construct a Zend_Mail instance based on a configuration array
185
+ *
186
+ * @param array $config
187
+ * @return Zend_Mail
188
+ */
189
+ protected static function _constructMailFromConfig(array $config)
190
+ {
191
+ $mailClass = 'Zend_Mail';
192
+ if (isset($config['mail'])) {
193
+ $mailClass = $config['mail'];
194
+ }
195
+
196
+ if (!array_key_exists('charset', $config)) {
197
+ $config['charset'] = null;
198
+ }
199
+ $mail = new $mailClass($config['charset']);
200
+ if (!$mail instanceof Zend_Mail) {
201
+ throw new Zend_Log_Exception($mail . 'must extend Zend_Mail');
202
+ }
203
+
204
+ if (isset($config['subject'])) {
205
+ $mail->setSubject($config['subject']);
206
+ }
207
+
208
+ $headerAddresses = array_intersect_key($config, self::$_methodMapHeaders);
209
+ if (count($headerAddresses)) {
210
+ foreach ($headerAddresses as $header => $address) {
211
+ $method = self::$_methodMapHeaders[$header];
212
+ if (is_array($address) && isset($address['name'])
213
+ && !is_numeric($address['name'])
214
+ ) {
215
+ $params = array(
216
+ $address['email'],
217
+ $address['name']
218
+ );
219
+ } else if (is_array($address) && isset($address['email'])) {
220
+ $params = array($address['email']);
221
+ } else {
222
+ $params = array($address);
223
+ }
224
+ call_user_func_array(array($mail, $method), $params);
225
+ }
226
+ }
227
+
228
+ return $mail;
229
+ }
230
+
231
+ /**
232
+ * Construct a Zend_Layout instance based on a configuration array
233
+ *
234
+ * @param array $config
235
+ * @return Zend_Layout
236
+ */
237
+ protected function _constructLayoutFromConfig(array $config)
238
+ {
239
+ $config = array_merge(array(
240
+ 'layout' => 'Zend_Layout',
241
+ 'layoutOptions' => null
242
+ ), $config);
243
+
244
+ $layoutClass = $config['layout'];
245
+ $layout = new $layoutClass($config['layoutOptions']);
246
+ if (!$layout instanceof Zend_Layout) {
247
+ throw new Zend_Log_Exception($layout . 'must extend Zend_Layout');
248
+ }
249
+
250
+ return $layout;
251
  }
252
 
253
  /**
lib/Zend/Log/Writer/Syslog.php CHANGED
@@ -17,9 +17,12 @@
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Syslog.php 22632 2010-07-18 18:30:08Z ramon $
21
  */
22
 
 
 
 
23
  /** Zend_Log_Writer_Abstract */
24
  #require_once 'Zend/Log/Writer/Abstract.php';
25
 
@@ -179,7 +182,7 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract
179
  public function setFacility($facility)
180
  {
181
  if ($this->_facility === $facility) {
182
- return;
183
  }
184
 
185
  if (!count($this->_validFacilities)) {
@@ -200,6 +203,7 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract
200
 
201
  $this->_facility = $facility;
202
  $this->_initializeSyslog();
 
203
  }
204
 
205
  /**
@@ -211,10 +215,11 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract
211
  public function setApplicationName($application)
212
  {
213
  if ($this->_application === $application) {
214
- return;
215
  }
216
  $this->_application = $application;
217
  $this->_initializeSyslog();
 
218
  }
219
 
220
  /**
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Syslog.php 22977 2010-09-19 12:44:00Z intiilapa $
21
  */
22
 
23
+ /** Zend_Log */
24
+ #require_once 'Zend/Log.php';
25
+
26
  /** Zend_Log_Writer_Abstract */
27
  #require_once 'Zend/Log/Writer/Abstract.php';
28
 
182
  public function setFacility($facility)
183
  {
184
  if ($this->_facility === $facility) {
185
+ return $this;
186
  }
187
 
188
  if (!count($this->_validFacilities)) {
203
 
204
  $this->_facility = $facility;
205
  $this->_initializeSyslog();
206
+ return $this;
207
  }
208
 
209
  /**
215
  public function setApplicationName($application)
216
  {
217
  if ($this->_application === $application) {
218
+ return $this;
219
  }
220
  $this->_application = $application;
221
  $this->_initializeSyslog();
222
+ return $this;
223
  }
224
 
225
  /**
lib/Zend/Log/Writer/ZendMonitor.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: ZendMonitor.php 22533 2010-07-07 02:38:14Z ramon $
21
  */
22
 
23
  /** Zend_Log_Writer_Abstract */
@@ -29,7 +29,7 @@
29
  * @subpackage Writer
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
- * @version $Id: ZendMonitor.php 22533 2010-07-07 02:38:14Z ramon $
33
  */
34
  class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract
35
  {
@@ -39,6 +39,12 @@ class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract
39
  */
40
  protected $_isEnabled = true;
41
 
 
 
 
 
 
 
42
  /**
43
  * @throws Zend_Log_Exception if Zend Monitor extension not present
44
  */
@@ -47,6 +53,9 @@ class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract
47
  if (!function_exists('monitor_custom_event')) {
48
  $this->_isEnabled = false;
49
  }
 
 
 
50
  }
51
 
52
  /**
@@ -103,7 +112,17 @@ class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract
103
  unset($event['priority'], $event['message']);
104
 
105
  if (!empty($event)) {
106
- monitor_custom_event($priority, $message, false, $event);
 
 
 
 
 
 
 
 
 
 
107
  } else {
108
  monitor_custom_event($priority, $message);
109
  }
17
  * @subpackage Writer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: ZendMonitor.php 23351 2010-11-16 18:09:45Z matthew $
21
  */
22
 
23
  /** Zend_Log_Writer_Abstract */
29
  * @subpackage Writer
30
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31
  * @license http://framework.zend.com/license/new-bsd New BSD License
32
+ * @version $Id: ZendMonitor.php 23351 2010-11-16 18:09:45Z matthew $
33
  */
34
  class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract
35
  {
39
  */
40
  protected $_isEnabled = true;
41
 
42
+ /**
43
+ * Is this for a Zend Server intance?
44
+ * @var bool
45
+ */
46
+ protected $_isZendServer = false;
47
+
48
  /**
49
  * @throws Zend_Log_Exception if Zend Monitor extension not present
50
  */
53
  if (!function_exists('monitor_custom_event')) {
54
  $this->_isEnabled = false;
55
  }
56
+ if (function_exists('zend_monitor_custom_event')) {
57
+ $this->_isZendServer = true;
58
+ }
59
  }
60
 
61
  /**
112
  unset($event['priority'], $event['message']);
113
 
114
  if (!empty($event)) {
115
+ if ($this->_isZendServer) {
116
+ // On Zend Server; third argument should be the event
117
+ zend_monitor_custom_event($priority, $message, $event);
118
+ } else {
119
+ // On Zend Platform; third argument is severity -- either
120
+ // 0 or 1 -- and fourth is optional (event)
121
+ // Severity is either 0 (normal) or 1 (severe); classifying
122
+ // notice, info, and debug as "normal", and all others as
123
+ // "severe"
124
+ monitor_custom_event($priority, $message, ($priority > 4) ? 0 : 1, $event);
125
+ }
126
  } else {
127
  monitor_custom_event($priority, $message);
128
  }
lib/Zend/Mail.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Mail
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Mail.php 20783 2010-01-31 08:06:30Z yoshida@zend.co.jp $
20
  */
21
 
22
 
@@ -77,7 +77,7 @@ class Zend_Mail extends Zend_Mime_Message
77
  * Mail character set
78
  * @var string
79
  */
80
- protected $_charset = null;
81
 
82
  /**
83
  * Mail headers
@@ -208,11 +208,14 @@ class Zend_Mail extends Zend_Mime_Message
208
  /**
209
  * Public constructor
210
  *
211
- * @param string $charset
 
212
  */
213
- public function __construct($charset = 'iso-8859-1')
214
  {
215
- $this->_charset = $charset;
 
 
216
  }
217
 
218
  /**
@@ -535,12 +538,11 @@ class Zend_Mail extends Zend_Mime_Message
535
  * Clear header from the message
536
  *
537
  * @param string $headerName
 
538
  */
539
  protected function _clearHeader($headerName)
540
  {
541
- if (isset($this->_headers[$headerName])){
542
- unset($this->_headers[$headerName]);
543
- }
544
  }
545
 
546
  /**
@@ -629,6 +631,20 @@ class Zend_Mail extends Zend_Mime_Message
629
  return array_keys($this->_recipients);
630
  }
631
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
632
  /**
633
  * Clears list of recipient email addresses
634
  *
@@ -639,9 +655,9 @@ class Zend_Mail extends Zend_Mime_Message
639
  $this->_recipients = array();
640
  $this->_to = array();
641
 
642
- $this->_clearHeader('To');
643
- $this->_clearHeader('Cc');
644
- $this->_clearHeader('Bcc');
645
 
646
  return $this;
647
  }
@@ -726,7 +742,7 @@ class Zend_Mail extends Zend_Mime_Message
726
  public function clearFrom()
727
  {
728
  $this->_from = null;
729
- $this->_clearHeader('From');
730
 
731
  return $this;
732
  }
@@ -739,7 +755,7 @@ class Zend_Mail extends Zend_Mime_Message
739
  public function clearReplyTo()
740
  {
741
  $this->_replyTo = null;
742
- $this->_clearHeader('Reply-To');
743
 
744
  return $this;
745
  }
@@ -891,7 +907,7 @@ class Zend_Mail extends Zend_Mime_Message
891
  public function clearReturnPath()
892
  {
893
  $this->_returnPath = null;
894
- $this->_clearHeader('Return-Path');
895
 
896
  return $this;
897
  }
@@ -937,7 +953,7 @@ class Zend_Mail extends Zend_Mime_Message
937
  public function clearSubject()
938
  {
939
  $this->_subject = null;
940
- $this->_clearHeader('Subject');
941
 
942
  return $this;
943
  }
@@ -1007,7 +1023,7 @@ class Zend_Mail extends Zend_Mime_Message
1007
  public function clearDate()
1008
  {
1009
  $this->_date = null;
1010
- $this->_clearHeader('Date');
1011
 
1012
  return $this;
1013
  }
@@ -1065,7 +1081,7 @@ class Zend_Mail extends Zend_Mime_Message
1065
  public function clearMessageId()
1066
  {
1067
  $this->_messageId = null;
1068
- $this->_clearHeader('Message-Id');
1069
 
1070
  return $this;
1071
  }
16
  * @package Zend_Mail
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Mail.php 23251 2010-10-26 12:47:55Z matthew $
20
  */
21
 
22
 
77
  * Mail character set
78
  * @var string
79
  */
80
+ protected $_charset = 'iso-8859-1';
81
 
82
  /**
83
  * Mail headers
208
  /**
209
  * Public constructor
210
  *
211
+ * @param string $charset
212
+ * @return void
213
  */
214
+ public function __construct($charset = null)
215
  {
216
+ if ($charset != null) {
217
+ $this->_charset = $charset;
218
+ }
219
  }
220
 
221
  /**
538
  * Clear header from the message
539
  *
540
  * @param string $headerName
541
+ * @deprecated use public method directly
542
  */
543
  protected function _clearHeader($headerName)
544
  {
545
+ $this->clearHeader($headerName);
 
 
546
  }
547
 
548
  /**
631
  return array_keys($this->_recipients);
632
  }
633
 
634
+ /**
635
+ * Clear header from the message
636
+ *
637
+ * @param string $headerName
638
+ * @return Zend_Mail Provides fluent inter
639
+ */
640
+ public function clearHeader($headerName)
641
+ {
642
+ if (isset($this->_headers[$headerName])){
643
+ unset($this->_headers[$headerName]);
644
+ }
645
+ return $this;
646
+ }
647
+
648
  /**
649
  * Clears list of recipient email addresses
650
  *
655
  $this->_recipients = array();
656
  $this->_to = array();
657
 
658
+ $this->clearHeader('To');
659
+ $this->clearHeader('Cc');
660
+ $this->clearHeader('Bcc');
661
 
662
  return $this;
663
  }
742
  public function clearFrom()
743
  {
744
  $this->_from = null;
745
+ $this->clearHeader('From');
746
 
747
  return $this;
748
  }
755
  public function clearReplyTo()
756
  {
757
  $this->_replyTo = null;
758
+ $this->clearHeader('Reply-To');
759
 
760
  return $this;
761
  }
907
  public function clearReturnPath()
908
  {
909
  $this->_returnPath = null;
910
+ $this->clearHeader('Return-Path');
911
 
912
  return $this;
913
  }
953
  public function clearSubject()
954
  {
955
  $this->_subject = null;
956
+ $this->clearHeader('Subject');
957
 
958
  return $this;
959
  }
1023
  public function clearDate()
1024
  {
1025
  $this->_date = null;
1026
+ $this->clearHeader('Date');
1027
 
1028
  return $this;
1029
  }
1081
  public function clearMessageId()
1082
  {
1083
  $this->_messageId = null;
1084
+ $this->clearHeader('Message-Id');
1085
 
1086
  return $this;
1087
  }
lib/Zend/Mail/Protocol/Abstract.php CHANGED
@@ -18,7 +18,7 @@
18
  * @subpackage Protocol
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
- * @version $Id: Abstract.php 21635 2010-03-24 15:25:13Z yoshida@zend.co.jp $
22
  */
23
 
24
 
@@ -44,7 +44,7 @@
44
  * @subpackage Protocol
45
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
46
  * @license http://framework.zend.com/license/new-bsd New BSD License
47
- * @version $Id: Abstract.php 21635 2010-03-24 15:25:13Z yoshida@zend.co.jp $
48
  * @todo Implement proxy settings
49
  */
50
  abstract class Zend_Mail_Protocol_Abstract
@@ -62,8 +62,9 @@ abstract class Zend_Mail_Protocol_Abstract
62
 
63
  /**
64
  * Maximum of the transaction log
 
65
  */
66
- const MAXIMUM_LOG = 64;
67
 
68
 
69
  /**
@@ -159,6 +160,28 @@ abstract class Zend_Mail_Protocol_Abstract
159
  $this->_disconnect();
160
  }
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
 
163
  /**
164
  * Create a connection to the remote host
@@ -219,7 +242,7 @@ abstract class Zend_Mail_Protocol_Abstract
219
  */
220
  protected function _addLog($value)
221
  {
222
- if (count($this->_log) >= self::MAXIMUM_LOG) {
223
  array_shift($this->_log);
224
  }
225
 
18
  * @subpackage Protocol
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
+ * @version $Id: Abstract.php 22602 2010-07-16 22:37:31Z freak $
22
  */
23
 
24
 
44
  * @subpackage Protocol
45
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
46
  * @license http://framework.zend.com/license/new-bsd New BSD License
47
+ * @version $Id: Abstract.php 22602 2010-07-16 22:37:31Z freak $
48
  * @todo Implement proxy settings
49
  */
50
  abstract class Zend_Mail_Protocol_Abstract
62
 
63
  /**
64
  * Maximum of the transaction log
65
+ * @var integer
66
  */
67
+ protected $_maximumLog = 64;
68
 
69
 
70
  /**
160
  $this->_disconnect();
161
  }
162
 
163
+ /**
164
+ * Set the maximum log size
165
+ *
166
+ * @param integer $maximumLog Maximum log size
167
+ * @return void
168
+ */
169
+ public function setMaximumLog($maximumLog)
170
+ {
171
+ $this->_maximumLog = (int) $maximumLog;
172
+ }
173
+
174
+
175
+ /**
176
+ * Get the maximum log size
177
+ *
178
+ * @return int the maximum log size
179
+ */
180
+ public function getMaximumLog()
181
+ {
182
+ return $this->_maximumLog;
183
+ }
184
+
185
 
186
  /**
187
  * Create a connection to the remote host
242
  */
243
  protected function _addLog($value)
244
  {
245
+ if ($this->_maximumLog >= 0 && count($this->_log) >= $this->_maximumLog) {
246
  array_shift($this->_log);
247
  }
248
 
lib/Zend/Mail/Protocol/Smtp/Auth/Crammd5.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Protocol
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Crammd5.php 22655 2010-07-22 18:47:20Z mabe $
21
  */
22
 
23
 
17
  * @subpackage Protocol
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Crammd5.php 22653 2010-07-22 18:41:39Z mabe $
21
  */
22
 
23
 
lib/Zend/Mail/Protocol/Smtp/Auth/Plain.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Protocol
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Plain.php 22655 2010-07-22 18:47:20Z mabe $
21
  */
22
 
23
 
17
  * @subpackage Protocol
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Plain.php 22653 2010-07-22 18:41:39Z mabe $
21
  */
22
 
23
 
lib/Zend/Mail/Transport/File.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Mail
17
+ * @subpackage Transport
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id$
21
+ */
22
+
23
+ /**
24
+ * @see Zend_Mail_Transport_Abstract
25
+ */
26
+ #require_once 'Zend/Mail/Transport/Abstract.php';
27
+
28
+
29
+ /**
30
+ * File transport
31
+ *
32
+ * Class for saving outgoing emails in filesystem
33
+ *
34
+ * @category Zend
35
+ * @package Zend_Mail
36
+ * @subpackage Transport
37
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
38
+ * @license http://framework.zend.com/license/new-bsd New BSD License
39
+ */
40
+ class Zend_Mail_Transport_File extends Zend_Mail_Transport_Abstract
41
+ {
42
+ /**
43
+ * Target directory for saving sent email messages
44
+ *
45
+ * @var string
46
+ */
47
+ protected $_path;
48
+
49
+ /**
50
+ * Callback function generating a file name
51
+ *
52
+ * @var string|array
53
+ */
54
+ protected $_callback;
55
+
56
+ /**
57
+ * Constructor
58
+ *
59
+ * @param array|Zend_Config $options OPTIONAL (Default: null)
60
+ * @return void
61
+ */
62
+ public function __construct($options = null)
63
+ {
64
+ if ($options instanceof Zend_Config) {
65
+ $options = $options->toArray();
66
+ } elseif (!is_array($options)) {
67
+ $options = array();
68
+ }
69
+
70
+ // Making sure we have some defaults to work with
71
+ if (!isset($options['path'])) {
72
+ $options['path'] = sys_get_temp_dir();
73
+ }
74
+ if (!isset($options['callback'])) {
75
+ $options['callback'] = array($this, 'defaultCallback');
76
+ }
77
+
78
+ $this->setOptions($options);
79
+ }
80
+
81
+ /**
82
+ * Sets options
83
+ *
84
+ * @param array $options
85
+ * @return void
86
+ */
87
+ public function setOptions(array $options)
88
+ {
89
+ if (isset($options['path'])&& is_dir($options['path'])) {
90
+ $this->_path = $options['path'];
91
+ }
92
+ if (isset($options['callback']) && is_callable($options['callback'])) {
93
+ $this->_callback = $options['callback'];
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Saves e-mail message to a file
99
+ *
100
+ * @return void
101
+ * @throws Zend_Mail_Transport_Exception on not writable target directory
102
+ * @throws Zend_Mail_Transport_Exception on file_put_contents() failure
103
+ */
104
+ protected function _sendMail()
105
+ {
106
+ $file = $this->_path . DIRECTORY_SEPARATOR . call_user_func($this->_callback, $this);
107
+
108
+ if (!is_writable(dirname($file))) {
109
+ #require_once 'Zend/Mail/Transport/Exception.php';
110
+ throw new Zend_Mail_Transport_Exception(sprintf(
111
+ 'Target directory "%s" does not exist or is not writable',
112
+ dirname($file)
113
+ ));
114
+ }
115
+
116
+ $email = $this->header . $this->EOL . $this->body;
117
+
118
+ if (!file_put_contents($file, $email)) {
119
+ #require_once 'Zend/Mail/Transport/Exception.php';
120
+ throw new Zend_Mail_Transport_Exception('Unable to send mail');
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Default callback for generating filenames
126
+ *
127
+ * @param Zend_Mail_Transport_File File transport instance
128
+ * @return string
129
+ */
130
+ public function defaultCallback($transport)
131
+ {
132
+ return 'ZendMail_' . $_SERVER['REQUEST_TIME'] . '_' . mt_rand() . '.tmp';
133
+ }
134
+ }
lib/Zend/Mail/Transport/Sendmail.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Transport
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Sendmail.php 21605 2010-03-22 15:09:03Z yoshida@zend.co.jp $
21
  */
22
 
23
 
17
  * @subpackage Transport
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Sendmail.php 21603 2010-03-22 12:47:11Z yoshida@zend.co.jp $
21
  */
22
 
23
 
lib/Zend/Mail/Transport/Smtp.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Transport
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Smtp.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
 
@@ -204,7 +204,7 @@ class Zend_Mail_Transport_Smtp extends Zend_Mail_Transport_Abstract
204
  }
205
 
206
  // Set sender email address
207
- $this->_connection->mail($this->_mail->getFrom());
208
 
209
  // Set recipient forward paths
210
  foreach ($this->_mail->getRecipients() as $recipient) {
17
  * @subpackage Transport
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Smtp.php 23424 2010-11-22 22:42:55Z bittarman $
21
  */
22
 
23
 
204
  }
205
 
206
  // Set sender email address
207
+ $this->_connection->mail($this->_mail->getReturnPath());
208
 
209
  // Set recipient forward paths
210
  foreach ($this->_mail->getRecipients() as $recipient) {
lib/Zend/Markup/Parser/Bbcode.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Parser
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Bbcode.php 21128 2010-02-21 15:36:07Z kokx $
21
  */
22
 
23
  /**
17
  * @subpackage Parser
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Bbcode.php 21127 2010-02-21 15:35:03Z kokx $
21
  */
22
 
23
  /**
lib/Zend/Markup/Renderer/Html.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Renderer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Html.php 22281 2010-05-25 14:21:43Z matthew $
21
  */
22
 
23
  /**
17
  * @subpackage Renderer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Html.php 22286 2010-05-25 14:26:45Z matthew $
21
  */
22
 
23
  /**
lib/Zend/Markup/Renderer/Html/Img.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Renderer_Html
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Img.php 20664 2010-01-26 18:46:20Z kokx $
21
  */
22
 
23
  /**
17
  * @subpackage Renderer_Html
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Img.php 20663 2010-01-26 18:45:18Z kokx $
21
  */
22
 
23
  /**
lib/Zend/Markup/Renderer/Html/Url.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Renderer_Html
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Url.php 20664 2010-01-26 18:46:20Z kokx $
21
  */
22
 
23
  /**
17
  * @subpackage Renderer_Html
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Url.php 20663 2010-01-26 18:45:18Z kokx $
21
  */
22
 
23
  /**
lib/Zend/Markup/Renderer/RendererAbstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Renderer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: RendererAbstract.php 22198 2010-05-19 13:33:52Z kokx $
21
  */
22
 
23
  /**
17
  * @subpackage Renderer
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: RendererAbstract.php 22197 2010-05-19 13:32:25Z kokx $
21
  */
22
 
23
  /**
lib/Zend/Measure/Abstract.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Measure
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Abstract.php 21330 2010-03-04 22:07:38Z thomas $
20
  */
21
 
22
  /**
16
  * @package Zend_Measure
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Abstract.php 21329 2010-03-04 22:06:08Z thomas $
20
  */
21
 
22
  /**
lib/Zend/Memory.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Memory
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Memory.php 20805 2010-02-01 15:52:15Z alexander $
20
  */
21
 
22
  /** Zend_Memory_Exception */
16
  * @package Zend_Memory
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Memory.php 20804 2010-02-01 15:49:16Z alexander $
20
  */
21
 
22
  /** Zend_Memory_Exception */
lib/Zend/Navigation/Page.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Navigation
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Page.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -136,6 +136,13 @@ abstract class Zend_Navigation_Page extends Zend_Navigation_Container
136
  */
137
  protected $_properties = array();
138
 
 
 
 
 
 
 
 
139
  // Initialization:
140
 
141
  /**
@@ -181,6 +188,11 @@ abstract class Zend_Navigation_Page extends Zend_Navigation_Container
181
 
182
  if (isset($options['type'])) {
183
  $type = $options['type'];
 
 
 
 
 
184
  if (is_string($type) && !empty($type)) {
185
  switch (strtolower($type)) {
186
  case 'mvc':
@@ -1107,6 +1119,20 @@ abstract class Zend_Navigation_Page extends Zend_Navigation_Container
1107
  {
1108
  return str_replace(' ', '', ucwords(str_replace('_', ' ', $property)));
1109
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1110
 
1111
  // Abstract methods:
1112
 
16
  * @package Zend_Navigation
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Page.php 22882 2010-08-22 14:00:16Z freak $
20
  */
21
 
22
  /**
136
  */
137
  protected $_properties = array();
138
 
139
+ /**
140
+ * The type of page to use when it wasn't set
141
+ *
142
+ * @var string
143
+ */
144
+ protected static $_defaultPageType;
145
+
146
  // Initialization:
147
 
148
  /**
188
 
189
  if (isset($options['type'])) {
190
  $type = $options['type'];
191
+ } elseif(self::getDefaultPageType()!= null) {
192
+ $type = self::getDefaultPageType();
193
+ }
194
+
195
+ if(isset($type)) {
196
  if (is_string($type) && !empty($type)) {
197
  switch (strtolower($type)) {
198
  case 'mvc':
1119
  {
1120
  return str_replace(' ', '', ucwords(str_replace('_', ' ', $property)));
1121
  }
1122
+
1123
+ public static function setDefaultPageType($type = null) {
1124
+ if($type !== null && !is_string($type)) {
1125
+ throw new Zend_Navigation_Exception(
1126
+ 'Cannot set default page type: type is no string but should be'
1127
+ );
1128
+ }
1129
+
1130
+ self::$_defaultPageType = $type;
1131
+ }
1132
+
1133
+ public static function getDefaultPageType() {
1134
+ return self::$_defaultPageType;
1135
+ }
1136
 
1137
  // Abstract methods:
1138
 
lib/Zend/Oauth.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Oauth.php 21071 2010-02-16 14:35:00Z padraic $
20
  */
21
 
22
  /** Zend_Http_Client */
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Oauth.php 21070 2010-02-16 14:34:25Z padraic $
20
  */
21
 
22
  /** Zend_Http_Client */
lib/Zend/Oauth/Client.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Client.php 22051 2010-04-29 13:51:41Z padraic $
20
  */
21
 
22
  /** Zend_Oauth */
@@ -74,11 +74,14 @@ class Zend_Oauth_Client extends Zend_Http_Client
74
  * @param array|Zend_Config $config
75
  * @return void
76
  */
77
- public function __construct(array $oauthOptions, $uri = null, $config = null)
78
  {
 
 
 
79
  parent::__construct($uri, $config);
80
  $this->_config = new Zend_Oauth_Config;
81
- if (!is_null($oauthOptions)) {
82
  if ($oauthOptions instanceof Zend_Config) {
83
  $oauthOptions = $oauthOptions->toArray();
84
  }
@@ -95,7 +98,7 @@ class Zend_Oauth_Client extends Zend_Http_Client
95
  {
96
  return $this->adapter;
97
  }
98
-
99
  /**
100
  * Load the connection adapter
101
  *
@@ -217,7 +220,7 @@ class Zend_Oauth_Client extends Zend_Http_Client
217
  */
218
  public function request($method = null)
219
  {
220
- if (!is_null($method)) {
221
  $this->setMethod($method);
222
  }
223
  $this->prepareOauth();
@@ -260,7 +263,7 @@ class Zend_Oauth_Client extends Zend_Http_Client
260
  $this->_config,
261
  $this->_getSignableParametersAsQueryString()
262
  );
263
- $this->setRawData($raw);
264
  $this->paramsPost = array();
265
  } elseif ($requestScheme == Zend_Oauth::REQUEST_SCHEME_QUERYSTRING) {
266
  $params = array();
@@ -269,8 +272,8 @@ class Zend_Oauth_Client extends Zend_Http_Client
269
  $queryParts = explode('&', $this->getUri()->getQuery());
270
  foreach ($queryParts as $queryPart) {
271
  $kvTuple = explode('=', $queryPart);
272
- $params[$kvTuple[0]] =
273
- (array_key_exists(1, $kvTuple) ? $kvTuple[1] : NULL);
274
  }
275
  }
276
  if (!empty($this->paramsPost)) {
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Client.php 23076 2010-10-10 21:37:20Z padraic $
20
  */
21
 
22
  /** Zend_Oauth */
74
  * @param array|Zend_Config $config
75
  * @return void
76
  */
77
+ public function __construct($oauthOptions, $uri = null, $config = null)
78
  {
79
+ if (!isset($config['rfc3986_strict'])) {
80
+ $config['rfc3986_strict'] = true;
81
+ }
82
  parent::__construct($uri, $config);
83
  $this->_config = new Zend_Oauth_Config;
84
+ if ($oauthOptions !== null) {
85
  if ($oauthOptions instanceof Zend_Config) {
86
  $oauthOptions = $oauthOptions->toArray();
87
  }
98
  {
99
  return $this->adapter;
100
  }
101
+
102
  /**
103
  * Load the connection adapter
104
  *
220
  */
221
  public function request($method = null)
222
  {
223
+ if ($method !== null) {
224
  $this->setMethod($method);
225
  }
226
  $this->prepareOauth();
263
  $this->_config,
264
  $this->_getSignableParametersAsQueryString()
265
  );
266
+ $this->setRawData($raw, 'application/x-www-form-urlencoded');
267
  $this->paramsPost = array();
268
  } elseif ($requestScheme == Zend_Oauth::REQUEST_SCHEME_QUERYSTRING) {
269
  $params = array();
272
  $queryParts = explode('&', $this->getUri()->getQuery());
273
  foreach ($queryParts as $queryPart) {
274
  $kvTuple = explode('=', $queryPart);
275
+ $params[urldecode($kvTuple[0])] =
276
+ (array_key_exists(1, $kvTuple) ? urldecode($kvTuple[1]) : NULL);
277
  }
278
  }
279
  if (!empty($this->paramsPost)) {
lib/Zend/Oauth/Config.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Config.php 20232 2010-01-12 17:56:33Z matthew $
20
  */
21
 
22
  /** Zend_Oauth */
@@ -156,7 +156,7 @@ class Zend_Oauth_Config implements Zend_Oauth_Config_ConfigInterface
156
  */
157
  public function __construct($options = null)
158
  {
159
- if (!is_null($options)) {
160
  if ($options instanceof Zend_Config) {
161
  $options = $options->toArray();
162
  }
@@ -267,7 +267,7 @@ class Zend_Oauth_Config implements Zend_Oauth_Config_ConfigInterface
267
  */
268
  public function getConsumerSecret()
269
  {
270
- if (!is_null($this->_rsaPrivateKey)) {
271
  return $this->_rsaPrivateKey;
272
  }
273
  return $this->_consumerSecret;
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Config.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /** Zend_Oauth */
156
  */
157
  public function __construct($options = null)
158
  {
159
+ if ($options !== null) {
160
  if ($options instanceof Zend_Config) {
161
  $options = $options->toArray();
162
  }
267
  */
268
  public function getConsumerSecret()
269
  {
270
+ if ($this->_rsaPrivateKey !== null) {
271
  return $this->_rsaPrivateKey;
272
  }
273
  return $this->_consumerSecret;
lib/Zend/Oauth/Consumer.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Consumer.php 22475 2010-06-20 18:25:36Z padraic $
20
  */
21
 
22
  /** Zend_Oauth */
@@ -79,7 +79,7 @@ class Zend_Oauth_Consumer extends Zend_Oauth
79
  public function __construct($options = null)
80
  {
81
  $this->_config = new Zend_Oauth_Config;
82
- if (!is_null($options)) {
83
  if ($options instanceof Zend_Config) {
84
  $options = $options->toArray();
85
  }
@@ -102,12 +102,12 @@ class Zend_Oauth_Consumer extends Zend_Oauth
102
  $httpMethod = null,
103
  Zend_Oauth_Http_RequestToken $request = null
104
  ) {
105
- if (is_null($request)) {
106
  $request = new Zend_Oauth_Http_RequestToken($this, $customServiceParameters);
107
- } elseif(!is_null($customServiceParameters)) {
108
  $request->setParameters($customServiceParameters);
109
  }
110
- if (!is_null($httpMethod)) {
111
  $request->setMethod($httpMethod);
112
  } else {
113
  $request->setMethod($this->getRequestMethod());
@@ -134,12 +134,12 @@ class Zend_Oauth_Consumer extends Zend_Oauth
134
  Zend_Oauth_Token_Request $token = null,
135
  Zend_Oauth_Http_UserAuthorization $redirect = null
136
  ) {
137
- if (is_null($redirect)) {
138
  $redirect = new Zend_Oauth_Http_UserAuthorization($this, $customServiceParameters);
139
- } elseif(!is_null($customServiceParameters)) {
140
  $redirect->setParameters($customServiceParameters);
141
  }
142
- if (!is_null($token)) {
143
  $this->_requestToken = $token;
144
  }
145
  return $redirect->getUrl();
@@ -152,14 +152,20 @@ class Zend_Oauth_Consumer extends Zend_Oauth
152
  * Sends headers and exit()s on completion.
153
  *
154
  * @param null|array $customServiceParameters
 
155
  * @param null|Zend_Oauth_Http_UserAuthorization $request
156
  * @return void
157
  */
158
  public function redirect(
159
  array $customServiceParameters = null,
 
160
  Zend_Oauth_Http_UserAuthorization $request = null
161
  ) {
162
- $redirectUrl = $this->getRedirectUrl($customServiceParameters, $request);
 
 
 
 
163
  header('Location: ' . $redirectUrl);
164
  exit(1);
165
  }
@@ -187,18 +193,18 @@ class Zend_Oauth_Consumer extends Zend_Oauth
187
  throw new Zend_Oauth_Exception(
188
  'Response from Service Provider is not a valid authorized request token');
189
  }
190
- if (is_null($request)) {
191
  $request = new Zend_Oauth_Http_AccessToken($this);
192
  }
193
 
194
  // OAuth 1.0a Verifier
195
- if (!is_null($authorizedToken->getParam('oauth_verifier'))) {
196
  $params = array_merge($request->getParameters(), array(
197
  'oauth_verifier' => $authorizedToken->getParam('oauth_verifier')
198
  ));
199
  $request->setParameters($params);
200
  }
201
- if (!is_null($httpMethod)) {
202
  $request->setMethod($httpMethod);
203
  } else {
204
  $request->setMethod($this->getRequestMethod());
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Consumer.php 23170 2010-10-19 18:29:24Z mabe $
20
  */
21
 
22
  /** Zend_Oauth */
79
  public function __construct($options = null)
80
  {
81
  $this->_config = new Zend_Oauth_Config;
82
+ if ($options !== null) {
83
  if ($options instanceof Zend_Config) {
84
  $options = $options->toArray();
85
  }
102
  $httpMethod = null,
103
  Zend_Oauth_Http_RequestToken $request = null
104
  ) {
105
+ if ($request === null) {
106
  $request = new Zend_Oauth_Http_RequestToken($this, $customServiceParameters);
107
+ } elseif($customServiceParameters !== null) {
108
  $request->setParameters($customServiceParameters);
109
  }
110
+ if ($httpMethod !== null) {
111
  $request->setMethod($httpMethod);
112
  } else {
113
  $request->setMethod($this->getRequestMethod());
134
  Zend_Oauth_Token_Request $token = null,
135
  Zend_Oauth_Http_UserAuthorization $redirect = null
136
  ) {
137
+ if ($redirect === null) {
138
  $redirect = new Zend_Oauth_Http_UserAuthorization($this, $customServiceParameters);
139
+ } elseif($customServiceParameters !== null) {
140
  $redirect->setParameters($customServiceParameters);
141
  }
142
+ if ($token !== null) {
143
  $this->_requestToken = $token;
144
  }
145
  return $redirect->getUrl();
152
  * Sends headers and exit()s on completion.
153
  *
154
  * @param null|array $customServiceParameters
155
+ * @param null|Zend_Oauth_Token_Request $token
156
  * @param null|Zend_Oauth_Http_UserAuthorization $request
157
  * @return void
158
  */
159
  public function redirect(
160
  array $customServiceParameters = null,
161
+ Zend_Oauth_Token_Request $token = null,
162
  Zend_Oauth_Http_UserAuthorization $request = null
163
  ) {
164
+ if ($token instanceof Zend_Oauth_Http_UserAuthorization) {
165
+ $request = $token;
166
+ $token = null;
167
+ }
168
+ $redirectUrl = $this->getRedirectUrl($customServiceParameters, $token, $request);
169
  header('Location: ' . $redirectUrl);
170
  exit(1);
171
  }
193
  throw new Zend_Oauth_Exception(
194
  'Response from Service Provider is not a valid authorized request token');
195
  }
196
+ if ($request === null) {
197
  $request = new Zend_Oauth_Http_AccessToken($this);
198
  }
199
 
200
  // OAuth 1.0a Verifier
201
+ if ($authorizedToken->getParam('oauth_verifier') !== null) {
202
  $params = array_merge($request->getParameters(), array(
203
  'oauth_verifier' => $authorizedToken->getParam('oauth_verifier')
204
  ));
205
  $request->setParameters($params);
206
  }
207
+ if ($httpMethod !== null) {
208
  $request->setMethod($httpMethod);
209
  } else {
210
  $request->setMethod($this->getRequestMethod());
lib/Zend/Oauth/Exception.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
  /**
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Exception.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
  /**
lib/Zend/Oauth/Http.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Http.php 20232 2010-01-12 17:56:33Z matthew $
20
  */
21
 
22
  /** Zend_Oauth_Http_Utility */
@@ -86,10 +86,10 @@ class Zend_Oauth_Http
86
  ) {
87
  $this->_consumer = $consumer;
88
  $this->_preferredRequestScheme = $this->_consumer->getRequestScheme();
89
- if (!is_null($parameters)) {
90
  $this->setParameters($parameters);
91
  }
92
- if (!is_null($utility)) {
93
  $this->_httpUtility = $utility;
94
  } else {
95
  $this->_httpUtility = new Zend_Oauth_Http_Utility;
@@ -177,11 +177,11 @@ class Zend_Oauth_Http
177
  #require_once 'Zend/Oauth/Exception.php';
178
  throw new Zend_Oauth_Exception('Error in HTTP request', null, $e);
179
  }
180
- if (!is_null($response)) {
181
  $body = $response->getBody();
182
  $status = $response->getStatus();
183
  }
184
- if (is_null($response) // Request failure/exception
185
  || $status == 500 // Internal Server Error
186
  || $status == 400 // Bad Request
187
  || $status == 401 // Unauthorized
@@ -233,7 +233,7 @@ class Zend_Oauth_Http
233
  #require_once 'Zend/Oauth/Exception.php';
234
  throw new Zend_Oauth_Exception(
235
  'Could not retrieve a valid Token response from Token URL:'
236
- . (!is_null($response)
237
  ? PHP_EOL . $response->getBody()
238
  : ' No body - check for headers')
239
  );
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Http.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /** Zend_Oauth_Http_Utility */
86
  ) {
87
  $this->_consumer = $consumer;
88
  $this->_preferredRequestScheme = $this->_consumer->getRequestScheme();
89
+ if ($parameters !== null) {
90
  $this->setParameters($parameters);
91
  }
92
+ if ($utility !== null) {
93
  $this->_httpUtility = $utility;
94
  } else {
95
  $this->_httpUtility = new Zend_Oauth_Http_Utility;
177
  #require_once 'Zend/Oauth/Exception.php';
178
  throw new Zend_Oauth_Exception('Error in HTTP request', null, $e);
179
  }
180
+ if ($response !== null) {
181
  $body = $response->getBody();
182
  $status = $response->getStatus();
183
  }
184
+ if ($response === null // Request failure/exception
185
  || $status == 500 // Internal Server Error
186
  || $status == 400 // Bad Request
187
  || $status == 401 // Unauthorized
233
  #require_once 'Zend/Oauth/Exception.php';
234
  throw new Zend_Oauth_Exception(
235
  'Could not retrieve a valid Token response from Token URL:'
236
+ . ($response !== null
237
  ? PHP_EOL . $response->getBody()
238
  : ' No body - check for headers')
239
  );
lib/Zend/Oauth/Http/RequestToken.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: RequestToken.php 20217 2010-01-12 16:01:57Z matthew $
20
  */
21
 
22
  /** Zend_Oauth_Http */
@@ -108,7 +108,7 @@ class Zend_Oauth_Http_RequestToken extends Zend_Oauth_Http
108
  $client->setHeaders('Authorization', $headerValue);
109
  $rawdata = $this->_httpUtility->toEncodedQueryString($params, true);
110
  if (!empty($rawdata)) {
111
- $client->setRawData($rawdata);
112
  }
113
  $client->setMethod($this->_preferredRequestMethod);
114
  return $client;
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: RequestToken.php 23076 2010-10-10 21:37:20Z padraic $
20
  */
21
 
22
  /** Zend_Oauth_Http */
108
  $client->setHeaders('Authorization', $headerValue);
109
  $rawdata = $this->_httpUtility->toEncodedQueryString($params, true);
110
  if (!empty($rawdata)) {
111
+ $client->setRawData($rawdata, 'application/x-www-form-urlencoded');
112
  }
113
  $client->setMethod($this->_preferredRequestMethod);
114
  return $client;
lib/Zend/Oauth/Http/Utility.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Utility.php 21233 2010-02-28 13:48:58Z padraic $
20
  */
21
 
22
  /** Zend_Oauth */
@@ -60,7 +60,7 @@ class Zend_Oauth_Http_Utility
60
  }
61
 
62
 
63
- if (!is_null($serviceProviderParams)) {
64
  $params = array_merge($params, $serviceProviderParams);
65
  }
66
 
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Utility.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /** Zend_Oauth */
60
  }
61
 
62
 
63
+ if ($serviceProviderParams !== null) {
64
  $params = array_merge($params, $serviceProviderParams);
65
  }
66
 
lib/Zend/Oauth/Signature/Plaintext.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Plaintext.php 20217 2010-01-12 16:01:57Z matthew $
20
  */
21
 
22
  /** Zend_Oauth_Signature_SignatureAbstract */
@@ -40,7 +40,7 @@ class Zend_Oauth_Signature_Plaintext extends Zend_Oauth_Signature_SignatureAbstr
40
  */
41
  public function sign(array $params, $method = null, $url = null)
42
  {
43
- if (is_null($this->_tokenSecret)) {
44
  return $this->_consumerSecret . '&';
45
  }
46
  $return = implode('&', array($this->_consumerSecret, $this->_tokenSecret));
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Plaintext.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /** Zend_Oauth_Signature_SignatureAbstract */
40
  */
41
  public function sign(array $params, $method = null, $url = null)
42
  {
43
+ if ($this->_tokenSecret === null) {
44
  return $this->_consumerSecret . '&';
45
  }
46
  $return = implode('&', array($this->_consumerSecret, $this->_tokenSecret));
lib/Zend/Oauth/Signature/SignatureAbstract.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: SignatureAbstract.php 20217 2010-01-12 16:01:57Z matthew $
20
  */
21
 
22
  /** Zend_Oauth_Http_Utility */
@@ -115,7 +115,7 @@ abstract class Zend_Oauth_Signature_SignatureAbstract
115
  protected function _assembleKey()
116
  {
117
  $parts = array($this->_consumerSecret);
118
- if (!is_null($this->_tokenSecret)) {
119
  $parts[] = $this->_tokenSecret;
120
  }
121
  foreach ($parts as $key => $secret) {
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: SignatureAbstract.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /** Zend_Oauth_Http_Utility */
115
  protected function _assembleKey()
116
  {
117
  $parts = array($this->_consumerSecret);
118
+ if ($this->_tokenSecret !== null) {
119
  $parts[] = $this->_tokenSecret;
120
  }
121
  foreach ($parts as $key => $secret) {
lib/Zend/Oauth/Token.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Token.php 20232 2010-01-12 17:56:33Z matthew $
20
  */
21
 
22
  /** Zend_Oauth_Http_Utility */
@@ -68,14 +68,14 @@ abstract class Zend_Oauth_Token
68
  Zend_Http_Response $response = null,
69
  Zend_Oauth_Http_Utility $utility = null
70
  ) {
71
- if (!is_null($response)) {
72
  $this->_response = $response;
73
  $params = $this->_parseParameters($response);
74
  if (count($params) > 0) {
75
  $this->setParams($params);
76
  }
77
  }
78
- if (!is_null($utility)) {
79
  $this->_httpUtility = $utility;
80
  } else {
81
  $this->_httpUtility = new Zend_Oauth_Http_Utility;
@@ -278,7 +278,7 @@ abstract class Zend_Oauth_Token
278
  */
279
  public function __wakeup()
280
  {
281
- if (is_null($this->_httpUtility)) {
282
  $this->_httpUtility = new Zend_Oauth_Http_Utility;
283
  }
284
  }
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Token.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /** Zend_Oauth_Http_Utility */
68
  Zend_Http_Response $response = null,
69
  Zend_Oauth_Http_Utility $utility = null
70
  ) {
71
+ if ($response !== null) {
72
  $this->_response = $response;
73
  $params = $this->_parseParameters($response);
74
  if (count($params) > 0) {
75
  $this->setParams($params);
76
  }
77
  }
78
+ if ($utility !== null) {
79
  $this->_httpUtility = $utility;
80
  } else {
81
  $this->_httpUtility = new Zend_Oauth_Http_Utility;
278
  */
279
  public function __wakeup()
280
  {
281
+ if ($this->_httpUtility === null) {
282
  $this->_httpUtility = new Zend_Oauth_Http_Utility;
283
  }
284
  }
lib/Zend/Oauth/Token/AuthorizedRequest.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: AuthorizedRequest.php 20217 2010-01-12 16:01:57Z matthew $
20
  */
21
 
22
  /** Zend_Oauth_Token */
@@ -44,14 +44,14 @@ class Zend_Oauth_Token_AuthorizedRequest extends Zend_Oauth_Token
44
  */
45
  public function __construct(array $data = null, Zend_Oauth_Http_Utility $utility = null)
46
  {
47
- if (!is_null($data)) {
48
  $this->_data = $data;
49
  $params = $this->_parseData();
50
  if (count($params) > 0) {
51
  $this->setParams($params);
52
  }
53
  }
54
- if (!is_null($utility)) {
55
  $this->_httpUtility = $utility;
56
  } else {
57
  $this->_httpUtility = new Zend_Oauth_Http_Utility;
16
  * @package Zend_Oauth
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: AuthorizedRequest.php 22662 2010-07-24 17:37:36Z mabe $
20
  */
21
 
22
  /** Zend_Oauth_Token */
44
  */
45
  public function __construct(array $data = null, Zend_Oauth_Http_Utility $utility = null)
46
  {
47
+ if ($data !== null) {
48
  $this->_data = $data;
49
  $params = $this->_parseData();
50
  if (count($params) > 0) {
51
  $this->setParams($params);
52
  }
53
  }
54
+ if ($utility !== null) {
55
  $this->_httpUtility = $utility;
56
  } else {
57
  $this->_httpUtility = new Zend_Oauth_Http_Utility;
lib/Zend/OpenId.php CHANGED
@@ -17,7 +17,7 @@
17
  * @package Zend_OpenId
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: OpenId.php 22655 2010-07-22 18:47:20Z mabe $
21
  */
22
 
23
  /**
17
  * @package Zend_OpenId
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: OpenId.php 22653 2010-07-22 18:41:39Z mabe $
21
  */
22
 
23
  /**
lib/Zend/OpenId/Consumer/Storage/File.php CHANGED
@@ -18,7 +18,7 @@
18
  * @subpackage Zend_OpenId_Consumer
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
- * @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $
22
  */
23
 
24
  /**
@@ -479,20 +479,24 @@ class Zend_OpenId_Consumer_Storage_File extends Zend_OpenId_Consumer_Storage
479
  }
480
  try {
481
  if (!is_int($date) && !is_string($date)) {
482
- foreach (glob($this->_dir . '/nonce_*') as $name) {
 
483
  @unlink($name);
484
  }
 
485
  } else {
486
  if (is_string($date)) {
487
  $time = time($date);
488
  } else {
489
  $time = $date;
490
  }
491
- foreach (glob($this->_dir . '/nonce_*') as $name) {
 
492
  if (filemtime($name) < $time) {
493
  @unlink($name);
494
  }
495
  }
 
496
  }
497
  if ($lock !== false) {
498
  fclose($lock);
18
  * @subpackage Zend_OpenId_Consumer
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
+ * @version $Id: File.php 23161 2010-10-19 16:08:36Z matthew $
22
  */
23
 
24
  /**
479
  }
480
  try {
481
  if (!is_int($date) && !is_string($date)) {
482
+ $nonceFiles = glob($this->_dir . '/nonce_*');
483
+ foreach ((array) $nonceFiles as $name) {
484
  @unlink($name);
485
  }
486
+ unset($nonceFiles);
487
  } else {
488
  if (is_string($date)) {
489
  $time = time($date);
490
  } else {
491
  $time = $date;
492
  }
493
+ $nonceFiles = glob($this->_dir . '/nonce_*');
494
+ foreach ((array) $nonceFiles as $name) {
495
  if (filemtime($name) < $time) {
496
  @unlink($name);
497
  }
498
  }
499
+ unset($nonceFiles);
500
  }
501
  if ($lock !== false) {
502
  fclose($lock);
lib/Zend/OpenId/Provider.php CHANGED
@@ -18,7 +18,7 @@
18
  * @subpackage Zend_OpenId_Provider
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
- * @version $Id: Provider.php 20096 2010-01-06 02:05:09Z bkarwin $
22
  */
23
 
24
  /**
@@ -770,12 +770,34 @@ class Zend_OpenId_Provider
770
  $data .= $params['openid_' . strtr($key,'.','_')]."\n";
771
  }
772
  }
773
- if (base64_decode($params['openid_sig']) ===
774
- Zend_OpenId::hashHmac($macFunc, $data, $secret)) {
775
  $ret['is_valid'] = 'true';
776
  } else {
777
  $ret['is_valid'] = 'false';
778
  }
779
  return $ret;
780
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
781
  }
18
  * @subpackage Zend_OpenId_Provider
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
+ * @version $Id: Provider.php 23088 2010-10-11 19:53:24Z padraic $
22
  */
23
 
24
  /**
770
  $data .= $params['openid_' . strtr($key,'.','_')]."\n";
771
  }
772
  }
773
+ if ($this->_secureStringCompare(base64_decode($params['openid_sig']),
774
+ Zend_OpenId::hashHmac($macFunc, $data, $secret))) {
775
  $ret['is_valid'] = 'true';
776
  } else {
777
  $ret['is_valid'] = 'false';
778
  }
779
  return $ret;
780
  }
781
+
782
+ /**
783
+ * Securely compare two strings for equality while avoided C level memcmp()
784
+ * optimisations capable of leaking timing information useful to an attacker
785
+ * attempting to iteratively guess the unknown string (e.g. password) being
786
+ * compared against.
787
+ *
788
+ * @param string $a
789
+ * @param string $b
790
+ * @return bool
791
+ */
792
+ protected function _secureStringCompare($a, $b)
793
+ {
794
+ if (strlen($a) !== strlen($b)) {
795
+ return false;
796
+ }
797
+ $result = 0;
798
+ for ($i = 0; $i < strlen($a); $i++) {
799
+ $result |= ord($a[$i]) ^ ord($b[$i]);
800
+ }
801
+ return $result == 0;
802
+ }
803
  }
lib/Zend/Paginator.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Paginator
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Paginator.php 22829 2010-08-11 19:56:28Z bate $
20
  */
21
 
22
  /**
@@ -78,6 +78,15 @@ class Zend_Paginator implements Countable, IteratorAggregate
78
  */
79
  protected static $_defaultItemCountPerPage = 10;
80
 
 
 
 
 
 
 
 
 
 
81
  /**
82
  * Scrolling style plugin loader
83
  *
@@ -154,7 +163,7 @@ class Zend_Paginator implements Countable, IteratorAggregate
154
  *
155
  * @var integer
156
  */
157
- protected $_pageRange = 10;
158
 
159
  /**
160
  * Pages
@@ -375,6 +384,26 @@ class Zend_Paginator implements Countable, IteratorAggregate
375
  self::$_defaultItemCountPerPage = (int) $count;
376
  }
377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
  /**
379
  * Sets a cache object
380
  *
@@ -702,11 +731,11 @@ class Zend_Paginator implements Countable, IteratorAggregate
702
  * @param integer $itemCountPerPage
703
  * @return Zend_Paginator $this
704
  */
705
- public function setItemCountPerPage($itemCountPerPage)
706
  {
707
  $this->_itemCountPerPage = (integer) $itemCountPerPage;
708
  if ($this->_itemCountPerPage < 1) {
709
- $this->_itemCountPerPage = $this->getItemCountPerPage();
710
  }
711
  $this->_pageCount = $this->_calculatePageCount();
712
  $this->_currentItems = null;
@@ -788,6 +817,10 @@ class Zend_Paginator implements Countable, IteratorAggregate
788
  */
789
  public function getPageRange()
790
  {
 
 
 
 
791
  return $this->_pageRange;
792
  }
793
 
16
  * @package Zend_Paginator
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Paginator.php 22865 2010-08-21 12:28:09Z ramon $
20
  */
21
 
22
  /**
78
  */
79
  protected static $_defaultItemCountPerPage = 10;
80
 
81
+ /**
82
+ * Default number of local pages (i.e., the number of discretes
83
+ * page numbers that will be displayed, including the current
84
+ * page number)
85
+ *
86
+ * @var int
87
+ */
88
+ protected static $_defaultPageRange = 10;
89
+
90
  /**
91
  * Scrolling style plugin loader
92
  *
163
  *
164
  * @var integer
165
  */
166
+ protected $_pageRange = null;
167
 
168
  /**
169
  * Pages
384
  self::$_defaultItemCountPerPage = (int) $count;
385
  }
386
 
387
+ /**
388
+ * Get the default page range
389
+ *
390
+ * @return int
391
+ */
392
+ public static function getDefaultPageRange()
393
+ {
394
+ return self::$_defaultPageRange;
395
+ }
396
+
397
+ /**
398
+ * Set the default page range
399
+ *
400
+ * @param int $count
401
+ */
402
+ public static function setDefaultPageRange($count)
403
+ {
404
+ self::$_defaultPageRange = (int) $count;
405
+ }
406
+
407
  /**
408
  * Sets a cache object
409
  *
731
  * @param integer $itemCountPerPage
732
  * @return Zend_Paginator $this
733
  */
734
+ public function setItemCountPerPage($itemCountPerPage = -1)
735
  {
736
  $this->_itemCountPerPage = (integer) $itemCountPerPage;
737
  if ($this->_itemCountPerPage < 1) {
738
+ $this->_itemCountPerPage = $this->getTotalItemCount();
739
  }
740
  $this->_pageCount = $this->_calculatePageCount();
741
  $this->_currentItems = null;
817
  */
818
  public function getPageRange()
819
  {
820
+ if (null === $this->_pageRange) {
821
+ $this->_pageRange = self::getDefaultPageRange();
822
+ }
823
+
824
  return $this->_pageRange;
825
  }
826
 
lib/Zend/Paginator/Adapter/Interface.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Paginator
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -29,13 +29,6 @@
29
  */
30
  interface Zend_Paginator_Adapter_Interface extends Countable
31
  {
32
- /**
33
- * Returns the total number of rows in the collection.
34
- *
35
- * @return integer
36
- */
37
- //public function count();
38
-
39
  /**
40
  * Returns an collection of items for a page.
41
  *
@@ -44,4 +37,4 @@ interface Zend_Paginator_Adapter_Interface extends Countable
44
  * @return array
45
  */
46
  public function getItems($offset, $itemCountPerPage);
47
- }
16
  * @package Zend_Paginator
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Interface.php 23314 2010-11-08 19:48:10Z matthew $
20
  */
21
 
22
  /**
29
  */
30
  interface Zend_Paginator_Adapter_Interface extends Countable
31
  {
 
 
 
 
 
 
 
32
  /**
33
  * Returns an collection of items for a page.
34
  *
37
  * @return array
38
  */
39
  public function getItems($offset, $itemCountPerPage);
40
+ }
lib/Zend/Paginator/Adapter/Null.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Paginator
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Null.php 21151 2010-02-23 16:34:14Z matthew $
20
  */
21
 
22
  /**
16
  * @package Zend_Paginator
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Null.php 21150 2010-02-23 16:27:36Z matthew $
20
  */
21
 
22
  /**
lib/Zend/Paginator/AdapterAggregate.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: AdapterAggregate.php 22543 2010-07-09 19:46:37Z ramon $
21
  */
22
 
23
  /**
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: AdapterAggregate.php 22542 2010-07-09 19:41:46Z ramon $
21
  */
22
 
23
  /**
lib/Zend/Paginator/SerializableLimitIterator.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Paginator
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: SerializableLimitIterator.php 22636 2010-07-19 00:09:26Z ramon $
20
  */
21
 
22
  /**
@@ -122,6 +122,7 @@ class Zend_Paginator_SerializableLimitIterator extends LimitIterator implements
122
  return null !== $current;
123
  } catch (OutOfBoundsException $e) {
124
  // reset position in case of exception is assigned null
 
125
  $this->seek($currentOffset);
126
  return false;
127
  }
16
  * @package Zend_Paginator
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: SerializableLimitIterator.php 23189 2010-10-20 18:55:32Z mabe $
20
  */
21
 
22
  /**
122
  return null !== $current;
123
  } catch (OutOfBoundsException $e) {
124
  // reset position in case of exception is assigned null
125
+ $this->rewind();
126
  $this->seek($currentOffset);
127
  return false;
128
  }
lib/Zend/Pdf.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Pdf.php 22655 2010-07-22 18:47:20Z mabe $
20
  */
21
 
22
 
@@ -47,6 +47,12 @@
47
  /** Zend_Pdf_Font */
48
  #require_once 'Zend/Pdf/Font.php';
49
 
 
 
 
 
 
 
50
 
51
  /** Internally used classes */
52
  #require_once 'Zend/Pdf/Element.php';
@@ -286,7 +292,7 @@ class Zend_Pdf
286
  * from a file.
287
 
288
  * $revision used to roll back document to specified version
289
- * (0 - currtent version, 1 - previous version, 2 - ...)
290
  *
291
  * @param string $source - PDF file to load
292
  * @param integer $revision
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Pdf.php 22908 2010-08-25 20:52:47Z alexander $
20
  */
21
 
22
 
47
  /** Zend_Pdf_Font */
48
  #require_once 'Zend/Pdf/Font.php';
49
 
50
+ /** Zend_Pdf_Resource_Extractor */
51
+ #require_once 'Zend/Pdf/Resource/Extractor.php';
52
+
53
+ /** Zend_Pdf_Canvas */
54
+ #require_once 'Zend/Pdf/Canvas.php';
55
+
56
 
57
  /** Internally used classes */
58
  #require_once 'Zend/Pdf/Element.php';
292
  * from a file.
293
 
294
  * $revision used to roll back document to specified version
295
+ * (0 - current version, 1 - previous version, 2 - ...)
296
  *
297
  * @param string $source - PDF file to load
298
  * @param integer $revision
lib/Zend/Pdf/Action.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Actions
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Action.php 22438 2010-06-15 16:15:51Z alexander $
21
  */
22
 
23
 
17
  * @subpackage Actions
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Action.php 22437 2010-06-15 16:13:46Z alexander $
21
  */
22
 
23
 
lib/Zend/Pdf/Annotation/Markup.php CHANGED
@@ -17,6 +17,7 @@
17
  * @subpackage Annotation
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
20
  */
21
 
22
  /** Internally used classes */
17
  * @subpackage Annotation
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Markup.php 20785 2010-01-31 09:43:03Z mikaelkael $
21
  */
22
 
23
  /** Internally used classes */
lib/Zend/Pdf/Canvas.php ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Pdf
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $
20
+ */
21
+
22
+ #require_once 'Zend/Pdf/Canvas/Abstract.php';
23
+
24
+ /**
25
+ * Canvas is an abstract rectangle drawing area which can be dropped into
26
+ * page object at specified place.
27
+ *
28
+ * @package Zend_Pdf
29
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30
+ * @license http://framework.zend.com/license/new-bsd New BSD License
31
+ */
32
+ class Zend_Pdf_Canvas extends Zend_Pdf_Canvas_Abstract
33
+ {
34
+ /**
35
+ * Canvas procedure sets.
36
+ *
37
+ * Allowed values: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'.
38
+ *
39
+ * @var array
40
+ */
41
+ protected $_procSet = array();
42
+
43
+ /**
44
+ * Canvas width expressed in default user space units (1/72 inch)
45
+ *
46
+ * @var float
47
+ */
48
+ protected $_width;
49
+
50
+ /**
51
+ * Canvas height expressed in default user space units (1/72 inch)
52
+ *
53
+ * @var float
54
+ */
55
+ protected $_height;
56
+
57
+ protected $_resources = array('Font' => array(),
58
+ 'XObject' => array(),
59
+ 'ExtGState' => array());
60
+
61
+ /**
62
+ * Object constructor
63
+ *
64
+ * @param float $width
65
+ * @param float $height
66
+ */
67
+ public function __construct($width, $height)
68
+ {
69
+ $this->_width = $width;
70
+ $this->_height = $height;
71
+ }
72
+
73
+ /**
74
+ * Add procedure set to the canvas description
75
+ *
76
+ * @param string $procSetName
77
+ */
78
+ protected function _addProcSet($procSetName)
79
+ {
80
+ $this->_procset[$procSetName] = 1;
81
+ }
82
+
83
+ /**
84
+ * Attach resource to the canvas
85
+ *
86
+ * Method returns a name of the resource which can be used
87
+ * as a resource reference within drawing instructions stream
88
+ * Allowed types: 'ExtGState', 'ColorSpace', 'Pattern', 'Shading',
89
+ * 'XObject', 'Font', 'Properties'
90
+ *
91
+ * @param string $type
92
+ * @param Zend_Pdf_Resource $resource
93
+ * @return string
94
+ */
95
+ protected function _attachResource($type, Zend_Pdf_Resource $resource)
96
+ {
97
+ // Check, that resource is already attached to resource set.
98
+ $resObject = $resource->getResource();
99
+ foreach ($this->_resources[$type] as $resName => $collectedResObject) {
100
+ if ($collectedResObject === $resObject) {
101
+ return $resName;
102
+ }
103
+ }
104
+
105
+ $idCounter = 1;
106
+ do {
107
+ $newResName = $type[0] . $idCounter++;
108
+ } while (isset($this->_resources[$type][$newResName]));
109
+
110
+ $this->_resources[$type][$newResName] = $resObject;
111
+
112
+ return $newResName;
113
+ }
114
+
115
+ /**
116
+ * Returns dictionaries of used resources.
117
+ *
118
+ * Used for canvas implementations interoperability
119
+ *
120
+ * Structure of the returned array:
121
+ * array(
122
+ * <resTypeName> => array(
123
+ * <resName> => <Zend_Pdf_Resource object>,
124
+ * <resName> => <Zend_Pdf_Resource object>,
125
+ * <resName> => <Zend_Pdf_Resource object>,
126
+ * ...
127
+ * ),
128
+ * <resTypeName> => array(
129
+ * <resName> => <Zend_Pdf_Resource object>,
130
+ * <resName> => <Zend_Pdf_Resource object>,
131
+ * <resName> => <Zend_Pdf_Resource object>,
132
+ * ...
133
+ * ),
134
+ * ...
135
+ * 'ProcSet' => array()
136
+ * )
137
+ *
138
+ * where ProcSet array is a list of used procedure sets names (strings).
139
+ * Allowed procedure set names: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'
140
+ *
141
+ * @internal
142
+ * @return array
143
+ */
144
+ public function getResources()
145
+ {
146
+ $this->_resources['ProcSet'] = array_keys($this->_procSet);
147
+ return $this->_resources;
148
+ }
149
+
150
+ /**
151
+ * Get drawing instructions stream
152
+ *
153
+ * It has to be returned as a PDF stream object to make it reusable.
154
+ *
155
+ * @internal
156
+ * @returns Zend_Pdf_Resource_ContentStream
157
+ */
158
+ public function getContents()
159
+ {
160
+ /** @todo implementation */
161
+ }
162
+
163
+ /**
164
+ * Return the height of this page in points.
165
+ *
166
+ * @return float
167
+ */
168
+ public function getHeight()
169
+ {
170
+ return $this->_height;
171
+ }
172
+
173
+ /**
174
+ * Return the width of this page in points.
175
+ *
176
+ * @return float
177
+ */
178
+ public function getWidth()
179
+ {
180
+ return $this->_width;
181
+ }
182
+ }
lib/Zend/Pdf/Canvas/Abstract.php ADDED
@@ -0,0 +1,1214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Pdf
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $
20
+ */
21
+
22
+ #require_once 'Zend/Pdf/Canvas/Interface.php';
23
+
24
+ /** Internally used classes */
25
+ #require_once 'Zend/Pdf/Element.php';
26
+ #require_once 'Zend/Pdf/Element/Array.php';
27
+ #require_once 'Zend/Pdf/Element/String/Binary.php';
28
+ #require_once 'Zend/Pdf/Element/Boolean.php';
29
+ #require_once 'Zend/Pdf/Element/Dictionary.php';
30
+ #require_once 'Zend/Pdf/Element/Name.php';
31
+ #require_once 'Zend/Pdf/Element/Null.php';
32
+ #require_once 'Zend/Pdf/Element/Numeric.php';
33
+ #require_once 'Zend/Pdf/Element/String.php';
34
+
35
+
36
+ /**
37
+ * Canvas is an abstract rectangle drawing area which can be dropped into
38
+ * page object at specified place.
39
+ *
40
+ * @package Zend_Pdf
41
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
42
+ * @license http://framework.zend.com/license/new-bsd New BSD License
43
+ */
44
+ abstract class Zend_Pdf_Canvas_Abstract implements Zend_Pdf_Canvas_Interface
45
+ {
46
+ /**
47
+ * Drawing instructions
48
+ *
49
+ * @var string
50
+ */
51
+ protected $_contents = '';
52
+
53
+ /**
54
+ * Current font
55
+ *
56
+ * @var Zend_Pdf_Resource_Font
57
+ */
58
+ protected $_font = null;
59
+
60
+ /**
61
+ * Current font size
62
+ *
63
+ * @var float
64
+ */
65
+ protected $_fontSize;
66
+
67
+ /**
68
+ * Current style
69
+ *
70
+ * @var Zend_Pdf_Style
71
+ */
72
+ protected $_style = null;
73
+
74
+
75
+ /**
76
+ * Counter for the "Save" operations
77
+ *
78
+ * @var integer
79
+ */
80
+ protected $_saveCount = 0;
81
+
82
+
83
+ /**
84
+ * Add procedureSet to the Page description
85
+ *
86
+ * @param string $procSetName
87
+ */
88
+ abstract protected function _addProcSet($procSetName);
89
+
90
+ /**
91
+ * Attach resource to the canvas
92
+ *
93
+ * Method returns a name of the resource which can be used
94
+ * as a resource reference within drawing instructions stream
95
+ * Allowed types: 'ExtGState', 'ColorSpace', 'Pattern', 'Shading',
96
+ * 'XObject', 'Font', 'Properties'
97
+ *
98
+ * @param string $type
99
+ * @param Zend_Pdf_Resource $resource
100
+ * @return string
101
+ */
102
+ abstract protected function _attachResource($type, Zend_Pdf_Resource $resource);
103
+
104
+ /**
105
+ * Draw a canvas at the specified location
106
+ *
107
+ * If upper right corner is not specified then canvas heght and width
108
+ * are used.
109
+ *
110
+ * @param Zend_Pdf_Canvas_Interface $canvas
111
+ * @param float $x1
112
+ * @param float $y1
113
+ * @param float $x2
114
+ * @param float $y2
115
+ * @return Zend_Pdf_Canvas_Interface
116
+ */
117
+ public function drawCanvas(Zend_Pdf_Canvas_Interface $canvas, $x1, $y1, $x2 = null, $y2 = null)
118
+ {
119
+ $this->saveGS();
120
+
121
+ $this->translate($x1, $y1);
122
+
123
+ if ($x2 === null) {
124
+ $with = $canvas->getWidth();
125
+ } else {
126
+ $with = $x2 - $x1;
127
+ }
128
+ if ($y2 === null) {
129
+ $height = $canvas->getHeight();
130
+ } else {
131
+ $height = $y2 - $y1;
132
+ }
133
+
134
+ $this->clipRectangle(0, 0, $with, $height);
135
+
136
+ if ($x2 !== null || $y2 !== null) {
137
+ // Drawn canvas has to be scaled.
138
+ if ($x2 !== null) {
139
+ $xScale = $with/$canvas->getWidth();
140
+ } else {
141
+ $xScale = 1;
142
+ }
143
+
144
+ if ($y2 !== null) {
145
+ $yScale = $height/$canvas->getHeight();
146
+ } else {
147
+ $yScale = 1;
148
+ }
149
+
150
+ $this->scale($xScale, $yScale);
151
+ }
152
+
153
+ $contentsToDraw = $canvas->getContents();
154
+ /** @todo implementation */
155
+
156
+ $this->restoreGS();
157
+
158
+ return $this;
159
+ }
160
+
161
+ /**
162
+ * Set fill color.
163
+ *
164
+ * @param Zend_Pdf_Color $color
165
+ * @return Zend_Pdf_Canvas_Interface
166
+ */
167
+ public function setFillColor(Zend_Pdf_Color $color)
168
+ {
169
+ $this->_addProcSet('PDF');
170
+ $this->_contents .= $color->instructions(false);
171
+
172
+ return $this;
173
+ }
174
+
175
+ /**
176
+ * Set line color.
177
+ *
178
+ * @param Zend_Pdf_Color $color
179
+ * @return Zend_Pdf_Canvas_Interface
180
+ */
181
+ public function setLineColor(Zend_Pdf_Color $color)
182
+ {
183
+ $this->_addProcSet('PDF');
184
+ $this->_contents .= $color->instructions(true);
185
+
186
+ return $this;
187
+ }
188
+
189
+ /**
190
+ * Set line width.
191
+ *
192
+ * @param float $width
193
+ * @return Zend_Pdf_Canvas_Interface
194
+ */
195
+ public function setLineWidth($width)
196
+ {
197
+ $this->_addProcSet('PDF');
198
+ $widthObj = new Zend_Pdf_Element_Numeric($width);
199
+ $this->_contents .= $widthObj->toString() . " w\n";
200
+
201
+ return $this;
202
+ }
203
+
204
+ /**
205
+ * Set line dashing pattern
206
+ *
207
+ * Pattern is an array of floats: array(on_length, off_length, on_length, off_length, ...)
208
+ * or Zend_Pdf_Page::LINE_DASHING_SOLID constant
209
+ * Phase is shift from the beginning of line.
210
+ *
211
+ * @param mixed $pattern
212
+ * @param array $phase
213
+ * @return Zend_Pdf_Canvas_Interface
214
+ */
215
+ public function setLineDashingPattern($pattern, $phase = 0)
216
+ {
217
+ $this->_addProcSet('PDF');
218
+
219
+ #require_once 'Zend/Pdf/Page.php';
220
+ if ($pattern === Zend_Pdf_Page::LINE_DASHING_SOLID) {
221
+ $pattern = array();
222
+ $phase = 0;
223
+ }
224
+
225
+ $dashPattern = new Zend_Pdf_Element_Array();
226
+ $phaseEleemnt = new Zend_Pdf_Element_Numeric($phase);
227
+
228
+ foreach ($pattern as $dashItem) {
229
+ $dashElement = new Zend_Pdf_Element_Numeric($dashItem);
230
+ $dashPattern->items[] = $dashElement;
231
+ }
232
+
233
+ $this->_contents .= $dashPattern->toString() . ' '
234
+ . $phaseEleemnt->toString() . " d\n";
235
+
236
+ return $this;
237
+ }
238
+
239
+ /**
240
+ * Set current font.
241
+ *
242
+ * @param Zend_Pdf_Resource_Font $font
243
+ * @param float $fontSize
244
+ * @return Zend_Pdf_Canvas_Interface
245
+ */
246
+ public function setFont(Zend_Pdf_Resource_Font $font, $fontSize)
247
+ {
248
+ $this->_addProcSet('Text');
249
+ $fontName = $this->_attachResource('Font', $font);
250
+
251
+ $this->_font = $font;
252
+ $this->_fontSize = $fontSize;
253
+
254
+ $fontNameObj = new Zend_Pdf_Element_Name($fontName);
255
+ $fontSizeObj = new Zend_Pdf_Element_Numeric($fontSize);
256
+ $this->_contents .= $fontNameObj->toString() . ' ' . $fontSizeObj->toString() . " Tf\n";
257
+
258
+ return $this;
259
+ }
260
+
261
+ /**
262
+ * Set the style to use for future drawing operations on this page
263
+ *
264
+ * @param Zend_Pdf_Style $style
265
+ * @return Zend_Pdf_Canvas_Interface
266
+ */
267
+ public function setStyle(Zend_Pdf_Style $style)
268
+ {
269
+ $this->_addProcSet('Text');
270
+ $this->_addProcSet('PDF');
271
+ if ($style->getFont() !== null) {
272
+ $this->setFont($style->getFont(), $style->getFontSize());
273
+ }
274
+ $this->_contents .= $style->instructions($this->_dictionary->Resources);
275
+
276
+ $this->_style = $style;
277
+
278
+ return $this;
279
+ }
280
+
281
+ /**
282
+ * Get current font.
283
+ *
284
+ * @return Zend_Pdf_Resource_Font $font
285
+ */
286
+ public function getFont()
287
+ {
288
+ return $this->_font;
289
+ }
290
+
291
+ /**
292
+ * Get current font size
293
+ *
294
+ * @return float $fontSize
295
+ */
296
+ public function getFontSize()
297
+ {
298
+ return $this->_fontSize;
299
+ }
300
+
301
+ /**
302
+ * Return the style, applied to the page.
303
+ *
304
+ * @return Zend_Pdf_Style
305
+ */
306
+ public function getStyle()
307
+ {
308
+ return $this->_style;
309
+ }
310
+
311
+ /**
312
+ * Save the graphics state of this page.
313
+ * This takes a snapshot of the currently applied style, position, clipping area and
314
+ * any rotation/translation/scaling that has been applied.
315
+ *
316
+ * @todo check for the open paths
317
+ * @throws Zend_Pdf_Exception - if a save is performed with an open path
318
+ * @return Zend_Pdf_Canvas_Interface
319
+ */
320
+ public function saveGS()
321
+ {
322
+ $this->_saveCount++;
323
+
324
+ $this->_addProcSet('PDF');
325
+ $this->_contents .= " q\n";
326
+
327
+ return $this;
328
+ }
329
+
330
+ /**
331
+ * Restore the graphics state that was saved with the last call to saveGS().
332
+ *
333
+ * @throws Zend_Pdf_Exception - if there is no previously saved state
334
+ * @return Zend_Pdf_Canvas_Interface
335
+ */
336
+ public function restoreGS()
337
+ {
338
+ if ($this->_saveCount-- <= 0) {
339
+ #require_once 'Zend/Pdf/Exception.php';
340
+ throw new Zend_Pdf_Exception('Restoring graphics state which is not saved');
341
+ }
342
+ $this->_contents .= " Q\n";
343
+
344
+ return $this;
345
+ }
346
+
347
+ /**
348
+ * Set the transparancy
349
+ *
350
+ * $alpha == 0 - transparent
351
+ * $alpha == 1 - opaque
352
+ *
353
+ * Transparency modes, supported by PDF:
354
+ * Normal (default), Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight,
355
+ * SoftLight, Difference, Exclusion
356
+ *
357
+ * @param float $alpha
358
+ * @param string $mode
359
+ * @return Zend_Pdf_Canvas_Interface
360
+ */
361
+ public function setAlpha($alpha, $mode = 'Normal')
362
+ {
363
+ $this->_addProcSet('Text');
364
+ $this->_addProcSet('PDF');
365
+
366
+ $graphicsState = new Zend_Pdf_Resource_GraphicsState();
367
+
368
+ $graphicsState->setAlpha($alpha, $mode);
369
+ $gStateName = $this->_attachResource('ExtGState', $graphicsState);
370
+
371
+ $gStateNameObject = new Zend_Pdf_Element_Name($gStateName);
372
+ $this->_contents .= $gStateNameObject->toString() . " gs\n";
373
+
374
+ return $this;
375
+ }
376
+
377
+ /**
378
+ * Intersect current clipping area with a circle.
379
+ *
380
+ * @param float $x
381
+ * @param float $y
382
+ * @param float $radius
383
+ * @param float $startAngle
384
+ * @param float $endAngle
385
+ * @return Zend_Pdf_Canvas_Interface
386
+ */
387
+ public function clipCircle($x, $y, $radius, $startAngle = null, $endAngle = null)
388
+ {
389
+ $this->clipEllipse($x - $radius, $y - $radius,
390
+ $x + $radius, $y + $radius,
391
+ $startAngle, $endAngle);
392
+
393
+ return $this;
394
+ }
395
+
396
+ /**
397
+ * Intersect current clipping area with a polygon.
398
+ *
399
+ * Method signatures:
400
+ * drawEllipse($x1, $y1, $x2, $y2);
401
+ * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
402
+ *
403
+ * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
404
+ *
405
+ * @param float $x1
406
+ * @param float $y1
407
+ * @param float $x2
408
+ * @param float $y2
409
+ * @param float $startAngle
410
+ * @param float $endAngle
411
+ * @return Zend_Pdf_Canvas_Interface
412
+ */
413
+ public function clipEllipse($x1, $y1, $x2, $y2, $startAngle = null, $endAngle = null)
414
+ {
415
+ $this->_addProcSet('PDF');
416
+
417
+ if ($x2 < $x1) {
418
+ $temp = $x1;
419
+ $x1 = $x2;
420
+ $x2 = $temp;
421
+ }
422
+ if ($y2 < $y1) {
423
+ $temp = $y1;
424
+ $y1 = $y2;
425
+ $y2 = $temp;
426
+ }
427
+
428
+ $x = ($x1 + $x2)/2.;
429
+ $y = ($y1 + $y2)/2.;
430
+
431
+ $xC = new Zend_Pdf_Element_Numeric($x);
432
+ $yC = new Zend_Pdf_Element_Numeric($y);
433
+
434
+ if ($startAngle !== null) {
435
+ if ($startAngle != 0) { $startAngle = fmod($startAngle, M_PI*2); }
436
+ if ($endAngle != 0) { $endAngle = fmod($endAngle, M_PI*2); }
437
+
438
+ if ($startAngle > $endAngle) {
439
+ $endAngle += M_PI*2;
440
+ }
441
+
442
+ $clipPath = $xC->toString() . ' ' . $yC->toString() . " m\n";
443
+ $clipSectors = (int)ceil(($endAngle - $startAngle)/M_PI_4);
444
+ $clipRadius = max($x2 - $x1, $y2 - $y1);
445
+
446
+ for($count = 0; $count <= $clipSectors; $count++) {
447
+ $pAngle = $startAngle + ($endAngle - $startAngle)*$count/(float)$clipSectors;
448
+
449
+ $pX = new Zend_Pdf_Element_Numeric($x + cos($pAngle)*$clipRadius);
450
+ $pY = new Zend_Pdf_Element_Numeric($y + sin($pAngle)*$clipRadius);
451
+ $clipPath .= $pX->toString() . ' ' . $pY->toString() . " l\n";
452
+ }
453
+
454
+ $this->_contents .= $clipPath . "h\nW\nn\n";
455
+ }
456
+
457
+ $xLeft = new Zend_Pdf_Element_Numeric($x1);
458
+ $xRight = new Zend_Pdf_Element_Numeric($x2);
459
+ $yUp = new Zend_Pdf_Element_Numeric($y2);
460
+ $yDown = new Zend_Pdf_Element_Numeric($y1);
461
+
462
+ $xDelta = 2*(M_SQRT2 - 1)*($x2 - $x1)/3.;
463
+ $yDelta = 2*(M_SQRT2 - 1)*($y2 - $y1)/3.;
464
+ $xr = new Zend_Pdf_Element_Numeric($x + $xDelta);
465
+ $xl = new Zend_Pdf_Element_Numeric($x - $xDelta);
466
+ $yu = new Zend_Pdf_Element_Numeric($y + $yDelta);
467
+ $yd = new Zend_Pdf_Element_Numeric($y - $yDelta);
468
+
469
+ $this->_contents .= $xC->toString() . ' ' . $yUp->toString() . " m\n"
470
+ . $xr->toString() . ' ' . $yUp->toString() . ' '
471
+ . $xRight->toString() . ' ' . $yu->toString() . ' '
472
+ . $xRight->toString() . ' ' . $yC->toString() . " c\n"
473
+ . $xRight->toString() . ' ' . $yd->toString() . ' '
474
+ . $xr->toString() . ' ' . $yDown->toString() . ' '
475
+ . $xC->toString() . ' ' . $yDown->toString() . " c\n"
476
+ . $xl->toString() . ' ' . $yDown->toString() . ' '
477
+ . $xLeft->toString() . ' ' . $yd->toString() . ' '
478
+ . $xLeft->toString() . ' ' . $yC->toString() . " c\n"
479
+ . $xLeft->toString() . ' ' . $yu->toString() . ' '
480
+ . $xl->toString() . ' ' . $yUp->toString() . ' '
481
+ . $xC->toString() . ' ' . $yUp->toString() . " c\n"
482
+ . "h\nW\nn\n";
483
+
484
+ return $this;
485
+ }
486
+
487
+ /**
488
+ * Intersect current clipping area with a polygon.
489
+ *
490
+ * @param array $x - array of float (the X co-ordinates of the vertices)
491
+ * @param array $y - array of float (the Y co-ordinates of the vertices)
492
+ * @param integer $fillMethod
493
+ * @return Zend_Pdf_Canvas_Interface
494
+ */
495
+ public function clipPolygon($x, $y, $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING)
496
+ {
497
+ $this->_addProcSet('PDF');
498
+
499
+ $firstPoint = true;
500
+ foreach ($x as $id => $xVal) {
501
+ $xObj = new Zend_Pdf_Element_Numeric($xVal);
502
+ $yObj = new Zend_Pdf_Element_Numeric($y[$id]);
503
+
504
+ if ($firstPoint) {
505
+ $path = $xObj->toString() . ' ' . $yObj->toString() . " m\n";
506
+ $firstPoint = false;
507
+ } else {
508
+ $path .= $xObj->toString() . ' ' . $yObj->toString() . " l\n";
509
+ }
510
+ }
511
+
512
+ $this->_contents .= $path;
513
+
514
+ if ($fillMethod == Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING) {
515
+ $this->_contents .= " h\n W\nn\n";
516
+ } else {
517
+ // Even-Odd fill method.
518
+ $this->_contents .= " h\n W*\nn\n";
519
+ }
520
+
521
+ return $this;
522
+ }
523
+
524
+ /**
525
+ * Intersect current clipping area with a rectangle.
526
+ *
527
+ * @param float $x1
528
+ * @param float $y1
529
+ * @param float $x2
530
+ * @param float $y2
531
+ * @return Zend_Pdf_Canvas_Interface
532
+ */
533
+ public function clipRectangle($x1, $y1, $x2, $y2)
534
+ {
535
+ $this->_addProcSet('PDF');
536
+
537
+ $x1Obj = new Zend_Pdf_Element_Numeric($x1);
538
+ $y1Obj = new Zend_Pdf_Element_Numeric($y1);
539
+ $widthObj = new Zend_Pdf_Element_Numeric($x2 - $x1);
540
+ $height2Obj = new Zend_Pdf_Element_Numeric($y2 - $y1);
541
+
542
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
543
+ . $widthObj->toString() . ' ' . $height2Obj->toString() . " re\n"
544
+ . " W\nn\n";
545
+
546
+ return $this;
547
+ }
548
+
549
+ // ------------------------------------------------------------------------------------------
550
+ /**
551
+ * Draw a circle centered on x, y with a radius of radius.
552
+ *
553
+ * Method signatures:
554
+ * drawCircle($x, $y, $radius);
555
+ * drawCircle($x, $y, $radius, $fillType);
556
+ * drawCircle($x, $y, $radius, $startAngle, $endAngle);
557
+ * drawCircle($x, $y, $radius, $startAngle, $endAngle, $fillType);
558
+ *
559
+ *
560
+ * It's not a really circle, because PDF supports only cubic Bezier curves.
561
+ * But _very_ good approximation.
562
+ * It differs from a real circle on a maximum 0.00026 radiuses
563
+ * (at PI/8, 3*PI/8, 5*PI/8, 7*PI/8, 9*PI/8, 11*PI/8, 13*PI/8 and 15*PI/8 angles).
564
+ * At 0, PI/4, PI/2, 3*PI/4, PI, 5*PI/4, 3*PI/2 and 7*PI/4 it's exactly a tangent to a circle.
565
+ *
566
+ * @param float $x
567
+ * @param float $y
568
+ * @param float $radius
569
+ * @param mixed $param4
570
+ * @param mixed $param5
571
+ * @param mixed $param6
572
+ * @return Zend_Pdf_Canvas_Interface
573
+ */
574
+ public function drawCircle($x, $y, $radius, $param4 = null, $param5 = null, $param6 = null)
575
+ {
576
+ $this->drawEllipse($x - $radius, $y - $radius,
577
+ $x + $radius, $y + $radius,
578
+ $param4, $param5, $param6);
579
+
580
+ return $this;
581
+ }
582
+
583
+ /**
584
+ * Draw an ellipse inside the specified rectangle.
585
+ *
586
+ * Method signatures:
587
+ * drawEllipse($x1, $y1, $x2, $y2);
588
+ * drawEllipse($x1, $y1, $x2, $y2, $fillType);
589
+ * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
590
+ * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle, $fillType);
591
+ *
592
+ * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
593
+ *
594
+ * @param float $x1
595
+ * @param float $y1
596
+ * @param float $x2
597
+ * @param float $y2
598
+ * @param mixed $param5
599
+ * @param mixed $param6
600
+ * @param mixed $param7
601
+ * @return Zend_Pdf_Canvas_Interface
602
+ */
603
+ public function drawEllipse($x1, $y1, $x2, $y2, $param5 = null, $param6 = null, $param7 = null)
604
+ {
605
+ if ($param5 === null) {
606
+ // drawEllipse($x1, $y1, $x2, $y2);
607
+ $startAngle = null;
608
+ $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE;
609
+ } else if ($param6 === null) {
610
+ // drawEllipse($x1, $y1, $x2, $y2, $fillType);
611
+ $startAngle = null;
612
+ $fillType = $param5;
613
+ } else {
614
+ // drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
615
+ // drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle, $fillType);
616
+ $startAngle = $param5;
617
+ $endAngle = $param6;
618
+
619
+ if ($param7 === null) {
620
+ $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE;
621
+ } else {
622
+ $fillType = $param7;
623
+ }
624
+ }
625
+
626
+ $this->_addProcSet('PDF');
627
+
628
+ if ($x2 < $x1) {
629
+ $temp = $x1;
630
+ $x1 = $x2;
631
+ $x2 = $temp;
632
+ }
633
+ if ($y2 < $y1) {
634
+ $temp = $y1;
635
+ $y1 = $y2;
636
+ $y2 = $temp;
637
+ }
638
+
639
+ $x = ($x1 + $x2)/2.;
640
+ $y = ($y1 + $y2)/2.;
641
+
642
+ $xC = new Zend_Pdf_Element_Numeric($x);
643
+ $yC = new Zend_Pdf_Element_Numeric($y);
644
+
645
+ if ($startAngle !== null) {
646
+ if ($startAngle != 0) { $startAngle = fmod($startAngle, M_PI*2); }
647
+ if ($endAngle != 0) { $endAngle = fmod($endAngle, M_PI*2); }
648
+
649
+ if ($startAngle > $endAngle) {
650
+ $endAngle += M_PI*2;
651
+ }
652
+
653
+ $clipPath = $xC->toString() . ' ' . $yC->toString() . " m\n";
654
+ $clipSectors = (int)ceil(($endAngle - $startAngle)/M_PI_4);
655
+ $clipRadius = max($x2 - $x1, $y2 - $y1);
656
+
657
+ for($count = 0; $count <= $clipSectors; $count++) {
658
+ $pAngle = $startAngle + ($endAngle - $startAngle)*$count/(float)$clipSectors;
659
+
660
+ $pX = new Zend_Pdf_Element_Numeric($x + cos($pAngle)*$clipRadius);
661
+ $pY = new Zend_Pdf_Element_Numeric($y + sin($pAngle)*$clipRadius);
662
+ $clipPath .= $pX->toString() . ' ' . $pY->toString() . " l\n";
663
+ }
664
+
665
+ $this->_contents .= "q\n" . $clipPath . "h\nW\nn\n";
666
+ }
667
+
668
+ $xLeft = new Zend_Pdf_Element_Numeric($x1);
669
+ $xRight = new Zend_Pdf_Element_Numeric($x2);
670
+ $yUp = new Zend_Pdf_Element_Numeric($y2);
671
+ $yDown = new Zend_Pdf_Element_Numeric($y1);
672
+
673
+ $xDelta = 2*(M_SQRT2 - 1)*($x2 - $x1)/3.;
674
+ $yDelta = 2*(M_SQRT2 - 1)*($y2 - $y1)/3.;
675
+ $xr = new Zend_Pdf_Element_Numeric($x + $xDelta);
676
+ $xl = new Zend_Pdf_Element_Numeric($x - $xDelta);
677
+ $yu = new Zend_Pdf_Element_Numeric($y + $yDelta);
678
+ $yd = new Zend_Pdf_Element_Numeric($y - $yDelta);
679
+
680
+ $this->_contents .= $xC->toString() . ' ' . $yUp->toString() . " m\n"
681
+ . $xr->toString() . ' ' . $yUp->toString() . ' '
682
+ . $xRight->toString() . ' ' . $yu->toString() . ' '
683
+ . $xRight->toString() . ' ' . $yC->toString() . " c\n"
684
+ . $xRight->toString() . ' ' . $yd->toString() . ' '
685
+ . $xr->toString() . ' ' . $yDown->toString() . ' '
686
+ . $xC->toString() . ' ' . $yDown->toString() . " c\n"
687
+ . $xl->toString() . ' ' . $yDown->toString() . ' '
688
+ . $xLeft->toString() . ' ' . $yd->toString() . ' '
689
+ . $xLeft->toString() . ' ' . $yC->toString() . " c\n"
690
+ . $xLeft->toString() . ' ' . $yu->toString() . ' '
691
+ . $xl->toString() . ' ' . $yUp->toString() . ' '
692
+ . $xC->toString() . ' ' . $yUp->toString() . " c\n";
693
+
694
+ switch ($fillType) {
695
+ case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
696
+ $this->_contents .= " B*\n";
697
+ break;
698
+ case Zend_Pdf_Page::SHAPE_DRAW_FILL:
699
+ $this->_contents .= " f*\n";
700
+ break;
701
+ case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
702
+ $this->_contents .= " S\n";
703
+ break;
704
+ }
705
+
706
+ if ($startAngle !== null) {
707
+ $this->_contents .= "Q\n";
708
+ }
709
+
710
+ return $this;
711
+ }
712
+
713
+ /**
714
+ * Draw an image at the specified position on the page.
715
+ *
716
+ * @param Zend_Pdf_Image $image
717
+ * @param float $x1
718
+ * @param float $y1
719
+ * @param float $x2
720
+ * @param float $y2
721
+ * @return Zend_Pdf_Canvas_Interface
722
+ */
723
+ public function drawImage(Zend_Pdf_Resource_Image $image, $x1, $y1, $x2, $y2)
724
+ {
725
+ $this->_addProcSet('PDF');
726
+
727
+ $imageName = $this->_attachResource('XObject', $image);
728
+ $imageNameObj = new Zend_Pdf_Element_Name($imageName);
729
+
730
+ $x1Obj = new Zend_Pdf_Element_Numeric($x1);
731
+ $y1Obj = new Zend_Pdf_Element_Numeric($y1);
732
+ $widthObj = new Zend_Pdf_Element_Numeric($x2 - $x1);
733
+ $heightObj = new Zend_Pdf_Element_Numeric($y2 - $y1);
734
+
735
+ $this->_contents .= "q\n"
736
+ . '1 0 0 1 ' . $x1Obj->toString() . ' ' . $y1Obj->toString() . " cm\n"
737
+ . $widthObj->toString() . ' 0 0 ' . $heightObj->toString() . " 0 0 cm\n"
738
+ . $imageNameObj->toString() . " Do\n"
739
+ . "Q\n";
740
+
741
+ return $this;
742
+ }
743
+
744
+ /**
745
+ * Draw a LayoutBox at the specified position on the page.
746
+ *
747
+ * @internal (not implemented now)
748
+ *
749
+ * @param Zend_Pdf_Element_LayoutBox $box
750
+ * @param float $x
751
+ * @param float $y
752
+ * @return Zend_Pdf_Canvas_Interface
753
+ */
754
+ public function drawLayoutBox($box, $x, $y)
755
+ {
756
+ /** @todo implementation */
757
+ return $this;
758
+ }
759
+
760
+ /**
761
+ * Draw a line from x1,y1 to x2,y2.
762
+ *
763
+ * @param float $x1
764
+ * @param float $y1
765
+ * @param float $x2
766
+ * @param float $y2
767
+ * @return Zend_Pdf_Canvas_Interface
768
+ */
769
+ public function drawLine($x1, $y1, $x2, $y2)
770
+ {
771
+ $this->_addProcSet('PDF');
772
+
773
+ $x1Obj = new Zend_Pdf_Element_Numeric($x1);
774
+ $y1Obj = new Zend_Pdf_Element_Numeric($y1);
775
+ $x2Obj = new Zend_Pdf_Element_Numeric($x2);
776
+ $y2Obj = new Zend_Pdf_Element_Numeric($y2);
777
+
778
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " m\n"
779
+ . $x2Obj->toString() . ' ' . $y2Obj->toString() . " l\n S\n";
780
+
781
+ return $this;
782
+ }
783
+
784
+ /**
785
+ * Draw a polygon.
786
+ *
787
+ * If $fillType is Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE or
788
+ * Zend_Pdf_Page::SHAPE_DRAW_FILL, then polygon is automatically closed.
789
+ * See detailed description of these methods in a PDF documentation
790
+ * (section 4.4.2 Path painting Operators, Filling)
791
+ *
792
+ * @param array $x - array of float (the X co-ordinates of the vertices)
793
+ * @param array $y - array of float (the Y co-ordinates of the vertices)
794
+ * @param integer $fillType
795
+ * @param integer $fillMethod
796
+ * @return Zend_Pdf_Canvas_Interface
797
+ */
798
+ public function drawPolygon($x, $y,
799
+ $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE,
800
+ $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING)
801
+ {
802
+ $this->_addProcSet('PDF');
803
+
804
+ $firstPoint = true;
805
+ foreach ($x as $id => $xVal) {
806
+ $xObj = new Zend_Pdf_Element_Numeric($xVal);
807
+ $yObj = new Zend_Pdf_Element_Numeric($y[$id]);
808
+
809
+ if ($firstPoint) {
810
+ $path = $xObj->toString() . ' ' . $yObj->toString() . " m\n";
811
+ $firstPoint = false;
812
+ } else {
813
+ $path .= $xObj->toString() . ' ' . $yObj->toString() . " l\n";
814
+ }
815
+ }
816
+
817
+ $this->_contents .= $path;
818
+
819
+ switch ($fillType) {
820
+ case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
821
+ if ($fillMethod == Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING) {
822
+ $this->_contents .= " b\n";
823
+ } else {
824
+ // Even-Odd fill method.
825
+ $this->_contents .= " b*\n";
826
+ }
827
+ break;
828
+ case Zend_Pdf_Page::SHAPE_DRAW_FILL:
829
+ if ($fillMethod == Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING) {
830
+ $this->_contents .= " h\n f\n";
831
+ } else {
832
+ // Even-Odd fill method.
833
+ $this->_contents .= " h\n f*\n";
834
+ }
835
+ break;
836
+ case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
837
+ $this->_contents .= " S\n";
838
+ break;
839
+ }
840
+
841
+ return $this;
842
+ }
843
+
844
+ /**
845
+ * Draw a rectangle.
846
+ *
847
+ * Fill types:
848
+ * Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
849
+ * Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
850
+ * Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
851
+ *
852
+ * @param float $x1
853
+ * @param float $y1
854
+ * @param float $x2
855
+ * @param float $y2
856
+ * @param integer $fillType
857
+ * @return Zend_Pdf_Canvas_Interface
858
+ */
859
+ public function drawRectangle($x1, $y1, $x2, $y2, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)
860
+ {
861
+ $this->_addProcSet('PDF');
862
+
863
+ $x1Obj = new Zend_Pdf_Element_Numeric($x1);
864
+ $y1Obj = new Zend_Pdf_Element_Numeric($y1);
865
+ $widthObj = new Zend_Pdf_Element_Numeric($x2 - $x1);
866
+ $height2Obj = new Zend_Pdf_Element_Numeric($y2 - $y1);
867
+
868
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
869
+ . $widthObj->toString() . ' ' . $height2Obj->toString() . " re\n";
870
+
871
+ switch ($fillType) {
872
+ case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
873
+ $this->_contents .= " B*\n";
874
+ break;
875
+ case Zend_Pdf_Page::SHAPE_DRAW_FILL:
876
+ $this->_contents .= " f*\n";
877
+ break;
878
+ case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
879
+ $this->_contents .= " S\n";
880
+ break;
881
+ }
882
+
883
+ return $this;
884
+ }
885
+
886
+ /**
887
+ * Draw a rounded rectangle.
888
+ *
889
+ * Fill types:
890
+ * Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
891
+ * Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
892
+ * Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
893
+ *
894
+ * radius is an integer representing radius of the four corners, or an array
895
+ * of four integers representing the radius starting at top left, going
896
+ * clockwise
897
+ *
898
+ * @param float $x1
899
+ * @param float $y1
900
+ * @param float $x2
901
+ * @param float $y2
902
+ * @param integer|array $radius
903
+ * @param integer $fillType
904
+ * @return Zend_Pdf_Canvas_Interface
905
+ */
906
+ public function drawRoundedRectangle($x1, $y1, $x2, $y2, $radius,
907
+ $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)
908
+ {
909
+
910
+ $this->_addProcSet('PDF');
911
+
912
+ if(!is_array($radius)) {
913
+ $radius = array($radius, $radius, $radius, $radius);
914
+ } else {
915
+ for ($i = 0; $i < 4; $i++) {
916
+ if(!isset($radius[$i])) {
917
+ $radius[$i] = 0;
918
+ }
919
+ }
920
+ }
921
+
922
+ $topLeftX = $x1;
923
+ $topLeftY = $y2;
924
+ $topRightX = $x2;
925
+ $topRightY = $y2;
926
+ $bottomRightX = $x2;
927
+ $bottomRightY = $y1;
928
+ $bottomLeftX = $x1;
929
+ $bottomLeftY = $y1;
930
+
931
+ //draw top side
932
+ $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX + $radius[0]);
933
+ $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY);
934
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " m\n";
935
+ $x1Obj = new Zend_Pdf_Element_Numeric($topRightX - $radius[1]);
936
+ $y1Obj = new Zend_Pdf_Element_Numeric($topRightY);
937
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
938
+
939
+ //draw top right corner if needed
940
+ if ($radius[1] != 0) {
941
+ $x1Obj = new Zend_Pdf_Element_Numeric($topRightX);
942
+ $y1Obj = new Zend_Pdf_Element_Numeric($topRightY);
943
+ $x2Obj = new Zend_Pdf_Element_Numeric($topRightX);
944
+ $y2Obj = new Zend_Pdf_Element_Numeric($topRightY);
945
+ $x3Obj = new Zend_Pdf_Element_Numeric($topRightX);
946
+ $y3Obj = new Zend_Pdf_Element_Numeric($topRightY - $radius[1]);
947
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
948
+ . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
949
+ . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
950
+ . " c\n";
951
+ }
952
+
953
+ //draw right side
954
+ $x1Obj = new Zend_Pdf_Element_Numeric($bottomRightX);
955
+ $y1Obj = new Zend_Pdf_Element_Numeric($bottomRightY + $radius[2]);
956
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
957
+
958
+ //draw bottom right corner if needed
959
+ if ($radius[2] != 0) {
960
+ $x1Obj = new Zend_Pdf_Element_Numeric($bottomRightX);
961
+ $y1Obj = new Zend_Pdf_Element_Numeric($bottomRightY);
962
+ $x2Obj = new Zend_Pdf_Element_Numeric($bottomRightX);
963
+ $y2Obj = new Zend_Pdf_Element_Numeric($bottomRightY);
964
+ $x3Obj = new Zend_Pdf_Element_Numeric($bottomRightX - $radius[2]);
965
+ $y3Obj = new Zend_Pdf_Element_Numeric($bottomRightY);
966
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
967
+ . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
968
+ . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
969
+ . " c\n";
970
+ }
971
+
972
+ //draw bottom side
973
+ $x1Obj = new Zend_Pdf_Element_Numeric($bottomLeftX + $radius[3]);
974
+ $y1Obj = new Zend_Pdf_Element_Numeric($bottomLeftY);
975
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
976
+
977
+ //draw bottom left corner if needed
978
+ if ($radius[3] != 0) {
979
+ $x1Obj = new Zend_Pdf_Element_Numeric($bottomLeftX);
980
+ $y1Obj = new Zend_Pdf_Element_Numeric($bottomLeftY);
981
+ $x2Obj = new Zend_Pdf_Element_Numeric($bottomLeftX);
982
+ $y2Obj = new Zend_Pdf_Element_Numeric($bottomLeftY);
983
+ $x3Obj = new Zend_Pdf_Element_Numeric($bottomLeftX);
984
+ $y3Obj = new Zend_Pdf_Element_Numeric($bottomLeftY + $radius[3]);
985
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
986
+ . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
987
+ . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
988
+ . " c\n";
989
+ }
990
+
991
+ //draw left side
992
+ $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX);
993
+ $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY - $radius[0]);
994
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
995
+
996
+ //draw top left corner if needed
997
+ if ($radius[0] != 0) {
998
+ $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX);
999
+ $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY);
1000
+ $x2Obj = new Zend_Pdf_Element_Numeric($topLeftX);
1001
+ $y2Obj = new Zend_Pdf_Element_Numeric($topLeftY);
1002
+ $x3Obj = new Zend_Pdf_Element_Numeric($topLeftX + $radius[0]);
1003
+ $y3Obj = new Zend_Pdf_Element_Numeric($topLeftY);
1004
+ $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
1005
+ . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
1006
+ . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
1007
+ . " c\n";
1008
+ }
1009
+
1010
+ switch ($fillType) {
1011
+ case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
1012
+ $this->_contents .= " B*\n";
1013
+ break;
1014
+ case Zend_Pdf_Page::SHAPE_DRAW_FILL:
1015
+ $this->_contents .= " f*\n";
1016
+ break;
1017
+ case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
1018
+ $this->_contents .= " S\n";
1019
+ break;
1020
+ }
1021
+
1022
+ return $this;
1023
+ }
1024
+
1025
+ /**
1026
+ * Draw a line of text at the specified position.
1027
+ *
1028
+ * @param string $text
1029
+ * @param float $x
1030
+ * @param float $y
1031
+ * @param string $charEncoding (optional) Character encoding of source text.
1032
+ * Defaults to current locale.
1033
+ * @throws Zend_Pdf_Exception
1034
+ * @return Zend_Pdf_Canvas_Interface
1035
+ */
1036
+ public function drawText($text, $x, $y, $charEncoding = '')
1037
+ {
1038
+ if ($this->_font === null) {
1039
+ #require_once 'Zend/Pdf/Exception.php';
1040
+ throw new Zend_Pdf_Exception('Font has not been set');
1041
+ }
1042
+
1043
+ $this->_addProcSet('Text');
1044
+
1045
+ $textObj = new Zend_Pdf_Element_String($this->_font->encodeString($text, $charEncoding));
1046
+ $xObj = new Zend_Pdf_Element_Numeric($x);
1047
+ $yObj = new Zend_Pdf_Element_Numeric($y);
1048
+
1049
+ $this->_contents .= "BT\n"
1050
+ . $xObj->toString() . ' ' . $yObj->toString() . " Td\n"
1051
+ . $textObj->toString() . " Tj\n"
1052
+ . "ET\n";
1053
+
1054
+ return $this;
1055
+ }
1056
+
1057
+ /**
1058
+ * Close the path by drawing a straight line back to it's beginning.
1059
+ *
1060
+ * @internal (needs implementation)
1061
+ *
1062
+ * @throws Zend_Pdf_Exception - if a path hasn't been started with pathMove()
1063
+ * @return Zend_Pdf_Canvas_Interface
1064
+ */
1065
+ public function pathClose()
1066
+ {
1067
+ /** @todo implementation */
1068
+ return $this;
1069
+ }
1070
+
1071
+ /**
1072
+ * Continue the open path in a straight line to the specified position.
1073
+ *
1074
+ * @internal (needs implementation)
1075
+ *
1076
+ * @param float $x - the X co-ordinate to move to
1077
+ * @param float $y - the Y co-ordinate to move to
1078
+ * @return Zend_Pdf_Canvas_Interface
1079
+ */
1080
+ public function pathLine($x, $y)
1081
+ {
1082
+ /** @todo implementation */
1083
+ return $this;
1084
+ }
1085
+
1086
+ /**
1087
+ * Start a new path at the specified position. If a path has already been started,
1088
+ * move the cursor without drawing a line.
1089
+ *
1090
+ * @internal (needs implementation)
1091
+ *
1092
+ * @param float $x - the X co-ordinate to move to
1093
+ * @param float $y - the Y co-ordinate to move to
1094
+ * @return Zend_Pdf_Canvas_Interface
1095
+ */
1096
+ public function pathMove($x, $y)
1097
+ {
1098
+ /** @todo implementation */
1099
+ return $this;
1100
+ }
1101
+
1102
+ /**
1103
+ * Rotate the page.
1104
+ *
1105
+ * @param float $x - the X co-ordinate of rotation point
1106
+ * @param float $y - the Y co-ordinate of rotation point
1107
+ * @param float $angle - rotation angle
1108
+ * @return Zend_Pdf_Canvas_Interface
1109
+ */
1110
+ public function rotate($x, $y, $angle)
1111
+ {
1112
+ $cos = new Zend_Pdf_Element_Numeric(cos($angle));
1113
+ $sin = new Zend_Pdf_Element_Numeric(sin($angle));
1114
+ $mSin = new Zend_Pdf_Element_Numeric(-$sin->value);
1115
+
1116
+ $xObj = new Zend_Pdf_Element_Numeric($x);
1117
+ $yObj = new Zend_Pdf_Element_Numeric($y);
1118
+
1119
+ $mXObj = new Zend_Pdf_Element_Numeric(-$x);
1120
+ $mYObj = new Zend_Pdf_Element_Numeric(-$y);
1121
+
1122
+
1123
+ $this->_addProcSet('PDF');
1124
+ $this->_contents .= '1 0 0 1 ' . $xObj->toString() . ' ' . $yObj->toString() . " cm\n"
1125
+ . $cos->toString() . ' ' . $sin->toString() . ' ' . $mSin->toString() . ' ' . $cos->toString() . " 0 0 cm\n"
1126
+ . '1 0 0 1 ' . $mXObj->toString() . ' ' . $mYObj->toString() . " cm\n";
1127
+
1128
+ return $this;
1129
+ }
1130
+
1131
+ /**
1132
+ * Scale coordination system.
1133
+ *
1134
+ * @param float $xScale - X dimention scale factor
1135
+ * @param float $yScale - Y dimention scale factor
1136
+ * @return Zend_Pdf_Canvas_Interface
1137
+ */
1138
+ public function scale($xScale, $yScale)
1139
+ {
1140
+ $xScaleObj = new Zend_Pdf_Element_Numeric($xScale);
1141
+ $yScaleObj = new Zend_Pdf_Element_Numeric($yScale);
1142
+
1143
+ $this->_addProcSet('PDF');
1144
+ $this->_contents .= $xScaleObj->toString() . ' 0 0 ' . $yScaleObj->toString() . " 0 0 cm\n";
1145
+
1146
+ return $this;
1147
+ }
1148
+
1149
+ /**
1150
+ * Translate coordination system.
1151
+ *
1152
+ * @param float $xShift - X coordinate shift
1153
+ * @param float $yShift - Y coordinate shift
1154
+ * @return Zend_Pdf_Canvas_Interface
1155
+ */
1156
+ public function translate($xShift, $yShift)
1157
+ {
1158
+ $xShiftObj = new Zend_Pdf_Element_Numeric($xShift);
1159
+ $yShiftObj = new Zend_Pdf_Element_Numeric($yShift);
1160
+
1161
+ $this->_addProcSet('PDF');
1162
+ $this->_contents .= '1 0 0 1 ' . $xShiftObj->toString() . ' ' . $yShiftObj->toString() . " cm\n";
1163
+
1164
+ return $this;
1165
+ }
1166
+
1167
+ /**
1168
+ * Translate coordination system.
1169
+ *
1170
+ * @param float $x - the X co-ordinate of axis skew point
1171
+ * @param float $y - the Y co-ordinate of axis skew point
1172
+ * @param float $xAngle - X axis skew angle
1173
+ * @param float $yAngle - Y axis skew angle
1174
+ * @return Zend_Pdf_Canvas_Interface
1175
+ */
1176
+ public function skew($x, $y, $xAngle, $yAngle)
1177
+ {
1178
+ $tanXObj = new Zend_Pdf_Element_Numeric(tan($xAngle));
1179
+ $tanYObj = new Zend_Pdf_Element_Numeric(-tan($yAngle));
1180
+
1181
+ $xObj = new Zend_Pdf_Element_Numeric($x);
1182
+ $yObj = new Zend_Pdf_Element_Numeric($y);
1183
+
1184
+ $mXObj = new Zend_Pdf_Element_Numeric(-$x);
1185
+ $mYObj = new Zend_Pdf_Element_Numeric(-$y);
1186
+
1187
+ $this->_addProcSet('PDF');
1188
+ $this->_contents .= '1 0 0 1 ' . $xObj->toString() . ' ' . $yObj->toString() . " cm\n"
1189
+ . '1 ' . $tanXObj->toString() . ' ' . $tanYObj->toString() . " 1 0 0 cm\n"
1190
+ . '1 0 0 1 ' . $mXObj->toString() . ' ' . $mYObj->toString() . " cm\n";
1191
+
1192
+ return $this;
1193
+ }
1194
+
1195
+ /**
1196
+ * Writes the raw data to the page's content stream.
1197
+ *
1198
+ * Be sure to consult the PDF reference to ensure your syntax is correct. No
1199
+ * attempt is made to ensure the validity of the stream data.
1200
+ *
1201
+ * @param string $data
1202
+ * @param string $procSet (optional) Name of ProcSet to add.
1203
+ * @return Zend_Pdf_Canvas_Interface
1204
+ */
1205
+ public function rawWrite($data, $procSet = null)
1206
+ {
1207
+ if (! empty($procSet)) {
1208
+ $this->_addProcSet($procSet);
1209
+ }
1210
+ $this->_contents .= $data;
1211
+
1212
+ return $this;
1213
+ }
1214
+ }
lib/Zend/Pdf/Canvas/Interface.php ADDED
@@ -0,0 +1,493 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Pdf
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $
20
+ */
21
+
22
+
23
+ /**
24
+ * Canvas is an abstract rectangle drawing area which can be dropped into
25
+ * page object at specified place.
26
+ *
27
+ * @package Zend_Pdf
28
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
29
+ * @license http://framework.zend.com/license/new-bsd New BSD License
30
+ */
31
+ interface Zend_Pdf_Canvas_Interface
32
+ {
33
+ /**
34
+ * Returns dictionaries of used resources.
35
+ *
36
+ * Used for canvas implementations interoperability
37
+ *
38
+ * Structure of the returned array:
39
+ * array(
40
+ * <resTypeName> => array(
41
+ * <resName> => <Zend_Pdf_Resource object>,
42
+ * <resName> => <Zend_Pdf_Resource object>,
43
+ * <resName> => <Zend_Pdf_Resource object>,
44
+ * ...
45
+ * ),
46
+ * <resTypeName> => array(
47
+ * <resName> => <Zend_Pdf_Resource object>,
48
+ * <resName> => <Zend_Pdf_Resource object>,
49
+ * <resName> => <Zend_Pdf_Resource object>,
50
+ * ...
51
+ * ),
52
+ * ...
53
+ * 'ProcSet' => array()
54
+ * )
55
+ *
56
+ * where ProcSet array is a list of used procedure sets names (strings).
57
+ * Allowed procedure set names: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'
58
+ *
59
+ * @internal
60
+ * @return array
61
+ */
62
+ public function getResources();
63
+
64
+ /**
65
+ * Get drawing instructions stream
66
+ *
67
+ * It has to be returned as a PDF stream object to make it reusable.
68
+ *
69
+ * @internal
70
+ * @returns Zend_Pdf_Resource_ContentStream
71
+ */
72
+ public function getContents();
73
+
74
+ /**
75
+ * Return canvas height.
76
+ *
77
+ * @return float
78
+ */
79
+ public function getHeight();
80
+
81
+ /**
82
+ * Return canvas width.
83
+ *
84
+ * @return float
85
+ */
86
+ public function getWidth();
87
+
88
+ /**
89
+ * Draw a canvas at the specified location
90
+ *
91
+ * If upper right corner is not specified then canvas heght and width
92
+ * are used.
93
+ *
94
+ * @param Zend_Pdf_Canvas_Interface $canvas
95
+ * @param float $x1
96
+ * @param float $y1
97
+ * @param float $x2
98
+ * @param float $y2
99
+ * @return Zend_Pdf_Canvas_Interface
100
+ */
101
+ public function drawCanvas(Zend_Pdf_Canvas_Interface $canvas, $x1, $y1, $x2 = null, $y2 = null);
102
+
103
+ /**
104
+ * Set fill color.
105
+ *
106
+ * @param Zend_Pdf_Color $color
107
+ * @return Zend_Pdf_Canvas_Interface
108
+ */
109
+ public function setFillColor(Zend_Pdf_Color $color);
110
+
111
+ /**
112
+ * Set line color.
113
+ *
114
+ * @param Zend_Pdf_Color $color
115
+ * @return Zend_Pdf_Canvas_Interface
116
+ */
117
+ public function setLineColor(Zend_Pdf_Color $color);
118
+
119
+ /**
120
+ * Set line width.
121
+ *
122
+ * @param float $width
123
+ * @return Zend_Pdf_Canvas_Interface
124
+ */
125
+ public function setLineWidth($width);
126
+
127
+ /**
128
+ * Set line dashing pattern
129
+ *
130
+ * Pattern is an array of floats: array(on_length, off_length, on_length, off_length, ...)
131
+ * or Zend_Pdf_Page::LINE_DASHING_SOLID constant
132
+ * Phase is shift from the beginning of line.
133
+ *
134
+ * @param mixed $pattern
135
+ * @param array $phase
136
+ * @return Zend_Pdf_Canvas_Interface
137
+ */
138
+ public function setLineDashingPattern($pattern, $phase = 0);
139
+
140
+ /**
141
+ * Set current font.
142
+ *
143
+ * @param Zend_Pdf_Resource_Font $font
144
+ * @param float $fontSize
145
+ * @return Zend_Pdf_Canvas_Interface
146
+ */
147
+ public function setFont(Zend_Pdf_Resource_Font $font, $fontSize);
148
+
149
+ /**
150
+ * Set the style to use for future drawing operations on this page
151
+ *
152
+ * @param Zend_Pdf_Style $style
153
+ * @return Zend_Pdf_Canvas_Interface
154
+ */
155
+ public function setStyle(Zend_Pdf_Style $style);
156
+
157
+ /**
158
+ * Get current font.
159
+ *
160
+ * @return Zend_Pdf_Resource_Font $font
161
+ */
162
+ public function getFont();
163
+
164
+ /**
165
+ * Get current font size
166
+ *
167
+ * @return float $fontSize
168
+ */
169
+ public function getFontSize();
170
+
171
+ /**
172
+ * Return the style, applied to the page.
173
+ *
174
+ * @return Zend_Pdf_Style|null
175
+ */
176
+ public function getStyle();
177
+
178
+ /**
179
+ * Save the graphics state of this page.
180
+ * This takes a snapshot of the currently applied style, position, clipping area and
181
+ * any rotation/translation/scaling that has been applied.
182
+ *
183
+ * @throws Zend_Pdf_Exception - if a save is performed with an open path
184
+ * @return Zend_Pdf_Page
185
+ */
186
+ public function saveGS();
187
+
188
+ /**
189
+ * Set the transparancy
190
+ *
191
+ * $alpha == 0 - transparent
192
+ * $alpha == 1 - opaque
193
+ *
194
+ * Transparency modes, supported by PDF:
195
+ * Normal (default), Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight,
196
+ * SoftLight, Difference, Exclusion
197
+ *
198
+ * @param float $alpha
199
+ * @param string $mode
200
+ * @throws Zend_Pdf_Exception
201
+ * @return Zend_Pdf_Canvas_Interface
202
+ */
203
+ public function setAlpha($alpha, $mode = 'Normal');
204
+
205
+ /**
206
+ * Intersect current clipping area with a circle.
207
+ *
208
+ * @param float $x
209
+ * @param float $y
210
+ * @param float $radius
211
+ * @param float $startAngle
212
+ * @param float $endAngle
213
+ * @return Zend_Pdf_Canvas_Interface
214
+ */
215
+ public function clipCircle($x, $y, $radius, $startAngle = null, $endAngle = null);
216
+
217
+ /**
218
+ * Intersect current clipping area with a polygon.
219
+ *
220
+ * Method signatures:
221
+ * drawEllipse($x1, $y1, $x2, $y2);
222
+ * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
223
+ *
224
+ * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
225
+ *
226
+ * @param float $x1
227
+ * @param float $y1
228
+ * @param float $x2
229
+ * @param float $y2
230
+ * @param float $startAngle
231
+ * @param float $endAngle
232
+ * @return Zend_Pdf_Canvas_Interface
233
+ */
234
+ public function clipEllipse($x1, $y1, $x2, $y2, $startAngle = null, $endAngle = null);
235
+
236
+ /**
237
+ * Intersect current clipping area with a polygon.
238
+ *
239
+ * @param array $x - array of float (the X co-ordinates of the vertices)
240
+ * @param array $y - array of float (the Y co-ordinates of the vertices)
241
+ * @param integer $fillMethod
242
+ * @return Zend_Pdf_Canvas_Interface
243
+ */
244
+ public function clipPolygon($x, $y, $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING);
245
+
246
+ /**
247
+ * Intersect current clipping area with a rectangle.
248
+ *
249
+ * @param float $x1
250
+ * @param float $y1
251
+ * @param float $x2
252
+ * @param float $y2
253
+ * @return Zend_Pdf_Canvas_Interface
254
+ */
255
+ public function clipRectangle($x1, $y1, $x2, $y2);
256
+
257
+ /**
258
+ * Draw a circle centered on x, y with a radius of radius.
259
+ *
260
+ * Method signatures:
261
+ * drawCircle($x, $y, $radius);
262
+ * drawCircle($x, $y, $radius, $fillType);
263
+ * drawCircle($x, $y, $radius, $startAngle, $endAngle);
264
+ * drawCircle($x, $y, $radius, $startAngle, $endAngle, $fillType);
265
+ *
266
+ *
267
+ * It's not a really circle, because PDF supports only cubic Bezier curves.
268
+ * But _very_ good approximation.
269
+ * It differs from a real circle on a maximum 0.00026 radiuses
270
+ * (at PI/8, 3*PI/8, 5*PI/8, 7*PI/8, 9*PI/8, 11*PI/8, 13*PI/8 and 15*PI/8 angles).
271
+ * At 0, PI/4, PI/2, 3*PI/4, PI, 5*PI/4, 3*PI/2 and 7*PI/4 it's exactly a tangent to a circle.
272
+ *
273
+ * @param float $x
274
+ * @param float $y
275
+ * @param float $radius
276
+ * @param mixed $param4
277
+ * @param mixed $param5
278
+ * @param mixed $param6
279
+ * @return Zend_Pdf_Canvas_Interface
280
+ */
281
+ public function drawCircle($x, $y, $radius, $param4 = null, $param5 = null, $param6 = null);
282
+
283
+ /**
284
+ * Draw an ellipse inside the specified rectangle.
285
+ *
286
+ * Method signatures:
287
+ * drawEllipse($x1, $y1, $x2, $y2);
288
+ * drawEllipse($x1, $y1, $x2, $y2, $fillType);
289
+ * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
290
+ * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle, $fillType);
291
+ *
292
+ * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
293
+ *
294
+ * @param float $x1
295
+ * @param float $y1
296
+ * @param float $x2
297
+ * @param float $y2
298
+ * @param mixed $param5
299
+ * @param mixed $param6
300
+ * @param mixed $param7
301
+ * @return Zend_Pdf_Canvas_Interface
302
+ */
303
+ public function drawEllipse($x1, $y1, $x2, $y2, $param5 = null, $param6 = null, $param7 = null);
304
+
305
+ /**
306
+ * Draw an image at the specified position on the page.
307
+ *
308
+ * @param Zend_Pdf_Image $image
309
+ * @param float $x1
310
+ * @param float $y1
311
+ * @param float $x2
312
+ * @param float $y2
313
+ * @return Zend_Pdf_Canvas_Interface
314
+ */
315
+ public function drawImage(Zend_Pdf_Resource_Image $image, $x1, $y1, $x2, $y2);
316
+
317
+ /**
318
+ * Draw a LayoutBox at the specified position on the page.
319
+ *
320
+ * @internal (not implemented now)
321
+ *
322
+ * @param Zend_Pdf_Element_LayoutBox $box
323
+ * @param float $x
324
+ * @param float $y
325
+ * @return Zend_Pdf_Canvas_Interface
326
+ */
327
+ public function drawLayoutBox($box, $x, $y);
328
+
329
+ /**
330
+ * Draw a line from x1,y1 to x2,y2.
331
+ *
332
+ * @param float $x1
333
+ * @param float $y1
334
+ * @param float $x2
335
+ * @param float $y2
336
+ * @return Zend_Pdf_Canvas_Interface
337
+ */
338
+ public function drawLine($x1, $y1, $x2, $y2);
339
+
340
+ /**
341
+ * Draw a polygon.
342
+ *
343
+ * If $fillType is Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE or
344
+ * Zend_Pdf_Page::SHAPE_DRAW_FILL, then polygon is automatically closed.
345
+ * See detailed description of these methods in a PDF documentation
346
+ * (section 4.4.2 Path painting Operators, Filling)
347
+ *
348
+ * @param array $x - array of float (the X co-ordinates of the vertices)
349
+ * @param array $y - array of float (the Y co-ordinates of the vertices)
350
+ * @param integer $fillType
351
+ * @param integer $fillMethod
352
+ * @return Zend_Pdf_Canvas_Interface
353
+ */
354
+ public function drawPolygon($x, $y,
355
+ $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE,
356
+ $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING);
357
+ /**
358
+ * Draw a rectangle.
359
+ *
360
+ * Fill types:
361
+ * Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
362
+ * Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
363
+ * Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
364
+ *
365
+ * @param float $x1
366
+ * @param float $y1
367
+ * @param float $x2
368
+ * @param float $y2
369
+ * @param integer $fillType
370
+ * @return Zend_Pdf_Canvas_Interface
371
+ */
372
+ public function drawRectangle($x1, $y1, $x2, $y2, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE);
373
+
374
+ /**
375
+ * Draw a rounded rectangle.
376
+ *
377
+ * Fill types:
378
+ * Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
379
+ * Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
380
+ * Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
381
+ *
382
+ * radius is an integer representing radius of the four corners, or an array
383
+ * of four integers representing the radius starting at top left, going
384
+ * clockwise
385
+ *
386
+ * @param float $x1
387
+ * @param float $y1
388
+ * @param float $x2
389
+ * @param float $y2
390
+ * @param integer|array $radius
391
+ * @param integer $fillType
392
+ * @return Zend_Pdf_Canvas_Interface
393
+ */
394
+ public function drawRoundedRectangle($x1, $y1, $x2, $y2, $radius,
395
+ $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE);
396
+
397
+ /**
398
+ * Draw a line of text at the specified position.
399
+ *
400
+ * @param string $text
401
+ * @param float $x
402
+ * @param float $y
403
+ * @param string $charEncoding (optional) Character encoding of source text.
404
+ * Defaults to current locale.
405
+ * @throws Zend_Pdf_Exception
406
+ * @return Zend_Pdf_Canvas_Interface
407
+ */
408
+ public function drawText($text, $x, $y, $charEncoding = '');
409
+
410
+ /**
411
+ * Close the path by drawing a straight line back to it's beginning.
412
+ *
413
+ * @internal (needs implementation)
414
+ *
415
+ * @throws Zend_Pdf_Exception - if a path hasn't been started with pathMove()
416
+ * @return Zend_Pdf_Canvas_Interface
417
+ */
418
+ public function pathClose();
419
+
420
+ /**
421
+ * Continue the open path in a straight line to the specified position.
422
+ *
423
+ * @internal (needs implementation)
424
+ *
425
+ * @param float $x - the X co-ordinate to move to
426
+ * @param float $y - the Y co-ordinate to move to
427
+ * @return Zend_Pdf_Canvas_Interface
428
+ */
429
+ public function pathLine($x, $y);
430
+
431
+ /**
432
+ * Start a new path at the specified position. If a path has already been started,
433
+ * move the cursor without drawing a line.
434
+ *
435
+ * @internal (needs implementation)
436
+ *
437
+ * @param float $x - the X co-ordinate to move to
438
+ * @param float $y - the Y co-ordinate to move to
439
+ * @return Zend_Pdf_Canvas_Interface
440
+ */
441
+ public function pathMove($x, $y);
442
+
443
+ /**
444
+ * Rotate the page.
445
+ *
446
+ * @param float $x - the X co-ordinate of rotation point
447
+ * @param float $y - the Y co-ordinate of rotation point
448
+ * @param float $angle - rotation angle
449
+ * @return Zend_Pdf_Canvas_Interface
450
+ */
451
+ public function rotate($x, $y, $angle);
452
+
453
+ /**
454
+ * Scale coordination system.
455
+ *
456
+ * @param float $xScale - X dimention scale factor
457
+ * @param float $yScale - Y dimention scale factor
458
+ * @return Zend_Pdf_Canvas_Interface
459
+ */
460
+ public function scale($xScale, $yScale);
461
+
462
+ /**
463
+ * Translate coordination system.
464
+ *
465
+ * @param float $xShift - X coordinate shift
466
+ * @param float $yShift - Y coordinate shift
467
+ * @return Zend_Pdf_Canvas_Interface
468
+ */
469
+ public function translate($xShift, $yShift);
470
+
471
+ /**
472
+ * Translate coordination system.
473
+ *
474
+ * @param float $x - the X co-ordinate of axis skew point
475
+ * @param float $y - the Y co-ordinate of axis skew point
476
+ * @param float $xAngle - X axis skew angle
477
+ * @param float $yAngle - Y axis skew angle
478
+ * @return Zend_Pdf_Canvas_Interface
479
+ */
480
+ public function skew($x, $y, $xAngle, $yAngle);
481
+
482
+ /**
483
+ * Writes the raw data to the page's content stream.
484
+ *
485
+ * Be sure to consult the PDF reference to ensure your syntax is correct. No
486
+ * attempt is made to ensure the validity of the stream data.
487
+ *
488
+ * @param string $data
489
+ * @param string $procSet (optional) Name of ProcSet to add.
490
+ * @return Zend_Pdf_Canvas_Interface
491
+ */
492
+ public function rawWrite($data, $procSet = null);
493
+ }
lib/Zend/Pdf/Element.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Element.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -64,6 +64,24 @@ abstract class Zend_Pdf_Element
64
  */
65
  abstract public function toString($factory = null);
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  /**
69
  * Set top level parent indirect object.
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Element.php 22797 2010-08-06 15:02:12Z alexander $
20
  */
21
 
22
 
64
  */
65
  abstract public function toString($factory = null);
66
 
67
+ const CLONE_MODE_SKIP_PAGES = 1; // Do not follow pages during deep copy process
68
+ const CLONE_MODE_FORCE_CLONING = 2; // Force top level object cloning even it's already processed
69
+
70
+ /**
71
+ * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
72
+ *
73
+ * @todo It's nevessry to check if SplObjectStorage class works faster
74
+ * (Needs PHP 5.3.x to attach object _with_ additional data to storage)
75
+ *
76
+ * @param Zend_Pdf_ElementFactory $factory The factory to attach
77
+ * @param array &$processed List of already processed indirect objects, used to avoid objects duplication
78
+ * @param integer $mode Cloning mode (defines filter for objects cloning)
79
+ * @returns Zend_Pdf_Element
80
+ */
81
+ public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
82
+ {
83
+ return clone $this;
84
+ }
85
 
86
  /**
87
  * Set top level parent indirect object.
lib/Zend/Pdf/Element/Array.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Array.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -128,6 +128,39 @@ class Zend_Pdf_Element_Array extends Zend_Pdf_Element
128
  return $outStr;
129
  }
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  /**
132
  * Convert PDF element to PHP type.
133
  *
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Array.php 22797 2010-08-06 15:02:12Z alexander $
20
  */
21
 
22
 
128
  return $outStr;
129
  }
130
 
131
+ /**
132
+ * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
133
+ *
134
+ * @param Zend_Pdf_ElementFactory $factory The factory to attach
135
+ * @param array &$processed List of already processed indirect objects, used to avoid objects duplication
136
+ * @param integer $mode Cloning mode (defines filter for objects cloning)
137
+ * @returns Zend_Pdf_Element
138
+ */
139
+ public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
140
+ {
141
+ $newArray = new self();
142
+
143
+ foreach ($this->items as $key => $value) {
144
+ $newArray->items[$key] = $value->makeClone($factory, $processed, $mode);
145
+ }
146
+
147
+ return $newArray;
148
+ }
149
+
150
+ /**
151
+ * Set top level parent indirect object.
152
+ *
153
+ * @param Zend_Pdf_Element_Object $parent
154
+ */
155
+ public function setParentObject(Zend_Pdf_Element_Object $parent)
156
+ {
157
+ parent::setParentObject($parent);
158
+
159
+ foreach ($this->items as $item) {
160
+ $item->setParentObject($parent);
161
+ }
162
+ }
163
+
164
  /**
165
  * Convert PDF element to PHP type.
166
  *
lib/Zend/Pdf/Element/Dictionary.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Dictionary.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -168,6 +168,53 @@ class Zend_Pdf_Element_Dictionary extends Zend_Pdf_Element
168
  return $outStr;
169
  }
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
  /**
173
  * Convert PDF element to PHP type.
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Dictionary.php 22797 2010-08-06 15:02:12Z alexander $
20
  */
21
 
22
 
168
  return $outStr;
169
  }
170
 
171
+ /**
172
+ * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
173
+ *
174
+ * @param Zend_Pdf_ElementFactory $factory The factory to attach
175
+ * @param array &$processed List of already processed indirect objects, used to avoid objects duplication
176
+ * @param integer $mode Cloning mode (defines filter for objects cloning)
177
+ * @returns Zend_Pdf_Element
178
+ * @throws Zend_Pdf_Exception
179
+ */
180
+ public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
181
+ {
182
+ if (isset($this->_items['Type'])) {
183
+ if ($this->_items['Type']->value == 'Pages') {
184
+ // It's a page tree node
185
+ // skip it and its children
186
+ return new Zend_Pdf_Element_Null();
187
+ }
188
+
189
+ if ($this->_items['Type']->value == 'Page' &&
190
+ $mode == Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES
191
+ ) {
192
+ // It's a page node, skip it
193
+ return new Zend_Pdf_Element_Null();
194
+ }
195
+ }
196
+
197
+ $newDictionary = new self();
198
+ foreach ($this->_items as $key => $value) {
199
+ $newDictionary->_items[$key] = $value->makeClone($factory, $processed, $mode);
200
+ }
201
+
202
+ return $newDictionary;
203
+ }
204
+
205
+ /**
206
+ * Set top level parent indirect object.
207
+ *
208
+ * @param Zend_Pdf_Element_Object $parent
209
+ */
210
+ public function setParentObject(Zend_Pdf_Element_Object $parent)
211
+ {
212
+ parent::setParentObject($parent);
213
+
214
+ foreach ($this->_items as $item) {
215
+ $item->setParentObject($parent);
216
+ }
217
+ }
218
 
219
  /**
220
  * Convert PDF element to PHP type.
lib/Zend/Pdf/Element/Object.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Object.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -211,6 +211,40 @@ class Zend_Pdf_Element_Object extends Zend_Pdf_Element
211
  return call_user_func_array(array($this->_value, $method), $args);
212
  }
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
 
215
  /**
216
  * Mark object as modified, to include it into new PDF file segment
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Object.php 22844 2010-08-16 15:38:53Z alexander $
20
  */
21
 
22
 
211
  return call_user_func_array(array($this->_value, $method), $args);
212
  }
213
 
214
+ /**
215
+ * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
216
+ *
217
+ * @param Zend_Pdf_ElementFactory $factory The factory to attach
218
+ * @param array &$processed List of already processed indirect objects, used to avoid objects duplication
219
+ * @param integer $mode Cloning mode (defines filter for objects cloning)
220
+ * @returns Zend_Pdf_Element
221
+ */
222
+ public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
223
+ {
224
+ $id = spl_object_hash($this);
225
+ if (isset($processed[$id])) {
226
+ // Do nothing if object is already processed
227
+ // return it
228
+ return $processed[$id];
229
+ }
230
+
231
+ // Create obect with null value and register it in $processed container
232
+ $processed[$id] = $clonedObject = $factory->newObject(new Zend_Pdf_Element_Null());
233
+
234
+ // Pecursively process actual data
235
+ $clonedObject->_value = $this->_value->makeClone($factory, $processed, $mode);
236
+
237
+ if ($clonedObject->_value instanceof Zend_Pdf_Element_Null) {
238
+ // Do not store null objects within $processed container since it may be filtered
239
+ // by $mode parameter but used in some future pass
240
+ unset($processed[$id]);
241
+
242
+ // Return direct null object
243
+ return $clonedObject->_value;
244
+ }
245
+
246
+ return $clonedObject;
247
+ }
248
 
249
  /**
250
  * Mark object as modified, to include it into new PDF file segment
lib/Zend/Pdf/Element/Object/Stream.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -57,13 +57,13 @@ class Zend_Pdf_Element_Object_Stream extends Zend_Pdf_Element_Object
57
 
58
  /**
59
  * Stored original stream object dictionary.
60
- * Used to decode stream during an access time.
61
  *
62
- * The only properties, which affect decoding, are sored here.
63
  *
64
  * @var array|null
65
  */
66
- private $_originalDictionary = null;
67
 
68
  /**
69
  * Object constructor
@@ -91,77 +91,80 @@ class Zend_Pdf_Element_Object_Stream extends Zend_Pdf_Element_Object
91
 
92
 
93
  /**
94
- * Store original dictionary information in $_originalDictionary class member.
95
- * Used to store information and to normalize filters information before defiltering.
96
  *
 
97
  */
98
- private function _storeOriginalDictionary()
99
  {
100
- $this->_originalDictionary = array();
101
 
102
- $this->_originalDictionary['Filter'] = array();
103
- $this->_originalDictionary['DecodeParms'] = array();
104
  if ($this->_dictionary->Filter === null) {
105
  // Do nothing.
106
  } else if ($this->_dictionary->Filter->getType() == Zend_Pdf_Element::TYPE_ARRAY) {
107
  foreach ($this->_dictionary->Filter->items as $id => $filter) {
108
- $this->_originalDictionary['Filter'][$id] = $filter->value;
109
- $this->_originalDictionary['DecodeParms'][$id] = array();
110
 
111
  if ($this->_dictionary->DecodeParms !== null ) {
112
  if ($this->_dictionary->DecodeParms->items[$id] !== null &&
113
  $this->_dictionary->DecodeParms->items[$id]->value !== null ) {
114
  foreach ($this->_dictionary->DecodeParms->items[$id]->getKeys() as $paramKey) {
115
- $this->_originalDictionary['DecodeParms'][$id][$paramKey] =
116
  $this->_dictionary->DecodeParms->items[$id]->$paramKey->value;
117
  }
118
  }
119
  }
120
  }
121
  } else if ($this->_dictionary->Filter->getType() != Zend_Pdf_Element::TYPE_NULL) {
122
- $this->_originalDictionary['Filter'][0] = $this->_dictionary->Filter->value;
123
- $this->_originalDictionary['DecodeParms'][0] = array();
124
  if ($this->_dictionary->DecodeParms !== null ) {
125
  foreach ($this->_dictionary->DecodeParms->getKeys() as $paramKey) {
126
- $this->_originalDictionary['DecodeParms'][0][$paramKey] =
127
  $this->_dictionary->DecodeParms->$paramKey->value;
128
  }
129
  }
130
  }
131
 
132
  if ($this->_dictionary->F !== null) {
133
- $this->_originalDictionary['F'] = $this->_dictionary->F->value;
134
  }
135
 
136
- $this->_originalDictionary['FFilter'] = array();
137
- $this->_originalDictionary['FDecodeParms'] = array();
138
  if ($this->_dictionary->FFilter === null) {
139
  // Do nothing.
140
  } else if ($this->_dictionary->FFilter->getType() == Zend_Pdf_Element::TYPE_ARRAY) {
141
  foreach ($this->_dictionary->FFilter->items as $id => $filter) {
142
- $this->_originalDictionary['FFilter'][$id] = $filter->value;
143
- $this->_originalDictionary['FDecodeParms'][$id] = array();
144
 
145
  if ($this->_dictionary->FDecodeParms !== null ) {
146
  if ($this->_dictionary->FDecodeParms->items[$id] !== null &&
147
  $this->_dictionary->FDecodeParms->items[$id]->value !== null) {
148
  foreach ($this->_dictionary->FDecodeParms->items[$id]->getKeys() as $paramKey) {
149
- $this->_originalDictionary['FDecodeParms'][$id][$paramKey] =
150
  $this->_dictionary->FDecodeParms->items[$id]->items[$paramKey]->value;
151
  }
152
  }
153
  }
154
  }
155
  } else {
156
- $this->_originalDictionary['FFilter'][0] = $this->_dictionary->FFilter->value;
157
- $this->_originalDictionary['FDecodeParms'][0] = array();
158
  if ($this->_dictionary->FDecodeParms !== null ) {
159
  foreach ($this->_dictionary->FDecodeParms->getKeys() as $paramKey) {
160
- $this->_originalDictionary['FDecodeParms'][0][$paramKey] =
161
  $this->_dictionary->FDecodeParms->items[$paramKey]->value;
162
  }
163
  }
164
  }
 
 
165
  }
166
 
167
  /**
@@ -171,21 +174,21 @@ class Zend_Pdf_Element_Object_Stream extends Zend_Pdf_Element_Object
171
  */
172
  private function _decodeStream()
173
  {
174
- if ($this->_originalDictionary === null) {
175
- $this->_storeOriginalDictionary();
176
  }
177
 
178
  /**
179
  * All applied stream filters must be processed to decode stream.
180
  * If we don't recognize any of applied filetrs an exception should be thrown here
181
  */
182
- if (isset($this->_originalDictionary['F'])) {
183
  /** @todo Check, how external files can be processed. */
184
  #require_once 'Zend/Pdf/Exception.php';
185
  throw new Zend_Pdf_Exception('External filters are not supported now.');
186
  }
187
 
188
- foreach ($this->_originalDictionary['Filter'] as $id => $filterName ) {
189
  $valueRef = &$this->_value->value->getRef();
190
  $this->_value->value->touch();
191
  switch ($filterName) {
@@ -202,13 +205,13 @@ class Zend_Pdf_Element_Object_Stream extends Zend_Pdf_Element_Object
202
  case 'FlateDecode':
203
  #require_once 'Zend/Pdf/Filter/Compression/Flate.php';
204
  $valueRef = Zend_Pdf_Filter_Compression_Flate::decode($valueRef,
205
- $this->_originalDictionary['DecodeParms'][$id]);
206
  break;
207
 
208
  case 'LZWDecode':
209
  #require_once 'Zend/Pdf/Filter/Compression/Lzw.php';
210
  $valueRef = Zend_Pdf_Filter_Compression_Lzw::decode($valueRef,
211
- $this->_originalDictionary['DecodeParms'][$id]);
212
  break;
213
 
214
  case 'RunLengthDecode':
@@ -236,13 +239,13 @@ class Zend_Pdf_Element_Object_Stream extends Zend_Pdf_Element_Object
236
  * All applied stream filters must be processed to encode stream.
237
  * If we don't recognize any of applied filetrs an exception should be thrown here
238
  */
239
- if (isset($this->_originalDictionary['F'])) {
240
  /** @todo Check, how external files can be processed. */
241
  #require_once 'Zend/Pdf/Exception.php';
242
  throw new Zend_Pdf_Exception('External filters are not supported now.');
243
  }
244
 
245
- $filters = array_reverse($this->_originalDictionary['Filter'], true);
246
 
247
  foreach ($filters as $id => $filterName ) {
248
  $valueRef = &$this->_value->value->getRef();
@@ -261,13 +264,13 @@ class Zend_Pdf_Element_Object_Stream extends Zend_Pdf_Element_Object
261
  case 'FlateDecode':
262
  #require_once 'Zend/Pdf/Filter/Compression/Flate.php';
263
  $valueRef = Zend_Pdf_Filter_Compression_Flate::encode($valueRef,
264
- $this->_originalDictionary['DecodeParms'][$id]);
265
  break;
266
 
267
  case 'LZWDecode':
268
  #require_once 'Zend/Pdf/Filter/Compression/Lzw.php';
269
  $valueRef = Zend_Pdf_Filter_Compression_Lzw::encode($valueRef,
270
- $this->_originalDictionary['DecodeParms'][$id]);
271
  break;
272
 
273
  case 'RunLengthDecode':
@@ -295,10 +298,10 @@ class Zend_Pdf_Element_Object_Stream extends Zend_Pdf_Element_Object
295
  {
296
  if ($property == 'dictionary') {
297
  /**
298
- * If stream is note decoded yet, then store original decoding options (do it only once).
299
  */
300
- if (( !$this->_streamDecoded ) && ($this->_originalDictionary === null)) {
301
- $this->_storeOriginalDictionary();
302
  }
303
 
304
  return $this->_dictionary;
@@ -373,6 +376,38 @@ class Zend_Pdf_Element_Object_Stream extends Zend_Pdf_Element_Object
373
  }
374
  }
375
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
  /**
377
  * Dump object to a string to save within PDF file
378
  *
@@ -386,18 +421,14 @@ class Zend_Pdf_Element_Object_Stream extends Zend_Pdf_Element_Object
386
  $shift = $factory->getEnumerationShift($this->_factory);
387
 
388
  if ($this->_streamDecoded) {
389
- $this->_storeOriginalDictionary();
390
  $this->_encodeStream();
391
- } else if ($this->_originalDictionary != null) {
392
- $startDictionary = $this->_originalDictionary;
393
- $this->_storeOriginalDictionary();
394
- $newDictionary = $this->_originalDictionary;
395
 
396
- if ($startDictionary !== $newDictionary) {
397
- $this->_originalDictionary = $startDictionary;
398
  $this->_decodeStream();
399
-
400
- $this->_originalDictionary = $newDictionary;
401
  $this->_encodeStream();
402
  }
403
  }
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Stream.php 22909 2010-08-27 19:57:48Z alexander $
20
  */
21
 
22
 
57
 
58
  /**
59
  * Stored original stream object dictionary.
60
+ * Used to decode stream at access time.
61
  *
62
+ * The only properties affecting decoding are sored here.
63
  *
64
  * @var array|null
65
  */
66
+ private $_initialDictionaryData = null;
67
 
68
  /**
69
  * Object constructor
91
 
92
 
93
  /**
94
+ * Extract dictionary data which are used to store information and to normalize filters
95
+ * information before defiltering.
96
  *
97
+ * @return array
98
  */
99
+ private function _extractDictionaryData()
100
  {
101
+ $dictionaryArray = array();
102
 
103
+ $dictionaryArray['Filter'] = array();
104
+ $dictionaryArray['DecodeParms'] = array();
105
  if ($this->_dictionary->Filter === null) {
106
  // Do nothing.
107
  } else if ($this->_dictionary->Filter->getType() == Zend_Pdf_Element::TYPE_ARRAY) {
108
  foreach ($this->_dictionary->Filter->items as $id => $filter) {
109
+ $dictionaryArray['Filter'][$id] = $filter->value;
110
+ $dictionaryArray['DecodeParms'][$id] = array();
111
 
112
  if ($this->_dictionary->DecodeParms !== null ) {
113
  if ($this->_dictionary->DecodeParms->items[$id] !== null &&
114
  $this->_dictionary->DecodeParms->items[$id]->value !== null ) {
115
  foreach ($this->_dictionary->DecodeParms->items[$id]->getKeys() as $paramKey) {
116
+ $dictionaryArray['DecodeParms'][$id][$paramKey] =
117
  $this->_dictionary->DecodeParms->items[$id]->$paramKey->value;
118
  }
119
  }
120
  }
121
  }
122
  } else if ($this->_dictionary->Filter->getType() != Zend_Pdf_Element::TYPE_NULL) {
123
+ $dictionaryArray['Filter'][0] = $this->_dictionary->Filter->value;
124
+ $dictionaryArray['DecodeParms'][0] = array();
125
  if ($this->_dictionary->DecodeParms !== null ) {
126
  foreach ($this->_dictionary->DecodeParms->getKeys() as $paramKey) {
127
+ $dictionaryArray['DecodeParms'][0][$paramKey] =
128
  $this->_dictionary->DecodeParms->$paramKey->value;
129
  }
130
  }
131
  }
132
 
133
  if ($this->_dictionary->F !== null) {
134
+ $dictionaryArray['F'] = $this->_dictionary->F->value;
135
  }
136
 
137
+ $dictionaryArray['FFilter'] = array();
138
+ $dictionaryArray['FDecodeParms'] = array();
139
  if ($this->_dictionary->FFilter === null) {
140
  // Do nothing.
141
  } else if ($this->_dictionary->FFilter->getType() == Zend_Pdf_Element::TYPE_ARRAY) {
142
  foreach ($this->_dictionary->FFilter->items as $id => $filter) {
143
+ $dictionaryArray['FFilter'][$id] = $filter->value;
144
+ $dictionaryArray['FDecodeParms'][$id] = array();
145
 
146
  if ($this->_dictionary->FDecodeParms !== null ) {
147
  if ($this->_dictionary->FDecodeParms->items[$id] !== null &&
148
  $this->_dictionary->FDecodeParms->items[$id]->value !== null) {
149
  foreach ($this->_dictionary->FDecodeParms->items[$id]->getKeys() as $paramKey) {
150
+ $dictionaryArray['FDecodeParms'][$id][$paramKey] =
151
  $this->_dictionary->FDecodeParms->items[$id]->items[$paramKey]->value;
152
  }
153
  }
154
  }
155
  }
156
  } else {
157
+ $dictionaryArray['FFilter'][0] = $this->_dictionary->FFilter->value;
158
+ $dictionaryArray['FDecodeParms'][0] = array();
159
  if ($this->_dictionary->FDecodeParms !== null ) {
160
  foreach ($this->_dictionary->FDecodeParms->getKeys() as $paramKey) {
161
+ $dictionaryArray['FDecodeParms'][0][$paramKey] =
162
  $this->_dictionary->FDecodeParms->items[$paramKey]->value;
163
  }
164
  }
165
  }
166
+
167
+ return $dictionaryArray;
168
  }
169
 
170
  /**
174
  */
175
  private function _decodeStream()
176
  {
177
+ if ($this->_initialDictionaryData === null) {
178
+ $this->_initialDictionaryData = $this->_extractDictionaryData();
179
  }
180
 
181
  /**
182
  * All applied stream filters must be processed to decode stream.
183
  * If we don't recognize any of applied filetrs an exception should be thrown here
184
  */
185
+ if (isset($this->_initialDictionaryData['F'])) {
186
  /** @todo Check, how external files can be processed. */
187
  #require_once 'Zend/Pdf/Exception.php';
188
  throw new Zend_Pdf_Exception('External filters are not supported now.');
189
  }
190
 
191
+ foreach ($this->_initialDictionaryData['Filter'] as $id => $filterName ) {
192
  $valueRef = &$this->_value->value->getRef();
193
  $this->_value->value->touch();
194
  switch ($filterName) {
205
  case 'FlateDecode':
206
  #require_once 'Zend/Pdf/Filter/Compression/Flate.php';
207
  $valueRef = Zend_Pdf_Filter_Compression_Flate::decode($valueRef,
208
+ $this->_initialDictionaryData['DecodeParms'][$id]);
209
  break;
210
 
211
  case 'LZWDecode':
212
  #require_once 'Zend/Pdf/Filter/Compression/Lzw.php';
213
  $valueRef = Zend_Pdf_Filter_Compression_Lzw::decode($valueRef,
214
+ $this->_initialDictionaryData['DecodeParms'][$id]);
215
  break;
216
 
217
  case 'RunLengthDecode':
239
  * All applied stream filters must be processed to encode stream.
240
  * If we don't recognize any of applied filetrs an exception should be thrown here
241
  */
242
+ if (isset($this->_initialDictionaryData['F'])) {
243
  /** @todo Check, how external files can be processed. */
244
  #require_once 'Zend/Pdf/Exception.php';
245
  throw new Zend_Pdf_Exception('External filters are not supported now.');
246
  }
247
 
248
+ $filters = array_reverse($this->_initialDictionaryData['Filter'], true);
249
 
250
  foreach ($filters as $id => $filterName ) {
251
  $valueRef = &$this->_value->value->getRef();
264
  case 'FlateDecode':
265
  #require_once 'Zend/Pdf/Filter/Compression/Flate.php';
266
  $valueRef = Zend_Pdf_Filter_Compression_Flate::encode($valueRef,
267
+ $this->_initialDictionaryData['DecodeParms'][$id]);
268
  break;
269
 
270
  case 'LZWDecode':
271
  #require_once 'Zend/Pdf/Filter/Compression/Lzw.php';
272
  $valueRef = Zend_Pdf_Filter_Compression_Lzw::encode($valueRef,
273
+ $this->_initialDictionaryData['DecodeParms'][$id]);
274
  break;
275
 
276
  case 'RunLengthDecode':
298
  {
299
  if ($property == 'dictionary') {
300
  /**
301
+ * If stream is not decoded yet, then store original decoding options (do it only once).
302
  */
303
+ if (( !$this->_streamDecoded ) && ($this->_initialDictionaryData === null)) {
304
+ $this->_initialDictionaryData = $this->_extractDictionaryData();
305
  }
306
 
307
  return $this->_dictionary;
376
  }
377
  }
378
 
379
+ /**
380
+ * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
381
+ *
382
+ * @param Zend_Pdf_ElementFactory $factory The factory to attach
383
+ * @param array &$processed List of already processed indirect objects, used to avoid objects duplication
384
+ * @param integer $mode Cloning mode (defines filter for objects cloning)
385
+ * @returns Zend_Pdf_Element
386
+ */
387
+ public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
388
+ {
389
+ $id = spl_object_hash($this);
390
+ if (isset($processed[$id])) {
391
+ // Do nothing if object is already processed
392
+ // return it
393
+ return $processed[$id];
394
+ }
395
+
396
+ $streamValue = $this->_value;
397
+ $streamDictionary = $this->_dictionary->makeClone($factory, $processed, $mode);
398
+
399
+ // Make new empty instance of stream object and register it in $processed container
400
+ $processed[$id] = $clonedObject = $factory->newStreamObject('');
401
+
402
+ // Copy current object data and state
403
+ $clonedObject->_dictionary = $this->_dictionary->makeClone($factory, $processed, $mode);
404
+ $clonedObject->_value = $this->_value->makeClone($factory, $processed, $mode);
405
+ $clonedObject->_initialDictionaryData = $this->_initialDictionaryData;
406
+ $clonedObject->_streamDecoded = $this->_streamDecoded;
407
+
408
+ return $clonedObject;
409
+ }
410
+
411
  /**
412
  * Dump object to a string to save within PDF file
413
  *
421
  $shift = $factory->getEnumerationShift($this->_factory);
422
 
423
  if ($this->_streamDecoded) {
424
+ $this->_initialDictionaryData = $this->_extractDictionaryData();
425
  $this->_encodeStream();
426
+ } else if ($this->_initialDictionaryData != null) {
427
+ $newDictionary = $this->_extractDictionaryData();
 
 
428
 
429
+ if ($this->_initialDictionaryData !== $newDictionary) {
 
430
  $this->_decodeStream();
431
+ $this->_initialDictionaryData = $newDictionary;
 
432
  $this->_encodeStream();
433
  }
434
  }
lib/Zend/Pdf/Element/Reference.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Reference.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -181,6 +181,32 @@ class Zend_Pdf_Element_Reference extends Zend_Pdf_Element
181
  $this->_ref = $obj;
182
  }
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  /**
185
  * Mark object as modified, to include it into new PDF file segment.
186
  */
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Reference.php 22797 2010-08-06 15:02:12Z alexander $
20
  */
21
 
22
 
181
  $this->_ref = $obj;
182
  }
183
 
184
+ /**
185
+ * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
186
+ *
187
+ * @param Zend_Pdf_ElementFactory $factory The factory to attach
188
+ * @param array &$processed List of already processed indirect objects, used to avoid objects duplication
189
+ * @param integer $mode Cloning mode (defines filter for objects cloning)
190
+ * @returns Zend_Pdf_Element
191
+ */
192
+ public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
193
+ {
194
+ if ($this->_ref === null) {
195
+ $this->_dereference();
196
+ }
197
+
198
+ // This code duplicates code in Zend_Pdf_Element_Object class,
199
+ // but allows to avoid unnecessary method call in most cases
200
+ $id = spl_object_hash($this->_ref);
201
+ if (isset($processed[$id])) {
202
+ // Do nothing if object is already processed
203
+ // return it
204
+ return $processed[$id];
205
+ }
206
+
207
+ return $this->_ref->makeClone($factory, $processed, $mode);
208
+ }
209
+
210
  /**
211
  * Mark object as modified, to include it into new PDF file segment.
212
  */
lib/Zend/Pdf/Element/Stream.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -104,6 +104,19 @@ class Zend_Pdf_Element_Stream extends Zend_Pdf_Element
104
  }
105
 
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  /**
108
  * Return object as string
109
  *
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Stream.php 22797 2010-08-06 15:02:12Z alexander $
20
  */
21
 
22
 
104
  }
105
 
106
 
107
+ /**
108
+ * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
109
+ *
110
+ * @param Zend_Pdf_ElementFactory $factory The factory to attach
111
+ * @param array &$processed List of already processed indirect objects, used to avoid objects duplication
112
+ * @param integer $mode Cloning mode (defines filter for objects cloning)
113
+ * @returns Zend_Pdf_Element
114
+ */
115
+ public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
116
+ {
117
+ return new self($this->value->getRef());
118
+ }
119
+
120
  /**
121
  * Return object as string
122
  *
lib/Zend/Pdf/Element/String.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: String.php 21545 2010-03-18 09:12:27Z bate $
20
  */
21
 
22
 
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: String.php 21542 2010-03-18 08:56:40Z bate $
20
  */
21
 
22
 
lib/Zend/Pdf/ElementFactory.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: ElementFactory.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -116,6 +116,16 @@ class Zend_Pdf_ElementFactory implements Zend_Pdf_ElementFactory_Interface
116
  }
117
 
118
 
 
 
 
 
 
 
 
 
 
 
119
  /**
120
  * Factory generator
121
  *
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: ElementFactory.php 22797 2010-08-06 15:02:12Z alexander $
20
  */
21
 
22
 
116
  }
117
 
118
 
119
+ /**
120
+ * Get factory
121
+ *
122
+ * @return Zend_Pdf_ElementFactory_Interface
123
+ */
124
+ public function getFactory()
125
+ {
126
+ return $this;
127
+ }
128
+
129
  /**
130
  * Factory generator
131
  *
lib/Zend/Pdf/ElementFactory/Interface.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -29,6 +29,13 @@
29
  */
30
  interface Zend_Pdf_ElementFactory_Interface
31
  {
 
 
 
 
 
 
 
32
  /**
33
  * Close factory and clean-up resources
34
  *
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Interface.php 22797 2010-08-06 15:02:12Z alexander $
20
  */
21
 
22
  /**
29
  */
30
  interface Zend_Pdf_ElementFactory_Interface
31
  {
32
+ /**
33
+ * Get factory
34
+ *
35
+ * @return Zend_Pdf_ElementFactory_Interface
36
+ */
37
+ public function getFactory();
38
+
39
  /**
40
  * Close factory and clean-up resources
41
  *
lib/Zend/Pdf/ElementFactory/Proxy.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Proxy.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /** Zend_Pdf_ElementFactory_Interface */
@@ -56,6 +56,16 @@ class Zend_Pdf_ElementFactory_Proxy implements Zend_Pdf_ElementFactory_Interface
56
  $this->_factory = null;
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
59
  /**
60
  * Close factory and clean-up resources
61
  *
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Proxy.php 22797 2010-08-06 15:02:12Z alexander $
20
  */
21
 
22
  /** Zend_Pdf_ElementFactory_Interface */
56
  $this->_factory = null;
57
  }
58
 
59
+ /**
60
+ * Get factory
61
+ *
62
+ * @return Zend_Pdf_ElementFactory_Interface
63
+ */
64
+ public function getFactory()
65
+ {
66
+ return $this->_factory->getFactory();
67
+ }
68
+
69
  /**
70
  * Close factory and clean-up resources
71
  *
lib/Zend/Pdf/FileParser/Image/Png.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage FileParser
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Png.php 22655 2010-07-22 18:47:20Z mabe $
21
  */
22
 
23
  /** @see Zend_Pdf_FileParser_Image */
17
  * @subpackage FileParser
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Png.php 22653 2010-07-22 18:41:39Z mabe $
21
  */
22
 
23
  /** @see Zend_Pdf_FileParser_Image */
lib/Zend/Pdf/Filter/Ascii85.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Ascii85.php 22655 2010-07-22 18:47:20Z mabe $
20
  */
21
 
22
 
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Ascii85.php 22653 2010-07-22 18:41:39Z mabe $
20
  */
21
 
22
 
lib/Zend/Pdf/Filter/RunLength.php CHANGED
@@ -16,6 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
 
19
  */
20
 
21
 
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: RunLength.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
  */
21
 
22
 
lib/Zend/Pdf/Outline/Loaded.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Actions
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Loaded.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
 
@@ -335,8 +335,11 @@ class Zend_Pdf_Outline_Loaded extends Zend_Pdf_Outline
335
  $childOutlinesCount = abs($childOutlinesCount);
336
 
337
  $childDictionary = $dictionary->First;
338
- for ($count = 0; $count < $childOutlinesCount; $count++) {
339
- if ($childDictionary === null) {
 
 
 
340
  #require_once 'Zend/Pdf/Exception.php';
341
  throw new Zend_Pdf_Exception('Outline childs load error.');
342
  }
@@ -348,11 +351,6 @@ class Zend_Pdf_Outline_Loaded extends Zend_Pdf_Outline
348
  $childDictionary = $childDictionary->Next;
349
  }
350
 
351
- if ($childDictionary !== null) {
352
- #require_once 'Zend/Pdf/Exception.php';
353
- throw new Zend_Pdf_Exception('Outline childs load error.');
354
- }
355
-
356
  $this->_originalChildOutlines = $this->childOutlines;
357
  }
358
  }
17
  * @subpackage Actions
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Loaded.php 23195 2010-10-21 10:12:12Z alexander $
21
  */
22
 
23
 
335
  $childOutlinesCount = abs($childOutlinesCount);
336
 
337
  $childDictionary = $dictionary->First;
338
+
339
+ $children = new SplObjectStorage();
340
+ while ($childDictionary !== null) {
341
+ // Check children structure for cyclic references
342
+ if ($children->contains($childDictionary)) {
343
  #require_once 'Zend/Pdf/Exception.php';
344
  throw new Zend_Pdf_Exception('Outline childs load error.');
345
  }
351
  $childDictionary = $childDictionary->Next;
352
  }
353
 
 
 
 
 
 
354
  $this->_originalChildOutlines = $this->childOutlines;
355
  }
356
  }
lib/Zend/Pdf/Page.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Page.php 20470 2010-01-21 16:10:42Z alexander $
20
  */
21
 
22
  /** Internally used classes */
@@ -29,6 +29,9 @@
29
  #require_once 'Zend/Pdf/Element/Null.php';
30
  #require_once 'Zend/Pdf/Element/Numeric.php';
31
  #require_once 'Zend/Pdf/Element/String.php';
 
 
 
32
 
33
 
34
  /**
@@ -38,7 +41,7 @@
38
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
39
  * @license http://framework.zend.com/license/new-bsd New BSD License
40
  */
41
- class Zend_Pdf_Page
42
  {
43
  /**** Class Constants ****/
44
 
@@ -111,7 +114,7 @@ class Zend_Pdf_Page
111
  *
112
  * @var Zend_Pdf_Element_Reference|Zend_Pdf_Element_Object
113
  */
114
- protected $_pageDictionary;
115
 
116
  /**
117
  * PDF objects factory.
@@ -128,27 +131,6 @@ class Zend_Pdf_Page
128
  */
129
  protected $_attached;
130
 
131
- /**
132
- * Stream of the drawing instructions.
133
- *
134
- * @var string
135
- */
136
- protected $_contents = '';
137
-
138
- /**
139
- * Current style
140
- *
141
- * @var Zend_Pdf_Style
142
- */
143
- protected $_style = null;
144
-
145
- /**
146
- * Counter for the "Save" operations
147
- *
148
- * @var integer
149
- */
150
- protected $_saveCount = 0;
151
-
152
  /**
153
  * Safe Graphics State semafore
154
  *
@@ -160,20 +142,6 @@ class Zend_Pdf_Page
160
  */
161
  protected $_safeGS;
162
 
163
- /**
164
- * Current font
165
- *
166
- * @var Zend_Pdf_Resource_Font
167
- */
168
- protected $_font = null;
169
-
170
- /**
171
- * Current font size
172
- *
173
- * @var float
174
- */
175
- protected $_fontSize;
176
-
177
  /**
178
  * Object constructor.
179
  * Constructor signatures:
@@ -185,7 +153,7 @@ class Zend_Pdf_Page
185
  * Zend_Pdf_ElementFactory_Interface $factory);
186
  * ---------------------------------------------------------
187
  *
188
- * 2. Clone PDF page.
189
  * New page is created in the same context as source page. Object factory is shared.
190
  * Thus it will be attached to the document, but need to be placed into Zend_Pdf::$pages array
191
  * to be included into output.
@@ -215,45 +183,59 @@ class Zend_Pdf_Page
215
  */
216
  public function __construct($param1, $param2 = null, $param3 = null)
217
  {
218
- if ($param1 instanceof Zend_Pdf_Element_Reference &&
219
- $param1->getType() == Zend_Pdf_Element::TYPE_DICTIONARY &&
 
220
  $param2 instanceof Zend_Pdf_ElementFactory_Interface &&
221
  $param3 === null
222
  ) {
223
- $this->_pageDictionary = $param1;
224
- $this->_objFactory = $param2;
225
- $this->_attached = true;
226
- $this->_safeGS = false;
 
 
 
 
227
 
228
- return;
 
 
 
229
 
 
 
 
 
 
 
230
  } else if ($param1 instanceof Zend_Pdf_Page && $param2 === null && $param3 === null) {
231
- // Clone existing page.
232
  // Let already existing content and resources to be shared between pages
233
  // We don't give existing content modification functionality, so we don't need "deep copy"
234
  $this->_objFactory = $param1->_objFactory;
235
  $this->_attached = &$param1->_attached;
236
  $this->_safeGS = false;
237
 
238
- $this->_pageDictionary = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
239
 
240
- foreach ($param1->_pageDictionary->getKeys() as $key) {
241
  if ($key == 'Contents') {
242
  // Clone Contents property
243
 
244
- $this->_pageDictionary->Contents = new Zend_Pdf_Element_Array();
245
 
246
- if ($param1->_pageDictionary->Contents->getType() != Zend_Pdf_Element::TYPE_ARRAY) {
247
  // Prepare array of content streams and add existing stream
248
- $this->_pageDictionary->Contents->items[] = $param1->_pageDictionary->Contents;
249
  } else {
250
  // Clone array of the content streams
251
- foreach ($param1->_pageDictionary->Contents->items as $srcContentStream) {
252
- $this->_pageDictionary->Contents->items[] = $srcContentStream;
253
  }
254
  }
255
  } else {
256
- $this->_pageDictionary->$key = $param1->_pageDictionary->$key;
257
  }
258
  }
259
 
@@ -322,33 +304,27 @@ class Zend_Pdf_Page
322
  throw new Zend_Pdf_Exception('Unrecognized method signature, wrong number of arguments or wrong argument types.');
323
  }
324
 
325
- $this->_pageDictionary = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
326
- $this->_pageDictionary->Type = new Zend_Pdf_Element_Name('Page');
327
  #require_once 'Zend/Pdf.php';
328
- $this->_pageDictionary->LastModified = new Zend_Pdf_Element_String(Zend_Pdf::pdfDate());
329
- $this->_pageDictionary->Resources = new Zend_Pdf_Element_Dictionary();
330
- $this->_pageDictionary->MediaBox = new Zend_Pdf_Element_Array();
331
- $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0);
332
- $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0);
333
- $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageWidth);
334
- $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageHeight);
335
- $this->_pageDictionary->Contents = new Zend_Pdf_Element_Array();
336
  }
337
 
338
 
339
  /**
340
- * Clone operator
341
  *
342
- * @throws Zend_Pdf_Exception
343
- */
344
- public function __clone()
345
- {
346
- #require_once 'Zend/Pdf/Exception.php';
347
- throw new Zend_Pdf_Exception('Cloning Zend_Pdf_Page object using \'clone\' keyword is not supported. Use \'new Zend_Pdf_Page($srcPage)\' syntax');
348
- }
349
-
350
- /**
351
- * Attach resource to the page
352
  *
353
  * @param string $type
354
  * @param Zend_Pdf_Resource $resource
@@ -357,17 +333,17 @@ class Zend_Pdf_Page
357
  protected function _attachResource($type, Zend_Pdf_Resource $resource)
358
  {
359
  // Check that Resources dictionary contains appropriate resource set
360
- if ($this->_pageDictionary->Resources->$type === null) {
361
- $this->_pageDictionary->Resources->touch();
362
- $this->_pageDictionary->Resources->$type = new Zend_Pdf_Element_Dictionary();
363
  } else {
364
- $this->_pageDictionary->Resources->$type->touch();
365
  }
366
 
367
  // Check, that resource is already attached to resource set.
368
  $resObject = $resource->getResource();
369
- foreach ($this->_pageDictionary->Resources->$type->getKeys() as $ResID) {
370
- if ($this->_pageDictionary->Resources->$type->$ResID === $resObject) {
371
  return $ResID;
372
  }
373
  }
@@ -375,9 +351,9 @@ class Zend_Pdf_Page
375
  $idCounter = 1;
376
  do {
377
  $newResName = $type[0] . $idCounter++;
378
- } while ($this->_pageDictionary->Resources->$type->$newResName !== null);
379
 
380
- $this->_pageDictionary->Resources->$type->$newResName = $resObject;
381
  $this->_objFactory->attach($resource->getFactory());
382
 
383
  return $newResName;
@@ -391,315 +367,257 @@ class Zend_Pdf_Page
391
  protected function _addProcSet($procSetName)
392
  {
393
  // Check that Resources dictionary contains ProcSet entry
394
- if ($this->_pageDictionary->Resources->ProcSet === null) {
395
- $this->_pageDictionary->Resources->touch();
396
- $this->_pageDictionary->Resources->ProcSet = new Zend_Pdf_Element_Array();
397
  } else {
398
- $this->_pageDictionary->Resources->ProcSet->touch();
399
  }
400
 
401
- foreach ($this->_pageDictionary->Resources->ProcSet->items as $procSetEntry) {
402
  if ($procSetEntry->value == $procSetName) {
403
  // Procset is already included into a ProcSet array
404
  return;
405
  }
406
  }
407
 
408
- $this->_pageDictionary->Resources->ProcSet->items[] = new Zend_Pdf_Element_Name($procSetName);
409
  }
410
 
411
  /**
412
- * Retrive PDF file reference to the page
413
  *
414
- * @internal
415
- * @return Zend_Pdf_Element_Dictionary
416
- */
417
- public function getPageDictionary()
418
- {
419
- return $this->_pageDictionary;
420
- }
421
-
422
- /**
423
- * Dump current drawing instructions into the content stream.
424
  *
425
- * @todo Don't forget to close all current graphics operations (like path drawing)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  *
427
- * @throws Zend_Pdf_Exception
 
 
 
 
428
  */
429
- public function flush()
430
  {
431
- if ($this->_saveCount != 0) {
432
- #require_once 'Zend/Pdf/Exception.php';
433
- throw new Zend_Pdf_Exception('Saved graphics state is not restored');
434
- }
435
-
436
- if ($this->_contents == '') {
437
- return;
438
- }
439
-
440
- if ($this->_pageDictionary->Contents->getType() != Zend_Pdf_Element::TYPE_ARRAY) {
441
- /**
442
- * It's a stream object.
443
- * Prepare Contents page attribute for update.
444
- */
445
- $this->_pageDictionary->touch();
446
 
447
- $currentPageContents = $this->_pageDictionary->Contents;
448
- $this->_pageDictionary->Contents = new Zend_Pdf_Element_Array();
449
- $this->_pageDictionary->Contents->items[] = $currentPageContents;
450
- } else {
451
- $this->_pageDictionary->Contents->touch();
452
- }
453
 
454
- if ((!$this->_safeGS) && (count($this->_pageDictionary->Contents->items) != 0)) {
455
- /**
456
- * Page already has some content which is not treated as safe.
457
- *
458
- * Add save/restore GS operators
459
- */
460
- $this->_addProcSet('PDF');
461
 
462
- $newContentsArray = new Zend_Pdf_Element_Array();
463
- $newContentsArray->items[] = $this->_objFactory->newStreamObject(" q\n");
464
- foreach ($this->_pageDictionary->Contents->items as $contentStream) {
465
- $newContentsArray->items[] = $contentStream;
466
  }
467
- $newContentsArray->items[] = $this->_objFactory->newStreamObject(" Q\n");
468
-
469
- $this->_pageDictionary->touch();
470
- $this->_pageDictionary->Contents = $newContentsArray;
471
-
472
- $this->_safeGS = true;
473
  }
474
 
475
- $this->_pageDictionary->Contents->items[] =
476
- $this->_objFactory->newStreamObject($this->_contents);
477
-
478
- $this->_contents = '';
479
  }
480
 
481
  /**
482
- * Prepare page to be rendered into PDF.
483
- *
484
- * @todo Don't forget to close all current graphics operations (like path drawing)
485
  *
486
- * @param Zend_Pdf_ElementFactory_Interface $objFactory
487
- * @throws Zend_Pdf_Exception
488
- */
489
- public function render(Zend_Pdf_ElementFactory_Interface $objFactory)
490
- {
491
- $this->flush();
492
-
493
- if ($objFactory === $this->_objFactory) {
494
- // Page is already attached to the document.
495
- return;
496
- }
497
-
498
- if ($this->_attached) {
499
- #require_once 'Zend/Pdf/Exception.php';
500
- throw new Zend_Pdf_Exception('Page is attached to one documen, but rendered in context of another.');
501
- /**
502
- * @todo Page cloning must be implemented here instead of exception.
503
- * PDF objects (ex. fonts) can be shared between pages.
504
- * Thus all referenced objects, which can be modified, must be cloned recursively,
505
- * to avoid producing wrong object references in a context of source PDF.
506
- */
507
-
508
- //...
509
- } else {
510
- $objFactory->attach($this->_objFactory);
511
- }
512
- }
513
-
514
-
515
-
516
- /**
517
- * Set fill color.
518
  *
519
- * @param Zend_Pdf_Color $color
520
- * @return Zend_Pdf_Page
521
  */
522
- public function setFillColor(Zend_Pdf_Color $color)
523
  {
524
- $this->_addProcSet('PDF');
525
- $this->_contents .= $color->instructions(false);
526
-
527
- return $this;
528
  }
529
 
530
  /**
531
- * Set line color.
532
  *
533
- * @param Zend_Pdf_Color $color
534
- * @return Zend_Pdf_Page
535
  */
536
- public function setLineColor(Zend_Pdf_Color $color)
537
  {
538
- $this->_addProcSet('PDF');
539
- $this->_contents .= $color->instructions(true);
540
-
541
- return $this;
542
  }
543
 
544
  /**
545
- * Set line width.
546
  *
547
- * @param float $width
548
- * @return Zend_Pdf_Page
549
  */
550
- public function setLineWidth($width)
551
  {
552
- $this->_addProcSet('PDF');
553
- $widthObj = new Zend_Pdf_Element_Numeric($width);
554
- $this->_contents .= $widthObj->toString() . " w\n";
555
-
556
- return $this;
557
  }
558
 
559
  /**
560
- * Set line dashing pattern
561
- *
562
- * Pattern is an array of floats: array(on_length, off_length, on_length, off_length, ...)
563
- * Phase is shift from the beginning of line.
564
- *
565
- * @param array $pattern
566
- * @param array $phase
567
- * @return Zend_Pdf_Page
568
  */
569
- public function setLineDashingPattern($pattern, $phase = 0)
570
  {
571
- $this->_addProcSet('PDF');
572
-
573
- if ($pattern === Zend_Pdf_Page::LINE_DASHING_SOLID) {
574
- $pattern = array();
575
- $phase = 0;
576
- }
577
-
578
- $dashPattern = new Zend_Pdf_Element_Array();
579
- $phaseEleemnt = new Zend_Pdf_Element_Numeric($phase);
580
 
581
- foreach ($pattern as $dashItem) {
582
- $dashElement = new Zend_Pdf_Element_Numeric($dashItem);
583
- $dashPattern->items[] = $dashElement;
 
 
 
 
 
584
  }
585
 
586
- $this->_contents .= $dashPattern->toString() . ' '
587
- . $phaseEleemnt->toString() . " d\n";
588
-
589
- return $this;
 
590
  }
591
 
592
  /**
593
- * Set current font.
 
594
  *
595
- * @param Zend_Pdf_Resource_Font $font
596
- * @param float $fontSize
 
597
  * @return Zend_Pdf_Page
598
  */
599
- public function setFont(Zend_Pdf_Resource_Font $font, $fontSize)
600
  {
601
- $this->_addProcSet('Text');
602
- $fontName = $this->_attachResource('Font', $font);
603
-
604
- $this->_font = $font;
605
- $this->_fontSize = $fontSize;
 
 
 
 
606
 
607
- $fontNameObj = new Zend_Pdf_Element_Name($fontName);
608
- $fontSizeObj = new Zend_Pdf_Element_Numeric($fontSize);
609
- $this->_contents .= $fontNameObj->toString() . ' ' . $fontSizeObj->toString() . " Tf\n";
610
 
611
- return $this;
612
  }
613
 
614
  /**
615
- * Set the style to use for future drawing operations on this page
616
  *
617
- * @param Zend_Pdf_Style $style
618
- * @return Zend_Pdf_Page
619
  */
620
- public function setStyle(Zend_Pdf_Style $style)
621
  {
622
- $this->_style = $style;
623
-
624
- $this->_addProcSet('Text');
625
- $this->_addProcSet('PDF');
626
- if ($style->getFont() !== null) {
627
- $this->setFont($style->getFont(), $style->getFontSize());
628
- }
629
- $this->_contents .= $style->instructions($this->_pageDictionary->Resources);
630
-
631
- return $this;
632
  }
633
 
634
  /**
635
- * Set the transparancy
636
- *
637
- * $alpha == 0 - transparent
638
- * $alpha == 1 - opaque
639
  *
640
- * Transparency modes, supported by PDF:
641
- * Normal (default), Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight,
642
- * SoftLight, Difference, Exclusion
643
  *
644
- * @param float $alpha
645
- * @param string $mode
646
  * @throws Zend_Pdf_Exception
647
- * @return Zend_Pdf_Page
648
  */
649
- public function setAlpha($alpha, $mode = 'Normal')
650
  {
651
- if (!in_array($mode, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge',
652
- 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion'))) {
653
- #require_once 'Zend/Pdf/Exception.php';
654
- throw new Zend_Pdf_Exception('Unsupported transparency mode.');
655
- }
656
- if (!is_numeric($alpha) || $alpha < 0 || $alpha > 1) {
657
  #require_once 'Zend/Pdf/Exception.php';
658
- throw new Zend_Pdf_Exception('Alpha value must be numeric between 0 (transparent) and 1 (opaque).');
659
  }
660
 
661
- $this->_addProcSet('Text');
662
- $this->_addProcSet('PDF');
 
663
 
664
- $resources = $this->_pageDictionary->Resources;
 
 
 
 
 
665
 
666
- // Check if Resources dictionary contains ExtGState entry
667
- if ($resources->ExtGState === null) {
668
- $resources->touch();
669
- $resources->ExtGState = new Zend_Pdf_Element_Dictionary();
670
  } else {
671
- $resources->ExtGState->touch();
672
  }
673
 
674
- $idCounter = 1;
675
- do {
676
- $gStateName = 'GS' . $idCounter++;
677
- } while ($resources->ExtGState->$gStateName !== null);
 
 
 
678
 
 
 
 
 
 
 
679
 
680
- $gStateDictionary = new Zend_Pdf_Element_Dictionary();
681
- $gStateDictionary->Type = new Zend_Pdf_Element_Name('ExtGState');
682
- $gStateDictionary->BM = new Zend_Pdf_Element_Name($mode);
683
- $gStateDictionary->CA = new Zend_Pdf_Element_Numeric($alpha);
684
- $gStateDictionary->ca = new Zend_Pdf_Element_Numeric($alpha);
685
 
686
- $resources->ExtGState->$gStateName = $this->_objFactory->newObject($gStateDictionary);
 
687
 
688
- $gStateNameObj = new Zend_Pdf_Element_Name($gStateName);
689
- $this->_contents .= $gStateNameObj->toString() . " gs\n";
690
 
691
- return $this;
692
  }
693
 
694
-
695
  /**
696
- * Get current font.
 
 
697
  *
698
- * @return Zend_Pdf_Resource_Font $font
 
699
  */
700
- public function getFont()
701
  {
702
- return $this->_font;
 
 
 
 
 
 
 
 
 
 
 
 
703
  }
704
 
705
  /**
@@ -714,7 +632,7 @@ class Zend_Pdf_Page
714
  */
715
  public function extractResources()
716
  {
717
- return $this->_pageDictionary->Resources;
718
  }
719
 
720
  /**
@@ -727,13 +645,13 @@ class Zend_Pdf_Page
727
  */
728
  public function extractFonts()
729
  {
730
- if ($this->_pageDictionary->Resources->Font === null) {
731
  // Page doesn't have any font attached
732
  // Return empty array
733
  return array();
734
  }
735
 
736
- $fontResources = $this->_pageDictionary->Resources->Font;
737
 
738
  $fontResourcesUnique = array();
739
  foreach ($fontResources->getKeys() as $fontResourceName) {
@@ -777,12 +695,12 @@ class Zend_Pdf_Page
777
  */
778
  public function extractFont($fontName)
779
  {
780
- if ($this->_pageDictionary->Resources->Font === null) {
781
  // Page doesn't have any font attached
782
  return null;
783
  }
784
 
785
- $fontResources = $this->_pageDictionary->Resources->Font;
786
 
787
  $fontResourcesUnique = array();
788
 
@@ -825,955 +743,29 @@ class Zend_Pdf_Page
825
  }
826
 
827
  /**
828
- * Get current font size
829
- *
830
- * @return float $fontSize
831
- */
832
- public function getFontSize()
833
- {
834
- return $this->_fontSize;
835
- }
836
-
837
- /**
838
- * Return the style, applied to the page.
839
- *
840
- * @return Zend_Pdf_Style|null
841
- */
842
- public function getStyle()
843
- {
844
- return $this->_style;
845
- }
846
-
847
-
848
- /**
849
- * Save the graphics state of this page.
850
- * This takes a snapshot of the currently applied style, position, clipping area and
851
- * any rotation/translation/scaling that has been applied.
852
- *
853
- * @todo check for the open paths
854
- * @throws Zend_Pdf_Exception - if a save is performed with an open path
855
- * @return Zend_Pdf_Page
856
- */
857
- public function saveGS()
858
- {
859
- $this->_saveCount++;
860
-
861
- $this->_addProcSet('PDF');
862
- $this->_contents .= " q\n";
863
-
864
- return $this;
865
- }
866
-
867
- /**
868
- * Restore the graphics state that was saved with the last call to saveGS().
869
  *
870
- * @throws Zend_Pdf_Exception - if there is no previously saved state
871
  * @return Zend_Pdf_Page
872
  */
873
- public function restoreGS()
874
  {
875
- if ($this->_saveCount-- <= 0) {
876
- #require_once 'Zend/Pdf/Exception.php';
877
- throw new Zend_Pdf_Exception('Restoring graphics state which is not saved');
 
878
  }
879
- $this->_contents .= " Q\n";
880
-
881
- return $this;
882
- }
883
-
884
 
885
- /**
886
- * Intersect current clipping area with a circle.
887
- *
888
- * @param float $x
889
- * @param float $y
890
- * @param float $radius
891
- * @param float $startAngle
892
- * @param float $endAngle
893
- * @return Zend_Pdf_Page
894
- */
895
- public function clipCircle($x, $y, $radius, $startAngle = null, $endAngle = null)
896
- {
897
- $this->clipEllipse($x - $radius, $y - $radius,
898
- $x + $radius, $y + $radius,
899
- $startAngle, $endAngle);
900
 
901
- return $this;
902
- }
903
-
904
- /**
905
- * Intersect current clipping area with a polygon.
906
- *
907
- * Method signatures:
908
- * drawEllipse($x1, $y1, $x2, $y2);
909
- * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
910
- *
911
- * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
912
- *
913
- * @param float $x1
914
- * @param float $y1
915
- * @param float $x2
916
- * @param float $y2
917
- * @param float $startAngle
918
- * @param float $endAngle
919
- * @return Zend_Pdf_Page
920
- */
921
- public function clipEllipse($x1, $y1, $x2, $y2, $startAngle = null, $endAngle = null)
922
- {
923
- $this->_addProcSet('PDF');
924
-
925
- if ($x2 < $x1) {
926
- $temp = $x1;
927
- $x1 = $x2;
928
- $x2 = $temp;
929
- }
930
- if ($y2 < $y1) {
931
- $temp = $y1;
932
- $y1 = $y2;
933
- $y2 = $temp;
934
- }
935
-
936
- $x = ($x1 + $x2)/2.;
937
- $y = ($y1 + $y2)/2.;
938
-
939
- $xC = new Zend_Pdf_Element_Numeric($x);
940
- $yC = new Zend_Pdf_Element_Numeric($y);
941
-
942
- if ($startAngle !== null) {
943
- if ($startAngle != 0) { $startAngle = fmod($startAngle, M_PI*2); }
944
- if ($endAngle != 0) { $endAngle = fmod($endAngle, M_PI*2); }
945
-
946
- if ($startAngle > $endAngle) {
947
- $endAngle += M_PI*2;
948
- }
949
-
950
- $clipPath = $xC->toString() . ' ' . $yC->toString() . " m\n";
951
- $clipSectors = (int)ceil(($endAngle - $startAngle)/M_PI_4);
952
- $clipRadius = max($x2 - $x1, $y2 - $y1);
953
-
954
- for($count = 0; $count <= $clipSectors; $count++) {
955
- $pAngle = $startAngle + ($endAngle - $startAngle)*$count/(float)$clipSectors;
956
-
957
- $pX = new Zend_Pdf_Element_Numeric($x + cos($pAngle)*$clipRadius);
958
- $pY = new Zend_Pdf_Element_Numeric($y + sin($pAngle)*$clipRadius);
959
- $clipPath .= $pX->toString() . ' ' . $pY->toString() . " l\n";
960
- }
961
-
962
- $this->_contents .= $clipPath . "h\nW\nn\n";
963
- }
964
-
965
- $xLeft = new Zend_Pdf_Element_Numeric($x1);
966
- $xRight = new Zend_Pdf_Element_Numeric($x2);
967
- $yUp = new Zend_Pdf_Element_Numeric($y2);
968
- $yDown = new Zend_Pdf_Element_Numeric($y1);
969
-
970
- $xDelta = 2*(M_SQRT2 - 1)*($x2 - $x1)/3.;
971
- $yDelta = 2*(M_SQRT2 - 1)*($y2 - $y1)/3.;
972
- $xr = new Zend_Pdf_Element_Numeric($x + $xDelta);
973
- $xl = new Zend_Pdf_Element_Numeric($x - $xDelta);
974
- $yu = new Zend_Pdf_Element_Numeric($y + $yDelta);
975
- $yd = new Zend_Pdf_Element_Numeric($y - $yDelta);
976
-
977
- $this->_contents .= $xC->toString() . ' ' . $yUp->toString() . " m\n"
978
- . $xr->toString() . ' ' . $yUp->toString() . ' '
979
- . $xRight->toString() . ' ' . $yu->toString() . ' '
980
- . $xRight->toString() . ' ' . $yC->toString() . " c\n"
981
- . $xRight->toString() . ' ' . $yd->toString() . ' '
982
- . $xr->toString() . ' ' . $yDown->toString() . ' '
983
- . $xC->toString() . ' ' . $yDown->toString() . " c\n"
984
- . $xl->toString() . ' ' . $yDown->toString() . ' '
985
- . $xLeft->toString() . ' ' . $yd->toString() . ' '
986
- . $xLeft->toString() . ' ' . $yC->toString() . " c\n"
987
- . $xLeft->toString() . ' ' . $yu->toString() . ' '
988
- . $xl->toString() . ' ' . $yUp->toString() . ' '
989
- . $xC->toString() . ' ' . $yUp->toString() . " c\n"
990
- . "h\nW\nn\n";
991
-
992
- return $this;
993
- }
994
-
995
-
996
- /**
997
- * Intersect current clipping area with a polygon.
998
- *
999
- * @param array $x - array of float (the X co-ordinates of the vertices)
1000
- * @param array $y - array of float (the Y co-ordinates of the vertices)
1001
- * @param integer $fillMethod
1002
- * @return Zend_Pdf_Page
1003
- */
1004
- public function clipPolygon($x, $y, $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING)
1005
- {
1006
- $this->_addProcSet('PDF');
1007
-
1008
- $firstPoint = true;
1009
- foreach ($x as $id => $xVal) {
1010
- $xObj = new Zend_Pdf_Element_Numeric($xVal);
1011
- $yObj = new Zend_Pdf_Element_Numeric($y[$id]);
1012
-
1013
- if ($firstPoint) {
1014
- $path = $xObj->toString() . ' ' . $yObj->toString() . " m\n";
1015
- $firstPoint = false;
1016
- } else {
1017
- $path .= $xObj->toString() . ' ' . $yObj->toString() . " l\n";
1018
- }
1019
- }
1020
-
1021
- $this->_contents .= $path;
1022
-
1023
- if ($fillMethod == Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING) {
1024
- $this->_contents .= " h\n W\nn\n";
1025
- } else {
1026
- // Even-Odd fill method.
1027
- $this->_contents .= " h\n W*\nn\n";
1028
- }
1029
-
1030
- return $this;
1031
- }
1032
-
1033
- /**
1034
- * Intersect current clipping area with a rectangle.
1035
- *
1036
- * @param float $x1
1037
- * @param float $y1
1038
- * @param float $x2
1039
- * @param float $y2
1040
- * @return Zend_Pdf_Page
1041
- */
1042
- public function clipRectangle($x1, $y1, $x2, $y2)
1043
- {
1044
- $this->_addProcSet('PDF');
1045
-
1046
- $x1Obj = new Zend_Pdf_Element_Numeric($x1);
1047
- $y1Obj = new Zend_Pdf_Element_Numeric($y1);
1048
- $widthObj = new Zend_Pdf_Element_Numeric($x2 - $x1);
1049
- $height2Obj = new Zend_Pdf_Element_Numeric($y2 - $y1);
1050
-
1051
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
1052
- . $widthObj->toString() . ' ' . $height2Obj->toString() . " re\n"
1053
- . " W\nn\n";
1054
-
1055
- return $this;
1056
- }
1057
-
1058
- /**
1059
- * Draw a Zend_Pdf_ContentStream at the specified position on the page
1060
- *
1061
- * @param ZPdfContentStream $cs
1062
- * @param float $x1
1063
- * @param float $y1
1064
- * @param float $x2
1065
- * @param float $y2
1066
- * @return Zend_Pdf_Page
1067
- */
1068
- public function drawContentStream($cs, $x1, $y1, $x2, $y2)
1069
- {
1070
- /** @todo implementation */
1071
- return $this;
1072
- }
1073
-
1074
- /**
1075
- * Draw a circle centered on x, y with a radius of radius.
1076
- *
1077
- * Method signatures:
1078
- * drawCircle($x, $y, $radius);
1079
- * drawCircle($x, $y, $radius, $fillType);
1080
- * drawCircle($x, $y, $radius, $startAngle, $endAngle);
1081
- * drawCircle($x, $y, $radius, $startAngle, $endAngle, $fillType);
1082
- *
1083
- *
1084
- * It's not a really circle, because PDF supports only cubic Bezier curves.
1085
- * But _very_ good approximation.
1086
- * It differs from a real circle on a maximum 0.00026 radiuses
1087
- * (at PI/8, 3*PI/8, 5*PI/8, 7*PI/8, 9*PI/8, 11*PI/8, 13*PI/8 and 15*PI/8 angles).
1088
- * At 0, PI/4, PI/2, 3*PI/4, PI, 5*PI/4, 3*PI/2 and 7*PI/4 it's exactly a tangent to a circle.
1089
- *
1090
- * @param float $x
1091
- * @param float $y
1092
- * @param float $radius
1093
- * @param mixed $param4
1094
- * @param mixed $param5
1095
- * @param mixed $param6
1096
- * @return Zend_Pdf_Page
1097
- */
1098
- public function drawCircle($x, $y, $radius, $param4 = null, $param5 = null, $param6 = null)
1099
- {
1100
- $this->drawEllipse($x - $radius, $y - $radius,
1101
- $x + $radius, $y + $radius,
1102
- $param4, $param5, $param6);
1103
-
1104
- return $this;
1105
- }
1106
-
1107
- /**
1108
- * Draw an ellipse inside the specified rectangle.
1109
- *
1110
- * Method signatures:
1111
- * drawEllipse($x1, $y1, $x2, $y2);
1112
- * drawEllipse($x1, $y1, $x2, $y2, $fillType);
1113
- * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
1114
- * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle, $fillType);
1115
- *
1116
- * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
1117
- *
1118
- * @param float $x1
1119
- * @param float $y1
1120
- * @param float $x2
1121
- * @param float $y2
1122
- * @param mixed $param5
1123
- * @param mixed $param6
1124
- * @param mixed $param7
1125
- * @return Zend_Pdf_Page
1126
- */
1127
- public function drawEllipse($x1, $y1, $x2, $y2, $param5 = null, $param6 = null, $param7 = null)
1128
- {
1129
- if ($param5 === null) {
1130
- // drawEllipse($x1, $y1, $x2, $y2);
1131
- $startAngle = null;
1132
- $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE;
1133
- } else if ($param6 === null) {
1134
- // drawEllipse($x1, $y1, $x2, $y2, $fillType);
1135
- $startAngle = null;
1136
- $fillType = $param5;
1137
- } else {
1138
- // drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
1139
- // drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle, $fillType);
1140
- $startAngle = $param5;
1141
- $endAngle = $param6;
1142
-
1143
- if ($param7 === null) {
1144
- $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE;
1145
- } else {
1146
- $fillType = $param7;
1147
- }
1148
- }
1149
-
1150
- $this->_addProcSet('PDF');
1151
-
1152
- if ($x2 < $x1) {
1153
- $temp = $x1;
1154
- $x1 = $x2;
1155
- $x2 = $temp;
1156
- }
1157
- if ($y2 < $y1) {
1158
- $temp = $y1;
1159
- $y1 = $y2;
1160
- $y2 = $temp;
1161
- }
1162
-
1163
- $x = ($x1 + $x2)/2.;
1164
- $y = ($y1 + $y2)/2.;
1165
-
1166
- $xC = new Zend_Pdf_Element_Numeric($x);
1167
- $yC = new Zend_Pdf_Element_Numeric($y);
1168
-
1169
- if ($startAngle !== null) {
1170
- if ($startAngle != 0) { $startAngle = fmod($startAngle, M_PI*2); }
1171
- if ($endAngle != 0) { $endAngle = fmod($endAngle, M_PI*2); }
1172
-
1173
- if ($startAngle > $endAngle) {
1174
- $endAngle += M_PI*2;
1175
- }
1176
-
1177
- $clipPath = $xC->toString() . ' ' . $yC->toString() . " m\n";
1178
- $clipSectors = (int)ceil(($endAngle - $startAngle)/M_PI_4);
1179
- $clipRadius = max($x2 - $x1, $y2 - $y1);
1180
-
1181
- for($count = 0; $count <= $clipSectors; $count++) {
1182
- $pAngle = $startAngle + ($endAngle - $startAngle)*$count/(float)$clipSectors;
1183
-
1184
- $pX = new Zend_Pdf_Element_Numeric($x + cos($pAngle)*$clipRadius);
1185
- $pY = new Zend_Pdf_Element_Numeric($y + sin($pAngle)*$clipRadius);
1186
- $clipPath .= $pX->toString() . ' ' . $pY->toString() . " l\n";
1187
- }
1188
-
1189
- $this->_contents .= "q\n" . $clipPath . "h\nW\nn\n";
1190
- }
1191
-
1192
- $xLeft = new Zend_Pdf_Element_Numeric($x1);
1193
- $xRight = new Zend_Pdf_Element_Numeric($x2);
1194
- $yUp = new Zend_Pdf_Element_Numeric($y2);
1195
- $yDown = new Zend_Pdf_Element_Numeric($y1);
1196
-
1197
- $xDelta = 2*(M_SQRT2 - 1)*($x2 - $x1)/3.;
1198
- $yDelta = 2*(M_SQRT2 - 1)*($y2 - $y1)/3.;
1199
- $xr = new Zend_Pdf_Element_Numeric($x + $xDelta);
1200
- $xl = new Zend_Pdf_Element_Numeric($x - $xDelta);
1201
- $yu = new Zend_Pdf_Element_Numeric($y + $yDelta);
1202
- $yd = new Zend_Pdf_Element_Numeric($y - $yDelta);
1203
-
1204
- $this->_contents .= $xC->toString() . ' ' . $yUp->toString() . " m\n"
1205
- . $xr->toString() . ' ' . $yUp->toString() . ' '
1206
- . $xRight->toString() . ' ' . $yu->toString() . ' '
1207
- . $xRight->toString() . ' ' . $yC->toString() . " c\n"
1208
- . $xRight->toString() . ' ' . $yd->toString() . ' '
1209
- . $xr->toString() . ' ' . $yDown->toString() . ' '
1210
- . $xC->toString() . ' ' . $yDown->toString() . " c\n"
1211
- . $xl->toString() . ' ' . $yDown->toString() . ' '
1212
- . $xLeft->toString() . ' ' . $yd->toString() . ' '
1213
- . $xLeft->toString() . ' ' . $yC->toString() . " c\n"
1214
- . $xLeft->toString() . ' ' . $yu->toString() . ' '
1215
- . $xl->toString() . ' ' . $yUp->toString() . ' '
1216
- . $xC->toString() . ' ' . $yUp->toString() . " c\n";
1217
-
1218
- switch ($fillType) {
1219
- case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
1220
- $this->_contents .= " B*\n";
1221
- break;
1222
- case Zend_Pdf_Page::SHAPE_DRAW_FILL:
1223
- $this->_contents .= " f*\n";
1224
- break;
1225
- case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
1226
- $this->_contents .= " S\n";
1227
- break;
1228
- }
1229
-
1230
- if ($startAngle !== null) {
1231
- $this->_contents .= "Q\n";
1232
- }
1233
-
1234
- return $this;
1235
- }
1236
-
1237
- /**
1238
- * Draw an image at the specified position on the page.
1239
- *
1240
- * @param Zend_Pdf_Image $image
1241
- * @param float $x1
1242
- * @param float $y1
1243
- * @param float $x2
1244
- * @param float $y2
1245
- * @return Zend_Pdf_Page
1246
- */
1247
- public function drawImage(Zend_Pdf_Resource_Image $image, $x1, $y1, $x2, $y2)
1248
- {
1249
- $this->_addProcSet('PDF');
1250
-
1251
- $imageName = $this->_attachResource('XObject', $image);
1252
- $imageNameObj = new Zend_Pdf_Element_Name($imageName);
1253
-
1254
- $x1Obj = new Zend_Pdf_Element_Numeric($x1);
1255
- $y1Obj = new Zend_Pdf_Element_Numeric($y1);
1256
- $widthObj = new Zend_Pdf_Element_Numeric($x2 - $x1);
1257
- $heightObj = new Zend_Pdf_Element_Numeric($y2 - $y1);
1258
-
1259
- $this->_contents .= "q\n"
1260
- . '1 0 0 1 ' . $x1Obj->toString() . ' ' . $y1Obj->toString() . " cm\n"
1261
- . $widthObj->toString() . ' 0 0 ' . $heightObj->toString() . " 0 0 cm\n"
1262
- . $imageNameObj->toString() . " Do\n"
1263
- . "Q\n";
1264
-
1265
- return $this;
1266
- }
1267
-
1268
- /**
1269
- * Draw a LayoutBox at the specified position on the page.
1270
- *
1271
- * @param Zend_Pdf_Element_LayoutBox $box
1272
- * @param float $x
1273
- * @param float $y
1274
- * @return Zend_Pdf_Page
1275
- */
1276
- public function drawLayoutBox($box, $x, $y)
1277
- {
1278
- /** @todo implementation */
1279
- return $this;
1280
- }
1281
-
1282
- /**
1283
- * Draw a line from x1,y1 to x2,y2.
1284
- *
1285
- * @param float $x1
1286
- * @param float $y1
1287
- * @param float $x2
1288
- * @param float $y2
1289
- * @return Zend_Pdf_Page
1290
- */
1291
- public function drawLine($x1, $y1, $x2, $y2)
1292
- {
1293
- $this->_addProcSet('PDF');
1294
-
1295
- $x1Obj = new Zend_Pdf_Element_Numeric($x1);
1296
- $y1Obj = new Zend_Pdf_Element_Numeric($y1);
1297
- $x2Obj = new Zend_Pdf_Element_Numeric($x2);
1298
- $y2Obj = new Zend_Pdf_Element_Numeric($y2);
1299
-
1300
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " m\n"
1301
- . $x2Obj->toString() . ' ' . $y2Obj->toString() . " l\n S\n";
1302
-
1303
- return $this;
1304
- }
1305
-
1306
- /**
1307
- * Draw a polygon.
1308
- *
1309
- * If $fillType is Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE or
1310
- * Zend_Pdf_Page::SHAPE_DRAW_FILL, then polygon is automatically closed.
1311
- * See detailed description of these methods in a PDF documentation
1312
- * (section 4.4.2 Path painting Operators, Filling)
1313
- *
1314
- * @param array $x - array of float (the X co-ordinates of the vertices)
1315
- * @param array $y - array of float (the Y co-ordinates of the vertices)
1316
- * @param integer $fillType
1317
- * @param integer $fillMethod
1318
- * @return Zend_Pdf_Page
1319
- */
1320
- public function drawPolygon($x, $y,
1321
- $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE,
1322
- $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING)
1323
- {
1324
- $this->_addProcSet('PDF');
1325
-
1326
- $firstPoint = true;
1327
- foreach ($x as $id => $xVal) {
1328
- $xObj = new Zend_Pdf_Element_Numeric($xVal);
1329
- $yObj = new Zend_Pdf_Element_Numeric($y[$id]);
1330
-
1331
- if ($firstPoint) {
1332
- $path = $xObj->toString() . ' ' . $yObj->toString() . " m\n";
1333
- $firstPoint = false;
1334
- } else {
1335
- $path .= $xObj->toString() . ' ' . $yObj->toString() . " l\n";
1336
- }
1337
- }
1338
-
1339
- $this->_contents .= $path;
1340
-
1341
- switch ($fillType) {
1342
- case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
1343
- if ($fillMethod == Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING) {
1344
- $this->_contents .= " b\n";
1345
- } else {
1346
- // Even-Odd fill method.
1347
- $this->_contents .= " b*\n";
1348
- }
1349
- break;
1350
- case Zend_Pdf_Page::SHAPE_DRAW_FILL:
1351
- if ($fillMethod == Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING) {
1352
- $this->_contents .= " h\n f\n";
1353
- } else {
1354
- // Even-Odd fill method.
1355
- $this->_contents .= " h\n f*\n";
1356
- }
1357
- break;
1358
- case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
1359
- $this->_contents .= " S\n";
1360
- break;
1361
- }
1362
-
1363
- return $this;
1364
- }
1365
-
1366
- /**
1367
- * Draw a rectangle.
1368
- *
1369
- * Fill types:
1370
- * Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
1371
- * Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
1372
- * Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
1373
- *
1374
- * @param float $x1
1375
- * @param float $y1
1376
- * @param float $x2
1377
- * @param float $y2
1378
- * @param integer $fillType
1379
- * @return Zend_Pdf_Page
1380
- */
1381
- public function drawRectangle($x1, $y1, $x2, $y2, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)
1382
- {
1383
- $this->_addProcSet('PDF');
1384
-
1385
- $x1Obj = new Zend_Pdf_Element_Numeric($x1);
1386
- $y1Obj = new Zend_Pdf_Element_Numeric($y1);
1387
- $widthObj = new Zend_Pdf_Element_Numeric($x2 - $x1);
1388
- $height2Obj = new Zend_Pdf_Element_Numeric($y2 - $y1);
1389
-
1390
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
1391
- . $widthObj->toString() . ' ' . $height2Obj->toString() . " re\n";
1392
-
1393
- switch ($fillType) {
1394
- case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
1395
- $this->_contents .= " B*\n";
1396
- break;
1397
- case Zend_Pdf_Page::SHAPE_DRAW_FILL:
1398
- $this->_contents .= " f*\n";
1399
- break;
1400
- case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
1401
- $this->_contents .= " S\n";
1402
- break;
1403
- }
1404
-
1405
- return $this;
1406
- }
1407
-
1408
- /**
1409
- * Draw a rounded rectangle.
1410
- *
1411
- * Fill types:
1412
- * Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
1413
- * Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
1414
- * Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
1415
- *
1416
- * radius is an integer representing radius of the four corners, or an array
1417
- * of four integers representing the radius starting at top left, going
1418
- * clockwise
1419
- *
1420
- * @param float $x1
1421
- * @param float $y1
1422
- * @param float $x2
1423
- * @param float $y2
1424
- * @param integer|array $radius
1425
- * @param integer $fillType
1426
- * @return Zend_Pdf_Page
1427
- */
1428
- public function drawRoundedRectangle($x1, $y1, $x2, $y2, $radius,
1429
- $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)
1430
- {
1431
-
1432
- $this->_addProcSet('PDF');
1433
-
1434
- if(!is_array($radius)) {
1435
- $radius = array($radius, $radius, $radius, $radius);
1436
- } else {
1437
- for ($i = 0; $i < 4; $i++) {
1438
- if(!isset($radius[$i])) {
1439
- $radius[$i] = 0;
1440
- }
1441
- }
1442
- }
1443
-
1444
- $topLeftX = $x1;
1445
- $topLeftY = $y2;
1446
- $topRightX = $x2;
1447
- $topRightY = $y2;
1448
- $bottomRightX = $x2;
1449
- $bottomRightY = $y1;
1450
- $bottomLeftX = $x1;
1451
- $bottomLeftY = $y1;
1452
-
1453
- //draw top side
1454
- $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX + $radius[0]);
1455
- $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY);
1456
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " m\n";
1457
- $x1Obj = new Zend_Pdf_Element_Numeric($topRightX - $radius[1]);
1458
- $y1Obj = new Zend_Pdf_Element_Numeric($topRightY);
1459
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
1460
-
1461
- //draw top right corner if needed
1462
- if ($radius[1] != 0) {
1463
- $x1Obj = new Zend_Pdf_Element_Numeric($topRightX);
1464
- $y1Obj = new Zend_Pdf_Element_Numeric($topRightY);
1465
- $x2Obj = new Zend_Pdf_Element_Numeric($topRightX);
1466
- $y2Obj = new Zend_Pdf_Element_Numeric($topRightY);
1467
- $x3Obj = new Zend_Pdf_Element_Numeric($topRightX);
1468
- $y3Obj = new Zend_Pdf_Element_Numeric($topRightY - $radius[1]);
1469
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
1470
- . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
1471
- . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
1472
- . " c\n";
1473
- }
1474
-
1475
- //draw right side
1476
- $x1Obj = new Zend_Pdf_Element_Numeric($bottomRightX);
1477
- $y1Obj = new Zend_Pdf_Element_Numeric($bottomRightY + $radius[2]);
1478
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
1479
-
1480
- //draw bottom right corner if needed
1481
- if ($radius[2] != 0) {
1482
- $x1Obj = new Zend_Pdf_Element_Numeric($bottomRightX);
1483
- $y1Obj = new Zend_Pdf_Element_Numeric($bottomRightY);
1484
- $x2Obj = new Zend_Pdf_Element_Numeric($bottomRightX);
1485
- $y2Obj = new Zend_Pdf_Element_Numeric($bottomRightY);
1486
- $x3Obj = new Zend_Pdf_Element_Numeric($bottomRightX - $radius[2]);
1487
- $y3Obj = new Zend_Pdf_Element_Numeric($bottomRightY);
1488
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
1489
- . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
1490
- . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
1491
- . " c\n";
1492
- }
1493
-
1494
- //draw bottom side
1495
- $x1Obj = new Zend_Pdf_Element_Numeric($bottomLeftX + $radius[3]);
1496
- $y1Obj = new Zend_Pdf_Element_Numeric($bottomLeftY);
1497
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
1498
-
1499
- //draw bottom left corner if needed
1500
- if ($radius[3] != 0) {
1501
- $x1Obj = new Zend_Pdf_Element_Numeric($bottomLeftX);
1502
- $y1Obj = new Zend_Pdf_Element_Numeric($bottomLeftY);
1503
- $x2Obj = new Zend_Pdf_Element_Numeric($bottomLeftX);
1504
- $y2Obj = new Zend_Pdf_Element_Numeric($bottomLeftY);
1505
- $x3Obj = new Zend_Pdf_Element_Numeric($bottomLeftX);
1506
- $y3Obj = new Zend_Pdf_Element_Numeric($bottomLeftY + $radius[3]);
1507
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
1508
- . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
1509
- . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
1510
- . " c\n";
1511
- }
1512
-
1513
- //draw left side
1514
- $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX);
1515
- $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY - $radius[0]);
1516
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
1517
-
1518
- //draw top left corner if needed
1519
- if ($radius[0] != 0) {
1520
- $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX);
1521
- $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY);
1522
- $x2Obj = new Zend_Pdf_Element_Numeric($topLeftX);
1523
- $y2Obj = new Zend_Pdf_Element_Numeric($topLeftY);
1524
- $x3Obj = new Zend_Pdf_Element_Numeric($topLeftX + $radius[0]);
1525
- $y3Obj = new Zend_Pdf_Element_Numeric($topLeftY);
1526
- $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
1527
- . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
1528
- . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
1529
- . " c\n";
1530
- }
1531
-
1532
- switch ($fillType) {
1533
- case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
1534
- $this->_contents .= " B*\n";
1535
- break;
1536
- case Zend_Pdf_Page::SHAPE_DRAW_FILL:
1537
- $this->_contents .= " f*\n";
1538
- break;
1539
- case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
1540
- $this->_contents .= " S\n";
1541
- break;
1542
- }
1543
-
1544
- return $this;
1545
- }
1546
-
1547
- /**
1548
- * Draw a line of text at the specified position.
1549
- *
1550
- * @param string $text
1551
- * @param float $x
1552
- * @param float $y
1553
- * @param string $charEncoding (optional) Character encoding of source text.
1554
- * Defaults to current locale.
1555
- * @throws Zend_Pdf_Exception
1556
- * @return Zend_Pdf_Page
1557
- */
1558
- public function drawText($text, $x, $y, $charEncoding = '')
1559
- {
1560
- if ($this->_font === null) {
1561
- #require_once 'Zend/Pdf/Exception.php';
1562
- throw new Zend_Pdf_Exception('Font has not been set');
1563
- }
1564
-
1565
- $this->_addProcSet('Text');
1566
-
1567
- $textObj = new Zend_Pdf_Element_String($this->_font->encodeString($text, $charEncoding));
1568
- $xObj = new Zend_Pdf_Element_Numeric($x);
1569
- $yObj = new Zend_Pdf_Element_Numeric($y);
1570
-
1571
- $this->_contents .= "BT\n"
1572
- . $xObj->toString() . ' ' . $yObj->toString() . " Td\n"
1573
- . $textObj->toString() . " Tj\n"
1574
- . "ET\n";
1575
-
1576
- return $this;
1577
- }
1578
-
1579
- /**
1580
- *
1581
- * @param Zend_Pdf_Annotation $annotation
1582
- * @return Zend_Pdf_Page
1583
- */
1584
- public function attachAnnotation(Zend_Pdf_Annotation $annotation)
1585
- {
1586
- $annotationDictionary = $annotation->getResource();
1587
- if (!$annotationDictionary instanceof Zend_Pdf_Element_Object &&
1588
- !$annotationDictionary instanceof Zend_Pdf_Element_Reference) {
1589
- $annotationDictionary = $this->_objFactory->newObject($annotationDictionary);
1590
- }
1591
-
1592
- if ($this->_pageDictionary->Annots === null) {
1593
- $this->_pageDictionary->touch();
1594
- $this->_pageDictionary->Annots = new Zend_Pdf_Element_Array();
1595
- } else {
1596
- $this->_pageDictionary->Annots->touch();
1597
- }
1598
-
1599
- $this->_pageDictionary->Annots->items[] = $annotationDictionary;
1600
 
1601
  $annotationDictionary->touch();
1602
- $annotationDictionary->P = $this->_pageDictionary;
1603
-
1604
- return $this;
1605
- }
1606
-
1607
- /**
1608
- * Return the height of this page in points.
1609
- *
1610
- * @return float
1611
- */
1612
- public function getHeight()
1613
- {
1614
- return $this->_pageDictionary->MediaBox->items[3]->value -
1615
- $this->_pageDictionary->MediaBox->items[1]->value;
1616
- }
1617
-
1618
- /**
1619
- * Return the width of this page in points.
1620
- *
1621
- * @return float
1622
- */
1623
- public function getWidth()
1624
- {
1625
- return $this->_pageDictionary->MediaBox->items[2]->value -
1626
- $this->_pageDictionary->MediaBox->items[0]->value;
1627
- }
1628
-
1629
- /**
1630
- * Close the path by drawing a straight line back to it's beginning.
1631
- *
1632
- * @throws Zend_Pdf_Exception - if a path hasn't been started with pathMove()
1633
- * @return Zend_Pdf_Page
1634
- */
1635
- public function pathClose()
1636
- {
1637
- /** @todo implementation */
1638
- return $this;
1639
- }
1640
-
1641
- /**
1642
- * Continue the open path in a straight line to the specified position.
1643
- *
1644
- * @param float $x - the X co-ordinate to move to
1645
- * @param float $y - the Y co-ordinate to move to
1646
- * @return Zend_Pdf_Page
1647
- */
1648
- public function pathLine($x, $y)
1649
- {
1650
- /** @todo implementation */
1651
- return $this;
1652
- }
1653
-
1654
- /**
1655
- * Start a new path at the specified position. If a path has already been started,
1656
- * move the cursor without drawing a line.
1657
- *
1658
- * @param float $x - the X co-ordinate to move to
1659
- * @param float $y - the Y co-ordinate to move to
1660
- * @return Zend_Pdf_Page
1661
- */
1662
- public function pathMove($x, $y)
1663
- {
1664
- /** @todo implementation */
1665
- return $this;
1666
- }
1667
-
1668
- /**
1669
- * Writes the raw data to the page's content stream.
1670
- *
1671
- * Be sure to consult the PDF reference to ensure your syntax is correct. No
1672
- * attempt is made to ensure the validity of the stream data.
1673
- *
1674
- * @param string $data
1675
- * @param string $procSet (optional) Name of ProcSet to add.
1676
- * @return Zend_Pdf_Page
1677
- */
1678
- public function rawWrite($data, $procSet = null)
1679
- {
1680
- if (! empty($procSet)) {
1681
- $this->_addProcSet($procSet);
1682
- }
1683
- $this->_contents .= $data;
1684
-
1685
- return $this;
1686
- }
1687
-
1688
- /**
1689
- * Rotate the page.
1690
- *
1691
- * @param float $x - the X co-ordinate of rotation point
1692
- * @param float $y - the Y co-ordinate of rotation point
1693
- * @param float $angle - rotation angle
1694
- * @return Zend_Pdf_Page
1695
- */
1696
- public function rotate($x, $y, $angle)
1697
- {
1698
- $cos = new Zend_Pdf_Element_Numeric(cos($angle));
1699
- $sin = new Zend_Pdf_Element_Numeric(sin($angle));
1700
- $mSin = new Zend_Pdf_Element_Numeric(-$sin->value);
1701
-
1702
- $xObj = new Zend_Pdf_Element_Numeric($x);
1703
- $yObj = new Zend_Pdf_Element_Numeric($y);
1704
-
1705
- $mXObj = new Zend_Pdf_Element_Numeric(-$x);
1706
- $mYObj = new Zend_Pdf_Element_Numeric(-$y);
1707
-
1708
-
1709
- $this->_addProcSet('PDF');
1710
- $this->_contents .= '1 0 0 1 ' . $xObj->toString() . ' ' . $yObj->toString() . " cm\n"
1711
- . $cos->toString() . ' ' . $sin->toString() . ' ' . $mSin->toString() . ' ' . $cos->toString() . " 0 0 cm\n"
1712
- . '1 0 0 1 ' . $mXObj->toString() . ' ' . $mYObj->toString() . " cm\n";
1713
-
1714
- return $this;
1715
- }
1716
-
1717
- /**
1718
- * Scale coordination system.
1719
- *
1720
- * @param float $xScale - X dimention scale factor
1721
- * @param float $yScale - Y dimention scale factor
1722
- * @return Zend_Pdf_Page
1723
- */
1724
- public function scale($xScale, $yScale)
1725
- {
1726
- $xScaleObj = new Zend_Pdf_Element_Numeric($xScale);
1727
- $yScaleObj = new Zend_Pdf_Element_Numeric($yScale);
1728
-
1729
- $this->_addProcSet('PDF');
1730
- $this->_contents .= $xScaleObj->toString() . ' 0 0 ' . $yScaleObj->toString() . " 0 0 cm\n";
1731
-
1732
- return $this;
1733
- }
1734
-
1735
- /**
1736
- * Translate coordination system.
1737
- *
1738
- * @param float $xShift - X coordinate shift
1739
- * @param float $yShift - Y coordinate shift
1740
- * @return Zend_Pdf_Page
1741
- */
1742
- public function translate($xShift, $yShift)
1743
- {
1744
- $xShiftObj = new Zend_Pdf_Element_Numeric($xShift);
1745
- $yShiftObj = new Zend_Pdf_Element_Numeric($yShift);
1746
-
1747
- $this->_addProcSet('PDF');
1748
- $this->_contents .= '1 0 0 1 ' . $xShiftObj->toString() . ' ' . $yShiftObj->toString() . " cm\n";
1749
-
1750
- return $this;
1751
- }
1752
-
1753
- /**
1754
- * Translate coordination system.
1755
- *
1756
- * @param float $x - the X co-ordinate of axis skew point
1757
- * @param float $y - the Y co-ordinate of axis skew point
1758
- * @param float $xAngle - X axis skew angle
1759
- * @param float $yAngle - Y axis skew angle
1760
- * @return Zend_Pdf_Page
1761
- */
1762
- public function skew($x, $y, $xAngle, $yAngle)
1763
- {
1764
- $tanXObj = new Zend_Pdf_Element_Numeric(tan($xAngle));
1765
- $tanYObj = new Zend_Pdf_Element_Numeric(-tan($yAngle));
1766
-
1767
- $xObj = new Zend_Pdf_Element_Numeric($x);
1768
- $yObj = new Zend_Pdf_Element_Numeric($y);
1769
-
1770
- $mXObj = new Zend_Pdf_Element_Numeric(-$x);
1771
- $mYObj = new Zend_Pdf_Element_Numeric(-$y);
1772
-
1773
- $this->_addProcSet('PDF');
1774
- $this->_contents .= '1 0 0 1 ' . $xObj->toString() . ' ' . $yObj->toString() . " cm\n"
1775
- . '1 ' . $tanXObj->toString() . ' ' . $tanYObj->toString() . " 1 0 0 cm\n"
1776
- . '1 0 0 1 ' . $mXObj->toString() . ' ' . $mYObj->toString() . " cm\n";
1777
 
1778
  return $this;
1779
  }
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Page.php 22909 2010-08-27 19:57:48Z alexander $
20
  */
21
 
22
  /** Internally used classes */
29
  #require_once 'Zend/Pdf/Element/Null.php';
30
  #require_once 'Zend/Pdf/Element/Numeric.php';
31
  #require_once 'Zend/Pdf/Element/String.php';
32
+ #require_once 'Zend/Pdf/Resource/Unified.php';
33
+
34
+ #require_once 'Zend/Pdf/Canvas/Abstract.php';
35
 
36
 
37
  /**
41
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
42
  * @license http://framework.zend.com/license/new-bsd New BSD License
43
  */
44
+ class Zend_Pdf_Page extends Zend_Pdf_Canvas_Abstract
45
  {
46
  /**** Class Constants ****/
47
 
114
  *
115
  * @var Zend_Pdf_Element_Reference|Zend_Pdf_Element_Object
116
  */
117
+ protected $_dictionary;
118
 
119
  /**
120
  * PDF objects factory.
131
  */
132
  protected $_attached;
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  /**
135
  * Safe Graphics State semafore
136
  *
142
  */
143
  protected $_safeGS;
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  /**
146
  * Object constructor.
147
  * Constructor signatures:
153
  * Zend_Pdf_ElementFactory_Interface $factory);
154
  * ---------------------------------------------------------
155
  *
156
+ * 2. Make a copy of the PDF page.
157
  * New page is created in the same context as source page. Object factory is shared.
158
  * Thus it will be attached to the document, but need to be placed into Zend_Pdf::$pages array
159
  * to be included into output.
183
  */
184
  public function __construct($param1, $param2 = null, $param3 = null)
185
  {
186
+ if (($param1 instanceof Zend_Pdf_Element_Reference ||
187
+ $param1 instanceof Zend_Pdf_Element_Object
188
+ ) &&
189
  $param2 instanceof Zend_Pdf_ElementFactory_Interface &&
190
  $param3 === null
191
  ) {
192
+ switch ($param1->getType()) {
193
+ case Zend_Pdf_Element::TYPE_DICTIONARY:
194
+ $this->_dictionary = $param1;
195
+ $this->_objFactory = $param2;
196
+ $this->_attached = true;
197
+ $this->_safeGS = false;
198
+ return;
199
+ break;
200
 
201
+ case Zend_Pdf_Element::TYPE_NULL:
202
+ $this->_objFactory = $param2;
203
+ $pageWidth = $pageHeight = 0;
204
+ break;
205
 
206
+ default:
207
+ #require_once 'Zend/Pdf/Exception.php';
208
+ throw new Zend_Pdf_Exception('Unrecognized object type.');
209
+ break;
210
+
211
+ }
212
  } else if ($param1 instanceof Zend_Pdf_Page && $param2 === null && $param3 === null) {
213
+ // Duplicate existing page.
214
  // Let already existing content and resources to be shared between pages
215
  // We don't give existing content modification functionality, so we don't need "deep copy"
216
  $this->_objFactory = $param1->_objFactory;
217
  $this->_attached = &$param1->_attached;
218
  $this->_safeGS = false;
219
 
220
+ $this->_dictionary = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
221
 
222
+ foreach ($param1->_dictionary->getKeys() as $key) {
223
  if ($key == 'Contents') {
224
  // Clone Contents property
225
 
226
+ $this->_dictionary->Contents = new Zend_Pdf_Element_Array();
227
 
228
+ if ($param1->_dictionary->Contents->getType() != Zend_Pdf_Element::TYPE_ARRAY) {
229
  // Prepare array of content streams and add existing stream
230
+ $this->_dictionary->Contents->items[] = $param1->_dictionary->Contents;
231
  } else {
232
  // Clone array of the content streams
233
+ foreach ($param1->_dictionary->Contents->items as $srcContentStream) {
234
+ $this->_dictionary->Contents->items[] = $srcContentStream;
235
  }
236
  }
237
  } else {
238
+ $this->_dictionary->$key = $param1->_dictionary->$key;
239
  }
240
  }
241
 
304
  throw new Zend_Pdf_Exception('Unrecognized method signature, wrong number of arguments or wrong argument types.');
305
  }
306
 
307
+ $this->_dictionary = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
308
+ $this->_dictionary->Type = new Zend_Pdf_Element_Name('Page');
309
  #require_once 'Zend/Pdf.php';
310
+ $this->_dictionary->LastModified = new Zend_Pdf_Element_String(Zend_Pdf::pdfDate());
311
+ $this->_dictionary->Resources = new Zend_Pdf_Element_Dictionary();
312
+ $this->_dictionary->MediaBox = new Zend_Pdf_Element_Array();
313
+ $this->_dictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0);
314
+ $this->_dictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0);
315
+ $this->_dictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageWidth);
316
+ $this->_dictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageHeight);
317
+ $this->_dictionary->Contents = new Zend_Pdf_Element_Array();
318
  }
319
 
320
 
321
  /**
322
+ * Attach resource to the canvas
323
  *
324
+ * Method returns a name of the resource which can be used
325
+ * as a resource reference within drawing instructions stream
326
+ * Allowed types: 'ExtGState', 'ColorSpace', 'Pattern', 'Shading',
327
+ * 'XObject', 'Font', 'Properties'
 
 
 
 
 
 
328
  *
329
  * @param string $type
330
  * @param Zend_Pdf_Resource $resource
333
  protected function _attachResource($type, Zend_Pdf_Resource $resource)
334
  {
335
  // Check that Resources dictionary contains appropriate resource set
336
+ if ($this->_dictionary->Resources->$type === null) {
337
+ $this->_dictionary->Resources->touch();
338
+ $this->_dictionary->Resources->$type = new Zend_Pdf_Element_Dictionary();
339
  } else {
340
+ $this->_dictionary->Resources->$type->touch();
341
  }
342
 
343
  // Check, that resource is already attached to resource set.
344
  $resObject = $resource->getResource();
345
+ foreach ($this->_dictionary->Resources->$type->getKeys() as $ResID) {
346
+ if ($this->_dictionary->Resources->$type->$ResID === $resObject) {
347
  return $ResID;
348
  }
349
  }
351
  $idCounter = 1;
352
  do {
353
  $newResName = $type[0] . $idCounter++;
354
+ } while ($this->_dictionary->Resources->$type->$newResName !== null);
355
 
356
+ $this->_dictionary->Resources->$type->$newResName = $resObject;
357
  $this->_objFactory->attach($resource->getFactory());
358
 
359
  return $newResName;
367
  protected function _addProcSet($procSetName)
368
  {
369
  // Check that Resources dictionary contains ProcSet entry
370
+ if ($this->_dictionary->Resources->ProcSet === null) {
371
+ $this->_dictionary->Resources->touch();
372
+ $this->_dictionary->Resources->ProcSet = new Zend_Pdf_Element_Array();
373
  } else {
374
+ $this->_dictionary->Resources->ProcSet->touch();
375
  }
376
 
377
+ foreach ($this->_dictionary->Resources->ProcSet->items as $procSetEntry) {
378
  if ($procSetEntry->value == $procSetName) {
379
  // Procset is already included into a ProcSet array
380
  return;
381
  }
382
  }
383
 
384
+ $this->_dictionary->Resources->ProcSet->items[] = new Zend_Pdf_Element_Name($procSetName);
385
  }
386
 
387
  /**
388
+ * Returns dictionaries of used resources.
389
  *
390
+ * Used for canvas implementations interoperability
 
 
 
 
 
 
 
 
 
391
  *
392
+ * Structure of the returned array:
393
+ * array(
394
+ * <resTypeName> => array(
395
+ * <resName> => <Zend_Pdf_Resource object>,
396
+ * <resName> => <Zend_Pdf_Resource object>,
397
+ * <resName> => <Zend_Pdf_Resource object>,
398
+ * ...
399
+ * ),
400
+ * <resTypeName> => array(
401
+ * <resName> => <Zend_Pdf_Resource object>,
402
+ * <resName> => <Zend_Pdf_Resource object>,
403
+ * <resName> => <Zend_Pdf_Resource object>,
404
+ * ...
405
+ * ),
406
+ * ...
407
+ * 'ProcSet' => array()
408
+ * )
409
  *
410
+ * where ProcSet array is a list of used procedure sets names (strings).
411
+ * Allowed procedure set names: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'
412
+ *
413
+ * @internal
414
+ * @return array
415
  */
416
+ public function getResources()
417
  {
418
+ $resources = array();
419
+ $resDictionary = $this->_dictionary->Resources;
 
 
 
 
 
 
 
 
 
 
 
 
 
420
 
421
+ foreach ($resDictionary->getKeys() as $resType) {
422
+ $resources[$resType] = array();
 
 
 
 
423
 
424
+ if ($resType == 'ProcSet') {
425
+ foreach ($resDictionary->ProcSet->items as $procSetEntry) {
426
+ $resources[$resType][] = $procSetEntry->value;
427
+ }
428
+ } else {
429
+ $resMap = $resDictionary->$resType;
 
430
 
431
+ foreach ($resMap->getKeys() as $resId) {
432
+ $resources[$resType][$resId] =new Zend_Pdf_Resource_Unified($resMap->$resId);
433
+ }
 
434
  }
 
 
 
 
 
 
435
  }
436
 
437
+ return $resources;
 
 
 
438
  }
439
 
440
  /**
441
+ * Get drawing instructions stream
 
 
442
  *
443
+ * It has to be returned as a PDF stream object to make it reusable.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  *
445
+ * @internal
446
+ * @returns Zend_Pdf_Resource_ContentStream
447
  */
448
+ public function getContents()
449
  {
450
+ /** @todo implementation */
 
 
 
451
  }
452
 
453
  /**
454
+ * Return the height of this page in points.
455
  *
456
+ * @return float
 
457
  */
458
+ public function getHeight()
459
  {
460
+ return $this->_dictionary->MediaBox->items[3]->value -
461
+ $this->_dictionary->MediaBox->items[1]->value;
 
 
462
  }
463
 
464
  /**
465
+ * Return the width of this page in points.
466
  *
467
+ * @return float
 
468
  */
469
+ public function getWidth()
470
  {
471
+ return $this->_dictionary->MediaBox->items[2]->value -
472
+ $this->_dictionary->MediaBox->items[0]->value;
 
 
 
473
  }
474
 
475
  /**
476
+ * Clone page, extract it and dependent objects from the current document,
477
+ * so it can be used within other docs.
 
 
 
 
 
 
478
  */
479
+ public function __clone()
480
  {
481
+ $factory = Zend_Pdf_ElementFactory::createFactory(1);
482
+ $processed = array();
 
 
 
 
 
 
 
483
 
484
+ // Clone dictionary object.
485
+ // Do it explicitly to prevent sharing page attributes between different
486
+ // results of clonePage() operation (other resources are still shared)
487
+ $dictionary = new Zend_Pdf_Element_Dictionary();
488
+ foreach ($this->_dictionary->getKeys() as $key) {
489
+ $dictionary->$key = $this->_dictionary->$key->makeClone($factory->getFactory(),
490
+ $processed,
491
+ Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES);
492
  }
493
 
494
+ $this->_dictionary = $factory->newObject($dictionary);
495
+ $this->_objFactory = $factory;
496
+ $this->_attached = false;
497
+ $this->_style = null;
498
+ $this->_font = null;
499
  }
500
 
501
  /**
502
+ * Clone page, extract it and dependent objects from the current document,
503
+ * so it can be used within other docs.
504
  *
505
+ * @internal
506
+ * @param Zend_Pdf_ElementFactory_Interface $factory
507
+ * @param array $processed
508
  * @return Zend_Pdf_Page
509
  */
510
+ public function clonePage($factory, &$processed)
511
  {
512
+ // Clone dictionary object.
513
+ // Do it explicitly to prevent sharing page attributes between different
514
+ // results of clonePage() operation (other resources are still shared)
515
+ $dictionary = new Zend_Pdf_Element_Dictionary();
516
+ foreach ($this->_dictionary->getKeys() as $key) {
517
+ $dictionary->$key = $this->_dictionary->$key->makeClone($factory->getFactory(),
518
+ $processed,
519
+ Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES);
520
+ }
521
 
522
+ $clonedPage = new Zend_Pdf_Page($factory->newObject($dictionary), $factory);
523
+ $clonedPage->_attached = false;
 
524
 
525
+ return $clonedPage;
526
  }
527
 
528
  /**
529
+ * Retrive PDF file reference to the page
530
  *
531
+ * @internal
532
+ * @return Zend_Pdf_Element_Dictionary
533
  */
534
+ public function getPageDictionary()
535
  {
536
+ return $this->_dictionary;
 
 
 
 
 
 
 
 
 
537
  }
538
 
539
  /**
540
+ * Dump current drawing instructions into the content stream.
 
 
 
541
  *
542
+ * @todo Don't forget to close all current graphics operations (like path drawing)
 
 
543
  *
 
 
544
  * @throws Zend_Pdf_Exception
 
545
  */
546
+ public function flush()
547
  {
548
+ if ($this->_saveCount != 0) {
 
 
 
 
 
549
  #require_once 'Zend/Pdf/Exception.php';
550
+ throw new Zend_Pdf_Exception('Saved graphics state is not restored');
551
  }
552
 
553
+ if ($this->_contents == '') {
554
+ return;
555
+ }
556
 
557
+ if ($this->_dictionary->Contents->getType() != Zend_Pdf_Element::TYPE_ARRAY) {
558
+ /**
559
+ * It's a stream object.
560
+ * Prepare Contents page attribute for update.
561
+ */
562
+ $this->_dictionary->touch();
563
 
564
+ $currentPageContents = $this->_dictionary->Contents;
565
+ $this->_dictionary->Contents = new Zend_Pdf_Element_Array();
566
+ $this->_dictionary->Contents->items[] = $currentPageContents;
 
567
  } else {
568
+ $this->_dictionary->Contents->touch();
569
  }
570
 
571
+ if ((!$this->_safeGS) && (count($this->_dictionary->Contents->items) != 0)) {
572
+ /**
573
+ * Page already has some content which is not treated as safe.
574
+ *
575
+ * Add save/restore GS operators
576
+ */
577
+ $this->_addProcSet('PDF');
578
 
579
+ $newContentsArray = new Zend_Pdf_Element_Array();
580
+ $newContentsArray->items[] = $this->_objFactory->newStreamObject(" q\n");
581
+ foreach ($this->_dictionary->Contents->items as $contentStream) {
582
+ $newContentsArray->items[] = $contentStream;
583
+ }
584
+ $newContentsArray->items[] = $this->_objFactory->newStreamObject(" Q\n");
585
 
586
+ $this->_dictionary->touch();
587
+ $this->_dictionary->Contents = $newContentsArray;
 
 
 
588
 
589
+ $this->_safeGS = true;
590
+ }
591
 
592
+ $this->_dictionary->Contents->items[] =
593
+ $this->_objFactory->newStreamObject($this->_contents);
594
 
595
+ $this->_contents = '';
596
  }
597
 
 
598
  /**
599
+ * Prepare page to be rendered into PDF.
600
+ *
601
+ * @todo Don't forget to close all current graphics operations (like path drawing)
602
  *
603
+ * @param Zend_Pdf_ElementFactory_Interface $objFactory
604
+ * @throws Zend_Pdf_Exception
605
  */
606
+ public function render(Zend_Pdf_ElementFactory_Interface $objFactory)
607
  {
608
+ $this->flush();
609
+
610
+ if ($objFactory === $this->_objFactory) {
611
+ // Page is already attached to the document.
612
+ return;
613
+ }
614
+
615
+ if ($this->_attached) {
616
+ #require_once 'Zend/Pdf/Exception.php';
617
+ throw new Zend_Pdf_Exception('Page is attached to other documen. Use clone $page to get it context free.');
618
+ } else {
619
+ $objFactory->attach($this->_objFactory);
620
+ }
621
  }
622
 
623
  /**
632
  */
633
  public function extractResources()
634
  {
635
+ return $this->_dictionary->Resources;
636
  }
637
 
638
  /**
645
  */
646
  public function extractFonts()
647
  {
648
+ if ($this->_dictionary->Resources->Font === null) {
649
  // Page doesn't have any font attached
650
  // Return empty array
651
  return array();
652
  }
653
 
654
+ $fontResources = $this->_dictionary->Resources->Font;
655
 
656
  $fontResourcesUnique = array();
657
  foreach ($fontResources->getKeys() as $fontResourceName) {
695
  */
696
  public function extractFont($fontName)
697
  {
698
+ if ($this->_dictionary->Resources->Font === null) {
699
  // Page doesn't have any font attached
700
  return null;
701
  }
702
 
703
+ $fontResources = $this->_dictionary->Resources->Font;
704
 
705
  $fontResourcesUnique = array();
706
 
743
  }
744
 
745
  /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
746
  *
747
+ * @param Zend_Pdf_Annotation $annotation
748
  * @return Zend_Pdf_Page
749
  */
750
+ public function attachAnnotation(Zend_Pdf_Annotation $annotation)
751
  {
752
+ $annotationDictionary = $annotation->getResource();
753
+ if (!$annotationDictionary instanceof Zend_Pdf_Element_Object &&
754
+ !$annotationDictionary instanceof Zend_Pdf_Element_Reference) {
755
+ $annotationDictionary = $this->_objFactory->newObject($annotationDictionary);
756
  }
 
 
 
 
 
757
 
758
+ if ($this->_dictionary->Annots === null) {
759
+ $this->_dictionary->touch();
760
+ $this->_dictionary->Annots = new Zend_Pdf_Element_Array();
761
+ } else {
762
+ $this->_dictionary->Annots->touch();
763
+ }
 
 
 
 
 
 
 
 
 
764
 
765
+ $this->_dictionary->Annots->items[] = $annotationDictionary;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
766
 
767
  $annotationDictionary->touch();
768
+ $annotationDictionary->P = $this->_dictionary;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769
 
770
  return $this;
771
  }
lib/Zend/Pdf/Parser.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Parser.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /** Internally used classes */
@@ -367,14 +367,22 @@ class Zend_Pdf_Parser
367
  throw new Zend_Pdf_Exception( "Can not open '$source' file for reading." );
368
  }
369
 
 
370
  $byteCount = filesize($source);
 
 
 
 
 
 
371
 
372
- $data = fread($pdfFile, $byteCount);
373
- $byteCount -= strlen($data);
374
- while ( $byteCount > 0 && ($nextBlock = fread($pdfFile, $byteCount)) != false ) {
375
  $data .= $nextBlock;
376
  $byteCount -= strlen($nextBlock);
377
  }
 
 
 
 
378
  fclose($pdfFile);
379
 
380
  $this->_stringParser = new Zend_Pdf_StringParser($data, $factory);
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Parser.php 23395 2010-11-19 15:30:47Z alexander $
20
  */
21
 
22
  /** Internally used classes */
367
  throw new Zend_Pdf_Exception( "Can not open '$source' file for reading." );
368
  }
369
 
370
+ $data = '';
371
  $byteCount = filesize($source);
372
+ while ($byteCount > 0 && !feof($pdfFile)) {
373
+ $nextBlock = fread($pdfFile, $byteCount);
374
+ if ($nextBlock === false) {
375
+ #require_once 'Zend/Pdf/Exception.php';
376
+ throw new Zend_Pdf_Exception( "Error occured while '$source' file reading." );
377
+ }
378
 
 
 
 
379
  $data .= $nextBlock;
380
  $byteCount -= strlen($nextBlock);
381
  }
382
+ if ($byteCount != 0) {
383
+ #require_once 'Zend/Pdf/Exception.php';
384
+ throw new Zend_Pdf_Exception( "Error occured while '$source' file reading." );
385
+ }
386
  fclose($pdfFile);
387
 
388
  $this->_stringParser = new Zend_Pdf_StringParser($data, $factory);
lib/Zend/Pdf/Resource.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Resource.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -66,16 +66,80 @@ abstract class Zend_Pdf_Resource
66
  */
67
  public function __construct($resource)
68
  {
 
 
 
 
 
 
 
69
  #require_once 'Zend/Pdf/ElementFactory.php';
70
 
71
- $this->_objectFactory = Zend_Pdf_ElementFactory::createFactory(1);
72
  if ($resource instanceof Zend_Pdf_Element) {
73
- $this->_resource = $this->_objectFactory->newObject($resource);
74
  } else {
75
- $this->_resource = $this->_objectFactory->newStreamObject($resource);
76
  }
77
  }
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  /**
80
  * Get resource.
81
  * Used to reference resource in an internal PDF data structures (resource dictionaries)
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Resource.php 22909 2010-08-27 19:57:48Z alexander $
20
  */
21
 
22
 
66
  */
67
  public function __construct($resource)
68
  {
69
+ if ($resource instanceof Zend_Pdf_Element_Object) {
70
+ $this->_objectFactory = $resource->getFactory();
71
+ $this->_resource = $resource;
72
+
73
+ return;
74
+ }
75
+
76
  #require_once 'Zend/Pdf/ElementFactory.php';
77
 
78
+ $this->_objectFactory = Zend_Pdf_ElementFactory::createFactory(1);
79
  if ($resource instanceof Zend_Pdf_Element) {
80
+ $this->_resource = $this->_objectFactory->newObject($resource);
81
  } else {
82
+ $this->_resource = $this->_objectFactory->newStreamObject($resource);
83
  }
84
  }
85
 
86
+ /**
87
+ * Clone page, extract it and dependent objects from the current document,
88
+ * so it can be used within other docs.
89
+ */
90
+ public function __clone()
91
+ {
92
+ /** @todo implementation*/
93
+
94
+ // $factory = Zend_Pdf_ElementFactory::createFactory(1);
95
+ // $processed = array();
96
+ //
97
+ // // Clone dictionary object.
98
+ // // Do it explicitly to prevent sharing resource attributes between different
99
+ // // results of clone operation (other resources are still shared)
100
+ // $dictionary = new Zend_Pdf_Element_Dictionary();
101
+ // foreach ($this->_pageDictionary->getKeys() as $key) {
102
+ // $dictionary->$key = $this->_pageDictionary->$key->makeClone($factory->getFactory(),
103
+ // $processed,
104
+ // Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES);
105
+ // }
106
+ //
107
+ // $this->_pageDictionary = $factory->newObject($dictionary);
108
+ // $this->_objectFactory = $factory;
109
+ // $this->_attached = false;
110
+ // $this->_style = null;
111
+ // $this->_font = null;
112
+ }
113
+
114
+ /**
115
+ * Clone resource, extract it and dependent objects from the current document,
116
+ * so it can be used within other docs.
117
+ *
118
+ * @internal
119
+ * @param Zend_Pdf_ElementFactory_Interface $factory
120
+ * @param array $processed
121
+ * @return Zend_Pdf_Page
122
+ */
123
+ public function cloneResource($factory, &$processed)
124
+ {
125
+ /** @todo implementation*/
126
+
127
+ // // Clone dictionary object.
128
+ // // Do it explicitly to prevent sharing page attributes between different
129
+ // // results of clonePage() operation (other resources are still shared)
130
+ // $dictionary = new Zend_Pdf_Element_Dictionary();
131
+ // foreach ($this->_pageDictionary->getKeys() as $key) {
132
+ // $dictionary->$key = $this->_pageDictionary->$key->makeClone($factory->getFactory(),
133
+ // $processed,
134
+ // Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES);
135
+ // }
136
+ //
137
+ // $clonedPage = new Zend_Pdf_Page($factory->newObject($dictionary), $factory);
138
+ // $clonedPage->_attached = false;
139
+ //
140
+ // return $clonedPage;
141
+ }
142
+
143
  /**
144
  * Get resource.
145
  * Used to reference resource in an internal PDF data structures (resource dictionaries)
lib/Zend/Pdf/Resource/ContentStream.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Pdf
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Image.php 20096 2010-01-06 02:05:09Z bkarwin $
20
+ */
21
+
22
+
23
+ /** Internally used classes */
24
+ #require_once 'Zend/Pdf/Element/Object.php';
25
+ #require_once 'Zend/Pdf/Element/Dictionary.php';
26
+ #require_once 'Zend/Pdf/Element/Name.php';
27
+ #require_once 'Zend/Pdf/Element/Numeric.php';
28
+
29
+
30
+ /** Zend_Pdf_Resource */
31
+ #require_once 'Zend/Pdf/Resource.php';
32
+
33
+
34
+ /**
35
+ * Content stream (drawing instructions container)
36
+ *
37
+ * @package Zend_Pdf
38
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
39
+ * @license http://framework.zend.com/license/new-bsd New BSD License
40
+ */
41
+ class Zend_Pdf_Resource_ContentStream extends Zend_Pdf_Resource
42
+ {
43
+ /**
44
+ * Buffered content
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_bufferedContent = '';
49
+
50
+ /**
51
+ * Object constructor.
52
+ *
53
+ * @param Zend_Pdf_Element_Object_Stream|string $contentStreamObject
54
+ * @throws Zend_Pdf_Exception
55
+ */
56
+ public function __construct($contentStreamObject = '')
57
+ {
58
+ if ($contentStreamObject !== null &&
59
+ !$contentStreamObject instanceof Zend_Pdf_Element_Object_Stream &&
60
+ !is_string($contentStreamObject)
61
+ ) {
62
+ #require_once 'Zend/Pdf/Exception.php';
63
+ throw new Zend_Pdf_Exception('Content stream parameter must be a string or stream object');
64
+ }
65
+
66
+ parent::__construct($contentStreamObject);
67
+ }
68
+
69
+ /**
70
+ * Appends instructions to the end of the content stream
71
+ *
72
+ * @param string $instructions
73
+ * @return Zend_Pdf_Resource_ContentStream
74
+ */
75
+ public function addInstructions($instructions)
76
+ {
77
+ $this->_bufferedContent .= $instructions;
78
+ return $this;
79
+ }
80
+
81
+ /**
82
+ * Get current stream content
83
+ *
84
+ * @return string
85
+ */
86
+ public function getInstructions()
87
+ {
88
+ $this->flush();
89
+ return $this->_resource->value;
90
+ }
91
+
92
+ /**
93
+ * Clear stream content.
94
+ *
95
+ * @return Zend_Pdf_Resource_ContentStream
96
+ */
97
+ public function clear()
98
+ {
99
+ $this->_resource->value = '';
100
+ $this->_bufferedContent = '';
101
+ return $this;
102
+ }
103
+
104
+ /**
105
+ * Flush buffered content
106
+ */
107
+ public function flush()
108
+ {
109
+ $this->_resource->value .= $this->_bufferedContent;
110
+ $this->_bufferedContent = '';
111
+
112
+ return $this;
113
+ }
114
+ }
lib/Zend/Pdf/Resource/Extractor.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Pdf
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id:
20
+ */
21
+
22
+ /** Internally used classes */
23
+ #require_once 'Zend/Pdf/Element.php';
24
+ #require_once 'Zend/Pdf/Element/Array.php';
25
+ #require_once 'Zend/Pdf/Element/String/Binary.php';
26
+ #require_once 'Zend/Pdf/Element/Boolean.php';
27
+ #require_once 'Zend/Pdf/Element/Dictionary.php';
28
+ #require_once 'Zend/Pdf/Element/Name.php';
29
+ #require_once 'Zend/Pdf/Element/Null.php';
30
+ #require_once 'Zend/Pdf/Element/Numeric.php';
31
+ #require_once 'Zend/Pdf/Element/String.php';
32
+
33
+
34
+ /**
35
+ * Resource extractor class is used to detach resources from original PDF document.
36
+ *
37
+ * It provides resources sharing, so different pages or other PDF resources can share
38
+ * its dependent resources (e.g. fonts or images) or other resources still use them without duplication.
39
+ * It also reduces output PDF size, required memory for PDF processing and
40
+ * processing time.
41
+ *
42
+ * The same extractor may be used for different source documents, several
43
+ * extractors may be used for constracting one target document, but extractor
44
+ * must not be shared between target documents.
45
+ *
46
+ * @package Zend_Pdf
47
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
48
+ * @license http://framework.zend.com/license/new-bsd New BSD License
49
+ */
50
+ class Zend_Pdf_Resource_Extractor
51
+ {
52
+ /**
53
+ * PDF objects factory.
54
+ *
55
+ * @var Zend_Pdf_ElementFactory_Interface
56
+ */
57
+ protected $_factory;
58
+
59
+ /**
60
+ * Reusable list of already processed objects
61
+ *
62
+ * @var array
63
+ */
64
+ protected $_processed;
65
+
66
+ /**
67
+ * Object constructor.
68
+ */
69
+ public function __construct()
70
+ {
71
+ $this->_factory = Zend_Pdf_ElementFactory::createFactory(1);
72
+ $this->_processed = array();
73
+ }
74
+
75
+ /**
76
+ * Clone page, extract it and dependent objects from the current document,
77
+ * so it can be used within other docs
78
+ *
79
+ * return Zend_Pdf_Page
80
+ */
81
+ public function clonePage(Zend_Pdf_Page $page)
82
+ {
83
+ return $page->clonePage($this->_factory, $this->_processed);
84
+ }
85
+ }
86
+
lib/Zend/Pdf/Resource/Font/Extracted.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Fonts
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Extracted.php 20893 2010-02-03 22:59:25Z yoshida@zend.co.jp $
21
  */
22
 
23
 
17
  * @subpackage Fonts
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Extracted.php 20866 2010-02-03 05:30:07Z yoshida@zend.co.jp $
21
  */
22
 
23
 
lib/Zend/Pdf/Resource/GraphicsState.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Pdf
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Image.php 20096 2010-01-06 02:05:09Z bkarwin $
20
+ */
21
+
22
+
23
+ /** Internally used classes */
24
+ #require_once 'Zend/Pdf/Element/Object.php';
25
+ #require_once 'Zend/Pdf/Element/Dictionary.php';
26
+ #require_once 'Zend/Pdf/Element/Name.php';
27
+ #require_once 'Zend/Pdf/Element/Numeric.php';
28
+
29
+
30
+ /** Zend_Pdf_Resource */
31
+ #require_once 'Zend/Pdf/Resource.php';
32
+
33
+
34
+ /**
35
+ * Graphics State.
36
+ *
37
+ * While some parameters in the graphics state can be set with individual operators,
38
+ * as shown in Table 4.7, others cannot. The latter can only be set with the generic
39
+ * graphics state operator gs (PDF 1.2).
40
+ *
41
+ * @package Zend_Pdf
42
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
43
+ * @license http://framework.zend.com/license/new-bsd New BSD License
44
+ */
45
+ class Zend_Pdf_Resource_GraphicsState extends Zend_Pdf_Resource
46
+ {
47
+ /**
48
+ * Object constructor.
49
+ *
50
+ * @param Zend_Pdf_Element_Object $extGStateObject
51
+ * @throws Zend_Pdf_Exception
52
+ */
53
+ public function __construct(Zend_Pdf_Element_Object $extGStateObject = null)
54
+ {
55
+ if ($extGStateObject == null) {
56
+ // Create new Graphics State object
57
+ #require_once 'Zend/Pdf/ElementFactory.php';
58
+ $factory = Zend_Pdf_ElementFactory::createFactory(1);
59
+
60
+ $gsDictionary = new Zend_Pdf_Element_Dictionary();
61
+ $gsDictionary->Type = new Zend_Pdf_Element_Name('ExtGState');
62
+
63
+ $extGStateObject = $factory->newObject($gsDictionary);
64
+ }
65
+
66
+ if ($extGStateObject->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
67
+ #require_once 'Zend/Pdf/Exception.php';
68
+ throw new Zend_Pdf_Exception('Graphics state PDF object must be a dictionary');
69
+ }
70
+
71
+ parent::__construct($gsDictionary);
72
+ }
73
+
74
+ /**
75
+ * Set the transparancy
76
+ *
77
+ * $alpha == 0 - transparent
78
+ * $alpha == 1 - opaque
79
+ *
80
+ * Transparency modes, supported by PDF:
81
+ * Normal (default), Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight,
82
+ * SoftLight, Difference, Exclusion
83
+ *
84
+ * @param float $alpha
85
+ * @param string $mode
86
+ * @throws Zend_Pdf_Exception
87
+ * @return Zend_Pdf_Canvas_Interface
88
+ */
89
+ public function setAlpha($alpha, $mode = 'Normal')
90
+ {
91
+ if (!in_array($mode, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge',
92
+ 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion'))) {
93
+ #require_once 'Zend/Pdf/Exception.php';
94
+ throw new Zend_Pdf_Exception('Unsupported transparency mode.');
95
+ }
96
+ if (!is_numeric($alpha) || $alpha < 0 || $alpha > 1) {
97
+ #require_once 'Zend/Pdf/Exception.php';
98
+ throw new Zend_Pdf_Exception('Alpha value must be numeric between 0 (transparent) and 1 (opaque).');
99
+ }
100
+
101
+ $this->_resource->BM = new Zend_Pdf_Element_Name($mode);
102
+ $this->_resource->CA = new Zend_Pdf_Element_Numeric($alpha);
103
+ $this->_resource->ca = new Zend_Pdf_Element_Numeric($alpha);
104
+ }
105
+
106
+
107
+ /** @todo add other Graphics State features support */
108
+ }
109
+
lib/Zend/Pdf/Resource/Image.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Image.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -33,10 +33,6 @@
33
  /**
34
  * Image abstraction.
35
  *
36
- * Class is named not in accordance to the name convention.
37
- * It's "end-user" class, but its ancestor is not.
38
- * Thus part of the common class name is removed.
39
- *
40
  * @package Zend_Pdf
41
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
42
  * @license http://framework.zend.com/license/new-bsd New BSD License
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Image.php 22908 2010-08-25 20:52:47Z alexander $
20
  */
21
 
22
 
33
  /**
34
  * Image abstraction.
35
  *
 
 
 
 
36
  * @package Zend_Pdf
37
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
38
  * @license http://framework.zend.com/license/new-bsd New BSD License
lib/Zend/Pdf/Resource/Image/Jpeg.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Jpeg.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -102,19 +102,30 @@ class Zend_Pdf_Resource_Image_Jpeg extends Zend_Pdf_Resource_Image
102
  }
103
  $byteCount = filesize($imageFileName);
104
  $this->_resource->value = '';
105
- while ( $byteCount > 0 && ($nextBlock = fread($imageFile, $byteCount)) != false ) {
 
 
 
 
 
 
 
106
  $this->_resource->value .= $nextBlock;
107
  $byteCount -= strlen($nextBlock);
108
  }
 
 
 
 
109
  fclose($imageFile);
110
  $this->_resource->skipFilters();
111
 
112
- $this->_width = $imageInfo[0];
113
- $this->_height = $imageInfo[1];
114
- $this->_imageProperties = array();
115
- $this->_imageProperties['bitDepth'] = $imageInfo['bits'];
116
- $this->_imageProperties['jpegImageType'] = $imageInfo[2];
117
- $this->_imageProperties['jpegColorType'] = $imageInfo['channels'];
118
  }
119
 
120
  /**
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Jpeg.php 23395 2010-11-19 15:30:47Z alexander $
20
  */
21
 
22
 
102
  }
103
  $byteCount = filesize($imageFileName);
104
  $this->_resource->value = '';
105
+
106
+ while ($byteCount > 0 && !feof($imageFile)) {
107
+ $nextBlock = fread($imageFile, $byteCount);
108
+ if ($nextBlock === false) {
109
+ #require_once 'Zend/Pdf/Exception.php';
110
+ throw new Zend_Pdf_Exception( "Error occured while '$imageFileName' file reading." );
111
+ }
112
+
113
  $this->_resource->value .= $nextBlock;
114
  $byteCount -= strlen($nextBlock);
115
  }
116
+ if ($byteCount != 0) {
117
+ #require_once 'Zend/Pdf/Exception.php';
118
+ throw new Zend_Pdf_Exception( "Error occured while '$imageFileName' file reading." );
119
+ }
120
  fclose($imageFile);
121
  $this->_resource->skipFilters();
122
 
123
+ $this->_width = $imageInfo[0];
124
+ $this->_height = $imageInfo[1];
125
+ $this->_imageProperties = array();
126
+ $this->_imageProperties['bitDepth'] = $imageInfo['bits'];
127
+ $this->_imageProperties['jpegImageType'] = $imageInfo[2];
128
+ $this->_imageProperties['jpegColorType'] = $imageInfo['channels'];
129
  }
130
 
131
  /**
lib/Zend/Pdf/Resource/Image/Png.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Png.php 22655 2010-07-22 18:47:20Z mabe $
20
  */
21
 
22
 
@@ -123,10 +123,16 @@ class Zend_Pdf_Resource_Image_Png extends Zend_Pdf_Resource_Image
123
  * The following loop processes PNG chunks. 4 Byte Longs are packed first give the chunk length
124
  * followed by the chunk signature, a four byte code. IDAT and IEND are manditory in any PNG.
125
  */
126
- while(($chunkLengthBytes = fread($imageFile, 4)) !== false) {
127
- $chunkLengthtmp = unpack('Ni', $chunkLengthBytes);
128
- $chunkLength = $chunkLengthtmp['i'];
129
- $chunkType = fread($imageFile, 4);
 
 
 
 
 
 
130
  switch($chunkType) {
131
  case 'IDAT': //Image Data
132
  /*
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Png.php 23395 2010-11-19 15:30:47Z alexander $
20
  */
21
 
22
 
123
  * The following loop processes PNG chunks. 4 Byte Longs are packed first give the chunk length
124
  * followed by the chunk signature, a four byte code. IDAT and IEND are manditory in any PNG.
125
  */
126
+ while (!feof($imageFile)) {
127
+ $chunkLengthBytes = fread($imageFile, 4);
128
+ if ($chunkLengthBytes === false) {
129
+ #require_once 'Zend/Pdf/Exception.php';
130
+ throw new Zend_Pdf_Exception('Error ocuured while image file reading.');
131
+ }
132
+
133
+ $chunkLengthtmp = unpack('Ni', $chunkLengthBytes);
134
+ $chunkLength = $chunkLengthtmp['i'];
135
+ $chunkType = fread($imageFile, 4);
136
  switch($chunkType) {
137
  case 'IDAT': //Image Data
138
  /*
lib/Zend/Pdf/Resource/Unified.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Pdf
17
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
+ * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Image.php 20096 2010-01-06 02:05:09Z bkarwin $
20
+ */
21
+
22
+
23
+ /** Zend_Pdf_Resource */
24
+ #require_once 'Zend/Pdf/Resource.php';
25
+
26
+ /**
27
+ * Unified resource.
28
+ *
29
+ * Class is used to represent any resource when resource type not actually important.
30
+ *
31
+ * @package Zend_Pdf
32
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33
+ * @license http://framework.zend.com/license/new-bsd New BSD License
34
+ */
35
+ class Zend_Pdf_Resource_Unified extends Zend_Pdf_Resource
36
+ {
37
+ }
38
+
lib/Zend/Pdf/StringParser.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: StringParser.php 22312 2010-05-27 13:11:23Z padraic $
20
  */
21
 
22
 
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: StringParser.php 22311 2010-05-27 12:57:37Z padraic $
20
  */
21
 
22
 
lib/Zend/Pdf/Style.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -292,4 +292,3 @@ class Zend_Pdf_Style
292
  }
293
 
294
  }
295
-
16
  * @package Zend_Pdf
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Style.php 22908 2010-08-25 20:52:47Z alexander $
20
  */
21
 
22
 
292
  }
293
 
294
  }
 
lib/Zend/Queue/Adapter/Db/queue_sqlite.sql CHANGED
@@ -1,4 +1,5 @@
1
  /*
 
2
  Sample grant for SQLite
3
 
4
  CREATE ROLE queue LOGIN
1
  /*
2
+ * @version $Id: queue_sqlite.sql 20874 2010-02-03 13:14:59Z matthew $
3
  Sample grant for SQLite
4
 
5
  CREATE ROLE queue LOGIN
lib/Zend/Queue/Adapter/Db/sqlsrv.sql ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ CREATE TABLE [dbo].[queue](
3
+ [queue_id] [int] IDENTITY(1,1) NOT NULL,
4
+ [queue_name] [varchar](100) NOT NULL,
5
+ [timeout] [int] NOT NULL,
6
+ CONSTRAINT [PK_queue] PRIMARY KEY CLUSTERED
7
+ (
8
+ [queue_id] ASC
9
+ )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
10
+ ) ON [PRIMARY]
11
+
12
+ GO
13
+
14
+ ALTER TABLE [dbo].[queue] ADD DEFAULT ((30)) FOR [timeout]
15
+ GO
16
+
17
+
18
+ CREATE TABLE [dbo].[message](
19
+ [message_id] [bigint] IDENTITY(1,1) NOT NULL,
20
+ [queue_id] [int] NOT NULL,
21
+ [handle] [char](32) NULL,
22
+ [body] [varchar](max) NOT NULL,
23
+ [md5] [char](32) NOT NULL,
24
+ [timeout] [decimal](14, 4) NULL,
25
+ [created] [int] NOT NULL,
26
+ CONSTRAINT [PK_message] PRIMARY KEY CLUSTERED
27
+ (
28
+ [message_id] ASC
29
+ )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
30
+ ) ON [PRIMARY]
31
+
32
+ GO
33
+
34
+ ALTER TABLE [dbo].[message] WITH CHECK ADD CONSTRAINT [fk_message_queue_id] FOREIGN KEY([queue_id])
35
+ REFERENCES [dbo].[queue] ([queue_id])
36
+ GO
37
+
38
+ ALTER TABLE [dbo].[message] CHECK CONSTRAINT [fk_message_queue_id]
39
+ GO
40
+
41
+
42
+
43
+
44
+
lib/Zend/Queue/Stomp/Frame.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Stomp
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Frame.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -195,7 +195,7 @@ class Zend_Queue_Stomp_Frame
195
  */
196
  public function getBody()
197
  {
198
- return is_null($this->_body)
199
  ? false
200
  : $this->_body;
201
  }
@@ -211,7 +211,7 @@ class Zend_Queue_Stomp_Frame
211
  */
212
  public function setBody($body)
213
  {
214
- if (!is_string($body) && !is_null($body)) {
215
  #require_once 'Zend/Queue/Exception.php';
216
  throw new Zend_Queue_Exception('$body is not a string or null');
217
  }
@@ -229,7 +229,7 @@ class Zend_Queue_Stomp_Frame
229
  */
230
  public function getCommand()
231
  {
232
- return is_null($this->_command)
233
  ? false
234
  : $this->_command;
235
  }
@@ -243,7 +243,7 @@ class Zend_Queue_Stomp_Frame
243
  */
244
  public function setCommand($command)
245
  {
246
- if (!is_string($command) && !is_null($command)) {
247
  #require_once 'Zend/Queue/Exception.php';
248
  throw new Zend_Queue_Exception('$command is not a string or null');
249
  }
17
  * @subpackage Stomp
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Frame.php 22662 2010-07-24 17:37:36Z mabe $
21
  */
22
 
23
  /**
195
  */
196
  public function getBody()
197
  {
198
+ return $this->_body === null
199
  ? false
200
  : $this->_body;
201
  }
211
  */
212
  public function setBody($body)
213
  {
214
+ if (!is_string($body) && $body !== null) {
215
  #require_once 'Zend/Queue/Exception.php';
216
  throw new Zend_Queue_Exception('$body is not a string or null');
217
  }
229
  */
230
  public function getCommand()
231
  {
232
+ return $this->_command === null
233
  ? false
234
  : $this->_command;
235
  }
243
  */
244
  public function setCommand($command)
245
  {
246
+ if (!is_string($command) && $command !== null) {
247
  #require_once 'Zend/Queue/Exception.php';
248
  throw new Zend_Queue_Exception('$command is not a string or null');
249
  }
lib/Zend/Reflection/File.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Reflection
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: File.php 20903 2010-02-04 16:16:47Z matthew $
20
  */
21
 
22
  /**
16
  * @package Zend_Reflection
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: File.php 20904 2010-02-04 16:18:18Z matthew $
20
  */
21
 
22
  /**
lib/Zend/Rest/Route.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Rest
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Route.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
  /**
@@ -274,15 +274,27 @@ class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
274
  $controller = $params[$this->_controllerKey];
275
  unset($params[$this->_controllerKey]);
276
 
 
 
 
 
277
  unset($params[$this->_actionKey]);
278
 
279
  if (isset($params['index']) && $params['index']) {
280
  unset($params['index']);
281
  $url .= '/index';
 
 
 
 
282
  foreach ($params as $key => $value) {
283
  if ($encode) $value = urlencode($value);
284
  $url .= '/' . $key . '/' . $value;
285
  }
 
 
 
 
286
  } elseif (isset($params['id'])) {
287
  $url .= '/' . $params['id'];
288
  }
16
  * @package Zend_Rest
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Route.php 23421 2010-11-21 10:03:53Z wilmoore $
20
  */
21
 
22
  /**
274
  $controller = $params[$this->_controllerKey];
275
  unset($params[$this->_controllerKey]);
276
 
277
+ // set $action if value given is 'new' or 'edit'
278
+ if (in_array($params[$this->_actionKey], array('new', 'edit'))) {
279
+ $action = $params[$this->_actionKey];
280
+ }
281
  unset($params[$this->_actionKey]);
282
 
283
  if (isset($params['index']) && $params['index']) {
284
  unset($params['index']);
285
  $url .= '/index';
286
+ if (isset($params['id'])) {
287
+ $url .= '/'.$params['id'];
288
+ unset($params['id']);
289
+ }
290
  foreach ($params as $key => $value) {
291
  if ($encode) $value = urlencode($value);
292
  $url .= '/' . $key . '/' . $value;
293
  }
294
+ } elseif (! empty($action) && isset($params['id'])) {
295
+ $url .= sprintf('/%s/%s', $params['id'], $action);
296
+ } elseif (! empty($action)) {
297
+ $url .= sprintf('/%s', $action);
298
  } elseif (isset($params['id'])) {
299
  $url .= '/' . $params['id'];
300
  }
lib/Zend/Search/Lucene.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Search_Lucene
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Lucene.php 21640 2010-03-24 18:28:32Z alexander $
20
  */
21
 
22
 
@@ -707,6 +707,8 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
707
  */
708
  public function isDeleted($id)
709
  {
 
 
710
  if ($id >= $this->_docCount) {
711
  #require_once 'Zend/Search/Lucene/Exception.php';
712
  throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
@@ -1521,7 +1523,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
1521
  }
1522
 
1523
  /**
1524
- * Skip terms stream up to specified term preffix.
1525
  *
1526
  * Prefix contains fully specified field info and portion of searched term
1527
  *
16
  * @package Zend_Search_Lucene
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Lucene.php 22987 2010-09-21 10:39:53Z alexander $
20
  */
21
 
22
 
707
  */
708
  public function isDeleted($id)
709
  {
710
+ $this->commit();
711
+
712
  if ($id >= $this->_docCount) {
713
  #require_once 'Zend/Search/Lucene/Exception.php';
714
  throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
1523
  }
1524
 
1525
  /**
1526
+ * Skip terms stream up to the specified term preffix.
1527
  *
1528
  * Prefix contains fully specified field info and portion of searched term
1529
  *
lib/Zend/Search/Lucene/Document/Html.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Document
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Html.php 21946 2010-04-19 08:21:02Z alexander $
21
  */
22
 
23
 
@@ -102,7 +102,7 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
102
  // Document encoding is not recognized
103
 
104
  /** @todo improve HTML vs HTML fragment recognition */
105
- if (preg_match('/<html>/i', $htmlData, $matches, PREG_OFFSET_CAPTURE)) {
106
  // It's an HTML document
107
  // Add additional HEAD section and recognize document
108
  $htmlTagOffset = $matches[0][1] + strlen($matches[0][0]);
17
  * @subpackage Document
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Html.php 23392 2010-11-19 09:53:16Z ramon $
21
  */
22
 
23
 
102
  // Document encoding is not recognized
103
 
104
  /** @todo improve HTML vs HTML fragment recognition */
105
+ if (preg_match('/<html[^>]*>/i', $htmlData, $matches, PREG_OFFSET_CAPTURE)) {
106
  // It's an HTML document
107
  // Add additional HEAD section and recognize document
108
  $htmlTagOffset = $matches[0][1] + strlen($matches[0][0]);
lib/Zend/Search/Lucene/Index/SegmentInfo.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Index
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: SegmentInfo.php 22724 2010-07-29 22:07:22Z alexander $
21
  */
22
 
23
  /** Zend_Search_Lucene_Index_TermsStream_Interface */
@@ -1861,7 +1861,7 @@ class Zend_Search_Lucene_Index_SegmentInfo implements Zend_Search_Lucene_Index_T
1861
 
1862
 
1863
  /**
1864
- * Skip terms stream up to specified term preffix.
1865
  *
1866
  * Prefix contains fully specified field info and portion of searched term
1867
  *
17
  * @subpackage Index
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: SegmentInfo.php 22987 2010-09-21 10:39:53Z alexander $
21
  */
22
 
23
  /** Zend_Search_Lucene_Index_TermsStream_Interface */
1861
 
1862
 
1863
  /**
1864
+ * Skip terms stream up to the specified term preffix.
1865
  *
1866
  * Prefix contains fully specified field info and portion of searched term
1867
  *
lib/Zend/Search/Lucene/Index/TermsStream/Interface.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Index
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -35,7 +35,7 @@ interface Zend_Search_Lucene_Index_TermsStream_Interface
35
  public function resetTermsStream();
36
 
37
  /**
38
- * Skip terms stream up to specified term preffix.
39
  *
40
  * Prefix contains fully specified field info and portion of searched term
41
  *
17
  * @subpackage Index
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Interface.php 22987 2010-09-21 10:39:53Z alexander $
21
  */
22
 
23
  /**
35
  public function resetTermsStream();
36
 
37
  /**
38
+ * Skip terms stream up to the specified term preffix.
39
  *
40
  * Prefix contains fully specified field info and portion of searched term
41
  *
lib/Zend/Search/Lucene/MultiSearcher.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Search_Lucene
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: MultiSearcher.php 20096 2010-01-06 02:05:09Z bkarwin $
20
  */
21
 
22
 
@@ -144,7 +144,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
144
  $count = 0;
145
 
146
  foreach ($this->_indices as $index) {
147
- $count += $this->_indices->count();
148
  }
149
 
150
  return $count;
@@ -172,7 +172,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
172
  $docs = 0;
173
 
174
  foreach ($this->_indices as $index) {
175
- $docs += $this->_indices->numDocs();
176
  }
177
 
178
  return $docs;
16
  * @package Zend_Search_Lucene
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: MultiSearcher.php 22967 2010-09-18 18:53:58Z ramon $
20
  */
21
 
22
 
144
  $count = 0;
145
 
146
  foreach ($this->_indices as $index) {
147
+ $count += $index->count();
148
  }
149
 
150
  return $count;
172
  $docs = 0;
173
 
174
  foreach ($this->_indices as $index) {
175
+ $docs += $index->numDocs();
176
  }
177
 
178
  return $docs;
lib/Zend/Search/Lucene/Search/Query/Range.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Search
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Range.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
 
@@ -186,7 +186,7 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
186
 
187
  while ($index->currentTerm() !== null &&
188
  $index->currentTerm()->field == $field &&
189
- $index->currentTerm()->text < $upperTerm->text) {
190
  $this->_matches[] = $index->currentTerm();
191
 
192
  if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
17
  * @subpackage Search
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Range.php 22987 2010-09-21 10:39:53Z alexander $
21
  */
22
 
23
 
186
 
187
  while ($index->currentTerm() !== null &&
188
  $index->currentTerm()->field == $field &&
189
+ strcmp($index->currentTerm()->text, $upperTerm->text) < 0) {
190
  $this->_matches[] = $index->currentTerm();
191
 
192
  if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
lib/Zend/Search/Lucene/Search/QueryParser.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Search
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: QueryParser.php 21638 2010-03-24 17:56:46Z alexander $
21
  */
22
 
23
 
17
  * @subpackage Search
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: QueryParser.php 21637 2010-03-24 17:52:04Z alexander $
21
  */
22
 
23
 
lib/Zend/Search/Lucene/Storage/File/Filesystem.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Storage
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Filesystem.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /** Zend_Search_Lucene_Storage_File */
@@ -159,10 +159,21 @@ class Zend_Search_Lucene_Storage_File_Filesystem extends Zend_Search_Lucene_Stor
159
  }
160
 
161
  $data = '';
162
- while ( $length > 0 && ($nextBlock = fread($this->_fileHandle, $length)) != false ) {
 
 
 
 
 
 
163
  $data .= $nextBlock;
164
  $length -= strlen($nextBlock);
165
  }
 
 
 
 
 
166
  return $data;
167
  }
168
 
17
  * @subpackage Storage
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Filesystem.php 23395 2010-11-19 15:30:47Z alexander $
21
  */
22
 
23
  /** Zend_Search_Lucene_Storage_File */
159
  }
160
 
161
  $data = '';
162
+ while ($length > 0 && !feof($this->_fileHandle)) {
163
+ $nextBlock = fread($this->_fileHandle, $length);
164
+ if ($nextBlock === false) {
165
+ #require_once 'Zend/Search/Lucene/Exception.php';
166
+ throw new Zend_Search_Lucene_Exception( "Error occured while file reading." );
167
+ }
168
+
169
  $data .= $nextBlock;
170
  $length -= strlen($nextBlock);
171
  }
172
+ if ($length != 0) {
173
+ #require_once 'Zend/Search/Lucene/Exception.php';
174
+ throw new Zend_Search_Lucene_Exception( "Error occured while file reading." );
175
+ }
176
+
177
  return $data;
178
  }
179
 
lib/Zend/Search/Lucene/TermStreamsPriorityQueue.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Index
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: TermStreamsPriorityQueue.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /** Zend_Search_Lucene_Index_TermsStream_Interface */
@@ -90,7 +90,7 @@ class Zend_Search_Lucene_TermStreamsPriorityQueue implements Zend_Search_Lucene_
90
  }
91
 
92
  /**
93
- * Skip terms stream up to specified term preffix.
94
  *
95
  * Prefix contains fully specified field info and portion of searched term
96
  *
@@ -98,13 +98,9 @@ class Zend_Search_Lucene_TermStreamsPriorityQueue implements Zend_Search_Lucene_
98
  */
99
  public function skipTo(Zend_Search_Lucene_Index_Term $prefix)
100
  {
101
- $termStreams = array();
102
-
103
- while (($termStream = $this->_termsStreamQueue->pop()) !== null) {
104
- $termStreams[] = $termStream;
105
- }
106
 
107
- foreach ($termStreams as $termStream) {
108
  $termStream->skipTo($prefix);
109
 
110
  if ($termStream->currentTerm() !== null) {
@@ -112,7 +108,7 @@ class Zend_Search_Lucene_TermStreamsPriorityQueue implements Zend_Search_Lucene_
112
  }
113
  }
114
 
115
- $this->nextTerm();
116
  }
117
 
118
  /**
17
  * @subpackage Index
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: TermStreamsPriorityQueue.php 22987 2010-09-21 10:39:53Z alexander $
21
  */
22
 
23
  /** Zend_Search_Lucene_Index_TermsStream_Interface */
90
  }
91
 
92
  /**
93
+ * Skip terms stream up to the specified term preffix.
94
  *
95
  * Prefix contains fully specified field info and portion of searched term
96
  *
98
  */
99
  public function skipTo(Zend_Search_Lucene_Index_Term $prefix)
100
  {
101
+ $this->_termsStreamQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue();
 
 
 
 
102
 
103
+ foreach ($this->_termStreams as $termStream) {
104
  $termStream->skipTo($prefix);
105
 
106
  if ($termStream->currentTerm() !== null) {
108
  }
109
  }
110
 
111
+ return $this->nextTerm();
112
  }
113
 
114
  /**
lib/Zend/Serializer.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Serializer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Serializer.php 20575 2010-01-24 17:48:27Z mabe $
20
  */
21
 
22
  /** @see Zend_Loader_PluginLoader */
16
  * @package Zend_Serializer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Serializer.php 20574 2010-01-24 17:39:14Z mabe $
20
  */
21
 
22
  /** @see Zend_Loader_PluginLoader */
lib/Zend/Serializer/Adapter/AdapterAbstract.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: AdapterAbstract.php 20575 2010-01-24 17:48:27Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterInterface */
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: AdapterAbstract.php 20574 2010-01-24 17:39:14Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterInterface */
lib/Zend/Serializer/Adapter/AdapterInterface.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: AdapterInterface.php 20575 2010-01-24 17:48:27Z mabe $
21
  */
22
 
23
  /**
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: AdapterInterface.php 20574 2010-01-24 17:39:14Z mabe $
21
  */
22
 
23
  /**
lib/Zend/Serializer/Adapter/Amf0.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Amf0.php 20575 2010-01-24 17:48:27Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Amf0.php 20574 2010-01-24 17:39:14Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
lib/Zend/Serializer/Adapter/Amf3.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Amf3.php 20575 2010-01-24 17:48:27Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Amf3.php 20574 2010-01-24 17:39:14Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
lib/Zend/Serializer/Adapter/Igbinary.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Igbinary.php 20575 2010-01-24 17:48:27Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Igbinary.php 20574 2010-01-24 17:39:14Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
lib/Zend/Serializer/Adapter/Json.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Json.php 20575 2010-01-24 17:48:27Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Json.php 20574 2010-01-24 17:39:14Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
lib/Zend/Serializer/Adapter/PhpCode.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: PhpCode.php 20575 2010-01-24 17:48:27Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: PhpCode.php 20574 2010-01-24 17:39:14Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
lib/Zend/Serializer/Adapter/PhpSerialize.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: PhpSerialize.php 20575 2010-01-24 17:48:27Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: PhpSerialize.php 20574 2010-01-24 17:39:14Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
lib/Zend/Serializer/Adapter/PythonPickle.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: PythonPickle.php 20575 2010-01-24 17:48:27Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
@@ -1366,7 +1366,7 @@ class Zend_Serializer_Adapter_PythonPickle extends Zend_Serializer_Adapter_Adapt
1366
  {
1367
  $proto = ord($this->_read(1));
1368
  if ($proto < 2 || $proto > 3) {
1369
- #require_once 'Zend/Serializer/Excception.php';
1370
  throw new Zend_Serializer_Exception('Invalid protocol version detected');
1371
  }
1372
  $this->_protocol = $proto;
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: PythonPickle.php 21187 2010-02-24 01:22:01Z stas $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
1366
  {
1367
  $proto = ord($this->_read(1));
1368
  if ($proto < 2 || $proto > 3) {
1369
+ #require_once 'Zend/Serializer/Exception.php';
1370
  throw new Zend_Serializer_Exception('Invalid protocol version detected');
1371
  }
1372
  $this->_protocol = $proto;
lib/Zend/Serializer/Adapter/Wddx.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Wddx.php 20575 2010-01-24 17:48:27Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
17
  * @subpackage Adapter
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Wddx.php 20574 2010-01-24 17:39:14Z mabe $
21
  */
22
 
23
  /** @see Zend_Serializer_Adapter_AdapterAbstract */
lib/Zend/Serializer/Exception.php CHANGED
@@ -16,7 +16,7 @@
16
  * @package Zend_Serializer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
- * @version $Id: Exception.php 20575 2010-01-24 17:48:27Z mabe $
20
  */
21
 
22
  /** @see Zend_Exception */
16
  * @package Zend_Serializer
17
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18
  * @license http://framework.zend.com/license/new-bsd New BSD License
19
+ * @version $Id: Exception.php 20574 2010-01-24 17:39:14Z mabe $
20
  */
21
 
22
  /** @see Zend_Exception */
lib/Zend/Server/Reflection/Function/Abstract.php CHANGED
@@ -48,7 +48,7 @@
48
  * @subpackage Reflection
49
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
50
  * @license http://framework.zend.com/license/new-bsd New BSD License
51
- * @version $Id: Abstract.php 20637 2010-01-25 22:33:22Z matthew $
52
  */
53
  abstract class Zend_Server_Reflection_Function_Abstract
54
  {
@@ -293,7 +293,7 @@ abstract class Zend_Server_Reflection_Function_Abstract
293
  // Get param types and description
294
  if (preg_match_all('/@param\s+([^\s]+)/m', $docBlock, $matches)) {
295
  $paramTypesTmp = $matches[1];
296
- if (preg_match_all('/@param\s+\S+\s+(\$\S+)\s+(.*?)(@|\*\/)/s', $docBlock, $matches))
297
  {
298
  $paramDesc = $matches[2];
299
  foreach ($paramDesc as $key => $value) {
@@ -306,6 +306,16 @@ abstract class Zend_Server_Reflection_Function_Abstract
306
  } else {
307
  $helpText = $function->getName();
308
  $return = 'void';
 
 
 
 
 
 
 
 
 
 
309
  }
310
 
311
  // Set method description
@@ -339,7 +349,9 @@ abstract class Zend_Server_Reflection_Function_Abstract
339
  #require_once 'Zend/Server/Reflection/Exception.php';
340
  throw new Zend_Server_Reflection_Exception(
341
  'Variable number of arguments is not supported for services (except optional parameters). '
342
- . 'Number of function arguments must correspond to actual number of arguments described in a docblock.');
 
 
343
  }
344
 
345
  $paramTypes = array();
48
  * @subpackage Reflection
49
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
50
  * @license http://framework.zend.com/license/new-bsd New BSD License
51
+ * @version $Id: Abstract.php 23320 2010-11-12 21:57:29Z alexander $
52
  */
53
  abstract class Zend_Server_Reflection_Function_Abstract
54
  {
293
  // Get param types and description
294
  if (preg_match_all('/@param\s+([^\s]+)/m', $docBlock, $matches)) {
295
  $paramTypesTmp = $matches[1];
296
+ if (preg_match_all('/@param\s+\S+\s+(\$\S+)\s+(.*?)(?=@|\*\/)/s', $docBlock, $matches))
297
  {
298
  $paramDesc = $matches[2];
299
  foreach ($paramDesc as $key => $value) {
306
  } else {
307
  $helpText = $function->getName();
308
  $return = 'void';
309
+
310
+ // Try and auto-determine type, based on reflection
311
+ $paramTypesTmp = array();
312
+ foreach ($parameters as $i => $param) {
313
+ $paramType = 'mixed';
314
+ if ($param->isArray()) {
315
+ $paramType = 'array';
316
+ }
317
+ $paramTypesTmp[$i] = $paramType;
318
+ }
319
  }
320
 
321
  // Set method description
349
  #require_once 'Zend/Server/Reflection/Exception.php';
350
  throw new Zend_Server_Reflection_Exception(
351
  'Variable number of arguments is not supported for services (except optional parameters). '
352
+ . 'Number of function arguments in ' . $function->getDeclaringClass()->getName() . '::'
353
+ . $function->getName() . '() must correspond to actual number of arguments described in the '
354
+ . 'docblock.');
355
  }
356
 
357
  $paramTypes = array();
lib/Zend/Service/Amazon/Authentication.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Service_Amazon
17
+ * @subpackage Authentication
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @category Zend
24
+ * @package Zend_Service_Amazon
25
+ * @subpackage Authentication
26
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
27
+ * @license http://framework.zend.com/license/new-bsd New BSD License
28
+ */
29
+ abstract class Zend_Service_Amazon_Authentication
30
+ {
31
+ protected $_accessKey;
32
+ protected $_secretKey;
33
+ protected $_apiVersion;
34
+
35
+ /**
36
+ * Constructor
37
+ *
38
+ * @param string $accessKey
39
+ * @param string $secretKey
40
+ * @param string $apiVersion
41
+ * @return void
42
+ */
43
+ public function __construct($accessKey, $secretKey, $apiVersion)
44
+ {
45
+ $this->setAccessKey($accessKey);
46
+ $this->setSecretKey($secretKey);
47
+ $this->setApiVersion($apiVersion);
48
+ }
49
+
50
+ /**
51
+ * Set access key
52
+ *
53
+ * @param string $accessKey
54
+ * @return void
55
+ */
56
+ public function setAccessKey($accessKey)
57
+ {
58
+ $this->_accessKey = $accessKey;
59
+ }
60
+
61
+ /**
62
+ * Set secret key
63
+ *
64
+ * @param string $secretKey
65
+ * @return void
66
+ */
67
+ public function setSecretKey($secretKey)
68
+ {
69
+ $this->_secretKey = $secretKey;
70
+ }
71
+
72
+ /**
73
+ * Set API version
74
+ *
75
+ * @param string $apiVersion
76
+ * @return void
77
+ */
78
+ public function setApiVersion($apiVersion)
79
+ {
80
+ $this->_apiVersion = $apiVersion;
81
+ }
82
+ }
lib/Zend/Service/Amazon/Authentication/Exception.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Service_Amazon
17
+ * @subpackage Authentication
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Service_Amazon_Exception
24
+ */
25
+ #require_once 'Zend/Service/Amazon/Exception.php';
26
+
27
+ /**
28
+ * @category Zend
29
+ * @package Zend_Service_Amazon
30
+ * @subpackage Authentication
31
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
+ * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ */
34
+ class Zend_Service_Amazon_Authentication_Exception extends Zend_Service_Amazon_Exception
35
+ {
36
+
37
+ }
lib/Zend/Service/Amazon/Authentication/S3.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Service_Amazon
17
+ * @subpackage Authentication
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+
23
+ /**
24
+ * @see Zend_Service_Amazon_Authentication
25
+ */
26
+ #require_once 'Zend/Service/Amazon/Authentication.php';
27
+
28
+ /**
29
+ * @see Zend_Crypt_Hmac
30
+ */
31
+ #require_once 'Zend/Crypt/Hmac.php';
32
+
33
+ /**
34
+ * @category Zend
35
+ * @package Zend_Service_Amazon
36
+ * @subpackage Authentication
37
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
38
+ * @license http://framework.zend.com/license/new-bsd New BSD License
39
+ */
40
+ class Zend_Service_Amazon_Authentication_S3 extends Zend_Service_Amazon_Authentication
41
+ {
42
+ /**
43
+ * Add the S3 Authorization signature to the request headers
44
+ *
45
+ * @param string $method
46
+ * @param string $path
47
+ * @param array &$headers
48
+ * @return string
49
+ */
50
+ public function generateSignature($method, $path, &$headers)
51
+ {
52
+ if (! is_array($headers)) {
53
+ $headers = array($headers);
54
+ }
55
+
56
+ $type = $md5 = $date = '';
57
+
58
+ // Search for the Content-type, Content-MD5 and Date headers
59
+ foreach ($headers as $key => $val) {
60
+ if (strcasecmp($key, 'content-type') == 0) {
61
+ $type = $val;
62
+ } else if (strcasecmp($key, 'content-md5') == 0) {
63
+ $md5 = $val;
64
+ } else if (strcasecmp($key, 'date') == 0) {
65
+ $date = $val;
66
+ }
67
+ }
68
+
69
+ // If we have an x-amz-date header, use that instead of the normal Date
70
+ if (isset($headers['x-amz-date']) && isset($date)) {
71
+ $date = '';
72
+ }
73
+
74
+ $sig_str = "$method\n$md5\n$type\n$date\n";
75
+
76
+ // For x-amz- headers, combine like keys, lowercase them, sort them
77
+ // alphabetically and remove excess spaces around values
78
+ $amz_headers = array();
79
+ foreach ($headers as $key => $val) {
80
+ $key = strtolower($key);
81
+ if (substr($key, 0, 6) == 'x-amz-') {
82
+ if (is_array($val)) {
83
+ $amz_headers[$key] = $val;
84
+ } else {
85
+ $amz_headers[$key][] = preg_replace('/\s+/', ' ', $val);
86
+ }
87
+ }
88
+ }
89
+ if (!empty($amz_headers)) {
90
+ ksort($amz_headers);
91
+ foreach ($amz_headers as $key => $val) {
92
+ $sig_str .= $key . ':' . implode(',', $val) . "\n";
93
+ }
94
+ }
95
+
96
+ $sig_str .= '/'.parse_url($path, PHP_URL_PATH);
97
+ if (strpos($path, '?location') !== false) {
98
+ $sig_str .= '?location';
99
+ } else
100
+ if (strpos($path, '?acl') !== false) {
101
+ $sig_str .= '?acl';
102
+ } else
103
+ if (strpos($path, '?torrent') !== false) {
104
+ $sig_str .= '?torrent';
105
+ }
106
+
107
+ $signature = base64_encode(Zend_Crypt_Hmac::compute($this->_secretKey, 'sha1', utf8_encode($sig_str), Zend_Crypt_Hmac::BINARY));
108
+ $headers['Authorization'] = 'AWS ' . $this->_accessKey . ':' . $signature;
109
+
110
+ return $sig_str;
111
+ }
112
+ }
lib/Zend/Service/Amazon/Authentication/V1.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Service_Amazon
17
+ * @subpackage Authentication
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Service_Amazon_Authentication
24
+ */
25
+ #require_once 'Zend/Service/Amazon/Authentication.php';
26
+
27
+ /**
28
+ * @see Zend_Crypt_Hmac
29
+ */
30
+ #require_once 'Zend/Crypt/Hmac.php';
31
+
32
+ /**
33
+ * @category Zend
34
+ * @package Zend_Service_Amazon
35
+ * @subpackage Authentication
36
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
37
+ * @license http://framework.zend.com/license/new-bsd New BSD License
38
+ */
39
+ class Zend_Service_Amazon_Authentication_V1 extends Zend_Service_Amazon_Authentication
40
+ {
41
+ /**
42
+ * Signature Version
43
+ */
44
+ protected $_signatureVersion = '1';
45
+
46
+ /**
47
+ * Signature Encoding Method
48
+ */
49
+ protected $_signatureMethod = 'HmacSHA256';
50
+
51
+ /**
52
+ * Generate the required attributes for the signature
53
+ * @param string $url
54
+ * @param array $parameters
55
+ * @return string
56
+ */
57
+ public function generateSignature($url, array &$parameters)
58
+ {
59
+ $parameters['AWSAccessKeyId'] = $this->_accessKey;
60
+ $parameters['SignatureVersion'] = $this->_signatureVersion;
61
+ $parameters['Version'] = $this->_apiVersion;
62
+ if(!isset($parameters['Timestamp'])) {
63
+ $parameters['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z', time()+10);
64
+ }
65
+
66
+ $data = $this->_signParameters($url, $parameters);
67
+
68
+ return $data;
69
+ }
70
+
71
+ /**
72
+ * Computes the RFC 2104-compliant HMAC signature for request parameters
73
+ *
74
+ * This implements the Amazon Web Services signature, as per the following
75
+ * specification:
76
+ *
77
+ * 1. Sort all request parameters (including <tt>SignatureVersion</tt> and
78
+ * excluding <tt>Signature</tt>, the value of which is being created),
79
+ * ignoring case.
80
+ *
81
+ * 2. Iterate over the sorted list and append the parameter name (in its
82
+ * original case) and then its value. Do not URL-encode the parameter
83
+ * values before constructing this string. Do not use any separator
84
+ * characters when appending strings.
85
+ *
86
+ * @param string $queue_url Queue URL
87
+ * @param array $parameters the parameters for which to get the signature.
88
+ *
89
+ * @return string the signed data.
90
+ */
91
+ protected function _signParameters($url, array &$paramaters)
92
+ {
93
+ $data = '';
94
+
95
+ uksort($paramaters, 'strcasecmp');
96
+ unset($paramaters['Signature']);
97
+
98
+ foreach($paramaters as $key => $value) {
99
+ $data .= $key . $value;
100
+ }
101
+
102
+ $hmac = Zend_Crypt_Hmac::compute($this->_secretKey, 'SHA1', $data, Zend_Crypt_Hmac::BINARY);
103
+
104
+ $paramaters['Signature'] = base64_encode($hmac);
105
+
106
+ return $data;
107
+ }
108
+ }
lib/Zend/Service/Amazon/Authentication/V2.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Service_Amazon
17
+ * @subpackage Authentication
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Service_Amazon_Authentication
24
+ */
25
+ #require_once 'Zend/Service/Amazon/Authentication.php';
26
+
27
+ /**
28
+ * @see Zend_Crypt_Hmac
29
+ */
30
+ #require_once 'Zend/Crypt/Hmac.php';
31
+
32
+ /**
33
+ * @category Zend
34
+ * @package Zend_Service_Amazon
35
+ * @subpackage Authentication
36
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
37
+ * @license http://framework.zend.com/license/new-bsd New BSD License
38
+ */
39
+ class Zend_Service_Amazon_Authentication_V2 extends Zend_Service_Amazon_Authentication
40
+ {
41
+ /**
42
+ * Signature Version
43
+ */
44
+ protected $_signatureVersion = '2';
45
+
46
+ /**
47
+ * Signature Encoding Method
48
+ */
49
+ protected $_signatureMethod = 'HmacSHA256';
50
+
51
+ /**
52
+ * Type of http request
53
+ * @var string
54
+ */
55
+ protected $_httpMethod = "POST";
56
+
57
+ /**
58
+ * Generate the required attributes for the signature
59
+ * @param string $url
60
+ * @param array $parameters
61
+ * @return string
62
+ */
63
+ public function generateSignature($url, array &$parameters)
64
+ {
65
+ $parameters['AWSAccessKeyId'] = $this->_accessKey;
66
+ $parameters['SignatureVersion'] = $this->_signatureVersion;
67
+ $parameters['Version'] = $this->_apiVersion;
68
+ $parameters['SignatureMethod'] = $this->_signatureMethod;
69
+ if(!isset($parameters['Timestamp'])) {
70
+ $parameters['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z', time()+10);
71
+ }
72
+
73
+ $data = $this->_signParameters($url, $parameters);
74
+
75
+ return $data;
76
+ }
77
+
78
+ /**
79
+ * Set http request type to POST or GET
80
+ * @param $method string
81
+ */
82
+ public function setHttpMethod($method = "POST") {
83
+ $this->_httpMethod = strtoupper($method);
84
+ }
85
+
86
+ /**
87
+ * Get the current http request type
88
+ * @return string
89
+ */
90
+ public function getHttpMethod()
91
+ {
92
+ return $this->_httpMethod;
93
+ }
94
+
95
+ /**
96
+ * Computes the RFC 2104-compliant HMAC signature for request parameters
97
+ *
98
+ * This implements the Amazon Web Services signature, as per the following
99
+ * specification:
100
+ *
101
+ * 1. Sort all request parameters (including <tt>SignatureVersion</tt> and
102
+ * excluding <tt>Signature</tt>, the value of which is being created),
103
+ * ignoring case.
104
+ *
105
+ * 2. Iterate over the sorted list and append the parameter name (in its
106
+ * original case) and then its value. Do not URL-encode the parameter
107
+ * values before constructing this string. Do not use any separator
108
+ * characters when appending strings.
109
+ *
110
+ * @param string $queue_url Queue URL
111
+ * @param array $parameters the parameters for which to get the signature.
112
+ *
113
+ * @return string the signed data.
114
+ */
115
+ protected function _signParameters($url, array &$paramaters)
116
+ {
117
+ $data = $this->_httpMethod . "\n";
118
+ $data .= parse_url($url, PHP_URL_HOST) . "\n";
119
+ $data .= ('' == $path = parse_url($url, PHP_URL_PATH)) ? '/' : $path;
120
+ $data .= "\n";
121
+
122
+ uksort($paramaters, 'strcmp');
123
+ unset($paramaters['Signature']);
124
+
125
+ $arrData = array();
126
+ foreach($paramaters as $key => $value) {
127
+ $arrData[] = $key . '=' . str_replace('%7E', '~', rawurlencode($value));
128
+ }
129
+
130
+ $data .= implode('&', $arrData);
131
+
132
+ $hmac = Zend_Crypt_Hmac::compute($this->_secretKey, 'SHA256', $data, Zend_Crypt_Hmac::BINARY);
133
+
134
+ $paramaters['Signature'] = base64_encode($hmac);
135
+
136
+ return $data;
137
+ }
138
+ }
lib/Zend/Service/Amazon/Ec2/Ebs.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Ec2
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Ebs.php 22048 2010-04-28 22:23:19Z shahar $
21
  */
22
 
23
  /**
17
  * @subpackage Ec2
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Ebs.php 22047 2010-04-28 22:14:51Z shahar $
21
  */
22
 
23
  /**
lib/Zend/Service/Amazon/Ec2/Instance.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Ec2
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Instance.php 22048 2010-04-28 22:23:19Z shahar $
21
  */
22
 
23
  /**
17
  * @subpackage Ec2
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Instance.php 22046 2010-04-28 22:12:32Z shahar $
21
  */
22
 
23
  /**
lib/Zend/Service/Amazon/Item.php CHANGED
@@ -18,7 +18,7 @@
18
  * @subpackage Amazon
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
- * @version $Id: Item.php 21884 2010-04-16 15:08:34Z dragonbe $
22
  */
23
 
24
 
18
  * @subpackage Amazon
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
+ * @version $Id: Item.php 21883 2010-04-16 14:57:07Z dragonbe $
22
  */
23
 
24
 
lib/Zend/Service/Amazon/Offer.php CHANGED
@@ -18,7 +18,7 @@
18
  * @subpackage Amazon
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
- * @version $Id: Offer.php 21155 2010-02-23 17:11:12Z matthew $
22
  */
23
 
24
 
18
  * @subpackage Amazon
19
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20
  * @license http://framework.zend.com/license/new-bsd New BSD License
21
+ * @version $Id: Offer.php 21154 2010-02-23 17:10:34Z matthew $
22
  */
23
 
24
 
lib/Zend/Service/Amazon/S3.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Amazon_S3
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: S3.php 20096 2010-01-06 02:05:09Z bkarwin $
21
  */
22
 
23
  /**
@@ -190,6 +190,7 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
190
  */
191
  public function isObjectAvailable($object)
192
  {
 
193
  $response = $this->_makeRequest('HEAD', $object);
194
 
195
  return ($response->getStatus() == 200);
@@ -502,6 +503,57 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
502
  return ($response->getStatus() == 204);
503
  }
504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
505
  /**
506
  * Make a request to Amazon S3
507
  *
@@ -556,10 +608,13 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
556
  $client->setAuth(false);
557
  // Work around buglet in HTTP client - it doesn't clean headers
558
  // Remove when ZHC is fixed
559
- $client->setHeaders(array('Content-MD5' => null,
560
- 'Expect' => null,
561
- 'Range' => null,
562
- 'x-amz-acl' => null));
 
 
 
563
 
564
  $client->setHeaders($headers);
565
 
17
  * @subpackage Amazon_S3
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: S3.php 23224 2010-10-22 13:45:57Z matthew $
21
  */
22
 
23
  /**
190
  */
191
  public function isObjectAvailable($object)
192
  {
193
+ $object = $this->_fixupObjectName($object);
194
  $response = $this->_makeRequest('HEAD', $object);
195
 
196
  return ($response->getStatus() == 200);
503
  return ($response->getStatus() == 204);
504
  }
505
 
506
+ /**
507
+ * Copy an object
508
+ *
509
+ * @param string $sourceObject Source object name
510
+ * @param string $destObject Destination object name
511
+ * @param array $meta (OPTIONAL) Metadata to apply to desination object.
512
+ * Set to null to copy metadata from source object.
513
+ * @return boolean
514
+ */
515
+ public function copyObject($sourceObject, $destObject, $meta = null)
516
+ {
517
+ $sourceObject = $this->_fixupObjectName($sourceObject);
518
+ $destObject = $this->_fixupObjectName($destObject);
519
+
520
+ $headers = (is_array($meta)) ? $meta : array();
521
+ $headers['x-amz-copy-source'] = $sourceObject;
522
+ $headers['x-amz-metadata-directive'] = $meta === null ? 'COPY' : 'REPLACE';
523
+
524
+ $response = $this->_makeRequest('PUT', $destObject, null, $headers);
525
+
526
+ if ($response->getStatus() == 200 && !stristr($response->getBody(), '<Error>')) {
527
+ return true;
528
+ }
529
+
530
+ return false;
531
+ }
532
+
533
+ /**
534
+ * Move an object
535
+ *
536
+ * Performs a copy to dest + verify + remove source
537
+ *
538
+ * @param string $sourceObject Source object name
539
+ * @param string $destObject Destination object name
540
+ * @param array $meta (OPTIONAL) Metadata to apply to destination object.
541
+ * Set to null to retain existing metadata.
542
+ */
543
+ public function moveObject($sourceObject, $destObject, $meta = null)
544
+ {
545
+ $sourceInfo = $this->getInfo($sourceObject);
546
+
547
+ $this->copyObject($sourceObject, $destObject, $meta);
548
+ $destInfo = $this->getInfo($destObject);
549
+
550
+ if ($sourceInfo['etag'] === $destInfo['etag']) {
551
+ return $this->removeObject($sourceObject);
552
+ } else {
553
+ return false;
554
+ }
555
+ }
556
+
557
  /**
558
  * Make a request to Amazon S3
559
  *
608
  $client->setAuth(false);
609
  // Work around buglet in HTTP client - it doesn't clean headers
610
  // Remove when ZHC is fixed
611
+ $client->setHeaders(array('Content-MD5' => null,
612
+ 'Content-Encoding' => null,
613
+ 'Expect' => null,
614
+ 'Range' => null,
615
+ 'x-amz-acl' => null,
616
+ 'x-amz-copy-source' => null,
617
+ 'x-amz-metadata-directive' => null));
618
 
619
  $client->setHeaders($headers);
620
 
lib/Zend/Service/Amazon/S3/Stream.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Amazon_S3
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Stream.php 22623 2010-07-18 00:43:57Z torio $
21
  */
22
 
23
  /**
17
  * @subpackage Amazon_S3
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Stream.php 22621 2010-07-18 00:35:48Z torio $
21
  */
22
 
23
  /**
lib/Zend/Service/Amazon/SimpleDb.php ADDED
@@ -0,0 +1,580 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Service_Amazon
17
+ * @subpackage SimpleDb
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Service_Amazon_Abstract
24
+ */
25
+ #require_once 'Zend/Service/Amazon/Abstract.php';
26
+
27
+ /**
28
+ * @see Zend_Service_Amazon_SimpleDb_Response
29
+ */
30
+ #require_once 'Zend/Service/Amazon/SimpleDb/Response.php';
31
+
32
+ /**
33
+ * @see Zend_Service_Amazon_SimpleDb_Page
34
+ */
35
+ #require_once 'Zend/Service/Amazon/SimpleDb/Page.php';
36
+
37
+ /**
38
+ * @see Zend_Service_Amazon_SimpleDb_Attribute
39
+ */
40
+ #require_once 'Zend/Service/Amazon/SimpleDb/Attribute.php';
41
+
42
+ /**
43
+ * @see Zend_Service_Amazon_SimpleDb_Exception
44
+ */
45
+ #require_once 'Zend/Service/Amazon/SimpleDb/Exception.php';
46
+
47
+ /**
48
+ * @see Zend_Crypt_Hmac
49
+ */
50
+ #require_once 'Zend/Crypt/Hmac.php';
51
+
52
+ /**
53
+ * @category Zend
54
+ * @package Zend_Service_Amazon
55
+ * @subpackage SimpleDb
56
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
57
+ * @license http://framework.zend.com/license/new-bsd New BSD License
58
+ */
59
+ class Zend_Service_Amazon_SimpleDb extends Zend_Service_Amazon_Abstract
60
+ {
61
+ /* Notes */
62
+ // TODO SSL is required
63
+
64
+ /**
65
+ * The HTTP query server
66
+ */
67
+ protected $_sdbEndpoint = 'sdb.amazonaws.com/';
68
+
69
+ /**
70
+ * Period after which HTTP request will timeout in seconds
71
+ */
72
+ protected $_httpTimeout = 10;
73
+
74
+ /**
75
+ * The API version to use
76
+ */
77
+ protected $_sdbApiVersion = '2009-04-15';
78
+
79
+ /**
80
+ * Signature Version
81
+ */
82
+ protected $_signatureVersion = '2';
83
+
84
+ /**
85
+ * Signature Encoding Method
86
+ */
87
+ protected $_signatureMethod = 'HmacSHA256';
88
+
89
+ /**
90
+ * Create Amazon SimpleDB client.
91
+ *
92
+ * @param string $access_key Override the default Access Key
93
+ * @param string $secret_key Override the default Secret Key
94
+ * @param string $region Sets the AWS Region
95
+ * @return void
96
+ */
97
+ public function __construct($accessKey, $secretKey)
98
+ {
99
+ parent::__construct($accessKey, $secretKey);
100
+ $this->setEndpoint("https://" . $this->_sdbEndpoint);
101
+ }
102
+
103
+ /**
104
+ * Set SimpleDB endpoint to use
105
+ *
106
+ * @param string|Zend_Uri_Http $endpoint
107
+ * @return Zend_Service_Amazon_SimpleDb
108
+ */
109
+ public function setEndpoint($endpoint)
110
+ {
111
+ if(!($endpoint instanceof Zend_Uri_Http)) {
112
+ $endpoint = Zend_Uri::factory($endpoint);
113
+ }
114
+ if(!$endpoint->valid()) {
115
+ #require_once 'Zend/Service/Amazon/SimpleDb/Exception.php';
116
+ throw new Zend_Service_Amazon_SimpleDb_Exception("Invalid endpoint supplied");
117
+ }
118
+ $this->_endpoint = $endpoint;
119
+ return $this;
120
+ }
121
+
122
+ /**
123
+ * Get SimpleDB endpoint
124
+ *
125
+ * @return Zend_Uri_Http
126
+ */
127
+ public function getEndpoint()
128
+ {
129
+ return $this->_endpoint;
130
+ }
131
+
132
+ /**
133
+ * Get attributes API method
134
+ *
135
+ * @param string $domainName Domain name within database
136
+ * @param string
137
+ */
138
+ public function getAttributes(
139
+ $domainName, $itemName, $attributeName = null
140
+ ) {
141
+ $params = array();
142
+ $params['Action'] = 'GetAttributes';
143
+ $params['DomainName'] = $domainName;
144
+ $params['ItemName'] = $itemName;
145
+
146
+ if (isset($attributeName)) {
147
+ $params['AttributeName'] = $attributeName;
148
+ }
149
+
150
+ $response = $this->_sendRequest($params);
151
+ $document = $response->getSimpleXMLDocument();
152
+
153
+ $attributeNodes = $document->GetAttributesResult->Attribute;
154
+
155
+ // Return an array of arrays
156
+ $attributes = array();
157
+ foreach($attributeNodes as $attributeNode) {
158
+ $name = (string)$attributeNode->Name;
159
+ $valueNodes = $attributeNode->Value;
160
+ $data = null;
161
+ if (is_array($valueNodes) && !empty($valueNodes)) {
162
+ $data = array();
163
+ foreach($valueNodes as $valueNode) {
164
+ $data[] = (string)$valueNode;
165
+ }
166
+ } elseif (isset($valueNodes)) {
167
+ $data = (string)$valueNodes;
168
+ }
169
+ if (isset($attributes[$name])) {
170
+ $attributes[$name]->addValue($data);
171
+ } else {
172
+ $attributes[$name] = new Zend_Service_Amazon_SimpleDb_Attribute($itemName, $name, $data);
173
+ }
174
+ }
175
+ return $attributes;
176
+ }
177
+
178
+ /**
179
+ * Push attributes
180
+ *
181
+ * @param string $domainName
182
+ * @param string $itemName
183
+ * @param array|Traverable $attributes
184
+ * @param array $replace
185
+ * @return void
186
+ */
187
+ public function putAttributes(
188
+ $domainName, $itemName, $attributes, $replace = array()
189
+ ) {
190
+ $params = array();
191
+ $params['Action'] = 'PutAttributes';
192
+ $params['DomainName'] = $domainName;
193
+ $params['ItemName'] = $itemName;
194
+
195
+ $index = 0;
196
+ foreach ($attributes as $attribute) {
197
+ $attributeName = $attribute->getName();
198
+ foreach ($attribute->getValues() as $value) {
199
+ $params['Attribute.' . $index . '.Name'] = $attributeName;
200
+ $params['Attribute.' . $index . '.Value'] = $value;
201
+
202
+ // Check if it should be replaced
203
+ if(array_key_exists($attributeName, $replace) && $replace[$attributeName]) {
204
+ $params['Attribute.' . $index . '.Replace'] = 'true';
205
+ }
206
+ $index++;
207
+ }
208
+ }
209
+
210
+ // Exception should get thrown if there's an error
211
+ $response = $this->_sendRequest($params);
212
+ }
213
+
214
+ /**
215
+ * Add many attributes at once
216
+ *
217
+ * @param array $items
218
+ * @param string $domainName
219
+ * @param array $replace
220
+ * @return void
221
+ */
222
+ public function batchPutAttributes($items, $domainName, array $replace = array())
223
+ {
224
+
225
+ $params = array();
226
+ $params['Action'] = 'BatchPutAttributes';
227
+ $params['DomainName'] = $domainName;
228
+
229
+ $itemIndex = 0;
230
+ foreach ($items as $name => $attributes) {
231
+ $params['Item.' . $itemIndex . '.ItemName'] = $name;
232
+ $attributeIndex = 0;
233
+ foreach ($attributes as $attribute) {
234
+ // attribute value cannot be array, so when several items are passed
235
+ // they are treated as separate values with the same attribute name
236
+ foreach($attribute->getValues() as $value) {
237
+ $params['Item.' . $itemIndex . '.Attribute.' . $attributeIndex . '.Name'] = $attribute->getName();
238
+ $params['Item.' . $itemIndex . '.Attribute.' . $attributeIndex . '.Value'] = $value;
239
+ if (isset($replace[$name])
240
+ && isset($replace[$name][$attribute->getName()])
241
+ && $replace[$name][$attribute->getName()]
242
+ ) {
243
+ $params['Item.' . $itemIndex . '.Attribute.' . $attributeIndex . '.Replace'] = 'true';
244
+ }
245
+ $attributeIndex++;
246
+ }
247
+ }
248
+ $itemIndex++;
249
+ }
250
+
251
+ $response = $this->_sendRequest($params);
252
+ }
253
+
254
+ /**
255
+ * Delete attributes
256
+ *
257
+ * @param string $domainName
258
+ * @param string $itemName
259
+ * @param array $attributes
260
+ * @return void
261
+ */
262
+ public function deleteAttributes($domainName, $itemName, array $attributes = array())
263
+ {
264
+ $params = array();
265
+ $params['Action'] = 'DeleteAttributes';
266
+ $params['DomainName'] = $domainName;
267
+ $params['ItemName'] = $itemName;
268
+
269
+ $attributeIndex = 0;
270
+ foreach ($attributes as $attribute) {
271
+ foreach ($attribute->getValues() as $value) {
272
+ $params['Attribute.' . $attributeIndex . '.Name'] = $attribute->getName();
273
+ $params['Attribute.' . $attributeIndex . '.Value'] = $value;
274
+ $attributeIndex++;
275
+ }
276
+ }
277
+
278
+ $response = $this->_sendRequest($params);
279
+
280
+ return true;
281
+ }
282
+
283
+ /**
284
+ * List domains
285
+ *
286
+ * @param $maxNumberOfDomains int
287
+ * @param $nextToken int
288
+ * @return array 0 or more domain names
289
+ */
290
+ public function listDomains($maxNumberOfDomains = 100, $nextToken = null)
291
+ {
292
+ $params = array();
293
+ $params['Action'] = 'ListDomains';
294
+ $params['MaxNumberOfDomains'] = $maxNumberOfDomains;
295
+
296
+ if (null !== $nextToken) {
297
+ $params['NextToken'] = $nextToken;
298
+ }
299
+ $response = $this->_sendRequest($params);
300
+
301
+ $domainNodes = $response->getSimpleXMLDocument()->ListDomainsResult->DomainName;
302
+
303
+ $data = array();
304
+ foreach ($domainNodes as $domain) {
305
+ $data[] = (string)$domain;
306
+ }
307
+
308
+ $nextTokenNode = $response->getSimpleXMLDocument()->ListDomainsResult->NextToken;
309
+ $nextToken = (string)$nextTokenNode;
310
+ $nextToken = (trim($nextToken) === '') ? null : $nextToken;
311
+
312
+ return new Zend_Service_Amazon_SimpleDb_Page($data, $nextToken);
313
+ }
314
+
315
+ /**
316
+ * Retrieve domain metadata
317
+ *
318
+ * @param $domainName string Name of the domain for which metadata will be requested
319
+ * @return array Key/value array of metadatum names and values.
320
+ */
321
+ public function domainMetadata($domainName)
322
+ {
323
+ $params = array();
324
+ $params['Action'] = 'DomainMetadata';
325
+ $params['DomainName'] = $domainName;
326
+ $response = $this->_sendRequest($params);
327
+
328
+ $document = $response->getSimpleXMLDocument();
329
+
330
+ $metadataNodes = $document->DomainMetadataResult->children();
331
+ $metadata = array();
332
+ foreach ($metadataNodes as $metadataNode) {
333
+ $name = $metadataNode->getName();
334
+ $metadata[$name] = (string)$metadataNode;
335
+ }
336
+
337
+ return $metadata;
338
+ }
339
+
340
+ /**
341
+ * Create a new domain
342
+ *
343
+ * @param $domainName string Valid domain name of the domain to create
344
+ * @return boolean True if successful, false if not
345
+ */
346
+ public function createDomain($domainName)
347
+ {
348
+ $params = array();
349
+ $params['Action'] = 'CreateDomain';
350
+ $params['DomainName'] = $domainName;
351
+ $response = $this->_sendRequest($params);
352
+ return $response->getHttpResponse()->isSuccessful();
353
+ }
354
+
355
+ /**
356
+ * Delete a domain
357
+ *
358
+ * @param $domainName string Valid domain name of the domain to delete
359
+ * @return boolean True if successful, false if not
360
+ */
361
+ public function deleteDomain($domainName)
362
+ {
363
+ $params = array();
364
+ $params['Action'] = 'DeleteDomain';
365
+ $params['DomainName'] = $domainName;
366
+ $response = $this->_sendRequest($params);
367
+ return $response->getHttpResponse()->isSuccessful();
368
+ }
369
+
370
+ /**
371
+ * Select items from the database
372
+ *
373
+ * @param string $selectExpression
374
+ * @param null|string $nextToken
375
+ * @return Zend_Service_Amazon_SimpleDb_Page
376
+ */
377
+ public function select($selectExpression, $nextToken = null)
378
+ {
379
+ $params = array();
380
+ $params['Action'] = 'Select';
381
+ $params['SelectExpression'] = $selectExpression;
382
+
383
+ if (null !== $nextToken) {
384
+ $params['NextToken'] = $nextToken;
385
+ }
386
+
387
+ $response = $this->_sendRequest($params);
388
+ $xml = $response->getSimpleXMLDocument();
389
+
390
+ $attributes = array();
391
+ foreach ($xml->SelectResult->Item as $item) {
392
+ $itemName = (string)$item->Name;
393
+
394
+ foreach ($item->Attribute as $attribute) {
395
+ $attributeName = (string)$attribute->Name;
396
+
397
+ $values = array();
398
+ foreach ($attribute->Value as $value) {
399
+ $values[] = (string)$value;
400
+ }
401
+ $attributes[$itemName][$attributeName] = new Zend_Service_Amazon_SimpleDb_Attribute($itemName, $attributeName, $values);
402
+ }
403
+ }
404
+
405
+ $nextToken = (string)$xml->NextToken;
406
+
407
+ return new Zend_Service_Amazon_SimpleDb_Page($attributes, $nextToken);
408
+ }
409
+
410
+ /**
411
+ * Quote SDB value
412
+ *
413
+ * Wraps it in ''
414
+ *
415
+ * @param string $value
416
+ * @return string
417
+ */
418
+ public function quote($value)
419
+ {
420
+ // wrap in single quotes and convert each ' inside to ''
421
+ return "'" . str_replace("'", "''", $value) . "'";
422
+ }
423
+
424
+ /**
425
+ * Quote SDB column or table name
426
+ *
427
+ * Wraps it in ``
428
+ * @param string $name
429
+ * @return string
430
+ */
431
+ public function quoteName($name)
432
+ {
433
+ if (preg_match('/^[a-z_$][a-z0-9_$-]*$/i', $name) == false) {
434
+ throw new Zend_Service_Amazon_SimpleDb_Exception("Invalid name: can contain only alphanumeric characters, \$ and _");
435
+ }
436
+ return "`$name`";
437
+ }
438
+
439
+ /**
440
+ * Sends a HTTP request to the SimpleDB service using Zend_Http_Client
441
+ *
442
+ * @param array $params List of parameters to send with the request
443
+ * @return Zend_Service_Amazon_SimpleDb_Response
444
+ * @throws Zend_Service_Amazon_SimpleDb_Exception
445
+ */
446
+ protected function _sendRequest(array $params = array())
447
+ {
448
+ // UTF-8 encode all parameters and replace '+' characters
449
+ foreach ($params as $name => $value) {
450
+ unset($params[$name]);
451
+ $params[utf8_encode($name)] = $value;
452
+ }
453
+
454
+ $params = $this->_addRequiredParameters($params);
455
+
456
+ try {
457
+ /* @var $request Zend_Http_Client */
458
+ $request = self::getHttpClient();
459
+ $request->resetParameters();
460
+
461
+ $request->setConfig(array(
462
+ 'timeout' => $this->_httpTimeout
463
+ ));
464
+
465
+
466
+ $request->setUri($this->getEndpoint());
467
+ $request->setMethod(Zend_Http_Client::POST);
468
+ foreach ($params as $key => $value) {
469
+ $params_out[] = rawurlencode($key)."=".rawurlencode($value);
470
+ }
471
+ $request->setRawData(join('&', $params_out), Zend_Http_Client::ENC_URLENCODED);
472
+ $httpResponse = $request->request();
473
+ } catch (Zend_Http_Client_Exception $zhce) {
474
+ $message = 'Error in request to AWS service: ' . $zhce->getMessage();
475
+ throw new Zend_Service_Amazon_SimpleDb_Exception($message, $zhce->getCode());
476
+ }
477
+ $response = new Zend_Service_Amazon_SimpleDb_Response($httpResponse);
478
+ $this->_checkForErrors($response);
479
+ return $response;
480
+ }
481
+
482
+ /**
483
+ * Adds required authentication and version parameters to an array of
484
+ * parameters
485
+ *
486
+ * The required parameters are:
487
+ * - AWSAccessKey
488
+ * - SignatureVersion
489
+ * - Timestamp
490
+ * - Version and
491
+ * - Signature
492
+ *
493
+ * If a required parameter is already set in the <tt>$parameters</tt> array,
494
+ * it is overwritten.
495
+ *
496
+ * @param array $parameters the array to which to add the required
497
+ * parameters.
498
+ *
499
+ * @return array
500
+ */
501
+ protected function _addRequiredParameters(array $parameters)
502
+ {
503
+ $parameters['AWSAccessKeyId'] = $this->_getAccessKey();
504
+ $parameters['SignatureVersion'] = $this->_signatureVersion;
505
+ $parameters['Timestamp'] = gmdate('c');
506
+ $parameters['Version'] = $this->_sdbApiVersion;
507
+ $parameters['SignatureMethod'] = $this->_signatureMethod;
508
+ $parameters['Signature'] = $this->_signParameters($parameters);
509
+
510
+ return $parameters;
511
+ }
512
+
513
+ /**
514
+ * Computes the RFC 2104-compliant HMAC signature for request parameters
515
+ *
516
+ * This implements the Amazon Web Services signature, as per the following
517
+ * specification:
518
+ *
519
+ * 1. Sort all request parameters (including <tt>SignatureVersion</tt> and
520
+ * excluding <tt>Signature</tt>, the value of which is being created),
521
+ * ignoring case.
522
+ *
523
+ * 2. Iterate over the sorted list and append the parameter name (in its
524
+ * original case) and then its value. Do not URL-encode the parameter
525
+ * values before constructing this string. Do not use any separator
526
+ * characters when appending strings.
527
+ *
528
+ * @param array $parameters the parameters for which to get the signature.
529
+ * @param string $secretKey the secret key to use to sign the parameters.
530
+ *
531
+ * @return string the signed data.
532
+ */
533
+ protected function _signParameters(array $paramaters)
534
+ {
535
+ $data = "POST\n";
536
+ $data .= $this->getEndpoint()->getHost() . "\n";
537
+ $data .= "/\n";
538
+
539
+ uksort($paramaters, 'strcmp');
540
+ unset($paramaters['Signature']);
541
+
542
+ $arrData = array();
543
+ foreach ($paramaters as $key => $value) {
544
+ $value = urlencode($value);
545
+ $value = str_replace("%7E", "~", $value);
546
+ $value = str_replace("+", "%20", $value);
547
+ $arrData[] = urlencode($key) . '=' . $value;
548
+ }
549
+
550
+ $data .= implode('&', $arrData);
551
+
552
+ #require_once 'Zend/Crypt/Hmac.php';
553
+ $hmac = Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'SHA256', $data, Zend_Crypt_Hmac::BINARY);
554
+
555
+ return base64_encode($hmac);
556
+ }
557
+
558
+ /**
559
+ * Checks for errors responses from Amazon
560
+ *
561
+ * @param Zend_Service_Amazon_SimpleDb_Response $response the response object to
562
+ * check.
563
+ *
564
+ * @return void
565
+ *
566
+ * @throws Zend_Service_Amazon_SimpleDb_Exception if one or more errors are
567
+ * returned from Amazon.
568
+ */
569
+ private function _checkForErrors(Zend_Service_Amazon_SimpleDb_Response $response)
570
+ {
571
+ $xpath = new DOMXPath($response->getDocument());
572
+ $list = $xpath->query('//Error');
573
+ if ($list->length > 0) {
574
+ $node = $list->item(0);
575
+ $code = $xpath->evaluate('string(Code/text())', $node);
576
+ $message = $xpath->evaluate('string(Message/text())', $node);
577
+ throw new Zend_Service_Amazon_SimpleDb_Exception($message, 0, $code);
578
+ }
579
+ }
580
+ }
lib/Zend/Service/Amazon/SimpleDb/Attribute.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Service_Amazon
17
+ * @subpackage SimpleDb
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Response.php 17539 2009-08-10 22:51:26Z mikaelkael $
21
+ */
22
+
23
+ /**
24
+ * @category Zend
25
+ * @package Zend_Service_Amazon
26
+ * @subpackage SimpleDb
27
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
28
+ * @license http://framework.zend.com/license/new-bsd New BSD License
29
+ */
30
+ class Zend_Service_Amazon_SimpleDb_Attribute
31
+ {
32
+ protected $_itemName;
33
+ protected $_name;
34
+ protected $_values;
35
+
36
+ /**
37
+ * Constructor
38
+ *
39
+ * @param string $itemName
40
+ * @param string $name
41
+ * @param array $values
42
+ * @return void
43
+ */
44
+ function __construct($itemName, $name, $values)
45
+ {
46
+ $this->_itemName = $itemName;
47
+ $this->_name = $name;
48
+
49
+ if (!is_array($values)) {
50
+ $this->_values = array($values);
51
+ } else {
52
+ $this->_values = $values;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Return the item name to which the attribute belongs
58
+ *
59
+ * @return string
60
+ */
61
+ public function getItemName ()
62
+ {
63
+ return $this->_itemName;
64
+ }
65
+
66
+ /**
67
+ * Retrieve attribute values
68
+ *
69
+ * @return array
70
+ */
71
+ public function getValues()
72
+ {
73
+ return $this->_values;
74
+ }
75
+
76
+ /**
77
+ * Retrieve the attribute name
78
+ *
79
+ * @return string
80
+ */
81
+ public function getName ()
82
+ {
83
+ return $this->_name;
84
+ }
85
+
86
+ /**
87
+ * Add value
88
+ *
89
+ * @param mixed $value
90
+ * @return void
91
+ */
92
+ public function addValue($value)
93
+ {
94
+ if (is_array($value)) {
95
+ $this->_values += $value;
96
+ } else {
97
+ $this->_values[] = $value;
98
+ }
99
+ }
100
+
101
+ public function setValues($values)
102
+ {
103
+ if (!is_array($values)) {
104
+ $values = array($values);
105
+ }
106
+ $this->_values = $values;
107
+ }
108
+ }
lib/Zend/Service/Amazon/SimpleDb/Exception.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Service_Amazon
17
+ * @subpackage SimpleDb
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Service_Amazon_Exception
24
+ */
25
+ #require_once 'Zend/Service/Amazon/Exception.php';
26
+
27
+ /**
28
+ * The Custom Exception class that allows you to have access to the AWS Error Code.
29
+ *
30
+ * @category Zend
31
+ * @package Zend_Service_Amazon
32
+ * @subpackage SimpleDb
33
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
+ * @license http://framework.zend.com/license/new-bsd New BSD License
35
+ */
36
+ class Zend_Service_Amazon_SimpleDb_Exception extends Zend_Service_Amazon_Exception
37
+ {
38
+ /**
39
+ * @var string
40
+ */
41
+ private $_awsErrorCode = '';
42
+
43
+ /**
44
+ * Constructor
45
+ *
46
+ * @param string $message
47
+ * @param int $code
48
+ * @param string $awsErrorCode
49
+ * @return void
50
+ */
51
+ public function __construct($message, $code = 0, $awsErrorCode = '')
52
+ {
53
+ parent::__construct($message, $code);
54
+ $this->_awsErrorCode = $awsErrorCode;
55
+ }
56
+
57
+ /**
58
+ * Get AWS error code
59
+ *
60
+ * @return string
61
+ */
62
+ public function getErrorCode()
63
+ {
64
+ return $this->_awsErrorCode;
65
+ }
66
+ }
lib/Zend/Service/Amazon/SimpleDb/Page.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Service_Amazon
17
+ * @subpackage SimpleDb
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Service_Amazon_Exception
24
+ */
25
+ #require_once 'Zend/Service/Amazon/Exception.php';
26
+
27
+ /**
28
+ * The Custom Exception class that allows you to have access to the AWS Error Code.
29
+ *
30
+ * @category Zend
31
+ * @package Zend_Service_Amazon
32
+ * @subpackage SimpleDb
33
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34
+ * @license http://framework.zend.com/license/new-bsd New BSD License
35
+ */
36
+ class Zend_Service_Amazon_SimpleDb_Page
37
+ {
38
+ /** @var string Page data */
39
+ protected $_data;
40
+
41
+ /** @var string|null Token identifying page */
42
+ protected $_token;
43
+
44
+ /**
45
+ * Constructor
46
+ *
47
+ * @param string $data
48
+ * @param string|null $token
49
+ * @return void
50
+ */
51
+ public function __construct($data, $token = null)
52
+ {
53
+ $this->_data = $data;
54
+ $this->_token = $token;
55
+ }
56
+
57
+ /**
58
+ * Retrieve page data
59
+ *
60
+ * @return string
61
+ */
62
+ public function getData()
63
+ {
64
+ return $this->_data;
65
+ }
66
+
67
+ /**
68
+ * Retrieve token
69
+ *
70
+ * @return string|null
71
+ */
72
+ public function getToken()
73
+ {
74
+ return $this->_token;
75
+ }
76
+
77
+ /**
78
+ * Determine whether this is the last page of data
79
+ *
80
+ * @return void
81
+ */
82
+ public function isLast()
83
+ {
84
+ return (null === $this->_token);
85
+ }
86
+
87
+ /**
88
+ * Cast to string
89
+ *
90
+ * @return string
91
+ */
92
+ public function __toString()
93
+ {
94
+ return "Page with token: " . $this->_token
95
+ . "\n and data: " . $this->_data;
96
+ }
97
+ }
lib/Zend/Service/Amazon/SimpleDb/Response.php ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zend Framework
4
+ *
5
+ * LICENSE
6
+ *
7
+ * This source file is subject to the new BSD license that is bundled
8
+ * with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://framework.zend.com/license/new-bsd
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@zend.com so we can send you a copy immediately.
14
+ *
15
+ * @category Zend
16
+ * @package Zend_Service_Amazon
17
+ * @subpackage SimpleDb
18
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
+ * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ */
21
+
22
+ /**
23
+ * @see Zend_Http_Response
24
+ */
25
+ #require_once 'Zend/Http/Response.php';
26
+
27
+ /**
28
+ * @category Zend
29
+ * @package Zend_Service_Amazon
30
+ * @subpackage SimpleDb
31
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32
+ * @license http://framework.zend.com/license/new-bsd New BSD License
33
+ */
34
+ class Zend_Service_Amazon_SimpleDb_Response
35
+ {
36
+ /**
37
+ * XML namespace used for SimpleDB responses.
38
+ */
39
+ protected $_xmlNamespace = 'http://sdb.amazonaws.com/doc/2009-04-15/';
40
+
41
+ /**
42
+ * The original HTTP response
43
+ *
44
+ * This contains the response body and headers.
45
+ *
46
+ * @var Zend_Http_Response
47
+ */
48
+ private $_httpResponse = null;
49
+
50
+ /**
51
+ * The response document object
52
+ *
53
+ * @var DOMDocument
54
+ */
55
+ private $_document = null;
56
+
57
+ /**
58
+ * The response XPath
59
+ *
60
+ * @var DOMXPath
61
+ */
62
+ private $_xpath = null;
63
+
64
+ /**
65
+ * Last error code
66
+ *
67
+ * @var integer
68
+ */
69
+ private $_errorCode = 0;
70
+
71
+ /**
72
+ * Last error message
73
+ *
74
+ * @var string
75
+ */
76
+ private $_errorMessage = '';
77
+
78
+ /**
79
+ * Creates a new high-level SimpleDB response object
80
+ *
81
+ * @param Zend_Http_Response $httpResponse the HTTP response.
82
+ * @return void
83
+ */
84
+ public function __construct(Zend_Http_Response $httpResponse)
85
+ {
86
+ $this->_httpResponse = $httpResponse;
87
+ }
88
+
89
+ /**
90
+ * Gets the XPath object for this response
91
+ *
92
+ * @return DOMXPath the XPath object for response.
93
+ */
94
+ public function getXPath()
95
+ {
96
+ if ($this->_xpath === null) {
97
+ $document = $this->getDocument();
98
+ if ($document === false) {
99
+ $this->_xpath = false;
100
+ } else {
101
+ $this->_xpath = new DOMXPath($document);
102
+ $this->_xpath->registerNamespace('sdb',
103
+ $this->getNamespace());
104
+ }
105
+ }
106
+
107
+ return $this->_xpath;
108
+ }
109
+
110
+ /**
111
+ * Gets the SimpleXML document object for this response
112
+ *
113
+ * @return SimpleXMLElement
114
+ */
115
+ public function getSimpleXMLDocument()
116
+ {
117
+ try {
118
+ $body = $this->_httpResponse->getBody();
119
+ } catch (Zend_Http_Exception $e) {
120
+ $body = false;
121
+ }
122
+
123
+
124
+ return simplexml_load_string($body);
125
+ }
126
+
127
+ /**
128
+ * Get HTTP response object
129
+ *
130
+ * @return Zend_Http_Response
131
+ */
132
+ public function getHttpResponse()
133
+ {
134
+ return $this->_httpResponse;
135
+ }
136
+
137
+ /**
138
+ * Gets the document object for this response
139
+ *
140
+ * @return DOMDocument the DOM Document for this response.
141
+ */
142
+ public function getDocument()
143
+ {
144
+ try {
145
+ $body = $this->_httpResponse->getBody();
146
+ } catch (Zend_Http_Exception $e) {
147
+ $body = false;
148
+ }
149
+
150
+ if ($this->_document === null) {
151
+ if ($body !== false) {
152
+ // turn off libxml error handling
153
+ $errors = libxml_use_internal_errors();
154
+
155
+ $this->_document = new DOMDocument();
156
+ if (!$this->_document->loadXML($body)) {
157
+ $this->_document = false;
158
+ }
159
+
160
+ // reset libxml error handling
161
+ libxml_clear_errors();
162
+ libxml_use_internal_errors($errors);
163
+ } else {
164
+ $this->_document = false;
165
+ }
166
+ }
167
+
168
+ return $this->_document;
169
+ }
170
+
171
+ /**
172
+ * Return the current set XML Namespace.
173
+ *
174
+ * @return string
175
+ */
176
+ public function getNamespace()
177
+ {
178
+ return $this->_xmlNamespace;
179
+ }
180
+
181
+ /**
182
+ * Set a new XML Namespace
183
+ *
184
+ * @param string $namespace
185
+ */
186
+ public function setNamespace($namespace)
187
+ {
188
+ $this->_xmlNamespace = $namespace;
189
+ }
190
+ }
lib/Zend/Service/Amazon/Sqs.php CHANGED
@@ -17,7 +17,7 @@
17
  * @subpackage Amazon_Sqs
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
- * @version $Id: Sqs.php 21323 2010-03-04 18:27:32Z stas $
21
  */
22
 
23
  /**
@@ -105,7 +105,9 @@ class Zend_Service_Amazon_Sqs extends Zend_Service_Amazon_Abstract
105
  $retry = false;
106
  $resu
17
  * @subpackage Amazon_Sqs
18
  * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19
  * @license http://framework.zend.com/license/new-bsd New BSD License
20
+ * @version $Id: Sqs.php 22984 2010-09-21 02:52:48Z matthew $
21
  */
22
 
23
  /**
105
  $retry = false;
106
  $resu