Posts Tagged PHP

Getting started with zfc-user-doctrine-orm

zfc-user-doctrine-orm Is a Zend Framework 2 Module that enables Doctrine 2 support for the ZfcUser module.

Basic Setup

Installation via composer:

composer require "zf-commons/zfc-user-doctrine-orm:0.1.*"

An appropriate version of ZfcUser should be pulled in during installation.

Configuration Setup

  • Copy vendor/zf-commons/zfcuser.global.php.dist to config/autoload/zfcuser.global.php
  • Edit your application.config.php to include
    modules => array('ZfcBase',
            'ZfcUser',
            'ZfcUserDoctrineORM')

You don’t have to edit zfcuser.global.php – the default values will work fine, and zfc-user-doctrine-orm will inject itself such that you don’t even have to edit the zend_db_adapter (as I initially thought you would).

Custom User Entity

If you wish to use a custom user entity definition (too add additional fields, for example).

To do this, modify your zfcuser.gloabl.php to include the following configuration values:

'zfcuser' => array(
     'UserEntityClass' => '\UserEntityNamespace\UserEntityClass',
     'EnableDefaultEntities' => false
),

, , , ,

No Comments

Reset Zend Server password on OpenShift

If you are using the Zend Zerver Installation on the OpenShift cloud and happen to forget your password, you may find yourself wondering where gui_passwrd.sh is located.

When you ssh into your openshift gear, you find that the zend/bin folder does not include the gui_passwrd.sh script. This is because this folder stores the openshift scripts to install / maintain / remove the zend server itself. The Zend Server’s bin folder is located at zend/usr/local/zend/bin

#To Change your password, login to your openshift instance and enter the following command
zend/usr/local/zend/bin/gui_passwd.sh

Alternatively, use the new configuration utility, as gui_passwd.sh is deprecated:

zend/usr/local/zend/bin/zs-setup set-password <password>

, , , ,

No Comments

Hack WordPress Version Number

Recently when developing a plugin that examines available updates for WordPress, I needed to test situations where the WordPress Core is out of date.

Rather than going and installing an old version of WordPress, its much easier to simply modify the internal version number to an older version.

Head over to wp-includes/version.php and modify the $wp_version variable.

, , ,

No Comments

End a Request with a Zend Framework 2 Controller Plugin

By default, Zend Framework 2 (ZF2) controller plugins cannot force the request to end. Typically, the controller action calls plugin methods and then does what it wishes with the returned value. However, there are some circumstances (such as user authentication), where you may want to end the request if certain conditions are met in the controller plugin.

For example:
Say you want to return the currently authenticated user using a controller plugin, and if there is no authenticated user, return a 401 status code. When your controller calls the plugin, you would have to check the return value every time and have boilerplate code to set the status code in the response and return the response from your controller action.

There is a better way:
Instead of having to check in your controller, wouldn’t it be better if you could just have the Plugin do the work: set the status code and return the response to the client?

This class makes that possible. By emitting MvcEvent:EVENT_FINISH, it triggers the listeners to send the response to the client. By immediately exiting the application and ending the request, we ensure that MvcEvent:EVENT_FINISH is emitted only once.

/**
 * Plugins interiting from this superclass will be able to terminate the request by calling sendResponse()
 *
 * Class RequestTerminationPlugin
 * @package Application\Controller\Plugin
 */
abstract class SendResponsePlugin extends AbstractPlugin
{
 
    /**
     * @var MvcEvent
     */
    private $event;
 
 
    /**
     * Sends the response and terminates.
     * @param ResponseInterface $response
     */
    protected function sendResponse(ResponseInterface $response)
    {
        $e = $this->getEvent();
        $e->setResponse($response);
 
        $e->getApplication()->getEventManager()->trigger(MvcEvent::EVENT_FINISH, $e);
        exit();
    }
 
 
    /**
     * Get the event
     *
     * @return MvcEvent
     * @throws DomainException if unable to find event
     */
    protected function getEvent()
    {
        if ($this->event) {
            return $this->event;
        }
 
        $controller = $this->getController();
        if (!$controller instanceof InjectApplicationEventInterface) {
            throw new DomainException(get_class($this) . ' requires a controller that implements InjectApplicationEventInterface');
        }
 
        $event = $controller->getEvent();
        if (!$event instanceof MvcEvent) {
            $params = $event->getParams();
            $event  = new MvcEvent();
            $event->setParams($params);
        }
        $this->event = $event;
 
        return $this->event;
    }
 
}

, , , ,

No Comments

Doctrine And ORM Designer

Edit: Shortly after positing this entry, Inventic contacted me with some responses. These are in italics.

I’ve been using Doctrine in conjunction with the Zend Framework for years. Although it is an excellent ORM, writing yaml by hand is a tedious and error-prone process. Furthermore, it can be difficult to visualize a large database from a series of text files, so I find myself maintaining a MySQL Workbench diagram in addition to the textual database representation.

ORM Designer promises to change all that. It brings a visual database editor for Doctrine 1 and 2 that reduces effort, mistakes and increases productivity. Migration from my existing workflow was a snap due to the import functionality: I had the option to import both my yaml database definitions as well as my MySQL workbench files. The ability to break up the data-model into individual modules keeps the code clean and organized, and the export functionality, in conjunction to the external tools integrate yaml generation and Doctrine CLI operations directly into ORM Designer’s interface.

ORM Designer Features for Doctrine Users:

  • Behaviour Support
    • Versionable
    • Timestampable
    • Sluggable
    • I18n
    • NestedSet
    • Searchable
    • Geographical
    • SoftDelete
    • EventLoggable
    • GoogleI18n
    • Sortable
    • Blameable
    • Taggable
  • Inheritance Support
  • Many-to-one, Many-to-many relations
  • Index support
  • yaml Generation

Extendability:

  • Creation of new ORM Properties & data-types
  • Creation of new behaviours

Support and Releases

The folks at Inventic crank out a new version of ORM Designer every few months. There were around 16 releases in 2010, but development seems to have slowed slightly with only three releases to date in 2011. On the whole, with both bug fixes and feature updates, you can still expect good value for the 1 year upgrade maintenance that is included in the purchase price.
ORM Designer is currently very stable and as such doesn’t require many bug fixes. The team is currently putting most of their energy into ORM Designer 2 which is slated for a public beta around the end of 2011. However, there are 1.x beta releases available at http://www.orm-designer.com/beta which contain new features and bug fixes as they become available.

The forums are a little thin, which may be simply because the software is relatively new and is still being discovered. However, it appears that user posts commonly receive a same-day reply from the developers. Users can really take advantage of the small community and direct access to developers to suggest features and shape future directions of the software.

My Wish List

Although ORM Designer supports modules I would like to see this area further developed. For example:

Say you have a common user module stored in a common SVN location (Eg: SVN External) that you would like to use with every project, the ability to link the common module, add relations / properties (without affecting the original module) and export the module relative to the current project’s path would be excellent additions to ORM Designer’s feature set.
Inventic suggests pulling in modules directly into the application (at the appropriate path) using SVN Externals rather than having a more libary-like directory structure

Conclusion

ORM Designer provides excellent value for anyone who uses either Doctrine or Propel. The ability to visually edit data models for these ORMs brings them on par with the nHibernate framework in terms of usability.

ORM Designer also supports the Doctrine2 and Propel ORM’s as well as the CakePHP and Symfony frameworks.

ORM Designer is designed for windows, however it can run under WINE for Linux/OSX support. However, ORM Designer 2 is currently under development and makes use of QT rather than MFC which will bring native support to the other operating systems.

, , , ,

No Comments