I want to change the below object serialize values for 'secret_key' and 'public_key' and then i have to unserialize again.
What is the best way to modify (without string replace option)?
__PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => RulesReactionRule
[*parent] =>
[id] => 51
[*elementId] => 1
[weight] => 0
[settings] => Array
(
)
[name] => commerce_payment_commerce_stripe
[label] => Stripe
[plugin] => reaction rule
[active] => 1
[status] => 3
[dirty] =>
[module] => commerce_payment
[owner] => rules
[access_exposed] => 0
[data] => __PHP_Incomplete_Class Object
*RECURSION*
[tags] => Array
(
[0] => Commerce Payment
)
[*children] => Array
(
[0] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => RulesAction
[*parent] => __PHP_Incomplete_Class Object
*RECURSION*
[id] =>
[*elementId] => 3
[weight] => 0
[settings] => Array
(
[commerce_order:select] => commerce-order
[payment_method] => Array
(
[method_id] => commerce_stripe
[settings] => Array
(
[stripe_currency] => USD
[secret_key] => sk_test_CCVVVVCC
[public_key] => pk_test_SDFFEFEF
[display_title] => Stripe
[cardonfile] => 1
[txn_type] => authorize
)
)
)
[*elementName] => commerce_payment_enable_commerce_stripe
)
)
[*info] => Array
(
)
[*conditions] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => RulesAnd
[*parent] => __PHP_Incomplete_Class Object
*RECURSION*
[id] =>
[*elementId] => 2
[weight] => 0
[settings] => Array
(
)
[*children] => Array
(
)
[*info] => Array
(
)
[*negate] =>
)
[*events] => Array
(
[0] => commerce_payment_methods
)
[*eventSettings] => Array
(
)
)
Related
I am working on Facebook leads API and successfully getting response for my lead
use FacebookAds\Object\Lead;
$form = new Lead('LEAD_ID');
$re = $form->read();
echo '<pre>';
print_r($re);
and the response is in following format :
FacebookAds\Object\Lead Object
(
[changedFields:protected] => Array
(
)
[api:protected] => FacebookAds\Api Object
(
[session:FacebookAds\Api:private] => FacebookAds\Session Object
(
[appId:protected] => 448283968712152
[appSecret:protected] => 0cf8998603f3050f9d80ded4cecdb7f7
[accessToken:protected] => EAAGXtj62rdgBAP0ZCjmnddu3ZBIgZAECUluzPL6CGUuZB07tPUlERk4L1iRb2gy31qlUx2ExBENZBegpvfHxmxsJYks8rghrKOZBHMWEblEgsIvo5GF3ySzbyVszg7lbYIuBSgeFdzAMq6GuW6iZCQrgXd4KfAVoiQZD
[appSecretProof:protected] => c6112ce522414623dea1fb41cc29f6f15ca480845b8490d7c45ec67a485fa3f6
)
[logger:protected] => FacebookAds\Logger\NullLogger Object
(
)
[httpClient:protected] => FacebookAds\Http\Client Object
(
[requestPrototype:protected] => FacebookAds\Http\Request Object
(
[client:protected] => FacebookAds\Http\Client Object
*RECURSION*
[headers:protected] =>
[method:protected] => GET
[protocol:protected] => https://
[domain:protected] =>
[path:protected] =>
[graphVersion:protected] =>
[queryParams:protected] =>
[bodyParams:protected] =>
[fileParams:protected] =>
)
[responsePrototype:protected] => FacebookAds\Http\Response Object
(
[request:protected] =>
[statusCode:protected] =>
[headers:protected] =>
[body:protected] =>
[content:protected] =>
)
[defaultRequestHeaders:protected] => FacebookAds\Http\Headers Object
(
[storage:ArrayObject:private] => Array
(
[User-Agent] => fb-php-ads-2.5.1
[Accept-Encoding] => *
)
)
[adapter:protected] => FacebookAds\Http\Adapter\CurlAdapter Object
(
[curl:protected] => FacebookAds\Http\Adapter\Curl\Curl Object
(
[handle:protected] => Resource id #34
)
[opts:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[78] => 10
[13] => 60
[19913] => 1
[42] => 1
[10065] => /home/leadsgeneration/public_html/v1/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/../../../fb_ca_chain_bundle.crt
)
)
[client:protected] => FacebookAds\Http\Client Object
*RECURSION*
)
[caBundlePath:protected] => /home/leadsgeneration/public_html/v1/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/../../../fb_ca_chain_bundle.crt
[defaultGraphBaseDomain:protected] => facebook.com
)
[defaultGraphVersion:protected] => 2.5
)
[parentId:protected] =>
[data:protected] => Array
(
[ad_id] =>
[adset_id] =>
[campaign_id] =>
[created_time] => 2016-04-18T04:17:55+0000
[field_data] => Array
(
[0] => Array
(
[name] => email
[values] => Array
(
[0] => varunroute69#gmail.com
)
)
[1] => Array
(
[name] => phone_number
[values] => Array
(
[0] => +919731688688
)
)
[2] => Array
(
[name] => full_name
[values] => Array
(
[0] => Varun Majety
)
)
)
[form_id] =>
[id] => 571052196402628
[post] =>
)
)
I want to store [data:protected][field_data] in database so i want to read this array but when i try to echo like echo '-->'.$re['FacebookAds\Object\Lead Object']['data:protected'][field_data][0]['name']; it throws me an error.
How to read the above format?Any help would be greatly appreciated.
$form = new \FacebookAds\Object\Lead('LEAD_ID');
$form->read();
echo '<pre>';
print_r($form->getData());
Will give you
Array
(
[ad_id] =>
[ad_name] =>
[adset_id] =>
[adset_name] =>
[campaign_id] =>
[campaign_name] =>
[created_time] => 2016-09-18T06:57:13+0000
[custom_disclaimer_responses] =>
[field_data] => Array
(
[0] => Array
(
[name] => full_name
[values] => Array
(
[0] =>
)
)
[1] => Array
(
[name] => email
[values] => Array
(
[0] => test#fb.com
)
)
[2] => Array
(
[name] => phone_number
[values] => Array
(
[0] =>
)
)
)
[form_id] =>
[id] => 1681384948848301
[is_organic] =>
[post] =>
)
I got array value from API.
model\Quote Object
(
[quote_reference:protected] => 12345
[proposals:protected] => model\Proposals Object
(
[proposal:protected] => Array
(
[0] => model\Proposal Object
(
[id:protected] => prp_3453453453sdfsd
[fees_included:protected] => 1
[charged_amount:protected] => model\Amount Object
(
[currency:protected] => USD
[amount:protected] => 105.00
)
[credited_amount:protected] => model\Amount Object
(
[currency:protected] => MAD
[amount:protected] => 1000.00
)
[principal_amount:protected] => model\Amount Object
(
[currency:protected] => USD
[amount:protected] => 100.00
)
[expiration_date:protected] => DateTime Object
(
[date] => 2016-04-07 02:12:55.682000
[timezone_type] => 1
[timezone] => -05:00
)
[destination_service_tag:protected] =>
[corridor_tag:protected] =>
[resource_type:protected] => proposal
[additional_data_list:protected] => model\AdditionalDataList Object
(
[data:protected] => model\Data Object
(
[data_field:protected] => Array
(
[0] => model\DataField Object
(
[name:protected] => 811
[value:protected] => 123
)
[1] => model\DataField Object
(
[name:protected] => 851
[value:protected] => 456
)
)
)
[item_count:protected] => 2
[resource_type:protected] => list
)
[wholesale_fx_rate:protected] =>
)
[1] => model\Proposal Object
(
[id:protected] => prp_456sgdfgsdfg [fees_included:protected] => 1
[charged_amount:protected] => model\Amount Object
(
[currency:protected] => USD
[amount:protected] => 100.00
)
[credited_amount:protected] => model\Amount Object
(
[currency:protected] => MAD
[amount:protected] => 950.00
)
[principal_amount:protected] => model\Amount Object
(
[currency:protected] => USD
[amount:protected] => 100.00
)
[expiration_date:protected] => DateTime Object
(
[date] => 2016-04-07 02:22:55.682000
[timezone_type] => 1
[timezone] => -05:00
)
[destination_service_tag:protected] =>
[corridor_tag:protected] =>
[resource_type:protected] => proposal
[additional_data_list:protected] => model\AdditionalDataList Object
(
[data:protected] => model\Data Object
(
[data_field:protected] => Array
(
[0] => model\DataField Object
(
[name:protected] => 811
[value:protected] => 123
)
[1] => model\DataField Object
(
[name:protected] => 851
[value:protected] => 456
)
)
)
[item_count:protected] => 2
[resource_type:protected] => list
)
[wholesale_fx_rate:protected] =>
)
)
)
)
I need to access both proposal array values at 0 and 1 index position.
I Tried:
$arrayobject->proposals->proposal[0];
Getting error:
Fatal error: Cannot access protected property model\Quote::$proposal
Any idea or help would be appreciated.
Thanks!
Actually I am Using the stripe checkout system and after the successful payment I have to store the information in the database..But I am facing the issue that is protected fields.
Stripe_Customer Object
(
[_apiKey:protected] => ------------------
[_values:protected] => Array
(
[id] => cus_58BUXTsLUEyImY
[object] => customer
[created] => 1415775664
[livemode] =>
[description] =>
[email] => basic#basic.com
[delinquent] =>
[metadata] => Stripe_AttachedObject Object
(
[_apiKey:protected] => -----------------
[_values:protected] => Array
(
)
[_unsavedValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_transientValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_retrieveOptions:protected] => Array
(
)
)
[subscriptions] => Stripe_List Object
(
[_apiKey:protected] => -------------------
[_values:protected] => Array
(
[object] => list
[total_count] => 1
[has_more] =>
[url] => /v1/customers/cus_58BUXTsLUEyImY/subscriptions
[data] => Array
(
[0] => Stripe_Subscription Object
(
[_apiKey:protected] => ----------------------
[_values:protected] => Array
(
[id] => sub_58BUHhWam3SGYw
[plan] => Stripe_Plan Object
(
[_apiKey:protected] => ------------
[_values:protected] => Array
(
[id] => gold
[interval] => year
[name] => yearly
[created] => 1415687816
[amount] => 34999
[currency] => usd
[object] => plan
[livemode] =>
[interval_count] => 1
[trial_period_days] =>
[metadata] => Stripe_AttachedObject Object
(
[_apiKey:protected] => ------------------------
[_values:protected] => Array
(
)
[_unsavedValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_transientValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_retrieveOptions:protected] => Array
(
)
)
First I have used like this: $obj->_values but nothing happened, blank return I get. After that I have covert the object into array. Then it has been converted in array. And got the response like this
Array
(
[*_apiKey] => --------
[*_values] => Array
(
[id] => cus_58CD1hhGW454545
[object] => customer
[created] => 1415778371
[livemode] =>
[description] =>
[email] => basic#basic.com
[delinquent] =>
[metadata] => Stripe_AttachedObject Object
(
[_apiKey:protected] => -----------------
[_values:protected] => Array
(
)
[_unsavedValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_transientValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_retrieveOptions:protected] => Array
(
)
)
[subscriptions] => Stripe_List Object
(
[_apiKey:protected] => s---------------
[_values:protected] => Array
(
[object] => list
[total_count] => 1
[has_more] =>
[url] => /v1/customers/cus_58CD1hhGWeX0OA/subscriptions
[data] => Array
(
[0] => Stripe_Subscription Object
(
[_apiKey:protected] => --------------------
[_values:protected] => Array
(
Now when I tried to use the [*_values] index I got he error that is undefined index. After that I have used the foreach() to access the next index then got the response.
Array
(
[id] => cus_58CD1hhGWeX0OA
[object] => customer
[created] => 1415778371
[livemode] =>
[description] =>
[email] => basic#basic.com
[delinquent] =>
[metadata] => Stripe_AttachedObject Object
(
[_apiKey:protected] => s--------------------
[_values:protected] => Array
(
)
[_unsavedValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_transientValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_retrieveOptions:protected] => Array
(
)
)
Now I have tried to access the field normally we use. like $variable['id']; then I got the error Illegal string offset 'id' ....Now please let me know How can I use these indexes .....and I also have to fetch the below indexes which are in multidimensional array.
As far as I know the Stripe objects have a megic getter method. try to use the __get("key") method to retrieve the protected values.
Check out the Stripe source to see the magic getters and setters.
I have this array:
stdClass Object
(
[tid] => 26001835
[vid] => 5
[name] => AppleTV
[description] => My description
[format] => filtered_html
[weight] => 0
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608990
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => Apple-TV.png
[uri] => public://Apple-TV.png
[filemime] => image/png
[filesize] => 2103
[status] => 1
[timestamp] => 1405346182
)
)
)
[field_buy_now_button_link] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://www.something.com
[format] =>
[safe_value] => http://www.something.com
)
)
)
[field_learn_more] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://something.com/somepage
[format] =>
[safe_value] => http://something.com/somepage
)
)
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => network
)
)
)
)
stdClass Object
(
[tid] => 26001834
[vid] => 5
[name] => Playstation - USA
[description] => My description
[format] => filtered_html
[weight] => 2
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608991
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => ps4network.png
[uri] => public://ps4network.png
[filemime] => image/png
[filesize] => 4566
[status] => 1
[timestamp] => 1405346218
)
)
)
[field_buy_now_button_link] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://www.somesite.com
[format] =>
[safe_value] => http://somesite.com
)
)
)
[field_learn_more] => Array
(
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => blast_areas
)
)
)
)
stdClass Object
(
[tid] => 26001836
[vid] => 5
[name] => Brighthouse Networks
[description] => My description
[format] => filtered_html
[weight] => 3
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608993
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => brighthouse.png
[uri] => public://brighthouse.png
[filemime] => image/png
[filesize] => 8392
[status] => 1
[timestamp] => 1405358781
)
)
)
[field_buy_now_button_link] => Array
(
)
[field_learn_more] => Array
(
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => ppv_provider
)
)
)
)
I want to sort the array by the array by the value in field_device_category. Basically, I want to group the results but first I need to make sure all the objects are sorted by field_device_category.
Thanks in advance!
Use usort for this kind of sorting. It uses Quicksort in the background and takes a user-defined function to compare the array elements:
usort($array, "complicatedArrayComparer");
function complicatedArrayComparer($a,$b)
{
if ($a['field_device_category'] == $b['field_device_category']) {
return 0;
}
return ($a['field_device_category'] < $b['field_device_category']) ? -1 : 1;
}
I am trying to access data inside a php object. I am confused about what the exact stynax is. Here is the output of the object:
stdClass Object ( [vid] => 10 [uid] => 1 [title] => Beachhead Don [log] =>
[status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [ds_switch] => [nid] =>
10 [type] => product [language] => und [created] => 1357668665 [changed] => 1358198386
[tnid] => 0 [translate] => 0 [revision_timestamp] => 1358198386 [revision_uid] => 1
[model] => B 3000 [list_price] => 0.00000 [cost] => 0.00000 [sell_price] => 1.00000
[weight] => 0 [weight_units] => lb [length] => 0 [width] => 0 [height] => 0
[length_units] => in [pkg_qty] => 1 [default_qty] => 1 [unique_hash] =>
2eec0fcc8483f3a3541870fb24223296 [ordering] => 0 [shippable] => 0 [price] => 1.00000
[body] => Array ( [und] => Array ( [0] => Array ( [value] => Description info
))))))))))))))))))))))))))))))))))))))0 [summary] => [format] => filtered_html
[safe_value] =>Description info ))))))))))))))))))))))))))))))))))))))0[safe_summary]
=> ) ) ) [uc_product_image] => Array ( [und] => Array ( [0] => Array ( [fid] => 11
[alt] => [title] => [width] => 90 [height] => 120 [uid] => 1 [filename] =>
beachhead_don.jpg [uri] => public://beachhead_don.jpg [filemime] => image/jpeg
[filesize] => 14342 [status] => 1 [timestamp] => 1357668665 [rdf_mapping] => Array ( )
) ) ) [field_author] => Array ( [und] => Array ( [0] => Array ( [value] => John B.
Romesier [format] => [safe_value] => John B. Romesier ) ) ) [field_publisher] => Array
( [und] => Array ( [0] => Array ( [value] => Unknown [format] => [safe_value] =>
Unknown ) ) ) [field_release_date] => Array ( [und] => Array ( [0] => Array ( [value]
=> Mar 2012 [format] => [safe_value] => Mar 2012 ) ) ) [field_number_of_pages] => Array
( [und] => Array ( [0] => Array ( [value] => 123 ) ) ) [field_catagory] => Array (
[und] => Array ( [0] => Array ( [tid] => 4 ) ) ) [field_book_type] => Array ( [und] => Array ( [0] => Array ( [tid] => 1 ) ) ) [field_isbn] => Array ( ) [field_about_the_author] => Array ( [und] => Array ( [0] => Array ( [value] => Beachhed Don authoer............................ [format] => [safe_value] => Beachhed Don authoer............................ ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1357668665 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => admin [picture] => 0 [data] => b:0; [entity_view_prepared] => 1 )
I am trying to retrive the [value] of Description info ))))))))))))))))))))))))))))))))))))))0
I tried this
<?php
$node = menu_get_object(); //drupal code
if ( !empty($node) ) {
print $node ->body=>und=>0=>value;
}?>
and got an error about the '=' sign. What is the proper way to get my data?
[body] and [und] are arrays, so access them like this:
echo $node->body['und'][0]['value'];
It should be:
$node->body['und'][0]['value']
'Body' and 'und' are Arrays and need to be accessed with array syntax([]).
Accessing these values directly is sometimes frowned upon in drupal. You may want to look into: http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render/7