Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop' of git://github.com/zendframework/zf2 into string
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 25 changed files with 210 additions and 3,752 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"homepage": "https://github.com/zendframework/zend-file",
"autoload": {
"psr-4": {
"Zend\\File": "src/"
"Zend\\File\\": "src/"
}
},
"require": {
Expand All @@ -27,8 +27,7 @@
"suggest": {
"zendframework/zend-filter": "Zend\\Filter component",
"zendframework/zend-i18n": "Zend\\I18n component",
"zendframework/zend-validator": "Zend\\Validator component",
"zendframework/zend-loader": "Zend\\Loader component"
"zendframework/zend-validator": "Zend\\Validator component"
},
"extra": {
"branch-alias": {
Expand Down
81 changes: 43 additions & 38 deletions src/ClassFileLocator.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,38 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_File
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_File
*/

namespace Zend\File;

// import SPL classes/interfaces into local scope
use DirectoryIterator,
FilterIterator,
RecursiveIterator,
RecursiveDirectoryIterator,
RecursiveIteratorIterator;
use DirectoryIterator;
use FilterIterator;
use RecursiveDirectoryIterator;
use RecursiveIterator;
use RecursiveIteratorIterator;
use SplFileInfo;

/**
* Locate files containing PHP classes, interfaces, abstracts or traits
*
* @category Zend
* @package Zend_File
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class ClassFileLocator extends FilterIterator
{
/**
* Create an instance of the locator iterator
*
* Expects either a directory, or a DirectoryIterator (or its recursive variant)
*
* Expects either a directory, or a DirectoryIterator (or its recursive variant)
* instance.
*
*
* @param string|DirectoryIterator $dirOrIterator
* @throws Exception\InvalidArgumentException
*/
public function __construct($dirOrIterator = '.')
{
Expand All @@ -62,20 +51,20 @@ public function __construct($dirOrIterator = '.')
}

parent::__construct($dirOrIterator);
$this->setInfoClass('Zend\File\PhpClassFile');
}

/**
* Filter for files containing PHP classes, interfaces, or abstracts
*
*
* @return bool
*/
public function accept()
{
$file = $this->getInnerIterator()->current();

// If we somehow have something other than an SplFileInfo object, just
// If we somehow have something other than an SplFileInfo object, just
// return false
if (!$file instanceof \SplFileInfo) {
if (!$file instanceof SplFileInfo) {
return false;
}

Expand All @@ -95,13 +84,11 @@ public function accept()
$t_trait = defined('T_TRAIT') ? T_TRAIT : -1; // For preserve PHP 5.3 compatibility
for ($i = 0; $i < $count; $i++) {
$token = $tokens[$i];

if (!is_array($token)) {
// single character token found; skip
$i++;
continue;
}

switch ($token[0]) {
case T_NAMESPACE:
// Namespace found; grab it for later
Expand All @@ -110,6 +97,11 @@ public function accept()
$token = $tokens[$i];
if (is_string($token)) {
if (';' === $token) {
$saveNamespace = false;
break;
}
if ('{' === $token) {
$saveNamespace = true;
break;
}
continue;
Expand All @@ -122,9 +114,9 @@ public function accept()
break;
}
}

// Set the namespace of this file in the object
$file->namespace = $namespace;
if ($saveNamespace) {
$savedNamespace = $namespace;
}
break;
case $t_trait:
case T_CLASS:
Expand All @@ -141,16 +133,29 @@ public function accept()
if (T_STRING == $type) {
// If a classname was found, set it in the object, and
// return boolean true (found)
$file->classname = $content;
return true;
if (!isset($namespace) || null === $namespace) {
if (isset($saveNamespace) && $saveNamespace) {
$namespace = $savedNamespace;
} else {
$namespace = null;
}

}
$class = (null === $namespace) ? $content : $namespace . '\\' . $content;
$file->addClass($class);
$namespace = null;
break;
}
}
break;
default:
break;
}
}

$classes = $file->getClasses();
if (!empty($classes)) {
return true;
}
// No class-type tokens found; return false
return false;
}
Expand Down
24 changes: 6 additions & 18 deletions src/Exception/BadMethodCallException.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_File_Transfer
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_File
*/

namespace Zend\File\Exception;

/**
* @category Zend
* @package Zend_File_Transfer
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class BadMethodCallException extends \BadMethodCallException implements
class BadMethodCallException extends \BadMethodCallException implements
ExceptionInterface
{}
24 changes: 6 additions & 18 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_File
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_File
*/

namespace Zend\File\Exception;

/**
* Marker interface for exceptions found in this component
*
*
* @package Zend_File
* @subpackage Exception
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
interface ExceptionInterface
{
Expand Down
28 changes: 8 additions & 20 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_File
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_File
*/

namespace Zend\File\Exception;

/**
* Exception class raised when invalid arguments are discovered
*
*
* @package Zend_File
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class InvalidArgumentException
extends \InvalidArgumentException
class InvalidArgumentException
extends \InvalidArgumentException
implements ExceptionInterface
{
}
24 changes: 6 additions & 18 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_File_Transfer
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_File
*/

namespace Zend\File\Exception;

/**
* @category Zend
* @package Zend_File_Transfer
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class RuntimeException
extends \RuntimeException
implements ExceptionInterface
{}
{}
49 changes: 49 additions & 0 deletions src/PhpClassFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_File
*/

namespace Zend\File;

use SplFileInfo;

/**
* Locate files containing PHP classes, interfaces, abstracts or traits
*
* @category Zend
* @package Zend_File
*/
class PhpClassFile extends SplFileInfo
{
/**
* @var array
*/
protected $classes;

/**
* Get classes
*
* @return array
*/
public function getClasses()
{
return $this->classes;
}

/**
* Add class
*
* @param string $class
* @return PhpClassFile
*/
public function addClass($class)
{
$this->classes[] = $class;
return $this;
}
}
Loading

0 comments on commit 60c43e9

Please sign in to comment.