Lithium 101

Lithium101 is an unofficial community resource for the Lithium PHP framework indexing articles, tutorials, code snippets and libraries.

Libraries

Tracking 261 plugins, categorised and sorted. If you are the plugin owner you can edit the status and category.

Snippets

So far there are 54 Lithium related snippets. It's super easy to add your gists as snippets on the site, if there is anything you think might be interesting or helpful take a minute to share it.

Latest Activity

Add exists method to Filesystem

It is useful to know whether a file exists on the file system

mariuskubilius/li3_filesystem currently has:

Notice on end of maintenance.

  • README.md had +2 additions and -0 deletions.
6 days ago gavD created a comment about an issue in cgarvis/li3_aws
6 days ago gavD opened a pull request in cgarvis/li3_aws

Implement S3 deletion

* Wrapping S3 API's delete_object method * Update tests - change to the {bucket}.{region} format requested by S3 * Add test coverage for delete method - check that when a file is removed from S3 it subsequently 403s Note that to run the tests I replaced $configuration with my own bucket configuration.
6 days ago gavD forked cgarvis/li3_aws

cgarvis/li3_aws currently has:

6 days ago davidpersson pushed to UnionOfRAD/li3_cldr

Drop usage of --O for curl output.

7 days ago nateabele created a comment about an issue in UnionOfRAD/lithium

Cannot get connection to work when using multiple keys for environments

Look at the call trace, figure out where the call to the database is coming from, and, wherever the stack leaves your code and enters the framework, log to make sure the environment is correct. If the database works without an environment configuration, then this is the problem. nateabele
7 days ago ThomasWunderlich started watching notomato/li3_vagrant

notomato/li3_vagrant currently has:

10 days ago Siraris created a comment about an issue in UnionOfRAD/lithium

Cannot get connection to work when using multiple keys for environments

@nateabele So a lot of this involves trying to run a test on my users controller, and it seems that even though the tests run now without the original error, it's still not behaving as expected. When I output Environment::get() in my setUp method in my controller test, it outputs "test". When I output the available connections, it shows default and test. When I output Connections::get("test") it shows the correct connection info, but when I run my actual test (to create a user and then to remove the user collection on tearDown) it operates on the default connection settings. I'm clearly doing something very wrong here, but based on documentation, I have no idea what more could be wrong. Siraris
10 days ago Siraris created a comment about an issue in UnionOfRAD/lithium

Cannot get connection to work when using multiple keys for environments

@nateabele Two things. 1. The Environment::is with a closure never seems to work for me. I placed the following: lithium\core\Environment::is(function($request){ $host = $request->env('HTTP_HOST'); if ($host == 'project.local' || $host == 'localhost') { return 'development'; } if (preg_match('/test/', $host)) { return 'test'; } if (preg_match('/^qa/', $host)) { return 'qa'; } if (preg_match('/beta/', $host)) { return 'staging'; } return 'production'; }); in the library bootstrap file and it never seems to fire. It seems strange to me that without that code, the framework would return an empty string for the environment. Is this normal behavior or is something else misconfigured? 2. Even though this works now when I explicitly set the environment to development in the libraries bootstrap, it seems that the Connections::add call I have above doesn't work. I have to say Connections::add("default") and Connections::add("test") in two separate calls. That nested array doesn't work. Is that antiquated? I found it http://nitschinger.at/Using-Environments-in-Lithium here I believe. Siraris
10 days ago adallaway opened an issue in UnionOfRAD/lithium

Media::encode() causes $data objects that implement JsonSerializer to json_encode incorrectly.

Media::encode() casts objects in the view data to arrays. This prevents **jsonSerialize()** from being called on objects that implement **JsonSerializable**. I'm not sure if this is intended behavior but here's a possible fix: https://github.com/UnionOfRAD/lithium/blob/master/net/http/Media.php#L766 ```php if ($data instanceof \JsonSerializable)) { return $data; } ``` As a workaround, a dummy **to()** method can be added to the objects: ```php public function to() { return $this; } ```
10 days ago nateabele closed an issue in UnionOfRAD/lithium

Cannot get connection to work when using multiple keys for environments

Whenever I try to define multiple environments for my default connection, I get the following error: PHP Fatal error: Uncaught exception 'lithium\\core\\ConfigException' with message 'No adapter set for configuration in class `lithium\\data\\Connections` My connection is defined as follows: Connections::add('default', array( 'development' => array( 'type' => 'MongoDb', 'host' => 'localhost', 'database' => 'dev' ), 'test' => array( 'type' => 'MongoDb', 'host' => getenv("MONGO_IPADDRESS"), 'database' => 'test' ), 'production' => array( 'type' => 'MongoDb', 'host' => getenv("MONGO_IPADDRESS"), 'database' => $_SESSION['settings']->company_short ) )); in my connections bootstrap file. I have tried for 2 weeks to get this to work and no matter what I do, unless I hardcode the environment in a bootstrap file, it always throws the above error. If I define one default connection (Connections::add('default', array('type'=>'MongoDb', 'host'=>'localhost', 'database'=>'blah') it works fine. I'm desperate for help.
10 days ago nateabele created a comment about an issue in UnionOfRAD/lithium

Cannot get connection to work when using multiple keys for environments

Most likely the environment is either not being specified, or is being specified after your application's first attempt to access the database. To verify, call `lithium\core\Environment::set("development")` immediately after including `libraries.php` in your bootstrap. This should fix it. For a proper implementation, see the docs for `Environment::is()`: http://li3.me/docs/lithium/core/Environment::is() nateabele
11 days ago Siraris opened an issue in UnionOfRAD/lithium

Cannot get connection to work when using multiple keys for environments

Whenever I try to define multiple environments for my default connection, I get the following error: PHP Fatal error: Uncaught exception 'lithium\\core\\ConfigException' with message 'No adapter set for configuration in class `lithium\\data\\Connections` My connection is defined as follows: Connections::add('default', array( 'development' => array( 'type' => 'MongoDb', 'host' => 'localhost', 'database' => 'dev' ), 'test' => array( 'type' => 'MongoDb', 'host' => getenv("MONGO_IPADDRESS"), 'database' => 'test' ), 'production' => array( 'type' => 'MongoDb', 'host' => getenv("MONGO_IPADDRESS"), 'database' => $_SESSION['settings']->company_short ) )); in my connections bootstrap file. I have tried for 2 weeks to get this to work and no matter what I do, unless I hardcode the environment in a bootstrap file, it always throws the above error. I'm desperate for help.
12 days ago blubear83 started watching UnionOfRAD/lithium

UnionOfRAD/lithium currently has:

13 days ago alexbowers-tecmark created a comment about an issue in UnionOfRAD/lithium

Packagist use git instead of https

This is still not solved. Still clones rather than caching @nateabele @davidpersson alexbowers-tecmark
18 days ago quent01 started watching UnionOfRAD/lithium

UnionOfRAD/lithium currently has:

20 days ago carlhaynes started watching UnionOfRAD/lithium

UnionOfRAD/lithium currently has:

Enhance Auth Form adapter

As of now it is very hard to bind a model to a login form when using Auth/Form as the Form adapter has no way to read sub array data. This enhancement makes the Form adapter check if a sub array matching the models name exists and if so use it for `Auth::check()` ```php <?= $this->form->create($user); ?> <?= $this->form->text('user.username'); ?> <?= $this->form->password('user.password'); ?> <?= $this->form->end(); ?> ```
21 days ago markwilde closed an issue in UnionOfRAD/li3_queue

implement pub/sub with ampq

@markwilde any suggestion to implement pub/sub for ampq adapter, for each queue in ampq class should generate new uniq queue ;/ there is impossible i think with actual configuration @Link https://www.rabbitmq.com/tutorials/tutorial-three-php.html i did workaround for pub/sub with config: ````````````````````php use li3_queue\storage\Queue; Queue::config(array( 'li3.publisher' => array( 'adapter' => 'AMQP', 'host' => 'localhost', 'port' => 5672, 'user' => 'guest', 'pass' => 'guest', 'vhost' => '/', 'exchange' => 'amq.fanout', 'queue' => 'li3.events.1', 'routingKey' => 'li3.events', 'autoConfirm' => false, 'readTimeout' => 0, 'type' => AMQP_EX_TYPE_FANOUT, 'prefetchCount' => 1 ), 'li3.subscriber.1' => array( #same like publisher jus for clarify 'adapter' => 'AMQP', 'host' => 'localhost', 'port' => 5672, 'user' => 'guest', 'pass' => 'guest', 'vhost' => '/', 'exchange' => 'amq.fanout', 'queue' => 'li3.events.1', 'routingKey' => 'li3.events', 'autoConfirm' => false, 'readTimeout' => 0, 'type' => AMQP_EX_TYPE_FANOUT, 'prefetchCount' => 1 ), 'li3.subscriber.2' => array( 'adapter' => 'AMQP', 'host' => 'localhost', 'port' => 5672, 'user' => 'guest', 'pass' => 'guest', 'vhost' => '/', 'exchange' => 'amq.fanout', 'queue' => 'li3.events.2', 'routingKey' => 'li3.events', 'autoConfirm' => false, 'readTimeout' => 0, 'type' => AMQP_EX_TYPE_FANOUT, 'prefetchCount' => 1 ) )); ````````````````````````````````` publish evets ````````````````php Queue::write('li3.publisher', json_encode(['model' => 'Users', 'method' => 'save', 'id' => $entity->user_id] + compact('options'))); ```````````````` two consumers # - 1,2 receive same event info eg ``````````````json {"model":"Users","method":"save","id":"4023","options":{"validate":false,"whitelist":["profile_id"]}} ``````````````` ``````````````````php Queue::consume('li3.subscriber.#', function($message) { sleep(2); $this->out($message->data()); //$message->confirm(); //if (false) { // Confirm message $message->confirm(); //} // Requeue message //$message->requeue(); }); ```````````````````````````
22 days ago SobanVuex created a comment about an issue in UnionOfRAD/lithium
23 days ago nateabele closed an issue in UnionOfRAD/lithium

schema defined field as integer return string

i use `type` integer for model schema definition https://github.com/UnionOfRAD/lithium/blob/dev/data/source/database/adapter/MySql.php#L33 ````sql `hidden` tinyint(1) DEFAULT NULL, ````` ````php protected $_schema = [ 'id' => ['type' => 'id'], 'hidden' => ['type' => 'integer'] ]; ```` but find all returns sting type for hiddn field ;/ ``` ["hidden"]=> string(1) "1" `````
23 days ago nateabele created a comment about an issue in UnionOfRAD/lithium

schema defined field as integer return string

For fixed-schema databases, the schema definition (which is normally read from the database in those cases, not defined manually) is just a hint for the code when saving, not something enforced at read time. If the database is returning strings, it's probably because you've got a string column type underneath. nateabele
23 days ago nateabele created a comment about an issue in UnionOfRAD/lithium

Enhance Auth Form adapter

Looks good to me, please just fix the line endings and squash your commits. Thanks. nateabele

Enhance Auth Form adapter

As of now it is very hard to bind a model to a login form when using Auth/Form as the Form adapter has no way to read sub array data. This enhancement makes the Form adapter check if a sub array matching the models name exists and if so use it for `Auth::check()` ```php <?= $this->form->create($user); ?> <?= $this->form->text('user.username'); ?> <?= $this->form->password('user.password'); ?> <?= $this->form->end(); ?> ```