Jump to content

3rd Party Framework


3KyNoX

Recommended Posts

Hello !

Following currently Plugin Creation and The Autoloader, and got some difficulties to find out how to load a 3rd party framework.

I know new 4.x guides are in hard writing, but end of Autoloader Guide is quite small.

To explain what I'm doing, I need to uses PhealNG framework inside my plugin, so I :

  • Created a Code Hook
  • Installed PhealNG with composer in system/3rd_party/phealng
    • Inside that folder, I got the vendor folder
      • vendor-> autoload.php (that loads all other classes)
  • Used->
    \IPS\IPS::$PSR0Namespaces['phealng'] = \IPS\ROOT_PATH . '/system/3rd_party/phealng/vendor/autoload.php';

          in my hook.

  • Anf don't know what to do next

It looks like when I call :

use Pheal\Pheal;
$pheal = new Pheal();

It throw an Exception.

Using IPS 4.0.5.1.

Any advices please ?

Link to comment
Share on other sites

Thanks for reply.

I must do something wrong.

First, code can be found here -> PhealNG Framework

I made it work with a simple php page.

Inside IPB I made a code hook following tutorial and tried to link autoload.php inside vendor folder.

calling Pheal throw an error, same if I move alone ...

\IPS\IPS::$PSR0Namespaces['phealng'] = \IPS\ROOT_PATH . '/system/3rd_party/phealng/vendor/autoload.php';

Inside the class, throw too an error.

95b754f51e.png

I tried to load autoload.php manually after upload of framework inside ../plugins/EvEBridge/hooks  :

require_once 'vendor/autoload.php';

throwing error page since call.

 

I hope more details are given and thanks in advance for help.

Link to comment
Share on other sites

Hello again,

I first gives some apologies, because I'm a .Net developer and while object programming concepts is aquired, php syntax is not perfectly known in the present day.

I tried to extend a method in the left column in developer center, and while declaring call of the framework before the _hook class (just after //<?php)

\IPS\IPS::$PSR0Namespaces['phealng'] = \IPS\ROOT_PATH . '/system/3rd_party/phealng/vendor/autoload.php';
use Pheal\Pheal

I create a object instance inside the extended method :

$pheal = new Pheal();

No error is this time shown. But it looks like my object instance is not usable, because if I remove first 2 lines calling framework, my object instance do not throw an error alone too.

Not sure if it's well explained;

http://puu.sh/hSMOn/59bbe4ead1.png <--- Works with no error, and it's not normal, because framework not called.

---------------------------------------

Anyway, I tried to take the problem differently and try to get access to my framework classes manually.

I this time created a Theme Hook (like on the plugin tutorial example "core --> front: global -> globalTemplate")

I inserted globalMessage div content:

<div class="ipsMessage ipsMessage_information">This is the global message.</div>

and using my ftp client, I edited manually the hook file to call framework:

//<?php
require_once 'vendor/autoload.php';

class hook24 extends _HOOK_CLASS_
{
/* !Hook Data - DO NOT REMOVE */
public static function hookData() {
 return array_merge_recursive( array (
  'globalTemplate' => 
  array (
    0 => 
    array (
      'selector' => '#ipsLayout_mainArea',
      'type' => 'add_inside_start',
      'content' => '<div class="ipsMessage ipsMessage_information">This is the global message.</div>',
    ),
  ),
), parent::hookData() );
}
/* End Hook Data */
}

I surely uploaded my framework vendor/ folder inside my hooks folder.

But when loading IPB front page, "vendor/autoload.php" is not found -> http://puu.sh/hSNtd/02f33baeaa.png

So, I'm blocked now and not sure what do do next, so if more support is possible, it would be greatly appreciated.

Link to comment
Share on other sites

\IPS\IPS::$PSR0Namespaces['phealng'] = \IPS\ROOT_PATH . '/system/3rd_party/phealng/vendor/autoload.php';

this is the problem itself, sorry for not spotting it sooner. you are simply supposed to provide the base path to the psr-0 compatible library, not call their autoloader, also the array key is the namespace's first 'bit', so...

\IPS\IPS::$PSR0Namespaces['Pheal'] = \IPS\ROOT_PATH . '/system/3rd_party/phealng/';

such is the beauty of the psr-0 standard, this is enough for the IPS autoloader to figure it out based on the class name called.... as support for such is baked in, the autoloader composer provides is strictly not needed.

Link to comment
Share on other sites

Ok trying this, you do not have to be sorry for anything, help is gratefull.

Maybe you have a suggestion to test it out the content of a variable to see if everything is ok ? (still caused by my lack of knowing ipb system and classes correctly).

Like show a popup with the display of this var content when extending a action button method of a specific class ?

 

EDIT :

Used new IPS call : http://puu.sh/hSTsz/8438ccb1ad.png

As it don't show code error from developer center, now forum index page shows : http://puu.sh/hSTzd/4605936390.png

phealng folder Permissions are set to 777 recursively for testing purpose and path is correct : http://puu.sh/hSTC3/964d28095c.png

Link to comment
Share on other sites

Ok got it, your answer puts me on right way, correct path was :

\IPS\IPS::$PSR0Namespaces['Pheal'] = \IPS\ROOT_PATH . '/system/3rd_party/phealng/vendor/3rdpartyeve/phealng/lib/Pheal/';

using that path, I was able to print some output.

Next steps will be find out what class / method to extend to modify registration form and user cp. I will maybe create another topic about that.

Thanks a lot for your help ! :)

Link to comment
Share on other sites

Hello,

My test forum did not liked that, white pages shown. No error shown.

​​Because constant \IPS\ROOT_PATH is not defined

init.php

		/* Load constants.php */
		if( file_exists( __DIR__ . '/constants.php' ) )
		{
			@include_once( __DIR__ . '/constants.php' );
		}
				
		/* Import and set defaults */
		$defaultConstants = static::defaultConstants();

		foreach ( $defaultConstants as $k => $v )
		{
			if( defined( $k ) )
			{
				define( 'IPS\\' . $k, constant( $k ) );
			}
			else
			{
				define( 'IPS\\' . $k, $v );
			}
		}

Your code runs before the constant \IPS\ROOT_PATH will be defined

Link to comment
Share on other sites

Thanks a lot. Corrected path, and it works. Assuming constants.php is already in the root path :

\IPS\IPS::$PSR0Namespaces['Pheal'] = '/system/3rd_party/phealng/vendor/3rdpartyeve/phealng/lib/Pheal/';
use Pheal\Pheal;

Now, still from plugin example, in modified template \IPS\Theme\class_core_front_global:

{{$pheal = new \Pheal\Pheal();}}
{{$response = $pheal->serverScope->ServerStatus();}}
<div class="ipsMessage ipsMessage_information">{{echo $response->onlinePlayers;}}</div>

Displays correctly online players number, but why a simple 'echo' statement make the front page displays without css decorating :

a856bcb320.png

Thanks for further help.

 

Link to comment
Share on other sites

Ok got it, double {{ }} and echo is not needed here, this lines done the job:

{{$pheal = new \Pheal\Pheal();}}
{{$response = $pheal->serverScope->ServerStatus();}}
<div class="ipsMessage ipsMessage_information">There is {$response->onlinePlayers} players online.</div>

 

Link to comment
Share on other sites

Finally no, it don't work, explaining myself.
It was working because I'm having currently two plugin hooks.

  1. The Theme Hook like on the plugin tutorial example -> \IPS\Theme\class_core_front_global
    1. {{$pheal = new \Pheal\Pheal();}}
      
      {{$response = $pheal->serverScope->ServerStatus();}}
      
      <div class="ipsMessage ipsMessage_information">The servers are currently {$scope->serverOpen ? "open" : "closed"} and there is currently {$scope->onlinePlayers} players online.</div>
      
  2. And a code hook with call to my framework inside -> \IPS\Login
    1. //<?php
      \IPS\IPS::$PSR0Namespaces['Pheal'] = \IPS\ROOT_PATH . '/system/3rd_party/phealng/vendor/3rdpartyeve/phealng/lib/Pheal/';
      use Pheal\Pheal;
      class hook12 extends _HOOK_CLASS_
      {
        public function __construct( \IPS\Http\Url $url )
        {
          $pheal = new Pheal();
          $response = $pheal->serverScope->ServerStatus();
          return call_user_func_array( 'parent::__construct', func_get_args() );
        }
      }

       

Because I was not logged in on my forums, and the presence of the code hook (with my framework call inside), it displayed my variables correctly in front page.

But once I log-in or I deleted my code hook, I get back error -> Class 'Pheal\Pheal' not found.

Meaning my code inside contants.php is not used for whole project and my theme hook so.

Here is the content of constants.php:

<?php
define( 'IN_DEV', TRUE );
\IPS\IPS::$PSR0Namespaces['Pheal'] = '/system/3rd_party/phealng/vendor/3rdpartyeve/phealng/lib/Pheal/';
use Pheal\Pheal;

Thanks for any further help.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...