提到开源,一定绕不开Linux。Linux 是一款开源软件,我们可以随意浏览和修改它的源代码,学习 Linux,不得不谈到开源精神。Linux 本身就是开源精神的受益者,它几乎是全球最大的开源软件。
用户具有使用自由、修改自由、重新发布自由和创建衍生品自由,这正好符合了黑客和极客对自由的追求,因此开源软件在国内外都有着很高的人气,大家聚集在开源社区,共同推动开源软件的进步。
那么今天介绍的这一款软件及时如此,首先他们的开源性毋庸置疑,所有版本的代码都是无加密,免费版本、商业版本都是可以商用的!而这个对于初创企业不要太好,商业模式不清楚的情况下,小步试错,初有成就之后买个商业版本,把商业版图扩大!
<?php
// +---------------------------------------------------------------------------+
// | This file is part of the core package. |
// | Copyright (c) laiketui.com |
// | |
// | For the full copyright and license information, please view the LICENSE |
// | file that was distributed with this source code. You can also view the |
// | LICENSE file online at http://www.laiketui.com |
// +---------------------------------------------------------------------------+
/**
* BasicSecurityUser will handle any type of data as a credential.
*
* @package laiketui
* @subpackage user
*
* @author ketter (ketter@laiketui.com)
* @since 3.0.0
*/
class
BasicSecurityUser
extends
SecurityUser
{
// +-----------------------------------------------------------------------+
// | CONSTANTS |
// +-----------------------------------------------------------------------+
/**
* The namespace under which authenticated status will be stored.
*/
const
AUTH_NAMESPACE
=
'org/mojavi/user/BasicSecurityUser/authenticated'
;
/**
* The namespace under which credentials will be stored.
*/
const
CREDENTIAL_NAMESPACE
=
'org/mojavi/user/BasicSecurityUser/credentials'
;
// +-----------------------------------------------------------------------+
// | PRIVATE VARIABLES |
// +-----------------------------------------------------------------------+
private
$authenticated
=
null
,
$credentials
=
null
;
// +-----------------------------------------------------------------------+
// | METHODS |
// +-----------------------------------------------------------------------+
/**
* Add a credential to this user.
*
* @param mixed Credential data.
*
* @return void
*
* @author ketter (ketter@laiketui.com)
* @since 3.0.0
*/
public
function
addCredential
(
$credential
)
{
if
(
!
in_array
(
$credential
,
$this
->
credentials
))
{
$this
->
credentials
[]
=
$credential
;
}
}
// -------------------------------------------------------------------------
/**
* Clear all credentials associated with this user.
*
* @return void
*
* @author ketter (ketter@laiketui.com)
* @since 3.0.0
*/
public
function
clearCredentials
()
{
$this
->
credentials
=
null
;
$this
->
credentials
=
array
();
}
// -------------------------------------------------------------------------
/**
* Indicates whether or not this user has a credential.
*
* @param mixed Credential data.
*
* @return bool true, if this user has the credential, otherwise false.
*
* @author ketter (ketter@laiketui.com)
* @since 3.0.0
*/
public
function
hasCredential
(
$credential
)
{
return
(
in_array
(
$credential
,
$this
->
credentials
));
}
// -------------------------------------------------------------------------
/**
* Initialize this User.
*
* @param Context A Context instance.
* @param array An associative array of initialization parameters.
*
* @return bool true, if initialization completes successfully, otherwise
* false.
*
* @throws <b>InitializationException</b> If an error occurs while
* initializing this User.
*
* @author ketter (ketter@laiketui.com)
* @since 3.0.0
*/
public
function
initialize
(
$context
,
$parameters
=
null
)
{
// initialize parent
parent
::
initialize
(
$context
,
$parameters
);
// read data from storage
$storage
=
$this
->
getContext
()
->
getStorage
();
$this
->
authenticated
=
$storage
->
read
(
self
::
AUTH_NAMESPACE
);
$this
->
credentials
=
$storage
->
read
(
self
::
CREDENTIAL_NAMESPACE
);
if
(
$this
->
authenticated
==
null
)
{
// initialize our data
$this
->
authenticated
=
false
;
$this
->
credentials
=
array
();
}
}
// -------------------------------------------------------------------------
/**
* Indicates whether or not this user is authenticated.
*
* @return bool true, if this user is authenticated, otherwise false.
*
* @author ketter (ketter@laiketui.com)
* @since 3.0.0
*/
public
function
isAuthenticated
()
{
return
$this
->
authenticated
;
}
// -------------------------------------------------------------------------
/**
* Remove a credential from this user.
*
* @param mixed Credential data.
*
* @return void
*
* @author ketter (ketter@laiketui.com)
* @since 3.0.0
*/
public
function
removeCredential
(
$credential
)
{
if
(
$this
->
hasCredential
(
$credential
))
{
// we have the credential, now we have to find it
// let's not foreach here and do exact instance checks
// for future safety
for
(
$i
=
0
,
$z
=
count
(
$this
->
credentials
);
$i
<
$z
;
$i
++
)
{
if
(
$credential
==
$this
->
credentials
[
$i
])
{
// found it, let's nuke it
unset
(
$this
->
credentials
[
$i
]);
return
;
}
}
}
}
// -------------------------------------------------------------------------
/**
* Set the authenticated status of this user.
*
* @param bool A flag indicating the authenticated status of this user.
*
* @return void
*
* @author ketter (ketter@laiketui.com)
* @since 3.0.0
*/
public
function
setAuthenticated
(
$authenticated
)
{
if
(
$authenticated
===
true
)
{
$this
->
authenticated
=
true
;
return
;
}
$this
->
authenticated
=
false
;
}
// -------------------------------------------------------------------------
/**
* Execute the shutdown procedure.
*
* @return void
*
* @author ketter (ketter@laiketui.com)
* @since 3.0.0
*/
public
function
shutdown
()
{
$storage
=
$this
->
getContext
()
->
getStorage
();
// write credentials to the storage
$storage
->
write
(
self
::
AUTH_NAMESPACE
,
$this
->
authenticated
);
$storage
->
write
(
self
::
CREDENTIAL_NAMESPACE
,
$this
->
credentials
);
// call the parent shutdown method
parent
::
shutdown
();
}
}
?>
另外,商业版本提供的各种文档是真的很齐全,因为涉及到相关协定,商业版本不能发了,但是有几个点可以透露下:开源无加密、多店铺入驻、技术免费售后、永久授权、永久免费更新……这些关键词全部满足的源码,在3万以内的预算的,应该找不到第二家。当然有小伙伴会拿着部分需求来对比,记住哈,全部满足的情况下,而且项目稳定迭代3年,这样的源码即便是PHP也不会低于3万的。