Booleans false negative between controllers and helpers

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
3Di
Registered User
Posts: 11869
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano - Frankfurt
Name: Marco
Contact:

Booleans false negative between controllers and helpers

Post by 3Di » Thu Oct 05, 2017 6:02 am

That's the first time I coded a controller and perhaps I lack of related knowledge for sure.
My search has been exhausting believe me.

p.s.: I solved my use case using $config to achieve my scope, just I need to know the insight of this.

In my helper I have a function

Code: Select all

public function style_badge_is_true()
{
	return file_exists($this->ext_path_web() . 'styles/' . rawurlencode($this->user->style['style_path']) . '/theme/images/tpotm_badge.png');
}
which relies on this function

Code: Select all

public function ext_path_web()
{
	return $this->path_helper->get_web_root_path() . 'ext/threedi/tpotm/';
}
The first function:
returns TRUE if true if dumped within the helper's context (say index/viewforum etc..)
var_dump($this->style_badge_is_true());

but return FALSE if true in my controller's context (say app.php)
var_dump($this->tpotm->style_badge_is_true());

What could it be the error by my side?

services.yml

Code: Select all

services:
    threedi.tpotm.controller:
        class: threedi\tpotm\controller\main
        arguments:
            - '@auth'
            - '@dbal.conn'
            - '@config'
            - '@controller.helper'
            - '@path_helper'
            - '@pagination'
            - '@request'
            - '@template'
            - '@user'
            - '@threedi.tpotm.tpotm'
            - '%core.php_ext%'
            - '%core.root_path%'

    threedi.tpotm.listener:
        class: threedi\tpotm\event\listener
        arguments:
            - '@controller.helper'
            - '@template'
            - '@user'
            - '%core.php_ext%'
            - '@threedi.tpotm.tpotm'

        tags:
            - { name: event.listener }

    threedi.tpotm.tpotm:
        class: threedi\tpotm\core\tpotm
        arguments:
            - '@auth'
            - '@cache'
            - '@config'
            - '@dbal.conn'
            - '@user'
            - '@path_helper'
            - '%core.root_path%'
            - '%core.php_ext%'
            - '@template'
routing.yml

Code: Select all

threedi_tpotm_controller:
    path: /tpotm/{name}
    defaults: { _controller: threedi.tpotm.controller:handle }
TIA.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades

User avatar
Ger
Registered User
Posts: 1155
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Booleans false negative between controllers and helpers

Post by Ger » Thu Oct 05, 2017 12:49 pm

Checkout my extensions: Simple CMS, Feed post bot, Modbreak, Magic OGP links and Live topic update

Like my work? Buy me a coffee to keep it coming. :ugeek:

User avatar
3Di
Registered User
Posts: 11869
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano - Frankfurt
Name: Marco
Contact:

Re: Booleans false negative between controllers and helpers

Post by 3Di » Thu Oct 05, 2017 1:07 pm

Nope, I am using config actually.
Investigating.. with file_exists() returns FALSE if TRUE in both sides. :? Also with DAE.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades

User avatar
Ger
Registered User
Posts: 1155
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Booleans false negative between controllers and helpers

Post by Ger » Thu Oct 05, 2017 1:29 pm

What do you mean exactly with
FALSE if TRUE
Checkout my extensions: Simple CMS, Feed post bot, Modbreak, Magic OGP links and Live topic update

Like my work? Buy me a coffee to keep it coming. :ugeek:

User avatar
3Di
Registered User
Posts: 11869
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano - Frankfurt
Name: Marco
Contact:

Re: Booleans false negative between controllers and helpers

Post by 3Di » Thu Oct 05, 2017 1:44 pm

The file exists with the right name so is TRUE .. because I know and because also the second method stores the correct result in $config..

Code: Select all

public function style_badge_exists()
{
	return file_exists(generate_board_url() . '/ext/threedi/tpotm/styles/' . rawurlencode($this->user->style['style_path']) . '/theme/images/tpotm_badge.png');
}

public function check_point_badge_img()
{
	/* If Img badge filename mistmach error, state is false and return */
	if (!$this->style_badge_exists())
	{
		$this->config->set('threedi_tpotm_badge_exists', 0);
		return;
	}
	else
	{
		/* Check passed, let's set it back to true. */
		$this->config->set('threedi_tpotm_badge_exists', 1);
	}
}
Hence I am relying on the Config.. that's true if true and false if false.. (the image is shown and if renamed fails the display.. ofcourse

Code: Select all

public function style_badge_is_true()
{
	return ($this->config['threedi_tpotm_badge_exists']) ? true : false;
}
but if I use
var_dump($this->tpotm->style_badge_exists()); helper/listener

or
var_dump($this->style_badge_exists()); app.php

which uses file_exists() it returns FALSE also if TRUE.

if I use the method style_badge_is_true() instead return always the truth in both situations.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades

User avatar
Ger
Registered User
Posts: 1155
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Booleans false negative between controllers and helpers

Post by Ger » Thu Oct 05, 2017 2:32 pm

I see. Keep in mind: generate_board_url() returns a full URL, e.g.: http://www.example.com/phpBB.
file_exists may not be used with with http wrappers, depending on your server config of allow_url_fopen.

I wouldn't use generate_board_url() in this case. IMO, you have 2 different things here:
1. Check if a file exists (style_avatar_is_true)
2. Output a valid image source to the browser (style_avatar)

For 1. I'd use a filepath, something you can do like I saw on Github this morning:

Code: Select all

		return (file_exists($this->ext_root_path . 'styles/' . rawurlencode($this->user->style['style_path']) . '/theme/images/dae_noavatar.png') && file_exists($this->ext_root_path . 'styles/' . rawurlencode($this->user->style['style_path']) . '/theme/images/dae_noavatar_medium.png') && file_exists($this->ext_root_path . 'styles/' . rawurlencode($this->user->style['style_path']) . '/theme/images/dae_noavatar_full.png')) ? true : false;
For 2. I'd use the generate_board_url() approach like I explained in the other topic.
Checkout my extensions: Simple CMS, Feed post bot, Modbreak, Magic OGP links and Live topic update

Like my work? Buy me a coffee to keep it coming. :ugeek:

User avatar
3Di
Registered User
Posts: 11869
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano - Frankfurt
Name: Marco
Contact:

Re: Booleans false negative between controllers and helpers

Post by 3Di » Thu Oct 05, 2017 2:52 pm

Yes, the DAE extension has been fixed 10 minutes ago with the same approach. It's finished 100% now and already pushed, thx. :)

Code: Select all

	public function style_avatar_is_true()
	{
		$ext_path = $this->ext_root_path . 'styles/' . rawurlencode($this->user->style['style_path']) . '/theme/images/dae_noavatar';

		return (file_exists($ext_path . '.png') && file_exists($ext_path . '_medium.png') && file_exists($ext_path . '_full.png')) ? true : false;
	}
The issue is with TPOTM actually, I am investigating on the services atm.
Also if using the configs solves my issue, the question is why happens. :geek:
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades

User avatar
3Di
Registered User
Posts: 11869
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano - Frankfurt
Name: Marco
Contact:

Re: Booleans false negative between controllers and helpers

Post by 3Di » Fri Oct 06, 2017 3:29 am

I would like to say thank you Ger, I did appreciate your efforts here and there.
It is everything all right now. Hopefully :lol: :geek:
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades

User avatar
Ger
Registered User
Posts: 1155
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Booleans false negative between controllers and helpers

Post by Ger » Fri Oct 06, 2017 7:04 am

Great :)
Checkout my extensions: Simple CMS, Feed post bot, Modbreak, Magic OGP links and Live topic update

Like my work? Buy me a coffee to keep it coming. :ugeek:

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 4 guests