2006-05-30 12:42:10 +04:00
|
|
|
<?php
|
2006-12-29 17:01:31 +03:00
|
|
|
/*
|
2006-07-27 21:51:19 +04:00
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
2008-01-23 01:52:53 +03:00
|
|
|
* <http://www.phpdoctrine.org>.
|
2006-07-27 21:51:19 +04:00
|
|
|
*/
|
2008-05-30 16:09:24 +04:00
|
|
|
|
|
|
|
#namespace Doctrine::ORM::Tools;
|
2007-10-21 10:23:59 +04:00
|
|
|
|
2006-07-27 21:51:19 +04:00
|
|
|
/**
|
|
|
|
* Doctrine_Lib has not commonly used static functions, mostly for debugging purposes
|
2006-11-30 00:18:38 +03:00
|
|
|
*
|
|
|
|
* @package Doctrine
|
2007-10-04 01:43:22 +04:00
|
|
|
* @subpackage Lib
|
2006-11-30 00:18:38 +03:00
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
2008-02-22 21:11:35 +03:00
|
|
|
* @link www.phpdoctrine.org
|
2006-11-30 00:18:38 +03:00
|
|
|
* @since 1.0
|
|
|
|
* @version $Revision$
|
2008-05-30 16:09:24 +04:00
|
|
|
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
|
|
* @todo Split into DBAL/ORM parts. DBAL class goes into Doctrine::DBAL::Tools
|
2006-11-30 00:18:38 +03:00
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
class Doctrine_Lib
|
|
|
|
{
|
2006-05-30 12:42:10 +04:00
|
|
|
/**
|
2007-11-28 05:21:42 +03:00
|
|
|
* getRecordStateAsString
|
|
|
|
*
|
|
|
|
* @param integer $state the state of record
|
2008-05-14 01:20:34 +04:00
|
|
|
* @see Doctrine_Entity::STATE_* constants
|
2007-11-28 05:21:42 +03:00
|
|
|
* @return string string representation of given state
|
2006-05-30 12:42:10 +04:00
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public static function getRecordStateAsString($state)
|
|
|
|
{
|
2006-12-29 17:01:31 +03:00
|
|
|
switch ($state) {
|
2008-05-14 01:20:34 +04:00
|
|
|
case Doctrine_Entity::STATE_PROXY:
|
2007-11-28 05:21:42 +03:00
|
|
|
return "proxy";
|
|
|
|
break;
|
2008-05-14 01:20:34 +04:00
|
|
|
case Doctrine_Entity::STATE_CLEAN:
|
2007-11-28 05:21:42 +03:00
|
|
|
return "persistent clean";
|
|
|
|
break;
|
2008-05-14 01:20:34 +04:00
|
|
|
case Doctrine_Entity::STATE_DIRTY:
|
2007-11-28 05:21:42 +03:00
|
|
|
return "persistent dirty";
|
|
|
|
break;
|
2008-05-14 01:20:34 +04:00
|
|
|
case Doctrine_Entity::STATE_TDIRTY:
|
2007-11-28 05:21:42 +03:00
|
|
|
return "transient dirty";
|
|
|
|
break;
|
2008-05-14 01:20:34 +04:00
|
|
|
case Doctrine_Entity::STATE_TCLEAN:
|
2007-11-28 05:21:42 +03:00
|
|
|
return "transient clean";
|
|
|
|
break;
|
2007-02-17 01:54:59 +03:00
|
|
|
}
|
2006-05-30 12:42:10 +04:00
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
2006-05-30 12:42:10 +04:00
|
|
|
/**
|
2007-11-28 05:21:42 +03:00
|
|
|
* getRecordAsString
|
|
|
|
*
|
2008-05-14 01:20:34 +04:00
|
|
|
* returns a string representation of Doctrine_Entity object
|
2007-11-28 05:21:42 +03:00
|
|
|
*
|
2008-05-14 01:20:34 +04:00
|
|
|
* @param Doctrine_Entity $record
|
2006-05-30 12:42:10 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
2008-05-14 01:20:34 +04:00
|
|
|
public static function getRecordAsString(Doctrine_Entity $record)
|
2006-12-29 17:40:47 +03:00
|
|
|
{
|
2007-05-16 23:20:55 +04:00
|
|
|
$r[] = '<pre>';
|
|
|
|
$r[] = 'Component : ' . $record->getTable()->getComponentName();
|
|
|
|
$r[] = 'ID : ' . $record->obtainIdentifier();
|
|
|
|
$r[] = 'References : ' . count($record->getReferences());
|
|
|
|
$r[] = 'State : ' . Doctrine_Lib::getRecordStateAsString($record->getState());
|
|
|
|
$r[] = 'OID : ' . $record->getOID();
|
|
|
|
$r[] = 'data : ' . Doctrine::dump($record->getData(), false);
|
|
|
|
$r[] = '</pre>';
|
2007-04-20 00:24:08 +04:00
|
|
|
|
2007-11-28 05:21:42 +03:00
|
|
|
return implode("\n",$r)."<br />";
|
2007-04-20 16:42:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-28 05:21:42 +03:00
|
|
|
* getConnectionStateAsString
|
2007-04-20 16:42:53 +04:00
|
|
|
*
|
2006-08-22 03:19:15 +04:00
|
|
|
* returns a given connection state as string
|
2007-11-28 05:21:42 +03:00
|
|
|
*
|
|
|
|
* @param integer $state State of the connection as a string
|
2006-05-30 12:42:10 +04:00
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public static function getConnectionStateAsString($state)
|
|
|
|
{
|
2006-12-29 17:01:31 +03:00
|
|
|
switch ($state) {
|
2007-11-28 05:21:42 +03:00
|
|
|
case Doctrine_Transaction::STATE_SLEEP:
|
|
|
|
return "open";
|
|
|
|
break;
|
|
|
|
case Doctrine_Transaction::STATE_BUSY:
|
|
|
|
return "busy";
|
|
|
|
break;
|
|
|
|
case Doctrine_Transaction::STATE_ACTIVE:
|
|
|
|
return "active";
|
|
|
|
break;
|
2007-02-17 01:54:59 +03:00
|
|
|
}
|
2006-05-30 12:42:10 +04:00
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
2006-05-30 12:42:10 +04:00
|
|
|
/**
|
2007-11-28 05:21:42 +03:00
|
|
|
* getConnectionAsString
|
|
|
|
*
|
2006-08-22 03:19:15 +04:00
|
|
|
* returns a string representation of Doctrine_Connection object
|
2007-11-28 05:21:42 +03:00
|
|
|
*
|
2006-08-22 03:19:15 +04:00
|
|
|
* @param Doctrine_Connection $connection
|
2006-05-30 12:42:10 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public static function getConnectionAsString(Doctrine_Connection $connection)
|
|
|
|
{
|
2007-02-17 01:54:59 +03:00
|
|
|
$r[] = '<pre>';
|
|
|
|
$r[] = 'Doctrine_Connection object';
|
|
|
|
$r[] = 'State : ' . Doctrine_Lib::getConnectionStateAsString($connection->transaction->getState());
|
|
|
|
$r[] = 'Open Transactions : ' . $connection->transaction->getTransactionLevel();
|
|
|
|
$r[] = 'Table in memory : ' . $connection->count();
|
2007-06-25 21:48:44 +04:00
|
|
|
$r[] = 'Driver name : ' . $connection->getAttribute(Doctrine::ATTR_DRIVER_NAME);
|
2006-05-30 12:42:10 +04:00
|
|
|
$r[] = "</pre>";
|
2007-11-28 05:21:42 +03:00
|
|
|
|
2006-05-30 12:42:10 +04:00
|
|
|
return implode("\n",$r)."<br>";
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
2006-05-30 12:42:10 +04:00
|
|
|
/**
|
2007-11-28 05:21:42 +03:00
|
|
|
* getTableAsString
|
|
|
|
*
|
2006-05-30 12:42:10 +04:00
|
|
|
* returns a string representation of Doctrine_Table object
|
2007-11-28 05:21:42 +03:00
|
|
|
*
|
2006-05-30 12:42:10 +04:00
|
|
|
* @param Doctrine_Table $table
|
|
|
|
* @return string
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public static function getTableAsString(Doctrine_Table $table)
|
|
|
|
{
|
2006-05-30 12:42:10 +04:00
|
|
|
$r[] = "<pre>";
|
2006-06-25 22:34:53 +04:00
|
|
|
$r[] = "Component : ".$table->getComponentName();
|
|
|
|
$r[] = "Table : ".$table->getTableName();
|
2006-05-30 12:42:10 +04:00
|
|
|
$r[] = "</pre>";
|
2007-11-28 05:21:42 +03:00
|
|
|
|
2006-05-30 12:42:10 +04:00
|
|
|
return implode("\n",$r)."<br>";
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
2006-06-09 02:11:36 +04:00
|
|
|
/**
|
2007-11-18 23:37:44 +03:00
|
|
|
* formatSql
|
|
|
|
*
|
|
|
|
* @todo: What about creating a config varialbe for the color?
|
|
|
|
* @param mixed $sql
|
|
|
|
* @return string the formated sql
|
2006-06-09 02:11:36 +04:00
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public static function formatSql($sql)
|
|
|
|
{
|
2006-06-09 02:11:36 +04:00
|
|
|
$e = explode("\n",$sql);
|
|
|
|
$color = "367FAC";
|
|
|
|
$l = $sql;
|
2006-12-28 14:56:24 +03:00
|
|
|
$l = str_replace("SELECT ", "<font color='$color'><b>SELECT </b></font><br \> ",$l);
|
|
|
|
$l = str_replace("FROM ", "<font color='$color'><b>FROM </b></font><br \>",$l);
|
|
|
|
$l = str_replace(" LEFT JOIN ", "<br \><font color='$color'><b> LEFT JOIN </b></font>",$l);
|
|
|
|
$l = str_replace(" INNER JOIN ", "<br \><font color='$color'><b> INNER JOIN </b></font>",$l);
|
|
|
|
$l = str_replace(" WHERE ", "<br \><font color='$color'><b> WHERE </b></font>",$l);
|
|
|
|
$l = str_replace(" GROUP BY ", "<br \><font color='$color'><b> GROUP BY </b></font>",$l);
|
|
|
|
$l = str_replace(" HAVING ", "<br \><font color='$color'><b> HAVING </b></font>",$l);
|
|
|
|
$l = str_replace(" AS ", "<font color='$color'><b> AS </b></font><br \> ",$l);
|
|
|
|
$l = str_replace(" ON ", "<font color='$color'><b> ON </b></font>",$l);
|
|
|
|
$l = str_replace(" ORDER BY ", "<font color='$color'><b> ORDER BY </b></font><br \>",$l);
|
|
|
|
$l = str_replace(" LIMIT ", "<font color='$color'><b> LIMIT </b></font><br \>",$l);
|
|
|
|
$l = str_replace(" OFFSET ", "<font color='$color'><b> OFFSET </b></font><br \>",$l);
|
|
|
|
$l = str_replace(" ", "<dd>",$l);
|
2006-12-29 17:01:31 +03:00
|
|
|
|
2006-06-09 02:11:36 +04:00
|
|
|
return $l;
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
2006-05-30 12:42:10 +04:00
|
|
|
/**
|
2007-11-28 05:21:42 +03:00
|
|
|
* getCollectionAsString
|
|
|
|
*
|
2006-05-30 12:42:10 +04:00
|
|
|
* returns a string representation of Doctrine_Collection object
|
2007-11-28 05:21:42 +03:00
|
|
|
*
|
2006-05-30 12:42:10 +04:00
|
|
|
* @param Doctrine_Collection $collection
|
|
|
|
* @return string
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public static function getCollectionAsString(Doctrine_Collection $collection)
|
|
|
|
{
|
2006-05-30 12:42:10 +04:00
|
|
|
$r[] = "<pre>";
|
|
|
|
$r[] = get_class($collection);
|
2007-05-23 01:05:52 +04:00
|
|
|
$r[] = 'data : ' . Doctrine::dump($collection->getData(), false);
|
|
|
|
//$r[] = 'snapshot : ' . Doctrine::dump($collection->getSnapshot());
|
2006-05-30 12:42:10 +04:00
|
|
|
$r[] = "</pre>";
|
2007-11-28 05:21:42 +03:00
|
|
|
|
2006-05-30 12:42:10 +04:00
|
|
|
return implode("\n",$r);
|
|
|
|
}
|
2007-11-28 05:21:42 +03:00
|
|
|
|
|
|
|
// Code from symfony sfToolkit class. See LICENSE
|
|
|
|
// code from php at moechofe dot com (array_merge comment on php.net)
|
|
|
|
/*
|
|
|
|
* arrayDeepMerge
|
|
|
|
*
|
|
|
|
* array arrayDeepMerge ( array array1 [, array array2 [, array ...]] )
|
|
|
|
*
|
|
|
|
* Like array_merge
|
|
|
|
*
|
|
|
|
* arrayDeepMerge() merges the elements of one or more arrays together so
|
|
|
|
* that the values of one are appended to the end of the previous one. It
|
|
|
|
* returns the resulting array.
|
|
|
|
* If the input arrays have the same string keys, then the later value for
|
|
|
|
* that key will overwrite the previous one. If, however, the arrays contain
|
|
|
|
* numeric keys, the later value will not overwrite the original value, but
|
|
|
|
* will be appended.
|
|
|
|
* If only one array is given and the array is numerically indexed, the keys
|
|
|
|
* get reindexed in a continuous way.
|
|
|
|
*
|
|
|
|
* Different from array_merge
|
|
|
|
* If string keys have arrays for values, these arrays will merge recursively.
|
|
|
|
*/
|
|
|
|
public static function arrayDeepMerge()
|
|
|
|
{
|
|
|
|
switch (func_num_args()) {
|
|
|
|
case 0:
|
|
|
|
return false;
|
|
|
|
case 1:
|
|
|
|
return func_get_arg(0);
|
|
|
|
case 2:
|
|
|
|
$args = func_get_args();
|
|
|
|
$args[2] = array();
|
|
|
|
|
|
|
|
if (is_array($args[0]) && is_array($args[1]))
|
|
|
|
{
|
|
|
|
foreach (array_unique(array_merge(array_keys($args[0]),array_keys($args[1]))) as $key)
|
|
|
|
{
|
|
|
|
$isKey0 = array_key_exists($key, $args[0]);
|
|
|
|
$isKey1 = array_key_exists($key, $args[1]);
|
|
|
|
|
|
|
|
if ($isKey0 && $isKey1 && is_array($args[0][$key]) && is_array($args[1][$key]))
|
|
|
|
{
|
|
|
|
$args[2][$key] = self::arrayDeepMerge($args[0][$key], $args[1][$key]);
|
|
|
|
} else if ($isKey0 && $isKey1) {
|
|
|
|
$args[2][$key] = $args[1][$key];
|
|
|
|
} else if ( ! $isKey1) {
|
|
|
|
$args[2][$key] = $args[0][$key];
|
|
|
|
} else if ( ! $isKey0) {
|
|
|
|
$args[2][$key] = $args[1][$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $args[2];
|
|
|
|
} else {
|
|
|
|
return $args[1];
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
$args = func_get_args();
|
|
|
|
$args[1] = sfToolkit::arrayDeepMerge($args[0], $args[1]);
|
|
|
|
array_shift($args);
|
|
|
|
|
|
|
|
return call_user_func_array(array('Doctrine', 'arrayDeepMerge'), $args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Code from symfony sfToolkit class. See LICENSE
|
|
|
|
/**
|
|
|
|
* stringToArray
|
|
|
|
*
|
|
|
|
* @param string $string
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function stringToArray($string)
|
|
|
|
{
|
|
|
|
preg_match_all('/
|
|
|
|
\s*(\w+) # key \\1
|
|
|
|
\s*=\s* # =
|
|
|
|
(\'|")? # values may be included in \' or " \\2
|
|
|
|
(.*?) # value \\3
|
|
|
|
(?(2) \\2) # matching \' or " if needed \\4
|
|
|
|
\s*(?:
|
|
|
|
(?=\w+\s*=) | \s*$ # followed by another key= or the end of the string
|
|
|
|
)
|
|
|
|
/x', $string, $matches, PREG_SET_ORDER);
|
|
|
|
|
|
|
|
$attributes = array();
|
|
|
|
foreach ($matches as $val) {
|
|
|
|
$attributes[$val[1]] = self::literalize($val[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the type of the passed value, returns the value as the new type.
|
|
|
|
*
|
|
|
|
* @param string
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public static function literalize($value, $quoted = false)
|
|
|
|
{
|
|
|
|
// lowercase our value for comparison
|
|
|
|
$value = trim($value);
|
|
|
|
$lvalue = strtolower($value);
|
|
|
|
|
|
|
|
if (in_array($lvalue, array('null', '~', '')))
|
|
|
|
{
|
|
|
|
$value = null;
|
|
|
|
} else if (in_array($lvalue, array('true', 'on', '+', 'yes'))) {
|
|
|
|
$value = true;
|
|
|
|
} else if (in_array($lvalue, array('false', 'off', '-', 'no'))) {
|
|
|
|
$value = false;
|
|
|
|
} else if (ctype_digit($value)) {
|
|
|
|
$value = (int) $value;
|
|
|
|
} else if (is_numeric($value)) {
|
|
|
|
$value = (float) $value;
|
|
|
|
} else {
|
|
|
|
if ($quoted)
|
|
|
|
{
|
|
|
|
$value = '\''.str_replace('\'', '\\\'', $value).'\'';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getValidators
|
|
|
|
*
|
|
|
|
* Get available doctrine validators
|
|
|
|
*
|
|
|
|
* @return array $validators
|
|
|
|
*/
|
|
|
|
public static function getValidators()
|
|
|
|
{
|
|
|
|
$validators = array();
|
|
|
|
|
2008-01-05 22:14:35 +03:00
|
|
|
$dir = Doctrine::getPath() . DIRECTORY_SEPARATOR . 'Doctrine' . DIRECTORY_SEPARATOR . 'Validator';
|
2007-11-28 05:21:42 +03:00
|
|
|
|
|
|
|
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY);
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$e = explode('.', $file->getFileName());
|
|
|
|
|
|
|
|
if (end($e) == 'php') {
|
|
|
|
$name = strtolower($e[0]);
|
|
|
|
|
|
|
|
$validators[$name] = $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $validators;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* makeDirectories
|
|
|
|
*
|
|
|
|
* Makes the directories for a path recursively
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function makeDirectories($path, $mode = 0777)
|
|
|
|
{
|
|
|
|
if ( ! $path) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_dir($path) || is_file($path)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mkdir($path, $mode, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* removeDirectories
|
|
|
|
*
|
|
|
|
* @param string $folderPath
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function removeDirectories($folderPath)
|
|
|
|
{
|
|
|
|
if (is_dir($folderPath))
|
|
|
|
{
|
|
|
|
foreach (scandir($folderPath) as $value)
|
|
|
|
{
|
|
|
|
if ($value != '.' && $value != '..')
|
|
|
|
{
|
|
|
|
$value = $folderPath . "/" . $value;
|
|
|
|
|
|
|
|
if (is_dir($value)) {
|
|
|
|
self::removeDirectories($value);
|
|
|
|
} else if (is_file($value)) {
|
|
|
|
@unlink($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rmdir ( $folderPath );
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-25 06:18:51 +03:00
|
|
|
public static function copyDirectory($source, $dest)
|
|
|
|
{
|
|
|
|
// Simple copy for a file
|
|
|
|
if (is_file($source)) {
|
|
|
|
return copy($source, $dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make destination directory
|
|
|
|
if ( ! is_dir($dest)) {
|
|
|
|
mkdir($dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop through the folder
|
|
|
|
$dir = dir($source);
|
|
|
|
while (false !== $entry = $dir->read()) {
|
|
|
|
// Skip pointers
|
|
|
|
if ($entry == '.' || $entry == '..') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deep copy directories
|
|
|
|
if ($dest !== "$source/$entry") {
|
|
|
|
self::copyDirectory("$source/$entry", "$dest/$entry");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
$dir->close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-11-28 05:21:42 +03:00
|
|
|
/**
|
|
|
|
* isValidClassName
|
|
|
|
*
|
|
|
|
* checks for valid class name (uses camel case and underscores)
|
|
|
|
*
|
|
|
|
* @param string $classname
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function isValidClassName($className)
|
|
|
|
{
|
|
|
|
if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $className)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|