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

Editing Factory.php when implementing custom adapter #124

Closed
sadreck opened this Issue Nov 5, 2017 · 10 comments

Comments

Projects
None yet
2 participants
@sadreck

sadreck commented Nov 5, 2017

Hi,

I've implemented a custom adapter to support remotepassword.com (so that I don't have to hardcode a password in the XML file), but in order to make it work I had to add to update Factory.php as well.

Code is here: https://github.com/sadreck/phpbu/blob/1f79ec45ebe18052514942ddd9bdd5d8be8bc04f/src/Factory.php#L37

The documentation says that you only need the file in /Adapter but that didn't seem to work for me. Is this a bug or am I missing something obvious?

Thanks,
Pavel

@sebastianfeldmann

This comment has been minimized.

Owner

sebastianfeldmann commented Nov 5, 2017

To use a custom Adapter you have to register it at the Factory.
This is done by using a bootstrap php file.

<phpbu bootstrap="init.php">

And within your bootstrap file register the Adapter.

<?php
use phpbu\App\Factory;
use phpbu\App\Adapter\RPass;

require 'vendor/autoload.php';

Factory::register('adapter', 'rpass', RPass::class);

With this you can put the Adapter in any namespace or directory you want.

<?php
use phpbu\App\Factory;
use My\Name\Space\RPass;

require 'vendor/autoload.php';

Factory::register('adapter', 'rpass', RPass::class);
@sadreck

This comment has been minimized.

sadreck commented Nov 5, 2017

Hi,

Thanks for the quick response.

I'm now using the bootstrap attribute but the file is never executed (even if I just put a die() statement there). Here's my XML:

<?xml version="1.0" encoding="UTF-8"?>
<phpbu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="http://schema.phpbu.de/5.0/phpbu.xsd" bootstrap="/home/pavel/dev/phpbu/src/init.php">
    <adapters>
        <adapter type="rpass" name="rpass">
            <option name="gpgPath" value="/usr/bin/gpg"></option>
        </adapter>
    </adapters>
    <backups>
        <backup>
            <!-- source -->
            <source type="mysqldump">
                <option name="databases" value="rpass2"/>
                <option name="user" value="pavel"/>
                <option name="password" value="adapter:rpass:z0Przsb8HtP1AE07BeulDwJ4NOVWxb16cRyLjJU1dK3No3V0hqlVW5ZJTVGq6Hxi29787f0c81a64f625b0f6dd0570412adb15754647aa9f846c4084162e0877396|A654B4F3"/>
            </source>
            <!-- where should the backup be stored -->
            <target dirname="backup/mysql"
                    filename="mysqldump-%Y%m%d-%H%i.sql"
                    />
        </backup>
    </backups>
</phpbu>

Even when I run ./phpbu --bootstrap=file (file has a die() statement) I get:

./phpbu --configuration=sample.xml --bootstrap=/home/pavel/dev/phpbu/src/init.php
phpbu 5.0-dev by Sebastian Feldmann and contributors.

unknown adapter: rpass

I've tried seeing where it dies out and it's in https://github.com/sebastianfeldmann/phpbu/blob/master/src/Configuration/Loader/File.php#L73

I believe it breaks due to the tag where I set the options.

Thanks,
Pavel

@sebastianfeldmann

This comment has been minimized.

Owner

sebastianfeldmann commented Nov 5, 2017

oO, I will look right into this ... tomorrow morning

@sebastianfeldmann

This comment has been minimized.

Owner

sebastianfeldmann commented Nov 7, 2017

Which version of phpbu are you using?

I tried this configuration

<?xml version="1.0" encoding="UTF-8"?>
<phpbu bootstrap="backup/bootstrap.php" verbose="false">

with this bootstrap file

<?php
// bootstrap demo file
echo "foo\n";
exit(1);

and this is the output I get

$ phpbu
phpbu 5.0.7 by Sebastian Feldmann and contributors.

foo

If I change the xml config to an invalid file I get the following output.

$ phpbu
phpbu 5.0.7 by Sebastian Feldmann and contributors.

Cannot open bootstrap file "/Users/sf/development/php/phpbu/backup/bootstrapp.php".

@sebastianfeldmann sebastianfeldmann self-assigned this Nov 7, 2017

@sadreck

This comment has been minimized.

sadreck commented Nov 8, 2017

Hi Sebastian,

sorry for the delay. I'm using 5.0.7 and here's what I have confirmed at the moment.

When I set an actual password it works (I get "foo"):

<option name="password" value="test"/>

When I use any adapter for the password, it doesn't (no "foo" for me!).

<option name="password" value="adapter:rpass:somevalue"/>

Thanks,
Pavel

@sebastianfeldmann

This comment has been minimized.

Owner

sebastianfeldmann commented Jan 12, 2018

You are sorry... what should I be, I totally overlooked this the whole time.

Shame on me.

Did you manage to make sure your bootstrap file is executed with something similar what I posted above?

<?php
// bootstrap demo file
echo "foo\n";
exit(1);
@sebastianfeldmann

This comment has been minimized.

Owner

sebastianfeldmann commented Jan 12, 2018

Forget what I said, I can reproduce your error now.

It's a chicken and egg problem.

Currently I create the configuration and setup the adapters first.
And then load the bootstrap file.
Obviously that doesn't work for Adapters because they are needed to create the Configuration in the first place.

So ... I have to restructure some things and will fix this as soon as possible.

sebastianfeldmann added a commit that referenced this issue Jan 13, 2018

Handle bootstrap before config creation - issue #124
Bootstrapping and config creation is kind of a chicken and egg
problem. To actually use a custom adapter the bootstrap file has
to be loaded before creating the configuration.

So from now on all config loader have to use the new Bootstrapper
to handle the bootstrap loading before creating the actual
configuration instance.
@sebastianfeldmann

This comment has been minimized.

Owner

sebastianfeldmann commented Jan 13, 2018

Ok I just released phpbu 5.0.9 including a bugfix for this problem.
The bootstrap file is no included before creating the configuration.
No custom Adapters should work as well.

@sadreck

This comment has been minimized.

sadreck commented Jan 14, 2018

Thank you Sebastian, works like a charm now!

Pavel

@sebastianfeldmann

This comment has been minimized.

Owner

sebastianfeldmann commented Jan 14, 2018

No worries, it took me way too long to recognize the severity of your problem and that it was an error on my side.

Thank you for letting me know that it works and reporting it in the first place.
I really appreciate it.

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