Coder Social home page Coder Social logo

bucket's People

Contributors

ikke avatar lsolesen avatar troelskn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bucket's Issues

bucket_Container::set() lowercases the classname

When setting an instance with bucket_Container::set(), the classname is lowercased and then stored in bucket_Scope::$instances. But since bucket_Container::get() doesn't lowercase the classname, the instance you set isn't found, and a new instance is created instead.

Non-object parameters

Am I correct in understanding that any class that has an array or string parameter would require its own factory? (i.e. there's no way to say: when instantiating PageController use $config for the parameter 'config'?)

Tests are failing - did they ever pass

codio@float-dance:~/workspace/bucket$ php bucket.test.php                       
bucket.test.php                                                                 
1) Exception [ReflectionException: Class ClassThatDoesntExist does not exist] sh
ould be type [TriedToAutoloadException] at [/home/codio/workspace/bucket/bucket.
test.php line 105]                                                              
        in test_undefined_class_triggers_autoload                               
        in TestOfBucketAutoload                                                 
Exception 1!                                                                    
Unexpected exception of type [ReflectionException] with message [Class ClassThat
DoesntExist does not exist] in [/home/codio/workspace/bucket/lib/bucket.inc.php 
line 146]                                                                       
        in test_undefined_class_triggers_autoload                               
        in TestOfBucketAutoload                                                 
Exception 2!                                                                    
Unexpected exception of type [ReflectionException] with message [Class ClassThat
DoesntExist does not exist] in [/home/codio/workspace/bucket/lib/bucket.inc.php 
line 146]                                                                       
        in test_autoload_gets_canonical_classname                               
        in TestOfBucketAutoload                                                 
FAILURES!!!                                                                     
Test cases run: 5/5, Passes: 27, Failures: 1, Exceptions: 2  

The need of calling " $bucket->create('Cuux');"?

Hi Troelskn,

Firstly, thanks a lot for your great work with Bucket. I downloaded the last version as of today and tried your example code as below:

$bucket = new bucket_Container();
$bucket->registerImplementation('Zap', 'Foo');
$cuux = $bucket->get('Cuux');
var_dump($bucket);

Result from var_dump:
protected 'instances' =>
array
'foo' =>
object(Foo)[12]
...
'cuux' =>
object(Cuux)[11]
...

Shouldn't I need to call $bucket->create('Cuux'); before or does it autocreate the object properly if it doesn't exist when running $bucket->get('Cuux')?

Thanks!

Change method_exists to is_callable for factory

I'm creating an application that will use self-contained modules, and each module would have it's own factory class. The factory I will pass to Bucket will basically be a proxy to the module factories through __call. But since Bucket uses method_exists and not is_callable, that can't be done. How about changing method_exists to is_callable?

Make it self aware

I have extended bucket to be "self aware" and in my case act as a singelton and be able to insert itself as a parameter when creating instances - maybe something you would consider adding to the source?

PHP 5.3 Namespace compability

Just wondering if there is some plan on making it compatible with PHP 5.3 namespaces?

There are some issues with relative vs absolute scope (which can be overcome) but the main issue is with the factory calls (cant make a new_\My\Name\Space\Class function). Without a proper rewrite there are two quick ways to resolve this:

  1. Translate the namespace separator to something else - in this case '_':
function create($classname) {
    $classname = $this->scope->getImplementation($classname);
    $funcname=strtr($classname,'\\','_');
    if (isset($this->factory->{'new_' . strtolower($funcname)})) {
      return call_user_func($this->factory->{'new_'.$funcname}, $this);
    }
    if (method_exists($this->factory, 'new_' . $funcname)) {
      return $this->factory->{'new_'.$funcname}($this);
    }
    return $this->createThroughReflection($classname);
}
  1. Instead of checking for the existence of the 'new_' function call it and require the factory to have a __call catchall method that either handles the classname conversion or returns false.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.