Skip to content

Issue Extend Core Class #1653

Description

@Iamscalla

There's an issue with getsharedinstance while extend the core class.
prior to the last major change on Autoload and Baseservice, it was all Good.

for instance i extended the view class and used the extended service as follows,
$renderer = Services::renderer($path, null, true);

i still get a call to the core class lib instead of the extended lib.
screenshot_2019-01-06 error

<?php

namespace App\Libraries\View;

use Config\Services;
use CodeIgniter\View\View as BaseView;

class View extends BaseView
{

	/**
	* Check if the view exist
	*
	* @param  string $view
	* @return boolean
	*/
	public function exists(string $view): bool
	{
		$fileExt  = pathinfo($view, PATHINFO_EXTENSION);
		$realPath = empty($fileExt) ? $view . '.php' : $view;
		$file = $this->viewPath . $realPath;
		if (! file_exists($file))
		{
			$file = $this->loader->locateFile($view, 'Views');
		}
		if (empty($file))
		{
			//log_message('error', "{$view} view is not found");
			return false;
		}
		return true;
	}
}

then i extended the render service as shown below

public static function renderer($viewPath = null, $config = null, bool $getShared = false)
	{
		if ($getShared)
		{
			return static::getSharedInstance('renderer', $viewPath, $config);
		}

		if (is_null($config))
		{
			$config = new \Config\View();
		}

		if (is_null($viewPath))
		{
			$paths = config(Paths::class);

			$viewPath = $paths->viewDirectory;
		}
		return new \App\Libraries\View\View(
			$config,
			$viewPath,
			static::locator(true), CI_DEBUG,
			static::logger(true)
		);
	}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions