Tag: english

The new providers discovery for Zend_Tool 1.10

With the recent release of the 1.10 version of the  Zend Framework, they made a subtle change on how Zend_Tool searches its providers. Before 1.10 the loader (aka the provider discover) was set to be the IncludePathLoader class; what that meens is that if you wrote a new provider, all that you needed to do to have Zend_Tool automatically find it was to edit your PHP’s include_path or add your provider’s directory to the ZEND_TOOL_INCLUDE_PATH_PREPEND environment variable.

Now that is history, because (source):

There were many issues for people when Zend_Tool used a scanning approach to finding providers. This caused many issues on all different platforms. Now we’ve opted to go the specify your providers approach.

(beware: the suggested solution in that post is wrong)

So if you ever write a new tool provider remember that there’s no more “auto discovery” by scanning the path. The loader now is the BasicLoader and you have to explicitely tell Zend_Tool where your providers are and how their classes are named. For this to happen, you can use the zf enable config.provider command or use the zf.ini file.

My solution is:

  • create a zf.ini file for your project. This is slighlty different from what the documentation implies; it considers zf.ini to be an hidden file in your $HOME. But this is only a default you can change via the  ZF_CONFIG_FILE env variable
  • put something like basicloader.classes.0 = “Migrations_MigrationProvider” as the first line (that example is the actual class name of my migration tool provider)
  • assure that your class can be loaded, setting ZEND_TOOL_INCLUDE_PATH_PREPEND accordingly

On the same topic you can also read this issue.

As a bonus track, below is a little bash script I use to run my migration tool.

#!/bin/bash

APPPATH=$(readlink -f ..)/app

export ZF_CONFIG_FILE=${APPPATH}/../zf.ini

if [ ! -f ${ZF_CONFIG_FILE} ]; then
  echo "Non trovo zf.ini"
  echo "Forse non stai eseguendo questo programma dalla directory DB?"
  exit -1
fi

if [[ "${ZF_BIN_DIR}" == "" ]]; then
  ZF_BIN_DIR=$(readlink -f ../vendor/Zend)/../../bin
  ZF_BIN_DIR=$(readlink -f ${ZF_BIN_DIR})
fi

if [ ! -f ${ZF_BIN_DIR}/zf.sh ]; then
  echo "Non trovo zf.sh in " ${ZF_BIN_DIR}
  echo "Forse non stai eseguendo questo programma dalla directory DB?"
  exit -1
fi

MIGCLASSDIR=$(readlink -f ../vendor/Renomo/library)

if [ ! -d ${MIGCLASSDIR} ]; then
  echo "Impossibile trovare la directory della classe Migration"
  exit -1
fi

MIGDIR=$(readlink -f migrations)

if [ ! -d ${MIGDIR} ]; then
  echo "Impossibile trovare la directory delle migration"
  exit -1
fi

export ZEND_TOOL_INCLUDE_PATH_PREPEND=${MIGCLASSDIR}

${ZF_BIN_DIR}/zf.sh run migration ${1}

SVN customized bash prompt (and Git!)

I recently had to split an SVN repository of mine into a TRUNK and a TAGged branch. Nothing fancy: a tag to identify the REV1.x and the TRUNK to keep developing.

From time to time I have to svn switch, jumping from the tagged branch to the trunk (testing, merging, usual staff…). And you know what? I’m keeping committing on the tagged branch! And that is bad (more on this with an appropriate future post. I promise).

How beautiful could be having a bash prompt that will costantly display the branch I’m in and the svn repository revision of the current directory?

So, here we are:

append this code to your ~/.bashrc, logout/login and enter a svn managed directory (beware: I’ve tested it only on my Ubuntu box… the key here is to use the PROMPT_COMMAND env variabile, passing it the function that does the “sniffing”. The PROMPT_COMMAND command will be executed every time, just before displaying the shell prompt).

PROMPT_COMMAND=prompt_command

prompt_command() {

  if [[ -d ".svn" ]] ; then
    local info rev url ver
    info=$(LC_MESSAGES=C svn info 2>/dev/null)
    rev=$(echo "${info}" | awk '/^Revision: [0-9]+/{print $2}')
    url=$(echo "${info}" | awk '/^URL: .*/{print $2}')

    echo ${url} | grep -q "/trunk\b"
    if [[ $? -eq 0 ]] ; then
      ver=trunk
    else
      echo ${url} | grep -q "/tags\b"
      if [[ $? -eq 0 ]] ; then
        ver=tag-$(echo ${url} | grep -o "/tags.*" | awk -F/ '{print $3}')
      fi
    fi

    echo -e "\e[00;33m[svn:r${rev}@${ver}]\e[00m"
  fi

}

The svn information will be displayed in yellow (is the 33 in the final echo line). Change it at your liking.

UPDATE: Giovanni Bajo gives the hints for the "-q" switch and the LC_MESSAGES trick to avoid locale inconsistences.

Giovanni has gone a step forward, giving us the code for a git enhanced prompt too.

Here it is:

  local gitout
  gitout=$(git branch -v --abbrev --no-color 2>/dev/null)
  if [[ $? -eq 0 ]]; then
    local full branch sha1
    full=$(echo "${gitout}" | grep '^*')
    branch=$(echo "${full}" | awk '/^* \w+ \w+/{print $2}')
    sha1=$(echo "${full}" | awk '/^* \w+ \w+/{print $3}')
    echo -e "\e[00;33m[git:${sha1}@${branch}]\e[00m"
  fi

Thanks to Uqbar on Freenode IRC for the awk hints!

example:

claudioc@enebish:~/Sites$
claudioc@enebish:~/Sites$ cd scrive2/
[svn:r452@trunk]
claudioc@enebish:~/Sites/scrive2$ svn switch $myrepos/tags/R2.4
[svn:r431@tag-R2.4]
claudioc@enebish:~/Sites/scrive2$

I contenuti di questo sito sono distribuiti con una licenza Creative Commons 2.5 eccetto dove diversamente specificato.

Tema WordPress Punto5 sviluppato da Claudio Cicali; icone del set famfamfam silk e komodomedia.

© 2005-2010
Claudio Cicali