forked from imiphp/imi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
344 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/res export-ignore | ||
/travis export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
language: php | ||
|
||
php: | ||
- 7.1 | ||
- '7.1' | ||
- '7.2' | ||
- '7.3' | ||
|
||
install: | ||
- php ./travis/install.php -nproc $(nproc) -version-name $(phpenv version-name) | ||
|
||
before_script: | ||
- phpenv config-rm xdebug.ini | ||
- composer update | ||
|
||
script: | ||
- php test/test.php | ||
- composer test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
require dirname(__DIR__) . '/vendor/autoload.php'; | ||
|
||
use Imi\App; | ||
use Imi\Event\Event; | ||
use Imi\Event\EventParam; | ||
use Imi\Tool\Tool; | ||
|
||
Event::on('IMI.INITED', function(EventParam $param){ | ||
$param->stopPropagation(); | ||
Tool::init(); | ||
echo 'imi inited!', PHP_EOL; | ||
}, PHP_INT_MAX); | ||
|
||
echo 'init imi...', PHP_EOL; | ||
|
||
App::run('Imi\Test'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
require dirname(__DIR__) . '/vendor/bin/phpunit'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="./bootstrap.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Aop"> | ||
<directory>unit/Tests</directory> | ||
<file>*.php</file> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace Imi\Test\Aop\Aop; | ||
|
||
use Imi\Aop\JoinPoint; | ||
use Imi\Bean\BeanProxy; | ||
use Imi\Bean\BeanFactory; | ||
use Imi\Aop\Annotation\After; | ||
use PHPUnit\Framework\Assert; | ||
use Imi\Aop\Annotation\Aspect; | ||
use Imi\Aop\Annotation\PointCut; | ||
|
||
/** | ||
* @Aspect | ||
*/ | ||
class AfterAop | ||
{ | ||
/** | ||
* @After | ||
* @PointCut( | ||
* allow={ | ||
* "Imi\Test\Aop\Classes\TestAfterAopClass::test" | ||
* } | ||
* ) | ||
* | ||
* @return void | ||
*/ | ||
public function injectAfterAop(JoinPoint $joinPoint) | ||
{ | ||
Assert::assertEquals([1], $joinPoint->getArgs()); | ||
Assert::assertEquals('test', $joinPoint->getMethod()); | ||
Assert::assertEquals(\Imi\Test\Aop\Classes\TestAfterClass::class, BeanFactory::getObjectClass($joinPoint->getTarget())); | ||
Assert::assertEquals(BeanProxy::class, get_class($joinPoint->getThis())); | ||
Assert::assertEquals('after', $joinPoint->getType()); | ||
$joinPoint->setArgs([2]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace Imi\Test\Aop\Aop; | ||
|
||
use Imi\Aop\JoinPoint; | ||
use PHPUnit\Framework\Assert; | ||
use Imi\Aop\Annotation\Aspect; | ||
use Imi\Aop\Annotation\Before; | ||
use Imi\Aop\Annotation\PointCut; | ||
use Imi\Bean\BeanFactory; | ||
use Imi\Bean\BeanProxy; | ||
|
||
/** | ||
* @Aspect | ||
*/ | ||
class BeforeAop | ||
{ | ||
/** | ||
* @Before | ||
* @PointCut( | ||
* allow={ | ||
* "Imi\Test\Aop\Classes\TestBeforeClass::test" | ||
* } | ||
* ) | ||
* | ||
* @return void | ||
*/ | ||
public function injectBefore(JoinPoint $joinPoint) | ||
{ | ||
Assert::assertEquals([1], $joinPoint->getArgs()); | ||
Assert::assertEquals('test', $joinPoint->getMethod()); | ||
Assert::assertEquals(\Imi\Test\Aop\Classes\TestBeforeClass::class, BeanFactory::getObjectClass($joinPoint->getTarget())); | ||
Assert::assertEquals(BeanProxy::class, get_class($joinPoint->getThis())); | ||
Assert::assertEquals('before', $joinPoint->getType()); | ||
$joinPoint->setArgs([2]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
namespace Imi\Test\Aop\Classes; | ||
|
||
use Imi\Bean\Annotation\Bean; | ||
|
||
/** | ||
* @Bean("TestAfterClass") | ||
*/ | ||
class TestAfterClass | ||
{ | ||
public function test(int $id) | ||
{ | ||
return $id; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
namespace Imi\Test\Aop\Classes; | ||
|
||
use Imi\Bean\Annotation\Bean; | ||
|
||
/** | ||
* @Bean("TestBeforeClass") | ||
*/ | ||
class TestBeforeClass | ||
{ | ||
public function test(int $id) | ||
{ | ||
return $id; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
namespace Imi\Test; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
abstract class BaseTest extends TestCase | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace Imi\Test; | ||
|
||
use Imi\Main\AppBaseMain; | ||
|
||
class Main extends AppBaseMain | ||
{ | ||
public function __init() | ||
{ | ||
// 这里可以做一些初始化操作,如果需要的话 | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
namespace Imi\Test\Tests; | ||
|
||
use Imi\Test\BaseTest; | ||
use Imi\App; | ||
|
||
class AopTest extends BaseTest | ||
{ | ||
/** | ||
* Aop Before | ||
* | ||
* @return void | ||
*/ | ||
public function testBefore() | ||
{ | ||
$test = App::getBean('TestBeforeClass'); | ||
$result = $test->test(1); | ||
$this->assertEquals(2, $result); | ||
} | ||
|
||
/** | ||
* Aop After | ||
* | ||
* @return void | ||
*/ | ||
public function testAfter() | ||
{ | ||
$test = App::getBean('TestAfterClass'); | ||
$result = $test->test(1); | ||
$this->assertEquals(1, $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
return [ | ||
'configs' => [ | ||
], | ||
// bean扫描目录 | ||
'beanScan' => [ | ||
'Imi\Test\Aop', | ||
], | ||
'beans' => [ | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* 命令行参数操作类 | ||
*/ | ||
abstract class Args | ||
{ | ||
/** | ||
* 参数存储 | ||
* @var string | ||
*/ | ||
private static $cliArgs; | ||
|
||
/** | ||
* 初始化 | ||
* | ||
* @param integer $argBegin 从第几个参数算 | ||
* @return void | ||
*/ | ||
public static function init($argBegin = 1) | ||
{ | ||
static::$cliArgs = []; | ||
$keyName = null; | ||
for($i = $argBegin; $i < $_SERVER['argc']; ++$i) | ||
{ | ||
if(isset($_SERVER['argv'][$i][0]) && '-' === $_SERVER['argv'][$i][0]) | ||
{ | ||
$keyName = substr($_SERVER['argv'][$i], 1); | ||
static::$cliArgs[$keyName] = true; | ||
} | ||
else | ||
{ | ||
if(null === $keyName) | ||
{ | ||
static::$cliArgs[$_SERVER['argv'][$i]] = true; | ||
} | ||
else | ||
{ | ||
static::$cliArgs[$keyName] = $_SERVER['argv'][$i]; | ||
$keyName = null; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* 指定数据是否存在 | ||
* @param string $name | ||
* @return bool | ||
*/ | ||
public static function exists($name) | ||
{ | ||
if(is_integer($name)) | ||
{ | ||
return isset($_SERVER['argv'][$name]); | ||
} | ||
else | ||
{ | ||
return isset(static::$cliArgs[$name]); | ||
} | ||
} | ||
|
||
/** | ||
* 获取值 | ||
* @param string $name | ||
* @param mixed $default | ||
* @return mixed | ||
*/ | ||
public static function get($name = '', $default = null) | ||
{ | ||
if(is_integer($name)) | ||
{ | ||
$data = $_SERVER['argv']; | ||
} | ||
else | ||
{ | ||
$data = &static::$cliArgs; | ||
} | ||
if ('' === $name) | ||
{ | ||
// 全部的值 | ||
return $data; | ||
} | ||
// 判断指定的值是否存在 | ||
else if (isset($data[$name])) | ||
{ | ||
return $data[$name]; | ||
} | ||
else | ||
{ | ||
// 返回默认值 | ||
return $default; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
require __DIR__ . '/Args.php'; | ||
|
||
Args::init(); | ||
$nproc = Args::get('nproc'); | ||
$versionName = Args::get('version-name'); | ||
|
||
define('OTHER_SWOOLE_VERSION', 'v4.4.0-beta'); | ||
|
||
if(version_compare(PHP_VERSION, '7.1', '>=')) | ||
{ | ||
$version = OTHER_SWOOLE_VERSION; | ||
|
||
`wget https://github.com/swoole/swoole-src/archive/{$version}.tar.gz -O swoole.tar.gz && mkdir -p swoole && tar -xf swoole.tar.gz -C swoole --strip-components=1 && rm swoole.tar.gz && cd swoole && phpize && ./configure && make -j{$nproc} && make install && cd -`; | ||
|
||
`echo "extension = swoole.so" >> ~/.phpenv/versions/{$versionName}/etc/php.ini`; | ||
} | ||
else | ||
{ | ||
echo 'Skip Swoole', PHP_EOL; | ||
} |