[limb-svn] r5963 - in 3.x/trunk/limb/core: . tests/cases

svn at limb-project.com svn at limb-project.com
Fri Jun 8 13:48:58 MSD 2007


Author: pachanga
Date: 2007-06-08 13:48:58 +0400 (Fri, 08 Jun 2007)
New Revision: 5963
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5963

Modified:
   3.x/trunk/limb/core/common.inc.php
   3.x/trunk/limb/core/tests/cases/lmbRequireTest.class.php
Log:
-- lmb_require_optional($file_path) it includes files only if they exist and if not it doesn't throw an exception(actually it's just a wrapper around lmb_require)
-- lmb_require 2nd 'optional' argument added
-- better tests for lmb_require

Modified: 3.x/trunk/limb/core/common.inc.php
===================================================================
--- 3.x/trunk/limb/core/common.inc.php	2007-06-08 07:03:30 UTC (rev 5962)
+++ 3.x/trunk/limb/core/common.inc.php	2007-06-08 09:48:58 UTC (rev 5963)
@@ -1,10 +1,10 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com 
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 $GLOBALS['LIMB_LAZY_CLASS_PATHS'] = array();
 
@@ -57,7 +57,7 @@
           (strlen($path) > 2 && $path{1} == ':'));
 }
 
-function lmb_require($file_path)
+function lmb_require($file_path, $optional = false)
 {
   static $tried = array();
 
@@ -73,6 +73,9 @@
     return;
   }
 
+  if($optional && !lmb_is_readable($file_path))
+    return;
+
   $file = basename($file_path);
   $items = explode('.', $file);
 
@@ -96,6 +99,11 @@
     throw new lmbException("Could not include source file '$file_path'");
 }
 
+function lmb_require_optional($file_path)
+{
+  lmb_require('limb/dbal/common.inc.php', true);
+}
+
 function lmb_autoload($name)
 {
   if(isset($GLOBALS['LIMB_LAZY_CLASS_PATHS'][$name]))

Modified: 3.x/trunk/limb/core/tests/cases/lmbRequireTest.class.php
===================================================================
--- 3.x/trunk/limb/core/tests/cases/lmbRequireTest.class.php	2007-06-08 07:03:30 UTC (rev 5962)
+++ 3.x/trunk/limb/core/tests/cases/lmbRequireTest.class.php	2007-06-08 09:48:58 UTC (rev 5963)
@@ -1,10 +1,10 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com 
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 
 class lmbRequireTest extends UnitTestCase
@@ -137,6 +137,23 @@
     $this->assertFalse(isset($cov2[$file][$line]));
   }
 
+  function testRequireThrowsExceptionForNonExistingFile()
+  {
+    try
+    {
+      @lmb_require($file = 'foo_' . mt_rand() . '.inc.php');
+    }
+    catch(lmbException $e)
+    {
+      $this->assertPattern('~' . preg_quote($file) . '~', $e->getMessage());
+    }
+  }
+
+  function testRequireOptionalDoesntThrowExceptionForNonExistingFile()
+  {
+    lmb_require($file = 'foo_' . mt_rand() . '.inc.php', true);
+  }
+
   function _locateIncludeOnceLine($file, $start_line)
   {
     $c = 0;



More information about the limb-svn mailing list