How can I keep just the required files in zend framework for my application? - zend-framework

I'm not sure where to ask this, but frankly I'm using some libraries from the zend framework but at this moment have the entire framework in my library folder. Is there any script or exe out there which go through the application and tell which files are not being used and which are. Theres loads of includes and easy loading going on there.

The files that are included via require_once in the Zend Framework code are mostly required only if they are used.
But if you want to be 100% sure that only the really used ones are loaded (on the fly), use the autoloader in combination with a script that strips all the require_once, as shown in the "Class Loading" part the official performance guide. There is a "How can I eliminate unnecessary require_once statements?" section. And this is a well know ZF optimisation technique, so it should be done anyway.

Related

Sailsjs disable a single js

Right now, I am using <%- assets.js() %> to include all the javascript files on all pages. So, it means all the functions will be initialized on all pages.
I am wondering how can I disable a javascript file on a specific web page? Or, if there is a way to include some of the javascript files on a specific web page but not all the javascript files.
The trouble with the auto-loading is that it's really hard to dictate the ordering of the source files in any meaningful way-- it really comes down to how you've structured the front-end.
In v0.8.x (the version you're working with, from what I can tell), you can use the config/assets.js to control the ordering of folders that get loaded in. This is not ideal, but is a decent workaround that my team used on several projects.
In v0.9, we've removed rigging/asset-rack in favor of tight integration Grunt, which has a large community and some really cool and well maintained packages for most types of asset bundling, etc.
In any case, here are the different approaches you can investigate for serving assets in the new version of Sails.js:
Treat it just like anything else
In your layout.ejs file, create <link /> and <script></script> tags to link in your css and javascript files like you would normally.
Use AMD (Require.JS)
I think lots of folks would say this is actually the best option. Require is a pretty powerful tool. And I'm mostly in agreement-- if you're working with front-end javascript that could be coming from anywhere, and is going to be extended by other developers who may be using a different framework, AMD is a great way to make sure you stay safe. If you're using Require, each js file is its own module, and declares its own dependencies, so asset dependency management becomes a thing of the past. Then in production mode, there are a couple of different options to compile and minify your CSS and JS. You can even dynamically load templates and CSS from JS with Require, which is pretty neat. AMD/RequireJS is a hands-down winner if you're interested in loading some or all of your assets asynchronously. It's also an all-client-side solution, which is pretty cool.
The only downside in my mind is the complexity. If you have control over the framework being used, you really shouldn't have to manually enter dependencies for each file-- it can figure that out itself (see https://github.com/balderdashy/mast/blob/2.x/lib/raise.js)
Use Grunt
When you make a new project with sails new foo in Sails v0.9, a file called Gruntfile.js is created. It has lots of stuff in it, a lot of which isn't being used by default. You can do almost anything with Grunt, but in particular, you'll want to look at how it's set up to copy files from assets/* to .tmp/public/.
sails new foo --linker (Sails v0.9 only)
Linker is a lot like what asset-rack/rigging does currently. It creates the same Gruntfile as #3 above, but utilizes more of the contents. It will auto-link files in the order you specify. Instead of view partials (e.g. <%= %>), the scriptlinker plugin allows you to customize the delimiters where js, css, and templates will be injected. By default, the Gruntfile is set up to use JST precompiled templates, but again, you can set it up however you like.
Hope that helps guys, and best of luck!
-Mike
PS- v0.9 is coming out very very soon, I've just been working through tests and issues to make sure we're 100% there. If you'd like to try it out, check out:
https://gist.github.com/mikermcneil/5930330
The lead for Sailsjs replied to this issue (though it was about selecting CSS files):
"For now, you can (a) bring in all styles all the time and make only the relevant ones apply (b) use another tool (like Grunt) to bundle assets like you would in a vanilla node.js project or (c) link the stylesheets manually (put them in your public folder)."
See: choosing assets sailsjs
Similar, more complex questions have been asked in the Google group:
https://groups.google.com/forum/#!topic/sailsjs/yt9EpJlfzXA
Considering the above, you may want to have a separate layout.ejs for each page. You can specify the layout.ejs you want for each page with
res.view({ layout: "different_layout" })
The layout.ejs would (a) not call assets.js() but have < script > for all the js files needed, or (b) call assets.js() to serve all the common js files in ./assets/js plus < script > to serve the page dependant ones residing elsewhere.
I have a wrapper around assets.js() that allows you to include all assets except for specified files. You can also use it to include only specific assets elsewhere. So you could load your common assets in layout and include other assets only on pages where they are required.
See my answer to How can I include javascript assets selectively in SailsJS?

Zend Framework and fuelphp

I wanted to know if it was possible to use zend framework libraries from zend 1.11 in fuelphp? fuel looks nice and I started looking at it as I believe its the next logical step for any CI developer.
Is there any site or a howto for using zend library with fuel?
Thanks
It really depends on what portions of Zend Framework you want to use. Some parts, e.g. Zend_View are tied into the MVC-part of the framework, but components like Zend_Pdf or Zend_Service_* have only few dependencies and should work fine in other frameworks as well.
What you should do is check out the Reference Manual to see what other components are required by the component you are trying to use. And then put them in a library folder. Alternatively, just put the whole Zend Framework in a folder if you don't mind carrying the dead weight with you.
I've been using ZF-components standalone and found that it's useful to add it to include_path as you would when using ZF as MVC-framework, because some ZF-classes are instantiated dynamically, i.e. not via require_once and that won't work without the folder containing Zend/ being in the include_path.
Finally you have to add the folder to your autoloader, this should be as easy as:
Autoloader::add_namespace('Zend', __DIR__.'/path/to/Zend/library');

Zend Framework contextually load stylesheets

Is it possible in Zend Framework to contextually autoload a stylesheet based on a unique identifier?
I'd like to load css based on the layout and the action name by first checking if the stylesheet exists then loading it.
Is that possible?
Yes it is possible and surprisingly simple to implement. I have just started trying this for myself in a small project I am working on.
See Andy Baird's blog on this, which also includes the code you need to get you started. He continues it in a second blog which takes the concept slightly further.
He uses the same technique for both CSS and javascript files, so you may want to try it with both too.

What do I put on php.ini for Zend Installation?

I have saved Zend to a folder on my hosting called httpdocs. From what I've read on other questions, I understand I'm now supposed to add something to the php.ini file, and I know it's supposed to look something like the line below. Is the .;c: standard or would it be different depending on my server? If so, how do I determine what I should have instead?
include_dir = .;c:\httpdocs\ZendGdata-1.11.2\library
Thanks in advance,
John
you are probably referring to the include path, which should be set so zend classes can be correctly loaded.
however i take the guess you are on an shared hosting enviornment where you cant do that.
you can. well you probably could it in htaccess but its unlikely.
you can however do this at runtime using the set_include_path functions
be sure not to loose your old include paths, specially "." which refers to the current directory.
however this is very well explained at zend framework manuals, please red the introduction
and also try to improve your accept rate.

How to prune Zend Framework?

I wouldn't use most of the classes from Zend Framework, that's why I'm looking for the thinnest possible ZF configuration.
Is there a better way of finding what I really need other than deleting the whole library/Zend folder, then putting back files based on the error messages that I receive?
I have not used it myself, but http://blog.fedecarg.com/2009/02/01/zend-framework-automatic-dependency-tracking/ may be what you are looking for.
Hm...
There is a lot of information about Zend Framework on SO and with a little bit of reading you would have found the answers to your question
You would also find the answers to your question by just reading the introduction to Zend Framework on the Zend Framework website.
No, that's not how you'll do it. Zend Framework, unlike most/all other PHP frameworks, is rigidly loosely coupled. You can use every component stand-alone. You can only use the loader, or only Zend_Translate. Or you can just use the MVC modules, or Zend_Db, etc.
Of course if you use Zend_Form and want to validate or filter the input, you'll need Zend_Validate and Zend_Filter. But you'll know that because you'll instantiate objects. So just copy into your empty library folder the modules you need. Or even better, copy everything in! A) you won't regret it. B) disk space is not your problem.
What I would do is set up the plugin loader cache and then purge all files apart from the ones called within the automatically generated include file.
zend.loader.pluginloader.performance
I hope it makes sense... :o)