11<?php
2+ use Df \Core \Exception as DFE ;
23use Df \Oro \Settings \General as S ;
34use Zend_Http_Client as C ;
45/**
56 * 2017-06-04
7+ * @used-by dfe_portal_stripe_customers()
68 * @param string $entity
79 * «How to apply a filter to a «get list» Web API request?» https://oplatform.club/t/103
810 * @param array(string => mixed) $filter [optional]
1214 * @param bool $local [optional]
1315 * «What is the difference between the «application/json» and «application/vnd.api+json»
1416 * content types of a Web API response?» https://oplatform.club/t/104
15- * @param bool $vnd [optional]
1617 * @return array(string => mixed)
18+ * @throws DFE
1719 */
18- function df_oro_get_list (
19- $ entity , array $ filter = [], array $ include = [], $ local = false , $ vnd = true
20- ) {
20+ function df_oro_get_list ($ entity , array $ filter = [], array $ include = [], $ local = false ) {
2121 // 2017-06-28
2222 // Due to a Oro Platform bug, a Web API request can randomly fail
2323 // with the «Unauthorized» response message.
@@ -27,23 +27,25 @@ function df_oro_get_list(
2727 $ c = null ; /** @var C $c */
2828 while (!$ raw && $ attempt ++ <= $ maxAttempts ) {
2929 $ c = df_zf_http ('https:// '
30- . ($ local ? 'localhost.com:848/app_dev .php ' : 'erp.mage2.pro ' )
30+ . ($ local ? 'localhost.com:848/index_dev .php ' : 'erp.mage2.pro ' )
3131 . "/api/extenddf $ entity "
3232 )
3333 // 2017-06-28
3434 // Due to a Oro Platform bug, the «content-type» headers is required for the «vnd» case,
3535 // even it does not have any sense here.
3636 // «Difference between the Accept and Content-Type HTTP headers»
3737 // https://webmasters.stackexchange.com/questions/31212
38- ->setHeaders (df_oro_headers () + (! $ vnd ? [ ' accept ' => ' application/json ' ] : array_fill_keys (
38+ ->setHeaders (df_oro_headers () + (array_fill_keys (
3939 ['accept ' , 'content-type ' ], 'application/vnd.api+json '
4040 )))
41- ->setParameterGet (df_clean (['filter ' => $ filter , 'include ' => df_csv ($ include )]))
41+ ->setParameterGet (df_clean ([
42+ 'filter ' => $ filter , 'include ' => df_csv ($ include ), 'page ' => ['size ' => -1 ]
43+ ]))
4244 ;
4345 $ raw = $ c ->request ()->getBody ();
4446 }
45- if (! $ raw ) {
46- $ res = $ c -> getLastResponse (); /** @var \Zend_Http_Response $res */
47+ $ res = $ c -> getLastResponse (); /** @var \Zend_Http_Response $res */
48+ if (! $ raw || $ res -> isError ()) {
4749 df_error ("The last Oro Web API request fails with the message « {$ res ->getMessage ()}». \n"
4850 ."The response headers: \n%s \n.The request: \n%s \n. "
4951 ,$ res ->getHeadersAsString (), $ c ->getLastRequest ()
0 commit comments