Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending Honeypot #41

Open
hoppities opened this issue Dec 9, 2015 · 2 comments
Open

Extending Honeypot #41

hoppities opened this issue Dec 9, 2015 · 2 comments

Comments

@hoppities
Copy link

I'm trying to extend Honeypot, and I'm running into issues.

I created my service provider, and that works fine, but I can't seem to call the parent class methods.

<?php

namespace App\Extensions;

use Honeypot;

class MyHoneypot extends Honeypot
{
/**
 * Generate a new honeypot and return the form HTML
 * @param  string $honey_name
 * @param  string $honey_time
 * @return string
 */
public function generate(array $honey_name, array $honey_time)
{
    $honey_time_encrypted = parent::getEncryptedTime();
    // Encrypt the current time

    $html = '<div id="' . $honey_name . '_wrap" style="display:none;">' . "\r\n" .
                '<input name="' . $honey_name . '" type="text" value="" id="' . $honey_name . '"/>' . "\r\n" .
                '<input name="' . $honey_time . '" type="text" value="' . $honey_time_encrypted . '"/>' . "\r\n" .
            '</div>';

    return $html;
}
}

I get the error Call to undefined method App\Extensions\MyHoneypot::getEncryptedTime().

I also attempted to use Msurguy\Honeypot, but that, too, failed. It could not find the class.

Any thoughts why?

@garygreen
Copy link
Contributor

Try the following:

namespace App\Extensions;

use Msurguy\Honeypot\Honeypot as BaseHoneypot;

class Honeypot extends BaseHoneypot
{

    public function generate(array $honey_name, array $honey_time)
    {
        $honey_time_encrypted = parent::getEncryptedTime();
        //
        //....
        //....
    }

}

You will also need to replace the resolved instance in the IOC. A good place to put this is in your own service provider which is included after HoneypotServiceProvider in your app.php:

app()->singleton('honeypot', 'App\Extensions\Honeypot');

If you have any further questions it's probably best asking on Stackoverflow as this stuff isn't really specific to honeypot but more of an understanding of namespaces and Laravel's IOC.

@hoppities
Copy link
Author

Ah! Of course...thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants