本文整理汇总了PHP中lithium\core\Libraries::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Libraries::find方法的具体用法?PHP Libraries::find怎么用?PHP Libraries::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\core\Libraries
的用法示例。
在下文中一共展示了Libraries::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Main method.
*
* @param string $path Absolute path to file or directory.
* @return boolean
*/
public function run()
{
$path = $this->request->action;
if (!($path = realpath($path))) {
$this->error('Not a valid path.');
return false;
}
if (!($library = $this->_library($path))) {
$this->error("No library registered for path `{$path}`.");
return false;
}
$classes = Libraries::find($library, array('recursive' => true, 'exclude' => '/tests|resources|webroot|index$|^app\\\\config|^app\\\\views|Exception$/'));
$tests = array();
foreach (Group::all() as $test) {
$class = preg_replace('/(tests\\\\[a-z]+\\\\|Test$)/', null, $test);
$tests[$class] = $test;
}
foreach ($classes as $class) {
$coverage = null;
if ($hasTest = isset($tests[$class])) {
$report = Dispatcher::run($tests[$class], array('reporter' => 'console', 'format' => 'txt', 'filters' => array('Coverage')));
$coverage = $report->results['filters']['lithium\\test\\filter\\Coverage'];
$coverage = isset($coverage[$class]) ? $coverage[$class]['percentage'] : null;
}
$this->out(sprintf('%10s | %7s | %s', $hasTest ? 'has test' : 'no test', is_numeric($coverage) ? sprintf('%.2f%%', $coverage) : 'n/a', $class));
}
}
示例2: add
/**
* Add a tests to the group
*
* @param string $test
* @param string $options
* @return array
*/
public function add($test = null, $options = array())
{
$callback = function ($test) {
if (empty($test)) {
return array();
}
if (is_object($test) && $test instanceof \lithium\test\Unit) {
return array(get_class($test));
}
if (is_string($test)) {
if ($test[0] != '\\') {
$test = "lithium\\tests\\cases\\{$test}";
}
if (preg_match("/Test/", $test)) {
return array($test);
}
$parts = array_filter(explode("\\", $test));
$library = array_shift($parts);
$test = Libraries::find($library, array('recursive' => true, 'path' => '/' . join('/', $parts), 'filter' => '/cases|intergration|functional/'));
return (array) $test;
}
return (array) $test;
};
if (is_array($test)) {
foreach ($test as $t) {
$this->_items = array_filter(array_merge($this->_items, $callback($t)));
}
return $this->_items;
}
return $this->_items = array_merge($this->_items, $callback($test));
}
示例3: run
public function run($library = 'lithium')
{
$libs = Libraries::find($library, array('recursive' => true));
$files = array();
foreach ((array) $libs as $lib) {
$file = Libraries::path($lib);
$this->_display($file);
}
}
示例4: run
public function run()
{
$classes = Libraries::find(true, array('exclude' => "/webroot|index\$|^app\\\\config|^app\\\\views/", 'recursive' => true));
foreach ($classes as $class) {
$path = Libraries::path($class);
$contents = explode("\n", file_get_contents($path));
$contents = $this->_header($contents);
if (file_put_contents($path, implode("\n", $contents))) {
$this->out($path . ' written');
}
}
}
示例5: harvest
public static function harvest()
{
$extractor = $this->_classes['extractor'];
$results = array();
foreach (Libraries::get() as $library => $info) {
$libFiles = Libraries::find($library, array('recursive' => true, 'exclude' => '/mocks|tests|libraries/'));
foreach ($libFiles as $file) {
$this->out("\n" . $file);
$fileData = $extractor::get($library, $file);
$results = array_merge(static::_harvestMethods($fileData), static::_harvestProperties($fileData), array(static::_harvestClass($fileData)));
}
}
return new Collection(array('data' => $results));
}
示例6: read
/**
* Extracts data from files within configured path recursively.
*
* @param string $category Dot-delimited category.
* @param string $locale A locale identifier.
* @param string $scope The scope for the current operation.
* @return mixed
*/
public function read($category, $locale, $scope)
{
if ($scope != $this->_config['scope']) {
return null;
}
$library = Libraries::get($this->_config['library']);
$data = array();
$classes = Libraries::find($this->_config['library'], array('recursive' => true, 'exclude' => '/\\w+Test$|Mock+\\w|webroot|index$|^app\\\\config|^\\w+\\\\views\\/|\\./'));
foreach ($classes as $class) {
if (preg_match('/\\\\(libraries|plugins)\\\\/', $class)) {
continue;
}
$data += $this->_parseClass($class);
}
return $data;
}
示例7: run
/**
* Main command logic.
*
* @return void
*/
public function run()
{
$this->_readyTables();
$extractor = $this->_classes['extractor'];
$libraries = Libraries::get();
foreach ($libraries as $library => $info) {
$this->header($library);
$libFiles = Libraries::find($library, array('recursive' => true, 'exclude' => '/mocks|tests|libraries/'));
foreach ($libFiles as $file) {
$this->out("\n" . $file);
$fileData = $extractor::get($library, $file);
$this->_harvestMethods($fileData);
$this->_harvestProperties($fileData);
$this->_harvestClass($fileData);
}
$this->out("\n\n");
}
$this->out("\n\n");
}
示例8: _affected
/**
* Returns all classes directly depending on a given class.
*
* @param string $dependency The class name to use as a dependency.
* @param string $exclude Regex path exclusion filter.
* @return array Classes having a direct dependency on `$dependency`. May contain duplicates.
*/
protected static function _affected($dependency, $exclude = null)
{
$exclude = $exclude ?: '/(tests|webroot|resources|libraries|plugins)/';
$classes = Libraries::find(true, compact('exclude') + array('recursive' => true));
$dependency = ltrim($dependency, '\\');
$affected = array();
foreach ($classes as $class) {
if (isset(static::$_cachedDepends[$class])) {
$depends = static::$_cachedDepends[$class];
} else {
$depends = Inspector::dependencies($class);
$depends = array_map(function ($c) {
return ltrim($c, '\\');
}, $depends);
static::$_cachedDepends[$class] = $depends;
}
if (in_array($dependency, $depends)) {
$affected[] = $class;
}
}
return $affected;
}
示例9: _children
protected static function _children($library, $path)
{
$result = array();
$types = array('namespace' => array('namespaces' => true), 'class' => array('namespaces' => false), 'file' => array('namespaces' => false, 'filter' => false, 'preFilter' => false));
foreach ($types as $type => $options) {
foreach (Libraries::find($library, compact('path') + $options) as $child) {
$result += array($child => $type);
}
}
return $result;
}
示例10: missing
/**
* Shows which classes are un-tested.
*
* @return void
*/
public function missing()
{
$this->header('Classes with no test case');
$classes = Libraries::find(true, array('recursive' => true, 'exclude' => '/\\w+Test$|webroot|index$|^app\\\\config|^app\\\\views/'));
$tests = Group::all();
$classes = array_diff($classes, $tests);
sort($classes);
$this->out($classes);
}
示例11: testLocateWithLithiumLibrary
public function testLocateWithLithiumLibrary()
{
$expected = (array) Libraries::find('lithium', array('path' => '/tests', 'preFilter' => '/[A-Z][A-Za-z0-9]+\\Test\\./', 'recursive' => true, 'filter' => '/cases|integration|functional|mocks/'));
$result = (array) Libraries::locate("tests", null, array('library' => 'lithium'));
$this->assertEqual($expected, $result);
}
示例12: testAddTestAppGroup
public function testAddTestAppGroup()
{
$testApp = Libraries::get(true, 'resources') . '/tmp/tests/test_app';
mkdir($testApp, 0777, true);
Libraries::add('test_app', array('path' => $testApp));
mkdir($testApp . '/tests/cases/models', 0777, true);
file_put_contents($testApp . '/tests/cases/models/UserTest.php', "<?php namespace test_app\\tests\\cases\\models;\n\n\t\t\tclass UserTest extends \\lithium\\test\\Unit { public function testMe() {\n\t\t\t\t\$this->assertTrue(true);\n\t\t\t}}");
Libraries::cache(false);
$expected = (array) Libraries::find('test_app', array('recursive' => true, 'path' => '/tests', 'filter' => '/cases|integration|functional/'));
Libraries::cache(false);
$group = new Group();
$result = $group->add('test_app');
$this->assertEqual($expected, $result);
Libraries::cache(false);
$this->_cleanUp();
}
示例13: _resolve
/**
* Resolves a unit test class (or classes) from a class or namespace path string.
*
* @param string $test The path string in which to find the test case(s). This may be a
* library, a namespace, or a fully-namespaced class reference.
* @return array Returns an array containing one or more fully-namespaced class references to
* unit tests.
*/
protected function _resolve($test)
{
if (strpos($test, '\\') === false && Libraries::get($test)) {
return (array) Libraries::find($test, array('recursive' => true, 'filter' => '/(cases|integration|functional)\\\\.*Test$/', 'exclude' => '/tests\\\\mocks/'));
}
if (!($test = trim($test, '\\'))) {
return array();
}
list($library, $path) = explode('\\', $test, 2) + array($test, null);
return (array) Libraries::find($library, array('recursive' => true, 'path' => '/' . str_replace('\\', '/', $path), 'filter' => '/(cases|integration|functional)\\\\.*Test$/', 'exclude' => strstr($test, 'tests\\mocks') ? '' : '/tests\\\\mocks/'));
}
示例14: testFindWithOptions
public function testFindWithOptions()
{
$result = Libraries::find('lithium', array('path' => '/console/command/create/template', 'namespaces' => false, 'suffix' => false, 'filter' => false, 'exclude' => false, 'format' => function ($file, $config) {
return basename($file);
}));
$this->assertTrue(count($result) > 3);
$this->assertTrue(array_search('controller.txt.php', $result));
$this->assertTrue(array_search('model.txt.php', $result));
$this->assertTrue(array_search('plugin.phar.gz', $result));
}
示例15: _resolve
/**
* Resolves a unit test class (or classes) from a class or namespace path string.
*
* @param string $test The path string in which to find the test case(s). This may be a
* library, a namespace, or a fully-namespaced class reference.
* @return array Returns an array containing one or more fully-namespaced class references to
* unit tests.
*/
protected function _resolve($test)
{
if (strpos($test, '\\') === false && Libraries::get($test)) {
return (array) Libraries::find($test, array('recursive' => true, 'filter' => '/cases|integration|functional/'));
}
if (preg_match("/Test/", $test)) {
return array($test);
}
if (!($test = trim($test, '\\'))) {
return array();
}
list($library, $path) = explode('\\', $test, 2) + array($test, null);
return (array) Libraries::find($library, array('recursive' => true, 'path' => '/' . str_replace('\\', '/', $path), 'filter' => '/cases|integration|functional/'));
}