Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP with Spl DataStructures as replacement for multi-dimensional array

Tags:

php

spl

acl

I've seen many questions on this topic, but none of them covers my case.

I am building an ACL module based on 5 classes:

  1. Role
  2. Privilege
  3. Group
  4. Wrapper(guess what it does..)Factory for the Privilege, Role and Group classes
  5. AccessList Store for the groups/roles (based on usage and case)

I am thinking to use the SplQueue to store the privileges levels(mainly for the inherited privileges) So I am thinking to use a single object to store everything and do not think that the normal multi-dimensional array will be the best choice. The flow will be like this paste, it is TL;DR.. Sorry about that.

So my question is will the SplQueue be an overkill in my case?

Should I use and alternative Spl Data Structure, and if so which one?

EDIT Well I couldn't think of a good example of the usage, so lets keep to the UNIX based GBAC.

like image 659
DaGhostman Dimitrov Avatar asked Oct 03 '22 12:10

DaGhostman Dimitrov


1 Answers

If you want to store your data in the object form then the use the SplObjectStorage. The SplQueue will overkill for small array.

SplQueue works on FIFO.

So you cann't access directly to last or near to the last and will take time.

Instead of SplQueue I will suggest you use the Array as you can access any element directly by array index.

You can also check the answer of this question: Associative Array versus SplObjectStorage

Also you can check the the performance of SPLobjectStorage and array, here is the code.

For more read here.

SplObjectStorage definitely scaled linearly. Array performance was less predictable (larger standard deviation) with smaller data sets. And SplObjectStorage is indeed a better solution for storing lots of objects in a set.

So if your data is small then you should use the array otherwise use the SplObjectStorage for large amount of data.

like image 115
Code Lღver Avatar answered Oct 12 '22 09:10

Code Lღver