Welcome Guest, Not a member yet? Register   Sign In
Khaos Library (r12)
#1

[eluser]Neophyte[/eluser]
Website - KhaosLibrary - Download - Khaos (r12)

If you use PHP 5.3 or are looking to switch to 5.3 and would like to be able to do some of the following things then the Khaos Library might be what you're looking for.

Code:
// Edit an image
$this->khaos->image('sample.jpg')->fit(150, 150)->grayscale()->save('thumbnail.jpg');

// ACL
if ($this->acl->subject('neophyte')->hasAccess('articles', 'publish'))
    echo 'I have access';

// Akismet spam checking
if ($this->khaos->akismet($comment)->isSpam() == false)
    echo 'Good to go...';

// Basic CRUD
$user = $this->khaos->table('members')->find(1);
$user->email = '[email protected]';
$user->save();

// W3C validation
if ($this->khaos->w3html($url)->isValid())
    echo 'Url is valid ...';

The library makes heavy use of lazy loading and dependency injection which is what makes the above syntax style possible whilst keeping each individual component decoupled. This also means you can keep your config options and general preferences outside of your application logic. The library is also extremely light weight with only exactly what you need being included when needed.

As an example in the above call to manipulate an image only when the call is made are the required classes instantiated, typically this would be the Image class and the GdDrawingPackage class (an instance of the GdDrawingPackage is injected into the Image instance)

Note: This code and accompanying website are under heavy development so if you like what you see any bug reports, feedback or any other help people can offer would be greatly appreciated ! Smile
#2

[eluser]Tominator[/eluser]
Is there any way how to lightweight it? I like your solution of ACL ($this->acl->subject('neophyte')->hasAccess('articles', 'publish'))). But I don't want images, tables and so on.

I know that there is khAcl ... but this one is better Smile

And how to use it?! It return me an error. Paste some example of usage. Probably some DB installation is missing ...
#3

[eluser]Neophyte[/eluser]
Sorry about that, please find the required schema in the following pastebin:
http://www.privatepaste.com/c752412059

Will also update the component documentation with the schema, dont forget to update the config file Smile any issues let me know.

If you're worried about all the other parts of the library impacting performance you dont need to worry as only exactly what is needed is ever included. This makes the library inherently very lightweight whilst also having alot of features.

If however you simply dont want to package the other files with your script then feel free to delete the components you dont need. As you're using the ACL you should keep the Security and Data folders, feel free to delete the others though.
#4

[eluser]Tominator[/eluser]
Thank you for reply but I have still problem.

If I use:
Code:
$this->load->library('khaos');
        
echo ($this->acl->subject('neophyte')->hasAccess('articles', 'publish')) ? "OK" : "KO";

It returns me:
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Home::$acl

Filename: controllers/home.php

Line Number: 14

And when I write:
Code:
$this->load->library('khaos');
        
echo ($this->khaos->acl->subject('neophyte')->hasAccess('articles', 'publish')) ? "OK" : "KO";

Answer is:
Quote:Fatal error: Uncaught exception 'Khaos\Exception' with message 'Actor 'acl' does not exist' in C:\[my_site]\application\libraries\khaos\Director.php:190 Stack trace: #0 C:\[my_site]\application\libraries\khaos\Director.php(176): Khaos\Director->__call('acl') #1 C:\[my_site]\application\controllers\home.php(14): Khaos\Director->__get('acl') #2 [internal function]: Home->index() #3 C:\[my_site\system\core\CodeIgniter.php(311): call_user_func_array(Array, Array) #4 C:\[my_site]\index.php(163): require_once('C:\[my_site]...') #5 {main} thrown in C:\[my_site]\application\libraries\khaos\Director.php on line 190

My performance:
- CI 2.0
- PHP 5.3.1
#5

[eluser]Neophyte[/eluser]
That's what i get for copy pasting from my general example :zip: the aliases ive setup by default for the codeigniter package are as follows:

Code:
'cache'      => 'Khaos\Caching\Cache',
'image'      => 'Khaos\Drawing\Image',
'dispatcher' => 'Khaos\EventDispatcher',
'database'   => 'Khaos\Data\Db',
'table'      => 'Khaos\Data\Table',
'rbac'       => 'Khaos\Security\AccessControl\Acl',
'session'    => 'Khaos\Web\SessionNamespace',

For the Acl class the alias is set as rbac so please try $this->khaos->rbac

As an asside note, the reason $this->rbac (notice i didnt specify khaos) doesnt work is because the khaos object itself uses magic methods to determine what to load.

If you did wish to use
Code:
$this->rbac
within your controller then you must first do
Code:
$this->rbac = $this->khaos->rbac;
#6

[eluser]Tominator[/eluser]
I'm confused. Khaos is for me something like chaos, but don't get me wrong Big Grin

Ok, I have new errors:
Quote:Fatal error: Uncaught exception 'PDOException' with message 'invalid data source name' in C:\[my_site]\application\libraries\khaos\Director.php:321 Stack trace: #0 [internal function]: PDO->__construct('', NULL, NULL) #1 C:\[my_site]\application\libraries\khaos\Director.php(321): ReflectionClass->newInstanceArgs(Array) #2 C:\[my_site]\application\libraries\khaos\Director.php(195): Khaos\Director->_constructClassInstance('Khaos\Data\Db', NULL) #3 C:\[my_site]\application\libraries\khaos\Director.php(262): Khaos\Director->__call('Khaos\Data\Db') #4 C:\[my_site]\application\libraries\khaos\Director.php(305): Khaos\Director->_processArguments(Array) #5 C:\[my_site]\application\libraries\khaos\Director.php(195): Khaos\Director->_constructClassInstance('rbac', NULL) #6 C:\[my_site]\application\libraries\khaos\Director.php(176): Khaos\Director->__call('rbac') #7 C:\[my_site]\application\controllers\home.php(14): Khaos\Director->__get('rbac') #8 [internal function]: Home->in in C:\[my_site]\application\libraries\khaos\Director.php on line 321

I don't know if I need to autoload config (I never use extra config), but when I use on autoload:
Code:
$autoload['config'] = array('khaos');

It gets me more errors Big Grin
Quote:A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Khaos::__construct(), called in C:\[my_site]\system\core\Loader.php on line 921 and defined
Filename: libraries/khaos.php
Line Number: 45

---------------------------------------

A PHP Error was encountered

Severity: Notice
Message: Undefined variable: config
Filename: libraries/khaos.php
Line Number: 50

---------------------------------------

A PHP Error was encountered

Severity: Notice
Message: Undefined variable: config
Filename: libraries/khaos.php
Line Number: 51

I feel, that I'm doing some noobie mistake somewhere, but I can't find where Smile
#7

[eluser]Neophyte[/eluser]
You dont need to add khaos to the config autoload, it is however interesting that if you autoload a libraries config file it is no longer passed to the constructor of the library.

Makes me wonder if that should really be the intended behaviour of CI, I will update my code to account for it though.

The first error you pasted is the important one, specifically:

Code:
PDO->__construct('', NULL, NULL)

In the config file you should see 3 options

Code:
'dsn'      => 'mysql:dbname=database;host=127.0.0.1',
'username' => 'username',
'password' => 'password',

It's almost as if these are blank in yours, if theyre not and you have set them correctly could you tell me which environment youre using, eg. are you using XAMPP for windows?
#8

[eluser]Tominator[/eluser]
You're right, I didn't set it correctly.

Now ...
1, Update your docs (http://www.khaoslibrary.com/documentation/#532):
Code:
$acl->addResource('articles');
$acl->addRole('public');
$acl->addRole('journalist', array('staff'));
$acl->addRole('editor', array('journalist'));

It throw error, that staff is not set. It should be:
Code:
$acl->addResource('articles');
$acl->addRole('public');
$acl->addRole('staff');
$acl->addRole('journalist', array('staff'));
$acl->addRole('editor', array('journalist'));

2, We have new problem:
Quote:Fatal error: Call to undefined method Khaos\Data\Db::beginTransation() in C:\[my_site]\application\libraries\khaos\Security\AccessControl\Acl.php on line 155

Caused:
Code:
$acl->addRole('journalist', array('staff'));
#9

[eluser]Tominator[/eluser]
I finally decited to use khacl ...
#10

[eluser]Neophyte[/eluser]
Thanks for the testing Smile it's what i need at the momment. I've already been able to work out a few bugs and improve the reliability.




Theme © iAndrew 2016 - Forum software by © MyBB