Seva's notes

Wisdom, Awareness, Responsibility :)

Archive for the ‘zend framework’ Category

Zend Framework View Script Recursion

leave a comment »

We know that in Zend Framework View Scripts it’s possible  to run in a recursion using a View Helper – either Partial, or Action, or a custom one.

However all of these become a certain execution overhead in case we need just a simple one-time tree traversal. Also for readability purpose, it would be nice to have the recursion defined inline.

Luckily, since PHP 5.3 we can use self referencing closures to define the behavior within the script:


<?php
$showTree = function(array $entities) use(&$showTree) {?>
 <?if(!$entities) return?>
 <ul>
 <?foreach($entities as $entity):?>
 <li><?=$entity->getName()?></li>
 <?=$showTree($entity->getChildren())?>
 <?endforeach?>
 </ul>
<?}
?>
<?=$showTree($this->entities)?>

Written by Seva

2013-04-03 (April 3) at 11:37:04

Download a Google Document with Zend_GData API

with 3 comments

Today I’ve thought of a way of showing a private Google Document on a custom page with no need to authenticate. I was surprised that the issue was not covered in any documentation; I also didn’t succeed to find a quick solution on the Internet. Thus I’m sharing with you the solution using Zend_GData library, my dear friend, with hope to save your valuable time:

$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, Zend_Gdata_Docs::AUTH_SERVICE_NAME);
$api = new Zend_Gdata_Docs($client);
$doc = $api->getDocument($docId);
$client->setUri($doc->getContent()->getSrc());
$response = $client->request();
$html = $response->getBody();   

Voila! The $html variable now contains the clean and image/css/js safe content to use (including <HTML> tags)

Note: The code lacks exception handling for simplicity, so please keep that in mind and fulfill upon need.

Written by Seva

2010-02-01 (February 1) at 06:35:51

PHP Frameworks popularity estimation

with 2 comments

About 2.5 years passed since I posted the development activity comparison of major PHP frameworks. Since then I’ve got about 4.5k hits from search engines, which IMHO is not such a bad sample to summarize people’s interest in each of them.

Again, no conclusions – just pure numbers 🙂

http://tr.im/lnXq:

Query Hits Zend CakePHP Symfony CodeIgniter Prado Seagull eZ
zend framework vs cakephp 573 573 573 0 0 0 0 0
zend vs cakephp 319 319 319 0 0 0 0 0
cakephp symfony 258 0 258 258 0 0 0 0
zend vs symfony 254 254 0 254 0 0 0 0
cakephp vs zend framework 217 217 217 0 0 0 0 0
symfony vs zend 210 210 0 210 0 0 0 0
zend framework vs symfony 187 187 0 187 0 0 0 0
symfony vs cakephp 185 0 185 185 0 0 0 0
zend framework vs 176 176 0 0 0 0 0 0
codeigniter vs zend framework 143 143 0 0 143 0 0 0
prado framework 139 0 0 0 0 139 0 0
cakephp vs zend 139 139 139 0 0 0 0 0
symfony vs zend framework 138 138 0 138 0 0 0 0
zend framework cakephp 131 131 131 0 0 0 0 0
prado vs zend 103 103 0 0 0 103 0 0
zend framework vs codeigniter 84 84 0 0 84 0 0 0
cakephp vs symfony 82 0 82 82 0 0 0 0
prado vs cakephp 81 0 81 0 0 81 0 0
prado vs symfony 80 0 0 80 0 80 0 0
zend vs codeigniter 76 76 0 0 76 0 0 0
zend or cakephp 69 69 69 0 0 0 0 0
codeigniter vs cakephp 68 0 68 0 68 0 0 0
codeigniter vs zend 62 62 0 0 62 0 0 0
zend vs code igniter 60 60 0 0 60 0 0 0
cakephp zend framework 59 59 59 0 0 0 0 0
codeigniter vs symfony 55 0 0 55 55 0 0 0
cakephp symfony zend 52 52 52 52 0 0 0 0
cakephp vs prado 50 0 50 0 0 50 0 0
symfony zend framework 48 48 0 48 0 0 0 0
cakephp vs codeigniter 48 0 48 0 48 0 0 0
zend framework vs code igniter 46 46 0 0 46 0 0 0
zend framework vs. cakephp 46 46 46 0 0 0 0 0
symfony vs codeigniter 45 0 0 45 45 0 0 0
symfony vs prado 39 0 0 39 0 39 0 0
zend vs prado 37 37 0 0 0 37 0 0
zend cakephp 37 37 37 0 0 0 0 0
zend framework symfony 36 36 0 36 0 0 0 0
zend framework or cakephp 35 35 35 0 0 0 0 0
prado symfony 35 0 0 35 0 35 0 0
seagull vs cakephp 34 0 34 0 0 0 34 0
zend framework versus cakephp 32 32 32 0 0 0 0 0
Total 4568 3369 2515 1704 687 564 34 0
Interest Ratio
73.75% 55.06% 37.30% 15.04% 12.35% 0.74% 0.00%

Written by Seva

2009-05-15 (May 15) at 01:33:24

Zend Porn

leave a comment »

And afterall – guess what would be the first Google result for zend porn 🙂

Written by Seva

2008-04-30 (April 30) at 12:09:55

Posted in leisure, zend framework

Web 2.0 Porn Sites run Zend Framework

with 2 comments

I never mentioned here, but in my pre-previous developer’s life I was working in a small adult internet company. Right now one of my collegues called me on IM to ask a question about an error he suddenly got fro one of the sites he affiliates to. This is the error:

Fatal error: Uncaught exception ‘Zend_Db_Adapter_Exception’ with message ‘SQLSTATE[00000] [1040] Too many connections’ in /www/zt/root/library/Zend/Db/Adapter/Pdo/Abstract.php:129

Stack trace:

#0 /www/zt/root/library/Zend/Db/Adapter/Abstract.php(216): Zend_Db_Adapter_Pdo_Abstract->_connect()

#1 /www/zt/root/library/Zend/Db/Adapter/Pdo/Abstract.php(204): Zend_Db_Adapter_Abstract->query(‘????SELECT?????…’, Array)

#2 /www/zt/root/mvc/models/User.php(490): Zend_Db_Adapter_Pdo_Abstract->query(‘????SELECT?????…’)

#3 /www/zt/root/mvc/models/User.php(91): User->attachVideosByIp()

#4 /www/zt/root/bootstrap.php(35): User->__construct()

#5 /www/zt/root/index.php(7): require(‘/www/zt/root/bo…’)

#6 {main}

thrown in /www/zt/root/library/Zend/Db/Adapter/Pdo/Abstract.php on line 129

Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0

BTW, the site (it was Zoo Tube) is not really bad (according to Google cache) and even seems to be a clone of another Web 2.0 porn site – Red Tube, which makes me think ZF is really becomes a trend in real world and and real money projects. Isn’t it amazing?

Written by Seva

2008-04-26 (April 26) at 02:29:10

Grouped Completion (Content Assist) in PDT

with 2 comments

Last Wednesday I was working on grouping of code completion (content assist) options. It’s now only exists in CVS and will be (hopefully) released with the build after the next one (the current is already finalized).

Overview

The main point of the feature is collapsing of multiple same-prefixed options into groups, instead of showing a long list of the options. For example if your application is based on Zend Framework or PEAR, most of library’s classes start with “Zend_” or “PEAR_”, and this is what you will get as a completion option. In addition, the grouped list doesn’t show common prefix if an user already typed it.

(Demo)

In general it’s applied to all the types of elements (classes, functions/methods, variables and constants) in all the possible contexts (general completion, doc blocks, new/instanceof etc.). The feature is disabled by default can can be found at:
Preferences->PHP->Editor->Code Assist->Group Completion Options

The logic of the grouping is very similar to completion of files in include statements in Zend Neon and is quite simple:

  1. If there are several options which share common prefix AND there are additional elements which do NOT have this prefix, the sibling elements are collapsed to groups with “…” suffix.
  2. After completion of a group, completion pops up immediately again to show elements with the typed prefix.
  3. If typed prefix has common prefix with proposed elements/groups, it’s collapsed with “…” prefix.

How it works

First, all the types of code completion options are created by objects which extend an abstract CompletionProposalGroup (View Source). The class’ work is to receive an array of CodeData‘s and return an array of ICompletionOption‘s. This is why the feature’s code is mostly aggregated in this class.
So, instead of just creating a completion option for each element, we should first create a tree of all elements, based on elements’ name chunks separated by “_”, then go over the tree and extract only the relevant elements and groups, and then create chopped completion options for groups and elements. And now in details –

Creating Tree of Elements

CompletionProposalGroup.buildCompletionTree()

Luckily, Eclipse platform provides two base components which made the implementation relatively simple. It’s IPath/Path couple, which provide a comfortable solution for handling abstract OS-like paths, and ElementTree, which is a recursive tree data structure which gives access to it’s nodes based on IPaths.
The first action item here is to create a path from element’s name – it’s done by replacing all delimiters with slashes and providing the result string to Path‘s constructor. Then it’s time to recursively create the element – if the parent path is not in the tree, we’ll add it with null data attached (these nodes will represent element groups in the future). After the parents exist, we are adding the element itself to the tree with CodeData object attached.

Extracting relevant Elements and Groups

CompletionProposalGroup.treeRecursiveCreateElement()

In order to get the relevant elements and groups according to 3 rules mentioned above, we basically need to recursively get children of a tree node starting from the root. However if there are no children for current node or the node has sibling(s) – we don’t want to continue deeper inside, and just return the current node. As a result, we get list of elements and collapsed groups to create completion proposals from.

Creating Elements and Groups Completion

CompletionProposalGroup.calcCompletionProposals()

Afterwards, the only remaining thing is to create proposals. For element proposals there is a wrapper proxy PartialProposal for CodeDataCompletionProposal which cuts off matching segments of prefix, and for groups – there is a wrapper proxy TemporaryCompletionProposal for CompletionProposal created with cut prefixes,  which only ovverrides ICompletionProposal.apply() method to reactivate completion immediately group application.

That’s all it’s about.

Written by Seva

2007-11-25 (November 25) at 06:52:43

Zend Framework vs. CakePHP, Symfony, Seagull, WACT, Prado, TRAX, eZ and CodeIgniter

with 19 comments

In contraversal with what it might seem, I won’t compare features of the mentioned projects. For that purpose you may just read this nice article by Dennis Pallett.

Instead, I will share you what I learned with help of [in]famous Ohloh project – the codebase, activity and participants dynamics comparison of the mentioned projects.

Well, I’ll not make any conclusions – just observe the facts.

Codebase:
(lines of code)


  Zend Framework   CakePHP   Symfony


  Zend Framework   Seagull   WACT


  Zend Framework   PRADO   TRAX


  Zend Framework   eZ   CodeIgniter

Activity:
(commits)

  Zend Framework   CakePHP   Symfony


  Zend Framework   Seagull   WACT


  Zend Framework   PRADO   TRAX


  Zend Framework   eZ   CodeIgniter

Participants:
(active committers)


  Zend Framework   CakePHP   Symfony


  Zend Framework   Seagull   WACT

  Zend Framework   PRADO   TRAX


  Zend Framework   eZ   CodeIgniter

Enjoy.

Written by Seva

2007-11-13 (November 13) at 01:38:51