getPackageName example

$request = $this->requestStack->getMainRequest();
        if (!$request) {
            return null;
        }
        $controller = $request->attributes->get('_controller');
        if (!$controller) {
            return null;
        }

        [$controllerClass$_] = explode('::', (string) $controller);

        $package = Package::getPackageName($controllerClass, true);
        if ($package) {
            return $package;
        }

        $controller = $this->container->get($controllerClass, ContainerInterface::NULL_ON_INVALID_REFERENCE);
        if (!$controller) {
            return null;
        }

        return Package::getPackageName($controller::class, true);
    }

    


    /** * @return array<string, array<string, string>> */
    private function getClassesPerArea(): array
    {
        $areas = [];

        foreach ($this->getShopwareClasses() as $class => $path) {
            try {
                $area = Package::getPackageName($class);
            } catch (\Throwable $e) {
                $areas['unknown'][$class] = $path;

                continue;
            }

            if (!\is_string($area)) {
                continue;
            }

            $areaTrim = strstr($area, \PHP_EOL, true) ?: $area;

            

class PackageTest extends TestCase
{
    public function testConstructor(): void
    {
        $package = new Package('test');
        static::assertSame('test', $package->package);
    }

    public function testNonExistingClass(): void
    {
        static::assertNull(Package::getPackageName('asdjkfljasdlkfjdas'));
    }

    public function testNoPackageAttribute(): void
    {
        static::assertNull(Package::getPackageName(NoPackage::class));
    }

    public function testPackage(): void
    {
        static::assertSame('test', Package::getPackageName(WithPackage::class));
    }

    
Home | Imprint | This part of the site doesn't use cookies.