Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F120836320
Utils.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
Utils.php
View Options
<?php
namespace
App
;
use
Ramsey\Uuid\Uuid
;
/**
* Small utility functions for App.
*/
class
Utils
{
/**
* Provide all unique combinations of elements in $input, with order and duplicates irrelevant.
*
* @param array $input The input array of elements.
*
* @return array[]
*/
public
static
function
powerSet
(
array
$input
):
array
{
$output
=
[];
for
(
$x
=
0
;
$x
<
count
(
$input
);
$x
++)
{
self
::
combine
(
$input
,
$x
+
1
,
0
,
[],
0
,
$output
);
}
return
$output
;
}
/**
* Returns a UUID in the form of an integer.
*
* @return integer
*/
public
static
function
uuidInt
():
int
{
$hex
=
Uuid
::
uuid4
();
$bin
=
pack
(
'h*'
,
str_replace
(
'-'
,
''
,
$hex
));
$ids
=
unpack
(
'L'
,
$bin
);
$id
=
array_shift
(
$ids
);
return
$id
;
}
/**
* Returns a UUID in the form of a string.
*
* @return string
*/
public
static
function
uuidStr
():
string
{
return
Uuid
::
uuid4
()->
toString
();
}
private
static
function
combine
(
$input
,
$r
,
$index
,
$data
,
$i
,
&
$output
):
void
{
$n
=
count
(
$input
);
// Current cobination is ready
if
(
$index
==
$r
)
{
$output
[]
=
array_slice
(
$data
,
0
,
$r
);
return
;
}
// When no more elements are there to put in data[]
if
(
$i
>=
$n
)
{
return
;
}
// current is included, put next at next location
$data
[
$index
]
=
$input
[
$i
];
self
::
combine
(
$input
,
$r
,
$index
+
1
,
$data
,
$i
+
1
,
$output
);
// current is excluded, replace it with next (Note that i+1
// is passed, but index is not changed)
self
::
combine
(
$input
,
$r
,
$index
,
$data
,
$i
+
1
,
$output
);
}
/**
* Create a configuration/environment data to be passed to
* the UI
*
* @todo For a lack of better place this is put here for now
*
* @return array Configuration data
*/
public
static
function
uiEnv
():
array
{
$opts
=
[
'app.name'
,
'app.url'
,
'app.domain'
];
$env
=
\app
(
'config'
)->
getMany
(
$opts
);
$countries
=
include
resource_path
(
'countries.php'
);
$env
[
'countries'
]
=
$countries
?:
[];
return
$env
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Apr 24, 1:28 PM (11 h, 27 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c2/70/cd90697d1aa14cc93c2233fa0930
Default Alt Text
Utils.php (2 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline