Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit 5e2c0a9

Browse files
committed
init project for inhere/librarys
0 parents  commit 5e2c0a9

18 files changed

+969
-0
lines changed

.editorconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
# 对所有文件生效
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
# 对后缀名为 md 的文件生效
13+
[*.md]
14+
trim_trailing_whitespace = false
15+
16+
[*.php]
17+
indent_size = 4

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.idea/
2+
.phpintel/
3+
!README.md
4+
!.gitkeep
5+
composer.lock
6+
*.swp
7+
*.log
8+
*.pid
9+
*.patch
10+
.DS_Store

LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 inhere
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# object utils for php
2+
3+
4+
## license
5+
6+
MIT

composer.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "mylib/obj-utils",
3+
"type": "library",
4+
"description": "some object tool library of the php",
5+
"keywords": ["library","tool","php"],
6+
"homepage": "https://github.com/php-mylib/obj-utils",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "inhere",
11+
"email": "[email protected]",
12+
"homepage": "http://www.yzone.net/"
13+
}
14+
],
15+
"require": {
16+
"php": ">=7.0.0"
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"MyLib\\Obj\\" : "src/"
21+
}
22+
},
23+
"suggest": {
24+
"inhere/simple-print-tool": "Very lightweight data printing tools",
25+
"inhere/php-validate": "Very lightweight data validate tool",
26+
"inhere/console": "a lightweight php console application library."
27+
}
28+
}

phpunit.xml.dist

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
bootstrap="./tests/boot.php"
6+
colors="false"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Php Library Test Suite">
15+
<directory>./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
<filter>
20+
<whitelist>
21+
<directory suffix=".php">./src</directory>
22+
</whitelist>
23+
</filter>
24+
</phpunit>
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Inhere
5+
* Date: 2018/1/29 0029
6+
* Time: 23:25
7+
*/
8+
9+
namespace MyLib\Obj\Exception;
10+
11+
/**
12+
* Class GetPropertyException
13+
* @package MyLib\Obj\Exception
14+
*/
15+
class GetPropertyException extends \RuntimeException
16+
{
17+
}

src/Exception/PropertyException.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Inhere
5+
* Date: 2018/1/29 0029
6+
* Time: 23:25
7+
*/
8+
9+
namespace MyLib\Obj\Exception;
10+
11+
/**
12+
* Class PropertyException
13+
* @package MyLib\Obj\Exception
14+
*/
15+
class PropertyException extends \RuntimeException
16+
{
17+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Inhere
5+
* Date: 2018/1/29 0029
6+
* Time: 23:25
7+
*/
8+
9+
namespace MyLib\Obj\Exception;
10+
11+
/**
12+
* Class SetPropertyException
13+
* @package MyLib\Obj\Exception
14+
*/
15+
class SetPropertyException extends \RuntimeException
16+
{
17+
}

src/Obj.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: inhere
5+
* Date: 2017/6/7
6+
* Time: 下午9:39
7+
*/
8+
9+
namespace MyLib\Obj;
10+
11+
use MyLib\Obj\Traits\ObjectPoolTrait;
12+
13+
/**
14+
* Class Obj
15+
* alias of the ObjectHelper
16+
* @package MyLib\Obj
17+
*/
18+
class Obj extends ObjectHelper
19+
{
20+
use ObjectPoolTrait;
21+
22+
/**
23+
* @var array
24+
*/
25+
private static $singletons = [];
26+
27+
/**
28+
* @param string $class
29+
* @return mixed
30+
*/
31+
public static function singleton(string $class)
32+
{
33+
if (!isset(self::$singletons[$class])) {
34+
self::$singletons[$class] = new $class;
35+
}
36+
37+
return self::$singletons[$class];
38+
}
39+
40+
/**
41+
* @param string $class
42+
* @return mixed
43+
*/
44+
public static function factory(string $class)
45+
{
46+
if (!isset(self::$singletons[$class])) {
47+
self::$singletons[$class] = new $class;
48+
}
49+
50+
return clone self::$singletons[$class];
51+
}
52+
53+
/**
54+
* @param $object
55+
* @return bool
56+
*/
57+
public static function isArrayable($object): bool
58+
{
59+
return $object instanceof \ArrayAccess || method_exists($object, 'toArray');
60+
}
61+
}

0 commit comments

Comments
 (0)