How to use Zend Cache with SimpleXML objects? - zend-framework

I'm trying to cache the user timeline of a Twitter feed using Zend_Service_Twitter which returns its results as a SimpleXML object. Unfortunately the regular serialize functions (which Zend Cache uses) don't play nice with SimpleXMl objects. I found this http://www.mail-archive.com/fw-general#lists.zend.com/msg18133.html.
So it looks like I'll need to create some kind of custom frontend for Zend Cache to be able to change the serialize function used. Anybody ever done this already or can point me where to look to start?

Instead of trying to cache the SimpleXML object, I chose to loop through Twitter posts returned and save that data as a string. I then save that string to the cache. Works for me!

Or you can call asXML() function:
$simpleXml = #simplexml_load_file($xml_url);
$cache->save($simpleXml->asXML(), 'name_of_cache');
Definition and Usage
The asXML() function returns the XML document, from a SimpleXMLElement
object, as a string.
This function returns FALSE on failure.

Related

What's the datatype of the value returned by octokit.createPullRequest() in octokit-plugin-create-pull-request?

I want to make a pull request from a react-native app. I am using the octokit-plugin-create-pull-request library from here. They have a function octokit.createPullRequest() in their documentation. I am at a point where I need to know the datatype of the value it returns. Is it an array or an object? Or is it another datatype?
It returns a pull request object, with the properties you see in the example response https://docs.github.com/en/rest/reference/pulls#create-a-pull-request.

Node.CloneNode() not a function -dom-to-image.js

I want to create a .png file of a HTML page in angularjs and download it. For this I'm currently using dom-to-image.js and using the domToImage.toBlob function and passing the node element to it. But internally when it goes to dom-to-image.js it throws the error:
node.cloneNode() is not a function
Can anyone please assist me here?
Thanks
This error arises when you attempt to call cloneNode() on anything other than a single DOM node.
In this case, the error is coming from the dom-to-image library, which calls that method internally.
Note that without a code snippet, its hard to identify the precise issue with your code, but the point is, when you call domtoimage.toBlob(), you need to supply a single DOM node.
So double check what you are calling it with. If you are selecting by class, for instance, you could end up with more than one element.
Its best practice to be precise with which node you want to convert to a blob - use the id attribute, like this:
domtoimage.toBlob(document.getElementById('element')).then(...)
where element is the id of your target node.
Its also possible you're selecting with angular.element() or even using jQuery directly.
In both cases, this returns an Object -- which you can't call cloneNode() on.
Also note the following from the Angular docs for angular.element():
Note: All element references in AngularJS are always wrapped with jQuery or jqLite (such as the element argument in a directive's compile / link function). They are never raw DOM references.
Which means you would observe the same behavior in both cases, e.g. both of these:
domtoimage.toBlob($('#element')).then(...)
domtoimage.toBlob(angular.element('#element')).then(...)
would result in the error you see. You can index the Object before supplying it to domtoimage.toBlob(), perhaps like this:
domtoimage.toBlob($('#element')[0]).then(...)
domtoimage.toBlob(angular.element('#element')[0]).then(...)
and that would also work.
Also check out this post about "cloneNode is not a function".

Can the Post for a ODataContoller in WebAPI 2 take an IEnumerable of a complex object

I want to know if passing a collection to the post of an ODataController is even possible before I waste my time trying to figure out where my problem is.
I've seen variations of this question over the internet, but nothing that has led me to an answer.
I created the Post method on an ODataContoller where I want to pass in a IEnumerable of a complex object. However, when I debug the controller, the parameter is null.
When I take each individual element of the collection and pass it into a Controller's Post (that takes a single object), the object is accepted. So I know the individual objects are being formatted correctly.
Technically this is possible. If you get null as complexObjects in the following call
[HttpPost]
public IHttpActionResult CreateMany([FromBody] IEnumerable<ComplexObject> complexObjects)
{
// ...
}
it's probably due to a format error in the bodies json object. If you have a working single object you can post, you just need to wrap it in brackets ... an array is an array even if it cotains only one element. This assumes, you check your web api actions via postman, fiddler etc., where you can 'compose' the entire request. Alternatively you can use the output of a 'GET all' action (if you have one) as input.
Regarding another aspect, the REST-fulness of list creation, you may find RESTful way to create multiple items in one request interesting
Hope this helps.

tastypie hydrate() not getting called

I am new to tastypie. I have a tastypie model resource where I want to use hydrate() to take serialized data from the client and turn it into a proper format that the data model can use. I have tried hydrate() hydrate_foo() but it seems all the hydrate() functions are not getting called, while dehydrate() will always get called. In my resource model, there're also obj_get(), obj_update(). Are there restrictions/constraints as to how the hydrate() function should be defined in the resource model so that I could use it to manipulate data submitted by the client?
I know this post is pretty old but, since documentation and examples on Tastypie are very limited, I'm adding my small experience here.
Without code it is hard to give a proper answer but I've seen that hydrate methods are only called if we explicitly call in the obj_create function the full_hydrate method as follows:
bundle = self.full_hydrate(bundle)
I thought they were automatically called by Tastypie but it seems not the case.

Issue with duplicate search results and XMLParser array refresh

I use an NSXMLParser to parse ext. API data. I also use a Singleton shared array var to maintain info retrieved from ext API.
This info is dynamic and changesas the user types anything in UISearchBar
Now the thing is as soon as the user types anything, I clear off the existing array contents by using [retrievedArray removeAllObjects];
Thus this refreshed retrievedArray based on the current terms in the search bar.
This works fine if the user types slowly. However I get to see duplicate search results if the user types very fast. This, I am assuming, is because the retrievedArray contents do not get enough time to clear off.
I am still trying to resolve the issue. Please suggest some more fixes.
Could you please provide me the fix.
No, I don't think this is the case, unless you're doing search in a separate thread and clear array in another one. If not, then there is probably error in your search logic.
First of all I think a singleton approach may not be the best way to go for what you are doing. But make sure that you are synchronizing all mutable access to the array. Instead of allowing the singleton to return a NSMutableArray for any object and their mom (super) to use you need to have methods like addObject,removeObject,clear with #synchronize blocks or any kind of lock you decide on. I still see issues with this approach because the code calling addObject, remove and clear will all need to be synchronized as well. Maybe consider on each auto complete request you use a delegate or post a NSNotification containing a timestamp, the characters the user typed to get data, and a NSArray of results. At that time you can see if the response is still valid, discard any invalid responses, and update the user with just the contents of the most recent valid NSArray