Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed and Added #424

Merged
merged 10 commits into from Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/aop/src/Aop.php
Expand Up @@ -82,7 +82,7 @@ public static function register(array $beanNames, string $className, string $met
$isExclude = $isExcludeBean || $isExcludeAnnotation || $isExcludeExecution;

if ($isInclude && !$isExclude) {
self::$mapping[$className][$method][] = $aspect['advice'];
self::$mapping[$className][$method][$aspectClass] = $aspect['advice'];
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/bean/src/Container.php
Expand Up @@ -26,6 +26,7 @@
use Swoft\Bean\Definition\PropertyInjection;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Stdlib\Helper\ArrayHelper;
use Swoft\Stdlib\Helper\ObjectHelper;
use Swoft\Stdlib\Reflections;
use function ucfirst;

Expand Down Expand Up @@ -1024,6 +1025,12 @@ private function newProperty(
$propertyValue = $this->getRefValue($propertyValue, $id);
}

// Parser property type
$propertyType = ObjectHelper::getPropertyBaseType($reflectProperty);
if (!empty($propertyType)) {
$propertyValue = ObjectHelper::parseParamType($propertyType, $propertyValue);
}

// First, try set value by setter method
$setter = 'set' . ucfirst($propertyName);
if (method_exists($reflectObject, $setter)) {
Expand Down Expand Up @@ -1102,7 +1109,7 @@ private function getRefValue($value, string $id = '')
return $value;
}

if(strpos($value, '.') !== 0){
if (strpos($value, '.') !== 0) {
return $this->newBean($value, $id);
}

Expand Down
94 changes: 94 additions & 0 deletions src/bean/test/testing/Definition/TypeBean.php
@@ -0,0 +1,94 @@
<?php declare(strict_types=1);


namespace SwoftTest\Bean\Testing\Definition;

use Swoft\Bean\Annotation\Mapping\Bean;

/**
* Class TypeBean
*
* @since 2.0
*
* @Bean("testTypeBean")
*/
class TypeBean
{
/**
* @var
*/
private $stringVar;

/**
* @var integer
*/
private $intVar;

/**
* @var int
*/
private $integerVar;

/**
* @var float
*/
private $floatVar;

/**
* @var double
*/
private $doubleVar;

/**
* @var array
*/
private $arrayVar;

/**
* @return mixed
*/
public function getStringVar()
{
return $this->stringVar;
}

/**
* @return mixed
*/
public function getIntVar()
{
return $this->intVar;
}

/**
* @return int
*/
public function getIntegerVar(): int
{
return $this->integerVar;
}

/**
* @return float
*/
public function getFloatVar(): float
{
return $this->floatVar;
}

/**
* @return float
*/
public function getDoubleVar(): float
{
return $this->doubleVar;
}

/**
* @return array
*/
public function getArrayVar(): array
{
return $this->arrayVar;
}
}
11 changes: 9 additions & 2 deletions src/bean/test/testing/bean.php
Expand Up @@ -72,10 +72,17 @@
'manyTwoInstance' => [
'class' => ManyInstance::class,
],
'two.many' => [
'two.many' => [
'class' => ManyInstance::class,
],
'commaNameClass' => [
'commaNameClass' => [
'manyInstance2' => \bean('two.many')
],
'testTypeBean' => [
'stringVar' => 1,
'intVar' => '1',
'integerVar' => '2',
'floatVar' => '1.1',
'doubleVar' => '1.2',
]
];
27 changes: 25 additions & 2 deletions src/bean/test/unit/BeanTest.php
Expand Up @@ -5,7 +5,10 @@


use PHPUnit\Framework\TestCase;
use ReflectionException;
use Swoft\Bean\BeanFactory;
use Swoft\Bean\Exception\ContainerException;
use SwoftTest\Bean\Testing\Definition\TypeBean;

/**
* Class BeanTest
Expand All @@ -14,8 +17,28 @@
*/
class BeanTest extends TestCase
{
public function testSingle()
/**
* @throws ReflectionException
* @throws ContainerException
*/
public function testType()
{
$this->assertTrue(true);
/* @var TypeBean $typeBean */
$typeBean = BeanFactory::getBean('testTypeBean');

$this->assertEquals($typeBean->getStringVar(), '1');
$this->assertEquals($typeBean->getIntVar(), 1);
$this->assertEquals($typeBean->getIntegerVar(), 2);
$this->assertEquals($typeBean->getFloatVar(), 1.1);
$this->assertEquals($typeBean->getDoubleVar(), 1.2);

/* @var TypeBean $typeBean */
$typeBean = BeanFactory::getBean(TypeBean::class);

$this->assertEquals($typeBean->getStringVar(), '1');
$this->assertEquals($typeBean->getIntVar(), 1);
$this->assertEquals($typeBean->getIntegerVar(), 2);
$this->assertEquals($typeBean->getFloatVar(), 1.1);
$this->assertEquals($typeBean->getDoubleVar(), 1.2);
}
}
4 changes: 3 additions & 1 deletion src/error/.travis.yml
Expand Up @@ -4,7 +4,9 @@ php:
- 7.1
- 7.2
- 7.3

install:
- wget https://github.com/swoole/swoole-src/archive/v4.3.3.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/$(phpenv version-name)/etc/php.ini
before_script:
- composer config -g process-timeout 9000 && composer update
- phpenv config-rm xdebug.ini
Expand Down
1 change: 0 additions & 1 deletion src/event/.travis.yml
Expand Up @@ -4,7 +4,6 @@ php:
- 7.1
- 7.2
- 7.3

before_script:
- composer config -g process-timeout 9000 && composer update
- phpenv config-rm xdebug.ini
Expand Down
2 changes: 1 addition & 1 deletion src/framework/src/Swoft.php
Expand Up @@ -26,7 +26,7 @@ class Swoft
/**
* Swoft version
*/
public const VERSION = '2.0.0-beta';
public const VERSION = '2.0.1-beta';

/**
* Swoft log
Expand Down
17 changes: 15 additions & 2 deletions src/http-message/src/Request.php
Expand Up @@ -359,6 +359,19 @@ public function getParsedQuery(): array
return $this->parsedQuery;
}

/**
* @param string $key
* @param null $default
*
* @return mixed|null
*/
public function parsedQuery(string $key, $default = null)
{
$parsedQuery = $this->getParsedQuery();

return $parsedQuery[$key] ?? $default;
}

/**
* @param array $query
*
Expand All @@ -380,8 +393,8 @@ public function withParsedQuery(array $query)
*/
public function parsedBody(string $key, $default = null)
{
$parseBody = $this->getParsedBody();
return $parseBody[$key] ?? $default;
$parsedBody = $this->getParsedBody();
return $parsedBody[$key] ?? $default;
}

/**
Expand Down
Expand Up @@ -30,7 +30,9 @@ class ValidatorController
*/
public function defaultValidator(Request $request)
{
$data = $request->getParsedBody();
$data = $request->getParsedBody();
$data['kString'] = $request->parsedBody('string');
$data['noKey'] = $request->parsedBody('noKey', 'not');

return $data;
}
Expand Down Expand Up @@ -65,6 +67,9 @@ public function defaultValidatorQuery(Request $request)
{
$data = $request->getParsedQuery();

$data['kString'] = $request->parsedQuery('string');
$data['noKey'] = $request->parsedQuery('noKey', 'not');

return $data;
}

Expand Down
8 changes: 6 additions & 2 deletions src/http-server/test/unit/ValidatorTest.php
Expand Up @@ -26,7 +26,9 @@ public function testDefaultValidator()
'bool' => true,
'array' => [
'array'
]
],
'kString' => 'string',
'noKey' => 'not',
];
$response = $this->mockServer->request(MockRequest::POST, '/testValidator/defautValidator');
$response->assertEqualJson($data);
Expand Down Expand Up @@ -75,7 +77,9 @@ public function testDefaultValidatorQuery()
'bool' => true,
'array' => [
'array'
]
],
'kString' => 'string',
'noKey' => 'not',
];
$response = $this->mockServer->request(MockRequest::GET, '/testValidator/defaultValidatorQuery');
$response->assertEqualJson($data);
Expand Down