Jump to content


IPBWI for Fuel PHP


  • You cannot reply to this topic
10 replies to this topic

#1 neen

    ReConnecter

  • Active Member
  • PipPip
  • 50 posts

Posted 10 May 2011 - 09:02 PM

Hey guys,

I've made some major enhancements to IPBWI and the way it loads classes. My goal here was to adapt the Fuel PHP Coding Standards (in particular, the Naming Conventions). Not only is this good for organization, but it makes the library 100% compatible as a package with Fuel PHP! You can find the code in my repository on GitHub.

Unfortunately at the moment it's only compatible with PHP 5.3+, as I've introduced namespaces into the library. I'll probably make a 5.2 version of the changes I have done and add them to a 5.2 branch.

#2 Matthias Reuter

    Forensklave

  • Admin
  • PipPipPipPipPipPipPipPip
  • 9234 posts
  • Gender:Male
  • Location:Hamburg / Germany

Posted 10 May 2011 - 09:06 PM

Good work! After IPBWI final is released, we should check if a merge of your code is possible without breaking compatibility.

#3 neen

    ReConnecter

  • Active Member
  • PipPip
  • 50 posts

Posted 10 May 2011 - 10:37 PM

Looks like there's a couple bugs I need to resolve. I'm probably going to do a bit of an overhaul to fix these problems. Not sure when they'll be fixed, but hopefully sometime within the next few days.

Edit: I fixed the cache initialization bug, which is the only one I've found so far.

I'd love it if someone could give it a download and let me know if they come across any issues. I updated the examples so they should be working with this new version.

IPBWI seems pretty stable, so for people who are running PHP 5.2, we can probably just have them use the current version and introduce a new version which only works with 5.3 (and has my changes). I see no reason why we can't just make a 3.1 version and make that PHP 5.3+.

I'll still look in to backporting the stuff I've done so far. I have tentative plans to completely overhaul the system and make it far more memory efficient, etc, cause right now it's using about 18mb of memory just to init.

Edited by neen, 10 May 2011 - 11:00 PM.


#4 Matthias Reuter

    Forensklave

  • Admin
  • PipPipPipPipPipPipPipPip
  • 9234 posts
  • Gender:Male
  • Location:Hamburg / Germany

Posted 11 May 2011 - 01:34 AM

View Postneen, on 10 May 2011 - 10:37 PM, said:

IPBWI seems pretty stable, so for people who are running PHP 5.2, we can probably just have them use the current version and introduce a new version which only works with 5.3 (and has my changes). I see no reason why we can't just make a 3.1 version and make that PHP 5.3+.

that's the plan :)

#5 neen

    ReConnecter

  • Active Member
  • PipPip
  • 50 posts

Posted 11 May 2011 - 05:56 AM

Just pushed out a nice update. There's a new config class now, which makes it far easier to overload settings if you ever want to. You can simply instantiate an Ipbwi_Config() like so:

$config = new Ipbwi_Config($config = array('key' => 'foo'));
echo $config->key;
$config->key = 'value';
echo $config->key;


#6 neen

    ReConnecter

  • Active Member
  • PipPip
  • 50 posts

Posted 15 May 2011 - 10:18 AM

I've been going through and making all of the classes singletons, since I really can't see the need to have multiple instances of any class. In addition, I'm storing all of these objects now in a private $loaded_classes array, and I've modified the magic __get() method so it will read the classes out of that array:

		private				$loaded_classes = array();
	
		
		public static function instance() {
			if(!isset(self::$instance)) {
				$class = __CLASS__;
				self::$instance = new $class;
			}
			
			return self::$instance;
		}
		public function __get($name){
			$name = ucfirst($name);
			if(!array_key_exists($name, $this->loaded_classes)) {
				if(!class_exists($name)) {
					$classname = '\Ipbwi\Ipbwi_'.$name;
					$this->loaded_classes[$name] = $classname::instance($this);
				}
			}
			return $this->loaded_classes[$name];
		}

This also means the code to set the config is a bit different now:

\Ipbwi_Config::instance()->set_config($config);

Still not done converting everything over, but when I am I'll push to my git repo. I'll be making a new 3.1 branch for this, and it'll be the default from now on. All of this occurs automatically behind the scenes - all you need to do is simply call $ipbwi->foo and it will instance the foo class for you using the autoloader and the magic __get() method. You can obviously chain methods as seen above.

Edited by neen, 15 May 2011 - 10:40 AM.


#7 Matthias Reuter

    Forensklave

  • Admin
  • PipPipPipPipPipPipPipPip
  • 9234 posts
  • Gender:Male
  • Location:Hamburg / Germany

Posted 15 May 2011 - 05:46 PM

Hi neen,

when you're fnished, I'm looking forward to a benchmark wether your new class loader is faster or not, :) IPBWI actually does not start multiple instances of loaded classes, so I'm eager to see the results of your benchmark.

Thx,
Matthias

#8 neen

    ReConnecter

  • Active Member
  • PipPip
  • 50 posts

Posted 15 May 2011 - 09:32 PM

View PostMatthias Reuter, on 15 May 2011 - 05:46 PM, said:

Hi neen,

when you're fnished, I'm looking forward to a benchmark wether your new class loader is faster or not, :) IPBWI actually does not start multiple instances of loaded classes, so I'm eager to see the results of your benchmark.

Thx,
Matthias
I'm actually aware of that, since it was storing the loaded classes in the IPBWI object. But even so, the main class could have actually been instantiated twice - which would have caused the classes to be loaded once per instance. Part of the reason I'm doing this is because, due to the way FuelPHP works, a singleton is really the best way to provide an interface to the IPBWI class.

Also, since the majority of the classes extend the base IPBWI object, we shouldn't need to pass the IPBWI object around when instantiating those classes, and it's probably a waste of memory to do so (though it is possible there is a legitimate reason for doing so).

Edit: seems like I was right, I've just set the cache class to the new singleton format, without passing the IPBWI object into its constructor, and it's working just fine! :)

Edited by neen, 15 May 2011 - 09:47 PM.


#9 neen

    ReConnecter

  • Active Member
  • PipPip
  • 50 posts

Posted 16 May 2011 - 12:41 AM

Actually, I think I'm going to remove the inheritance all-together. I'll replace it with static calls to the instance() method when I need to do something with an object. I'll probably get rid of the $loaded_classes array too - __get() can just return the instance() directly, since each class will have it's own instance property.

#10 Liens

    Rookie

  • Active Member
  • 5 posts

Posted 04 November 2011 - 01:54 PM

Hello!
Great work :) I like your version of this, because it feels easyer to load into framework.
Im using Yii Framework, and I've started to create Yii extension for Yii to make IPB session connected bridge.

#11 Matthias Reuter

    Forensklave

  • Admin
  • PipPipPipPipPipPipPipPip
  • 9234 posts
  • Gender:Male
  • Location:Hamburg / Germany

Posted 26 November 2011 - 01:34 AM

neen, since PHP 5.2 isn't supported anylonger by PHP group and PHP 5.3 is the new standard, please contact me if you want to stick together to make IPBWI more compatible with your framework.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users