Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4076046
D3215.id8233.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D3215.id8233.diff
View Options
diff --git a/omnitools/src/Reflection/CodeClass.php b/omnitools/src/Reflection/CodeClass.php
--- a/omnitools/src/Reflection/CodeClass.php
+++ b/omnitools/src/Reflection/CodeClass.php
@@ -21,6 +21,27 @@
) {
}
+ public static function from (object $object) : self {
+ return new self($object::class);
+ }
+
+ ///
+ /// Class name helper methods
+ ///
+
+ public function getClassName () : string {
+ return $this->className;
+ }
+
+ /**
+ * @throws ReflectionException
+ */
+ public function getShortClassName () : string {
+ $class = new ReflectionClass($this->className);
+
+ return $class->getShortName();
+ }
+
///
/// Represented class constructor helper methods
///
diff --git a/omnitools/tests/Reflection/CodeClassTest.php b/omnitools/tests/Reflection/CodeClassTest.php
--- a/omnitools/tests/Reflection/CodeClassTest.php
+++ b/omnitools/tests/Reflection/CodeClassTest.php
@@ -23,6 +23,20 @@
$this->class = new CodeClass(AcmeApplication::class);
}
+ public function testGetClassName () {
+ $this->assertEquals(
+ AcmeApplication::class,
+ $this->class->getClassName(),
+ );
+ }
+
+ public function testGetShortClassName () {
+ $this->assertEquals(
+ "AcmeApplication",
+ $this->class->getShortClassName(),
+ );
+ }
+
public function testNewInstanceFromServices () {
$services = [
// Some objects (in different order than the constructor)
@@ -104,4 +118,5 @@
$class->getConstructor();
}
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 31, 04:42 (6 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2387416
Default Alt Text
D3215.id8233.diff (1 KB)
Attached To
Mode
D3215: Get class name with or without namespace
Attached
Detach File
Event Timeline
Log In to Comment